BT19_053.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace DCGO.CardEffects.BT19
  6. {
  7. public class BT19_053 : 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
  13. if (timing == EffectTiming.None)
  14. {
  15. bool PermanentCondition(Permanent targetPermanent)
  16. {
  17. return targetPermanent.TopCard.IsLevel5 &&
  18. targetPermanent.TopCard.EqualsTraits("Royal Base");
  19. }
  20. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(
  21. permanentCondition: PermanentCondition, digivolutionCost: 3, ignoreDigivolutionRequirement: false,
  22. card: card, condition: null));
  23. }
  24. #endregion
  25. #region Alliance
  26. if (timing == EffectTiming.OnAllyAttack)
  27. {
  28. cardEffects.Add(CardEffectFactory.AllianceSelfEffect(isInheritedEffect: false, card: card, condition: null));
  29. }
  30. #endregion
  31. #region When Attacking
  32. if (timing == EffectTiming.OnAllyAttack)
  33. {
  34. ActivateClass activateClass = new ActivateClass();
  35. activateClass.SetUpICardEffect("Play [Royal Base] Digimon from face up security", CanUseCondition, card);
  36. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDiscription());
  37. activateClass.SetHashString("PlayDigimon_BT19_053");
  38. cardEffects.Add(activateClass);
  39. string EffectDiscription()
  40. {
  41. return "[When Attacking] [Once Per Turn] You may play 1 [Royal Base] trait Digimon card from your face up security cards with the play cost reduced by 8.";
  42. }
  43. bool CanSelectCardCondition(CardSource cardSource)
  44. {
  45. if (cardSource.IsDigimon)
  46. {
  47. if (cardSource.EqualsTraits("Royal Base"))
  48. {
  49. if (CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: true, cardEffect: activateClass))
  50. {
  51. return true;
  52. }
  53. }
  54. }
  55. return false;
  56. }
  57. bool CanUseCondition(Hashtable hashtable)
  58. {
  59. return CardEffectCommons.CanTriggerOnAttack(hashtable, card);
  60. }
  61. bool CanActivateCondition(Hashtable hashtable)
  62. {
  63. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) &&
  64. card.Owner.SecurityCards.Count(CanSelectCardCondition) > 0;
  65. }
  66. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  67. {
  68. #region reduce play cost
  69. ChangeCostClass changeCostClass = new ChangeCostClass();
  70. changeCostClass.SetUpICardEffect($"Play Cost -8", CanUseCondition1, card);
  71. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardSourceCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  72. Func<EffectTiming, ICardEffect> getCardEffect = GetCardEffect;
  73. card.Owner.UntilCalculateFixedCostEffect.Add(getCardEffect);
  74. ICardEffect GetCardEffect(EffectTiming _timing)
  75. {
  76. if (_timing == EffectTiming.None)
  77. {
  78. return changeCostClass;
  79. }
  80. return null;
  81. }
  82. bool CanUseCondition1(Hashtable hashtable)
  83. {
  84. return true;
  85. }
  86. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  87. {
  88. if (CardSourceCondition(cardSource))
  89. {
  90. if (RootCondition(root))
  91. {
  92. if (PermanentsCondition(targetPermanents))
  93. {
  94. Cost -= 8;
  95. }
  96. }
  97. }
  98. return Cost;
  99. }
  100. bool PermanentsCondition(List<Permanent> targetPermanents)
  101. {
  102. if (targetPermanents == null)
  103. {
  104. return true;
  105. }
  106. else
  107. {
  108. if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
  109. {
  110. return true;
  111. }
  112. }
  113. return false;
  114. }
  115. bool CardSourceCondition(CardSource cardSource)
  116. {
  117. if (cardSource.IsDigimon)
  118. {
  119. if (cardSource.EqualsTraits("Royal Base"))
  120. {
  121. return true;
  122. }
  123. }
  124. return false;
  125. }
  126. bool RootCondition(SelectCardEffect.Root root)
  127. {
  128. return true;
  129. }
  130. bool isUpDown()
  131. {
  132. return true;
  133. }
  134. #endregion
  135. List<CardSource> selectedCards = new List<CardSource>();
  136. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  137. selectCardEffect.SetUp(
  138. canTargetCondition: CanSelectCardCondition,
  139. canTargetCondition_ByPreSelecetedList: null,
  140. canEndSelectCondition: null,
  141. canNoSelect: () => false,
  142. selectCardCoroutine: SelectCardCoroutine,
  143. afterSelectCardCoroutine: null,
  144. message: "Select 1 card to play.",
  145. maxCount: 1,
  146. canEndNotMax: false,
  147. isShowOpponent: true,
  148. mode: SelectCardEffect.Mode.Custom,
  149. root: SelectCardEffect.Root.Custom,
  150. customRootCardList: card.Owner.SecurityCards.Filter(source => !source.IsFlipped),
  151. canLookReverseCard: false,
  152. selectPlayer: card.Owner,
  153. cardEffect: activateClass);
  154. selectCardEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  155. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  156. yield return StartCoroutine(selectCardEffect.Activate());
  157. IEnumerator SelectCardCoroutine(CardSource cardSource)
  158. {
  159. selectedCards.Add(cardSource);
  160. yield return null;
  161. }
  162. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  163. cardSources: selectedCards,
  164. activateClass: activateClass,
  165. payCost: true,
  166. isTapped: false,
  167. root: SelectCardEffect.Root.Custom,
  168. activateETB: true));
  169. #region release effect reducing play cost
  170. card.Owner.UntilCalculateFixedCostEffect.Remove(getCardEffect);
  171. #endregion
  172. }
  173. }
  174. #endregion
  175. #region All Turns - When Removed
  176. if (timing == EffectTiming.WhenRemoveField)
  177. {
  178. List<Permanent> removedPermanents = new List<Permanent>();
  179. ActivateClass activateClass = new ActivateClass();
  180. activateClass.SetUpICardEffect("Place those Digimon face up as your bottom security cards", CanUseCondition, card);
  181. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  182. activateClass.SetHashString("AllTurns_BT19-053");
  183. cardEffects.Add(activateClass);
  184. string EffectDiscription()
  185. {
  186. return "[All Turns] When any of your [Royal Base] trait Digimon would leave the battle area other than in battle, you may place those Digimon face up as your bottom security cards.";
  187. }
  188. bool HasRoyalBaseDigimon(Permanent permanent)
  189. {
  190. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  191. return permanent.TopCard.EqualsTraits("Royal Base");
  192. return false;
  193. }
  194. bool CanUseCondition(Hashtable hashtable)
  195. {
  196. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  197. {
  198. if (CardEffectCommons.CanTriggerWhenPermanentRemoveField(hashtable, HasRoyalBaseDigimon))
  199. {
  200. if (!CardEffectCommons.IsByBattle(hashtable))
  201. {
  202. if (!CardEffectCommons.IsByEffect(hashtable, effect => effect.HashString.Equals("AllTurns_BT19-053")))
  203. return true;
  204. }
  205. }
  206. }
  207. return false;
  208. }
  209. bool CanActivateCondition(Hashtable hashtable)
  210. {
  211. removedPermanents = CardEffectCommons.GetPermanentsFromHashtable(hashtable).Filter(HasRoyalBaseDigimon);
  212. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  213. && card.Owner.CanAddSecurity(activateClass);
  214. }
  215. IEnumerator ActivateCoroutine(Hashtable hashtable)
  216. {
  217. foreach(Permanent permanent in removedPermanents)
  218. {
  219. yield return ContinuousController.instance.StartCoroutine(new IPutSecurityPermanent(
  220. permanent,
  221. CardEffectCommons.CardEffectHashtable(activateClass), toTop: false, isFaceup: true).PutSecurity());
  222. permanent.HideHandBounceEffect();
  223. permanent.HideDeckBounceEffect();
  224. }
  225. }
  226. }
  227. #endregion
  228. return cardEffects;
  229. }
  230. }
  231. }