EX5_062.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. public class EX5_062 : CEntity_Effect
  6. {
  7. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  8. {
  9. List<ICardEffect> cardEffects = new List<ICardEffect>();
  10. if (timing == EffectTiming.OnEnterFieldAnyone)
  11. {
  12. ActivateClass activateClass = new ActivateClass();
  13. activateClass.SetUpICardEffect("Trash cards from hand and play 1 Digimon from trash", CanUseCondition, card);
  14. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, false, EffectDiscription());
  15. activateClass.SetHashString("PlayDigimon_EX5_062");
  16. cardEffects.Add(activateClass);
  17. string EffectDiscription()
  18. {
  19. return "[When Digivolving] [Once Per Turn] You may trash up to 3 cards from your hand. Then, play 1 purple Digimon card from your trash with the play cost reduced by 3. For each card trashed by this effect, further reduce it by 1.";
  20. }
  21. bool CanSelectCardCondition(CardSource cardSource)
  22. {
  23. if (cardSource.IsDigimon)
  24. {
  25. if (cardSource.HasCardColor(CardColor.Purple))
  26. {
  27. if (CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: true, cardEffect: activateClass))
  28. {
  29. return true;
  30. }
  31. }
  32. }
  33. return false;
  34. }
  35. bool CanUseCondition(Hashtable hashtable)
  36. {
  37. return CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  38. }
  39. bool CanActivateCondition(Hashtable hashtable)
  40. {
  41. if (CardEffectCommons.IsExistOnBattleArea(card))
  42. {
  43. return true;
  44. }
  45. return false;
  46. }
  47. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  48. {
  49. int discadedCount = 0;
  50. if (card.Owner.HandCards.Count >= 1)
  51. {
  52. int discardCount = Math.Min(3, card.Owner.HandCards.Count);
  53. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  54. selectHandEffect.SetUp(
  55. selectPlayer: card.Owner,
  56. canTargetCondition: cardSource => true,
  57. canTargetCondition_ByPreSelecetedList: null,
  58. canEndSelectCondition: CanEndSelectCondition,
  59. maxCount: discardCount,
  60. canNoSelect: true,
  61. canEndNotMax: true,
  62. isShowOpponent: true,
  63. selectCardCoroutine: null,
  64. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  65. mode: SelectHandEffect.Mode.Discard,
  66. cardEffect: activateClass);
  67. yield return StartCoroutine(selectHandEffect.Activate());
  68. bool CanEndSelectCondition(List<CardSource> cardSources)
  69. {
  70. if (CardEffectCommons.HasNoElement(cardSources))
  71. {
  72. return false;
  73. }
  74. return true;
  75. }
  76. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  77. {
  78. discadedCount += cardSources.Count;
  79. yield return null;
  80. }
  81. }
  82. int reduceCost = 3 + discadedCount;
  83. #region reduce play cost
  84. ChangeCostClass changeCostClass = new ChangeCostClass();
  85. changeCostClass.SetUpICardEffect($"Play Cost -{reduceCost}", CanUseCondition1, card);
  86. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardSourceCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  87. Func<EffectTiming, ICardEffect> getCardEffect = GetCardEffect;
  88. card.Owner.UntilCalculateFixedCostEffect.Add(getCardEffect);
  89. ICardEffect GetCardEffect(EffectTiming _timing)
  90. {
  91. if (_timing == EffectTiming.None)
  92. {
  93. return changeCostClass;
  94. }
  95. return null;
  96. }
  97. bool CanUseCondition1(Hashtable hashtable)
  98. {
  99. return true;
  100. }
  101. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  102. {
  103. if (CardSourceCondition(cardSource))
  104. {
  105. if (RootCondition(root))
  106. {
  107. if (PermanentsCondition(targetPermanents))
  108. {
  109. Cost -= reduceCost;
  110. }
  111. }
  112. }
  113. return Cost;
  114. }
  115. bool PermanentsCondition(List<Permanent> targetPermanents)
  116. {
  117. if (targetPermanents == null)
  118. {
  119. return true;
  120. }
  121. else
  122. {
  123. if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
  124. {
  125. return true;
  126. }
  127. }
  128. return false;
  129. }
  130. bool CardSourceCondition(CardSource cardSource)
  131. {
  132. if (cardSource.IsDigimon)
  133. {
  134. if (cardSource.HasCardColor(CardColor.Purple))
  135. {
  136. return true;
  137. }
  138. }
  139. return false;
  140. }
  141. bool RootCondition(SelectCardEffect.Root root)
  142. {
  143. return true;
  144. }
  145. bool isUpDown()
  146. {
  147. return true;
  148. }
  149. #endregion
  150. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanSelectCardCondition))
  151. {
  152. int maxCount = Math.Min(1, card.Owner.TrashCards.Count(CanSelectCardCondition));
  153. List<CardSource> selectedCards = new List<CardSource>();
  154. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  155. selectCardEffect.SetUp(
  156. canTargetCondition: CanSelectCardCondition,
  157. canTargetCondition_ByPreSelecetedList: null,
  158. canEndSelectCondition: null,
  159. canNoSelect: () => false,
  160. selectCardCoroutine: SelectCardCoroutine,
  161. afterSelectCardCoroutine: null,
  162. message: "Select 1 card to play.",
  163. maxCount: maxCount,
  164. canEndNotMax: false,
  165. isShowOpponent: true,
  166. mode: SelectCardEffect.Mode.Custom,
  167. root: SelectCardEffect.Root.Trash,
  168. customRootCardList: null,
  169. canLookReverseCard: true,
  170. selectPlayer: card.Owner,
  171. cardEffect: activateClass);
  172. selectCardEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  173. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  174. yield return StartCoroutine(selectCardEffect.Activate());
  175. IEnumerator SelectCardCoroutine(CardSource cardSource)
  176. {
  177. selectedCards.Add(cardSource);
  178. yield return null;
  179. }
  180. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  181. cardSources: selectedCards,
  182. activateClass: activateClass,
  183. payCost: true,
  184. isTapped: false,
  185. root: SelectCardEffect.Root.Trash,
  186. activateETB: true));
  187. }
  188. #region release effect reducing play cost
  189. card.Owner.UntilCalculateFixedCostEffect.Remove(getCardEffect);
  190. #endregion
  191. }
  192. }
  193. if (timing == EffectTiming.OnDeclaration)
  194. {
  195. ActivateClass activateClass = new ActivateClass();
  196. activateClass.SetUpICardEffect("Trash cards from hand and play 1 Digimon from trash", CanUseCondition, card);
  197. activateClass.SetUpActivateClass(null, ActivateCoroutine, 1, false, EffectDiscription());
  198. activateClass.SetHashString("PlayDigimon_EX5_062");
  199. cardEffects.Add(activateClass);
  200. string EffectDiscription()
  201. {
  202. return "[Main] [Once Per Turn] You may trash up to 3 cards from your hand. Then, play 1 purple Digimon card from your trash with the play cost reduced by 3. For each card trashed by this effect, further reduce it by 1.";
  203. }
  204. bool CanSelectCardCondition(CardSource cardSource)
  205. {
  206. if (cardSource.IsDigimon)
  207. {
  208. if (CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: true, cardEffect: activateClass))
  209. {
  210. if (cardSource.HasCardColor(CardColor.Purple))
  211. {
  212. return true;
  213. }
  214. }
  215. }
  216. return false;
  217. }
  218. bool CanUseCondition(Hashtable hashtable)
  219. {
  220. if (CardEffectCommons.IsExistOnBattleArea(card))
  221. {
  222. if (card.Owner.HandCards.Count >= 1)
  223. {
  224. return true;
  225. }
  226. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanSelectCardCondition))
  227. {
  228. return true;
  229. }
  230. }
  231. return false;
  232. }
  233. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  234. {
  235. int discadedCount = 0;
  236. if (card.Owner.HandCards.Count >= 1)
  237. {
  238. int discardCount = Math.Min(3, card.Owner.HandCards.Count);
  239. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  240. selectHandEffect.SetUp(
  241. selectPlayer: card.Owner,
  242. canTargetCondition: cardSource => true,
  243. canTargetCondition_ByPreSelecetedList: null,
  244. canEndSelectCondition: CanEndSelectCondition,
  245. maxCount: discardCount,
  246. canNoSelect: true,
  247. canEndNotMax: true,
  248. isShowOpponent: true,
  249. selectCardCoroutine: null,
  250. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  251. mode: SelectHandEffect.Mode.Discard,
  252. cardEffect: activateClass);
  253. yield return StartCoroutine(selectHandEffect.Activate());
  254. bool CanEndSelectCondition(List<CardSource> cardSources)
  255. {
  256. if (CardEffectCommons.HasNoElement(cardSources))
  257. {
  258. return false;
  259. }
  260. return true;
  261. }
  262. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  263. {
  264. discadedCount += cardSources.Count;
  265. yield return null;
  266. }
  267. }
  268. int reduceCost = 3 + discadedCount;
  269. #region reduce play cost
  270. ChangeCostClass changeCostClass = new ChangeCostClass();
  271. changeCostClass.SetUpICardEffect($"Play Cost -{reduceCost}", CanUseCondition1, card);
  272. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardSourceCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  273. Func<EffectTiming, ICardEffect> getCardEffect = GetCardEffect;
  274. card.Owner.UntilCalculateFixedCostEffect.Add(getCardEffect);
  275. ICardEffect GetCardEffect(EffectTiming _timing)
  276. {
  277. if (_timing == EffectTiming.None)
  278. {
  279. return changeCostClass;
  280. }
  281. return null;
  282. }
  283. bool CanUseCondition1(Hashtable hashtable)
  284. {
  285. return true;
  286. }
  287. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  288. {
  289. if (CardSourceCondition(cardSource))
  290. {
  291. if (RootCondition(root))
  292. {
  293. if (PermanentsCondition(targetPermanents))
  294. {
  295. Cost -= reduceCost;
  296. }
  297. }
  298. }
  299. return Cost;
  300. }
  301. bool PermanentsCondition(List<Permanent> targetPermanents)
  302. {
  303. if (targetPermanents == null)
  304. {
  305. return true;
  306. }
  307. else
  308. {
  309. if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
  310. {
  311. return true;
  312. }
  313. }
  314. return false;
  315. }
  316. bool CardSourceCondition(CardSource cardSource)
  317. {
  318. if (cardSource != null)
  319. {
  320. if (cardSource.Owner == card.Owner)
  321. {
  322. if (cardSource.HasCardColor(CardColor.Purple))
  323. {
  324. return true;
  325. }
  326. }
  327. }
  328. return false;
  329. }
  330. bool RootCondition(SelectCardEffect.Root root)
  331. {
  332. return true;
  333. }
  334. bool isUpDown()
  335. {
  336. return true;
  337. }
  338. #endregion
  339. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanSelectCardCondition))
  340. {
  341. int maxCount = Math.Min(1, card.Owner.TrashCards.Count(CanSelectCardCondition));
  342. List<CardSource> selectedCards = new List<CardSource>();
  343. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  344. selectCardEffect.SetUp(
  345. canTargetCondition: CanSelectCardCondition,
  346. canTargetCondition_ByPreSelecetedList: null,
  347. canEndSelectCondition: null,
  348. canNoSelect: () => false,
  349. selectCardCoroutine: SelectCardCoroutine,
  350. afterSelectCardCoroutine: null,
  351. message: "Select 1 card to play.",
  352. maxCount: maxCount,
  353. canEndNotMax: false,
  354. isShowOpponent: true,
  355. mode: SelectCardEffect.Mode.Custom,
  356. root: SelectCardEffect.Root.Trash,
  357. customRootCardList: null,
  358. canLookReverseCard: true,
  359. selectPlayer: card.Owner,
  360. cardEffect: activateClass);
  361. selectCardEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  362. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  363. yield return StartCoroutine(selectCardEffect.Activate());
  364. IEnumerator SelectCardCoroutine(CardSource cardSource)
  365. {
  366. selectedCards.Add(cardSource);
  367. yield return null;
  368. }
  369. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  370. cardSources: selectedCards,
  371. activateClass: activateClass,
  372. payCost: true,
  373. isTapped: false,
  374. root: SelectCardEffect.Root.Trash,
  375. activateETB: true));
  376. }
  377. #region release effect
  378. card.Owner.UntilCalculateFixedCostEffect.Remove(getCardEffect);
  379. #endregion
  380. }
  381. }
  382. if (timing == EffectTiming.OnEnterFieldAnyone)
  383. {
  384. ActivateClass activateClass = new ActivateClass();
  385. activateClass.SetUpICardEffect("Delete 1 level 5 or lower Digimon or Draw 1", CanUseCondition, card);
  386. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  387. cardEffects.Add(activateClass);
  388. string EffectDiscription()
  389. {
  390. return "[Your Turn] When an effect plays one of your Digimon, delete 1 of your opponent's level 5 or lower Digimon. If this effect didn't delete, <Draw 1> (Draw 1 card from your deck).";
  391. }
  392. bool CanSelectPermanentCondition(Permanent permanent)
  393. {
  394. if (CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card))
  395. {
  396. if (permanent.Level <= 5)
  397. {
  398. if (permanent.TopCard.HasLevel)
  399. {
  400. return true;
  401. }
  402. }
  403. }
  404. return false;
  405. }
  406. bool PermanentCondition(Permanent permanent)
  407. {
  408. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card);
  409. }
  410. bool CanUseCondition(Hashtable hashtable)
  411. {
  412. if (CardEffectCommons.IsExistOnBattleArea(card))
  413. {
  414. if (CardEffectCommons.CanTriggerOnPermanentPlay(hashtable, PermanentCondition))
  415. {
  416. if (CardEffectCommons.IsByEffect(hashtable, null))
  417. {
  418. if (CardEffectCommons.IsOwnerTurn(card))
  419. {
  420. return true;
  421. }
  422. }
  423. }
  424. }
  425. return false;
  426. }
  427. bool CanActivateCondition(Hashtable hashtable)
  428. {
  429. if (CardEffectCommons.IsExistOnBattleArea(card))
  430. {
  431. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  432. {
  433. return true;
  434. }
  435. if (card.Owner.LibraryCards.Count >= 1)
  436. {
  437. return true;
  438. }
  439. }
  440. return false;
  441. }
  442. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  443. {
  444. List<Permanent> deleteTargetPermanents = new List<Permanent>();
  445. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  446. {
  447. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  448. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  449. selectPermanentEffect.SetUp(
  450. selectPlayer: card.Owner,
  451. canTargetCondition: CanSelectPermanentCondition,
  452. canTargetCondition_ByPreSelecetedList: null,
  453. canEndSelectCondition: null,
  454. maxCount: maxCount,
  455. canNoSelect: false,
  456. canEndNotMax: false,
  457. selectPermanentCoroutine: null,
  458. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  459. mode: SelectPermanentEffect.Mode.Custom,
  460. cardEffect: activateClass);
  461. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to delete.", "The opponent is selecting 1 Digimon to delete.");
  462. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  463. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  464. {
  465. deleteTargetPermanents = permanents.Clone();
  466. yield return null;
  467. }
  468. }
  469. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DeletePeremanentAndProcessAccordingToResult(
  470. targetPermanents: deleteTargetPermanents,
  471. activateClass: activateClass,
  472. successProcess: null,
  473. failureProcess: FailureProcess));
  474. IEnumerator FailureProcess()
  475. {
  476. yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, activateClass).Draw());
  477. }
  478. }
  479. }
  480. return cardEffects;
  481. }
  482. }