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_attack_v2.php
More file actions
740 lines (637 loc) · 28.7 KB
/
ajax_attack_v2.php
File metadata and controls
740 lines (637 loc) · 28.7 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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
<?php
require_once 'includes/functions.php';
start_session_guarded();
function get_respect_for_level($level_diff)
{
$range = range(-100, 100);
$rtn = array();
$respect_payout = 0;
for ($i = 0; $i <= count($range) - 1; $i++) {
$rtn[$range[$i]] = ($respect_payout < .01) ? .01 : $respect_payout;
$respect_payout += .005;
}
return $rtn[max(-100, min(100, $level_diff))];
}
function get_user_streak($userid)
{
global $db;
$db->query("SELECT streak FROM user_kill_streaks WHERE userid = ?");
$db->execute([$userid]);
$user_streak = $db->fetch_row(true);
return $user_streak['streak'];
}
function add_user_streak($userid)
{
global $db;
$db->query("INSERT INTO user_kill_streaks (userid, streak) VALUES (?, 1) ON DUPLICATE KEY UPDATE streak = streak + 1");
$db->execute([$userid]);
}
function kill_user_streak($userid)
{
global $db;
$db->query("DELETE FROM user_kill_streaks WHERE userid = ?");
$db->execute([$userid]);
}
function print_pre($print)
{
// echo "<pre>";
// print_r($print);
// echo "<pre>";
}
function fetchGangUpgradeLevel($gangId)
{
global $db;
if (!$gangId) {
// If no gang ID is provided, return 0
return 0;
}
$db->query("SELECT upgrade7 FROM gangs WHERE id = " . $gangId);
$db->execute();
$result = $db->fetch_row(true);
if ($result['upgrade7']) {
return $result['upgrade7'];
}
return 0;
}
function error($msg)
{
$response = array();
$response['success'] = false;
$response['error'] = $msg;
return $response;
}
function success($msg)
{
$response = array();
$response['success'] = true;
$response['message'] = $msg;
return $response;
}
include_once "classes.php";
include_once "database/pdo_class.php";
$user_class = new User($_SESSION['id']);
session_write_close();
$response = array();
if (!isset($_GET['alv'])) {
echo json_encode(error('Something went wrong.'));
exit;
}
if ($_GET['alv'] !== 'yes') {
echo json_encode(error('Something went wrong.'));
exit;
}
$modifier = ($user_class->rmdays > 0) ? 0.2 : 0.25;
$energyneeded = floor($user_class->maxenergy * $modifier);
$tempItemUse = getItemTempUse($user_class->id);
if ($tempItemUse['love_potions_time'] > time()) {
$energyneeded = 0;
removeItemTempUse($user_class->id, 'love_potions_time', 1);
}
if (($user_class->energy <= $energyneeded || $user_class->energypercent <= 0) && $user_class->ngyref == 2) {
manual_refill('e');
}
$attack_person = new User($_GET['attack']);
$throneAttack = false;
if (isset($_GET['throne']) && $_GET['throne'] == 'attack') {
if ($user_class->gender === 'Male' && $attack_person->king < 1) {
$throneAttack = true;
}
if ($user_class->gender === 'Female' && $attack_person->queen < 1) {
$throneAttack = true;
}
}
if (isset($_GET['thrones']) && $_GET['thrones'] == 'attack') {
$throneAttack = true;
}
if ($user_class->id != 0) {
$error = "";
$error = ($user_class->energy < $energyneeded) ? "You need 25% energy if you want to attack someone." : $error;
//$error = ($user_class->energypercent <= 0) ? "You need 25% energy if you want to attack someone." : $error;
$error = ($user_class->hppercent < 25) ? "You need to have over 25% HP to attack someone." : $error;
$error = ($user_class->hospital > 0) ? "You can't attack someone if you are in hospital." : $error;
$error = ($_GET['attack'] == "") ? "You didn't choose someone to attack." : $error;
$error = ($_GET['attack'] == $user_class->id) ? "You can't attack yourself." : $error;
$currentTime = time();
$oneHourAgo = $currentTime - 3600; // 3600 seconds = 1 hour
// Check if user's HP is below 25%
if ($user_class->hppercent < 25) {
$error = "You need to have over 25% HP to attack someone.";
}
// Combine checks for user's attack protection and attack_person's last active time
else if ($user_class->aprotection > $currentTime && $attack_person->lastactive > $oneHourAgo) {
$error = "You cannot attack due to you having an active protection or the target's recent activity.";
}
// If none of the conditions are met, then no error
else {
$error = ""; // No error, ready to proceed
}
if (!empty($error)) {
echo json_encode(error($error));
exit;
}
if ($user_class->aprotection != 0) {
$error = "";
$error = ($user_class->energy < $energyneeded) ? "You need 25% energy if you want to attack someone." : $error;
//$error = ($user_class->energypercent <= 0) ? "You need 25% energy if you want to attack someone." : $error;
$error = ($user_class->hppercent < 25) ? "You need to have over 25% HP to attack someone." : $error;
$error = ($user_class->hospital > 0) ? "You can't attack someone if you are in hospital." : $error;
$error = ($_GET['attack'] == "") ? "You didn't choose someone to attack." : $error;
$error = ($_GET['attack'] == $user_class->id) ? "You can't attack yourself." : $error;
}
if ($attack_person->id >= 00 and $attack_person->id <= 00) {
$attack_person->level = $user_class->level + $attack_person->id - 410;
$attack_person->hp = $attack_person->purehp = $attack_person->maxhp = $attack_person->puremaxhp = $attack_person->level * 50;
$attack_person->hppercent = 100;
$attack_person->formattedhp = $attack_person->hp . " / " . $attack_person->maxhp . " [100%]";
$attack_person->city = $user_class->city;
$attack_person->jail = 0;
$attack_person->moddedstrength = rand(750 * (($attack_person->id - 404) / 10), 2200 * (($attack_person->id - 404) / 10));
$attack_person->moddeddefense = rand(750 * (($attack_person->id - 404) / 10), 2200 * (($attack_person->id - 404) / 10));
$attack_person->moddedspeed = rand(750 * (($attack_person->id - 404) / 10), 2200 * (($attack_person->id - 404) / 10));
$user_class->moddedstrength = rand(1000, 5000);
$user_class->moddeddefense = rand(1000, 5000);
$user_class->moddedspeed = rand(1000, 5000);
}
$error = ($user_class->hospital > 0) ? "You can't attack someone if you are in hospital." : $error;
$error = ($user_class->jail > 0 && $attack_person->jail == 0) ? "You can't attack someone if you are in prison." : $error;
$error = ($attack_person->jail > 0 && $user_class->jail == 0) ? "You can't attack someone that is in prison." : $error;
$error = ($attack_person->city != $user_class->city && $user_class->id != 0) ? "You must be in the same city as the person you're attacking!" : $error;
$error = ($attack_person->username == "") ? "That person doesn't exist." : $error;
$error = ($attack_person->hospital > 0 && !$throneAttack) ? "You can't attack someone that is in hospital." : $error;
$error = ($attack_person->hppercent < 25) ? "They need over 25% HP to be attacked." : $error;
$error = ($attack_person->admin == 1 && $user_class->admin < 1) ? "Im sorry, You cannot attack the owner" : $error;
$error = ($attack_person->id == $user_class->id) ? "Why would you want to attack yourself?" : $error;
$error = ($attack_person->aprotection > time() && !$throneAttack) ? "This Mobster is under Attack Protection." : $error;
$db->query("SELECT COUNT(*) FROM attackladder WHERE `user` = ?");
$db->execute([$attack_person->id]);
$attackLadder = $db->fetch_row();
if (count($attackLadder) == 0) {
$error = ($attack_person->aprotection > time()) ? "This Mobster is under Attack Protection." : $error;
$error = ($user_class->gang == $attack_person->gang && $user_class->gang > 0 && !$throneAttack) ? "You can't attack someone in your gang." : $error;
}
if (!empty($error)) {
echo json_encode(error($error));
exit;
}
$agreed = (isset($_GET['agreed'])) ? $_GET['agreed'] : 0;
}
$yourhp = $user_class->hp;
$theirhp = $attack_person->hp;
if ($user_class->jail) {
$user_class->moddeddefense = $user_class->defense;
$user_class->moddedspeed = $user_class->speed;
$user_class->moddedstrength = $user_class->strength;
$attack_person->moddeddefense = $attack_person->defense;
$attack_person->moddedspeed = $attack_person->speed;
$attack_person->moddedstrength = $attack_person->strength;
}
// Right before this comment is where you should apply the gang upgrade logic
// Fetch the gang upgrade levels
$userGangUpgradeLevel = fetchGangUpgradeLevel($user_class->gang);
$attackGangUpgradeLevel = fetchGangUpgradeLevel($attack_person->gang);
// Calculate the stat bonus multipliers
$userStatBonusMultiplier = 1 + ($userGangUpgradeLevel * 0.10);
$attackStatBonusMultiplier = 1 + ($attackGangUpgradeLevel * 0.10);
// Apply the stat bonus multipliers to the user_class and attack_person
$user_class->moddedstrength = round($user_class->moddedstrength * $userStatBonusMultiplier);
$user_class->moddeddefense = round($user_class->moddeddefense * $userStatBonusMultiplier);
$user_class->moddedspeed = round($user_class->moddedspeed * $userStatBonusMultiplier);
$user_class->moddedagility = round($user_class->moddedagility * $userStatBonusMultiplier);
if ($user_class->gang > 0) {
// Strength
$db->query("SELECT upgrade1 FROM gangs WHERE id = " . $user_class->gang);
$db->execute();
$u = $db->fetch_row(true);
$percent = $u['upgrade1'] * 20;
$user_class->moddedstrength += round(($user_class->moddedstrength * $percent) / 100);
// Defense
$db->query("SELECT upgrade2 FROM gangs WHERE id = " . $user_class->gang);
$db->execute();
$u = $db->fetch_row(true);
$percent = $u['upgrade2'] * 20;
$user_class->moddeddefense += round(($user_class->moddeddefense * $percent) / 100);
// Speed
$db->query("SELECT upgrade3 FROM gangs WHERE id = " . $user_class->gang);
$db->execute();
$u = $db->fetch_row(true);
$percent = $u['upgrade3'] * 20;
$user_class->moddedspeed += round(($user_class->moddedspeed * $percent) / 100);
// Agility
$db->query("SELECT upgrade_agility FROM gangs WHERE id = " . $user_class->gang);
$db->execute();
$u = $db->fetch_row(true);
$percent = $u['upgrade_agility'] * 20;
$user_class->moddedagility += round(($user_class->moddedagility * $percent) / 100);
}
$attack_person->moddedstrength = round($attack_person->moddedstrength * $attackStatBonusMultiplier);
$attack_person->moddeddefense = round($attack_person->moddeddefense * $attackStatBonusMultiplier);
$attack_person->moddedspeed = round($attack_person->moddedspeed * $attackStatBonusMultiplier);
if ($attack_person->gang > 0) {
// Strength
$db->query("SELECT upgrade1 FROM gangs WHERE id = " . $attack_person->gang);
$db->execute();
$u = $db->fetch_row(true);
$percent = $u['upgrade1'] * 20;
$attack_person->moddedstrength += round(($attack_person->moddedstrength * $percent) / 100);
// Defense
$db->query("SELECT upgrade2 FROM gangs WHERE id = " . $attack_person->gang);
$db->execute();
$u = $db->fetch_row(true);
$percent = $u['upgrade2'] * 20;
$attack_person->moddeddefense += round(($attack_person->moddeddefense * $percent) / 100);
// Speed
$db->query("SELECT upgrade3 FROM gangs WHERE id = " . $attack_person->gang);
$db->execute();
$u = $db->fetch_row(true);
$percent = $u['upgrade3'] * 20;
$attack_person->moddedspeed += round(($attack_person->moddedspeed * $percent) / 100);
}
$userspeed = $user_class->moddedspeed;
$attackspeed = $attack_person->moddedspeed;
$wait = ($userspeed > $attackspeed) ? 1 : 0;
$number = 0;
$rtn = array();
if ($user_class->invincible == 0) {
if ($attack_person->invincible == 0) {
while ($yourhp > 0 && $theirhp > 0) {
if ($wait == 0) {
$hitChance = 80;
if ($attack_person->moddedspeed > $user_class->moddedagility) {
$hitChance = $hitChance + 15;
}
if (mt_rand(1, 100) > $hitChance) {
// Missed
$rtn[] = array(
'attacking_person' => $attack_person->id,
'defending_person' => $user_class->id,
'is_first_attack' => $wait,
'is_hit' => 0,
'is_critical_hit' => 0,
'is_counter_attack' => 0,
'damage' => 0,
'yourhp' => $yourhp,
'theirhp' => $theirhp,
);
} else {
// Hit
$damageResult = getAttackDamage($attack_person, $user_class);
$damage = $damageResult['damage'];
$yourhp = $yourhp - $damage;
$rtn[] = array(
'attacking_person' => $attack_person->id,
'defending_person' => $user_class->id,
'is_first_attack' => $wait,
'is_hit' => 1,
'is_critical_hit' => $damageResult['is_critical_hit'],
'is_counter_attack' => 0,
'damage' => $damage,
'yourhp' => $yourhp,
'theirhp' => $theirhp,
);
}
} else {
$wait = 0;
}
if ($yourhp > 0) {
$hitChance = 80;
if ($user_class->moddedspeed > $attack_person->moddedagility) {
$hitChance = $hitChance + 15;
}
if (mt_rand(1, 100) > $hitChance) {
// Missed
$rtn[] = array(
'attacking_person' => $user_class->id,
'defending_person' => $attack_person->id,
'is_first_attack' => $wait,
'is_hit' => 0,
'is_critical_hit' => 0,
'is_counter_attack' => 0,
'damage' => 0,
'yourhp' => $yourhp,
'theirhp' => $theirhp,
);
} else {
// Hit
$damageResult = getAttackDamage($user_class, $attack_person);
$damage = $damageResult['damage'];
$theirhp = $theirhp - $damage;
$rtn[] = array(
'attacking_person' => $user_class->id,
'defending_person' => $attack_person->id,
'is_first_attack' => $wait,
'is_hit' => 1,
'is_critical_hit' => $damageResult['is_critical_hit'],
'is_counter_attack' => 0,
'damage' => $damage,
'yourhp' => $yourhp,
'theirhp' => $theirhp,
);
}
}
}
} else {
$yourhp = 0;
}
} else {
$theirhp = 0;
}
$respect_earnt = 0;
if ($theirhp <= 0) {
$winner = $user_class->id;
$moneywon = floor($attack_person->money / rand(8, 9));
$expwon = 100 - (100 * ($user_class->level - $attack_person->level));
$expwon = ($expwon < 20) ? 20 : $expwon;
$expwon = ($expwon > 10000) ? 10000 : $expwon;
$expwon = floor($expwon);
$theirhp = 0;
$db->query("SELECT `name` FROM cities WHERE `id` = " . $user_class->city);
$db->execute();
$cityn = $db->fetch_row(true);
$cityname = $cityn['name'];
$db->query("SELECT `id`, `city`, `king`, `queen` FROM `grpgusers` WHERE `id` = ?");
$db->execute([$attack_person->id]);
$row = $db->fetch_row();
if (isset($row[0])) {
$row = $row[0];
// Check if the attacked person is king and the winner is male
if ($row['king'] == $user_class->city) {
// Dethrone the current king
$db->query("UPDATE `grpgusers` SET `king` = 0, `queen` = 0 WHERE `id` = ?");
$db->execute([$attack_person->id]);
// Crown the new king
$db->query("UPDATE `grpgusers` SET `king` = ?, `queen` = 0 WHERE `id` = ?");
$db->execute([$user_class->city, $winner]);
// Send event notifications
Send_Event($attack_person->id, "You have been defeated and lost your status as Boss of " . $cityname . ".");
Send_Event($winner, "Congratulations! You have defeated the Boss of " . $cityname . ".");
}
// Check if the attacked person is queen and the winner is female
if ($row['queen'] == $user_class->city) {
// Dethrone the current queen
$db->query("UPDATE `grpgusers` SET `queen` = 0, `king` = 0 WHERE `id` = ?");
$db->execute([$attack_person->id]);
// Crown the new queen
$db->query("UPDATE `grpgusers` SET `queen` = ?, `king` = 0 WHERE `id` = ?");
$db->execute([$user_class->city, $winner]);
// Send event notifications
Send_Event($attack_person->id, "You have been defeated and lost your status as Under Boss of " . $cityname . ".");
Send_Event($winner, "Congratulations! You have defeated the Under Boss of " . $cityname . ".");
}
}
$city = $user_class->city;
//if ($user_class->id == 174) {
$spots = range(1, 10);
$db->query("SELECT * FROM attackladder");
$db->execute();
$attackLadder = $db->fetch_row();
$spotsTaken = [];
foreach ($attackLadder as $s) {
$spotsTaken[] = $s['spot'];
}
$spare = array_diff($spots, $spotsTaken);
$winnerKey = array_search($winner, array_column($attackLadder, 'user'));
$attackedKey = array_search($attack_person->id, array_column($attackLadder, 'user'));
if ($user_class->id == 0) {
var_dump($winnerKey);
var_dump($attackedKey);
}
if ($winnerKey === false && $attackedKey === false && !empty($spare)) {
$db->query("INSERT INTO attackladder (user, spot, last_attack) VALUES (?, ?, ?)");
$db->execute([$winner, reset($spare), time()]);
} else {
if ($attackedKey !== false && $winnerKey !== false) { // both are on the ladder
if ($attackLadder[$winnerKey]['spot'] > $attackLadder[$attackedKey]['spot']) {
$db->query("UPDATE `attackladder` SET `spot` = ?, last_attack = ? WHERE `user` = ?");
$db->execute([$attackLadder[$attackedKey]['spot'], time(), $winner]);
$db->query("UPDATE `attackladder` SET `spot` = ? WHERE `user` = ?");
$db->execute([$attackLadder[$attackedKey]['spot'] + 1, $attack_person->id]);
// winner spot = 8
// attacked spot = 2
// winner takes 2
// attacked spot + 1 (3)
// cascade down +1 (3 = 4)
// cascade down +1 (4 = 5) etc..
// until 10
$db->query("UPDATE `attackladder` SET `spot` = `spot` + 1 WHERE `user` = ? AND `spot` > ?");
$db->execute([$attack_person->id, $attackLadder[$attackedKey]['spot'] + 1]);
$db->query("DELETE FROM `attackladder` WHERE `spot` > 10");
$db->execute();
Send_Event($attack_person->id, "[-_USERID_-] You've been knocked from your place in the Attack Ladder ", $attack_person->id);
}
} else if ($attackedKey !== false && $winnerKey === false) { // attacked person is on ladder but winner is not
$db->query("UPDATE `attackladder` SET `user` = ?, last_attack = ? WHERE `spot` = ?");
$db->execute([$winner, time(), $attackLadder[$attackedKey]['spot']]);
Send_Event($attack_person->id, "[-_USERID_-] You've been knocked from your place in the Attack Ladder ", $attack_person->id);
}
}
$db->query("UPDATE `attackladder` SET `last_attack` = ? WHERE `user` = ?");
$db->execute([time(), $winner]);
bloodbath('defendlost', $attack_person->id);
bloodbath('attackswon', $user_class->id);
$toadd = array('kotd' => 1);
ofthes($user_class->id, $toadd);
$db->query("UPDATE grpgusers SET koth = koth + 1, loth = loth + ?, todaysexp = todaysexp + ?, exp = exp + ?, money = money + ?, battlewon = battlewon + 1, battlemoney = battlemoney + ?, todayskills = todayskills + 1, killcomp1 = killcomp1 + 1 WHERE id = ?");
$db->execute(array(
$expwon,
$expwon,
$expwon,
$moneywon,
$moneywon,
$user_class->id
));
$db->query("UPDATE grpgusers SET money = money - ?, hwho = ?, hhow = 'wasattacked', hwhen = ?, hospital = 120, battlelost = battlelost + 1, delay = delay + 10, battlemoney = battlemoney - ? WHERE id = ?");
$db->execute(array(
$moneywon,
$user_class->id,
date("g:i:sa", time()),
$moneywon,
$attack_person->id
));
$db->query("UPDATE pets SET exp = exp + ($expwon) / 10 WHERE userid = ? AND leash = 1");
$db->execute([$user_class->id]);
// UserCompLeaderboard
addToUserCompLeaderboard($user_class->id, 'attacks_complete', 1);
addToRelCompLeaderboard($user_class->id, 'attacks_complete', 1);
addToGangCompLeaderboard($user_class->gang, 'attacks_complete', 1);
$bpCategory = getBpCategory();
if ($bpCategory) {
addToBpCategoryUser($bpCategory, $user_class, 'attacks', 1);
}
payoutChristmasGift($user_class->id);
$db->query("SELECT * FROM activity_contest WHERE id = 1 LIMIT 1");
$db->execute();
$activityContest = $db->fetch_row(true);
if (!empty($activityContest) && isset($activityContest['type']) && $activityContest['type'] == 'attacks') {
addToUserCompLeaderboard($user_class->id, 'activity_complete', $activityContest['type_value']);
addToRelCompLeaderboard($user_class->id, 'activity_complete', $activityContest['type_value']);
}
$message = "You attacked " . $attack_person->formattedname . " and won! You gain " . prettynum($expwon) . " exp and stole $" . prettynum($moneywon) . ".";
if ($user_class->gang != 0) {
$db->query("UPDATE gangs SET exp = exp + ?, bbattackwon = bbattackwon + 1, dailyKills = dailyKills + 1 WHERE id = ?");
$db->execute(array(
$expwon,
$user_class->gang
));
}
// Chaos (Halloween Event)
// include_once 'includes/repositories/chaos_repository.php';
// $chaosRepository = new ChaosRepository();
// // 25% chance to get a soul
// $rnd = mt_rand(1, 4);
// if ($rnd == 1) {
// $chaosRepository->awardSouls($user_class->id, 1, 'attack');
// }
contribute_mission('k');
newmissions('kills');
updateGangActiveMission('kills', 1);
gangContest(array(
'kills' => 1,
'exp' => $expwon
));
$currentQuestSeason = getCurrentQuestSeasonForUser($user_class->id);
if (isset($currentQuestSeason['id'])) {
$questSeasonUser = getQuestSeasonUser($user_class->id, $currentQuestSeason['id']);
$questSeasonMissionUser = getQuestSeasonMissionUser($user_class->id, $currentQuestSeason['id']);
$questSeasonMission = getQuestSeasonMission($user_class->id, $currentQuestSeason['id']);
if (isset($questSeasonMission['requirements']['attack_player']) && $questSeasonMission['requirements']['attack_player'] == $attack_person->id) {
updateQuestSeasonMissionUserProgress($questSeasonMissionUser, 'attack_player', $attack_person->id);
}
}
}
if ($yourhp <= 0) {
$winner = $attack_person->id;
$moneywon = floor($user_class->money / rand(8, 9));
$expwon = 100 - (100 * ($attack_person->level - $user_class->level));
$expwon = ($expwon < 20) ? 20 : $expwon;
$expwon = ($expwon > 10000) ? 10000 : $expwon;
$expwon *= (.15 * $attack_person->prestige) + 1;
$expwon *= (.01 * $attack_person->battlemult);
$expwon = floor($expwon);
$expwon2 = $expwon;
$yourhp = 0;
bloodbath('attackslost', $user_class->id);
bloodbath('defendwon', $attack_person->id);
$db->query("UPDATE grpgusers SET todaysexp = todaysexp + ?, exp = exp + ?, money = money + ?, battlewon = battlewon + 1, battlemoney = battlemoney + ?, todayskills = todayskills + 1 WHERE id = ?");
$db->execute(array(
$expwon,
$expwon,
$moneywon,
$moneywon,
$attack_person->id
));
$db->query("UPDATE grpgusers SET money = money - ?, hwho = ?, hhow = 'attacked', hwhen = ?, hospital = 300, battlelost = battlelost + 1, delay = delay + 10, battlemoney = battlemoney - ? WHERE id = ?");
$db->execute(array(
$moneywon,
$attack_person->id,
date("g:i:sa", time()),
$moneywon,
$user_class->id
));
$db->query("UPDATE gangs SET bbattacklost = bbattacklost + 1 WHERE id = ?");
$db->execute(array(
$user_class->gang
));
$db->query("UPDATE pets SET exp = exp + ($expwon) / 10 WHERE userid = ? AND leash = 1");
$db->execute([$attack_person->id]);
$message = $attack_person->formattedname . " won the battle!";
if ($attack_person->gang != 0) {
$db->query("UPDATE gangs SET exp = exp + ? WHERE id = ?");
$db->execute(array(
$expwon,
$attack_person->gang
));
}
}
//$db->query("INSERT INTO attacklog (`timestamp`, attacker, defender, winner, exp, money, active) VALUES (?, ?, ?, ?, ?, ?, ?)");
//$db->execute([time(), $user_class->id, $attack_person->id, $winner, $expwon, $moneywon, (time() - $attack_person->lastactive <= 900) ? 1 : 0]);
$expwon2 = intval($expwon);
if ($attack_person->gang != 0) {
$active = (time() - $attack_person->lastactive < 900) ? 1 : 0;
$db->query("INSERT INTO deflog (timestamp, gangid, attacker, defender, winner, gangexp, active, respect) VALUES (unix_timestamp(), ?, ?, ?, ?, ?, ?, ?)");
$db->execute(array(
$attack_person->gang,
$user_class->id,
$attack_person->id,
$winner,
$expwon2,
$active,
$respect_earnt
));
}
if ($user_class->gang != 0) {
$active = (time() - $attack_person->lastactive < 900) ? 1 : 0;
$db->query("INSERT INTO attlog (timestamp, gangid, attacker, defender, winner, gangexp, active, respect) VALUES (unix_timestamp(), ?, ?, ?, ?, ?, ?, ?)");
$db->execute(array(
$user_class->gang,
$user_class->id,
$attack_person->id,
$winner,
$expwon2,
$active,
$respect_earnt
));
}
$db->query("INSERT INTO attack_v2 (attack_time, attacking_user_id, defending_user_id, winning_user_id, exp, money) VALUES (unix_timestamp(), ?, ?, ?, ?, ?)");
$db->execute(array(
$user_class->id,
$attack_person->id,
$winner,
$expwon2,
$moneywon
));
$lastInsertId = $db->insert_id();
foreach ($rtn as $round) {
$db->query("
INSERT INTO
attack_turn_log (attack_id, attacking_user_id, defending_user_id, is_first_attack, is_hit, is_critical_hit, is_counter_attack, damage, yourhp, theirhp)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$db->execute(array(
$lastInsertId,
$round['attacking_person'],
$round['defending_person'],
$round['is_first_attack'],
$round['is_hit'],
$round['is_critical_hit'],
$round['is_counter_attack'],
$round['damage'],
$round['yourhp'],
$round['theirhp']
));
}
if ($user_class->id == $winner) {
Send_Event($attack_person->id, "[-_USERID_-] attacked you and won! They gained " . prettynum($expwon) . " exp and stole $" . prettynum($moneywon) . ". <a href='view_attack.php?id=" . $lastInsertId . "'>View Result<\/a>", $user_class->id);
} else {
Send_Event($attack_person->id, "[-_USERID_-] attacked you and lost! You gained " . prettynum($expwon) . " exp and stole $" . prettynum($moneywon) . ". <a href='view_attack.php?id=" . $lastInsertId . "'>View Result<\/a>", $user_class->id);
}
$winner_class = new User($winner);
$db->query("SELECT * FROM gangwars WHERE (gang1 = ? OR gang2 = ?) AND (gang1 = ? OR gang2 = ?) AND accepted = 1 LIMIT 1");
$db->execute(array(
$user_class->gang,
$user_class->gang,
$attack_person->gang,
$attack_person->gang
));
if ($winner_class->gang != 0 && $db->num_rows()) {
$row = $db->fetch_row(true);
if (time() < $row['timeending']) {
$active = (time() - $attack_person->lastactive < 900) ? 50 : 10;
$wingang = ($winner_class->gang == $row['gang1']) ? 1 : 2;
$db->query("UPDATE gangwars SET gang{$wingang}score = gang{$wingang}score + ? WHERE warid = ?");
$db->execute(array(
$active,
$row['warid']
));
}
}
$theirhp = ($theirhp > $attack_person->puremaxhp) ? $attack_person->puremaxhp : $theirhp;
$yourhp = ($yourhp > $user_class->puremaxhp) ? $user_class->puremaxhp : $yourhp;
$db->query("UPDATE grpgusers SET hp = ? WHERE id = ?");
$db->execute(array(
$theirhp,
$attack_person->id
));
$db->query("UPDATE `grpgusers` SET `energy` = `energy` - {$energyneeded}, `last_attack_time` = " . time() . " WHERE `id` = {$user_class->id}");
$db->execute();
echo json_encode(success($message));
exit;