CardEffectCommons.cs 41 KB

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