This repository was archived by the owner on Apr 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax_crimes_api.php
More file actions
452 lines (390 loc) · 16.9 KB
/
Copy pathajax_crimes_api.php
File metadata and controls
452 lines (390 loc) · 16.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization");
header('Content-type: application/json');
require_once 'includes/functions.php';
start_session_guarded();
function shorthandNumber($number)
{
if ($number >= 1000000000) { // Check if the number is at least a billion
$shorthand = round($number / 1000000000, 2) . 'B'; // Convert to billions, round to 2 decimal places, and append 'B'
return $shorthand;
} elseif ($number >= 1000000) { // Check if the number is at least a million
$shorthand = round($number / 1000000, 2) . 'M'; // Convert to millions, round to 2 decimal places, and append 'M'
return $shorthand;
} elseif ($number >= 1000) { // Check if the number is at least a thousand
$shorthand = round($number / 1000, 1) . 'k'; // Convert to thousands, round to 1 decimal place, and append 'k'
return $shorthand;
}
return number_format($number); // Return the original number if it's less than 1000
}
$data = json_decode(file_get_contents("php://input"), true);
if (isset($data['user_id'])) {
$_SESSION['user_id'] = $data['user_id'];
$_SESSION['id'] = $data['user_id'];
}
include_once "classes.php";
include_once "database/pdo_class.php";
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
try {
if (isset($_GET['au_user_or']) && (int) $_GET['au_user_or']) {
$user_class = new User((int) $_GET['au_user_or']);
} else {
$user_class = new User($_SESSION['id']);
}
session_write_close();
$crime_multiplier = 1;
if (isset($data['cm'])) {
$allowed = array(1, 2, 4, 10, 20, 30, 50);
if (in_array($data['cm'], $allowed)) {
$crime_multiplier = $data['cm'];
}
}
$debug = array(
'id' => $user_class->id,
'crime_multiplier' => $crime_multiplier,
'data' => $data
);
if (!$user_class) {
throw new Exception("Invalid user.");
}
set_last_active($user_class->id);
if ($user_class->jail || $user_class->hospital) {
throw new Exception("You are not able to do crimes at the moment.");
}
if (isset($data['crime_id'])) {
$id = $data['crime_id'];
$db->query("SELECT `id`, `nerve`, `name` FROM crimes WHERE id = ? LIMIT 1");
$db->execute([$id]);
$row = $db->fetch_row(true);
if (empty($row)) {
throw new Exception("Not enough nerve to complete this crime");
}
$nerve = $row['nerve'];
$name = $row['name'];
if ($user_class->maxnerve < $nerve) {
throw new Exception("Not enough nerve for the crime.");
}
$time = floor(($nerve - ($nerve * 0.5)) * 6);
$stext = 'You successfully managed to ' . $name;
$ftext = 'You failed to ' . $name;
$chance = rand(1, 250);
$money = ((50 * $nerve) + 15 * ($nerve - 1)) * 1;
$exp = ((10 * $nerve) + 8 * ($nerve - 1)) * 1.0;
$db->query("SELECT `count` FROM crimeranks WHERE userid = ? AND crimeid = ?");
$db->execute(array($user_class->id, $row['id']));
$crimeRankResult = $db->fetch_row(true);
if ($crimeRankResult) {
$crimeCount = (int) $crimeRankResult['count'];
} else {
$crimeCount = 0;
}
// Determine the star level based on the crime count
if ($crimeCount >= 10000 && $crimeCount < 100000) {
$star_level = 1;
} elseif ($crimeCount >= 100000 && $crimeCount < 1000000) {
$star_level = 2;
} elseif ($crimeCount >= 1000000 && $crimeCount < 5000000) {
$star_level = 3;
} elseif ($crimeCount >= 5000000 && $crimeCount < 15000000) {
$star_level = 4;
} elseif ($crimeCount >= 15000000) {
if (isset($user_class->completeUserResearchTypesIndexedOnId[16])) {
if ($crimeCount >= 30000000) {
$star_level = 6;
} else {
$star_level = 5;
}
} else {
$star_level = 5;
}
} else {
$star_level = 0; // No bonus if the conditions are not met
}
$bonus_exp_per_star_level = 0.10; // 10% bonus per star level
$star_bonus_exp = $exp * $star_level * $bonus_exp_per_star_level;
$exp += $star_bonus_exp;
$crimeexpbonus = 0;
if ($user_class->crimeexpboost > 1) {
$crimeexpbonus += 0.2;
$crimeexpbonus += ($user_class->crimeexpboost - 1) * 0.0333;
} elseif ($user_class->crimeexpboost == 1) {
$crimeexpbonus = 0.2;
}
$bonus = $exp * $crimeexpbonus;
$exp = round($exp + $bonus, 2);
if ($user_class->prestige > 0) {
$exp *= (.20 * $user_class->prestige) + 1;
}
if ($user_class->exppill >= time()) {
$exp *= 2.0;
$chance = 100;
}
$tempItemUse = getItemTempUse($user_class->id);
if ($tempItemUse['crime_booster_time'] > time()) {
$exp += round(($exp / 5));
} else if ($tempItemUse['crime_potion_time'] > time()) {
$exp += round(($exp / 10));
}
$db->query("SELECT * FROM gamebonus WHERE ID = 1 LIMIT 1");
$db->execute();
$bonus_row = $db->fetch_row(true);
$tempItemUse = getItemTempUse($user_class->id);
$aTime = time();
if ($tempItemUse['gang_double_exp_time'] > $aTime) {
$exp *= 2;
$money *= 1;
$chance = 100;
} else {
if ($bonus_row['Time'] > 0) {
$exp *= 2;
$money *= 1;
$chance = 100;
}
}
if (time() < 1673827199) {
$exp *= 2;
$money *= 1;
$chance = 100;
}
if (isset($_GET['au_user_or']) && (int) $_GET['au_user_or']) {
$chance = 100;
}
// Crime Multiplier Adjustments
$mission_nerve = $nerve;
$nerve = ($nerve * $crime_multiplier);
$exp = ($exp * $crime_multiplier);
$money = ($money * $crime_multiplier);
$prepaid = false;
$debug['prenerve'] = $nerve;
$debug['preusernerve'] = $user_class->nerve;
if ($nerve > $user_class->nerve && $user_class->nerref == 2) {
$nerveneeded = $nerve - $user_class->nerve;
if ($nerveneeded < $user_class->maxnerve) {
$debug['override'] = 1;
$nerveneeded = $user_class->maxnerve;
}
$debug['refill'] = 'now';
$debug['nerve'] = $nerve;
$debug['usernerve'] = $user_class->nerve;
$debug['usermaxnerve'] = $user_class->maxnerve;
$debug['nerveneeded'] = $nerveneeded;
$cost = floor($nerveneeded / 10);
$debug['cost1'] = $cost;
if ($cost < 10) {
$cost = 10;
}
if ($cost > $user_class->points) {
throw new Exception("Not enough points for refill.");
} else if ($user_class->points < 10) {
throw new Exception("Not enough points for refill.");
}
$now = time();
if ($tempItemUse['nerve_vial_time'] > $now) {
$extraCost = $cost / 2;
$cost = ceil($cost - ($extraCost / 2));
}
$debug['cost'] = $cost;
$user_class->nerve = $user_class->maxnerve;
$user_class->points -= $cost;
$db->query("UPDATE grpgusers SET points = points - ?, nerve = ? WHERE id = ?");
$db->execute(array(
$cost,
$user_class->maxnerve,
$user_class->id
));
$prepaid = true;
} else if ($nerve > $user_class->nerve) {
throw new Exception("Refill not enabled.");
}
if ($user_class->nerve >= $nerve || $prepaid) {
if ($prepaid) {
$bbnerve = $nerve;
$nerve = 0;
} else {
$bbnerve = $nerve / $user_class->level;
}
if ($chance < 5) {
$user_class->nerve -= $nerve;
$db->query("UPDATE grpgusers SET crimefailed = crimefailed + 1, nerve = nerve - ? WHERE id = ?");
$db->execute(array(
$nerve,
$user_class->id
));
throw new Exception($ftext . ".|" . number_format($user_class->points) . "|" . number_format($user_class->money) . "|" . number_format($user_class->level) . "|" . genBars());
} elseif ($chance == 6) {
$user_class->nerve -= $nerve;
$db->query("UPDATE grpgusers SET crimefailed = crimefailed + 1, nerve = nerve - ?, caught = caught + 1, jail = 300 WHERE id = ?");
$db->execute(array(
$nerve,
$user_class->id
));
echo json_encode(array(
'text' => 'You were hauled off to jail for 5 minutes',
'error' => 'refresh'
));
die();
} else {
$debug['mission_nerve'] = $mission_nerve;
if ($mission_nerve >= 50) {
$which = "crimes50";
} elseif ($mission_nerve >= 25) {
$which = "crimes25";
} elseif ($mission_nerve >= 10) {
$which = "crimes10";
} elseif ($mission_nerve >= 5) {
$which = "crimes5";
} else {
$which = "crimes1";
}
newmissions($which, $crime_multiplier);
contribute_mission('c', $crime_multiplier);
gangContest(array('crimes' => $crime_multiplier, 'exp' => $exp));
bloodbath('crimes', $user_class->id, $bbnerve / $user_class->level, $user_class);
$userPrestigeSkills = getUserPrestigeSkills($user_class);
if ($userPrestigeSkills['crime_cash_unlock'] > 0) {
$money = $money + ($money / 100 * 10);
}
if ($userPrestigeSkills['crime_cash_boost_level'] > 0) {
$money = $money + ($money / 100 * (2 * $userPrestigeSkills['crime_cash_boost_level']));
}
if (isset($user_class->completeUserResearchTypesIndexedOnId[1])) {
$mPerIc = ceil($money / 100 * 2);
$money = $money + $mPerIc;
}
$researchExpBoost = 0;
if (isset($user_class->completeUserResearchTypesIndexedOnId[4])) {
$researchExpBoost += 5;
}
if (isset($user_class->completeUserResearchTypesIndexedOnId[7])) {
$researchExpBoost += 5;
}
if (isset($user_class->completeUserResearchTypesIndexedOnId[9])) {
$researchExpBoost += 5;
}
if (isset($user_class->completeUserResearchTypesIndexedOnId[12])) {
$researchExpBoost += 10;
}
if ($researchExpBoost > 0) {
$resExpInc = $exp / 100 * $researchExpBoost;
$exp = $exp + $resExpInc;
}
$exp = ceil($exp);
$gtax = 0;
if ($user_class->gang != 0) {
$db->query("SELECT `tax` FROM `gangs` WHERE `id` = ?");
$db->execute(array($user_class->gang));
$gangTax = $db->fetch_row(true);
if (isset($gangTax['tax']) && $gangTax['tax'] > 0) {
$gtax = $money * ($gangTax['tax'] / 100);
gangContest(array('tax' => $gtax));
}
}
$money = $money - $gtax;
$totaltax = $gtax;
$debug['exp_earned'] = $exp;
$maxnervePercCheck = $mission_nerve / $user_class->maxnerve * 100;
if ($maxnervePercCheck >= 50) {
addToUserCompLeaderboard($user_class->id, 'crimes_complete', $crime_multiplier);
}
$db->query("SELECT * FROM activity_contest WHERE id = 1 LIMIT 1");
$db->execute();
$activityContest = $db->fetch_row(true);
if ($activityContest['type'] == 'crimes') {
addToUserCompLeaderboard($user_class->id, 'activity_complete', $crime_multiplier);
}
addToGangCompLeaderboard($user_class->gang, 'crimes_complete', $crime_multiplier);
$bpCategory = getBpCategory();
if ($bpCategory) {
addToBpCategoryUser($bpCategory, $user_class, 'crimes', $crime_multiplier);
}
$user_class->money += $money;
$user_class->nerve -= $nerve;
$db->query("UPDATE grpgusers SET loth = loth + ?, exp = exp + ?, crimesucceeded = crimesucceeded + 1, crimemoney = crimemoney + ?, `money` = `money` + ?, nerve = nerve - ?, todaysexp = todaysexp + ?, expcount = expcount + ?, totaltax = totaltax + ? WHERE id = ?");
$db->execute(array(
$exp,
$exp,
$money,
$money,
$nerve,
$exp,
$exp,
$totaltax,
$user_class->id
));
$db->query("UPDATE gangs SET moneyvault = moneyvault + ? WHERE id = ?");
$db->execute(array(
$gtax,
$user_class->gang
));
$db->query("SELECT id FROM crimeranks WHERE userid = ? AND crimeid = ?");
$db->execute(array($user_class->id, $id));
$crimeRank = $db->fetch_row(true);
if ($crimeRank) {
$db->query("UPDATE crimeranks SET count = count + 1 WHERE id = ?");
$db->execute(array($crimeRank['id']));
} else {
$db->query("INSERT INTO crimeranks (userid, crimeid, count) VALUES (?, ?, 1)");
$db->execute(array($user_class->id, $id));
}
$db->query("SELECT `name`, mission.crimes as crimestarget, missions.crimes as crimesdone FROM missions LEFT JOIN mission ON missions.mid = mission.id WHERE `userid` = ? AND `completed` = \"no\" LIMIT 1");
$db->execute(array(
$user_class->id
));
$activeMission = $db->fetch_row(true);
$mt = "";
if ($activeMission) {
$mt = "Active Mission: {$activeMission['name']} Crimes: {$activeMission['crimesdone']}/{$activeMission['crimestarget']}";
}
$text = ($gtax > 0) ? "$stext. You received $exp exp and $$money.(Gang Tax: $$gtax)" : "$stext. You received $exp exp and $$money";
$debug['response'] = "Success! $text";
echo json_encode(array(
'debug' => $debug,
'text' => $text,
'stats' => array(
'points' => number_format($user_class->points),
'mb_points' => shorthandNumber($user_class->points),
'money' => number_format($user_class->money),
'mb_money' => shorthandNumber($user_class->money),
'level' => number_format($user_class->level),
'mission' => $mt
),
'bars' => array(
'energy' => array(
'percent' => $user_class->energypercent,
'title' => $user_class->formattedenergy
),
'nerve' => array(
'percent' => $user_class->nervepercent,
'title' => $user_class->formattednerve
),
'awake' => array(
'percent' => $user_class->awakepercent,
'title' => $user_class->awakepercent
),
'exp' => array(
'percent' => $user_class->exppercent,
'title' => $user_class->exppercent
),
)
));
exit;
}
} else {
throw new Exception("Not enough nerve.");
}
} else {
throw new Exception("Invalid crime ID.");
}
} catch (Exception $e) {
echo json_encode(array(
'error' => true,
'message' => $e->getMessage(),
'debug' => isset($debug) ? $debug : null
));
}
$db = null;
?>