CardEffectCommons.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. public static IEnumerator PlayAthoRenePorToken (ICardEffect activateClass)
  285. {
  286. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  287. tokenData: ContinuousController.instance.AthoRenePorToken,
  288. activateClass: activateClass,
  289. isOwnerPermanent: true,
  290. isTapped: false
  291. ));
  292. }
  293. #region Play 1 [Petrification] Token
  294. public static IEnumerator PlayPetrificationToken(ICardEffect activateClass)
  295. {
  296. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  297. tokenData: ContinuousController.instance.PetrificationToken,
  298. activateClass: activateClass,
  299. isOwnerPermanent: false,
  300. isTapped: false
  301. ));
  302. }
  303. #endregion
  304. #region Security effect of "add this card to hand"
  305. public static IEnumerator AddThisCardToHand(CardSource card1, ICardEffect activateClass)
  306. {
  307. yield return new WaitForSeconds(0.5f);
  308. yield return ContinuousController.instance.StartCoroutine(card1.Owner.brainStormObject.CloseBrainstrorm(card1));
  309. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(new List<CardSource>() { card1 }, false, activateClass));
  310. }
  311. #endregion
  312. #region Delete target permanents, and the effect determines whether the permanent has been deleted or not
  313. public static IEnumerator DeletePeremanentAndProcessAccordingToResult(List<Permanent> targetPermanents, ICardEffect activateClass, Func<List<Permanent>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  314. {
  315. DestroyPermanentsClass destroyPermanentsClass = new DestroyPermanentsClass(targetPermanents, CardEffectHashtable(activateClass));
  316. yield return ContinuousController.instance.StartCoroutine(destroyPermanentsClass.Destroy());
  317. if (targetPermanents.Some((permanent) => destroyPermanentsClass.IsDestroyed(permanent)))
  318. {
  319. if (successProcess != null)
  320. {
  321. yield return ContinuousController.instance.StartCoroutine(successProcess(destroyPermanentsClass.DestroyedPermanents));
  322. }
  323. }
  324. else
  325. {
  326. if (failureProcess != null)
  327. {
  328. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  329. }
  330. }
  331. }
  332. #endregion
  333. #region Bounce target 1 permanent, and the effect determines whether the permanent has been bounced or not
  334. public static IEnumerator BouncePeremanentAndProcessAccordingToResult(List<Permanent> targetPermanents, ICardEffect activateClass, IEnumerator successProcess, IEnumerator failureProcess)
  335. {
  336. HandBounceClaass bouncePermanentClass = new HandBounceClaass(targetPermanents, CardEffectHashtable(activateClass));
  337. yield return ContinuousController.instance.StartCoroutine(bouncePermanentClass.Bounce());
  338. if (targetPermanents.Some((permanent) => bouncePermanentClass.IsBounced(permanent)))
  339. {
  340. if (successProcess != null)
  341. {
  342. yield return ContinuousController.instance.StartCoroutine(successProcess);
  343. }
  344. }
  345. else
  346. {
  347. if (failureProcess != null)
  348. {
  349. yield return ContinuousController.instance.StartCoroutine(failureProcess);
  350. }
  351. }
  352. }
  353. #endregion
  354. #region Deck Bounce target 1 permanent, and the effect determines whether the permanent has been bounced or not
  355. public static IEnumerator DeckBouncePeremanentAndProcessAccordingToResult(List<Permanent> targetPermanents, ICardEffect activateClass, IEnumerator successProcess, IEnumerator failureProcess)
  356. {
  357. DeckBottomBounceClass deckBounceClass = new DeckBottomBounceClass(targetPermanents, CardEffectHashtable(activateClass));
  358. yield return ContinuousController.instance.StartCoroutine(deckBounceClass.DeckBounce());
  359. if (targetPermanents.Some((permanent) => deckBounceClass.IsDeckBounced(permanent)))
  360. {
  361. if (successProcess != null)
  362. {
  363. yield return ContinuousController.instance.StartCoroutine(successProcess);
  364. }
  365. }
  366. else
  367. {
  368. if (failureProcess != null)
  369. {
  370. yield return ContinuousController.instance.StartCoroutine(failureProcess);
  371. }
  372. }
  373. }
  374. #endregion
  375. #region Trash digivolution cards from top or bottom
  376. public static IEnumerator TrashDigivolutionCardsFromTopOrBottom(Permanent targetPermanent, int trashCount, bool isFromTop, ICardEffect activateClass)
  377. {
  378. if (activateClass == null) yield break;
  379. if (targetPermanent == null) yield break;
  380. if (targetPermanent.TopCard == null) yield break;
  381. if (targetPermanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(activateClass)) == 0) yield break;
  382. if (targetPermanent.TopCard.CanNotBeAffected(activateClass)) yield break;
  383. if (trashCount <= 0) yield break;
  384. List<CardSource> trashTargetCards = new List<CardSource>();
  385. for (int i = 0; i < trashCount; i++)
  386. {
  387. if (targetPermanent.DigivolutionCards.Count >= i + 1)
  388. {
  389. int index = isFromTop ? i : targetPermanent.DigivolutionCards.Count - 1 - i;
  390. CardSource trashTargetCard = targetPermanent.DigivolutionCards[index];
  391. trashTargetCards.Add(trashTargetCard);
  392. }
  393. }
  394. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(targetPermanent, trashTargetCards, activateClass).TrashDigivolutionCards());
  395. }
  396. #endregion
  397. #region this Option card's Main effect
  398. public static ActivateClass OptionMainEffect(CardSource card) => card.EffectList(EffectTiming.OptionSkill).Find(cardEffect => cardEffect != null && cardEffect is ActivateClass && cardEffect.EffectDiscription.Contains("[Main]")) as ActivateClass;
  399. #endregion
  400. #region this Option card's Security effect
  401. public static ActivateClass OptionSecurityEffect(CardSource card) => card.EffectList(EffectTiming.SecuritySkill).Find(cardEffect => cardEffect != null && cardEffect is ActivateClass && cardEffect.EffectDiscription.Contains("[Security]")) as ActivateClass;
  402. #endregion
  403. #region Add Option's Security effect that "Activate this card's Main effect" to cardEffects
  404. public static void AddActivateMainOptionSecurityEffect(CardSource card, ref List<ICardEffect> cardEffects, string effectName, string effectDiscription = "", Func<ICardEffect, IEnumerator> afterMainEffect = null)
  405. {
  406. if (OptionMainEffect(card) == null) return;
  407. cardEffects.Add(CardEffectFactory.ActivateMainOptionSecurityEffect(card, effectName, effectDiscription, afterMainEffect));
  408. }
  409. #endregion
  410. #region Target permanent Digivolves into Digimon card from hand or trash
  411. public static IEnumerator DigivolveIntoHandOrTrashCard(
  412. Permanent targetPermanent,
  413. Func<CardSource, bool> cardCondition,
  414. bool payCost,
  415. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple,
  416. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple,
  417. int ignoreDigivolutionRequirementFixedCost,
  418. bool isHand,
  419. ICardEffect activateClass,
  420. IEnumerator successProcess,
  421. //bool ignoreLevel = false,
  422. bool ignoreSelection = false,
  423. IgnoreRequirement ignoreRequirements = IgnoreRequirement.None,
  424. IEnumerator failedProcess = null)
  425. {
  426. if (targetPermanent == null) yield break;
  427. if (targetPermanent.TopCard == null) yield break;
  428. if (activateClass == null) yield break;
  429. if (activateClass.EffectSourceCard == null) yield break;
  430. Player owner = targetPermanent.TopCard.Owner;
  431. SelectCardEffect.Root root = isHand ? SelectCardEffect.Root.Hand : SelectCardEffect.Root.Trash;
  432. bool ignoreDigivolutionRequirement = !ignoreRequirements.Equals(IgnoreRequirement.None) || ignoreDigivolutionRequirementFixedCost >= 0;// ignoreDigivolutionRequirementFixedCost >= 0 || ignoreRequirements;
  433. int fixedCost = -1;
  434. bool successful = false;
  435. if (fixedCostTuple != null)
  436. {
  437. fixedCost = fixedCostTuple.Value.fixedCost;
  438. }
  439. Debug.Log($"Digivolve into hand or trash: {ignoreDigivolutionRequirement}");
  440. if (ignoreDigivolutionRequirement)
  441. {
  442. fixedCost = ignoreDigivolutionRequirementFixedCost;
  443. }
  444. bool CanSelectCardCondition(CardSource cardSource)
  445. {
  446. if (cardSource.IsDigimon)
  447. {
  448. if (cardCondition == null || cardCondition(cardSource))
  449. {
  450. if (!cardSource.CanNotEvolve(targetPermanent))
  451. {
  452. if (cardSource.CanPlayCardTargetFrame(
  453. frame: targetPermanent.PermanentFrame,
  454. PayCost: payCost,
  455. cardEffect: activateClass,
  456. root: root,
  457. fixedCost: fixedCost,
  458. ignore: ignoreRequirements))
  459. {
  460. return true;
  461. }
  462. }
  463. }
  464. }
  465. return false;
  466. }
  467. #region reduce cost
  468. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  469. if (reduceCostTuple != null)
  470. {
  471. bool PermanentCondition(Permanent permanent)
  472. {
  473. return permanent == targetPermanent;
  474. }
  475. bool CardCondition(CardSource cardSource)
  476. {
  477. if (cardSource != null)
  478. {
  479. if (cardSource.Owner == owner)
  480. {
  481. if (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource))
  482. {
  483. return true;
  484. }
  485. }
  486. }
  487. return false;
  488. }
  489. getChangeCostEffect = ChangeDigivolutionCostPlayerEffect(
  490. permanentCondition: PermanentCondition,
  491. cardCondition: CardCondition,
  492. rootCondition: null,
  493. changeValue: -reduceCostTuple.Value.reduceCost,
  494. activateClass: activateClass,
  495. setFixedCost: false);
  496. if (getChangeCostEffect != null)
  497. {
  498. AddEffectToPlayer(
  499. effectDuration: EffectDuration.UntilCalculateFixedCost,
  500. card: targetPermanent.TopCard,
  501. cardEffect: null,
  502. timing: EffectTiming.None,
  503. getCardEffect: getChangeCostEffect);
  504. }
  505. }
  506. #endregion
  507. #region set fixed cost
  508. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  509. if (fixedCostTuple != null)
  510. {
  511. bool PermanentCondition(Permanent permanent)
  512. {
  513. return permanent == targetPermanent;
  514. }
  515. bool CardCondition(CardSource cardSource)
  516. {
  517. if (cardSource != null)
  518. {
  519. if (cardSource.Owner == owner)
  520. {
  521. if (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource))
  522. {
  523. return true;
  524. }
  525. }
  526. }
  527. return false;
  528. }
  529. getFixedCostEffect = ChangeDigivolutionCostPlayerEffect(
  530. permanentCondition: PermanentCondition,
  531. cardCondition: CardCondition,
  532. rootCondition: null,
  533. changeValue: fixedCost,
  534. activateClass: activateClass,
  535. setFixedCost: true);
  536. if (getChangeCostEffect != null)
  537. {
  538. AddEffectToPlayer(
  539. effectDuration: EffectDuration.UntilCalculateFixedCost,
  540. card: targetPermanent.TopCard,
  541. cardEffect: null,
  542. timing: EffectTiming.None,
  543. getCardEffect: getFixedCostEffect);
  544. }
  545. }
  546. #endregion
  547. #region ignore digivolution requirement
  548. Func<EffectTiming, ICardEffect> getIgnoreDigivolutionRequirementEffect = null;
  549. if (ignoreDigivolutionRequirement)
  550. {
  551. bool PermanentCondition(Permanent permanent)
  552. {
  553. return permanent == targetPermanent;
  554. }
  555. bool CardCondition(CardSource cardSource)
  556. {
  557. if (cardSource == null)
  558. {
  559. return false;
  560. }
  561. if (cardSource.Owner != owner)
  562. {
  563. return false;
  564. }
  565. if (cardCondition == null || cardCondition(cardSource))
  566. {
  567. return true;
  568. }
  569. return false;
  570. }
  571. getIgnoreDigivolutionRequirementEffect = GainIgnoreDigivolutionRequirementPlayerEffect(
  572. permanentCondition: PermanentCondition,
  573. cardCondition: CardCondition,
  574. ignoreDigivolutionRequirement: ignoreDigivolutionRequirement,
  575. digivolutionCost: fixedCost,
  576. activateClass: activateClass);
  577. if (getIgnoreDigivolutionRequirementEffect != null)
  578. {
  579. AddEffectToPlayer(
  580. effectDuration: EffectDuration.UntilCalculateFixedCost,
  581. card: targetPermanent.TopCard,
  582. cardEffect: null,
  583. timing: EffectTiming.None,
  584. getCardEffect: getIgnoreDigivolutionRequirementEffect);
  585. }
  586. }
  587. #endregion
  588. List<CardSource> selectedCards = new List<CardSource>();
  589. IEnumerator SelectCardCoroutine(CardSource cardSource)
  590. {
  591. selectedCards.Add(cardSource);
  592. yield return null;
  593. }
  594. if (isHand)
  595. {
  596. if (owner.HandCards.Count(CanSelectCardCondition) >= 1)
  597. {
  598. int maxCount = Mathf.Min(1, owner.HandCards.Count(CanSelectCardCondition));
  599. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  600. selectHandEffect.SetUp(
  601. selectPlayer: owner,
  602. canTargetCondition: CanSelectCardCondition,
  603. canTargetCondition_ByPreSelecetedList: null,
  604. canEndSelectCondition: null,
  605. maxCount: maxCount,
  606. canNoSelect: true,
  607. canEndNotMax: false,
  608. isShowOpponent: true,
  609. selectCardCoroutine: SelectCardCoroutine,
  610. afterSelectCardCoroutine: null,
  611. mode: SelectHandEffect.Mode.Custom,
  612. cardEffect: activateClass);
  613. selectHandEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  614. selectHandEffect.SetUpCustomMessage_ShowCard("Selected Card");
  615. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  616. }
  617. }
  618. else
  619. {
  620. if (HasMatchConditionOwnersCardInTrash(targetPermanent.TopCard, CanSelectCardCondition) && !ignoreSelection)
  621. {
  622. int maxCount = 1;
  623. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  624. selectCardEffect.SetUp(
  625. canTargetCondition: CanSelectCardCondition,
  626. canTargetCondition_ByPreSelecetedList: null,
  627. canEndSelectCondition: null,
  628. canNoSelect: () => true,
  629. selectCardCoroutine: SelectCardCoroutine,
  630. afterSelectCardCoroutine: null,
  631. message: "Select 1 card to digivolve.",
  632. maxCount: maxCount,
  633. canEndNotMax: false,
  634. isShowOpponent: true,
  635. mode: SelectCardEffect.Mode.Custom,
  636. root: SelectCardEffect.Root.Trash,
  637. customRootCardList: null,
  638. canLookReverseCard: true,
  639. selectPlayer: owner,
  640. cardEffect: activateClass);
  641. selectCardEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  642. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  643. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  644. }
  645. else
  646. {
  647. if(ignoreSelection)
  648. selectedCards.Add(activateClass.EffectSourceCard);
  649. }
  650. }
  651. PlayCardClass playCardClass = new PlayCardClass(
  652. cardSources: selectedCards,
  653. hashtable: CardEffectHashtable(activateClass),
  654. payCost: payCost,
  655. targetPermanent: targetPermanent,
  656. isTapped: false,
  657. root: root,
  658. activateETB: true);
  659. //if (ignoreRequirements.Equals(IgnoreRequirement.All) || ignoreRequirements.Equals(IgnoreRequirement.Level))
  660. // playCardClass.SetIgnoreLevel();
  661. playCardClass.SetIgnoreRequirements(ignoreRequirements);
  662. //!ignoreRequirements
  663. if (fixedCost >= 0)
  664. playCardClass.SetFixedCost(fixedCost);
  665. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  666. #region release effect
  667. if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  668. #endregion
  669. #region release effect
  670. if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  671. #endregion
  672. #region release effect
  673. if (getIgnoreDigivolutionRequirementEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getIgnoreDigivolutionRequirementEffect);
  674. #endregion
  675. if (selectedCards.Count >= 1)
  676. {
  677. if (IsDigivolvedByTheEffect(targetPermanent, selectedCards[0], activateClass))
  678. {
  679. successful = true;
  680. }
  681. }
  682. if (successful)
  683. {
  684. if (successProcess != null)
  685. yield return ContinuousController.instance.StartCoroutine(successProcess);
  686. }
  687. else
  688. {
  689. if (failedProcess != null)
  690. yield return ContinuousController.instance.StartCoroutine(failedProcess);
  691. }
  692. }
  693. #endregion
  694. #region Target permanent Digivolves into Digimon card execution area
  695. public static IEnumerator DigivolveIntoExcecutingAreaCard(
  696. Permanent targetPermanent,
  697. Func<CardSource, bool> cardCondition,
  698. bool payCost,
  699. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple,
  700. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple,
  701. int ignoreDigivolutionRequirementFixedCost,
  702. ICardEffect activateClass,
  703. IEnumerator successProcess,
  704. bool ignoreSelection = false,
  705. IgnoreRequirement ignoreRequirements = IgnoreRequirement.None)
  706. {
  707. if (targetPermanent == null) yield break;
  708. if (targetPermanent.TopCard == null) yield break;
  709. if (activateClass == null) yield break;
  710. if (activateClass.EffectSourceCard == null) yield break;
  711. Player owner = targetPermanent.TopCard.Owner;
  712. SelectCardEffect.Root root = SelectCardEffect.Root.Execution;
  713. bool ignoreDigivolutionRequirement = !ignoreRequirements.Equals(IgnoreRequirement.None) || ignoreDigivolutionRequirementFixedCost >= 0;// ignoreDigivolutionRequirementFixedCost >= 0 || ignoreRequirements;
  714. int fixedCost = -1;
  715. if (fixedCostTuple != null)
  716. {
  717. fixedCost = fixedCostTuple.Value.fixedCost;
  718. }
  719. if (ignoreDigivolutionRequirement)
  720. {
  721. fixedCost = ignoreDigivolutionRequirementFixedCost;
  722. }
  723. bool CanSelectCardCondition(CardSource cardSource)
  724. {
  725. if (cardSource.IsDigimon)
  726. {
  727. if (cardCondition == null || cardCondition(cardSource))
  728. {
  729. if (!cardSource.CanNotEvolve(targetPermanent))
  730. {
  731. if (cardSource.CanPlayCardTargetFrame(
  732. frame: targetPermanent.PermanentFrame,
  733. PayCost: payCost,
  734. cardEffect: activateClass,
  735. root: root,
  736. fixedCost: fixedCost,
  737. ignore: ignoreRequirements))
  738. {
  739. return true;
  740. }
  741. }
  742. }
  743. }
  744. return false;
  745. }
  746. #region reduce cost
  747. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  748. if (reduceCostTuple != null)
  749. {
  750. bool PermanentCondition(Permanent permanent)
  751. {
  752. return permanent == targetPermanent;
  753. }
  754. bool CardCondition(CardSource cardSource)
  755. {
  756. if (cardSource != null)
  757. {
  758. if (cardSource.Owner == owner)
  759. {
  760. if (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource))
  761. {
  762. return true;
  763. }
  764. }
  765. }
  766. return false;
  767. }
  768. getChangeCostEffect = ChangeDigivolutionCostPlayerEffect(
  769. permanentCondition: PermanentCondition,
  770. cardCondition: CardCondition,
  771. rootCondition: null,
  772. changeValue: -reduceCostTuple.Value.reduceCost,
  773. activateClass: activateClass,
  774. setFixedCost: false);
  775. if (getChangeCostEffect != null)
  776. {
  777. AddEffectToPlayer(
  778. effectDuration: EffectDuration.UntilCalculateFixedCost,
  779. card: targetPermanent.TopCard,
  780. cardEffect: null,
  781. timing: EffectTiming.None,
  782. getCardEffect: getChangeCostEffect);
  783. }
  784. }
  785. #endregion
  786. #region set fixed cost
  787. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  788. if (fixedCostTuple != null)
  789. {
  790. bool PermanentCondition(Permanent permanent)
  791. {
  792. return permanent == targetPermanent;
  793. }
  794. bool CardCondition(CardSource cardSource)
  795. {
  796. if (cardSource != null)
  797. {
  798. if (cardSource.Owner == owner)
  799. {
  800. if (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource))
  801. {
  802. return true;
  803. }
  804. }
  805. }
  806. return false;
  807. }
  808. getFixedCostEffect = ChangeDigivolutionCostPlayerEffect(
  809. permanentCondition: PermanentCondition,
  810. cardCondition: CardCondition,
  811. rootCondition: null,
  812. changeValue: fixedCost,
  813. activateClass: activateClass,
  814. setFixedCost: true);
  815. if (getChangeCostEffect != null)
  816. {
  817. AddEffectToPlayer(
  818. effectDuration: EffectDuration.UntilCalculateFixedCost,
  819. card: targetPermanent.TopCard,
  820. cardEffect: null,
  821. timing: EffectTiming.None,
  822. getCardEffect: getFixedCostEffect);
  823. }
  824. }
  825. #endregion
  826. #region ignore digivolution requirement
  827. Func<EffectTiming, ICardEffect> getIgnoreDigivolutionRequirementEffect = null;
  828. if (ignoreDigivolutionRequirement)
  829. {
  830. bool PermanentCondition(Permanent permanent)
  831. {
  832. return permanent == targetPermanent;
  833. }
  834. bool CardCondition(CardSource cardSource)
  835. {
  836. if (cardSource == null)
  837. {
  838. return false;
  839. }
  840. if (cardSource.Owner != owner)
  841. {
  842. return false;
  843. }
  844. if (cardCondition == null || cardCondition(cardSource))
  845. {
  846. return true;
  847. }
  848. return false;
  849. }
  850. getIgnoreDigivolutionRequirementEffect = GainIgnoreDigivolutionRequirementPlayerEffect(
  851. permanentCondition: PermanentCondition,
  852. cardCondition: CardCondition,
  853. ignoreDigivolutionRequirement: ignoreDigivolutionRequirement,
  854. digivolutionCost: fixedCost,
  855. activateClass: activateClass);
  856. if (getIgnoreDigivolutionRequirementEffect != null)
  857. {
  858. AddEffectToPlayer(
  859. effectDuration: EffectDuration.UntilCalculateFixedCost,
  860. card: targetPermanent.TopCard,
  861. cardEffect: null,
  862. timing: EffectTiming.None,
  863. getCardEffect: getIgnoreDigivolutionRequirementEffect);
  864. }
  865. }
  866. #endregion
  867. List<CardSource> selectedCards = new List<CardSource>();
  868. IEnumerator SelectCardCoroutine(CardSource cardSource)
  869. {
  870. selectedCards.Add(cardSource);
  871. yield return null;
  872. }
  873. if (owner.ExecutingCards.Count(CanSelectCardCondition) > 1)
  874. {
  875. int maxCount = 1;
  876. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  877. selectCardEffect.SetUp(
  878. canTargetCondition: CanSelectCardCondition,
  879. canTargetCondition_ByPreSelecetedList: null,
  880. canEndSelectCondition: null,
  881. canNoSelect: () => true,
  882. selectCardCoroutine: SelectCardCoroutine,
  883. afterSelectCardCoroutine: null,
  884. message: "Select 1 card to digivolve.",
  885. maxCount: maxCount,
  886. canEndNotMax: false,
  887. isShowOpponent: true,
  888. mode: SelectCardEffect.Mode.Custom,
  889. root: SelectCardEffect.Root.Execution,
  890. customRootCardList: null,
  891. canLookReverseCard: true,
  892. selectPlayer: owner,
  893. cardEffect: activateClass);
  894. selectCardEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  895. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  896. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  897. }
  898. else
  899. {
  900. selectedCards.Add(activateClass.EffectSourceCard);
  901. }
  902. PlayCardClass playCardClass = new PlayCardClass(
  903. cardSources: selectedCards,
  904. hashtable: CardEffectHashtable(activateClass),
  905. payCost: payCost,
  906. targetPermanent: targetPermanent,
  907. isTapped: false,
  908. root: root,
  909. activateETB: true);
  910. playCardClass.SetIgnoreRequirements(ignoreRequirements);
  911. if (!ignoreDigivolutionRequirement && fixedCost >= 0) playCardClass.SetFixedCost(fixedCost);
  912. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  913. #region release effect
  914. if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  915. #endregion
  916. #region release effect
  917. if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  918. #endregion
  919. #region release effect
  920. if (getIgnoreDigivolutionRequirementEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getIgnoreDigivolutionRequirementEffect);
  921. #endregion
  922. if (selectedCards.Count >= 1)
  923. {
  924. if (IsDigivolvedByTheEffect(targetPermanent, selectedCards[0], activateClass))
  925. {
  926. if (successProcess != null)
  927. {
  928. yield return ContinuousController.instance.StartCoroutine(successProcess);
  929. }
  930. }
  931. }
  932. }
  933. #endregion
  934. #region Get the effect given by EffectTiming
  935. public static Func<EffectTiming, ICardEffect> GetCardEffectByEffectTiming(EffectTiming timing, ICardEffect cardEffect) => (_timing) => _timing == timing ? cardEffect : null;
  936. #endregion
  937. }