BT22_007.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. // Mother Eater
  7. namespace DCGO.CardEffects.BT22
  8. {
  9. public class BT22_007 : CEntity_Effect
  10. {
  11. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  12. {
  13. List<ICardEffect> cardEffects = new List<ICardEffect>();
  14. #region Start of Main Phase
  15. if (timing == EffectTiming.OnStartMainPhase)
  16. {
  17. ActivateClass activateClass = new ActivateClass();
  18. activateClass.SetUpICardEffect("Add [Mother Eater]s to top of stack. if 10 or more in digivolution source, play 3 [Mother Eater]s", CanUseCondition, card);
  19. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  20. cardEffects.Add(activateClass);
  21. string EffectDiscription()
  22. {
  23. return "[Breeding] [Start of Your Main Phase] Look at your Digi-Egg deck's top card. Among them, you may place [Mother Eater]s as this Digimon's top digivolution cards. Then, if this Digimon has 10 or more digivolution cards, you may play 3 [Mother Eater]s from its digivolution cards without paying the costs.";
  24. }
  25. bool CanSelectMother(CardSource source)
  26. {
  27. return source.EqualsCardName("Mother Eater") &&
  28. CardEffectCommons.CanPlayAsNewPermanent(source, false, activateClass, SelectCardEffect.Root.DigivolutionCards);
  29. }
  30. bool CanUseCondition(Hashtable hashtable)
  31. {
  32. return CardEffectCommons.IsOwnerTurn(card);
  33. }
  34. bool CanActivateCondition(Hashtable hashtable)
  35. {
  36. return CardEffectCommons.IsExistOnBreedingAreaDigimon(card);
  37. }
  38. IEnumerator ActivateCoroutine(Hashtable hashtable)
  39. {
  40. if (card.Owner.DigitamaLibraryCards.Count >= 1)
  41. {
  42. CardSource topEggCard = card.Owner.DigitamaLibraryCards[0];
  43. bool AddToBreedingArea = false;
  44. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topEggCard }, "Revealed Cards", true, true));
  45. if (topEggCard.EqualsCardName("Mother Eater"))
  46. {
  47. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  48. {
  49. new SelectionElement<bool>(message: $"Yes", value : true, spriteIndex: 0),
  50. new SelectionElement<bool>(message: $"No", value : false, spriteIndex: 1),
  51. };
  52. string selectPlayerMessage = "Place as top digivolution card?";
  53. string notSelectPlayerMessage = "The opponent is choosing to place as top digivolution card";
  54. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  55. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  56. AddToBreedingArea = GManager.instance.userSelectionManager.SelectedBoolValue;
  57. }
  58. if (AddToBreedingArea)
  59. {
  60. Permanent thisPermanent = card.PermanentOfThisCard();
  61. yield return ContinuousController.instance.StartCoroutine(thisPermanent.AddDigivolutionCardsTop(new List<CardSource>() { topEggCard }, activateClass));
  62. }
  63. }
  64. if (card.PermanentOfThisCard().DigivolutionCards.Count >= 10)
  65. {
  66. Permanent thisPermanent = card.PermanentOfThisCard();
  67. if (thisPermanent.DigivolutionCards.Exists(CanSelectMother))
  68. {
  69. int motherCount = thisPermanent.DigivolutionCards.Count(CanSelectMother);
  70. if (card.Owner.fieldCardFrames.Count((frame) => frame.IsEmptyFrame() && frame.IsBattleAreaFrame()) >= motherCount)
  71. {
  72. int maxCount = Math.Min(3, motherCount);
  73. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  74. selectCardEffect.SetUp(
  75. canTargetCondition: CanSelectMother,
  76. canTargetCondition_ByPreSelecetedList: null,
  77. canEndSelectCondition: null,
  78. canNoSelect: () => true,
  79. selectCardCoroutine: null,
  80. afterSelectCardCoroutine: SelectCardCoroutine,
  81. message: "Select [Mother Eater]'s to play.",
  82. maxCount: maxCount,
  83. canEndNotMax: false,
  84. isShowOpponent: true,
  85. mode: SelectCardEffect.Mode.Custom,
  86. root: SelectCardEffect.Root.DigivolutionCards,
  87. customRootCardList: thisPermanent.DigivolutionCards,
  88. canLookReverseCard: true,
  89. selectPlayer: card.Owner,
  90. cardEffect: activateClass);
  91. selectCardEffect.SetUpCustomMessage(
  92. "Select [Mother Eater]'s to play.",
  93. "The opponent is selecting [Mother Eater]'s to play.");
  94. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  95. IEnumerator SelectCardCoroutine(List<CardSource> cardSources)
  96. {
  97. if (cardSources.Count >= 1)
  98. {
  99. foreach (CardSource source in cardSources)
  100. {
  101. source.SetDP(16000);
  102. }
  103. yield return ContinuousController.instance.StartCoroutine(
  104. CardEffectCommons.PlayPermanentCards(
  105. cardSources: cardSources,
  106. activateClass: activateClass,
  107. payCost: false,
  108. isTapped: false,
  109. root: SelectCardEffect.Root.DigivolutionCards,
  110. activateETB: true));
  111. }
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }
  118. #endregion
  119. #region On Play
  120. if (timing == EffectTiming.OnEnterFieldAnyone)
  121. {
  122. ActivateClass activateClass = new ActivateClass();
  123. activateClass.SetUpICardEffect("Delete 1 Digimon", CanUseCondition, card);
  124. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  125. cardEffects.Add(activateClass);
  126. string EffectDiscription()
  127. {
  128. return "[On Play] Delete 1 of your opponent's Digimon.";
  129. }
  130. bool CanUseCondition(Hashtable hashtable)
  131. {
  132. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) &&
  133. CardEffectCommons.CanTriggerOnPlay(hashtable, card);
  134. }
  135. bool CanActivateCondition(Hashtable hashtable)
  136. {
  137. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  138. && CardEffectCommons.HasMatchConditionOpponentsPermanent(card, CanSelectCondition);
  139. }
  140. bool CanSelectCondition(Permanent permanent)
  141. => CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card);
  142. IEnumerator ActivateCoroutine(Hashtable hashtable)
  143. {
  144. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectCondition))
  145. {
  146. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectCondition));
  147. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  148. selectPermanentEffect.SetUp(
  149. selectPlayer: card.Owner,
  150. canTargetCondition: CanSelectCondition,
  151. canTargetCondition_ByPreSelecetedList: null,
  152. canEndSelectCondition: null,
  153. maxCount: maxCount,
  154. canNoSelect: false,
  155. canEndNotMax: false,
  156. selectPermanentCoroutine: null,
  157. afterSelectPermanentCoroutine: null,
  158. mode: SelectPermanentEffect.Mode.Destroy,
  159. cardEffect: activateClass);
  160. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  161. }
  162. }
  163. }
  164. #endregion
  165. #region All Turns - Remove Field
  166. if (timing == EffectTiming.WhenRemoveField)
  167. {
  168. List<Permanent> removedPermanents = new List<Permanent>();
  169. ActivateClass activateClass = new ActivateClass();
  170. activateClass.SetUpICardEffect("Place card as source", CanUseCondition, card);
  171. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDiscription());
  172. activateClass.SetHashString("BT22_007_Save");
  173. activateClass.SetIsInheritedEffect(true);
  174. cardEffects.Add(activateClass);
  175. string EffectDiscription()
  176. {
  177. return "[Breeding] [All Turns] [Once Per Turn] When any of your [Eater] trait Digimon would leave the battle area other than by your effects, you may place them as this Digimon's bottom digivolution cards.";
  178. }
  179. bool CanUseCondition(Hashtable hashtable)
  180. {
  181. return CardEffectCommons.CanTriggerWhenPermanentRemoveField(hashtable, IsEaterDigimon)
  182. && !CardEffectCommons.IsByEffect(hashtable, cardEffect => CardEffectCommons.IsOwnerEffect(cardEffect, card));
  183. }
  184. bool CanActivateCondition(Hashtable hashtable)
  185. {
  186. removedPermanents = CardEffectCommons.GetPermanentsFromHashtable(hashtable).Filter(IsEaterDigimon);
  187. return CardEffectCommons.IsExistOnBreedingArea(card)
  188. && removedPermanents.Some(permanent => CardEffectCommons.IsPermanentExistsOnBattleAreaDigimon(permanent));
  189. }
  190. bool IsEaterDigimon(Permanent permanent)
  191. {
  192. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card)
  193. && permanent.TopCard.HasEaterTraits;
  194. }
  195. IEnumerator ActivateCoroutine(Hashtable hashtable)
  196. {
  197. foreach (Permanent permanent in removedPermanents)
  198. {
  199. #region Remove Events from Permanent
  200. permanent.HideDeleteEffect();
  201. permanent.HideHandBounceEffect();
  202. permanent.HideDeckBounceEffect();
  203. permanent.HideWillRemoveFieldEffect();
  204. permanent.DestroyingEffect = null;
  205. permanent.IsDestroyedByBattle = false;
  206. permanent.HandBounceEffect = null;
  207. permanent.LibraryBounceEffect = null;
  208. permanent.willBeRemoveField = false;
  209. #endregion
  210. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(new List<CardSource>() { permanent.TopCard }, activateClass));
  211. }
  212. }
  213. }
  214. #endregion
  215. #region Remove Field - Reset DP
  216. if (timing == EffectTiming.OnRemovedField)
  217. {
  218. ActivateClass activateClass = new ActivateClass();
  219. activateClass.SetUpICardEffect("", CanUseCondition, card);
  220. activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, true, "");
  221. activateClass.SetIsBackgroundProcess(true);
  222. cardEffects.Add(activateClass);
  223. bool IsEaterDigimon(Permanent permanent)
  224. {
  225. return CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card)
  226. && permanent.TopCard.EqualsCardName("Mother Eater");
  227. }
  228. bool CanUseCondition(Hashtable hashtable)
  229. {
  230. return CardEffectCommons.CanTriggerWhenRemoveField(hashtable, card);
  231. }
  232. IEnumerator ActivateCoroutine(Hashtable hashtable)
  233. {
  234. List<Permanent> permanets = new List<Permanent>();
  235. if (CardEffectCommons.IsPermanentExistsOnBreedingArea(card.PermanentOfThisCard()))
  236. {
  237. permanets = card.Owner.GetBattleAreaDigimons()
  238. .Filter(IsEaterDigimon)
  239. .ToList();
  240. }
  241. else
  242. {
  243. permanets.Add(card.PermanentOfThisCard());
  244. }
  245. foreach (Permanent permanent in permanets)
  246. {
  247. #region Remove Events from Permanent
  248. permanent.TopCard.SetDP(0);
  249. #endregion
  250. }
  251. yield return null;
  252. }
  253. }
  254. #endregion
  255. return cardEffects;
  256. }
  257. }
  258. }