-
Notifications
You must be signed in to change notification settings - Fork 0
/
CardManager.cs
1608 lines (1432 loc) · 51.4 KB
/
CardManager.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class CardManager : MonoBehaviour
{
/* SINGELTON_PATTERN */
public static CardManager Instance { get; private set; }
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else Destroy(gameObject);
}
#region FIELDS
[Header("PREFABS"), SerializeField] private GameObject unitCardPrefab;
[SerializeField] private GameObject actionCardPrefab, unitZoomCardPrefab,
actionZoomCardPrefab, cardContainerPrefab, dragArrowPrefab;
[Header("PLAYER START UNITS")]
[SerializeField] private UnitCard[] playerStartUnits;
[Header("TUTORIAL PLAYER UNITS")]
[SerializeField] private UnitCard[] tutorialPlayerUnits;
[Header("ULTIMATE CREATED CARDS"), SerializeField] private ActionCard exploit_Ultimate;
[SerializeField] private ActionCard invention_Ultimate, scheme_Ultimate, extraction_Ultimate;
// Related Card References
[Header("RELATED CARD REFERENCES")]
public Card[] Exploits;
public Card[] Inventions;
public Card[] Schemes;
public Card[] Extractions;
public Card[] Traps;
private int lastCardIndex, lastContainerIndex;
// Positive Keywords
public const string ABILITY_ARMORED = "Armored";
public const string ABILITY_BLITZ = "Blitz";
public const string ABILITY_DEFENDER = "Defender";
public const string ABILITY_FORCEFIELD = "Forcefield";
public const string ABILITY_POISONOUS = "Poisonous";
public const string ABILITY_RANGED = "Ranged";
public const string ABILITY_REGENERATION = "Regeneration";
public const string ABILITY_STEALTH = "Stealth";
public const string ABILITY_WARD = "Ward";
// Status Keywords
public const string ABILITY_MARKED = "Marked";
public const string ABILITY_POISONED = "Poisoned";
public const string ABILITY_WOUNDED = "Wounded";
// Ability Triggers
public const string TRIGGER_DEATHBLOW = "Deathblow";
public const string TRIGGER_INFILTRATE = "Infiltrate";
public const string TRIGGER_PLAY = "Play";
public const string TRIGGER_RESEARCH = "Research";
public const string TRIGGER_RETALIATE = "Retaliate";
public const string TRIGGER_REVENGE = "Revenge";
public const string TRIGGER_SPARK = "Spark";
public const string TRIGGER_TRAP = "Trap";
public const string TRIGGER_TURN_START = "Turn Start";
public const string TRIGGER_TURN_END = "Turn End";
// Card Types
public const string EXPLOIT = "Exploit";
public const string INVENTION = "Invention";
public const string SCHEME = "Scheme";
public const string EXTRACTION = "Extraction";
// Ability Keywords
private static string[] AbilityKeywords = new string[]
{
// Positive Keywords
ABILITY_ARMORED,
ABILITY_BLITZ,
ABILITY_DEFENDER,
ABILITY_FORCEFIELD,
ABILITY_POISONOUS,
ABILITY_RANGED,
ABILITY_REGENERATION,
ABILITY_STEALTH,
ABILITY_WARD,
// Status Keywords
ABILITY_MARKED,
"Mark",
ABILITY_POISONED,
"Poison",
"Silence",
"Stunned",
"Stun",
"Evade",
"Exhausted",
"Refreshed",
"Refresh",
ABILITY_WOUNDED,
// Ability Triggers
TRIGGER_DEATHBLOW,
TRIGGER_INFILTRATE,
TRIGGER_PLAY,
TRIGGER_RESEARCH,
TRIGGER_RETALIATE,
TRIGGER_REVENGE,
TRIGGER_SPARK,
"Traps",
TRIGGER_TRAP,
TRIGGER_TURN_START,
TRIGGER_TURN_END
};
// Card Types
private static string[] CardTypes = new string[]
{
EXPLOIT + "s",
EXPLOIT,
INVENTION + "s",
INVENTION,
SCHEME + "s",
SCHEME,
EXTRACTION + "s",
EXTRACTION
};
// Unit Types
public const string MAGE = "Mage";
public const string MUTANT = "Mutant";
public const string ROGUE = "Rogue";
public const string TECH = "Tech";
public const string WARRIOR = "Warrior";
// Generatable Keywords
[Header("GENERATABLE KEYWORDS")]
public List<StaticAbility> GeneratableKeywords;
// Positive Abilities
public static string[] PositiveAbilities = new string[]
{
ABILITY_ARMORED,
ABILITY_BLITZ,
ABILITY_DEFENDER,
ABILITY_FORCEFIELD,
ABILITY_POISONOUS,
ABILITY_RANGED,
ABILITY_REGENERATION,
ABILITY_STEALTH,
ABILITY_WARD,
};
// Negative Abilities
public static string[] NegativeAbilities = new string[]
{
ABILITY_MARKED,
ABILITY_POISONED,
ABILITY_WOUNDED,
};
#endregion
#region PROPERTIES
public GameObject UnitCardPrefab { get => unitCardPrefab; }
public GameObject ActionCardPrefab { get => actionCardPrefab; }
public GameObject UnitZoomCardPrefab { get => unitZoomCardPrefab; }
public GameObject ActionZoomCardPrefab { get => actionZoomCardPrefab; }
public GameObject CardContainerPrefab { get => cardContainerPrefab; }
public GameObject DragArrowPrefab { get => dragArrowPrefab; }
public UnitCard[] PlayerStartUnits { get => playerStartUnits; }
public UnitCard[] TutorialPlayerUnits { get => tutorialPlayerUnits; }
public ActionCard Exploit_Ultimate { get => exploit_Ultimate; }
public ActionCard Invention_Ultimate { get => invention_Ultimate; }
public ActionCard Scheme_Ultimate { get => scheme_Ultimate; }
public ActionCard Extraction_Ultimate { get => extraction_Ultimate; }
public List<UnitCard> PlayerRecruitUnits { get; private set; }
public List<ActionCard> ActionShopCards { get; private set; }
#endregion
#region METHODS
#region UTILITY
private void Start()
{
PlayerRecruitUnits = new List<UnitCard>();
ActionShopCards = new List<ActionCard>();
}
#endregion
#region CARD HANDLING
/******
* *****
* ****** GetRelatedCards
* *****
*****/
public Card[] GetCreatedCards(string cardType, bool includeUltimates)
{
if (Enum.TryParse(cardType, out Card.CreatedCardType enumType))
return GetCreatedCards(enumType, includeUltimates);
else return null;
}
public Card[] GetCreatedCards(Card.CreatedCardType cardType, bool includeUltimates)
{
Card[] createdCards;
Card ultimate;
switch (cardType)
{
case Card.CreatedCardType.Exploit:
createdCards = Exploits;
ultimate = exploit_Ultimate;
break;
case Card.CreatedCardType.Invention:
createdCards = Inventions;
ultimate = invention_Ultimate;
break;
case Card.CreatedCardType.Scheme:
createdCards = Schemes;
ultimate = scheme_Ultimate;
break;
case Card.CreatedCardType.Extraction:
createdCards = Extractions;
ultimate = extraction_Ultimate;
break;
case Card.CreatedCardType.Trap:
return Traps;
default:
Debug.LogError("INVALID CARD TYPE!");
return null;
}
return includeUltimates ? createdCards.Concat(new Card[] { ultimate }).ToArray() : createdCards;
}
/******
* *****
* ****** NEW_CARD_INSTANCE
* *****
*****/
public Card NewCardInstance(Card card, bool isExactCopy = false)
{
var cardScript = ScriptableObject.CreateInstance(card.GetType()) as Card;
if (isExactCopy) cardScript.CopyCard(card);
else cardScript.LoadCard(card);
return cardScript;
}
/******
* *****
* ****** SHOW_CARD
* *****
*****/
public enum DisplayType
{
Default,
HeroSelect,
NewCard,
ChooseCard,
Cardpage
}
public GameObject ShowCard(Card card, Vector2 position,
DisplayType type = DisplayType.Default, bool banishAfterPlay = false)
{
if (card == null)
{
Debug.LogError("CARD IS NULL!");
return null;
}
card.BanishAfterPlay = banishAfterPlay;
GameObject prefab = null;
if (card is UnitCard)
{
// Unused "New Card" functionality
prefab = type is DisplayType.NewCard ? UnitZoomCardPrefab : UnitCardPrefab;
}
else if (card is ActionCard)
{
// Unused "New Card" functionality
prefab = type is DisplayType.NewCard ? ActionZoomCardPrefab : ActionCardPrefab;
}
GameObject parent = null;
if (Managers.CO_MAN.CardZone != null) parent = Managers.CO_MAN.CardZone;
//else if (Managers.U_MAN.CurrentCanvas != null) parent = Managers.U_MAN.CurrentCanvas;
else if (Managers.U_MAN.UICanvas != null) parent = Managers.U_MAN.UICanvas;
if (parent == null)
{
Debug.LogError("PARENT IS NULL!");
return null;
}
prefab = Instantiate(prefab, parent.transform);
prefab.transform.position = position;
var cd = prefab.GetComponent<CardDisplay>();
if (type is DisplayType.Default)
{
cd.CardScript = card;
//var containParent = Managers.U_MAN.CurrentCanvas != null ? Managers.U_MAN.CurrentCanvas : Managers.U_MAN.UICanvas;
//cd.CardContainer = Instantiate(CardContainerPrefab, containParent.transform);
cd.CardContainer = Instantiate(CardContainerPrefab, Managers.U_MAN.UICanvas.transform); // TESTING
cd.CardContainer.transform.position = position;
var cc = cd.CardContainer.GetComponent<CardContainer>();
cc.Child = prefab;
}
else
{
prefab.tag = Managers.P_MAN.CARD_TAG; // For CardZoom.CreateAbilityPopups()
var newCard = NewCardInstance(card);
if (type is DisplayType.HeroSelect) cd.CardScript = newCard;
else if (type is DisplayType.NewCard) cd.DisplayZoomCard(newCard);
else if (type is DisplayType.ChooseCard or DisplayType.Cardpage) cd.DisplayCardPageCard(newCard);
}
return prefab;
}
/******
* *****
* ****** HIDE_CARD
* *****
*****/
public Card HideCard(GameObject card)
{
card.GetComponent<CardZoom>().DestroyZoomPopups();
Card cardScript = card.GetComponent<CardDisplay>().CardScript;
Destroy(card.GetComponent<CardDisplay>().CardContainer);
if (card != null) Destroy(card);
return cardScript;
}
/******
* *****
* ****** DRAW_CARD
* *****
*****/
public GameObject DrawCard(HeroManager hero, Card drawnCard = null, List<Effect> additionalEffects = null)
{
if (hero == null)
{
Debug.LogError("HERO IS NULL!");
return null;
}
var deck = hero.CurrentDeck;
var hand = hero.HandZoneCards;
string cardTag = hero.CARD_TAG;
Vector2 position = new();
if (hero == Managers.P_MAN)
{
if (hand.Count >= GameManager.MAX_HAND_SIZE)
{
Managers.U_MAN.CreateFleetingInfoPopup("Your hand is full!");
Debug.Log("PLAYER HAND IS FULL!");
return null;
}
if (drawnCard == null) position.Set(-850, -410);
else position.Set(0, -350);
}
else if (hero == Managers.EN_MAN)
{
if (hand.Count >= GameManager.MAX_HAND_SIZE)
{
Managers.U_MAN.CreateFleetingInfoPopup("Enemy hand is full!");
Debug.Log("ENEMY HAND IS FULL!");
return null;
}
if (drawnCard == null) position.Set(850, 427);
else position.Set(0, 350);
}
// Shuffle discard into deck
if (drawnCard == null && deck.Count < 1)
{
var discard = hero.DiscardZoneCards;
if (discard.Count < 1)
{
Debug.LogError("DISCARD IS EMPTY!");
return null;
}
deck.AddRange(discard);
discard.Clear();
ShuffleDeck(hero);
}
GameObject card;
if (drawnCard == null)
{
Managers.AU_MAN.StartStopSound("SFX_DrawCard");
card = ShowCard(deck[0], position);
}
else
{
Managers.AU_MAN.StartStopSound("SFX_CreateCard");
card = ShowCard(drawnCard, position, DisplayType.Default, true);
}
if (card == null)
{
Debug.LogError("CARD IS NULL!");
return null;
}
if (drawnCard == null) deck.RemoveAt(0);
card.tag = cardTag;
ChangeCardZone(card, hero.HandZone);
Managers.AN_MAN.CreateParticleSystem(card, ParticleSystemHandler.ParticlesType.Drag, 1);
hero.HandZoneCards.Add(card);
if (additionalEffects != null)
{
foreach (var addEffect in additionalEffects)
Managers.EF_MAN.ResolveEffect(new List<GameObject>
{ card }, addEffect, false, 0, out _, false);
}
return card;
}
/******
* *****
* ****** CHANGE_CARD_ZONE
* *****
*****/
public enum ZoneChangeType
{
Default,
ReturnToIndex,
ChangeControl,
LoadFromSave,
}
public void ChangeCardZone(GameObject card, GameObject newZone, ZoneChangeType changeType = ZoneChangeType.Default)
{
if (card == null)
{
Debug.LogError("CARD IS NULL!");
return;
}
if (newZone == null)
{
Debug.LogError("NEW ZONE IS NULL"!);
return;
}
var cd = card.GetComponent<CardDisplay>();
var dd = card.GetComponent<DragDrop>();
var container = cd.CardContainer.GetComponent<CardContainer>();
Action action;
bool isPlayed = true;
bool wasPlayed = dd.IsPlayed; // For cards returned to hand
Managers.U_MAN.SelectTarget(card, UIManager.SelectionType.Disabled); // Unnecessary?
if (newZone == Managers.P_MAN.HandZone)
{
action = () => Managers.AN_MAN.RevealedHandState(card);
isPlayed = false;
}
else if (newZone == Managers.P_MAN.PlayZone)
{
action = () => Managers.AN_MAN.PlayedUnitState(card);
}
else if (newZone == Managers.P_MAN.ActionZone)
{
action = () => Managers.AN_MAN.PlayedActionState(card);
}
else if (newZone == Managers.EN_MAN.HandZone)
{
action = () => Managers.AN_MAN.HiddenHandState(card);
isPlayed = false;
}
else if (newZone == Managers.EN_MAN.PlayZone)
{
action = () => Managers.AN_MAN.PlayedUnitState(card);
}
else if (newZone == Managers.EN_MAN.ActionZone)
{
action = () => Managers.AN_MAN.PlayedActionState(card);
}
else
{
Debug.LogError("INVALID ZONE!");
return;
}
container.OnAttachAction += () => action();
if (changeType is not ZoneChangeType.ReturnToIndex)
{
lastCardIndex = dd.LastIndex;
lastContainerIndex = cd.CardContainer.transform.GetSiblingIndex();
/*
if (newZone == Managers.P_MAN.HandZone) card.transform.SetAsLastSibling();
else card.transform.SetAsFirstSibling();
*/
// Set hand cards immediately or they will momentarily appear in front of others
if (newZone == Managers.EN_MAN.HandZone) card.transform.SetAsFirstSibling();
else if (newZone == Managers.P_MAN.HandZone) card.transform.SetAsLastSibling();
else container.OnAttachAction += () => card.transform.SetAsFirstSibling();
}
container.MoveContainer(newZone);
if (changeType is ZoneChangeType.ChangeControl) dd.IsPlayed = true;
else if (changeType is ZoneChangeType.ReturnToIndex)
{
card.transform.SetSiblingIndex(lastCardIndex);
cd.CardContainer.transform.SetSiblingIndex(lastContainerIndex);
dd.IsPlayed = isPlayed;
}
else if (!isPlayed) // => PlayerHand OR EnemyHand
{
if (wasPlayed) // For ReturnCard effects (Play => Hand)
{
cd.ResetCard();
dd.IsPlayed = false;
}
Managers.EF_MAN.ApplyChangeNextCostEffects(card);
}
if (cd is UnitCardDisplay ucd)
{
if (changeType is not ZoneChangeType.LoadFromSave) // !!! Load From Save !!!
{
bool isExhausted = false;
if (isPlayed)
{
if (changeType is not ZoneChangeType.ChangeControl &&
!GetAbility(card, ABILITY_BLITZ)) isExhausted = true;
}
ucd.IsExhausted = isExhausted;
}
if (isPlayed) ucd.EnableVFX();
else ucd.DisableVFX();
container.OnAttachAction += () => FunctionTimer.Create(() => SetStats(card), 0.1f);
void SetStats(GameObject unitCard)
{
if (unitCard == null) return;
Managers.AN_MAN.UnitStatChangeState(card, 0, 0, false, true);
}
}
}
/******
* *****
* ****** IS_PLAYABLE
* *****
*****/
public bool IsPlayable(GameObject card, bool isPrecheck = false, bool ignoreCost = false)
{
if (card == null)
{
Debug.LogError("CARD IS NULL!");
return false;
}
HeroManager hMan = HeroManager.GetSourceHero(card);
CardDisplay cardDisplay = card.GetComponent<CardDisplay>();
if (cardDisplay is UnitCardDisplay)
{
bool isPlayerHero = hMan == Managers.P_MAN;
var zoneCards = isPlayerHero ? Managers.P_MAN.PlayZoneCards : Managers.EN_MAN.PlayZoneCards;
string errorMessage = isPlayerHero ? "You can't play more units!" : "Enemy can't play more units!";
if (zoneCards.Count >= GameManager.MAX_UNITS_PLAYED)
{
if (!isPrecheck)
{
Managers.U_MAN.CreateFleetingInfoPopup(errorMessage);
ErrorSound();
}
return false;
}
}
else if (cardDisplay is ActionCardDisplay acd)
{
if (!Managers.EF_MAN.CheckLegalTargets(acd.ActionCard.EffectGroupList, card, true))
{
if (!isPrecheck)
{
Managers.U_MAN.CreateFleetingInfoPopup("You can't play that right now!");
ErrorSound();
}
return false;
}
}
if (!ignoreCost)
{
int energyLeft;
if (hMan == Managers.P_MAN) energyLeft = Managers.P_MAN.CurrentEnergy;
else energyLeft = Managers.EN_MAN.CurrentEnergy;
if (energyLeft < cardDisplay.CurrentEnergyCost)
{
if (!isPrecheck)
{
Managers.U_MAN.CreateFleetingInfoPopup("Not enough energy!");
ErrorSound();
}
return false;
}
}
return true;
static void ErrorSound() => Managers.AU_MAN.StartStopSound("SFX_Error");
}
/******
* *****
* ****** PLAY_CARD [HAND >>> PLAY]
* *****
*****/
public void PlayCard(GameObject card)
{
var hMan = HeroManager.GetSourceHero(card);
var cd = card.GetComponent<CardDisplay>();
var container = cd.CardContainer.GetComponent<CardContainer>();
if (cd is UnitCardDisplay)
{
if (hMan.PlayZoneCards.Count >= GameManager.MAX_UNITS_PLAYED)
{
Debug.LogError("TOO MANY UNITS!");
return;
}
}
Managers.EV_MAN.PauseDelayedActions(true);
container.OnAttachAction += () => Managers.EV_MAN.PauseDelayedActions(false);
hMan.HandZoneCards.Remove(card);
int energyLeft = hMan.CurrentEnergy;
hMan.CurrentEnergy -= cd.CurrentEnergyCost;
int energyChange = hMan.CurrentEnergy - energyLeft;
if (energyChange != 0) Managers.AN_MAN.ModifyHeroEnergyState(energyChange, hMan.HeroObject, false);
if (hMan == Managers.P_MAN) Managers.EV_MAN.NewDelayedAction(() => SelectPlayableCards(), 0, true);
if (cd is UnitCardDisplay)
{
hMan.PlayZoneCards.Add(card);
ChangeCardZone(card, hMan.PlayZone);
Managers.EV_MAN.NewDelayedAction(() => PlayUnit(), 0, true);
}
else if (cd is ActionCardDisplay)
{
hMan.ActionZoneCards.Add(card);
ChangeCardZone(card, hMan.ActionZone);
Managers.EV_MAN.NewDelayedAction(() => PlayAction(), 0, true);
}
else
{
Debug.LogError("INVALID TYPE!");
return;
}
void PlayUnit()
{
if (card == null)
{
Debug.LogError("CARD IS NULL!");
return;
}
/*
bool hasPlayTrigger = TriggerUnitAbility(card, TRIGGER_PLAY);
if (HeroManager.GetSourceHero(card) == Managers.P_MAN)
{
if (!hasPlayTrigger) UnitTriggers();
}
else UnitTriggers();
*/
if (!TriggerUnitAbility(card, TRIGGER_PLAY)) UnitTriggers(); // TESTING
card.transform.SetAsFirstSibling();
PlayCardSound();
ParticleBurst();
void UnitTriggers()
{
Managers.U_MAN.CombatLog_PlayCard(card);
Managers.EF_MAN.ResolveChangeNextCostEffects(card); // Resolves IMMEDIATELY
TriggerTrapAbilities(card); // Resolves 3rd
Managers.EF_MAN.TriggerModifiers_PlayCard(card); // Resolves 2nd
Managers.EF_MAN.TriggerGiveNextEffects(card); // Resolves 1st
}
}
void PlayAction()
{
if (card == null)
{
Debug.LogError("CARD IS NULL!");
return;
}
Managers.AU_MAN.StartStopSound("SFX_PlayCard");
ResolveActionCard(card); // Resolves IMMEDIATELY
ParticleBurst();
}
void PlayCardSound()
{
Sound playSound = cd.CardScript.CardPlaySound;
if (playSound.clip == null) Debug.LogWarning("MISSING PLAY SOUND: " + cd.CardName);
else Managers.AU_MAN.StartStopSound(null, playSound);
}
void ParticleBurst() =>
Managers.AN_MAN.CreateParticleSystem(card, ParticleSystemHandler.ParticlesType.Play, 1);
}
/******
* *****
* ****** DISCARD_CARD [HAND/ACTION_ZONE >>> DISCARD]
* *****
*****/
public void DiscardCard(GameObject card, bool isAction = false)
{
var cd = card.GetComponent<CardDisplay>();
var hMan = HeroManager.GetSourceHero(card);
var previousZone = isAction ? hMan.ActionZoneCards : hMan.HandZoneCards;
var newZone = hMan.DiscardZoneCards;
previousZone.Remove(card);
if (cd.CardScript.BanishAfterPlay) HideCard(card);
else
{
cd.ResetCard();
newZone.Add(HideCard(card));
}
if (!isAction) Managers.AU_MAN.StartStopSound("SFX_DiscardCard");
}
/******
* *****
* ****** RESOLVE_ACTION_CARD
* *****
*****/
private void ResolveActionCard(GameObject card)
{
var groupList = card.GetComponent<ActionCardDisplay>().ActionCard.EffectGroupList;
Managers.EF_MAN.StartEffectGroupList(groupList, card);
}
/******
* *****
* ****** GET_COST_CONDITION_VALUE
* *****
*****/
public int GetCostConditionValue(Card cardScript, GameObject source) =>
GetCostConditionValue_Finish(source, cardScript.CostConditionType, cardScript.CostConditionValue, cardScript.CostConditionModifier);
public int GetCostConditionValue(HeroPower power, GameObject source) =>
GetCostConditionValue_Finish(source, power.CostConditionType, power.CostConditionValue, power.CostConditionModifier);
private int GetCostConditionValue_Finish(GameObject source, Effect.ConditionType conditionType, int conditionValue, int conditionModifier)
{
var hMan_Source = HeroManager.GetSourceHero(source, out HeroManager hMan_Enemy);
switch (conditionType)
{
case Effect.ConditionType.NONE:
return 0;
case Effect.ConditionType.EnemyWounded:
if (!hMan_Enemy.IsWounded()) return 0;
break;
case Effect.ConditionType.AlliesDestroyed_ThisTurn:
if (hMan_Source.AlliesDestroyed_ThisTurn < conditionValue) return 0;
break;
case Effect.ConditionType.EnemiesDestroyed_ThisTurn:
if (hMan_Enemy.AlliesDestroyed_ThisTurn < conditionValue) return 0;
break;
case Effect.ConditionType.HasMoreCards_Player:
if (hMan_Source.HandZoneCards.Count <= conditionValue) return 0;
break;
case Effect.ConditionType.HasLessCards_Player:
if (hMan_Source.HandZoneCards.Count >= conditionValue) return 0;
break;
default:
Debug.LogError("INVALID CONDITION TYPE!");
return 0;
}
return conditionModifier;
}
/******
* *****
* ****** SELECT_PLAYABLE_CARDS
* *****
*****/
public void SelectPlayableCards(bool setAllFalse = false)
{
Managers.EV_MAN.NewDelayedAction(() => SelectCards(), 0, true);
void SelectCards()
{
int playableCards = 0;
bool isPlayerTurn = !setAllFalse && Managers.P_MAN.IsMyTurn;
// Cards in Hand
foreach (var card in Managers.P_MAN.HandZoneCards)
{
if (card == null)
{
Debug.LogError("CARD IS NULL!");
continue;
}
// Apply cost conditions
card.GetComponent<CardDisplay>().UpdateCurrentEnergyCost();
if (isPlayerTurn && IsPlayable(card, true))
{
playableCards++;
Managers.U_MAN.SelectTarget(card, UIManager.SelectionType.Playable);
}
else Managers.U_MAN.SelectTarget(card, UIManager.SelectionType.Disabled);
}
// Hero Powers
// Display cost condition values
Managers.P_MAN.HeroObject.GetComponent<PlayerHeroDisplay>().DisplayHeroPowers();
bool playerHasActions = playableCards > 0;
foreach (var ally in Managers.P_MAN.PlayZoneCards)
{
if (isPlayerTurn && Managers.CO_MAN.CanAttack(ally, null, true, true))
{
Managers.U_MAN.SelectTarget(ally, UIManager.SelectionType.Playable);
playerHasActions = true;
}
else Managers.U_MAN.SelectTarget(ally, UIManager.SelectionType.Disabled);
}
if (!playerHasActions)
{
if (Managers.P_MAN.UseHeroPower(false, true) ||
Managers.P_MAN.UseHeroPower(true, true)) playerHasActions = true;
}
if (setAllFalse) playerHasActions = false;
Managers.U_MAN.SetReadyEndTurnButton(!playerHasActions);
}
}
/******
* *****
* ****** CHANGE_UNIT_CONTROL
* *****
*****/
public void ChangeUnitControl(GameObject card)
{
var hMan_Source = HeroManager.GetSourceHero(card, out HeroManager hMan_Enemy);
if (hMan_Enemy.PlayZoneCards.Count >= GameManager.MAX_UNITS_PLAYED)
{
Debug.LogWarning("TOO MANY UNITS!");
Managers.CO_MAN.DestroyUnit(card);
return;
}
hMan_Source.PlayZoneCards.Remove(card);
card.tag = hMan_Enemy.CARD_TAG;
ChangeCardZone(card, hMan_Enemy.PlayZone, ZoneChangeType.ChangeControl);
hMan_Enemy.PlayZoneCards.Add(card);
}
public string FilterCreatedCardProgress(string text, bool isPlayerSource)
{
HeroManager hMan = isPlayerSource ? Managers.P_MAN : Managers.EN_MAN;
text = text.Replace("{EXPLOITS}", CardProgress(hMan.ExploitsPlayed));
text = text.Replace("{INVENTIONS}", CardProgress(hMan.InventionsPlayed));
text = text.Replace("{SCHEMES}", CardProgress(hMan.SchemesPlayed));
text = text.Replace("{EXTRACTIONS}", CardProgress(hMan.ExtractionsPlayed));
return text;
static string CardProgress(int progress) =>
$"{TextFilter.Clrz_ylw(progress.ToString())}/{TextFilter.Clrz_ylw("3")}";
}
public string FilterKeywords(string text)
{
foreach (string str in AbilityKeywords)
text = text.Replace(str, TextFilter.Clrz_ylw(str));
foreach (string str in CardTypes)
text = text.Replace(str, TextFilter.Clrz_grn(str));
text = FilterUnitTypes(text);
return text;
}
public string FilterUnitTypes(string text)
{
string[] unitTypes =
{
MAGE + "s",
MAGE,
MUTANT + "s",
MUTANT,
ROGUE + "s",
ROGUE,
TECH + "s",
TECH,
WARRIOR + "s",
WARRIOR
};
foreach (string s in unitTypes) text = text.Replace(s, TextFilter.Clrz_grn(s));
return text;
}
public Color GetAbilityColor(CardAbility cardAbility)
{
if (cardAbility.OverrideColor) return cardAbility.AbilityColor;
if (cardAbility is TriggeredAbility or ModifierAbility) return Color.yellow;
foreach (string posAbi in PositiveAbilities)
if (cardAbility.AbilityName == posAbi) return Color.green;
foreach (string negAbi in NegativeAbilities)
if (cardAbility.AbilityName == negAbi) return Color.red;
return Color.yellow;
}
public void LoadNewActions()
{
var allActions = Resources.LoadAll<ActionCard>("Cards_Actions");
allActions.Shuffle();
List<ActionCard> actionList = new();
foreach (var action in allActions)
{
// Card Rarity Functionality
switch (action.CardRarity)
{
case Card.Rarity.Common:
AddCard();
AddCard();
AddCard();
goto case Card.Rarity.Rare;
case Card.Rarity.Rare:
AddCard();
AddCard();
goto case Card.Rarity.Legend;
case Card.Rarity.Legend:
AddCard();
break;
}
void AddCard() => actionList.Add(action);
}
while (ActionShopCards.Count < 8)
{
foreach (var ac in actionList)
{
if (ac == null) continue;
int index = Managers.P_MAN.DeckList.FindIndex(x => x.CardName == ac.CardName);
if (index == -1 && !ActionShopCards.Contains(ac))
{
ActionShopCards.Add(ac);
if (ActionShopCards.Count > 7) break;
}
}
}
}
public void LoadNewRecruits()
{
var allRecruits = Resources.LoadAll<UnitCard>("Cards_Units");
allRecruits.Shuffle();
List<UnitCard> recruitMages = new();
List<UnitCard> recruitMutants = new();
List<UnitCard> recruitRogues = new();
List<UnitCard> recruitTechs = new();
List<UnitCard> recruitWarriors = new();
foreach (var unitCard in allRecruits)
{
List<UnitCard> targetList;
switch (unitCard.CardType)
{