MedievalGallantmon_EX8_074.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace DCGO.CardEffects.EX8
  5. {
  6. public class MedievalGallantmon_EX8_074 : CEntity_Effect
  7. {
  8. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  9. {
  10. List<ICardEffect> cardEffects = new List<ICardEffect>();
  11. #region When Would be Played
  12. if (timing == EffectTiming.BeforePayCost)
  13. {
  14. ActivateClass activateClass = new ActivateClass();
  15. activateClass.SetUpICardEffect("Suspend 2 Digimon to get Play Cost -4", CanUseCondition, card);
  16. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDescription());
  17. activateClass.SetHashString("PlayCost-4_EX8_074");
  18. cardEffects.Add(activateClass);
  19. string EffectDescription()
  20. {
  21. return
  22. "When this card would be played, by suspending 2 Digimon, reduce the play cost by 4.";
  23. }
  24. bool CanUseCondition(Hashtable hashtable)
  25. {
  26. return CardEffectCommons.CanTriggerWhenPermanentWouldPlay(hashtable, CardCondition);
  27. }
  28. bool CardCondition(CardSource cardSource)
  29. {
  30. return cardSource == card && CardEffectCommons.IsExistOnHand(cardSource);
  31. }
  32. bool CanSelectPermanentCondition(Permanent permanent)
  33. {
  34. return CardEffectCommons.IsPermanentExistsOnBattleAreaDigimon(permanent) &&
  35. permanent != null &&
  36. permanent.TopCard &&
  37. !permanent.TopCard.CanNotBeAffected(activateClass) &&
  38. !permanent.IsSuspended && permanent.CanSuspend;
  39. }
  40. bool CanActivateCondition(Hashtable hashtable)
  41. {
  42. return CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition) >= 2;
  43. }
  44. IEnumerator ActivateCoroutine(Hashtable hashtable)
  45. {
  46. bool canNoSelect = true;
  47. CardSource cardFromHashtable = CardEffectCommons.GetCardFromHashtable(hashtable);
  48. if (cardFromHashtable && cardFromHashtable.PayingCost(SelectCardEffect.Root.Hand, null, checkAvailability: false) >
  49. cardFromHashtable.Owner.MaxMemoryCost)
  50. {
  51. canNoSelect = false;
  52. }
  53. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  54. selectPermanentEffect.SetUp(
  55. selectPlayer: card.Owner,
  56. canTargetCondition: CanSelectPermanentCondition,
  57. canTargetCondition_ByPreSelecetedList: null,
  58. canEndSelectCondition: null,
  59. maxCount: 2,
  60. canNoSelect: canNoSelect,
  61. canEndNotMax: false,
  62. selectPermanentCoroutine: null,
  63. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  64. mode: SelectPermanentEffect.Mode.Custom,
  65. cardEffect: activateClass);
  66. selectPermanentEffect.SetUpCustomMessage("Select 2 Digimon to suspend.",
  67. "The opponent is selecting 2 Digimon to suspend.");
  68. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  69. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  70. {
  71. if (permanents.Count == 2)
  72. {
  73. foreach (var selectedPermanent in permanents)
  74. {
  75. yield return ContinuousController.instance.StartCoroutine(
  76. new SuspendPermanentsClass(new List<Permanent>() { selectedPermanent },
  77. CardEffectCommons.CardEffectHashtable(activateClass)).Tap());
  78. }
  79. if (card.Owner.CanReduceCost(null, card))
  80. {
  81. ContinuousController.instance.PlaySE(GManager.instance.GetComponent<Effects>().BuffSE);
  82. }
  83. ChangeCostClass changeCostClass = new ChangeCostClass();
  84. changeCostClass.SetUpICardEffect("Play Cost -4", CanUseCondition1, card);
  85. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardSourceCondition,
  86. rootCondition: RootCondition, isUpDown: IsUpDown, isCheckAvailability: () => false,
  87. isChangePayingCost: () => true);
  88. card.Owner.UntilCalculateFixedCostEffect.Add(_ => changeCostClass);
  89. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.ShowReducedCost(hashtable));
  90. bool CanUseCondition1(Hashtable hashtable1)
  91. {
  92. return true;
  93. }
  94. int ChangeCost(CardSource cardSource, int cost, SelectCardEffect.Root root,
  95. List<Permanent> targetPermanents)
  96. {
  97. if (CardSourceCondition(cardSource) &&
  98. RootCondition(root) &&
  99. PermanentsCondition(targetPermanents))
  100. {
  101. cost -= 4;
  102. }
  103. return cost;
  104. }
  105. bool PermanentsCondition(List<Permanent> targetPermanents)
  106. {
  107. return targetPermanents == null || targetPermanents.Count(targetPermanent => targetPermanent != null) == 0;
  108. }
  109. bool CardSourceCondition(CardSource cardSource)
  110. {
  111. return cardSource == card;
  112. }
  113. bool RootCondition(SelectCardEffect.Root root)
  114. {
  115. return true;
  116. }
  117. bool IsUpDown()
  118. {
  119. return true;
  120. }
  121. }
  122. }
  123. }
  124. }
  125. #endregion
  126. #region Alliance
  127. if (timing == EffectTiming.OnAllyAttack)
  128. {
  129. cardEffects.Add(CardEffectFactory.AllianceSelfEffect(isInheritedEffect: false, card: card, condition: null));
  130. }
  131. #endregion
  132. #region Vortex
  133. if (timing == EffectTiming.OnEndTurn)
  134. {
  135. cardEffects.Add(CardEffectFactory.VortexSelfEffect(isInheritedEffect: false, card: card,
  136. condition: null));
  137. }
  138. #endregion
  139. #region When Digivolving
  140. if (timing == EffectTiming.OnEnterFieldAnyone)
  141. {
  142. ActivateClass activateClass = new ActivateClass();
  143. activateClass.SetUpICardEffect("Suspend 1 Digimon then Delete 1 Digimon", CanUseCondition, card);
  144. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDescription());
  145. cardEffects.Add(activateClass);
  146. string EffectDescription()
  147. {
  148. return
  149. "[When Digivolving] You may suspend 1 Digimon. Then, you may delete 1 of your opponent's 8000 DP or lower Digimon. For each other suspended Digimon, add 3000 to this DP deletion effect's maximum.";
  150. }
  151. bool CanUseCondition(Hashtable hashtable)
  152. {
  153. return CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  154. }
  155. bool CanSelectSuspendPermanentCondition(Permanent permanent)
  156. {
  157. return CardEffectCommons.IsPermanentExistsOnBattleAreaDigimon(permanent);
  158. }
  159. int DeletionMaxDP()
  160. {
  161. return 8000 + 3000 * CardEffectCommons.MatchConditionPermanentCount(permanent => permanent.IsSuspended);
  162. }
  163. bool CanSelectDeletePermanentCondition(Permanent permanent)
  164. {
  165. return CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card) &&
  166. permanent.DP <= card.Owner.MaxDP_DeleteEffect(DeletionMaxDP(), activateClass);
  167. }
  168. bool CanActivateCondition(Hashtable hashtable)
  169. {
  170. return CardEffectCommons.IsExistOnBattleAreaDigimon(card);
  171. }
  172. IEnumerator ActivateCoroutine(Hashtable hashtable)
  173. {
  174. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectSuspendPermanentCondition))
  175. {
  176. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  177. selectPermanentEffect.SetUp(
  178. selectPlayer: card.Owner,
  179. canTargetCondition: CanSelectSuspendPermanentCondition,
  180. canTargetCondition_ByPreSelecetedList: null,
  181. canEndSelectCondition: null,
  182. maxCount: 1,
  183. canNoSelect: true,
  184. canEndNotMax: false,
  185. selectPermanentCoroutine: null,
  186. afterSelectPermanentCoroutine: null,
  187. mode: SelectPermanentEffect.Mode.Tap,
  188. cardEffect: activateClass);
  189. selectPermanentEffect.SetUpCustomMessage(
  190. "Select 1 Digimon that will suspend.",
  191. "The opponent is selecting 1 Digimon that will suspend.");
  192. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  193. }
  194. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectDeletePermanentCondition))
  195. {
  196. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  197. selectPermanentEffect.SetUp(
  198. selectPlayer: card.Owner,
  199. canTargetCondition: CanSelectDeletePermanentCondition,
  200. canTargetCondition_ByPreSelecetedList: null,
  201. canEndSelectCondition: null,
  202. maxCount: 1,
  203. canNoSelect: false,
  204. canEndNotMax: false,
  205. selectPermanentCoroutine: null,
  206. afterSelectPermanentCoroutine: null,
  207. mode: SelectPermanentEffect.Mode.Destroy,
  208. cardEffect: activateClass);
  209. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  210. }
  211. }
  212. }
  213. #endregion
  214. #region All Turns
  215. if (timing == EffectTiming.OnEnterFieldAnyone)
  216. {
  217. ActivateClass activateClass = new ActivateClass();
  218. activateClass.SetUpICardEffect("Activate 1 of this Digimon's [When Digivolving] effects", CanUseCondition, card);
  219. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDescription());
  220. activateClass.SetHashString("PlayActivate_EX8_074");
  221. cardEffects.Add(activateClass);
  222. string EffectDescription()
  223. {
  224. return
  225. "[All Turns] (Once Per Turn) When Digimon are played, you may activate 1 of this Digimon's [When Digivolving] effects.";
  226. }
  227. bool PermanentCondition(Permanent permanent)
  228. {
  229. return CardEffectCommons.IsPermanentExistsOnBattleAreaDigimon(permanent);
  230. }
  231. bool CanUseCondition(Hashtable hashtable)
  232. {
  233. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) &&
  234. CardEffectCommons.CanTriggerOnPermanentPlay(hashtable, PermanentCondition);
  235. }
  236. bool CanActivateCondition(Hashtable hashtable)
  237. {
  238. return CardEffectCommons.IsExistOnBattleAreaDigimon(card);
  239. }
  240. IEnumerator ActivateCoroutine(Hashtable hashtable)
  241. {
  242. List<ICardEffect> candidateEffects = card.PermanentOfThisCard().EffectList(EffectTiming.OnEnterFieldAnyone)
  243. .Clone()
  244. .Filter(cardEffect =>
  245. cardEffect is ActivateICardEffect && !cardEffect.IsSecurityEffect && cardEffect.IsWhenDigivolving);
  246. if (candidateEffects.Count >= 1)
  247. {
  248. ICardEffect selectedEffect = null;
  249. if (candidateEffects.Count == 1)
  250. {
  251. selectedEffect = candidateEffects[0];
  252. }
  253. else
  254. {
  255. List<SkillInfo> skillInfos = candidateEffects
  256. .Map(cardEffect => new SkillInfo(cardEffect, null, EffectTiming.None));
  257. List<CardSource> cardSources = candidateEffects
  258. .Map(cardEffect => cardEffect.EffectSourceCard);
  259. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  260. selectCardEffect.SetUp(
  261. canTargetCondition: _ => true,
  262. canTargetCondition_ByPreSelecetedList: null,
  263. canEndSelectCondition: null,
  264. canNoSelect: () => false,
  265. selectCardCoroutine: null,
  266. afterSelectCardCoroutine: null,
  267. message: "Select 1 effect to activate.",
  268. maxCount: 1,
  269. canEndNotMax: false,
  270. isShowOpponent: false,
  271. mode: SelectCardEffect.Mode.Custom,
  272. root: SelectCardEffect.Root.Custom,
  273. customRootCardList: cardSources,
  274. canLookReverseCard: true,
  275. selectPlayer: card.Owner,
  276. cardEffect: activateClass);
  277. selectCardEffect.SetNotShowCard();
  278. selectCardEffect.SetUpSkillInfos(skillInfos);
  279. selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  280. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  281. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  282. {
  283. if (selectedIndexes.Count == 1)
  284. {
  285. selectedEffect = candidateEffects[selectedIndexes[0]];
  286. yield return null;
  287. }
  288. }
  289. }
  290. if (selectedEffect != null)
  291. {
  292. Hashtable effectHashtable =
  293. CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(selectedEffect.EffectSourceCard);
  294. yield return ContinuousController.instance.StartCoroutine(
  295. ((ActivateICardEffect)selectedEffect).Activate_Optional_Effect_Execute(effectHashtable));
  296. }
  297. }
  298. }
  299. }
  300. #endregion
  301. return cardEffects;
  302. }
  303. }
  304. }