CardEffectCommons.cs 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  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 target digivolution cards, and the effect determines whether the digivolution cards were trashed or not
  378. public static IEnumerator TrashDigivolutionCardsAndProcessAccordingToResult(Permanent targetPermanent, List<CardSource> targetDigivolutionCards, ICardEffect activateClass, Func<List<CardSource>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  379. {
  380. ITrashDigivolutionCards trashDigivolutionCards = new ITrashDigivolutionCards(targetPermanent, targetDigivolutionCards, activateClass);
  381. yield return ContinuousController.instance.StartCoroutine(trashDigivolutionCards.TrashDigivolutionCards());
  382. if (targetDigivolutionCards.Some((sourceCard) => trashDigivolutionCards.IsTrashed(sourceCard)))
  383. {
  384. if (successProcess != null)
  385. {
  386. yield return ContinuousController.instance.StartCoroutine(successProcess(trashDigivolutionCards.TrashedCards));
  387. }
  388. }
  389. else
  390. {
  391. if (failureProcess != null)
  392. {
  393. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  394. }
  395. }
  396. }
  397. #endregion
  398. #region Trash Security cards and the effect determines whether the security were trashed or not
  399. public static IEnumerator TrashSecurityAndProcessAccordingToResult(Player player, int trashAmount, ICardEffect activateClass, bool fromTop, Func<List<CardSource>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  400. {
  401. IDestroySecurity destroySecurity = new IDestroySecurity(player, trashAmount, activateClass, fromTop);
  402. yield return ContinuousController.instance.StartCoroutine(destroySecurity.DestroySecurity());
  403. if (destroySecurity.DestroyedSecurity.Any())
  404. {
  405. if (successProcess != null)
  406. {
  407. yield return ContinuousController.instance.StartCoroutine(successProcess(destroySecurity.DestroyedSecurity));
  408. }
  409. }
  410. else
  411. {
  412. if (failureProcess != null)
  413. {
  414. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  415. }
  416. }
  417. }
  418. #endregion
  419. #region Trash digivolution cards from top or bottom
  420. public static IEnumerator TrashDigivolutionCardsFromTopOrBottom(Permanent targetPermanent, int trashCount, bool isFromTop, ICardEffect activateClass, Func<CardSource, bool> cardCondition = null)
  421. {
  422. if (activateClass == null) yield break;
  423. if (targetPermanent == null) yield break;
  424. if (targetPermanent.TopCard == null) yield break;
  425. if (targetPermanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(activateClass)) == 0) yield break;
  426. if (targetPermanent.TopCard.CanNotBeAffected(activateClass)) yield break;
  427. if (trashCount <= 0) yield break;
  428. List<CardSource> trashTargetCards = new List<CardSource>();
  429. for (int i = 0; i < targetPermanent.DigivolutionCards.Count; i++)
  430. {
  431. if (trashTargetCards.Count >= trashCount)
  432. break;
  433. int index = isFromTop ? i : targetPermanent.DigivolutionCards.Count - 1 - i;
  434. CardSource trashTargetCard = targetPermanent.DigivolutionCards[index];
  435. bool trashCard = true;
  436. if (cardCondition != null)
  437. trashCard = cardCondition(trashTargetCard);
  438. if (trashCard)
  439. trashTargetCards.Add(trashTargetCard);
  440. }
  441. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(targetPermanent, trashTargetCards, activateClass).TrashDigivolutionCards());
  442. }
  443. #endregion
  444. #region this Option card's Main effect
  445. public static ActivateClass OptionMainEffect(CardSource card) => card.EffectList(EffectTiming.OptionSkill).Find(cardEffect => cardEffect != null && cardEffect is ActivateClass && cardEffect.EffectDiscription.Contains("[Main]")) as ActivateClass;
  446. #endregion
  447. #region this Option card's Security effect
  448. public static ActivateClass OptionSecurityEffect(CardSource card) => card.EffectList(EffectTiming.SecuritySkill).Find(cardEffect => cardEffect != null && cardEffect is ActivateClass && cardEffect.EffectDiscription.Contains("[Security]")) as ActivateClass;
  449. #endregion
  450. #region Add Option's Security effect that "Activate this card's Main effect" to cardEffects
  451. public static void AddActivateMainOptionSecurityEffect(CardSource card, ref List<ICardEffect> cardEffects, string effectName, string effectDiscription = "", Func<ICardEffect, IEnumerator> afterMainEffect = null)
  452. {
  453. if (OptionMainEffect(card) == null) return;
  454. cardEffects.Add(CardEffectFactory.ActivateMainOptionSecurityEffect(card, effectName, effectDiscription, afterMainEffect));
  455. }
  456. #endregion
  457. #region Target permanent Digivolves into Digimon card from hand or trash
  458. public static IEnumerator DigivolveIntoHandOrTrashCard(
  459. Permanent targetPermanent,
  460. Func<CardSource, bool> cardCondition,
  461. bool payCost,
  462. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple,
  463. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple,
  464. int ignoreDigivolutionRequirementFixedCost,
  465. bool isHand,
  466. ICardEffect activateClass,
  467. IEnumerator successProcess,
  468. //bool ignoreLevel = false,
  469. bool ignoreSelection = false,
  470. IgnoreRequirement ignoreRequirements = IgnoreRequirement.None,
  471. IEnumerator failedProcess = null)
  472. {
  473. if (targetPermanent == null) yield break;
  474. if (targetPermanent.TopCard == null) yield break;
  475. if (activateClass == null) yield break;
  476. if (activateClass.EffectSourceCard == null) yield break;
  477. Player owner = targetPermanent.TopCard.Owner;
  478. SelectCardEffect.Root root = isHand ? SelectCardEffect.Root.Hand : SelectCardEffect.Root.Trash;
  479. bool ignoreDigivolutionRequirement = !ignoreRequirements.Equals(IgnoreRequirement.None) || ignoreDigivolutionRequirementFixedCost >= 0;// ignoreDigivolutionRequirementFixedCost >= 0 || ignoreRequirements;
  480. int fixedCost = -1;
  481. bool successful = false;
  482. if (fixedCostTuple != null)
  483. {
  484. fixedCost = fixedCostTuple.Value.fixedCost;
  485. }
  486. Debug.Log($"Digivolve into hand or trash: {ignoreDigivolutionRequirement}");
  487. if (ignoreDigivolutionRequirement)
  488. {
  489. fixedCost = ignoreDigivolutionRequirementFixedCost;
  490. }
  491. bool CanSelectCardCondition(CardSource cardSource)
  492. {
  493. if (cardSource.IsDigimon)
  494. {
  495. if (cardCondition == null || cardCondition(cardSource))
  496. {
  497. if (!cardSource.CanNotEvolve(targetPermanent))
  498. {
  499. bool isBreeding = cardSource.Owner.GetBreedingAreaPermanents().Contains(targetPermanent);
  500. if (cardSource.CanPlayCardTargetFrame(
  501. frame: targetPermanent.PermanentFrame,
  502. PayCost: payCost,
  503. cardEffect: activateClass,
  504. root: root,
  505. fixedCost: fixedCost,
  506. ignore: ignoreRequirements,
  507. isBreedingArea: isBreeding))
  508. {
  509. return true;
  510. }
  511. }
  512. }
  513. }
  514. return false;
  515. }
  516. #region reduce cost
  517. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  518. if (reduceCostTuple != null)
  519. {
  520. bool PermanentCondition(Permanent permanent)
  521. {
  522. return permanent == targetPermanent;
  523. }
  524. bool CardCondition(CardSource cardSource)
  525. {
  526. if (cardSource != null)
  527. {
  528. if (cardSource.Owner == owner)
  529. {
  530. if (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource))
  531. {
  532. return true;
  533. }
  534. }
  535. }
  536. return false;
  537. }
  538. getChangeCostEffect = ChangeDigivolutionCostPlayerEffect(
  539. permanentCondition: PermanentCondition,
  540. cardCondition: CardCondition,
  541. rootCondition: null,
  542. changeValue: -reduceCostTuple.Value.reduceCost,
  543. activateClass: activateClass,
  544. setFixedCost: false);
  545. if (getChangeCostEffect != null)
  546. {
  547. AddEffectToPlayer(
  548. effectDuration: EffectDuration.UntilCalculateFixedCost,
  549. card: targetPermanent.TopCard,
  550. cardEffect: null,
  551. timing: EffectTiming.None,
  552. getCardEffect: getChangeCostEffect);
  553. }
  554. }
  555. #endregion
  556. #region set fixed cost
  557. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  558. if (fixedCostTuple != null)
  559. {
  560. bool PermanentCondition(Permanent permanent)
  561. {
  562. return permanent == targetPermanent;
  563. }
  564. bool CardCondition(CardSource cardSource)
  565. {
  566. if (cardSource != null)
  567. {
  568. if (cardSource.Owner == owner)
  569. {
  570. if (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource))
  571. {
  572. return true;
  573. }
  574. }
  575. }
  576. return false;
  577. }
  578. getFixedCostEffect = ChangeDigivolutionCostPlayerEffect(
  579. permanentCondition: PermanentCondition,
  580. cardCondition: CardCondition,
  581. rootCondition: null,
  582. changeValue: fixedCost,
  583. activateClass: activateClass,
  584. setFixedCost: true);
  585. if (getChangeCostEffect != null)
  586. {
  587. AddEffectToPlayer(
  588. effectDuration: EffectDuration.UntilCalculateFixedCost,
  589. card: targetPermanent.TopCard,
  590. cardEffect: null,
  591. timing: EffectTiming.None,
  592. getCardEffect: getFixedCostEffect);
  593. }
  594. }
  595. #endregion
  596. #region ignore digivolution requirement
  597. Func<EffectTiming, ICardEffect> getIgnoreDigivolutionRequirementEffect = null;
  598. if (ignoreDigivolutionRequirement)
  599. {
  600. bool PermanentCondition(Permanent permanent)
  601. {
  602. return permanent == targetPermanent;
  603. }
  604. bool CardCondition(CardSource cardSource)
  605. {
  606. if (cardSource == null)
  607. {
  608. return false;
  609. }
  610. if (cardSource.Owner != owner)
  611. {
  612. return false;
  613. }
  614. if (cardCondition == null || cardCondition(cardSource))
  615. {
  616. return true;
  617. }
  618. return false;
  619. }
  620. getIgnoreDigivolutionRequirementEffect = GainIgnoreDigivolutionRequirementPlayerEffect(
  621. permanentCondition: PermanentCondition,
  622. cardCondition: CardCondition,
  623. ignoreDigivolutionRequirement: ignoreDigivolutionRequirement,
  624. digivolutionCost: fixedCost,
  625. activateClass: activateClass);
  626. if (getIgnoreDigivolutionRequirementEffect != null)
  627. {
  628. AddEffectToPlayer(
  629. effectDuration: EffectDuration.UntilCalculateFixedCost,
  630. card: targetPermanent.TopCard,
  631. cardEffect: null,
  632. timing: EffectTiming.None,
  633. getCardEffect: getIgnoreDigivolutionRequirementEffect);
  634. }
  635. }
  636. #endregion
  637. List<CardSource> selectedCards = new List<CardSource>();
  638. IEnumerator SelectCardCoroutine(CardSource cardSource)
  639. {
  640. selectedCards.Add(cardSource);
  641. yield return null;
  642. }
  643. if (isHand)
  644. {
  645. if (owner.HandCards.Count(CanSelectCardCondition) >= 1)
  646. {
  647. int maxCount = Mathf.Min(1, owner.HandCards.Count(CanSelectCardCondition));
  648. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  649. selectHandEffect.SetUp(
  650. selectPlayer: owner,
  651. canTargetCondition: CanSelectCardCondition,
  652. canTargetCondition_ByPreSelecetedList: null,
  653. canEndSelectCondition: null,
  654. maxCount: maxCount,
  655. canNoSelect: true,
  656. canEndNotMax: false,
  657. isShowOpponent: true,
  658. selectCardCoroutine: SelectCardCoroutine,
  659. afterSelectCardCoroutine: null,
  660. mode: SelectHandEffect.Mode.Custom,
  661. cardEffect: activateClass);
  662. selectHandEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  663. selectHandEffect.SetUpCustomMessage_ShowCard("Selected Card");
  664. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  665. }
  666. }
  667. else
  668. {
  669. if (HasMatchConditionOwnersCardInTrash(targetPermanent.TopCard, CanSelectCardCondition) && !ignoreSelection)
  670. {
  671. int maxCount = 1;
  672. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  673. selectCardEffect.SetUp(
  674. canTargetCondition: CanSelectCardCondition,
  675. canTargetCondition_ByPreSelecetedList: null,
  676. canEndSelectCondition: null,
  677. canNoSelect: () => true,
  678. selectCardCoroutine: SelectCardCoroutine,
  679. afterSelectCardCoroutine: null,
  680. message: "Select 1 card to digivolve.",
  681. maxCount: maxCount,
  682. canEndNotMax: false,
  683. isShowOpponent: true,
  684. mode: SelectCardEffect.Mode.Custom,
  685. root: SelectCardEffect.Root.Trash,
  686. customRootCardList: null,
  687. canLookReverseCard: true,
  688. selectPlayer: owner,
  689. cardEffect: activateClass);
  690. selectCardEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  691. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  692. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  693. }
  694. else
  695. {
  696. if (ignoreSelection)
  697. selectedCards.Add(activateClass.EffectSourceCard);
  698. }
  699. }
  700. PlayCardClass playCardClass = new PlayCardClass(
  701. cardSources: selectedCards,
  702. hashtable: CardEffectHashtable(activateClass),
  703. payCost: payCost,
  704. targetPermanent: targetPermanent,
  705. isTapped: false,
  706. root: root,
  707. activateETB: true);
  708. //if (ignoreRequirements.Equals(IgnoreRequirement.All) || ignoreRequirements.Equals(IgnoreRequirement.Level))
  709. // playCardClass.SetIgnoreLevel();
  710. playCardClass.SetIgnoreRequirements(ignoreRequirements);
  711. //!ignoreRequirements
  712. if (fixedCost >= 0)
  713. playCardClass.SetFixedCost(fixedCost);
  714. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  715. #region release effect
  716. if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  717. #endregion
  718. #region release effect
  719. if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  720. #endregion
  721. #region release effect
  722. if (getIgnoreDigivolutionRequirementEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getIgnoreDigivolutionRequirementEffect);
  723. #endregion
  724. if (selectedCards.Count >= 1)
  725. {
  726. if (IsDigivolvedByTheEffect(targetPermanent, selectedCards[0], activateClass))
  727. {
  728. successful = true;
  729. }
  730. }
  731. if (successful)
  732. {
  733. if (successProcess != null)
  734. yield return ContinuousController.instance.StartCoroutine(successProcess);
  735. }
  736. else
  737. {
  738. if (failedProcess != null)
  739. yield return ContinuousController.instance.StartCoroutine(failedProcess);
  740. }
  741. }
  742. #endregion
  743. #region Target permanent Digivolves into Digimon card execution area
  744. public static IEnumerator DigivolveIntoExcecutingAreaCard(
  745. Permanent targetPermanent,
  746. Func<CardSource, bool> cardCondition,
  747. bool payCost,
  748. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple,
  749. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple,
  750. int ignoreDigivolutionRequirementFixedCost,
  751. ICardEffect activateClass,
  752. IEnumerator successProcess,
  753. bool ignoreSelection = false,
  754. IgnoreRequirement ignoreRequirements = IgnoreRequirement.None)
  755. {
  756. if (targetPermanent == null) yield break;
  757. if (targetPermanent.TopCard == null) yield break;
  758. if (activateClass == null) yield break;
  759. if (activateClass.EffectSourceCard == null) yield break;
  760. Player owner = targetPermanent.TopCard.Owner;
  761. SelectCardEffect.Root root = SelectCardEffect.Root.Execution;
  762. bool ignoreDigivolutionRequirement = !ignoreRequirements.Equals(IgnoreRequirement.None) || ignoreDigivolutionRequirementFixedCost >= 0;// ignoreDigivolutionRequirementFixedCost >= 0 || ignoreRequirements;
  763. int fixedCost = -1;
  764. if (fixedCostTuple != null)
  765. {
  766. fixedCost = fixedCostTuple.Value.fixedCost;
  767. }
  768. if (ignoreDigivolutionRequirement)
  769. {
  770. fixedCost = ignoreDigivolutionRequirementFixedCost;
  771. }
  772. bool CanSelectCardCondition(CardSource cardSource)
  773. {
  774. if (cardSource.IsDigimon)
  775. {
  776. if (cardCondition == null || cardCondition(cardSource))
  777. {
  778. if (!cardSource.CanNotEvolve(targetPermanent))
  779. {
  780. if (cardSource.CanPlayCardTargetFrame(
  781. frame: targetPermanent.PermanentFrame,
  782. PayCost: payCost,
  783. cardEffect: activateClass,
  784. root: root,
  785. fixedCost: fixedCost,
  786. ignore: ignoreRequirements))
  787. {
  788. return true;
  789. }
  790. }
  791. }
  792. }
  793. return false;
  794. }
  795. #region reduce cost
  796. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  797. if (reduceCostTuple != null)
  798. {
  799. bool PermanentCondition(Permanent permanent)
  800. {
  801. return permanent == targetPermanent;
  802. }
  803. bool CardCondition(CardSource cardSource)
  804. {
  805. if (cardSource != null)
  806. {
  807. if (cardSource.Owner == owner)
  808. {
  809. if (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource))
  810. {
  811. return true;
  812. }
  813. }
  814. }
  815. return false;
  816. }
  817. getChangeCostEffect = ChangeDigivolutionCostPlayerEffect(
  818. permanentCondition: PermanentCondition,
  819. cardCondition: CardCondition,
  820. rootCondition: null,
  821. changeValue: -reduceCostTuple.Value.reduceCost,
  822. activateClass: activateClass,
  823. setFixedCost: false);
  824. if (getChangeCostEffect != null)
  825. {
  826. AddEffectToPlayer(
  827. effectDuration: EffectDuration.UntilCalculateFixedCost,
  828. card: targetPermanent.TopCard,
  829. cardEffect: null,
  830. timing: EffectTiming.None,
  831. getCardEffect: getChangeCostEffect);
  832. }
  833. }
  834. #endregion
  835. #region set fixed cost
  836. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  837. if (fixedCostTuple != null)
  838. {
  839. bool PermanentCondition(Permanent permanent)
  840. {
  841. return permanent == targetPermanent;
  842. }
  843. bool CardCondition(CardSource cardSource)
  844. {
  845. if (cardSource != null)
  846. {
  847. if (cardSource.Owner == owner)
  848. {
  849. if (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource))
  850. {
  851. return true;
  852. }
  853. }
  854. }
  855. return false;
  856. }
  857. getFixedCostEffect = ChangeDigivolutionCostPlayerEffect(
  858. permanentCondition: PermanentCondition,
  859. cardCondition: CardCondition,
  860. rootCondition: null,
  861. changeValue: fixedCost,
  862. activateClass: activateClass,
  863. setFixedCost: true);
  864. if (getChangeCostEffect != null)
  865. {
  866. AddEffectToPlayer(
  867. effectDuration: EffectDuration.UntilCalculateFixedCost,
  868. card: targetPermanent.TopCard,
  869. cardEffect: null,
  870. timing: EffectTiming.None,
  871. getCardEffect: getFixedCostEffect);
  872. }
  873. }
  874. #endregion
  875. #region ignore digivolution requirement
  876. Func<EffectTiming, ICardEffect> getIgnoreDigivolutionRequirementEffect = null;
  877. if (ignoreDigivolutionRequirement)
  878. {
  879. bool PermanentCondition(Permanent permanent)
  880. {
  881. return permanent == targetPermanent;
  882. }
  883. bool CardCondition(CardSource cardSource)
  884. {
  885. if (cardSource == null)
  886. {
  887. return false;
  888. }
  889. if (cardSource.Owner != owner)
  890. {
  891. return false;
  892. }
  893. if (cardCondition == null || cardCondition(cardSource))
  894. {
  895. return true;
  896. }
  897. return false;
  898. }
  899. getIgnoreDigivolutionRequirementEffect = GainIgnoreDigivolutionRequirementPlayerEffect(
  900. permanentCondition: PermanentCondition,
  901. cardCondition: CardCondition,
  902. ignoreDigivolutionRequirement: ignoreDigivolutionRequirement,
  903. digivolutionCost: fixedCost,
  904. activateClass: activateClass);
  905. if (getIgnoreDigivolutionRequirementEffect != null)
  906. {
  907. AddEffectToPlayer(
  908. effectDuration: EffectDuration.UntilCalculateFixedCost,
  909. card: targetPermanent.TopCard,
  910. cardEffect: null,
  911. timing: EffectTiming.None,
  912. getCardEffect: getIgnoreDigivolutionRequirementEffect);
  913. }
  914. }
  915. #endregion
  916. List<CardSource> selectedCards = new List<CardSource>();
  917. IEnumerator SelectCardCoroutine(CardSource cardSource)
  918. {
  919. selectedCards.Add(cardSource);
  920. yield return null;
  921. }
  922. if (owner.ExecutingCards.Count(CanSelectCardCondition) > 1)
  923. {
  924. int maxCount = 1;
  925. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  926. selectCardEffect.SetUp(
  927. canTargetCondition: CanSelectCardCondition,
  928. canTargetCondition_ByPreSelecetedList: null,
  929. canEndSelectCondition: null,
  930. canNoSelect: () => true,
  931. selectCardCoroutine: SelectCardCoroutine,
  932. afterSelectCardCoroutine: null,
  933. message: "Select 1 card to digivolve.",
  934. maxCount: maxCount,
  935. canEndNotMax: false,
  936. isShowOpponent: true,
  937. mode: SelectCardEffect.Mode.Custom,
  938. root: SelectCardEffect.Root.Execution,
  939. customRootCardList: null,
  940. canLookReverseCard: true,
  941. selectPlayer: owner,
  942. cardEffect: activateClass);
  943. selectCardEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  944. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  945. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  946. }
  947. else
  948. {
  949. selectedCards.Add(activateClass.EffectSourceCard);
  950. }
  951. PlayCardClass playCardClass = new PlayCardClass(
  952. cardSources: selectedCards,
  953. hashtable: CardEffectHashtable(activateClass),
  954. payCost: payCost,
  955. targetPermanent: targetPermanent,
  956. isTapped: false,
  957. root: root,
  958. activateETB: true);
  959. playCardClass.SetIgnoreRequirements(ignoreRequirements);
  960. if (!ignoreDigivolutionRequirement && fixedCost >= 0) playCardClass.SetFixedCost(fixedCost);
  961. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  962. #region release effect
  963. if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  964. #endregion
  965. #region release effect
  966. if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  967. #endregion
  968. #region release effect
  969. if (getIgnoreDigivolutionRequirementEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getIgnoreDigivolutionRequirementEffect);
  970. #endregion
  971. if (selectedCards.Count >= 1)
  972. {
  973. if (IsDigivolvedByTheEffect(targetPermanent, selectedCards[0], activateClass))
  974. {
  975. if (successProcess != null)
  976. {
  977. yield return ContinuousController.instance.StartCoroutine(successProcess);
  978. }
  979. }
  980. }
  981. }
  982. #endregion
  983. #region Get the effect given by EffectTiming
  984. public static Func<EffectTiming, ICardEffect> GetCardEffectByEffectTiming(EffectTiming timing, ICardEffect cardEffect) => (_timing) => _timing == timing ? cardEffect : null;
  985. #endregion
  986. }