BT23_089.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. //Takumi Aiba
  5. namespace DCGO.CardEffects.BT23
  6. {
  7. public class BT23_089 : CEntity_Effect
  8. {
  9. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  10. {
  11. List<ICardEffect> cardEffects = new List<ICardEffect>();
  12. #region Start of Your Main Phase
  13. if (timing == EffectTiming.OnStartMainPhase)
  14. {
  15. ActivateClass activateClass = new ActivateClass();
  16. activateClass.SetUpICardEffect("Memory +1", CanUseCondition, card);
  17. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  18. cardEffects.Add(activateClass);
  19. string EffectDiscription()
  20. {
  21. return "[Start of Your Main Phase] If your opponent has a Digimon, gain 1 memory.";
  22. }
  23. bool CanUseCondition(Hashtable hashtable)
  24. {
  25. if (CardEffectCommons.IsExistOnBattleArea(card))
  26. {
  27. if (CardEffectCommons.IsOwnerTurn(card))
  28. {
  29. return true;
  30. }
  31. }
  32. return false;
  33. }
  34. bool CanActivateCondition(Hashtable hashtable)
  35. {
  36. if (CardEffectCommons.IsExistOnBattleArea(card))
  37. {
  38. if (card.Owner.Enemy.GetBattleAreaDigimons().Count >= 1)
  39. {
  40. if (card.Owner.CanAddMemory(activateClass))
  41. {
  42. return true;
  43. }
  44. }
  45. }
  46. return false;
  47. }
  48. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  49. {
  50. yield return ContinuousController.instance.StartCoroutine(card.Owner.AddMemory(1, activateClass));
  51. }
  52. }
  53. #endregion
  54. #region All Turns
  55. if (timing == EffectTiming.WhenRemoveField)
  56. {
  57. ActivateClass activateClass = new ActivateClass();
  58. activateClass.SetUpICardEffect("Prevent Digimon from leaving play", CanUseCondition, card);
  59. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  60. activateClass.SetHashString("Substitute_BT23_089");
  61. cardEffects.Add(activateClass);
  62. string EffectDiscription()
  63. {
  64. return "[All Turns] When any of your Digimon with the [CS] trait would leave the battle area, by suspending this Tamer and trash 2 same-level cards from 1 of your [CS] trait Digimon's digivolution cards, they don't leave.";
  65. }
  66. bool RemovedPermanent(Permanent permanent)
  67. {
  68. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card) &&
  69. permanent.TopCard.HasCSTraits;
  70. }
  71. bool CanSelectPermanentCondition(Permanent permanent)
  72. {
  73. if(CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  74. {
  75. if (permanent.TopCard.HasCSTraits)
  76. {
  77. if(permanent.DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  78. {
  79. return true;
  80. }
  81. }
  82. }
  83. return false;
  84. }
  85. bool CanSelectCardCondition(CardSource cardSource)
  86. {
  87. if (!cardSource.CanNotTrashFromDigivolutionCards(activateClass))
  88. {
  89. foreach (CardSource cardSource1 in cardSource.PermanentOfThisCard().DigivolutionCards)
  90. {
  91. if (cardSource != cardSource1)
  92. {
  93. if (cardSource.Level == cardSource1.Level)
  94. {
  95. if (!cardSource1.CanNotTrashFromDigivolutionCards(activateClass))
  96. {
  97. if (cardSource.HasLevel && cardSource1.HasLevel)
  98. {
  99. return true;
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. return false;
  107. }
  108. bool CanUseCondition(Hashtable hashtable)
  109. {
  110. return CardEffectCommons.IsExistOnBattleArea(card) &&
  111. CardEffectCommons.CanTriggerWhenPermanentRemoveField(hashtable, RemovedPermanent);
  112. }
  113. bool CanActivateCondition(Hashtable hashtable)
  114. {
  115. return CardEffectCommons.IsExistOnBattleArea(card) &&
  116. CardEffectCommons.CanActivateSuspendCostEffect(card) &&
  117. CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition);
  118. }
  119. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  120. {
  121. Permanent selectedPermanent = null;
  122. yield return ContinuousController.instance.StartCoroutine(new SuspendPermanentsClass(new List<Permanent>() { card.PermanentOfThisCard() }, _hashtable).Tap());
  123. #region Select Permanent to trash from
  124. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  125. selectPermanentEffect.SetUp(
  126. selectPlayer: card.Owner,
  127. canTargetCondition: CanSelectPermanentCondition,
  128. canTargetCondition_ByPreSelecetedList: null,
  129. canEndSelectCondition: null,
  130. maxCount: 1,
  131. canNoSelect: false,
  132. canEndNotMax: false,
  133. selectPermanentCoroutine: SelectPermanentCoroutine,
  134. afterSelectPermanentCoroutine: null,
  135. mode: SelectPermanentEffect.Mode.Custom,
  136. cardEffect: activateClass);
  137. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  138. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  139. {
  140. selectedPermanent = permanent;
  141. yield return null;
  142. }
  143. #endregion
  144. if(selectedPermanent != null)
  145. {
  146. List<CardSource> selectedCards = new List<CardSource>();
  147. int maxCount = 2;
  148. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  149. selectCardEffect.SetUp(
  150. canTargetCondition: CanSelectCardCondition,
  151. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  152. canEndSelectCondition: CanEndSelectCondition,
  153. canNoSelect: () => true,
  154. selectCardCoroutine: SelectCardCoroutine,
  155. afterSelectCardCoroutine: null,
  156. message: "Select cards to discard.",
  157. maxCount: maxCount,
  158. canEndNotMax: false,
  159. isShowOpponent: true,
  160. mode: SelectCardEffect.Mode.Custom,
  161. root: SelectCardEffect.Root.Custom,
  162. customRootCardList: selectedPermanent.DigivolutionCards,
  163. canLookReverseCard: true,
  164. selectPlayer: card.Owner,
  165. cardEffect: activateClass);
  166. selectCardEffect.SetNotShowCard();
  167. yield return StartCoroutine(selectCardEffect.Activate());
  168. bool CanEndSelectCondition(List<CardSource> cardSources)
  169. {
  170. if (CardEffectCommons.HasNoElement(cardSources))
  171. {
  172. return false;
  173. }
  174. List<int> levels = cardSources
  175. .Map(cardSource1 => cardSource1.Level)
  176. .Distinct()
  177. .ToList();
  178. if (levels.Count > 1)
  179. {
  180. return false;
  181. }
  182. return true;
  183. }
  184. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  185. {
  186. List<int> levels = cardSources
  187. .Map(cardSource1 => cardSource1.Level)
  188. .Concat(new List<int>() { cardSource.Level })
  189. .Distinct()
  190. .ToList();
  191. if (levels.Count > 1)
  192. {
  193. return false;
  194. }
  195. return true;
  196. }
  197. IEnumerator SelectCardCoroutine(CardSource cardSource)
  198. {
  199. selectedCards.Add(cardSource);
  200. yield return null;
  201. }
  202. if (selectedCards.Count == 2)
  203. {
  204. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  205. selectedPermanent,
  206. selectedCards,
  207. activateClass).TrashDigivolutionCards());
  208. List<Permanent> protectedPermanents = CardEffectCommons.GetPermanentsFromHashtable(_hashtable)
  209. .Filter(RemovedPermanent);
  210. foreach (Permanent removed in protectedPermanents)
  211. {
  212. removed.willBeRemoveField = false;
  213. removed.HideDeleteEffect();
  214. removed.HideHandBounceEffect();
  215. removed.HideDeckBounceEffect();
  216. }
  217. }
  218. }
  219. }
  220. }
  221. #endregion
  222. #region Security
  223. if (timing == EffectTiming.SecuritySkill)
  224. {
  225. cardEffects.Add(CardEffectFactory.PlaySelfTamerSecurityEffect(card));
  226. }
  227. #endregion
  228. return cardEffects;
  229. }
  230. }
  231. }