CardEffectCommons.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEditor;
  7. public partial class CardEffectCommons
  8. {
  9. #region Play cards as new permanents
  10. public static IEnumerator PlayPermanentCards(List<CardSource> cardSources, ICardEffect activateClass, bool payCost, bool isTapped, SelectCardEffect.Root root, bool activateETB, bool isBreedingArea = false, int fixedCost = -1)
  11. {
  12. if (cardSources == null) yield break;
  13. cardSources = cardSources
  14. .Filter(cardSource => cardSource != null)
  15. .Filter(cardSource => CanPlayAsNewPermanent(
  16. cardSource: cardSource,
  17. payCost: payCost,
  18. cardEffect: activateClass,
  19. isBreedingArea: isBreedingArea,
  20. fixedCost: fixedCost));
  21. if (cardSources.Count == 0) yield break;
  22. PlayCardClass playCardClass = new PlayCardClass(
  23. cardSources: cardSources,
  24. hashtable: CardEffectHashtable(activateClass),
  25. payCost: payCost,
  26. targetPermanent: null,
  27. isTapped: isTapped,
  28. root: root,
  29. activateETB: activateETB);
  30. if (isBreedingArea)
  31. playCardClass.SetIsBreedingArea();
  32. playCardClass.SetFixedCost(fixedCost);
  33. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  34. }
  35. #endregion
  36. #region Play option cards
  37. public static IEnumerator PlayOptionCards(List<CardSource> cardSources, ICardEffect activateClass, bool payCost, SelectCardEffect.Root root,
  38. bool setAddSecurityEndOption = false)
  39. {
  40. if (cardSources == null) yield break;
  41. cardSources = cardSources
  42. .Filter(cardSource => cardSource != null)
  43. .Filter(cardSource => !cardSource.CanNotPlayThisOption);
  44. if (cardSources.Count == 0) yield break;
  45. PlayCardClass playCard = new PlayCardClass(
  46. cardSources: cardSources,
  47. hashtable: CardEffectHashtable(activateClass),
  48. payCost: payCost,
  49. targetPermanent: null,
  50. isTapped: false,
  51. root: root,
  52. activateETB: true);
  53. if (activateClass != null)
  54. {
  55. playCard.SetShowEffect();
  56. }
  57. if (setAddSecurityEndOption)
  58. {
  59. playCard.SetAddSecurityEndOption();
  60. }
  61. yield return ContinuousController.instance.StartCoroutine(playCard.PlayCard());
  62. }
  63. #endregion
  64. #region Play Delay Option cards as new permanents
  65. public static IEnumerator PlaceDelayOptionCards(CardSource card, ICardEffect cardEffect, SelectCardEffect.Root root = SelectCardEffect.Root.Execution)
  66. {
  67. if (CanPlayAsNewPermanent(cardSource: card, payCost: false, cardEffect: cardEffect, isPlayOption: true))
  68. {
  69. PlayPermanentClass playPermanent = new PlayPermanentClass(
  70. cardSources: new List<CardSource>() { card },
  71. hashtable: CardEffectHashtable(cardEffect),
  72. targetPermanent: null,
  73. isTapped: false,
  74. root: root,
  75. ActivateETB: true);
  76. playPermanent.SetISPlayOption();
  77. yield return ContinuousController.instance.StartCoroutine(playPermanent.PlayPermanent());
  78. if (IsExistOnBattleArea(card))
  79. {
  80. card.PermanentOfThisCard().IsPlayedOptionPermanent = true;
  81. }
  82. }
  83. }
  84. #endregion
  85. #region Play 1 Token
  86. public static IEnumerator PlayToken(CEntity_Base tokenData, ICardEffect activateClass, bool isOwnerPermanent, bool isTapped, int quantity = 1)
  87. {
  88. if (activateClass == null) yield break;
  89. if (activateClass.EffectSourceCard == null) yield break;
  90. if (tokenData == null) yield break;
  91. CardSource card = activateClass.EffectSourceCard;
  92. Player player = isOwnerPermanent ? card.Owner : card.Owner.Enemy;
  93. if (card.Owner.fieldCardFrames.Count((frame) => frame.IsEmptyFrame() && frame.IsBattleAreaFrame()) >= quantity)
  94. {
  95. List<CardSource> playCards = new List<CardSource>();
  96. for (int i = 0; i < quantity; i++)
  97. {
  98. CardSource tokenCard = CardObjectController.CreateCardSource(
  99. player.PlayerID,
  100. tokenData,
  101. true);
  102. playCards.Add(tokenCard);
  103. }
  104. if (CanPlayAsNewPermanent(cardSource: playCards[0], payCost: false, cardEffect: activateClass))
  105. {
  106. yield return ContinuousController.instance.StartCoroutine(new PlayCardClass(
  107. cardSources: playCards,
  108. hashtable: CardEffectHashtable(activateClass),
  109. payCost: false,
  110. targetPermanent: null,
  111. isTapped: isTapped,
  112. root: SelectCardEffect.Root.None,
  113. activateETB: true).PlayCard());
  114. }
  115. }
  116. }
  117. #endregion
  118. #region Play 1 [Diaboromon] Token
  119. public static IEnumerator PlayDiaboromonToken(ICardEffect activateClass,int quantity = 1)
  120. {
  121. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  122. tokenData: ContinuousController.instance.DiaboromonToken,
  123. activateClass: activateClass,
  124. isOwnerPermanent: true,
  125. isTapped: false,
  126. quantity: quantity
  127. ));
  128. }
  129. #endregion
  130. #region Play 1 [Amon of Crimson Flame] Token
  131. public static IEnumerator PlayAmonToken(ICardEffect activateClass)
  132. {
  133. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  134. tokenData: ContinuousController.instance.AmonToken,
  135. activateClass: activateClass,
  136. isOwnerPermanent: true,
  137. isTapped: false
  138. ));
  139. }
  140. #endregion
  141. #region Play 1 [Umon of Blue Thunder] Token
  142. public static IEnumerator PlayUmonToken(ICardEffect activateClass)
  143. {
  144. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  145. tokenData: ContinuousController.instance.UmonToken,
  146. activateClass: activateClass,
  147. isOwnerPermanent: true,
  148. isTapped: false
  149. ));
  150. }
  151. #endregion
  152. #region Play 1 [Fujitsumon] Token
  153. public static IEnumerator PlayFujitsumonToken(ICardEffect activateClass, bool isOwnerPermanent)
  154. {
  155. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  156. tokenData: ContinuousController.instance.FujitsumonToken,
  157. activateClass: activateClass,
  158. isOwnerPermanent: isOwnerPermanent,
  159. isTapped: true
  160. ));
  161. }
  162. #endregion
  163. #region Play 1 [Gyuukimon] Token
  164. public static IEnumerator PlayGyuukimonToken(ICardEffect activateClass)
  165. {
  166. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  167. tokenData: ContinuousController.instance.GyuukimonToken,
  168. activateClass: activateClass,
  169. isOwnerPermanent: true,
  170. isTapped: false
  171. ));
  172. }
  173. #endregion
  174. #region Play 1 [KoHagurumon] Token
  175. public static IEnumerator PlayKoHagurumonToken(ICardEffect activateClass)
  176. {
  177. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  178. tokenData: ContinuousController.instance.KoHagurumonToken,
  179. activateClass: activateClass,
  180. isOwnerPermanent: true,
  181. isTapped: false
  182. ));
  183. }
  184. #endregion
  185. #region Security effect of "add this card to hand"
  186. public static IEnumerator AddThisCardToHand(CardSource card1, ICardEffect activateClass)
  187. {
  188. yield return new WaitForSeconds(0.5f);
  189. yield return ContinuousController.instance.StartCoroutine(card1.Owner.brainStormObject.CloseBrainstrorm(card1));
  190. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(new List<CardSource>() { card1 }, false, activateClass));
  191. }
  192. #endregion
  193. #region Delete target permanents, and the effect determines whether the permanent has been deleted or not
  194. public static IEnumerator DeletePeremanentAndProcessAccordingToResult(List<Permanent> targetPermanents, ICardEffect activateClass, Func<List<Permanent>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  195. {
  196. DestroyPermanentsClass destroyPermanentsClass = new DestroyPermanentsClass(targetPermanents, CardEffectHashtable(activateClass));
  197. yield return ContinuousController.instance.StartCoroutine(destroyPermanentsClass.Destroy());
  198. if (targetPermanents.Some((permanent) => destroyPermanentsClass.IsDestroyed(permanent)))
  199. {
  200. if (successProcess != null)
  201. {
  202. yield return ContinuousController.instance.StartCoroutine(successProcess(destroyPermanentsClass.DestroyedPermanents));
  203. }
  204. }
  205. else
  206. {
  207. if (failureProcess != null)
  208. {
  209. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  210. }
  211. }
  212. }
  213. #endregion
  214. #region Bounce target 1 permanent, and the effect determines whether the permanent has been bounced or not
  215. public static IEnumerator BouncePeremanentAndProcessAccordingToResult(List<Permanent> targetPermanents, ICardEffect activateClass, IEnumerator successProcess, IEnumerator failureProcess)
  216. {
  217. HandBounceClaass bouncePermanentClass = new HandBounceClaass(targetPermanents, CardEffectHashtable(activateClass));
  218. yield return ContinuousController.instance.StartCoroutine(bouncePermanentClass.Bounce());
  219. if (targetPermanents.Some((permanent) => bouncePermanentClass.IsBounced(permanent)))
  220. {
  221. if (successProcess != null)
  222. {
  223. yield return ContinuousController.instance.StartCoroutine(successProcess);
  224. }
  225. }
  226. else
  227. {
  228. if (failureProcess != null)
  229. {
  230. yield return ContinuousController.instance.StartCoroutine(failureProcess);
  231. }
  232. }
  233. }
  234. #endregion
  235. #region Deck Bounce target 1 permanent, and the effect determines whether the permanent has been bounced or not
  236. public static IEnumerator DeckBouncePeremanentAndProcessAccordingToResult(List<Permanent> targetPermanents, ICardEffect activateClass, IEnumerator successProcess, IEnumerator failureProcess)
  237. {
  238. DeckBottomBounceClass deckBounceClass = new DeckBottomBounceClass(targetPermanents, CardEffectHashtable(activateClass));
  239. yield return ContinuousController.instance.StartCoroutine(deckBounceClass.DeckBounce());
  240. if (targetPermanents.Some((permanent) => deckBounceClass.IsDeckBounced(permanent)))
  241. {
  242. if (successProcess != null)
  243. {
  244. yield return ContinuousController.instance.StartCoroutine(successProcess);
  245. }
  246. }
  247. else
  248. {
  249. if (failureProcess != null)
  250. {
  251. yield return ContinuousController.instance.StartCoroutine(failureProcess);
  252. }
  253. }
  254. }
  255. #endregion
  256. #region Trash digivolution cards from top or bottom
  257. public static IEnumerator TrashDigivolutionCardsFromTopOrBottom(Permanent targetPermanent, int trashCount, bool isFromTop, ICardEffect activateClass)
  258. {
  259. if (activateClass == null) yield break;
  260. if (targetPermanent == null) yield break;
  261. if (targetPermanent.TopCard == null) yield break;
  262. if (targetPermanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(activateClass)) == 0) yield break;
  263. Debug.Log($"Trashing Digivolution Cards From Top/Bottom: Target Can Not Be Affected - {targetPermanent.TopCard.CanNotBeAffected(activateClass)}");
  264. if (targetPermanent.TopCard.CanNotBeAffected(activateClass)) yield break;
  265. if (trashCount <= 0) yield break;
  266. List<CardSource> trashTargetCards = new List<CardSource>();
  267. for (int i = 0; i < trashCount; i++)
  268. {
  269. if (targetPermanent.DigivolutionCards.Count >= i + 1)
  270. {
  271. int index = isFromTop ? i : targetPermanent.DigivolutionCards.Count - 1 - i;
  272. CardSource trashTargetCard = targetPermanent.DigivolutionCards[index];
  273. trashTargetCards.Add(trashTargetCard);
  274. }
  275. }
  276. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(targetPermanent, trashTargetCards, activateClass).TrashDigivolutionCards());
  277. }
  278. #endregion
  279. #region this Option card's Main effect
  280. public static ActivateClass OptionMainEffect(CardSource card) => card.EffectList(EffectTiming.OptionSkill).Find(cardEffect => cardEffect != null && cardEffect is ActivateClass && cardEffect.EffectDiscription.Contains("[Main]")) as ActivateClass;
  281. #endregion
  282. #region this Option card's Security effect
  283. public static ActivateClass OptionSecurityEffect(CardSource card) => card.EffectList(EffectTiming.SecuritySkill).Find(cardEffect => cardEffect != null && cardEffect is ActivateClass && cardEffect.EffectDiscription.Contains("[Security]")) as ActivateClass;
  284. #endregion
  285. #region Add Option's Security effect that "Activate this card's Main effect" to cardEffects
  286. public static void AddActivateMainOptionSecurityEffect(CardSource card, ref List<ICardEffect> cardEffects, string effectName, string effectDiscription = "", Func<ICardEffect, IEnumerator> afterMainEffect = null)
  287. {
  288. if (OptionMainEffect(card) == null) return;
  289. cardEffects.Add(CardEffectFactory.ActivateMainOptionSecurityEffect(card, effectName, effectDiscription, afterMainEffect));
  290. }
  291. #endregion
  292. #region Target permanent Digivolves into Digimon card from hand or trash
  293. public static IEnumerator DigivolveIntoHandOrTrashCard(
  294. Permanent targetPermanent,
  295. Func<CardSource, bool> cardCondition,
  296. bool payCost,
  297. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple,
  298. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple,
  299. int ignoreDigivolutionRequirementFixedCost,
  300. bool isHand,
  301. ICardEffect activateClass,
  302. IEnumerator successProcess,
  303. bool ignoreLevel = false,
  304. bool ignoreSelection = false)
  305. {
  306. if (targetPermanent == null) yield break;
  307. if (targetPermanent.TopCard == null) yield break;
  308. if (activateClass == null) yield break;
  309. if (activateClass.EffectSourceCard == null) yield break;
  310. Player owner = targetPermanent.TopCard.Owner;
  311. SelectCardEffect.Root root = isHand ? SelectCardEffect.Root.Hand : SelectCardEffect.Root.Trash;
  312. bool ignoreDigivolutionRequirement = ignoreDigivolutionRequirementFixedCost >= 0;
  313. int fixedCost = -1;
  314. if (fixedCostTuple != null)
  315. {
  316. fixedCost = fixedCostTuple.Value.fixedCost;
  317. }
  318. if (ignoreDigivolutionRequirement)
  319. {
  320. fixedCost = ignoreDigivolutionRequirementFixedCost;
  321. }
  322. bool CanSelectCardCondition(CardSource cardSource)
  323. {
  324. if (cardSource.IsDigimon)
  325. {
  326. if (cardCondition == null || cardCondition(cardSource))
  327. {
  328. if (!cardSource.CanNotEvolve(targetPermanent))
  329. {
  330. if (ignoreLevel
  331. || cardSource.CanPlayCardTargetFrame(
  332. frame: targetPermanent.PermanentFrame,
  333. PayCost: payCost,
  334. cardEffect: activateClass,
  335. root: root,
  336. fixedCost: fixedCost))
  337. {
  338. return true;
  339. }
  340. }
  341. }
  342. }
  343. return false;
  344. }
  345. #region reduce cost
  346. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  347. if (reduceCostTuple != null)
  348. {
  349. bool PermanentCondition(Permanent permanent)
  350. {
  351. return permanent == targetPermanent;
  352. }
  353. bool CardCondition(CardSource cardSource)
  354. {
  355. if (cardSource != null)
  356. {
  357. if (cardSource.Owner == owner)
  358. {
  359. if (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource))
  360. {
  361. return true;
  362. }
  363. }
  364. }
  365. return false;
  366. }
  367. getChangeCostEffect = ChangeDigivolutionCostPlayerEffect(
  368. permanentCondition: PermanentCondition,
  369. cardCondition: CardCondition,
  370. rootCondition: null,
  371. changeValue: -reduceCostTuple.Value.reduceCost,
  372. activateClass: activateClass,
  373. setFixedCost: false);
  374. if (getChangeCostEffect != null)
  375. {
  376. AddEffectToPlayer(
  377. effectDuration: EffectDuration.UntilCalculateFixedCost,
  378. card: targetPermanent.TopCard,
  379. cardEffect: null,
  380. timing: EffectTiming.None,
  381. getCardEffect: getChangeCostEffect);
  382. }
  383. }
  384. #endregion
  385. #region set fixed cost
  386. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  387. if (fixedCostTuple != null)
  388. {
  389. bool PermanentCondition(Permanent permanent)
  390. {
  391. return permanent == targetPermanent;
  392. }
  393. bool CardCondition(CardSource cardSource)
  394. {
  395. if (cardSource != null)
  396. {
  397. if (cardSource.Owner == owner)
  398. {
  399. if (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource))
  400. {
  401. return true;
  402. }
  403. }
  404. }
  405. return false;
  406. }
  407. getFixedCostEffect = ChangeDigivolutionCostPlayerEffect(
  408. permanentCondition: PermanentCondition,
  409. cardCondition: CardCondition,
  410. rootCondition: null,
  411. changeValue: fixedCost,
  412. activateClass: activateClass,
  413. setFixedCost: true);
  414. if (getChangeCostEffect != null)
  415. {
  416. AddEffectToPlayer(
  417. effectDuration: EffectDuration.UntilCalculateFixedCost,
  418. card: targetPermanent.TopCard,
  419. cardEffect: null,
  420. timing: EffectTiming.None,
  421. getCardEffect: getFixedCostEffect);
  422. }
  423. }
  424. #endregion
  425. #region ignore digivolution requirement
  426. Func<EffectTiming, ICardEffect> getIgnoreDigivolutionRequirementEffect = null;
  427. if (ignoreDigivolutionRequirement)
  428. {
  429. bool PermanentCondition(Permanent permanent)
  430. {
  431. return permanent == targetPermanent;
  432. }
  433. bool CardCondition(CardSource cardSource)
  434. {
  435. if (cardSource == null)
  436. {
  437. return false;
  438. }
  439. if (cardSource.Owner != owner)
  440. {
  441. return false;
  442. }
  443. if (cardCondition == null || cardCondition(cardSource))
  444. {
  445. return true;
  446. }
  447. return false;
  448. }
  449. getIgnoreDigivolutionRequirementEffect = GainIgnoreDigivolutionRequirementPlayerEffect(
  450. permanentCondition: PermanentCondition,
  451. cardCondition: CardCondition,
  452. ignoreDigivolutionRequirement: ignoreDigivolutionRequirement,
  453. digivolutionCost: fixedCost,
  454. activateClass: activateClass);
  455. if (getIgnoreDigivolutionRequirementEffect != null)
  456. {
  457. AddEffectToPlayer(
  458. effectDuration: EffectDuration.UntilCalculateFixedCost,
  459. card: targetPermanent.TopCard,
  460. cardEffect: null,
  461. timing: EffectTiming.None,
  462. getCardEffect: getIgnoreDigivolutionRequirementEffect);
  463. }
  464. }
  465. #endregion
  466. List<CardSource> selectedCards = new List<CardSource>();
  467. IEnumerator SelectCardCoroutine(CardSource cardSource)
  468. {
  469. selectedCards.Add(cardSource);
  470. yield return null;
  471. }
  472. if (isHand)
  473. {
  474. if (owner.HandCards.Count(CanSelectCardCondition) >= 1)
  475. {
  476. int maxCount = Mathf.Min(1, owner.HandCards.Count(CanSelectCardCondition));
  477. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  478. selectHandEffect.SetUp(
  479. selectPlayer: owner,
  480. canTargetCondition: CanSelectCardCondition,
  481. canTargetCondition_ByPreSelecetedList: null,
  482. canEndSelectCondition: null,
  483. maxCount: maxCount,
  484. canNoSelect: true,
  485. canEndNotMax: false,
  486. isShowOpponent: true,
  487. selectCardCoroutine: SelectCardCoroutine,
  488. afterSelectCardCoroutine: null,
  489. mode: SelectHandEffect.Mode.Custom,
  490. cardEffect: activateClass);
  491. selectHandEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  492. selectHandEffect.SetUpCustomMessage_ShowCard("Selected Card");
  493. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  494. }
  495. }
  496. else
  497. {
  498. if (HasMatchConditionOwnersCardInTrash(targetPermanent.TopCard, CanSelectCardCondition) && !ignoreSelection)
  499. {
  500. int maxCount = 1;
  501. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  502. selectCardEffect.SetUp(
  503. canTargetCondition: CanSelectCardCondition,
  504. canTargetCondition_ByPreSelecetedList: null,
  505. canEndSelectCondition: null,
  506. canNoSelect: () => true,
  507. selectCardCoroutine: SelectCardCoroutine,
  508. afterSelectCardCoroutine: null,
  509. message: "Select 1 card to digivolve.",
  510. maxCount: maxCount,
  511. canEndNotMax: false,
  512. isShowOpponent: true,
  513. mode: SelectCardEffect.Mode.Custom,
  514. root: SelectCardEffect.Root.Trash,
  515. customRootCardList: null,
  516. canLookReverseCard: true,
  517. selectPlayer: owner,
  518. cardEffect: activateClass);
  519. selectCardEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  520. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  521. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  522. }
  523. else
  524. {
  525. selectedCards.Add(activateClass.EffectSourceCard);
  526. }
  527. }
  528. PlayCardClass playCardClass = new PlayCardClass(
  529. cardSources: selectedCards,
  530. hashtable: CardEffectHashtable(activateClass),
  531. payCost: payCost,
  532. targetPermanent: targetPermanent,
  533. isTapped: false,
  534. root: root,
  535. activateETB: true);
  536. if (ignoreLevel) playCardClass.SetIgnoreLevel();
  537. if (!ignoreDigivolutionRequirement && fixedCost >= 0) playCardClass.SetFixedCost(fixedCost);
  538. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  539. #region release effect
  540. if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  541. #endregion
  542. #region release effect
  543. if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  544. #endregion
  545. #region release effect
  546. if (getIgnoreDigivolutionRequirementEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getIgnoreDigivolutionRequirementEffect);
  547. #endregion
  548. if (selectedCards.Count >= 1)
  549. {
  550. if (IsDigivolvedByTheEffect(targetPermanent, selectedCards[0], activateClass))
  551. {
  552. if (successProcess != null)
  553. {
  554. yield return ContinuousController.instance.StartCoroutine(successProcess);
  555. }
  556. }
  557. }
  558. }
  559. #endregion
  560. #region Target permanent Digivolves into Digimon card execution area
  561. public static IEnumerator DigivolveIntoExcecutingAreaCard(
  562. Permanent targetPermanent,
  563. Func<CardSource, bool> cardCondition,
  564. bool payCost,
  565. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple,
  566. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple,
  567. int ignoreDigivolutionRequirementFixedCost,
  568. ICardEffect activateClass,
  569. IEnumerator successProcess,
  570. bool ignoreLevel = false,
  571. bool ignoreSelection = false)
  572. {
  573. if (targetPermanent == null) yield break;
  574. if (targetPermanent.TopCard == null) yield break;
  575. if (activateClass == null) yield break;
  576. if (activateClass.EffectSourceCard == null) yield break;
  577. Player owner = targetPermanent.TopCard.Owner;
  578. SelectCardEffect.Root root = SelectCardEffect.Root.Execution;
  579. bool ignoreDigivolutionRequirement = ignoreDigivolutionRequirementFixedCost >= 0;
  580. int fixedCost = -1;
  581. if (fixedCostTuple != null)
  582. {
  583. fixedCost = fixedCostTuple.Value.fixedCost;
  584. }
  585. if (ignoreDigivolutionRequirement)
  586. {
  587. fixedCost = ignoreDigivolutionRequirementFixedCost;
  588. }
  589. bool CanSelectCardCondition(CardSource cardSource)
  590. {
  591. if (cardSource.IsDigimon)
  592. {
  593. if (cardCondition == null || cardCondition(cardSource))
  594. {
  595. if (!cardSource.CanNotEvolve(targetPermanent))
  596. {
  597. if (ignoreLevel
  598. || cardSource.CanPlayCardTargetFrame(
  599. frame: targetPermanent.PermanentFrame,
  600. PayCost: payCost,
  601. cardEffect: activateClass,
  602. root: root,
  603. fixedCost: fixedCost))
  604. {
  605. return true;
  606. }
  607. }
  608. }
  609. }
  610. return false;
  611. }
  612. #region reduce cost
  613. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  614. if (reduceCostTuple != null)
  615. {
  616. bool PermanentCondition(Permanent permanent)
  617. {
  618. return permanent == targetPermanent;
  619. }
  620. bool CardCondition(CardSource cardSource)
  621. {
  622. if (cardSource != null)
  623. {
  624. if (cardSource.Owner == owner)
  625. {
  626. if (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource))
  627. {
  628. return true;
  629. }
  630. }
  631. }
  632. return false;
  633. }
  634. getChangeCostEffect = ChangeDigivolutionCostPlayerEffect(
  635. permanentCondition: PermanentCondition,
  636. cardCondition: CardCondition,
  637. rootCondition: null,
  638. changeValue: -reduceCostTuple.Value.reduceCost,
  639. activateClass: activateClass,
  640. setFixedCost: false);
  641. if (getChangeCostEffect != null)
  642. {
  643. AddEffectToPlayer(
  644. effectDuration: EffectDuration.UntilCalculateFixedCost,
  645. card: targetPermanent.TopCard,
  646. cardEffect: null,
  647. timing: EffectTiming.None,
  648. getCardEffect: getChangeCostEffect);
  649. }
  650. }
  651. #endregion
  652. #region set fixed cost
  653. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  654. if (fixedCostTuple != null)
  655. {
  656. bool PermanentCondition(Permanent permanent)
  657. {
  658. return permanent == targetPermanent;
  659. }
  660. bool CardCondition(CardSource cardSource)
  661. {
  662. if (cardSource != null)
  663. {
  664. if (cardSource.Owner == owner)
  665. {
  666. if (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource))
  667. {
  668. return true;
  669. }
  670. }
  671. }
  672. return false;
  673. }
  674. getFixedCostEffect = ChangeDigivolutionCostPlayerEffect(
  675. permanentCondition: PermanentCondition,
  676. cardCondition: CardCondition,
  677. rootCondition: null,
  678. changeValue: fixedCost,
  679. activateClass: activateClass,
  680. setFixedCost: true);
  681. if (getChangeCostEffect != null)
  682. {
  683. AddEffectToPlayer(
  684. effectDuration: EffectDuration.UntilCalculateFixedCost,
  685. card: targetPermanent.TopCard,
  686. cardEffect: null,
  687. timing: EffectTiming.None,
  688. getCardEffect: getFixedCostEffect);
  689. }
  690. }
  691. #endregion
  692. #region ignore digivolution requirement
  693. Func<EffectTiming, ICardEffect> getIgnoreDigivolutionRequirementEffect = null;
  694. if (ignoreDigivolutionRequirement)
  695. {
  696. bool PermanentCondition(Permanent permanent)
  697. {
  698. return permanent == targetPermanent;
  699. }
  700. bool CardCondition(CardSource cardSource)
  701. {
  702. if (cardSource == null)
  703. {
  704. return false;
  705. }
  706. if (cardSource.Owner != owner)
  707. {
  708. return false;
  709. }
  710. if (cardCondition == null || cardCondition(cardSource))
  711. {
  712. return true;
  713. }
  714. return false;
  715. }
  716. getIgnoreDigivolutionRequirementEffect = GainIgnoreDigivolutionRequirementPlayerEffect(
  717. permanentCondition: PermanentCondition,
  718. cardCondition: CardCondition,
  719. ignoreDigivolutionRequirement: ignoreDigivolutionRequirement,
  720. digivolutionCost: fixedCost,
  721. activateClass: activateClass);
  722. if (getIgnoreDigivolutionRequirementEffect != null)
  723. {
  724. AddEffectToPlayer(
  725. effectDuration: EffectDuration.UntilCalculateFixedCost,
  726. card: targetPermanent.TopCard,
  727. cardEffect: null,
  728. timing: EffectTiming.None,
  729. getCardEffect: getIgnoreDigivolutionRequirementEffect);
  730. }
  731. }
  732. #endregion
  733. List<CardSource> selectedCards = new List<CardSource>();
  734. IEnumerator SelectCardCoroutine(CardSource cardSource)
  735. {
  736. selectedCards.Add(cardSource);
  737. yield return null;
  738. }
  739. if (owner.ExecutingCards.Count(CanSelectCardCondition) >= 1)
  740. {
  741. int maxCount = 1;
  742. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  743. selectCardEffect.SetUp(
  744. canTargetCondition: CanSelectCardCondition,
  745. canTargetCondition_ByPreSelecetedList: null,
  746. canEndSelectCondition: null,
  747. canNoSelect: () => true,
  748. selectCardCoroutine: SelectCardCoroutine,
  749. afterSelectCardCoroutine: null,
  750. message: "Select 1 card to digivolve.",
  751. maxCount: maxCount,
  752. canEndNotMax: false,
  753. isShowOpponent: true,
  754. mode: SelectCardEffect.Mode.Custom,
  755. root: SelectCardEffect.Root.Execution,
  756. customRootCardList: null,
  757. canLookReverseCard: true,
  758. selectPlayer: owner,
  759. cardEffect: activateClass);
  760. selectCardEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  761. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  762. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  763. }
  764. else
  765. {
  766. selectedCards.Add(activateClass.EffectSourceCard);
  767. }
  768. PlayCardClass playCardClass = new PlayCardClass(
  769. cardSources: selectedCards,
  770. hashtable: CardEffectHashtable(activateClass),
  771. payCost: payCost,
  772. targetPermanent: targetPermanent,
  773. isTapped: false,
  774. root: root,
  775. activateETB: true);
  776. if (ignoreLevel) playCardClass.SetIgnoreLevel();
  777. if (!ignoreDigivolutionRequirement && fixedCost >= 0) playCardClass.SetFixedCost(fixedCost);
  778. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  779. #region release effect
  780. if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  781. #endregion
  782. #region release effect
  783. if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  784. #endregion
  785. #region release effect
  786. if (getIgnoreDigivolutionRequirementEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getIgnoreDigivolutionRequirementEffect);
  787. #endregion
  788. if (selectedCards.Count >= 1)
  789. {
  790. if (IsDigivolvedByTheEffect(targetPermanent, selectedCards[0], activateClass))
  791. {
  792. if (successProcess != null)
  793. {
  794. yield return ContinuousController.instance.StartCoroutine(successProcess);
  795. }
  796. }
  797. }
  798. }
  799. #endregion
  800. #region Get the effect given by EffectTiming
  801. public static Func<EffectTiming, ICardEffect> GetCardEffectByEffectTiming(EffectTiming timing, ICardEffect cardEffect) => (_timing) => _timing == timing ? cardEffect : null;
  802. #endregion
  803. }