CardEffectCommons.cs 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectCommons
  7. {
  8. #region Digivolution Requirements
  9. public enum IgnoreRequirement
  10. {
  11. None,
  12. All,
  13. Level,
  14. Color
  15. }
  16. #endregion
  17. #region Play cards as new permanents
  18. public static IEnumerator PlayPermanentCards(List<CardSource> cardSources, ICardEffect activateClass, bool payCost, bool isTapped, SelectCardEffect.Root root, bool activateETB, bool isBreedingArea = false, int fixedCost = -1)
  19. {
  20. if (cardSources == null) yield break;
  21. cardSources = cardSources
  22. .Filter(cardSource => cardSource != null)
  23. .Filter(cardSource => CanPlayAsNewPermanent(
  24. cardSource: cardSource,
  25. payCost: payCost,
  26. cardEffect: activateClass,
  27. isBreedingArea: isBreedingArea,
  28. fixedCost: fixedCost));
  29. if (cardSources.Count == 0) yield break;
  30. PlayCardClass playCardClass = new PlayCardClass(
  31. cardSources: cardSources,
  32. hashtable: CardEffectHashtable(activateClass),
  33. payCost: payCost,
  34. targetPermanent: null,
  35. isTapped: isTapped,
  36. root: root,
  37. activateETB: activateETB);
  38. if (isBreedingArea)
  39. playCardClass.SetIsBreedingArea();
  40. playCardClass.SetFixedCost(fixedCost);
  41. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  42. }
  43. #endregion
  44. #region Play option cards
  45. public static IEnumerator PlayOptionCards(List<CardSource> cardSources, ICardEffect activateClass, bool payCost, SelectCardEffect.Root root,
  46. bool setAddSecurityEndOption = false)
  47. {
  48. if (cardSources == null) yield break;
  49. Func<EffectTiming, ICardEffect> getEffect = null;
  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. if (setAddSecurityEndOption)
  66. {
  67. getEffect = GetCardEffect;
  68. activateClass.EffectSourceCard.Owner.UntilEachTurnEndEffects.Add(getEffect);
  69. }
  70. }
  71. yield return ContinuousController.instance.StartCoroutine(playCard.PlayCard());
  72. if (getEffect != null)
  73. {
  74. activateClass.EffectSourceCard.Owner.UntilEachTurnEndEffects.Remove(getEffect);
  75. }
  76. ICardEffect GetCardEffect(EffectTiming timing)
  77. {
  78. if (timing == EffectTiming.None)
  79. {
  80. return CardEffectFactory.PlaceToSecurityEffect(activateClass.EffectSourceCard, toTop: true);
  81. }
  82. return null;
  83. }
  84. }
  85. #endregion
  86. #region Play Delay Option cards as new permanents
  87. public static IEnumerator PlaceDelayOptionCards(CardSource card, ICardEffect cardEffect, SelectCardEffect.Root root = SelectCardEffect.Root.Execution)
  88. {
  89. if (CanPlayAsNewPermanent(cardSource: card, payCost: false, cardEffect: cardEffect, isPlayOption: true))
  90. {
  91. PlayPermanentClass playPermanent = new PlayPermanentClass(
  92. cardSources: new List<CardSource>() { card },
  93. hashtable: CardEffectHashtable(cardEffect),
  94. targetPermanent: null,
  95. isTapped: false,
  96. root: root,
  97. ActivateETB: true);
  98. playPermanent.SetISPlayOption();
  99. yield return ContinuousController.instance.StartCoroutine(playPermanent.PlayPermanent());
  100. if (IsExistOnBattleArea(card))
  101. {
  102. card.PermanentOfThisCard().IsPlayedOptionPermanent = true;
  103. }
  104. }
  105. }
  106. #endregion
  107. #region Play 1 Token
  108. public static IEnumerator PlayToken(CEntity_Base tokenData, ICardEffect activateClass, bool isOwnerPermanent, bool isTapped, int quantity = 1)
  109. {
  110. if (activateClass == null) yield break;
  111. if (activateClass.EffectSourceCard == null) yield break;
  112. if (tokenData == null) yield break;
  113. CardSource card = activateClass.EffectSourceCard;
  114. Player player = isOwnerPermanent ? card.Owner : card.Owner.Enemy;
  115. if (card.Owner.fieldCardFrames.Count((frame) => frame.IsEmptyFrame() && frame.IsBattleAreaFrame()) >= quantity)
  116. {
  117. List<CardSource> playCards = new List<CardSource>();
  118. for (int i = 0; i < quantity; i++)
  119. {
  120. CardSource tokenCard = CardObjectController.CreateCardSource(
  121. player.PlayerID,
  122. tokenData,
  123. true);
  124. playCards.Add(tokenCard);
  125. }
  126. if (CanPlayAsNewPermanent(cardSource: playCards[0], payCost: false, cardEffect: activateClass))
  127. {
  128. yield return ContinuousController.instance.StartCoroutine(new PlayCardClass(
  129. cardSources: playCards,
  130. hashtable: CardEffectHashtable(activateClass),
  131. payCost: false,
  132. targetPermanent: null,
  133. isTapped: isTapped,
  134. root: SelectCardEffect.Root.None,
  135. activateETB: true).PlayCard());
  136. }
  137. }
  138. }
  139. #endregion
  140. #region Play 1 [Diaboromon] Token
  141. public static IEnumerator PlayDiaboromonToken(ICardEffect activateClass, int quantity = 1)
  142. {
  143. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  144. tokenData: ContinuousController.instance.DiaboromonToken,
  145. activateClass: activateClass,
  146. isOwnerPermanent: true,
  147. isTapped: false,
  148. quantity: quantity
  149. ));
  150. }
  151. #endregion
  152. #region Play 1 [Amon of Crimson Flame] Token
  153. public static IEnumerator PlayAmonToken(ICardEffect activateClass)
  154. {
  155. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  156. tokenData: ContinuousController.instance.AmonToken,
  157. activateClass: activateClass,
  158. isOwnerPermanent: true,
  159. isTapped: false
  160. ));
  161. }
  162. #endregion
  163. #region Play 1 [Umon of Blue Thunder] Token
  164. public static IEnumerator PlayUmonToken(ICardEffect activateClass)
  165. {
  166. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  167. tokenData: ContinuousController.instance.UmonToken,
  168. activateClass: activateClass,
  169. isOwnerPermanent: true,
  170. isTapped: false
  171. ));
  172. }
  173. #endregion
  174. #region Play 1 [Fujitsumon] Token
  175. public static IEnumerator PlayFujitsumonToken(ICardEffect activateClass, bool isOwnerPermanent)
  176. {
  177. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  178. tokenData: ContinuousController.instance.FujitsumonToken,
  179. activateClass: activateClass,
  180. isOwnerPermanent: isOwnerPermanent,
  181. isTapped: true
  182. ));
  183. }
  184. #endregion
  185. #region Play 1 [Gyuukimon] Token
  186. public static IEnumerator PlayGyuukimonToken(ICardEffect activateClass)
  187. {
  188. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  189. tokenData: ContinuousController.instance.GyuukimonToken,
  190. activateClass: activateClass,
  191. isOwnerPermanent: true,
  192. isTapped: false
  193. ));
  194. }
  195. #endregion
  196. #region Play 1 [KoHagurumon] Token
  197. public static IEnumerator PlayKoHagurumonToken(ICardEffect activateClass)
  198. {
  199. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  200. tokenData: ContinuousController.instance.KoHagurumonToken,
  201. activateClass: activateClass,
  202. isOwnerPermanent: true,
  203. isTapped: false
  204. ));
  205. }
  206. #endregion
  207. #region Play 1 [Familiar] Token
  208. public static IEnumerator PlayFamiliarToken(ICardEffect activateClass, int quantity = 1)
  209. {
  210. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  211. tokenData: ContinuousController.instance.FamiliarToken,
  212. activateClass: activateClass,
  213. isOwnerPermanent: true,
  214. isTapped: false,
  215. quantity: quantity
  216. ));
  217. }
  218. #endregion
  219. #region Play 1 Self Deleting [Familiar] Token
  220. public static IEnumerator PlaySelfDeleteFamiliarToken(ICardEffect activateClass, int quantity = 1)
  221. {
  222. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  223. tokenData: ContinuousController.instance.SelfDeleteFamiliarToken,
  224. activateClass: activateClass,
  225. isOwnerPermanent: true,
  226. isTapped: false,
  227. quantity: quantity
  228. ));
  229. }
  230. #endregion
  231. #region Play 1 [Volée & Zerdrücken] Token
  232. public static IEnumerator PlayVoleeZerdrucken(ICardEffect activateClass)
  233. {
  234. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  235. tokenData: ContinuousController.instance.VoleeZerdruckenToken,
  236. activateClass: activateClass,
  237. isOwnerPermanent: true,
  238. isTapped: false
  239. ));
  240. }
  241. #endregion
  242. #region Play 1 [Uka-no-Mitama] Token
  243. public static IEnumerator PlayUkaNoMitama(ICardEffect activateClass)
  244. {
  245. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  246. tokenData: ContinuousController.instance.UkaNoMitamaToken,
  247. activateClass: activateClass,
  248. isOwnerPermanent: true,
  249. isTapped: false
  250. ));
  251. }
  252. #endregion
  253. #region Play 1 [WarGrowlmon] Token
  254. public static IEnumerator PlayWarGrowlmonToken(ICardEffect activateClass)
  255. {
  256. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  257. tokenData: ContinuousController.instance.WarGrowlmonToken,
  258. activateClass: activateClass,
  259. isOwnerPermanent: true,
  260. isTapped: false
  261. ));
  262. }
  263. #endregion
  264. #region Play 1 [Taomon] Token
  265. public static IEnumerator PlayTaomonToken(ICardEffect activateClass)
  266. {
  267. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  268. tokenData: ContinuousController.instance.TaomonToken,
  269. activateClass: activateClass,
  270. isOwnerPermanent: true,
  271. isTapped: false
  272. ));
  273. }
  274. #endregion
  275. #region Play 1 [Rapidmon] Token
  276. public static IEnumerator PlayRapidmonToken(ICardEffect activateClass)
  277. {
  278. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  279. tokenData: ContinuousController.instance.RapidmonToken,
  280. activateClass: activateClass,
  281. isOwnerPermanent: true,
  282. isTapped: false
  283. ));
  284. }
  285. #endregion
  286. #region Play 1 [Pipe-Fox] Token
  287. public static IEnumerator PlayPipeFox(ICardEffect activateClass)
  288. {
  289. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  290. tokenData: ContinuousController.instance.PipeFoxToken,
  291. activateClass: activateClass,
  292. isOwnerPermanent: true,
  293. isTapped: false
  294. ));
  295. }
  296. #endregion
  297. #region Play 1 [AthoRenePor] Token
  298. public static IEnumerator PlayAthoRenePorToken(ICardEffect activateClass)
  299. {
  300. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  301. tokenData: ContinuousController.instance.AthoRenePorToken,
  302. activateClass: activateClass,
  303. isOwnerPermanent: true,
  304. isTapped: false
  305. ));
  306. }
  307. #endregion
  308. #region Play 1 [Hinukamuy] Token
  309. public static IEnumerator PlayHinukamuyToken(ICardEffect activateClass)
  310. {
  311. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  312. tokenData: ContinuousController.instance.HinukamuyToken,
  313. activateClass: activateClass,
  314. isOwnerPermanent: true,
  315. isTapped: false
  316. ));
  317. }
  318. #endregion
  319. #region Play [Petrification] Token(s)
  320. public static IEnumerator PlayPetrificationToken(ICardEffect activateClass, int quantity = 1)
  321. {
  322. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  323. tokenData: ContinuousController.instance.PetrificationToken,
  324. activateClass: activateClass,
  325. isOwnerPermanent: false,
  326. isTapped: false,
  327. quantity
  328. ));
  329. }
  330. #endregion
  331. #region Play [Paishu] Token(s)
  332. public static IEnumerator PlayPaishuToken(ICardEffect activateClass, int quantity = 1)
  333. {
  334. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  335. tokenData: ContinuousController.instance.PaishuToken,
  336. activateClass: activateClass,
  337. isOwnerPermanent: true,
  338. isTapped: false,
  339. quantity
  340. ));
  341. }
  342. #endregion
  343. #region Play [Kotenken] Token(s)
  344. public static IEnumerator PlayKotenkenToken(ICardEffect activateClass, int quantity = 1)
  345. {
  346. yield return ContinuousController.instance.StartCoroutine(PlayToken(
  347. tokenData: ContinuousController.instance.KotenkenToken,
  348. activateClass: activateClass,
  349. isOwnerPermanent: true,
  350. isTapped: false,
  351. quantity
  352. ));
  353. }
  354. #endregion
  355. #region Security effect of "add this card to hand"
  356. public static IEnumerator AddThisCardToHand(CardSource card1, ICardEffect activateClass)
  357. {
  358. yield return new WaitForSeconds(0.5f);
  359. yield return ContinuousController.instance.StartCoroutine(card1.Owner.brainStormObject.CloseBrainstrorm(card1));
  360. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(new List<CardSource>() { card1 }, false, activateClass));
  361. }
  362. #endregion
  363. #region Suspend target permanents, and the effect determines whether the permanent has been suspended or not
  364. public static IEnumerator SuspendPeremanentAndProcessAccordingToResult(List<Permanent> targetPermanents, ICardEffect activateClass, Func<List<Permanent>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  365. {
  366. SuspendPermanentsClass suspendPermanentsClass = new SuspendPermanentsClass(targetPermanents, CardEffectHashtable(activateClass));
  367. yield return ContinuousController.instance.StartCoroutine(suspendPermanentsClass.Tap());
  368. if (targetPermanents.Some((permanent) => suspendPermanentsClass.IsSuspended(permanent)))
  369. {
  370. if (successProcess != null)
  371. {
  372. yield return ContinuousController.instance.StartCoroutine(successProcess(suspendPermanentsClass.SuspendedPermanents));
  373. }
  374. }
  375. else
  376. {
  377. if (failureProcess != null)
  378. {
  379. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  380. }
  381. }
  382. }
  383. #endregion
  384. #region Delete target permanents, and the effect determines whether the permanent has been deleted or not
  385. public static IEnumerator DeletePeremanentAndProcessAccordingToResult(List<Permanent> targetPermanents, ICardEffect activateClass, Func<List<Permanent>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  386. {
  387. DestroyPermanentsClass destroyPermanentsClass = new DestroyPermanentsClass(targetPermanents, CardEffectHashtable(activateClass));
  388. yield return ContinuousController.instance.StartCoroutine(destroyPermanentsClass.Destroy());
  389. if (targetPermanents.Some((permanent) => destroyPermanentsClass.IsDestroyed(permanent)))
  390. {
  391. if (successProcess != null)
  392. {
  393. yield return ContinuousController.instance.StartCoroutine(successProcess(destroyPermanentsClass.DestroyedPermanents));
  394. }
  395. }
  396. else
  397. {
  398. if (failureProcess != null)
  399. {
  400. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  401. }
  402. }
  403. }
  404. #endregion
  405. #region Bounce target 1 permanent, and the effect determines whether the permanent has been bounced or not
  406. public static IEnumerator BouncePeremanentAndProcessAccordingToResult(List<Permanent> targetPermanents, ICardEffect activateClass, IEnumerator successProcess, IEnumerator failureProcess)
  407. {
  408. HandBounceClaass bouncePermanentClass = new HandBounceClaass(targetPermanents, CardEffectHashtable(activateClass));
  409. yield return ContinuousController.instance.StartCoroutine(bouncePermanentClass.Bounce());
  410. if (targetPermanents.Some((permanent) => bouncePermanentClass.IsBounced(permanent)))
  411. {
  412. if (successProcess != null)
  413. {
  414. yield return ContinuousController.instance.StartCoroutine(successProcess);
  415. }
  416. }
  417. else
  418. {
  419. if (failureProcess != null)
  420. {
  421. yield return ContinuousController.instance.StartCoroutine(failureProcess);
  422. }
  423. }
  424. }
  425. #endregion
  426. #region Deck Bounce target 1 permanent, and the effect determines whether the permanent has been bounced or not
  427. public static IEnumerator DeckBouncePeremanentAndProcessAccordingToResult(List<Permanent> targetPermanents, ICardEffect activateClass, IEnumerator successProcess, IEnumerator failureProcess)
  428. {
  429. DeckBottomBounceClass deckBounceClass = new DeckBottomBounceClass(targetPermanents, CardEffectHashtable(activateClass));
  430. yield return ContinuousController.instance.StartCoroutine(deckBounceClass.DeckBounce());
  431. if (targetPermanents.Some((permanent) => deckBounceClass.IsDeckBounced(permanent)))
  432. {
  433. if (successProcess != null)
  434. {
  435. yield return ContinuousController.instance.StartCoroutine(successProcess);
  436. }
  437. }
  438. else
  439. {
  440. if (failureProcess != null)
  441. {
  442. yield return ContinuousController.instance.StartCoroutine(failureProcess);
  443. }
  444. }
  445. }
  446. #endregion
  447. #region Add target digivolution cards, and the effect determines whether the digivolution cards were added or not
  448. public static IEnumerator AddDigivolutionCardsAndProcessAccordingToResult(Permanent targetPermanent, List<CardSource> targetDigivolutionCards, bool isTop, ICardEffect activateClass, Func<List<CardSource>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  449. {
  450. if (targetPermanent == null) yield break;
  451. if (targetDigivolutionCards == null) yield break;
  452. if (targetDigivolutionCards.Count == 0) yield break;
  453. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(targetDigivolutionCards, "Digivolution Cards", true, true));
  454. if (isTop) yield return ContinuousController.instance.StartCoroutine(targetPermanent.AddDigivolutionCardsTop(targetDigivolutionCards, activateClass));
  455. else yield return ContinuousController.instance.StartCoroutine(targetPermanent.AddDigivolutionCardsBottom(targetDigivolutionCards, activateClass));
  456. if (targetDigivolutionCards.Some((sourceCard) => targetPermanent.DigivolutionCards.Contains(sourceCard)))
  457. {
  458. if (successProcess != null)
  459. {
  460. yield return ContinuousController.instance.StartCoroutine(successProcess(targetDigivolutionCards));
  461. }
  462. }
  463. else
  464. {
  465. if (failureProcess != null)
  466. {
  467. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  468. }
  469. }
  470. }
  471. #endregion
  472. #region Trash target digivolution cards, and the effect determines whether the digivolution cards were trashed or not
  473. public static IEnumerator TrashDigivolutionCardsAndProcessAccordingToResult(Permanent targetPermanent, List<CardSource> targetDigivolutionCards, ICardEffect activateClass, Func<List<CardSource>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  474. {
  475. ITrashDigivolutionCards trashDigivolutionCards = new ITrashDigivolutionCards(targetPermanent, targetDigivolutionCards, activateClass);
  476. yield return ContinuousController.instance.StartCoroutine(trashDigivolutionCards.TrashDigivolutionCards());
  477. if (targetDigivolutionCards.Some((sourceCard) => trashDigivolutionCards.IsTrashed(sourceCard)))
  478. {
  479. if (successProcess != null)
  480. {
  481. yield return ContinuousController.instance.StartCoroutine(successProcess(trashDigivolutionCards.TrashedCards));
  482. }
  483. }
  484. else
  485. {
  486. if (failureProcess != null)
  487. {
  488. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  489. }
  490. }
  491. }
  492. #endregion
  493. #region Trash target link cards, and the effect determines whether the link cards were trashed or not
  494. public static IEnumerator TrashLinkCardsAndProcessAccordingToResult(Permanent targetPermanent, List<CardSource> targetLinkCards, ICardEffect activateClass, Func<List<CardSource>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  495. {
  496. ITrashLinkCards trashLinkCards = new ITrashLinkCards(targetPermanent, targetLinkCards, activateClass);
  497. yield return ContinuousController.instance.StartCoroutine(trashLinkCards.TrashLinkCards());
  498. if (targetLinkCards.Some((sourceCard) => trashLinkCards.IsTrashed(sourceCard)))
  499. {
  500. if (successProcess != null)
  501. {
  502. yield return ContinuousController.instance.StartCoroutine(successProcess(trashLinkCards.TrashedLinkCards));
  503. }
  504. }
  505. else
  506. {
  507. if (failureProcess != null)
  508. {
  509. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  510. }
  511. }
  512. }
  513. #endregion
  514. #region Trash Security cards and the effect determines whether the security were trashed or not
  515. public static IEnumerator TrashSecurityAndProcessAccordingToResult(Player player, int trashAmount, ICardEffect activateClass, bool fromTop, Func<List<CardSource>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  516. {
  517. IDestroySecurity destroySecurity = new IDestroySecurity(player, trashAmount, activateClass, fromTop);
  518. yield return ContinuousController.instance.StartCoroutine(destroySecurity.DestroySecurity());
  519. if (destroySecurity.DestroyedSecurity.Any())
  520. {
  521. if (successProcess != null)
  522. {
  523. yield return ContinuousController.instance.StartCoroutine(successProcess(destroySecurity.DestroyedSecurity));
  524. }
  525. }
  526. else
  527. {
  528. if (failureProcess != null)
  529. {
  530. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  531. }
  532. }
  533. }
  534. #endregion
  535. #region Trash Hand card and the effect determines whether the security were trashed or not
  536. public static IEnumerator TrashHandAndProcessAccordingToResult(Player player, Hashtable hashtable, CardSource cardToTrash, ActivateClass activateClass, Func<CardSource, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  537. {
  538. IDiscardHands discardHands = new IDiscardHands(new List<IDiscardHand>() { new IDiscardHand(cardToTrash, hashtable) }, activateClass);
  539. yield return ContinuousController.instance.StartCoroutine(discardHands.DiscardHands());
  540. if (discardHands.HasDiscarded)
  541. {
  542. if (successProcess != null)
  543. {
  544. yield return ContinuousController.instance.StartCoroutine(successProcess(cardToTrash));
  545. }
  546. }
  547. else
  548. {
  549. if (failureProcess != null)
  550. {
  551. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  552. }
  553. }
  554. }
  555. #endregion
  556. #region Place in security with callbacks for success or failure
  557. public static IEnumerator PlacePermanentInSecurityAndProcessAccordingToResult(Permanent targetPermanent, ICardEffect activateClass, bool toTop, Func<CardSource, IEnumerator> successProcess, Func<IEnumerator> failureProcess = null, bool isFaceUp = false)
  558. {
  559. IPutSecurityPermanent putSecurityPermanent = new IPutSecurityPermanent(targetPermanent, CardEffectCommons.CardEffectHashtable(activateClass), toTop, isFaceUp);
  560. CardSource topCard = targetPermanent.TopCard;
  561. if (activateClass.EffectSourceCard != null
  562. && activateClass.EffectSourceCard.Owner.CanAddSecurity(activateClass))
  563. {
  564. yield return ContinuousController.instance.StartCoroutine(putSecurityPermanent.PutSecurity());
  565. }
  566. if (putSecurityPermanent.IsPlacedSecurity)
  567. {
  568. if (successProcess != null)
  569. {
  570. yield return ContinuousController.instance.StartCoroutine(successProcess(topCard));
  571. }
  572. }
  573. else
  574. {
  575. if (failureProcess != null)
  576. {
  577. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  578. }
  579. }
  580. }
  581. #endregion
  582. #region Trash digivolution cards from top or bottom
  583. public static IEnumerator TrashDigivolutionCardsFromTopOrBottom(Permanent targetPermanent, int trashCount, bool isFromTop, ICardEffect activateClass, Func<CardSource, bool> cardCondition = null)
  584. {
  585. if (activateClass == null) yield break;
  586. if (targetPermanent == null) yield break;
  587. if (targetPermanent.TopCard == null) yield break;
  588. if (targetPermanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(activateClass)) == 0) yield break;
  589. if (targetPermanent.TopCard.CanNotBeAffected(activateClass)) yield break;
  590. if (trashCount <= 0) yield break;
  591. List<CardSource> trashTargetCards = new List<CardSource>();
  592. for (int i = 0; i < targetPermanent.DigivolutionCards.Count; i++)
  593. {
  594. if (trashTargetCards.Count >= trashCount)
  595. break;
  596. int index = isFromTop ? i : targetPermanent.DigivolutionCards.Count - 1 - i;
  597. CardSource trashTargetCard = targetPermanent.DigivolutionCards[index];
  598. bool trashCard = true;
  599. if (cardCondition != null)
  600. trashCard = cardCondition(trashTargetCard);
  601. if (trashCard)
  602. trashTargetCards.Add(trashTargetCard);
  603. }
  604. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(targetPermanent, trashTargetCards, activateClass).TrashDigivolutionCards());
  605. }
  606. #endregion
  607. #region this Option card's Main effect
  608. public static ActivateClass OptionMainEffect(CardSource card) => card.EffectList(EffectTiming.OptionSkill).Find(cardEffect => cardEffect != null && cardEffect is ActivateClass && cardEffect.EffectDiscription.Contains("[Main]")) as ActivateClass;
  609. #endregion
  610. #region this Option card's Security effect
  611. public static ActivateClass OptionSecurityEffect(CardSource card) => card.EffectList(EffectTiming.SecuritySkill).Find(cardEffect => cardEffect != null && cardEffect is ActivateClass && cardEffect.EffectDiscription.Contains("[Security]")) as ActivateClass;
  612. #endregion
  613. #region Add Option's Security effect that "Activate this card's Main effect" to cardEffects
  614. public static void AddActivateMainOptionSecurityEffect(CardSource card, ref List<ICardEffect> cardEffects, string effectName, string effectDiscription = "", Func<ICardEffect, IEnumerator> afterMainEffect = null)
  615. {
  616. if (OptionMainEffect(card) == null) return;
  617. cardEffects.Add(CardEffectFactory.ActivateMainOptionSecurityEffect(card, effectName, effectDiscription, afterMainEffect));
  618. }
  619. #endregion
  620. #region Activate Main of Dual Cards Option Side
  621. public static IEnumerator ActivateMainOfOptionSide(CardSource card, ICardEffect activateClass, Func<ICardEffect, IEnumerator> afterMainEffect = null, bool asEffectOfThisDigimon = false)
  622. {
  623. ActivateClass mainActivateClass = OptionMainEffect(card);
  624. #region Set as option effect unless explicitly effect of the digimon
  625. mainActivateClass.SetIsDigimonEffect(asEffectOfThisDigimon);
  626. mainActivateClass.SetIsTamerEffect(false);
  627. #endregion
  628. if (mainActivateClass != null)
  629. {
  630. yield return ContinuousController.instance.StartCoroutine(mainActivateClass.Activate(CardEffectCommons.OptionMainCheckHashtable(card)));
  631. }
  632. if (afterMainEffect != null)
  633. {
  634. yield return ContinuousController.instance.StartCoroutine(afterMainEffect(activateClass));
  635. }
  636. }
  637. #endregion
  638. #region Target permanent Digivolves into Digimon card from hand or trash
  639. public static IEnumerator DigivolveIntoHandOrTrashCard(
  640. Permanent targetPermanent,
  641. Func<CardSource, bool> cardCondition,
  642. bool payCost,
  643. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple,
  644. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple,
  645. int ignoreDigivolutionRequirementFixedCost,
  646. bool isHand,
  647. ICardEffect activateClass,
  648. IEnumerator successProcess,
  649. //bool ignoreLevel = false,
  650. bool ignoreSelection = false,
  651. IgnoreRequirement ignoreRequirements = IgnoreRequirement.None,
  652. IEnumerator failedProcess = null,
  653. bool isOptional = true)
  654. {
  655. if (targetPermanent == null) yield break;
  656. if (targetPermanent.TopCard == null) yield break;
  657. if (activateClass == null) yield break;
  658. if (activateClass.EffectSourceCard == null) yield break;
  659. Player owner = targetPermanent.TopCard.Owner;
  660. SelectCardEffect.Root root = isHand ? SelectCardEffect.Root.Hand : SelectCardEffect.Root.Trash;
  661. bool ignoreDigivolutionRequirement = !ignoreRequirements.Equals(IgnoreRequirement.None) || ignoreDigivolutionRequirementFixedCost >= 0;// ignoreDigivolutionRequirementFixedCost >= 0 || ignoreRequirements;
  662. int fixedCost = -1;
  663. bool successful = false;
  664. if (fixedCostTuple != null)
  665. {
  666. fixedCost = fixedCostTuple.Value.fixedCost;
  667. }
  668. if (ignoreDigivolutionRequirement)
  669. {
  670. fixedCost = ignoreDigivolutionRequirementFixedCost;
  671. }
  672. bool CanSelectCardCondition(CardSource cardSource)
  673. {
  674. if (cardSource.IsDigimon)
  675. {
  676. if (cardCondition == null || cardCondition(cardSource))
  677. {
  678. if (!cardSource.CanNotEvolve(targetPermanent))
  679. {
  680. bool isBreeding = cardSource.Owner.GetBreedingAreaPermanents().Contains(targetPermanent);
  681. if (cardSource.CanPlayCardTargetFrame(
  682. frame: targetPermanent.PermanentFrame,
  683. PayCost: payCost,
  684. cardEffect: activateClass,
  685. root: root,
  686. fixedCost: fixedCost,
  687. ignore: ignoreRequirements,
  688. isBreedingArea: isBreeding))
  689. {
  690. return true;
  691. }
  692. }
  693. }
  694. }
  695. return false;
  696. }
  697. #region reduce cost
  698. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  699. if (reduceCostTuple != null)
  700. {
  701. bool PermanentCondition(Permanent permanent)
  702. {
  703. return permanent == targetPermanent;
  704. }
  705. bool CardCondition(CardSource cardSource)
  706. {
  707. if (cardSource != null)
  708. {
  709. if (cardSource.Owner == owner)
  710. {
  711. if (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource))
  712. {
  713. return true;
  714. }
  715. }
  716. }
  717. return false;
  718. }
  719. getChangeCostEffect = ChangeDigivolutionCostPlayerEffect(
  720. permanentCondition: PermanentCondition,
  721. cardCondition: CardCondition,
  722. rootCondition: null,
  723. changeValue: -reduceCostTuple.Value.reduceCost,
  724. activateClass: activateClass,
  725. setFixedCost: false);
  726. if (getChangeCostEffect != null)
  727. {
  728. AddEffectToPlayer(
  729. effectDuration: EffectDuration.UntilCalculateFixedCost,
  730. card: targetPermanent.TopCard,
  731. cardEffect: null,
  732. timing: EffectTiming.None,
  733. getCardEffect: getChangeCostEffect);
  734. }
  735. }
  736. #endregion
  737. #region set fixed cost
  738. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  739. if (fixedCostTuple != null)
  740. {
  741. bool PermanentCondition(Permanent permanent)
  742. {
  743. return permanent == targetPermanent;
  744. }
  745. bool CardCondition(CardSource cardSource)
  746. {
  747. if (cardSource != null)
  748. {
  749. if (cardSource.Owner == owner)
  750. {
  751. if (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource))
  752. {
  753. return true;
  754. }
  755. }
  756. }
  757. return false;
  758. }
  759. getFixedCostEffect = ChangeDigivolutionCostPlayerEffect(
  760. permanentCondition: PermanentCondition,
  761. cardCondition: CardCondition,
  762. rootCondition: null,
  763. changeValue: fixedCost,
  764. activateClass: activateClass,
  765. setFixedCost: true);
  766. if (getChangeCostEffect != null)
  767. {
  768. AddEffectToPlayer(
  769. effectDuration: EffectDuration.UntilCalculateFixedCost,
  770. card: targetPermanent.TopCard,
  771. cardEffect: null,
  772. timing: EffectTiming.None,
  773. getCardEffect: getFixedCostEffect);
  774. }
  775. }
  776. #endregion
  777. #region ignore digivolution requirement
  778. Func<EffectTiming, ICardEffect> getIgnoreDigivolutionRequirementEffect = null;
  779. if (ignoreDigivolutionRequirement)
  780. {
  781. bool PermanentCondition(Permanent permanent)
  782. {
  783. return permanent == targetPermanent;
  784. }
  785. bool CardCondition(CardSource cardSource)
  786. {
  787. if (cardSource == null)
  788. {
  789. return false;
  790. }
  791. if (cardSource.Owner != owner)
  792. {
  793. return false;
  794. }
  795. if (cardCondition == null || cardCondition(cardSource))
  796. {
  797. return true;
  798. }
  799. return false;
  800. }
  801. getIgnoreDigivolutionRequirementEffect = GainIgnoreDigivolutionRequirementPlayerEffect(
  802. permanentCondition: PermanentCondition,
  803. cardCondition: CardCondition,
  804. ignoreDigivolutionRequirement: ignoreDigivolutionRequirement,
  805. digivolutionCost: fixedCost,
  806. activateClass: activateClass);
  807. if (getIgnoreDigivolutionRequirementEffect != null)
  808. {
  809. AddEffectToPlayer(
  810. effectDuration: EffectDuration.UntilCalculateFixedCost,
  811. card: targetPermanent.TopCard,
  812. cardEffect: null,
  813. timing: EffectTiming.None,
  814. getCardEffect: getIgnoreDigivolutionRequirementEffect);
  815. }
  816. }
  817. #endregion
  818. List<CardSource> selectedCards = new List<CardSource>();
  819. IEnumerator SelectCardCoroutine(CardSource cardSource)
  820. {
  821. selectedCards.Add(cardSource);
  822. yield return null;
  823. }
  824. if (isHand)
  825. {
  826. if (owner.HandCards.Count(CanSelectCardCondition) >= 1)
  827. {
  828. int maxCount = Mathf.Min(1, owner.HandCards.Count(CanSelectCardCondition));
  829. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  830. selectHandEffect.SetUp(
  831. selectPlayer: owner,
  832. canTargetCondition: CanSelectCardCondition,
  833. canTargetCondition_ByPreSelecetedList: null,
  834. canEndSelectCondition: null,
  835. maxCount: maxCount,
  836. canNoSelect: isOptional,
  837. canEndNotMax: false,
  838. isShowOpponent: true,
  839. selectCardCoroutine: SelectCardCoroutine,
  840. afterSelectCardCoroutine: null,
  841. mode: SelectHandEffect.Mode.Custom,
  842. cardEffect: activateClass);
  843. selectHandEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  844. selectHandEffect.SetUpCustomMessage_ShowCard("Selected Card");
  845. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  846. }
  847. }
  848. else
  849. {
  850. if (HasMatchConditionOwnersCardInTrash(targetPermanent.TopCard, CanSelectCardCondition) && !ignoreSelection)
  851. {
  852. int maxCount = 1;
  853. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  854. selectCardEffect.SetUp(
  855. canTargetCondition: CanSelectCardCondition,
  856. canTargetCondition_ByPreSelecetedList: null,
  857. canEndSelectCondition: null,
  858. canNoSelect: () => isOptional,
  859. selectCardCoroutine: SelectCardCoroutine,
  860. afterSelectCardCoroutine: null,
  861. message: "Select 1 card to digivolve.",
  862. maxCount: maxCount,
  863. canEndNotMax: false,
  864. isShowOpponent: true,
  865. mode: SelectCardEffect.Mode.Custom,
  866. root: SelectCardEffect.Root.Trash,
  867. customRootCardList: null,
  868. canLookReverseCard: true,
  869. selectPlayer: owner,
  870. cardEffect: activateClass);
  871. selectCardEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  872. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  873. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  874. }
  875. else
  876. {
  877. if (ignoreSelection)
  878. selectedCards.Add(activateClass.EffectSourceCard);
  879. }
  880. }
  881. PlayCardClass playCardClass = new PlayCardClass(
  882. cardSources: selectedCards,
  883. hashtable: CardEffectHashtable(activateClass),
  884. payCost: payCost,
  885. targetPermanent: targetPermanent,
  886. isTapped: false,
  887. root: root,
  888. activateETB: true);
  889. //if (ignoreRequirements.Equals(IgnoreRequirement.All) || ignoreRequirements.Equals(IgnoreRequirement.Level))
  890. // playCardClass.SetIgnoreLevel();
  891. playCardClass.SetIgnoreRequirements(ignoreRequirements);
  892. //!ignoreRequirements
  893. if (fixedCost >= 0)
  894. playCardClass.SetFixedCost(fixedCost);
  895. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  896. #region release effect
  897. if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  898. #endregion
  899. #region release effect
  900. if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  901. #endregion
  902. #region release effect
  903. if (getIgnoreDigivolutionRequirementEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getIgnoreDigivolutionRequirementEffect);
  904. #endregion
  905. if (selectedCards.Count >= 1)
  906. {
  907. if (IsDigivolvedByTheEffect(targetPermanent, selectedCards[0], activateClass))
  908. {
  909. successful = true;
  910. }
  911. }
  912. if (successful)
  913. {
  914. if (successProcess != null)
  915. yield return ContinuousController.instance.StartCoroutine(successProcess);
  916. }
  917. else
  918. {
  919. if (failedProcess != null)
  920. yield return ContinuousController.instance.StartCoroutine(failedProcess);
  921. }
  922. }
  923. #endregion
  924. #region Target permanent Digivolves into Digimon card execution area
  925. public static IEnumerator DigivolveIntoExcecutingAreaCard(
  926. Permanent targetPermanent,
  927. Func<CardSource, bool> cardCondition,
  928. bool payCost,
  929. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple,
  930. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple,
  931. int ignoreDigivolutionRequirementFixedCost,
  932. ICardEffect activateClass,
  933. IEnumerator successProcess,
  934. bool ignoreSelection = false,
  935. IgnoreRequirement ignoreRequirements = IgnoreRequirement.None)
  936. {
  937. if (targetPermanent == null) yield break;
  938. if (targetPermanent.TopCard == null) yield break;
  939. if (activateClass == null) yield break;
  940. if (activateClass.EffectSourceCard == null) yield break;
  941. Player owner = targetPermanent.TopCard.Owner;
  942. SelectCardEffect.Root root = SelectCardEffect.Root.Execution;
  943. bool ignoreDigivolutionRequirement = !ignoreRequirements.Equals(IgnoreRequirement.None) || ignoreDigivolutionRequirementFixedCost >= 0;// ignoreDigivolutionRequirementFixedCost >= 0 || ignoreRequirements;
  944. int fixedCost = -1;
  945. if (fixedCostTuple != null)
  946. {
  947. fixedCost = fixedCostTuple.Value.fixedCost;
  948. }
  949. if (ignoreDigivolutionRequirement)
  950. {
  951. fixedCost = ignoreDigivolutionRequirementFixedCost;
  952. }
  953. bool CanSelectCardCondition(CardSource cardSource)
  954. {
  955. if (cardSource.IsDigimon)
  956. {
  957. if (cardCondition == null || cardCondition(cardSource))
  958. {
  959. if (!cardSource.CanNotEvolve(targetPermanent))
  960. {
  961. if (cardSource.CanPlayCardTargetFrame(
  962. frame: targetPermanent.PermanentFrame,
  963. PayCost: payCost,
  964. cardEffect: activateClass,
  965. root: root,
  966. fixedCost: fixedCost,
  967. ignore: ignoreRequirements))
  968. {
  969. return true;
  970. }
  971. }
  972. }
  973. }
  974. return false;
  975. }
  976. #region reduce cost
  977. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  978. if (reduceCostTuple != null)
  979. {
  980. bool PermanentCondition(Permanent permanent)
  981. {
  982. return permanent == targetPermanent;
  983. }
  984. bool CardCondition(CardSource cardSource)
  985. {
  986. if (cardSource != null)
  987. {
  988. if (cardSource.Owner == owner)
  989. {
  990. if (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource))
  991. {
  992. return true;
  993. }
  994. }
  995. }
  996. return false;
  997. }
  998. getChangeCostEffect = ChangeDigivolutionCostPlayerEffect(
  999. permanentCondition: PermanentCondition,
  1000. cardCondition: CardCondition,
  1001. rootCondition: null,
  1002. changeValue: -reduceCostTuple.Value.reduceCost,
  1003. activateClass: activateClass,
  1004. setFixedCost: false);
  1005. if (getChangeCostEffect != null)
  1006. {
  1007. AddEffectToPlayer(
  1008. effectDuration: EffectDuration.UntilCalculateFixedCost,
  1009. card: targetPermanent.TopCard,
  1010. cardEffect: null,
  1011. timing: EffectTiming.None,
  1012. getCardEffect: getChangeCostEffect);
  1013. }
  1014. }
  1015. #endregion
  1016. #region set fixed cost
  1017. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  1018. if (fixedCostTuple != null)
  1019. {
  1020. bool PermanentCondition(Permanent permanent)
  1021. {
  1022. return permanent == targetPermanent;
  1023. }
  1024. bool CardCondition(CardSource cardSource)
  1025. {
  1026. if (cardSource != null)
  1027. {
  1028. if (cardSource.Owner == owner)
  1029. {
  1030. if (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource))
  1031. {
  1032. return true;
  1033. }
  1034. }
  1035. }
  1036. return false;
  1037. }
  1038. getFixedCostEffect = ChangeDigivolutionCostPlayerEffect(
  1039. permanentCondition: PermanentCondition,
  1040. cardCondition: CardCondition,
  1041. rootCondition: null,
  1042. changeValue: fixedCost,
  1043. activateClass: activateClass,
  1044. setFixedCost: true);
  1045. if (getChangeCostEffect != null)
  1046. {
  1047. AddEffectToPlayer(
  1048. effectDuration: EffectDuration.UntilCalculateFixedCost,
  1049. card: targetPermanent.TopCard,
  1050. cardEffect: null,
  1051. timing: EffectTiming.None,
  1052. getCardEffect: getFixedCostEffect);
  1053. }
  1054. }
  1055. #endregion
  1056. #region ignore digivolution requirement
  1057. Func<EffectTiming, ICardEffect> getIgnoreDigivolutionRequirementEffect = null;
  1058. if (ignoreDigivolutionRequirement)
  1059. {
  1060. bool PermanentCondition(Permanent permanent)
  1061. {
  1062. return permanent == targetPermanent;
  1063. }
  1064. bool CardCondition(CardSource cardSource)
  1065. {
  1066. if (cardSource == null)
  1067. {
  1068. return false;
  1069. }
  1070. if (cardSource.Owner != owner)
  1071. {
  1072. return false;
  1073. }
  1074. if (cardCondition == null || cardCondition(cardSource))
  1075. {
  1076. return true;
  1077. }
  1078. return false;
  1079. }
  1080. getIgnoreDigivolutionRequirementEffect = GainIgnoreDigivolutionRequirementPlayerEffect(
  1081. permanentCondition: PermanentCondition,
  1082. cardCondition: CardCondition,
  1083. ignoreDigivolutionRequirement: ignoreDigivolutionRequirement,
  1084. digivolutionCost: fixedCost,
  1085. activateClass: activateClass);
  1086. if (getIgnoreDigivolutionRequirementEffect != null)
  1087. {
  1088. AddEffectToPlayer(
  1089. effectDuration: EffectDuration.UntilCalculateFixedCost,
  1090. card: targetPermanent.TopCard,
  1091. cardEffect: null,
  1092. timing: EffectTiming.None,
  1093. getCardEffect: getIgnoreDigivolutionRequirementEffect);
  1094. }
  1095. }
  1096. #endregion
  1097. List<CardSource> selectedCards = new List<CardSource>();
  1098. IEnumerator SelectCardCoroutine(CardSource cardSource)
  1099. {
  1100. selectedCards.Add(cardSource);
  1101. yield return null;
  1102. }
  1103. if (owner.ExecutingCards.Count(CanSelectCardCondition) > 1)
  1104. {
  1105. int maxCount = 1;
  1106. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  1107. selectCardEffect.SetUp(
  1108. canTargetCondition: CanSelectCardCondition,
  1109. canTargetCondition_ByPreSelecetedList: null,
  1110. canEndSelectCondition: null,
  1111. canNoSelect: () => true,
  1112. selectCardCoroutine: SelectCardCoroutine,
  1113. afterSelectCardCoroutine: null,
  1114. message: "Select 1 card to digivolve.",
  1115. maxCount: maxCount,
  1116. canEndNotMax: false,
  1117. isShowOpponent: true,
  1118. mode: SelectCardEffect.Mode.Custom,
  1119. root: SelectCardEffect.Root.Execution,
  1120. customRootCardList: null,
  1121. canLookReverseCard: true,
  1122. selectPlayer: owner,
  1123. cardEffect: activateClass);
  1124. selectCardEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  1125. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  1126. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  1127. }
  1128. else
  1129. {
  1130. selectedCards.Add(activateClass.EffectSourceCard);
  1131. }
  1132. PlayCardClass playCardClass = new PlayCardClass(
  1133. cardSources: selectedCards,
  1134. hashtable: CardEffectHashtable(activateClass),
  1135. payCost: payCost,
  1136. targetPermanent: targetPermanent,
  1137. isTapped: false,
  1138. root: root,
  1139. activateETB: true);
  1140. playCardClass.SetIgnoreRequirements(ignoreRequirements);
  1141. if (!ignoreDigivolutionRequirement && fixedCost >= 0) playCardClass.SetFixedCost(fixedCost);
  1142. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  1143. #region release effect
  1144. if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  1145. #endregion
  1146. #region release effect
  1147. if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  1148. #endregion
  1149. #region release effect
  1150. if (getIgnoreDigivolutionRequirementEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getIgnoreDigivolutionRequirementEffect);
  1151. #endregion
  1152. if (selectedCards.Count >= 1)
  1153. {
  1154. if (IsDigivolvedByTheEffect(targetPermanent, selectedCards[0], activateClass))
  1155. {
  1156. if (successProcess != null)
  1157. {
  1158. yield return ContinuousController.instance.StartCoroutine(successProcess);
  1159. }
  1160. }
  1161. }
  1162. }
  1163. #endregion
  1164. #region Get the effect given by EffectTiming
  1165. public static Func<EffectTiming, ICardEffect> GetCardEffectByEffectTiming(EffectTiming timing, ICardEffect cardEffect) => (_timing) => _timing == timing ? cardEffect : null;
  1166. #endregion
  1167. #region Draw cards and trash cards
  1168. public static IEnumerator DrawAndDiscardCards((Player drawPlayer, Player trashPlayer) player,
  1169. int drawAmount,
  1170. int trashAmount,
  1171. CardSource card,
  1172. ICardEffect activateClass,
  1173. Func<CardSource, bool> canTrashTargetCondition = null,
  1174. Func<List<CardSource>, CardSource, bool> canTargetCondition_ByPreSelecetedList = null,
  1175. Func<List<CardSource>, bool> canEndSelectCondition = null,
  1176. bool canNoSelect = false,
  1177. bool canEndNotMax = false,
  1178. bool isShowOpponent = true,
  1179. Func<List<CardSource>, IEnumerator> afterSelectPermanentCoroutine = null)
  1180. {
  1181. // Callback Setup
  1182. Func<List<CardSource>, IEnumerator> AfterSelectCardCoroutine = afterSelectPermanentCoroutine ?? null;
  1183. // Variable setup
  1184. Func<CardSource, bool> targetTrashCondition = canTrashTargetCondition ?? (cs => true);
  1185. yield return ContinuousController.instance.StartCoroutine(new DrawClass(player.drawPlayer, drawAmount, activateClass).Draw());
  1186. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  1187. selectHandEffect.SetUp(
  1188. selectPlayer: player.trashPlayer,
  1189. canTargetCondition: targetTrashCondition,
  1190. canTargetCondition_ByPreSelecetedList: canTargetCondition_ByPreSelecetedList,
  1191. canEndSelectCondition: canEndSelectCondition,
  1192. maxCount: trashAmount,
  1193. canNoSelect: canNoSelect,
  1194. canEndNotMax: canEndNotMax,
  1195. isShowOpponent: isShowOpponent,
  1196. selectCardCoroutine: null,
  1197. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  1198. mode: SelectHandEffect.Mode.Discard,
  1199. cardEffect: activateClass);
  1200. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  1201. }
  1202. #endregion
  1203. }