CardEffectCommons.cs 40 KB

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