ST21_04.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. //ST21 Zudomon
  5. namespace DCGO.CardEffects.ST21
  6. {
  7. public class ST21_04 : CEntity_Effect
  8. {
  9. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  10. {
  11. List<ICardEffect> cardEffects = new List<ICardEffect>();
  12. #region Alternate Digivolution Requirement
  13. if (timing == EffectTiming.None)
  14. {
  15. static bool PermanentCondition(Permanent targetPermanent)
  16. {
  17. return targetPermanent.TopCard.HasAdventureTraits && targetPermanent.TopCard.HasLevel && targetPermanent.TopCard.Level == 4;
  18. }
  19. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(permanentCondition: PermanentCondition, digivolutionCost: 3, ignoreDigivolutionRequirement: false, card: card, condition: null));
  20. }
  21. #endregion
  22. #region On Play/When Digivolving shared
  23. bool CanActivateConditionShared(Hashtable hashtable)
  24. {
  25. return CardEffectCommons.IsExistOnBattleAreaDigimon(card);
  26. }
  27. int TamerTwoColourCount()
  28. {
  29. List<CardSource> tamerCards = new List<CardSource>();
  30. foreach (Permanent permanent in card.Owner.GetBattleAreaPermanents())
  31. {
  32. if (permanent.IsTamer)
  33. {
  34. tamerCards.Add(permanent.TopCard);
  35. }
  36. }
  37. return Combinations.GetDifferenetColorCardCount(tamerCards) / 2;
  38. }
  39. bool CanSelectPermanentBounceCondition(Permanent permanent)
  40. {
  41. return CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card) && permanent.DigivolutionCards.Count() <= 1;
  42. }
  43. bool CanSelectPermanentStripCondition(Permanent permanent)
  44. {
  45. return CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card);
  46. }
  47. #endregion
  48. #region On Play
  49. if (timing == EffectTiming.OnEnterFieldAnyone)
  50. {
  51. ActivateClass activateClass = new ActivateClass();
  52. activateClass.SetUpICardEffect("Trash sources and bounce", CanUseCondition, card);
  53. activateClass.SetUpActivateClass(CanActivateConditionShared, ActivateCoroutine, -1, false, EffectDescription());
  54. cardEffects.Add(activateClass);
  55. string EffectDescription()
  56. {
  57. return "[On Play] From 1 of your opponent's Digimon, trash any 1 digivolution card for every 2 colors your Tamers have. Then, return 1 of their Digimon with 1 or fewer digivolution cards to the hand.";
  58. }
  59. bool CanUseCondition(Hashtable hashtable)
  60. {
  61. return CardEffectCommons.CanTriggerOnPlay(hashtable, card);
  62. }
  63. bool CanSelectCardCondition(CardSource cardSource)
  64. {
  65. return !cardSource.CanNotTrashFromDigivolutionCards(activateClass);
  66. }
  67. IEnumerator ActivateCoroutine(Hashtable hashtable)
  68. {
  69. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentStripCondition) && TamerTwoColourCount() > 0)
  70. {
  71. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.SelectTrashDigivolutionCards(
  72. permanentCondition: CanSelectPermanentStripCondition,
  73. cardCondition: CanSelectCardCondition,
  74. maxCount: TamerTwoColourCount(),
  75. canNoTrash: false,
  76. isFromOnly1Permanent: true,
  77. activateClass: activateClass
  78. ));
  79. }
  80. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentBounceCondition))
  81. {
  82. SelectPermanentEffect selectPermanentEffect1 = GManager.instance.GetComponent<SelectPermanentEffect>();
  83. selectPermanentEffect1.SetUp(
  84. selectPlayer: card.Owner,
  85. canTargetCondition: CanSelectPermanentBounceCondition,
  86. canTargetCondition_ByPreSelecetedList: null,
  87. canEndSelectCondition: null,
  88. maxCount: 1,
  89. canNoSelect: false,
  90. canEndNotMax: false,
  91. selectPermanentCoroutine: null,
  92. afterSelectPermanentCoroutine: null,
  93. mode: SelectPermanentEffect.Mode.Bounce,
  94. cardEffect: activateClass);
  95. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect1.Activate());
  96. }
  97. }
  98. }
  99. #endregion
  100. #region When Digivolving
  101. if (timing == EffectTiming.OnEnterFieldAnyone)
  102. {
  103. ActivateClass activateClass = new ActivateClass();
  104. activateClass.SetUpICardEffect("Trash sources and bounce", CanUseCondition, card);
  105. activateClass.SetUpActivateClass(CanActivateConditionShared, ActivateCoroutine, -1, false, EffectDescription());
  106. cardEffects.Add(activateClass);
  107. string EffectDescription()
  108. {
  109. return "[When Digivolving] From 1 of your opponent's Digimon, trash any 1 digivolution card for every 2 colors your Tamers have. Then, return 1 of their Digimon with 1 or fewer digivolution cards to the hand.";
  110. }
  111. bool CanUseCondition(Hashtable hashtable)
  112. {
  113. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) &&
  114. CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  115. }
  116. bool CanSelectCardCondition(CardSource cardSource)
  117. {
  118. return !cardSource.CanNotTrashFromDigivolutionCards(activateClass);
  119. }
  120. IEnumerator ActivateCoroutine(Hashtable hashtable)
  121. {
  122. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentStripCondition) && TamerTwoColourCount() > 0)
  123. {
  124. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.SelectTrashDigivolutionCards(
  125. permanentCondition: CanSelectPermanentStripCondition,
  126. cardCondition: CanSelectCardCondition,
  127. maxCount: TamerTwoColourCount(),
  128. canNoTrash: false,
  129. isFromOnly1Permanent: true,
  130. activateClass: activateClass
  131. ));
  132. }
  133. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentBounceCondition))
  134. {
  135. SelectPermanentEffect selectPermanentEffect1 = GManager.instance.GetComponent<SelectPermanentEffect>();
  136. selectPermanentEffect1.SetUp(
  137. selectPlayer: card.Owner,
  138. canTargetCondition: CanSelectPermanentBounceCondition,
  139. canTargetCondition_ByPreSelecetedList: null,
  140. canEndSelectCondition: null,
  141. maxCount: 1,
  142. canNoSelect: false,
  143. canEndNotMax: false,
  144. selectPermanentCoroutine: null,
  145. afterSelectPermanentCoroutine: null,
  146. mode: SelectPermanentEffect.Mode.Bounce,
  147. cardEffect: activateClass);
  148. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect1.Activate());
  149. }
  150. }
  151. }
  152. #endregion
  153. #region Your Turn
  154. if (timing == EffectTiming.OnEnterFieldAnyone)
  155. {
  156. ActivateClass activateClass = new ActivateClass();
  157. activateClass.SetUpICardEffect("Gain alliance then attack", CanUseCondition, card);
  158. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, false, EffectDiscription());
  159. activateClass.SetHashString("alliance-attack-ST21_04");
  160. cardEffects.Add(activateClass);
  161. string EffectDiscription()
  162. {
  163. return "[Your Turn][Once Per Turn] When your other Digimon are played or digivolve, if any of them have the [ADVENTURE] trait, 1 of your Digimon gains <Alliance> for the turn. Then, 1 of your Digimon may attack.";
  164. }
  165. bool MyDigimonAdventurePlayedDigid(Permanent permanent)
  166. {
  167. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card) &&
  168. permanent != card.PermanentOfThisCard() &&
  169. permanent.TopCard.EqualsTraits("ADVENTURE");
  170. }
  171. bool MyDigimonPlayedDigid(Permanent permanent)
  172. {
  173. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card) &&
  174. permanent != card.PermanentOfThisCard();
  175. }
  176. bool MyDigimonAlliance(Permanent permanent)
  177. {
  178. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card);
  179. }
  180. bool MyDigimonAttacking(Permanent permanent)
  181. {
  182. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card) &&
  183. permanent.CanAttack(activateClass);
  184. }
  185. bool CanUseCondition(Hashtable hashtable)
  186. {
  187. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  188. {
  189. if (CardEffectCommons.IsOwnerTurn(card))
  190. {
  191. if (CardEffectCommons.CanTriggerOnPermanentPlay(hashtable, MyDigimonPlayedDigid))
  192. return true;
  193. if (CardEffectCommons.CanTriggerWhenPermanentDigivolving(hashtable, MyDigimonPlayedDigid))
  194. return true;
  195. }
  196. }
  197. return false;
  198. }
  199. bool CanActivateCondition(Hashtable hashtable)
  200. {
  201. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  202. {
  203. return true;
  204. }
  205. return false;
  206. }
  207. IEnumerator ActivateCoroutine(Hashtable hashtable)
  208. {
  209. List<Permanent> etbPermanents = new List<Permanent>();
  210. List<Hashtable> hashtables = CardEffectCommons.GetHashtablesFromHashtable(hashtable);
  211. if (hashtables != null)
  212. {
  213. foreach (Hashtable hashtable1 in hashtables)
  214. {
  215. Permanent permanent = CardEffectCommons.GetPermanentFromHashtable(hashtable1);
  216. if (permanent != null)
  217. etbPermanents.Add(permanent);
  218. }
  219. etbPermanents = etbPermanents.Filter(MyDigimonAdventurePlayedDigid);
  220. }
  221. if (etbPermanents.Count > 0)
  222. {
  223. if (CardEffectCommons.HasMatchConditionPermanent(MyDigimonAlliance))
  224. {
  225. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  226. selectPermanentEffect.SetUp(
  227. selectPlayer: card.Owner,
  228. canTargetCondition: MyDigimonAlliance,
  229. canTargetCondition_ByPreSelecetedList: null,
  230. canEndSelectCondition: null,
  231. maxCount: 1,
  232. canNoSelect: false,
  233. canEndNotMax: false,
  234. selectPermanentCoroutine: SelectBoostedDigimon,
  235. afterSelectPermanentCoroutine: null,
  236. mode: SelectPermanentEffect.Mode.Custom,
  237. cardEffect: activateClass);
  238. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to gain <Alliance>", "The opponent is selecting 1 Digimon to gain <Alliance>");
  239. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  240. IEnumerator SelectBoostedDigimon(Permanent target)
  241. {
  242. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.GainAlliance(targetPermanent: target, effectDuration: EffectDuration.UntilEachTurnEnd, activateClass: activateClass)); ;
  243. }
  244. }
  245. }
  246. if (CardEffectCommons.HasMatchConditionPermanent(MyDigimonAttacking))
  247. {
  248. Permanent selectedPermanent = null;
  249. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  250. selectPermanentEffect.SetUp(
  251. selectPlayer: card.Owner,
  252. canTargetCondition: MyDigimonAttacking,
  253. canTargetCondition_ByPreSelecetedList: null,
  254. canEndSelectCondition: null,
  255. maxCount: 1,
  256. canNoSelect: true,
  257. canEndNotMax: false,
  258. selectPermanentCoroutine: SelectPermanentCoroutine,
  259. afterSelectPermanentCoroutine: null,
  260. mode: SelectPermanentEffect.Mode.Custom,
  261. cardEffect: activateClass);
  262. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to attack.", "The opponent is selecting 1 Digimon to attack.");
  263. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  264. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  265. {
  266. selectedPermanent = permanent;
  267. yield return null;
  268. }
  269. if (selectedPermanent != null)
  270. {
  271. SelectAttackEffect selectAttackEffect = GManager.instance.GetComponent<SelectAttackEffect>();
  272. selectAttackEffect.SetUp(
  273. attacker: selectedPermanent,
  274. canAttackPlayerCondition: () => true,
  275. defenderCondition: _ => true,
  276. cardEffect: activateClass);
  277. yield return ContinuousController.instance.StartCoroutine(selectAttackEffect.Activate());
  278. }
  279. }
  280. }
  281. }
  282. #endregion
  283. #region Alliance Inherit
  284. if (timing == EffectTiming.OnAllyAttack)
  285. {
  286. bool Condition()
  287. {
  288. return CardEffectCommons.IsExistOnBattleArea(card);
  289. }
  290. cardEffects.Add(CardEffectFactory.AllianceSelfEffect(isInheritedEffect: true, card: card, condition: Condition));
  291. }
  292. #endregion
  293. return cardEffects;
  294. }
  295. }
  296. }