P_094.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. // Destromon
  6. public class P_094 : CEntity_Effect
  7. {
  8. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  9. {
  10. List<ICardEffect> cardEffects = new List<ICardEffect>();
  11. #region DigiXros
  12. if (timing == EffectTiming.None)
  13. {
  14. AddDigiXrosConditionClass addDigiXrosConditionClass = new AddDigiXrosConditionClass();
  15. addDigiXrosConditionClass.SetUpICardEffect($"DigiXros", CanUseCondition, card);
  16. addDigiXrosConditionClass.SetUpAddDigiXrosConditionClass(getDigiXrosCondition: GetDigiXros);
  17. addDigiXrosConditionClass.SetNotShowUI(true);
  18. cardEffects.Add(addDigiXrosConditionClass);
  19. bool CanUseCondition(Hashtable hashtable)
  20. {
  21. return true;
  22. }
  23. DigiXrosCondition GetDigiXros(CardSource cardSource)
  24. {
  25. if (cardSource == card)
  26. {
  27. List<DigiXrosConditionElement> elements = new List<DigiXrosConditionElement>();
  28. DigiXrosConditionElement element = new DigiXrosConditionElement(CanSelectCardCondition, "Snatchmon");
  29. bool CanSelectCardCondition(CardSource cardSource)
  30. {
  31. return cardSource != null
  32. && cardSource.Owner == card.Owner
  33. && cardSource.IsDigimon
  34. && cardSource.CardNames_DigiXros.Contains("Snatchmon");
  35. }
  36. elements.Add(element);
  37. DigiXrosConditionElement element1 = new DigiXrosConditionElement(CanSelectCardCondition1, "Vemmon");
  38. bool CanSelectCardCondition1(CardSource cardSource)
  39. {
  40. return cardSource != null
  41. && cardSource.Owner == card.Owner
  42. && cardSource.IsDigimon
  43. && cardSource.CardNames_DigiXros.Contains("Vemmon");
  44. }
  45. for (int i = 0; i < 4; i++)
  46. {
  47. elements.Add(element1);
  48. }
  49. DigiXrosCondition digiXrosCondition = new DigiXrosCondition(elements, null, 1);
  50. return digiXrosCondition;
  51. }
  52. return null;
  53. }
  54. }
  55. #endregion
  56. #region Deletion Play Cost Calculation and Update
  57. int maxCost()
  58. {
  59. int maxCost = 3;
  60. if (CardEffectCommons.IsExistOnBattleArea(card))
  61. {
  62. maxCost += card.PermanentOfThisCard().DigivolutionCards.Count((cardSource) => cardSource.EqualsCardName("Vemmon"));
  63. }
  64. return maxCost;
  65. }
  66. #endregion
  67. #region Shared OP/WD
  68. string SharedEffectName() => $"Delete Digimon and/or Tamer(s) up to play cost of 3 + 1 per [Vemmon] in digivolution sources.";
  69. // for when we get it to update when we add sources to stack - $"Delete Digimon and/or Tamer(s) up to play cost of {maxCost()}."
  70. string SharedEffectDescription(string tag) => $"[{tag}] Delete your opponent's Digimon and Tamers with a total play cost of 3. For every [Vemmon] in this Digimon's digivolution cards, increase the maximum play cost you can choose by this effect by 1.";
  71. bool SharedCanActivateCondition(Hashtable hashtable)
  72. {
  73. return CardEffectCommons.IsExistOnBattleArea(card)
  74. && card.Owner.Enemy.GetBattleAreaPermanents().Count(SharedCanSelectPermanentCondition) >= 1;
  75. }
  76. bool SharedCanSelectPermanentCondition(Permanent permanent)
  77. {
  78. return CardEffectCommons.IsPermanentExistsOnOpponentBattleArea(permanent, card)
  79. && (permanent.IsDigimon
  80. || permanent.IsTamer)
  81. && permanent.TopCard.HasPlayCost
  82. && permanent.TopCard.GetCostItself <= maxCost();
  83. }
  84. IEnumerator SharedActivateCoroutine(Hashtable hashtable, ActivateClass activateClass)
  85. {
  86. if (card.Owner.Enemy.GetBattleAreaPermanents().Count(SharedCanSelectPermanentCondition) == 1)
  87. {
  88. List<Permanent> targetPermanent = card.Owner.Enemy.GetBattleAreaPermanents().Filter(SharedCanSelectPermanentCondition);
  89. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(targetPermanent, CardEffectCommons.CardEffectHashtable(activateClass)).Destroy());
  90. }
  91. else if (card.Owner.Enemy.GetBattleAreaPermanents().Count(SharedCanSelectPermanentCondition) >= 1)
  92. {
  93. List<Permanent> selectedPermanents = new List<Permanent>();
  94. int maxCount = card.Owner.Enemy.GetBattleAreaPermanents().Count(SharedCanSelectPermanentCondition);
  95. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  96. selectPermanentEffect.SetUp(
  97. selectPlayer: card.Owner,
  98. canTargetCondition: SharedCanSelectPermanentCondition,
  99. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  100. canEndSelectCondition: CanEndSelectCondition,
  101. maxCount: maxCount,
  102. canNoSelect: false,
  103. canEndNotMax: true,
  104. selectPermanentCoroutine: null,
  105. afterSelectPermanentCoroutine: null,
  106. mode: SelectPermanentEffect.Mode.Destroy,
  107. cardEffect: activateClass);
  108. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  109. bool CanEndSelectCondition(List<Permanent> permanents)
  110. {
  111. if (permanents.Count <= 0)
  112. {
  113. return false;
  114. }
  115. int sumCost = 0;
  116. foreach (Permanent permanent1 in permanents)
  117. {
  118. sumCost += permanent1.TopCard.GetCostItself;
  119. }
  120. if (sumCost > maxCost())
  121. {
  122. return false;
  123. }
  124. return true;
  125. }
  126. bool CanTargetCondition_ByPreSelecetedList(List<Permanent> permanents, Permanent permanent)
  127. {
  128. int sumCost = 0;
  129. foreach (Permanent permanent1 in permanents)
  130. {
  131. sumCost += permanent1.TopCard.GetCostItself;
  132. }
  133. sumCost += permanent.TopCard.GetCostItself;
  134. if (sumCost > maxCost())
  135. {
  136. return false;
  137. }
  138. return true;
  139. }
  140. }
  141. }
  142. #endregion
  143. #region On Play
  144. if (timing == EffectTiming.OnEnterFieldAnyone)
  145. {
  146. ActivateClass activateClass = new ActivateClass();
  147. activateClass.SetUpICardEffect(SharedEffectName(), CanUseCondition, card);
  148. activateClass.SetUpActivateClass(SharedCanActivateCondition, hash => SharedActivateCoroutine(hash, activateClass), -1, false, SharedEffectDescription("On Play"));
  149. cardEffects.Add(activateClass);
  150. bool CanUseCondition(Hashtable hashtable)
  151. {
  152. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  153. && CardEffectCommons.CanTriggerOnPlay(hashtable, card);
  154. }
  155. }
  156. #endregion
  157. #region When Digivolving
  158. if (timing == EffectTiming.OnEnterFieldAnyone)
  159. {
  160. ActivateClass activateClass = new ActivateClass();
  161. activateClass.SetUpICardEffect(SharedEffectName(), CanUseCondition, card);
  162. activateClass.SetUpActivateClass(SharedCanActivateCondition, hash => SharedActivateCoroutine(hash, activateClass), -1, false, SharedEffectDescription("When Digivolving"));
  163. cardEffects.Add(activateClass);
  164. bool CanUseCondition(Hashtable hashtable)
  165. {
  166. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  167. && CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  168. }
  169. }
  170. #endregion
  171. #region Inherited Effect: Switch Attack Target
  172. if (timing == EffectTiming.OnAllyAttack)
  173. {
  174. ActivateClass activateClass = new ActivateClass();
  175. activateClass.SetUpICardEffect("Return 2 [Vemmon] from [Galacticmon]'s digivolution cards to the deck bottom to switch attack target to this Digimon", CanUseCondition, card);
  176. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDiscription());
  177. activateClass.SetIsInheritedEffect(true);
  178. activateClass.SetHashString("SwitchAttackTarget_P_094");
  179. cardEffects.Add(activateClass);
  180. string EffectDiscription()
  181. {
  182. return "[Opponent's Turn] [Once Per Turn] When an opponent's Digimon attacks, by placing 2 [Vemmon] from 1 of your [Galacticmon]'s digivolution cards at the bottom of their owners' decks, switch the target of attack to this Digimon.";
  183. }
  184. bool CanSelectCardCondition(CardSource cardSource)
  185. {
  186. return cardSource.CardNames.Contains("Vemmon");
  187. }
  188. bool CanSelectPermanentCondition(Permanent permanent)
  189. {
  190. return CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card)
  191. && permanent.TopCard.CardNames.Contains("Galacticmon")
  192. && permanent.DigivolutionCards.Count(CanSelectCardCondition) >= 2;
  193. }
  194. bool PermanentCondition(Permanent permanent)
  195. {
  196. return CardEffectCommons.IsOpponentPermanent(permanent, card);
  197. }
  198. bool CanUseCondition(Hashtable hashtable)
  199. {
  200. return CardEffectCommons.IsExistOnBattleArea(card)
  201. && CardEffectCommons.IsOpponentTurn(card)
  202. && CardEffectCommons.CanTriggerOnPermanentAttack(hashtable, PermanentCondition);
  203. }
  204. bool CanActivateCondition(Hashtable hashtable)
  205. {
  206. return CardEffectCommons.IsExistOnBattleArea(card)
  207. && card.Owner.GetBattleAreaPermanents().Count(CanSelectPermanentCondition) >= 1;
  208. }
  209. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  210. {
  211. Permanent selectedPermanent = null;
  212. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  213. {
  214. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  215. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  216. selectPermanentEffect.SetUp(
  217. selectPlayer: card.Owner,
  218. canTargetCondition: CanSelectPermanentCondition,
  219. canTargetCondition_ByPreSelecetedList: null,
  220. canEndSelectCondition: null,
  221. maxCount: maxCount,
  222. canNoSelect: false,
  223. canEndNotMax: false,
  224. selectPermanentCoroutine: SelectPermanentCoroutine,
  225. afterSelectPermanentCoroutine: null,
  226. mode: SelectPermanentEffect.Mode.Custom,
  227. cardEffect: activateClass);
  228. selectPermanentEffect.SetUpCustomMessage("Select 1 [Galacticmon].", "The opponent is selecting 1 [Galacticmon].");
  229. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  230. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  231. {
  232. selectedPermanent = permanent;
  233. yield return null;
  234. }
  235. }
  236. if (selectedPermanent != null)
  237. {
  238. List<CardSource> selectedCards = new List<CardSource>();
  239. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  240. {
  241. int maxCount = 2;
  242. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  243. selectCardEffect.SetUp(
  244. canTargetCondition: CanSelectCardCondition,
  245. canTargetCondition_ByPreSelecetedList: null,
  246. canEndSelectCondition: null,
  247. canNoSelect: () => false,
  248. selectCardCoroutine: SelectCardCoroutine,
  249. afterSelectCardCoroutine: null,
  250. message: "Select 2 [Vemmon] that will return to the bottom of deck\n(cards will be placed back to the bottom of the deck so that cards with lower numbers are on top).",
  251. maxCount: maxCount,
  252. canEndNotMax: false,
  253. isShowOpponent: true,
  254. mode: SelectCardEffect.Mode.Custom,
  255. root: SelectCardEffect.Root.Custom,
  256. customRootCardList: selectedPermanent.DigivolutionCards,
  257. canLookReverseCard: true,
  258. selectPlayer: card.Owner,
  259. cardEffect: activateClass);
  260. selectCardEffect.SetUpCustomMessage("Select digivolution cards to return to the bottom of deck.", "The opponent is selecting digivolution cards to return to the bottom of deck.");
  261. selectCardEffect.SetNotShowCard();
  262. yield return StartCoroutine(selectCardEffect.Activate());
  263. IEnumerator SelectCardCoroutine(CardSource cardSource)
  264. {
  265. selectedCards.Add(cardSource);
  266. yield return null;
  267. }
  268. if (selectedCards.Count >= 1)
  269. {
  270. yield return ContinuousController.instance.StartCoroutine(new ReturnToLibraryBottomDigivolutionCardsClass(selectedPermanent, selectedCards, CardEffectCommons.CardEffectHashtable(activateClass)).ReturnToLibraryBottomDigivolutionCards());
  271. if (selectedCards.Count == 2 && CardEffectCommons.IsExistOnBattleArea(card))
  272. {
  273. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SwitchDefender(activateClass, false, card.PermanentOfThisCard()));
  274. }
  275. }
  276. }
  277. }
  278. }
  279. }
  280. #endregion
  281. return cardEffects;
  282. }
  283. }