P_214.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. // Betamon (X Antibody)
  6. namespace DCGO.CardEffects.P
  7. {
  8. public class P_214 : 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.EqualsCardName("Betamon") || targetPermanent.TopCard.EqualsCardName("ModokiBetamon");
  19. }
  20. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(
  21. permanentCondition: PermanentCondition,
  22. digivolutionCost: 0,
  23. ignoreDigivolutionRequirement: false,
  24. card: card,
  25. condition: null)
  26. );
  27. }
  28. #endregion
  29. #region Decode
  30. if (timing == EffectTiming.WhenRemoveField)
  31. {
  32. bool SourceCondition(CardSource source)
  33. {
  34. return source.EqualsCardName("Betamon") | source.EqualsCardName("ModokiBetamon");
  35. }
  36. string[] decodeStrings = { "(Betamon/ModokiBetamon)", "Betamon or ModokiBetamon" };
  37. cardEffects.Add(CardEffectFactory.DecodeSelfEffect(card: card, isInheritedEffect: false, decodeStrings: decodeStrings, sourceCondition: SourceCondition, condition: null));
  38. }
  39. #endregion
  40. #region Shared OP / WD
  41. string SharedEffectName() => "By placing this digimon as bottom source, bottom deck 1 Digimon";
  42. string SharedEffectDescription(string tag)
  43. {
  44. return $"[{tag}] By placing this Digimon as the bottom digivolution card of any of your other Digimon with [Seadramon] in its text, return 1 of your opponent's Digimon with as high or lower a level as 1 of your Digimon with [Seadramon] in its text to the bottom of the deck.";
  45. }
  46. bool SharedCanActivateCondition(Hashtable hashtable)
  47. {
  48. return CardEffectCommons.IsExistOnBattleArea(card) &&
  49. CardEffectCommons.HasMatchConditionPermanent(CanTuckTargetCondition);
  50. }
  51. bool CanTuckTargetCondition(Permanent permanent)
  52. {
  53. return CanSelectOwnSeadramonInName(permanent)
  54. && permanent != card.PermanentOfThisCard();
  55. }
  56. bool CanSelectOwnSeadramonInName(Permanent permanent)
  57. {
  58. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card)
  59. && permanent.TopCard.HasText("Seadramon");
  60. }
  61. bool CanSelectEnemyDigimon(Permanent permanent, int level)
  62. {
  63. return CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card) &&
  64. permanent.TopCard.HasLevel &&
  65. permanent.TopCard.Level <= level;
  66. }
  67. IEnumerator SharedActivateCoroutine(Hashtable hashtable, ActivateClass activateClass)
  68. {
  69. bool added = false;
  70. #region tuck this card under a Seadramon in Text
  71. if (CardEffectCommons.HasMatchConditionPermanent(CanTuckTargetCondition))
  72. {
  73. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanTuckTargetCondition));
  74. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  75. selectPermanentEffect.SetUp(
  76. selectPlayer: card.Owner,
  77. canTargetCondition: CanTuckTargetCondition,
  78. canTargetCondition_ByPreSelecetedList: null,
  79. canEndSelectCondition: null,
  80. maxCount: maxCount,
  81. canNoSelect: false,
  82. canEndNotMax: false,
  83. selectPermanentCoroutine: SelectPermanentCoroutine,
  84. afterSelectPermanentCoroutine: null,
  85. mode: SelectPermanentEffect.Mode.Custom,
  86. cardEffect: activateClass);
  87. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon that will get a digivolution card.", "The opponent is selecting 1 Digimon that will get a digivolution card.");
  88. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  89. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  90. {
  91. Permanent selectedPermanent = permanent;
  92. if (selectedPermanent != null)
  93. {
  94. yield return ContinuousController.instance.StartCoroutine(new IPlacePermanentToDigivolutionCards(new List<Permanent[]>() { new Permanent[] { card.PermanentOfThisCard(), selectedPermanent } }, false, activateClass).PlacePermanentToDigivolutionCards());
  95. if (CardEffectCommons.IsExistOnBattleArea(card))
  96. {
  97. if (selectedPermanent.DigivolutionCards.Contains(card))
  98. {
  99. added = true;
  100. }
  101. }
  102. }
  103. }
  104. }
  105. #endregion
  106. int level = -1;
  107. #region Select a Seadramon in name to set level
  108. if (added)
  109. {
  110. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectOwnSeadramonInName));
  111. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  112. selectPermanentEffect.SetUp(
  113. selectPlayer: card.Owner,
  114. canTargetCondition: CanSelectOwnSeadramonInName,
  115. canTargetCondition_ByPreSelecetedList: null,
  116. canEndSelectCondition: null,
  117. maxCount: maxCount,
  118. canNoSelect: false,
  119. canEndNotMax: false,
  120. selectPermanentCoroutine: SelectPermanentCoroutine,
  121. afterSelectPermanentCoroutine: null,
  122. mode: SelectPermanentEffect.Mode.Custom,
  123. cardEffect: activateClass);
  124. selectPermanentEffect.SetUpCustomMessage("Select 1 of your Digimon to use to compare levels.", "The opponent is selecting 1 of their Digimon to use to compare levels.");
  125. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  126. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  127. {
  128. Permanent selectedPermanent = permanent;
  129. if (selectedPermanent != null)
  130. {
  131. level = selectedPermanent.TopCard.Level;
  132. }
  133. yield return null;
  134. }
  135. }
  136. #endregion
  137. #region Bottom Deck opponent digimon
  138. if (level > 0)
  139. {
  140. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount((permanent) => CanSelectEnemyDigimon(permanent, level)));
  141. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  142. selectPermanentEffect.SetUp(
  143. selectPlayer: card.Owner,
  144. canTargetCondition: (permanent) => CanSelectEnemyDigimon(permanent, level),
  145. canTargetCondition_ByPreSelecetedList: null,
  146. canEndSelectCondition: null,
  147. maxCount: maxCount,
  148. canNoSelect: false,
  149. canEndNotMax: false,
  150. selectPermanentCoroutine: SelectPermanentCoroutine,
  151. afterSelectPermanentCoroutine: null,
  152. mode: SelectPermanentEffect.Mode.Custom,
  153. cardEffect: activateClass);
  154. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to dottom deck.", "The opponent is selecting 1 Digimon to bottom deck.");
  155. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  156. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  157. {
  158. yield return ContinuousController.instance.StartCoroutine(new DeckBottomBounceClass(new List<Permanent>() { permanent }, hashtable).DeckBounce());
  159. }
  160. }
  161. #endregion
  162. }
  163. #endregion
  164. #region On Play
  165. if (timing == EffectTiming.OnEnterFieldAnyone)
  166. {
  167. ActivateClass activateClass = new ActivateClass();
  168. activateClass.SetUpICardEffect(SharedEffectName(), CanUseCondition, card);
  169. activateClass.SetUpActivateClass(SharedCanActivateCondition, (hash) => SharedActivateCoroutine(hash, activateClass), -1, true, SharedEffectDescription("On Play"));
  170. cardEffects.Add(activateClass);
  171. bool CanUseCondition(Hashtable hashtable)
  172. {
  173. return CardEffectCommons.CanTriggerOnPlay(hashtable, card);
  174. }
  175. }
  176. #endregion
  177. #region When Digivolving
  178. if (timing == EffectTiming.OnEnterFieldAnyone)
  179. {
  180. ActivateClass activateClass = new ActivateClass();
  181. activateClass.SetUpICardEffect(SharedEffectName(), CanUseCondition, card);
  182. activateClass.SetUpActivateClass(SharedCanActivateCondition, (hash) => SharedActivateCoroutine(hash, activateClass), -1, true, SharedEffectDescription("When Digivolving"));
  183. cardEffects.Add(activateClass);
  184. bool CanUseCondition(Hashtable hashtable)
  185. {
  186. return CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  187. }
  188. }
  189. #endregion
  190. #region ESS
  191. if (timing == EffectTiming.WhenRemoveField)
  192. {
  193. ActivateClass activateClass = new ActivateClass();
  194. activateClass.SetUpICardEffect("Prevent this Digimon from leaving the battle area by trashing 2 same-level digivolution cards.", CanUseCondition, card);
  195. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  196. activateClass.SetIsInheritedEffect(true);
  197. activateClass.SetHashString("Substitute_P_214");
  198. cardEffects.Add(activateClass);
  199. string EffectDiscription()
  200. => "[All Turns] When this Digimon with [Seadramon] in its text would leave the battle area by your opponent's effects, by trashing 2 same-level cards in its digivolution cards, it doesn't leave.";
  201. bool CanSelectCardCondition(CardSource cardSource)
  202. {
  203. if (!cardSource.CanNotTrashFromDigivolutionCards(activateClass) &&
  204. cardSource.HasLevel &&
  205. CardEffectCommons.IsExistOnBattleArea(card) &&
  206. card.PermanentOfThisCard().DigivolutionCards.Contains(card))
  207. {
  208. foreach (CardSource cardSource1 in card.PermanentOfThisCard().DigivolutionCards)
  209. {
  210. if (cardSource != cardSource1 &&
  211. cardSource1.HasLevel &&
  212. !cardSource1.CanNotTrashFromDigivolutionCards(activateClass) &&
  213. cardSource.Level == cardSource1.Level)
  214. {
  215. return true;
  216. }
  217. }
  218. }
  219. return false;
  220. }
  221. bool CanUseCondition(Hashtable hashtable)
  222. {
  223. return CardEffectCommons.IsExistOnBattleArea(card) &&
  224. CardEffectCommons.CanTriggerWhenRemoveField(hashtable, card) &&
  225. CardEffectCommons.IsByEffect(hashtable, cardEffect => CardEffectCommons.IsOpponentEffect(cardEffect, card)) &&
  226. card.PermanentOfThisCard().TopCard.HasText("Seadramon");
  227. }
  228. bool CanActivateCondition(Hashtable hashtable)
  229. {
  230. return CardEffectCommons.IsExistOnBattleArea(card) &&
  231. card.PermanentOfThisCard().DigivolutionCards.Any(CanSelectCardCondition);
  232. }
  233. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  234. {
  235. if (CardEffectCommons.IsExistOnBattleArea(card))
  236. {
  237. Permanent selectedPermanent = card.PermanentOfThisCard();
  238. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  239. {
  240. List<CardSource> selectedCards = new List<CardSource>();
  241. int maxCount = 2;
  242. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  243. selectCardEffect.SetUp(
  244. canTargetCondition: CanSelectCardCondition,
  245. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  246. canEndSelectCondition: CanEndSelectCondition,
  247. canNoSelect: () => true,
  248. selectCardCoroutine: SelectCardCoroutine,
  249. afterSelectCardCoroutine: null,
  250. message: "Select cards to discard.",
  251. maxCount: maxCount,
  252. canEndNotMax: false,
  253. isShowOpponent: true,
  254. mode: SelectCardEffect.Mode.Custom,
  255. root: SelectCardEffect.Root.DigivolutionCards,
  256. customRootCardList: selectedPermanent.DigivolutionCards,
  257. canLookReverseCard: true,
  258. selectPlayer: card.Owner,
  259. cardEffect: activateClass);
  260. selectCardEffect.SetNotShowCard();
  261. yield return StartCoroutine(selectCardEffect.Activate());
  262. bool CanEndSelectCondition(List<CardSource> cardSources)
  263. {
  264. if (CardEffectCommons.HasNoElement(cardSources))
  265. {
  266. return false;
  267. }
  268. List<int> levels = cardSources
  269. .Map(cardSource1 => cardSource1.Level)
  270. .Distinct()
  271. .ToList();
  272. if (levels.Count > 1)
  273. {
  274. return false;
  275. }
  276. return true;
  277. }
  278. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  279. {
  280. List<int> levels = cardSources
  281. .Map(cardSource1 => cardSource1.Level)
  282. .Concat(new List<int>() { cardSource.Level })
  283. .Distinct()
  284. .ToList();
  285. if (levels.Count > 1)
  286. {
  287. return false;
  288. }
  289. return true;
  290. }
  291. IEnumerator SelectCardCoroutine(CardSource cardSource)
  292. {
  293. selectedCards.Add(cardSource);
  294. yield return null;
  295. }
  296. if (selectedCards.Count >= 1)
  297. {
  298. if (selectedCards.Count == 2)
  299. {
  300. selectedPermanent.HideDeleteEffect();
  301. selectedPermanent.HideHandBounceEffect();
  302. selectedPermanent.HideDeckBounceEffect();
  303. selectedPermanent.HideWillRemoveFieldEffect();
  304. selectedPermanent.DestroyingEffect = null;
  305. selectedPermanent.HandBounceEffect = null;
  306. selectedPermanent.LibraryBounceEffect = null;
  307. selectedPermanent.willBeRemoveField = false;
  308. }
  309. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  310. selectedPermanent,
  311. selectedCards,
  312. activateClass).TrashDigivolutionCards());
  313. }
  314. }
  315. }
  316. }
  317. }
  318. #endregion
  319. return cardEffects;
  320. }
  321. }
  322. }