CardEffectCommons.cs 40 KB

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