forked from SWU-Petranaki/SWUOnline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAllyAbilities.php
More file actions
4097 lines (3936 loc) · 179 KB
/
AllyAbilities.php
File metadata and controls
4097 lines (3936 loc) · 179 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
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require __DIR__ . "/Libraries/LayerHelpers.php";
function CreateCloneTrooper($player, $from = "-") {
return PlayAlly("3941784506", $player, from:$from, playAbility:true); //Clone Trooper
}
function CreateBattleDroid($player, $from = "-") {
return PlayAlly("3463348370", $player, from:$from, playAbility:true); //Battle Droid
}
function CreateXWing($player, $from = "-") {
return PlayAlly("9415311381", $player, from:$from, playAbility:true); //X-Wing
}
function CreateTieFighter($player, $from = "-") {
return PlayAlly("7268926664", $player, from:$from, playAbility:true); //Tie Fighter
}
// This function put an ally into play for a player, which means no when played abilities are triggered.
function PlayAlly($cardID, $player, $subCards = "-", $from = "-",
$owner = null, $cloned = false, $playAbility = false,
$epicAction = false, $turnsInPlay = 0) {
if($from == "TGY") {
$owner = $player == 1 ? 2 : 1;
}
$uniqueID = GetUniqueId();
$allies = &GetAllies($player);
if(count($allies) < AllyPieces()) $allies = [];
$allies[] = $cardID;
$allies[] = AllyEntersPlayState($cardID, $player, $from);
$allies[] = 0; //Damage
$allies[] = 0; //Frozen
$allies[] = $subCards; //Subcards
$allies[] = $uniqueID; //Unique ID
$allies[] = 0;//Counters
$allies[] = 0; //Power
$allies[] = 1; //Ability/effect uses
$allies[] = 0; //Round health modifier
$allies[] = 0; //Times attacked
$allies[] = $owner ?? $player; //Owner
$allies[] = $turnsInPlay; //Turns in play
$allies[] = $cloned ? 1 : 0; //Cloned
$allies[] = 0; //Healed this turn
$allies[] = "NA";//Arena Override
$allies[] = $epicAction ? 1 : 0; //Epic Action
$index = count($allies) - AllyPieces();
CurrentEffectAllyEntersPlay($player, $index);
CheckUniqueCard($cardID, $uniqueID);
if ($playAbility || $cardID == "0345124206") { //Clone - Ensure that the Clone will always choose a unit to clone whenever it enters play.
if(HasShielded($cardID, $player, $index)) {
AddLayer("TRIGGER", $player, "SHIELDED", "-", "-", $uniqueID);
}
if(HasAmbush($cardID, $player, $index, $from)) {
AddLayer("TRIGGER", $player, "AMBUSH", "-", "-", $uniqueID);
}
PlayAbility($cardID, $from, 0, uniqueId:$uniqueID);
}
// Check if any units will be destroyed due to cascading effects
CheckHealthAllAllies();
return $uniqueID;
}
function DefeatUpgradeForUniqueID($subcardUniqueID, $player = "") {
$initialPlayer = ($player == 1 || $player == 2) ? $player : 1;
$players = [$initialPlayer, ($initialPlayer % 2) + 1];
foreach ($players as $p) {
$allies = &GetAllies($p);
for ($i = 0; $i < count($allies); $i += AllyPieces()) {
$allySubcardsDelimited = $allies[$i + 4];
if ($allySubcardsDelimited == null || $allySubcardsDelimited == "" || $allySubcardsDelimited == "-") {
continue;
}
$allySubcards = explode(",", $allySubcardsDelimited);
for ($j = 0; $j < count($allySubcards); $j += SubcardPieces()) {
if ($allySubcards[$j + 3] == $subcardUniqueID) {
$ally = new Ally("MYALLY-" . $i, $p);
$ally->DefeatUpgrade($allySubcards[$j], $subcardUniqueID);
break;
}
}
}
}
}
function CheckHealthAllAllies() {
foreach ([1, 2] as $player) {
$allies = &GetAllies($player);
for ($i = 0; $i < count($allies); $i += AllyPieces()) {
$ally = new Ally("MYALLY-" . $i, $player);
$defeated = $ally->DefeatIfNoRemainingHP();
// If an ally was defeated, we don't need to check the rest of the allies because the DefeatAlly function will call this function again.
if ($defeated) {
break;
}
}
}
}
// Returns true if there is more than one unique unit in play, false otherwise.
function CheckUniqueCard($cardID, $allyUniqueID, $reportMode = false) {
$uniqueAllyInPlay = null;
$playedUniqueID = null;
$ally = new Ally($allyUniqueID);
if (!$ally->Exists()) return false;
if (!CardIsUnique($cardID)) return false;
// Get the player that controls the unique card
if ($cardID == $ally->CardID()) {
$player = $ally->Controller();
$playedUniqueID = $ally->UniqueID();
// Cloned units are not unique
if ($ally->IsCloned()) return false;
} else {
$subcard = $ally->GetSubcardForCard($cardID);
if ($subcard != null) {
$player = $subcard->Owner(); // TODO: we should check for controller instead of owner
$playedUniqueID = $subcard->UniqueID();
} else {
return false;
}
}
// Check if there are any other unique cards in play
for ($p = 1; $p <= 2; $p++) {
$allies = &GetAllies($p);
for ($i = 0; $i < count($allies); $i += AllyPieces()) {
$otherAlly = new Ally("MYALLY-" . $i, $p);
if ($otherAlly->CardID() == $cardID && !$otherAlly->IsCloned() && $otherAlly->Controller() == $player && $otherAlly->UniqueID() != $playedUniqueID) {
$uniqueAllyInPlay = $otherAlly;
break;
} else { //check for upgrades/pilots
$subcards = $otherAlly->GetSubcards();
for ($j = 0; $j < count($subcards); $j+=SubcardPieces()) {
$subcard = new SubCard($otherAlly, $j);
if ($subcard->IsCaptive()) continue; // Ignore captives
if ($subcard->CardID() == $cardID && $subcard->Owner() == $player && $subcard->UniqueID() != $playedUniqueID) {
$uniqueAllyInPlay = $otherAlly;
break;
}
}
if ($uniqueAllyInPlay != null) break;
}
}
}
if (!$reportMode && $uniqueAllyInPlay != null) {
PrependDecisionQueue("MZOP", $player, "DESTROYUNIQUECARD," . $cardID, 1);
PrependDecisionQueue("CHOOSEMULTIZONE", $player, "<-", 1);
PrependDecisionQueue("SETDQCONTEXT", $player, "You have two of this unique card; choose one to destroy", 1);
PrependDecisionQueue("UIDOP", $player, "GETMZINDEX", 1);
PrependDecisionQueue("PASSPARAMETER", $player, $ally->UniqueID() . "," . $uniqueAllyInPlay->UniqueID(), 1);
PrependDecisionQueue("NOPASS", $player, "-");
// Double check that there is more than one unique unit in play, in case any were defeated during the resolution.
PrependDecisionQueue("MZOP", $player, "CHECKUNIQUECARD");
PrependDecisionQueue("PASSPARAMETER", $player, $cardID . "," . $allyUniqueID);
}
return $uniqueAllyInPlay != null;
}
function LeaderAbilitiesIgnored() {
return AnyPlayerHasAlly("4602353389");//Brain Invaders
}
function HasWhenEnemyDestroyed($cardID, $uniqueID, $numUses, $wasUnique, $wasUpgraded) {
switch($cardID) {
case "1664771721"://Gideon Hask
case "b0dbca5c05"://Iden Versio Leader Unit
case "2407397504"://HK-47
return true;
case "2649829005"://Agent Kallus
return $wasUnique && $numUses > 0 && $uniqueID != $destroyedUniqueID;
case "8687233791"://Punishing One
$ally = new Ally($uniqueID);
return $ally->IsExhausted() && $wasUpgraded && $numUses > 0;
default: return false;
}
}
function HasWhenFriendlyDestroyed($player, $cardID, $numUses, $uniqueID,
$destroyedCardID, $destroyedUniqueID, $destroyedWasUnique, $destroyedWasUpgraded) {
switch($cardID) {
case "2649829005"://Agent Kallus //goes hand-in-hand with the enemy destroyed ability
return $numUses > 0 && $destroyedWasUnique && $uniqueID != $destroyedUniqueID;
case "9353672706"://General Krell
return $uniqueID != $destroyedUniqueID;
case "3feee05e13"://Gar Saxon Leader Unit
return !LeaderAbilitiesIgnored() && $destroyedWasUpgraded;
case "f05184bd91"://Nala Se Leader Unit
return !LeaderAbilitiesIgnored() && TraitContains($destroyedCardID, "Clone", $player) || IsCloned($destroyedUniqueID);
case "1039828081"://Calculating MagnaGuard
if(SearchCurrentTurnEffects("1039828081", $player)) return false;
return $uniqueID != $destroyedUniqueID;//while not specifically stated, it is implied that it will not be the destroyed unit
default: return false;
}
}
function AllyIsMultiAttacker($cardID) {
switch($cardID) {
case "8613680163"://Darth Maul (Revenge At Last)
return true;
default:
return false;
}
}
function AllyHasStaticHealthModifier($cardID)
{
switch($cardID)
{
case "1557302740"://General Veers
case "9799982630"://General Dodonna
case "3666212779"://Captain Tarkin
case "4339330745"://Wedge Antilles
case "4511413808"://Follower of the Way
case "3731235174"://Supreme Leader Snoke
case "8418001763"://Huyang
case "6097248635"://4-LOM
case "1690726274"://Zuckuss
case "2260777958"://41st Elite Corps
case "2265363405"://Echo
case "1209133362"://332nd Stalwart
case "47557288d6"://Captain Rex
case "0268657344"://Admiral Yularen
case "4718895864"://Padawan Starfighter
case "9017877021"://Clone Commander Cody
case "9811031405"://Victor Leader
case "5052103576"://Resistance X-Wing
case "3213928129"://Clone Combat Squadron
case "6931439330"://The Ghost SOR (with Phantom II)
case "5763330426"://The Ghost JTL (with Phantom II)
case "fadc48bab2"://Kanan Jarrus (LOF) Leader unit
return true;
default: return false;
}
}
function AllyStaticHealthModifier($cardID, $index, $player, $myCardID, $myIndex, $myPlayer)
{
$ally = new Ally("MYALLY-" . $index, $player);
if (!$ally->Exists() || $ally->LostAbilities()) {
return 0;
}
$eachOtherFriendly = $index != $myIndex && $player == $myPlayer;
$eachEnemy = $player != $myPlayer;
$self = $index == $myIndex && $player == $myPlayer;
switch($myCardID)
{
case "1557302740"://General Veers
if($eachOtherFriendly && TraitContains($cardID, "Imperial", $player)) return 1;
break;
case "9799982630"://General Dodonna
if($eachOtherFriendly && TraitContains($cardID, "Rebel", $player)) return 1;
break;
case "4339330745"://Wedge Antilles
if($eachOtherFriendly && TraitContains($cardID, "Vehicle", $player)) return 1;
break;
case "4511413808"://Follower of the Way
if($self && $ally->IsUpgraded()) return 1;
break;
case "2260777958"://41st Elite Corps
if($self && IsCoordinateActive($player)) return 3;
break;
case "2265363405"://Echo
if($self && IsCoordinateActive($player)) return 2;
break;
case "1209133362"://332nd Stalwart
if($self && IsCoordinateActive($player)) return 1;
break;
case "4718895864"://Padawan Starfighter
if($self && SearchCount(SearchAllies($player, trait:"Force"))) return 1;
else if($self && SearchCount(SearchUpgrades($player, trait:"Force"))) return 1;
break;
case "3213928129"://Clone Combat Squadron
if($self) return SearchCount(SearchAllies($player, arena:"Space")) - 1;
break;
case "3731235174"://Supreme Leader Snoke
if($eachEnemy) return !$ally->IsLeader() ? -2 : 0;
break;
case "8418001763"://Huyang
if ($player == $myPlayer)
return SearchLimitedCurrentTurnEffects($myCardID, $player) == $ally->UniqueID() ? 2 : 0;
return 0;
case "6097248635"://4-LOM
return ($player == $myPlayer && CardTitle($cardID) == "Zuckuss") ? 1 : 0;
case "1690726274"://Zuckuss
return ($player == $myPlayer && CardTitle($cardID) == "4-LOM") ? 1 : 0;
case "47557288d6"://Captain Rex
if($eachOtherFriendly && TraitContains($cardID, "Trooper", $player)) return 1;
break;
case "0268657344"://Admiral Yularen
if($eachOtherFriendly && AspectContains($cardID, "Heroism", $player)) return 1;
break;
case "9017877021"://Clone Commander Cody
if($eachOtherFriendly && IsCoordinateActive($player)) return 1;
break;
case "9811031405"://Victor Leader
if($eachOtherFriendly && CardArenas($cardID) == "Space") return 1;
break;
case "5052103576"://Resistance X-Wing
if($self && $ally->HasPilot()) return 1;
break;
//The Ghost with Phantom II
case "6931439330"://The Ghost SOR
case "5763330426"://The Ghost JTL
return $index == $myIndex && $ally->HasUpgrade("5306772000") ? 3 : 0;
//Legends of the Force
case "fadc48bab2"://Kanan Jarrus Leader unit
//right now nothing gives the Creature trait like Foundling gives Mandalorian.
//but if something does, then update this logic to check he's not a Creature himself..
$atLeastOneCreature = SearchCount(SearchAllies($player, trait:"Creature")) > 0;
$atLeastAnotherSpectre = SearchCount(SearchAllies($player, trait:"Spectre")) > 1;
if($self && ($atLeastOneCreature || $atLeastAnotherSpectre)) return 2;
break;
default: break;
}
return 0;
}
// Modifiers Based on Name, whether Ally or Leader
function NameBasedHealthModifiers($cardID, $index, $player, $stackingBuff = false) {
$modifier = 0;
$foundBuff = false;
$char = &GetPlayerCharacter($player);
for($i=0; $i<count($char); $i+=CharacterPieces()) {
switch($char[$i])
{
case "5784497124"://Emperor Palpatine
if($cardID == "1780978508") {
$modifier += 1;//Emperor's Royal Guard
$foundBuff = true;
}
break;
default: break;
}
}
if($foundBuff && !$stackingBuff) return $modifier;
$allies = GetAllies($player);
for($i=count($allies)-AllyPieces(); $i>=0; $i-=AllyPieces()) {
if($foundBuff && !$stackingBuff) break;
switch($allies[$i]) {
case "9097316363"://Emperor Palpatine (Master of the Dark Side)
case "6c5b96c7ef"://Emperor Palpatine (Deployed Leader Unit)
if($cardID == "1780978508") { //Emperor's Royal Guard
$foundBuff = true;
$modifier += 1;
}
break;
}
}
return $modifier;
}
// Modifiers from Base
function BaseHealthModifiers($cardID, $index, $player, $stackingBuff = false) {
$modifier = 0;
$char = &GetPlayerCharacter($player);
switch($char[0]) {
case "6594935791"://Pau City
$ally = new Ally("MYALLY-" . $index, $player);
$modifier += $ally->IsLeader() ? 1 : 0;
break;
default: break;
}
return $modifier;
}
// Health update: Leaving this for now. Not sure it is used and may be removed in a more
// comprehensive cleanup to ensure everything is going through the ally class method.
function DealAllyDamage($targetPlayer, $index, $damage, $type="")
{
$allies = &GetAllies($targetPlayer);
$allies[$index+2] -= $damage;
if($allies[$index+2] <= 0) DestroyAlly($targetPlayer, $index, fromCombat: $type == "COMBAT");
}
function RemoveAlly($player, $index, $removedFromPlay = true)
{
return DestroyAlly($player, $index, true, removedFromPlay: $removedFromPlay);
}
function GivesWhenDestroyedToAllies($cardID) {
switch($cardID) {
case "9353672706"://General Krell gives "When Defeated" to others
case "3feee05e13"://Gar Saxon Leader Unit gives "When Defeated" to himself and others
case "f05184bd91"://Nala Se Leader Unit gives "When Defeated" to others that are Clone traits
return true;
default: return false;
}
}
function DestroyAlly($player, $index,
$skipDestroy = false, $fromCombat = false, $skipRescue = false,
$removedFromPlay = true, $skipSpecialCase = false)
{
global $mainPlayer, $combatChainState, $CS_AlliesDestroyed, $CS_NumAlliesDestroyed, $CS_NumLeftPlay, $CCS_CachedLastDestroyed, $CS_NumEventsPlayed;
$allies = &GetAllies($player);
$ally = new Ally("MYALLY-" . $index, $player);
$cardID = $ally->CardID();
$owner = $ally->Owner();
$controller = $ally->Controller();
$uniqueID = $ally->UniqueID();
$lostAbilities = $ally->LostAbilities();
$isUpgraded = $ally->IsUpgraded();
$upgrades = $ally->GetUpgrades();
$upgradesWithOwnerData = $ally->GetUpgrades(true);
$isExhausted = $ally->IsExhausted();
$hasBounty = $ally->HasBounty();
$lastPower = $ally->CurrentPower();
$lastRemainingHP = $ally->Health();
$isSuperlaserTech = $cardID === "8954587682";
$isL337JTL = $cardID == "6032641503";
$discardPileModifier = "-";
if(!$skipDestroy && !$isL337JTL || $skipSpecialCase) {
OnKillAbility($player, $uniqueID);
$whenDestroyData="";$whenResourceData="";$whenBountiedData="";
$shouldLayerDestroyTriggers = (HasWhenDestroyed($cardID) && !$isSuperlaserTech && !GivesWhenDestroyedToAllies($cardID))
|| UpgradesContainWhenDefeated($upgrades)
|| CurrentEffectsContainWhenDefeated($player, $uniqueID);
if(!$lostAbilities && $shouldLayerDestroyTriggers)
$whenDestroyData=SerializeAllyDestroyData($uniqueID,$lostAbilities,$isUpgraded,$upgrades,$upgradesWithOwnerData,$lastPower,$lastRemainingHP,$owner);
if($isSuperlaserTech && !$lostAbilities)
$whenResourceData=SerializeResourceData("PLAY","DOWN",0,"0","-1");
if(!$lostAbilities && ($hasBounty || UpgradesContainBounty($upgrades)))
$whenBountiedData=SerializeBountiesData($uniqueID, $isExhausted, $owner, $upgrades);
if($ally->IsSpectreWithGhostBounty()) {
//The Ghost JTL
$theGhostIndex = SearchAlliesForCard($player, "5763330426");
$theGhost = new Ally("MYALLY-" . $theGhostIndex, $player);
$whenBountiedData=SerializeBountiesData($theGhost->UniqueID(), $theGhost->IsExhausted(), $theGhost->Owner(), $theGhost->GetUpgrades());
}
if($whenDestroyData || $whenResourceData || $whenBountiedData)
LayerDestroyTriggers($player, $cardID, $uniqueID, $whenDestroyData, $whenResourceData, $whenBountiedData);
$wasUnique = CardIsUnique($cardID);
$triggers = GetAllyWhenDestroyFriendlyEffects($player, $cardID, $uniqueID, $wasUnique, $isUpgraded, $upgradesWithOwnerData);
if(count($triggers) > 0) {
LayerFriendlyDestroyedTriggers($player, $triggers);
}
if($mainPlayer != $player && !$ally->LostAbilities() && GetAttackTarget() == "THEIRALLY-" . $ally->Index()) {
$combatChainState[$CCS_CachedLastDestroyed] = $ally->Serialize();
}
$otherPlayer = $player == 1 ? 2 : 1;
$triggers = GetAllyWhenDestroyTheirsEffects($mainPlayer, $otherPlayer, $uniqueID, $wasUnique, $isUpgraded, $upgradesWithOwnerData);
if(count($triggers) > 0) {
LayerTheirsDestroyedTriggers($player, $triggers);
}
IncrementClassState($player, $CS_NumAlliesDestroyed);
AppendClassState($player, $CS_AlliesDestroyed, $cardID);
} else if (!$skipDestroy && $isL337JTL && !$skipSpecialCase) {
if(SearchCount(SearchAllies($player, trait:"Vehicle")) > 0) {
AddLayer("TRIGGER", $player, $cardID, $uniqueID);
} else {
DestroyAlly($player, $index, skipSpecialCase:true);
}
return;
}
if($removedFromPlay) {
IncrementClassState($player, $CS_NumLeftPlay);
AllyLeavesPlayAbility($player, $index);
}
// Discard upgrades
for($i=0; $i<count($upgradesWithOwnerData); $i+=SubcardPieces()) {
if($upgradesWithOwnerData[$i] == "8752877738" || $upgradesWithOwnerData[$i] == "2007868442") continue; // Skip Shield and Experience tokens
if($upgradesWithOwnerData[$i] == "6911505367") $discardPileModifier = "TTFREE";//Second Chance
if($upgradesWithOwnerData[$i] == "5942811090") {//Luke Skywalker (You Still With Me?)
$controller = $upgradesWithOwnerData[$i+6];
$cardID = $upgradesWithOwnerData[$i];
$turnsInPlay = $upgradesWithOwnerData[$i+5];
AddLayer("TRIGGER", $controller, $cardID, $turnsInPlay); // We're adding a trigger to prevent bugs with A New Adventure, which clears the DQ after playing the card.
}
if(!CardIdIsLeader($upgradesWithOwnerData[$i]))
AddGraveyard($upgradesWithOwnerData[$i], $upgradesWithOwnerData[$i+1], "PLAY");
}
$captives = $ally->GetCaptives(true);
// Discard the ally
if(!$skipDestroy) {
if(DefinedTypesContains($cardID, "Leader", $player)) ;//If it's a leader it doesn't go in the discard
else if(isToken($cardID)) ; // If it's a token, it doesn't go in the discard
else if($isSuperlaserTech) ; //SLT is auto-added to resources
else {
$graveyardCardID = $ally->IsCloned() ? "0345124206" : $cardID; //Clone - Replace the cloned card with the original one in the graveyard
if($cardID == "6272475624" && !$ally->LostAbilities()) {//Stolen AT Hauler
$discardPileModifier = $owner == $controller ? "TTOPFREE" : "TTFREE";
}
AddGraveyard($graveyardCardID, $owner, "PLAY", $discardPileModifier);
}
}
// Remove the ally from the allies array
for($j = $index + AllyPieces() - 1; $j >= $index; --$j) unset($allies[$j]);
$allies = array_values($allies);
if(!$skipRescue) {
for($i=0; $i<count($captives); $i+=SubcardPieces()) {
$otherPlayer = $owner;
if($captives[$i] == "3401690666" && GetClassState($otherPlayer, $CS_NumEventsPlayed) == 0 ) AddCurrentTurnEffect("3401690666", $otherPlayer, from:"PLAY"); // Relentless
PlayAlly($captives[$i], $captives[$i+1], from:"CAPTIVE");
}
}
// Check if any units will be destroyed due to cascading effects (e.g. Coordinate)
CheckHealthAllAllies();
if($player == $mainPlayer) UpdateAttacker();
else UpdateAttackTarget();
return $cardID;
}
function CurrentEffectsContainWhenDefeated($player, $uniqueID) {
global $currentTurnEffects;
for($i=0;$i<count($currentTurnEffects); $i+=CurrentTurnEffectPieces()) {
if ($currentTurnEffects[$i+1] != $player) continue;
if ($currentTurnEffects[$i+2] != -1 && $currentTurnEffects[$i+2] != $uniqueID) continue;
switch($currentTurnEffects[$i]) {
case "1272825113"://In Defense of Kamino
case "9415708584": //Pyrrhic Assault
return true;
default: return false;
}
}
}
function UpgradesContainWhenDefeated($upgrades) {
for($i=0;$i<count($upgrades);++$i) {
if (HasWhenDestroyed($upgrades[$i])) return true;
}
return false;
}
function UpgradesContainBounty($upgrades) {
for($i=0;$i<count($upgrades);++$i) {
switch($upgrades[$i]) {
case "2178538979"://Price on Your Head
case "2740761445"://Guild Target
case "4282425335"://Top Target
case "3074091930"://Rich Reward
case "1780014071"://Public Enemy
case "9642863632"://Bounty Hunter's Quarry
case "0807120264"://Death Mark
case "4117365450"://Wanted
case "6420322033"://Enticing Reward
case "7270736993"://Unrefusable Offer
return true;
}
}
return false;
}
function AllyTakeControl($player, $uniqueID) {
global $currentTurnEffects, $CS_NumEventsPlayed;
if ($uniqueID == "" || $uniqueID == -1) return -1;
$otherPlayer = $player == 1 ? 2 : 1;
$ally = new Ally($uniqueID, $otherPlayer);
if (!$ally->Exists()) return -1;
if($ally->IsLeader()) {
$ally->Destroy();
return $uniqueID;
}
$allyIndex = $ally->Index();
$allyController = $ally->Controller();
$allyCardID = $ally->CardID();
if($allyCardID == "3401690666" && GetClassState($otherPlayer, $CS_NumEventsPlayed) == 0 ) AddCurrentTurnEffect("3401690666", $otherPlayer, from:"PLAY"); // Relentless
// Return if the ally is already controlled by the player
if ($allyController == $player) {
return $uniqueID;
}
$myAllies = &GetAllies($player);
$theirAllies = &GetAllies($otherPlayer);
// Swap current turn effects
for($i=0; $i<count($currentTurnEffects); $i+=CurrentTurnEffectPieces()) {
if($currentTurnEffects[$i+2] == -1 || $currentTurnEffects[$i+2] != $uniqueID) continue;
$effectCardID = explode("_", $currentTurnEffects[$i])[0];
// Skip the swap for specific cards
$skipSwap = false;
switch($effectCardID) {
case "3503494534"://Regional Governor
case "7964782056"://Qi'Ra unit
case "3148212344"://Admiral Yularen JTL
$skipSwap = true;
break;
default: break;
}
if ($skipSwap) continue;
$currentTurnEffects[$i+1] = $currentTurnEffects[$i+1] == 1 ? 2 : 1; // Swap players
}
// Swap ally
for ($i = $allyIndex; $i < $allyIndex + AllyPieces(); $i++) {
$myAllies[] = $theirAllies[$i];
}
for ($i= $allyIndex + AllyPieces() - 1; $i >= $allyIndex; $i--) {
unset($theirAllies[$i]);
}
$theirAllies = array_values($theirAllies); // Reindex the array
CheckHealthAllAllies();
// Check if the ally is unique and its subcards are unique
$newAlly = new Ally($uniqueID, $player);
CheckUniqueCard($newAlly->CardID(), $newAlly->UniqueID());
$subcards = $newAlly->GetSubcards();
for ($i = 0; $i < count($subcards); $i += SubcardPieces()) {
$subcard = new SubCard($newAlly, $i);
CheckUniqueCard($subcard->CardID(), $newAlly->UniqueID());
}
return $uniqueID;
}
function AllyAddGraveyard($player, $cardID, $subtype)
{
if(CardType($cardID) != "T") {
$set = substr($cardID, 0, 3);
$number = intval(substr($cardID, 3, 3));
$number -= 400;
if($number < 0) return;
$id = $number;
if($number < 100) $id = "0" . $id;
if($number < 10) $id = "0" . $id;
$id = $set . $id;
if(!SubtypeContains($id, $subtype, $player)) return;
AddGraveyard($id, $player, "PLAY");
}
}
function AllyEntersPlayState($cardID, $player, $from="-")
{
if(DefinedTypesContains($cardID, "Leader", $player)) return 2;
if(IsToken($cardID) && SearchAlliesForCard($player, "0038286155") != "") return 2;//Chancellor Palpatine
switch($cardID)
{
case "1785627279": return 2;//Millennium Falcon
default: return 1;
}
}
function AllyPlayableExhausted(Ally $ally) {
$playable = false;
$cardID = $ally->CardID();
switch($cardID) {
case "5630404651"://MagnaGuard Wing Leader
case "040a3e81f3"://Lando Leader Unit
return $ally->NumUses() > 0;
case "5306772000"://Phantom II
return NumResourcesAvailable($ally->PlayerID()) > 0;
case "4300219753"://Fett's Firespray
case "7144880397"://Ahsoka Tano TWI
case "2471223947"://Frontline Shuttle
case "1885628519"://Crosshair
case "2b13cefced"://Fennec Shand Leader Unit
case "a742dea1f1"://Han Solo Red Leader Unit
return true;
default: break;
}
if($ally->IsUpgraded()) {
$playable = $playable || CheckForUpgradesPlayableExhausted($ally);
}
return $playable;
}
function TheirAllyPlayableExhausted(Ally $ally) {
$playable = false;
$cardID = $ally->CardID();
switch($cardID) {
case "3577961001"://Mercenary Gunship
return true;
default: break;
}
if($ally->IsUpgraded()) {
$playable = $playable || CheckForUpgradesPlayableExhausted($ally);
}
return $playable;
}
function CheckForUpgradesPlayableExhausted(Ally $ally, $theirCard=false) {
global $currentPlayer, $CS_NumUsesLeaderUpgrade1, $CS_NumUsesLeaderUpgrade2;
$otherPlayer = $currentPlayer == 1 ? 2 : 1;
$playableBy = $theirCard ? $otherPlayer : $currentPlayer;
if($ally->IsUpgraded()) {
$upgrades = $ally->GetUpgrades(withMetadata:true);
for($i=0; $i<count($upgrades); $i+=SubcardPieces()) {
switch($upgrades[$i]) {
case "3eb545eb4b"://Poe Dameron JTL leader
return $upgrades[$i+1] == $playableBy && GetClassState($playableBy, $CS_NumUsesLeaderUpgrade1) > 0;
default: break;
}
}
}
return false;
}
function AllyDoesAbilityExhaust($cardID) {
global $currentPlayer;
$abilityName = GetResolvedAbilityName($cardID);
if($abilityName == "Poe Pilot") return false;
switch($cardID) {
case "5630404651"://MagnaGuard Wing Leader
return $abilityName != "Droid Attack";
case "4300219753"://Fett's Firespray
return $abilityName != "Exhaust";
case "7144880397"://Ahsoka Tano TWI
return $abilityName != "Return";
case "2471223947"://Frontline Shuttle
return $abilityName != "Shuttle";
case "1885628519"://Crosshair
return $abilityName != "Buff";
case "040a3e81f3"://Lando Leader Unit
return $abilityName != "Smuggle";
case "2b13cefced"://Fennec Shand Leader Unit
return $abilityName != "Ambush";
case "a742dea1f1"://Han Solo Red Leader Unit
return $abilityName != "Play";
case "5306772000"://Phantom II
return $abilityName != "Dock";
default: break;
}
return true;
}
function TheirAllyDoesAbilityExhaust($cardID) {
$abilityName = GetResolvedAbilityName($cardID);
if($abilityName == "Poe Pilot") return false;
switch($cardID) {
case "3577961001"://Mercenary Gunship
return $abilityName != "Take Control";
default: return true;
}
}
function AllyHealth($cardID, $playerID="")
{
$health = CardHP($cardID);
switch($cardID)
{
case "7648077180"://97th Legion
$health += NumResources($playerID);
break;
default: break;
}
return $health;
}
function AllyLeavesPlayAbility($player, $index)
{
global $CS_CachedLeader1EpicAction, $CS_CachedLeader2EpicAction;
$cachedEpicAction1 = GetClassState($player, $CS_CachedLeader1EpicAction) == 1;
$ally = new Ally("MYALLY-" . $index, $player);
$leaderUndeployed = LeaderUndeployed($ally->CardID());
if($leaderUndeployed != "") {
$usedEpicAction = $ally->FromEpicAction() || $cachedEpicAction1;
AddCharacter($leaderUndeployed, $ally->Owner(), counters:$usedEpicAction ? 1 : 0, status:1);
}
//Pilot leader upgrades
$subcardsArr = $ally->GetSubcards();
for($i=0;$i<count($subcardsArr);$i+=SubcardPieces()) {
$subcard = new SubCard($ally, $i);
if(CardIDIsLeader($subcard->CardID())) {
$leaderUndeployed = LeaderUndeployed($subcard->CardID());
if($leaderUndeployed != "") {
$cachedEpicAction1 = GetClassState($subcard->Owner(), $CS_CachedLeader1EpicAction) == 1;
$usedEpicAction = $subcard->FromEpicAction() || $cachedEpicAction1;
AddCharacter($leaderUndeployed, $subcard->Owner(), counters:$usedEpicAction ? 1 : 0, status:1);
}
}
}
$owner = $ally->Owner();
$notOwner = $owner == 1 ? 2 : 1;
switch($ally->CardID())
{
case "3401690666"://Relentless
$otherPlayer = ($player == 1 ? 2 : 1);
SearchCurrentTurnEffects("3401690666", $otherPlayer, remove:true);
break;
case "8418001763"://Huyang
SearchCurrentTurnEffects("8418001763", $owner, remove:true);
break;
case "7964782056"://Qi'Ra unit
$otherPlayer = $player == 1 ? 2 : 1;
SearchLimitedCurrentTurnEffects("7964782056", $notOwner, uniqueID:$ally->UniqueID(), remove:true);
break;
case "3503494534"://Regional Governor
$otherPlayer = $player == 1 ? 2 : 1;
SearchLimitedCurrentTurnEffects("3503494534", $notOwner, uniqueID:$ally->UniqueID(), remove:true);
break;
case "4002861992"://DJ (Blatant Thief)
$djAlly = new Ally("MYALLY-" . $index, $player);
$resourceFound = false;
for ($p = 1; $p <= 2; $p++) { // Iterate over both players (useful when DJ changes sides)
$arsenal = &GetArsenal($p);
for ($i = 0; $i < count($arsenal); $i += ArsenalPieces()) {
if ($arsenal[$i + 6] == $djAlly->UniqueID()) {
$otherPlayer = $p == 1 ? 2 : 1;
$isExhausted = $arsenal[$i + 4];
$resourceCard = RemoveResource($p, $i);
AddResources($resourceCard, $otherPlayer, "PLAY", "DOWN", isExhausted:$isExhausted);
$resourceFound = true;
break;
}
}
if ($resourceFound) break;
}
break;
case "3148212344"://Admiral Yularen JTL
SearchCurrentTurnEffects("3148212344", $owner, remove:true, startsWith:true);
break;
default: break;
}
//Opponent character abilities
$otherPlayer = ($player == 1 ? 2 : 1);
$char = &GetPlayerCharacter($otherPlayer);
for($i=0; $i<count($char); $i+=CharacterPieces())
{
switch($char[$i])
{
case "4626028465"://Boba Fett Leader
if($char[$i+1] == 2 && NumResourcesAvailable($otherPlayer) < NumResources($otherPlayer)) {
$char[$i+1] = 1;
ReadyResource($otherPlayer);
}
break;
default: break;
}
}
}
function AllyDestroyedAbility($player, $cardID, $uniqueID, $lostAbilities, $isUpgraded, $upgrades, $upgradesWithOwnerData, $lastPower, $lastRemainingHp, $owner)
{
global $initiativePlayer, $currentTurnEffects;
if (!$lostAbilities) {
$otherPlayer = $player == 1 ? 2 : 1;
switch($cardID) {
case "4405415770"://Yoda (Old Master)
AddDecisionQueue("SETDQCONTEXT", $player, "Choose player to draw 1 card");
AddDecisionQueue("BUTTONINPUT", $player, "Yourself,Opponent,Both");
AddDecisionQueue("SPECIFICCARD", $player, "YODAOLDMASTER", 1);
break;
case "8429598559"://Black One
BlackOne($player);
break;
case "9996676854"://Admiral Motti
AddDecisionQueue("MULTIZONEINDICES", $player, "MYALLY:aspect=Villainy");
AddDecisionQueue("SETDQCONTEXT", $player, "Choose a unit to ready");
AddDecisionQueue("MAYCHOOSEMULTIZONE", $player, "<-", 1);
AddDecisionQueue("MZOP", $player, "READY", 1);
break;
case "7517208605"://Star Wing Scout
if($player == $initiativePlayer) { Draw($player); Draw($player); }
break;
case "5575681343"://Vanguard Infantry
AddDecisionQueue("MULTIZONEINDICES", $player, "MYALLY&THEIRALLY");
AddDecisionQueue("SETDQCONTEXT", $player, "Choose a unit to add an experience");
AddDecisionQueue("MAYCHOOSEMULTIZONE", $player, "<-", 1);
AddDecisionQueue("MZOP", $player, "ADDEXPERIENCE", 1);
break;
case "9133080458"://Inferno Four
PlayerOpt($player, 2);
break;
case "1047592361"://Ruthless Raider
DealDamageAsync($otherPlayer, 2, "DAMAGE", "1047592361", sourcePlayer:$player);
AddDecisionQueue("MULTIZONEINDICES", $player, "THEIRALLY");
AddDecisionQueue("SETDQCONTEXT", $player, "Choose a unit to deal 2 damage to");
AddDecisionQueue("CHOOSEMULTIZONE", $player, "<-", 1);
AddDecisionQueue("MZOP", $player, "DEALDAMAGE,2,$player,1", 1);
break;
case "0949648290"://Greedo
$deck = &GetDeck($player);
if(count($deck) > 0) {
AddDecisionQueue("SETDQCONTEXT", $player, "Choose if you want to discard a card to Greedo");
AddDecisionQueue("YESNO", $player, "-");
AddDecisionQueue("NOPASS", $player, "-");
AddDecisionQueue("PASSPARAMETER", $player, "1", 1);
AddDecisionQueue("OP", $player, "MILL", 1);
AddDecisionQueue("NONECARDDEFINEDTYPEORPASS", $player, "Unit", 1);
AddDecisionQueue("MULTIZONEINDICES", $player, "MYALLY:arena=Ground&THEIRALLY:arena=Ground", 1);
AddDecisionQueue("SETDQCONTEXT", $player, "Choose a unit to deal 2 damage");
AddDecisionQueue("MAYCHOOSEMULTIZONE", $player, "<-", 1);
AddDecisionQueue("MZOP", $player, "DEALDAMAGE,2,$player,1", 1);
}
break;
case "3232845719"://K-2SO
$options = "Deal 3 damage to opponent's base;Opponent discards a card from their hand";
AddDecisionQueue("SETDQCONTEXT", $player, "Choose one");
AddDecisionQueue("CHOOSEOPTION", $player, "$cardID&$options");
AddDecisionQueue("SHOWOPTIONS", $player, "$cardID&$options");
AddDecisionQueue("MODAL", $player, "K2SO");
break;
case "8333567388"://Distant Patroller
AddDecisionQueue("SETDQCONTEXT", $player, "Choose a unit to give a shield");
AddDecisionQueue("MULTIZONEINDICES", $player, "MYALLY:aspect=Vigilance");
AddDecisionQueue("MAYCHOOSEMULTIZONE", $player, "<-", 1);
AddDecisionQueue("MZOP", $player, "ADDSHIELD", 1);
break;
case "4786320542"://Obi-Wan Kenobi
AddDecisionQueue("MULTIZONEINDICES", $player, "MYALLY");
AddDecisionQueue("SETDQCONTEXT", $player, "Choose a unit to add two experience");
AddDecisionQueue("MAYCHOOSEMULTIZONE", $player, "<-", 1);
AddDecisionQueue("MZOP", $player, "ADDEXPERIENCE", 1);
AddDecisionQueue("MZOP", $player, "ADDEXPERIENCE", 1);
AddDecisionQueue("SPECIFICCARD", $player, "OBIWANKENOBI", 1);
break;
case "8582806124"://The Annihilator JTL
TheAnnihilatorJTL($player);
break;
case "5184505570"://Chimaera JTL
CreateTieFighter($player);
CreateTieFighter($player);
break;
case "0474909987"://Val
AddDecisionQueue("MULTIZONEINDICES", $player, "MYALLY");
AddDecisionQueue("SETDQCONTEXT", $player, "Choose a unit to add two experience");
AddDecisionQueue("MAYCHOOSEMULTIZONE", $player, "<-", 1);
AddDecisionQueue("MZOP", $player, "ADDEXPERIENCE", 1);
AddDecisionQueue("MZOP", $player, "ADDEXPERIENCE", 1);
break;
case "7351946067"://Rhokai Gunship
AddDecisionQueue("MULTIZONEINDICES", $player, "MYALLY&THEIRALLY");
AddDecisionQueue("PREPENDLASTRESULT", $player, "MYCHAR-0,THEIRCHAR-0,");
AddDecisionQueue("SETDQCONTEXT", $player, "Choose something to deal 1 damage to");
AddDecisionQueue("CHOOSEMULTIZONE", $player, "<-", 1);
AddDecisionQueue("MZOP", $player, "DEALDAMAGE,1,$player,1" , 1);
break;
case "9151673075"://Cobb Vanth
AddDecisionQueue("SEARCHDECKTOPX", $player, "10;1;include-definedType-Unit&include-maxCost-2");
AddDecisionQueue("ADDDISCARD", $player, "HAND,TTFREE", 1);
AddDecisionQueue("REVEALCARDS", $player, "-", 1);
break;
case "9637610169"://Bo Katan
if(GetHealth(1) >= 15) Draw($player);
if(GetHealth(2) >= 15) Draw($player);
break;
case "7204838421"://Enterprising Lackeys
$discardID = SearchDiscardForCard($player, $cardID);
MZChooseAndDestroy($player, "MYRESOURCES", may:true, context:"Choose a resource to destroy");
AddDecisionQueue("PASSPARAMETER", $player, "MYDISCARD-$discardID", 1);
AddDecisionQueue("MZADDZONE", $player, "MYRESOURCESEXHAUSTED", 1);
AddDecisionQueue("PASSPARAMETER", $player, "MYDISCARD-$discardID", 1);
AddDecisionQueue("MZREMOVE", $player, "-", 1);
break;
case "8919416985"://Outspoken Representative
CreateCloneTrooper($player);
break;
case "6404471739"://Senatorial Corvette
PummelHit($otherPlayer);
break;
case "5584601885"://Battle Droid Escort
CreateBattleDroid($player);
break;
case "5350889336"://AT-TE Vanguard
CreateCloneTrooper($player);
CreateCloneTrooper($player);
break;
case "8096748603"://Steela Gerrera
AddDecisionQueue("SETDQCONTEXT", $player, "Do you want to deal 2 damage to your base?");
AddDecisionQueue("YESNO", $player, "-");
AddDecisionQueue("NOPASS", $player, "-");
AddDecisionQueue("PASSPARAMETER", $player, "MYCHAR-0", 1);
AddDecisionQueue("MZOP", $player, "DEALDAMAGE,2,$player,1", 1);
AddDecisionQueue("SEARCHDECKTOPX", $player, "8;1;include-trait-Tactic", 1);
AddDecisionQueue("ADDHAND", $player, "-", 1);
AddDecisionQueue("REVEALCARDS", $player, "-", 1);
break;
case "3680942691"://Confederate Courier
CreateBattleDroid($player);
break;