CardEffectCommons.cs 40 KB

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