BT19_100.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. namespace DCGO.CardEffects.BT19
  7. {
  8. public class BT19_100 : CEntity_Effect
  9. {
  10. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  11. {
  12. List<ICardEffect> cardEffects = new List<ICardEffect>();
  13. #region Security - Face up
  14. if (timing == EffectTiming.OnAllyAttack)
  15. {
  16. ActivateClass activateClass = new ActivateClass();
  17. activateClass.SetUpICardEffect("-1000DP for each digivolution source", CanUseCondition, card);
  18. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  19. cardEffects.Add(activateClass);
  20. string EffectDiscription()
  21. {
  22. return "[Security] [Opponent's Turn] When an opponent's Digimon attacks, if all of your Digimon and Tamers have the [D-Reaper] trait, for each of 1 of your [Mother D-Reaper]'s digivolution cards, the attacking Digimon get -1000 DP for the turn.";
  23. }
  24. bool IsMotherDReaper(Permanent permanent)
  25. {
  26. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card) &&
  27. permanent.TopCard.EqualsCardName("Mother D-Reaper");
  28. }
  29. bool HaveAllDReaper()
  30. {
  31. foreach (Permanent permanent in card.Owner.GetBattleAreaPermanents())
  32. {
  33. if (permanent.TopCard.IsOption)
  34. continue;
  35. if (!permanent.TopCard.EqualsTraits("D-Reaper"))
  36. return false;
  37. }
  38. return true;
  39. }
  40. bool CanSelectOpponentsDigimon(Permanent permanent)
  41. {
  42. return CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card);
  43. }
  44. bool CanUseCondition(Hashtable hashtable)
  45. {
  46. return CardEffectCommons.IsOpponentTurn(card) &&
  47. CardEffectCommons.CanTriggerOnPermanentAttack(hashtable, CanSelectOpponentsDigimon);
  48. }
  49. bool CanActivateCondition(Hashtable hashtable)
  50. {
  51. return CardEffectCommons.IsExistInSecurity(card) &&
  52. HaveAllDReaper() &&
  53. CardEffectCommons.HasMatchConditionOwnersPermanent(card, IsMotherDReaper);
  54. }
  55. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  56. {
  57. Permanent selectedPermanent = GManager.instance.attackProcess.AttackingPermanent;
  58. Permanent selectedMother = null;
  59. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  60. selectPermanentEffect.SetUp(
  61. selectPlayer: card.Owner,
  62. canTargetCondition: IsMotherDReaper,
  63. canTargetCondition_ByPreSelecetedList: null,
  64. canEndSelectCondition: null,
  65. maxCount: 1,
  66. canNoSelect: false,
  67. canEndNotMax: false,
  68. selectPermanentCoroutine: SelectMotherCoroutine,
  69. afterSelectPermanentCoroutine: null,
  70. mode: SelectPermanentEffect.Mode.Custom,
  71. cardEffect: activateClass);
  72. selectPermanentEffect.SetUpCustomMessage($"Choose 1 [Mother D-Reaper].", "The opponent is choosing 1 [Mother D-Reaper].");
  73. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  74. IEnumerator SelectMotherCoroutine(Permanent permanent)
  75. {
  76. selectedMother = permanent;
  77. yield return null;
  78. }
  79. if (selectedMother != null)
  80. {
  81. if (selectedPermanent != null)
  82. {
  83. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.ChangeDigimonDP(
  84. targetPermanent: selectedPermanent,
  85. changeValue: -1000 * selectedMother.DigivolutionCards.Count,
  86. effectDuration: EffectDuration.UntilEachTurnEnd,
  87. activateClass: activateClass));
  88. }
  89. }
  90. }
  91. }
  92. #endregion
  93. #region Main
  94. if (timing == EffectTiming.OptionSkill)
  95. {
  96. ActivateClass activateClass = new ActivateClass();
  97. activateClass.SetUpICardEffect("Trash top security, place this as faceup top of security", CanUseCondition, card);
  98. activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, false, EffectDiscription());
  99. cardEffects.Add(activateClass);
  100. string EffectDiscription()
  101. {
  102. return "[Main] If you have no face-up security cards, by trashing your top security card, place this card face up as your top security card.";
  103. }
  104. bool CanUseCondition(Hashtable hashtable)
  105. {
  106. return CardEffectCommons.CanTriggerOptionMainEffect(hashtable, card) &&
  107. card.Owner.SecurityCards.Count > 0 &&
  108. card.Owner.SecurityCards.Count(source => !source.IsFlipped) == 0;
  109. ;
  110. }
  111. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  112. {
  113. yield return ContinuousController.instance.StartCoroutine(new IDestroySecurity(
  114. player: card.Owner,
  115. destroySecurityCount: 1,
  116. cardEffect: activateClass,
  117. fromTop: true).DestroySecurity());
  118. // Place this card face up as the top security card
  119. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(
  120. card, toTop: true, faceUp: true));
  121. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  122. .CreateRecoveryEffect(card.Owner));
  123. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(card.Owner).AddSecurity());
  124. }
  125. }
  126. #endregion
  127. #region Security
  128. if (timing == EffectTiming.SecuritySkill)
  129. {
  130. ActivateClass activateClass = new ActivateClass();
  131. activateClass.SetUpICardEffect($"Play 1 [D-Reaper] trait card from hand.", CanUseCondition, card);
  132. activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, false, EffectDiscription());
  133. activateClass.SetIsSecurityEffect(true);
  134. cardEffects.Add(activateClass);
  135. string EffectDiscription()
  136. {
  137. return "[Security] You may play 1 [D-Reaper] trait card with a play cost equal to or lower than the number of digivolution cards of 1 of your [Mother D-Reaper]'s from your hand without paying the cost.";
  138. }
  139. int getMaxCount()
  140. {
  141. int count = 0;
  142. foreach (Permanent permanent in card.Owner.GetBattleAreaPermanents().Filter(IsMotherDReaper))
  143. {
  144. if (permanent.DigivolutionCards.Count > count)
  145. count = permanent.DigivolutionCards.Count;
  146. }
  147. return count;
  148. }
  149. bool IsMotherDReaper(Permanent permanent)
  150. {
  151. return permanent.TopCard.EqualsCardName("Mother D-Reaper");
  152. }
  153. bool CanSelectCardCondition(CardSource cardSource)
  154. {
  155. if (cardSource != null)
  156. {
  157. if (cardSource.Owner == card.Owner)
  158. {
  159. if (CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: false, cardEffect: activateClass))
  160. {
  161. if (cardSource.GetCostItself <= getMaxCount())
  162. {
  163. return true;
  164. }
  165. }
  166. }
  167. }
  168. return false;
  169. }
  170. bool CanUseCondition(Hashtable hashtable)
  171. {
  172. return CardEffectCommons.CanTriggerSecurityEffect(hashtable, card);
  173. }
  174. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  175. {
  176. if (CardEffectCommons.HasMatchConditionOwnersHand(card, (cardSource) => CanSelectCardCondition(cardSource)))
  177. {
  178. int maxCount = Math.Min(1, card.Owner.HandCards.Count((cardSource) => CanSelectCardCondition(cardSource)));
  179. List<CardSource> selectedCards = new List<CardSource>();
  180. SelectHandEffect selectCardEffect = GManager.instance.GetComponent<SelectHandEffect>();
  181. selectCardEffect.SetUp(
  182. canTargetCondition: CanSelectCardCondition,
  183. canTargetCondition_ByPreSelecetedList: null,
  184. canEndSelectCondition: null,
  185. canNoSelect: true,
  186. selectCardCoroutine: SelectCardCoroutine,
  187. afterSelectCardCoroutine: null,
  188. maxCount: maxCount,
  189. canEndNotMax: false,
  190. isShowOpponent: true,
  191. mode: SelectHandEffect.Mode.Custom,
  192. selectPlayer: card.Owner,
  193. cardEffect: activateClass);
  194. selectCardEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  195. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  196. yield return StartCoroutine(selectCardEffect.Activate());
  197. IEnumerator SelectCardCoroutine(CardSource cardSource)
  198. {
  199. selectedCards.Add(cardSource);
  200. yield return null;
  201. }
  202. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(cardSources: selectedCards, activateClass: activateClass, payCost: false, isTapped: false, root: SelectCardEffect.Root.Hand, activateETB: true));
  203. }
  204. }
  205. }
  206. #endregion
  207. return cardEffects;
  208. }
  209. }
  210. }