BT23_066.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. // Matadormon
  6. namespace DCGO.CardEffects.BT23
  7. {
  8. public class BT23_066 : CEntity_Effect
  9. {
  10. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  11. {
  12. List<ICardEffect> cardEffects = new List<ICardEffect>();
  13. #region Alternative Digivolution Condition
  14. if (timing == EffectTiming.None)
  15. {
  16. bool PermanentCondition(Permanent targetPermanent)
  17. {
  18. return targetPermanent.TopCard.HasLevel && targetPermanent.TopCard.IsLevel4
  19. && targetPermanent.TopCard.HasCSTraits;
  20. }
  21. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(
  22. permanentCondition: PermanentCondition,
  23. digivolutionCost: 3,
  24. ignoreDigivolutionRequirement: false,
  25. card: card,
  26. condition: null)
  27. );
  28. }
  29. #endregion
  30. #region Scapegoat
  31. if(timing == EffectTiming.WhenPermanentWouldBeDeleted)
  32. {
  33. string EffectDiscription()
  34. {
  35. return "<Scapegoat> (When this Digimon would be deleted other than by your own effects, by deleting 1 of your other Digimon, prevent that deletion.)";
  36. }
  37. cardEffects.Add(CardEffectFactory.ScapegoatSelfEffect(isInheritedEffect: false, card: card, condition: null, effectName: "<Scapegoat>", effectDiscription: EffectDiscription()));
  38. }
  39. #endregion
  40. #region Shared OP/WD
  41. const string SharedEffectDescription = "Delete 1 of your opponent's level 4 or lower Digimon. Then, if digivolving from the trash, you may play 1 play cost 3 or lower card with the [Undead] or [CS] trait from your trash without paying the cost.";
  42. bool SharedCanSelectOpponentDigimonCondition(Permanent permanent)
  43. {
  44. if (CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card))
  45. {
  46. if (permanent.Level <= 4)
  47. {
  48. if (permanent.TopCard.HasLevel)
  49. {
  50. return true;
  51. }
  52. }
  53. }
  54. return false;
  55. }
  56. bool SharedCanSelectUndeadOrCSCardCondition(CardSource cardSource, ActivateClass activateClass)
  57. {
  58. // Is digimon or tamer?
  59. if (cardSource.IsDigimon || cardSource.IsTamer)
  60. {
  61. // Is undead or CS?
  62. if (cardSource.HasUndeadTraits || cardSource.HasCSTraits)
  63. {
  64. // Is 3-cost or lower?
  65. if (cardSource.GetCostItself <= 3)
  66. {
  67. if (CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: false, cardEffect: activateClass))
  68. {
  69. return true;
  70. }
  71. }
  72. }
  73. }
  74. return false;
  75. }
  76. bool RootCondition(SelectCardEffect.Root root)
  77. {
  78. return root == SelectCardEffect.Root.Trash;
  79. }
  80. IEnumerator SharedActivateCoroutine(Hashtable _hashtable, ActivateClass activateClass)
  81. {
  82. // First, delete 1 opponent lvl 4 or lower digimon.
  83. if (CardEffectCommons.HasMatchConditionPermanent(SharedCanSelectOpponentDigimonCondition))
  84. {
  85. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(SharedCanSelectOpponentDigimonCondition));
  86. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  87. selectPermanentEffect.SetUp(
  88. selectPlayer: card.Owner,
  89. canTargetCondition: SharedCanSelectOpponentDigimonCondition,
  90. canTargetCondition_ByPreSelecetedList: null,
  91. canEndSelectCondition: null,
  92. maxCount: maxCount,
  93. canNoSelect: false,
  94. canEndNotMax: false,
  95. selectPermanentCoroutine: null,
  96. afterSelectPermanentCoroutine: null,
  97. mode: SelectPermanentEffect.Mode.Destroy,
  98. cardEffect: activateClass);
  99. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  100. }
  101. // Then, if digivolving from the trash, may play a 3-cost or lower [Undead] or [CS] card from trash
  102. if (CardEffectCommons.CanTriggerWhenDigivolving(_hashtable, card, RootCondition))
  103. {
  104. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, (cardSource) => SharedCanSelectUndeadOrCSCardCondition(cardSource, activateClass)))
  105. {
  106. List<CardSource> selectedCards = new List<CardSource>();
  107. int maxCount = 1;
  108. if (card.Owner.TrashCards.Count((cardSource) => SharedCanSelectUndeadOrCSCardCondition(cardSource, activateClass)) <= maxCount)
  109. {
  110. maxCount = card.Owner.TrashCards.Count((cardSource) => SharedCanSelectUndeadOrCSCardCondition(cardSource, activateClass));
  111. }
  112. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  113. selectCardEffect.SetUp(
  114. canTargetCondition: (cardSource) => SharedCanSelectUndeadOrCSCardCondition(cardSource, activateClass),
  115. canTargetCondition_ByPreSelecetedList: null,
  116. canEndSelectCondition: null,
  117. canNoSelect: () => true,
  118. selectCardCoroutine: SelectCardCoroutine,
  119. afterSelectCardCoroutine: null,
  120. message: "Select 1 card to play.",
  121. maxCount: maxCount,
  122. canEndNotMax: false,
  123. isShowOpponent: true,
  124. mode: SelectCardEffect.Mode.Custom,
  125. root: SelectCardEffect.Root.Trash,
  126. customRootCardList: null,
  127. canLookReverseCard: true,
  128. selectPlayer: card.Owner,
  129. cardEffect: activateClass);
  130. selectCardEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  131. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  132. yield return StartCoroutine(selectCardEffect.Activate());
  133. IEnumerator SelectCardCoroutine(CardSource cardSource)
  134. {
  135. selectedCards.Add(cardSource);
  136. yield return null;
  137. }
  138. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  139. cardSources: selectedCards,
  140. activateClass: activateClass,
  141. payCost: false,
  142. isTapped: false,
  143. root: SelectCardEffect.Root.Trash,
  144. activateETB: true));
  145. }
  146. }
  147. }
  148. #endregion
  149. #region On Play
  150. if (timing == EffectTiming.OnEnterFieldAnyone)
  151. {
  152. ActivateClass activateClass = new ActivateClass();
  153. activateClass.SetUpICardEffect("Delete a digimon, then play a digimon from trash", CanUseCondition, card);
  154. activateClass.SetUpActivateClass(CanActivateCondition, (hashTable) => SharedActivateCoroutine(hashTable, activateClass), -1, false, EffectDiscription());
  155. cardEffects.Add(activateClass);
  156. string EffectDiscription()
  157. {
  158. return "[On Play] " + SharedEffectDescription;
  159. }
  160. bool CanUseCondition(Hashtable hashtable)
  161. {
  162. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) &&
  163. CardEffectCommons.CanTriggerOnPlay(hashtable, card);
  164. }
  165. bool CanActivateCondition(Hashtable hashtable)
  166. {
  167. return CardEffectCommons.IsExistOnBattleAreaDigimon(card);
  168. }
  169. }
  170. #endregion
  171. #region When Digivolving
  172. if (timing == EffectTiming.OnEnterFieldAnyone)
  173. {
  174. ActivateClass activateClass = new ActivateClass();
  175. activateClass.SetUpICardEffect("Delete a digimon, then play a digimon from trash", CanUseCondition, card);
  176. activateClass.SetUpActivateClass(CanActivateCondition, (hashTable) => SharedActivateCoroutine(hashTable, activateClass), -1, false, EffectDiscription());
  177. cardEffects.Add(activateClass);
  178. string EffectDiscription()
  179. {
  180. return "[When Digivolving] " + SharedEffectDescription;
  181. }
  182. bool CanUseCondition(Hashtable hashtable)
  183. {
  184. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) &&
  185. CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  186. }
  187. bool CanActivateCondition(Hashtable hashtable)
  188. {
  189. return CardEffectCommons.IsExistOnBattleAreaDigimon(card);
  190. }
  191. }
  192. #endregion
  193. #region All Turns - ESS
  194. if (timing == EffectTiming.WhenRemoveField)
  195. {
  196. ActivateClass activateClass = new ActivateClass();
  197. activateClass.SetUpICardEffect("Protect others", CanUseCondition, card);
  198. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDiscription());
  199. activateClass.SetHashString("AllTurn_BT23_066");
  200. activateClass.SetIsInheritedEffect(true);
  201. cardEffects.Add(activateClass);
  202. string EffectDiscription()
  203. {
  204. return "[All Turns] [Once per Turn] When any of your other Digimon would leave the battle area, by deleting this Digimon, they don't leave.";
  205. }
  206. bool PermanentCondition(Permanent permanent)
  207. {
  208. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card) &&
  209. permanent != card.PermanentOfThisCard() &&
  210. permanent.willBeRemoveField;
  211. }
  212. bool CanUseCondition(Hashtable hashtable)
  213. {
  214. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) &&
  215. CardEffectCommons.CanTriggerWhenPermanentRemoveField(hashtable, PermanentCondition);
  216. }
  217. bool CanActivateCondition(Hashtable hashtable)
  218. {
  219. return CardEffectCommons.IsExistOnBattleAreaDigimon(card);
  220. }
  221. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  222. {
  223. if (CardEffectCommons.IsExistOnBattleArea(card))
  224. {
  225. Permanent thisCardPermanent = card.PermanentOfThisCard();
  226. // If there are other digimon on field about to leave
  227. if (CardEffectCommons.HasMatchConditionPermanent(PermanentCondition))
  228. {
  229. List<Permanent> permanents = new List<Permanent>();
  230. if (_hashtable.ContainsKey("Permanents"))
  231. {
  232. if (_hashtable["Permanents"] is List<Permanent>)
  233. {
  234. permanents = (List<Permanent>)_hashtable["Permanents"];
  235. permanents = permanents.Filter(PermanentCondition);
  236. // Offer to delete this digimon
  237. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DeletePeremanentAndProcessAccordingToResult(
  238. targetPermanents: new List<Permanent>() { thisCardPermanent },
  239. activateClass: activateClass,
  240. successProcess: permanents => SuccessProcess(),
  241. failureProcess: null));
  242. }
  243. }
  244. // If deletion was successful, protect each Digimon that was about to leave.
  245. IEnumerator SuccessProcess()
  246. {
  247. foreach (Permanent permanent in permanents)
  248. {
  249. permanent.willBeRemoveField = false;
  250. permanent.HideDeleteEffect();
  251. permanent.HideHandBounceEffect();
  252. permanent.HideDeckBounceEffect();
  253. permanent.HideWillRemoveFieldEffect();
  254. }
  255. yield return null;
  256. }
  257. }
  258. }
  259. }
  260. }
  261. #endregion
  262. return cardEffects;
  263. }
  264. }
  265. }