CardEffectCommons.cs 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475
  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 Trash target digivolution cards, and the effect determines whether the digivolution cards were trashed or not
  448. public static IEnumerator TrashDigivolutionCardsAndProcessAccordingToResult(Permanent targetPermanent, List<CardSource> targetDigivolutionCards, ICardEffect activateClass, Func<List<CardSource>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  449. {
  450. ITrashDigivolutionCards trashDigivolutionCards = new ITrashDigivolutionCards(targetPermanent, targetDigivolutionCards, activateClass);
  451. yield return ContinuousController.instance.StartCoroutine(trashDigivolutionCards.TrashDigivolutionCards());
  452. if (targetDigivolutionCards.Some((sourceCard) => trashDigivolutionCards.IsTrashed(sourceCard)))
  453. {
  454. if (successProcess != null)
  455. {
  456. yield return ContinuousController.instance.StartCoroutine(successProcess(trashDigivolutionCards.TrashedCards));
  457. }
  458. }
  459. else
  460. {
  461. if (failureProcess != null)
  462. {
  463. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  464. }
  465. }
  466. }
  467. #endregion
  468. #region Trash target link cards, and the effect determines whether the link cards were trashed or not
  469. public static IEnumerator TrashLinkCardsAndProcessAccordingToResult(Permanent targetPermanent, List<CardSource> targetLinkCards, ICardEffect activateClass, Func<List<CardSource>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  470. {
  471. ITrashLinkCards trashLinkCards = new ITrashLinkCards(targetPermanent, targetLinkCards, activateClass);
  472. yield return ContinuousController.instance.StartCoroutine(trashLinkCards.TrashLinkCards());
  473. if (targetLinkCards.Some((sourceCard) => trashLinkCards.IsTrashed(sourceCard)))
  474. {
  475. if (successProcess != null)
  476. {
  477. yield return ContinuousController.instance.StartCoroutine(successProcess(trashLinkCards.TrashedLinkCards));
  478. }
  479. }
  480. else
  481. {
  482. if (failureProcess != null)
  483. {
  484. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  485. }
  486. }
  487. }
  488. #endregion
  489. #region Trash Security cards and the effect determines whether the security were trashed or not
  490. public static IEnumerator TrashSecurityAndProcessAccordingToResult(Player player, int trashAmount, ICardEffect activateClass, bool fromTop, Func<List<CardSource>, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  491. {
  492. IDestroySecurity destroySecurity = new IDestroySecurity(player, trashAmount, activateClass, fromTop);
  493. yield return ContinuousController.instance.StartCoroutine(destroySecurity.DestroySecurity());
  494. if (destroySecurity.DestroyedSecurity.Any())
  495. {
  496. if (successProcess != null)
  497. {
  498. yield return ContinuousController.instance.StartCoroutine(successProcess(destroySecurity.DestroyedSecurity));
  499. }
  500. }
  501. else
  502. {
  503. if (failureProcess != null)
  504. {
  505. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  506. }
  507. }
  508. }
  509. #endregion
  510. #region Trash Hand card and the effect determines whether the security were trashed or not
  511. public static IEnumerator TrashHandAndProcessAccordingToResult(Player player, Hashtable hashtable, CardSource cardToTrash, ActivateClass activateClass, Func<CardSource, IEnumerator> successProcess, Func<IEnumerator> failureProcess)
  512. {
  513. IDiscardHands discardHands = new IDiscardHands(new List<IDiscardHand>() { new IDiscardHand(cardToTrash, hashtable) }, activateClass);
  514. yield return ContinuousController.instance.StartCoroutine(discardHands.DiscardHands());
  515. if (discardHands.HasDiscarded)
  516. {
  517. if (successProcess != null)
  518. {
  519. yield return ContinuousController.instance.StartCoroutine(successProcess(cardToTrash));
  520. }
  521. }
  522. else
  523. {
  524. if (failureProcess != null)
  525. {
  526. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  527. }
  528. }
  529. }
  530. #endregion
  531. #region Place in security with callbacks for success or failure
  532. public static IEnumerator PlacePermanentInSecurityAndProcessAccordingToResult(Permanent targetPermanent, ICardEffect activateClass, bool toTop, Func<CardSource, IEnumerator> successProcess, Func<IEnumerator> failureProcess = null, bool isFaceUp = false)
  533. {
  534. IPutSecurityPermanent putSecurityPermanent = new IPutSecurityPermanent(targetPermanent, CardEffectCommons.CardEffectHashtable(activateClass), toTop, isFaceUp);
  535. CardSource topCard = targetPermanent.TopCard;
  536. if (activateClass.EffectSourceCard != null
  537. && activateClass.EffectSourceCard.Owner.CanAddSecurity(activateClass))
  538. {
  539. yield return ContinuousController.instance.StartCoroutine(putSecurityPermanent.PutSecurity());
  540. }
  541. if (putSecurityPermanent.IsPlacedSecurity)
  542. {
  543. if (successProcess != null)
  544. {
  545. yield return ContinuousController.instance.StartCoroutine(successProcess(topCard));
  546. }
  547. }
  548. else
  549. {
  550. if (failureProcess != null)
  551. {
  552. yield return ContinuousController.instance.StartCoroutine(failureProcess());
  553. }
  554. }
  555. }
  556. #endregion
  557. #region Trash digivolution cards from top or bottom
  558. public static IEnumerator TrashDigivolutionCardsFromTopOrBottom(Permanent targetPermanent, int trashCount, bool isFromTop, ICardEffect activateClass, Func<CardSource, bool> cardCondition = null)
  559. {
  560. if (activateClass == null) yield break;
  561. if (targetPermanent == null) yield break;
  562. if (targetPermanent.TopCard == null) yield break;
  563. if (targetPermanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(activateClass)) == 0) yield break;
  564. if (targetPermanent.TopCard.CanNotBeAffected(activateClass)) yield break;
  565. if (trashCount <= 0) yield break;
  566. List<CardSource> trashTargetCards = new List<CardSource>();
  567. for (int i = 0; i < targetPermanent.DigivolutionCards.Count; i++)
  568. {
  569. if (trashTargetCards.Count >= trashCount)
  570. break;
  571. int index = isFromTop ? i : targetPermanent.DigivolutionCards.Count - 1 - i;
  572. CardSource trashTargetCard = targetPermanent.DigivolutionCards[index];
  573. bool trashCard = true;
  574. if (cardCondition != null)
  575. trashCard = cardCondition(trashTargetCard);
  576. if (trashCard)
  577. trashTargetCards.Add(trashTargetCard);
  578. }
  579. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(targetPermanent, trashTargetCards, activateClass).TrashDigivolutionCards());
  580. }
  581. #endregion
  582. #region this Option card's Main effect
  583. public static ActivateClass OptionMainEffect(CardSource card) => card.EffectList(EffectTiming.OptionSkill).Find(cardEffect => cardEffect != null && cardEffect is ActivateClass && cardEffect.EffectDiscription.Contains("[Main]")) as ActivateClass;
  584. #endregion
  585. #region this Option card's Security effect
  586. public static ActivateClass OptionSecurityEffect(CardSource card) => card.EffectList(EffectTiming.SecuritySkill).Find(cardEffect => cardEffect != null && cardEffect is ActivateClass && cardEffect.EffectDiscription.Contains("[Security]")) as ActivateClass;
  587. #endregion
  588. #region Add Option's Security effect that "Activate this card's Main effect" to cardEffects
  589. public static void AddActivateMainOptionSecurityEffect(CardSource card, ref List<ICardEffect> cardEffects, string effectName, string effectDiscription = "", Func<ICardEffect, IEnumerator> afterMainEffect = null)
  590. {
  591. if (OptionMainEffect(card) == null) return;
  592. cardEffects.Add(CardEffectFactory.ActivateMainOptionSecurityEffect(card, effectName, effectDiscription, afterMainEffect));
  593. }
  594. #endregion
  595. #region Activate Main of Dual Cards Option Side
  596. public static IEnumerator ActivateMainOfOptionSide(CardSource card, ICardEffect activateClass, Func<ICardEffect, IEnumerator> afterMainEffect = null, bool asEffectOfThisDigimon = false)
  597. {
  598. ActivateClass mainActivateClass = OptionMainEffect(card);
  599. #region Set as option effect unless explicitly effect of the digimon
  600. mainActivateClass.SetIsDigimonEffect(asEffectOfThisDigimon);
  601. mainActivateClass.SetIsTamerEffect(false);
  602. #endregion
  603. if (mainActivateClass != null)
  604. {
  605. yield return ContinuousController.instance.StartCoroutine(mainActivateClass.Activate(CardEffectCommons.OptionMainCheckHashtable(card)));
  606. }
  607. if (afterMainEffect != null)
  608. {
  609. yield return ContinuousController.instance.StartCoroutine(afterMainEffect(activateClass));
  610. }
  611. }
  612. #endregion
  613. #region Target permanent Digivolves into Digimon card from hand or trash
  614. public static IEnumerator DigivolveIntoHandOrTrashCard(
  615. Permanent targetPermanent,
  616. Func<CardSource, bool> cardCondition,
  617. bool payCost,
  618. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple,
  619. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple,
  620. int ignoreDigivolutionRequirementFixedCost,
  621. bool isHand,
  622. ICardEffect activateClass,
  623. IEnumerator successProcess,
  624. //bool ignoreLevel = false,
  625. bool ignoreSelection = false,
  626. IgnoreRequirement ignoreRequirements = IgnoreRequirement.None,
  627. IEnumerator failedProcess = null,
  628. bool isOptional = true)
  629. {
  630. if (targetPermanent == null) yield break;
  631. if (targetPermanent.TopCard == null) yield break;
  632. if (activateClass == null) yield break;
  633. if (activateClass.EffectSourceCard == null) yield break;
  634. Player owner = targetPermanent.TopCard.Owner;
  635. SelectCardEffect.Root root = isHand ? SelectCardEffect.Root.Hand : SelectCardEffect.Root.Trash;
  636. bool ignoreDigivolutionRequirement = !ignoreRequirements.Equals(IgnoreRequirement.None) || ignoreDigivolutionRequirementFixedCost >= 0;// ignoreDigivolutionRequirementFixedCost >= 0 || ignoreRequirements;
  637. int fixedCost = -1;
  638. bool successful = false;
  639. if (fixedCostTuple != null)
  640. {
  641. fixedCost = fixedCostTuple.Value.fixedCost;
  642. }
  643. if (ignoreDigivolutionRequirement)
  644. {
  645. fixedCost = ignoreDigivolutionRequirementFixedCost;
  646. }
  647. bool CanSelectCardCondition(CardSource cardSource)
  648. {
  649. if (cardSource.IsDigimon)
  650. {
  651. if (cardCondition == null || cardCondition(cardSource))
  652. {
  653. if (!cardSource.CanNotEvolve(targetPermanent))
  654. {
  655. bool isBreeding = cardSource.Owner.GetBreedingAreaPermanents().Contains(targetPermanent);
  656. if (cardSource.CanPlayCardTargetFrame(
  657. frame: targetPermanent.PermanentFrame,
  658. PayCost: payCost,
  659. cardEffect: activateClass,
  660. root: root,
  661. fixedCost: fixedCost,
  662. ignore: ignoreRequirements,
  663. isBreedingArea: isBreeding))
  664. {
  665. return true;
  666. }
  667. }
  668. }
  669. }
  670. return false;
  671. }
  672. #region reduce cost
  673. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  674. if (reduceCostTuple != null)
  675. {
  676. bool PermanentCondition(Permanent permanent)
  677. {
  678. return permanent == targetPermanent;
  679. }
  680. bool CardCondition(CardSource cardSource)
  681. {
  682. if (cardSource != null)
  683. {
  684. if (cardSource.Owner == owner)
  685. {
  686. if (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource))
  687. {
  688. return true;
  689. }
  690. }
  691. }
  692. return false;
  693. }
  694. getChangeCostEffect = ChangeDigivolutionCostPlayerEffect(
  695. permanentCondition: PermanentCondition,
  696. cardCondition: CardCondition,
  697. rootCondition: null,
  698. changeValue: -reduceCostTuple.Value.reduceCost,
  699. activateClass: activateClass,
  700. setFixedCost: false);
  701. if (getChangeCostEffect != null)
  702. {
  703. AddEffectToPlayer(
  704. effectDuration: EffectDuration.UntilCalculateFixedCost,
  705. card: targetPermanent.TopCard,
  706. cardEffect: null,
  707. timing: EffectTiming.None,
  708. getCardEffect: getChangeCostEffect);
  709. }
  710. }
  711. #endregion
  712. #region set fixed cost
  713. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  714. if (fixedCostTuple != null)
  715. {
  716. bool PermanentCondition(Permanent permanent)
  717. {
  718. return permanent == targetPermanent;
  719. }
  720. bool CardCondition(CardSource cardSource)
  721. {
  722. if (cardSource != null)
  723. {
  724. if (cardSource.Owner == owner)
  725. {
  726. if (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource))
  727. {
  728. return true;
  729. }
  730. }
  731. }
  732. return false;
  733. }
  734. getFixedCostEffect = ChangeDigivolutionCostPlayerEffect(
  735. permanentCondition: PermanentCondition,
  736. cardCondition: CardCondition,
  737. rootCondition: null,
  738. changeValue: fixedCost,
  739. activateClass: activateClass,
  740. setFixedCost: true);
  741. if (getChangeCostEffect != null)
  742. {
  743. AddEffectToPlayer(
  744. effectDuration: EffectDuration.UntilCalculateFixedCost,
  745. card: targetPermanent.TopCard,
  746. cardEffect: null,
  747. timing: EffectTiming.None,
  748. getCardEffect: getFixedCostEffect);
  749. }
  750. }
  751. #endregion
  752. #region ignore digivolution requirement
  753. Func<EffectTiming, ICardEffect> getIgnoreDigivolutionRequirementEffect = null;
  754. if (ignoreDigivolutionRequirement)
  755. {
  756. bool PermanentCondition(Permanent permanent)
  757. {
  758. return permanent == targetPermanent;
  759. }
  760. bool CardCondition(CardSource cardSource)
  761. {
  762. if (cardSource == null)
  763. {
  764. return false;
  765. }
  766. if (cardSource.Owner != owner)
  767. {
  768. return false;
  769. }
  770. if (cardCondition == null || cardCondition(cardSource))
  771. {
  772. return true;
  773. }
  774. return false;
  775. }
  776. getIgnoreDigivolutionRequirementEffect = GainIgnoreDigivolutionRequirementPlayerEffect(
  777. permanentCondition: PermanentCondition,
  778. cardCondition: CardCondition,
  779. ignoreDigivolutionRequirement: ignoreDigivolutionRequirement,
  780. digivolutionCost: fixedCost,
  781. activateClass: activateClass);
  782. if (getIgnoreDigivolutionRequirementEffect != null)
  783. {
  784. AddEffectToPlayer(
  785. effectDuration: EffectDuration.UntilCalculateFixedCost,
  786. card: targetPermanent.TopCard,
  787. cardEffect: null,
  788. timing: EffectTiming.None,
  789. getCardEffect: getIgnoreDigivolutionRequirementEffect);
  790. }
  791. }
  792. #endregion
  793. List<CardSource> selectedCards = new List<CardSource>();
  794. IEnumerator SelectCardCoroutine(CardSource cardSource)
  795. {
  796. selectedCards.Add(cardSource);
  797. yield return null;
  798. }
  799. if (isHand)
  800. {
  801. if (owner.HandCards.Count(CanSelectCardCondition) >= 1)
  802. {
  803. int maxCount = Mathf.Min(1, owner.HandCards.Count(CanSelectCardCondition));
  804. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  805. selectHandEffect.SetUp(
  806. selectPlayer: owner,
  807. canTargetCondition: CanSelectCardCondition,
  808. canTargetCondition_ByPreSelecetedList: null,
  809. canEndSelectCondition: null,
  810. maxCount: maxCount,
  811. canNoSelect: isOptional,
  812. canEndNotMax: false,
  813. isShowOpponent: true,
  814. selectCardCoroutine: SelectCardCoroutine,
  815. afterSelectCardCoroutine: null,
  816. mode: SelectHandEffect.Mode.Custom,
  817. cardEffect: activateClass);
  818. selectHandEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  819. selectHandEffect.SetUpCustomMessage_ShowCard("Selected Card");
  820. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  821. }
  822. }
  823. else
  824. {
  825. if (HasMatchConditionOwnersCardInTrash(targetPermanent.TopCard, CanSelectCardCondition) && !ignoreSelection)
  826. {
  827. int maxCount = 1;
  828. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  829. selectCardEffect.SetUp(
  830. canTargetCondition: CanSelectCardCondition,
  831. canTargetCondition_ByPreSelecetedList: null,
  832. canEndSelectCondition: null,
  833. canNoSelect: () => isOptional,
  834. selectCardCoroutine: SelectCardCoroutine,
  835. afterSelectCardCoroutine: null,
  836. message: "Select 1 card to digivolve.",
  837. maxCount: maxCount,
  838. canEndNotMax: false,
  839. isShowOpponent: true,
  840. mode: SelectCardEffect.Mode.Custom,
  841. root: SelectCardEffect.Root.Trash,
  842. customRootCardList: null,
  843. canLookReverseCard: true,
  844. selectPlayer: owner,
  845. cardEffect: activateClass);
  846. selectCardEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  847. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  848. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  849. }
  850. else
  851. {
  852. if (ignoreSelection)
  853. selectedCards.Add(activateClass.EffectSourceCard);
  854. }
  855. }
  856. PlayCardClass playCardClass = new PlayCardClass(
  857. cardSources: selectedCards,
  858. hashtable: CardEffectHashtable(activateClass),
  859. payCost: payCost,
  860. targetPermanent: targetPermanent,
  861. isTapped: false,
  862. root: root,
  863. activateETB: true);
  864. //if (ignoreRequirements.Equals(IgnoreRequirement.All) || ignoreRequirements.Equals(IgnoreRequirement.Level))
  865. // playCardClass.SetIgnoreLevel();
  866. playCardClass.SetIgnoreRequirements(ignoreRequirements);
  867. //!ignoreRequirements
  868. if (fixedCost >= 0)
  869. playCardClass.SetFixedCost(fixedCost);
  870. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  871. #region release effect
  872. if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  873. #endregion
  874. #region release effect
  875. if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  876. #endregion
  877. #region release effect
  878. if (getIgnoreDigivolutionRequirementEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getIgnoreDigivolutionRequirementEffect);
  879. #endregion
  880. if (selectedCards.Count >= 1)
  881. {
  882. if (IsDigivolvedByTheEffect(targetPermanent, selectedCards[0], activateClass))
  883. {
  884. successful = true;
  885. }
  886. }
  887. if (successful)
  888. {
  889. if (successProcess != null)
  890. yield return ContinuousController.instance.StartCoroutine(successProcess);
  891. }
  892. else
  893. {
  894. if (failedProcess != null)
  895. yield return ContinuousController.instance.StartCoroutine(failedProcess);
  896. }
  897. }
  898. #endregion
  899. #region Target permanent Digivolves into Digimon card execution area
  900. public static IEnumerator DigivolveIntoExcecutingAreaCard(
  901. Permanent targetPermanent,
  902. Func<CardSource, bool> cardCondition,
  903. bool payCost,
  904. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple,
  905. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple,
  906. int ignoreDigivolutionRequirementFixedCost,
  907. ICardEffect activateClass,
  908. IEnumerator successProcess,
  909. bool ignoreSelection = false,
  910. IgnoreRequirement ignoreRequirements = IgnoreRequirement.None)
  911. {
  912. if (targetPermanent == null) yield break;
  913. if (targetPermanent.TopCard == null) yield break;
  914. if (activateClass == null) yield break;
  915. if (activateClass.EffectSourceCard == null) yield break;
  916. Player owner = targetPermanent.TopCard.Owner;
  917. SelectCardEffect.Root root = SelectCardEffect.Root.Execution;
  918. bool ignoreDigivolutionRequirement = !ignoreRequirements.Equals(IgnoreRequirement.None) || ignoreDigivolutionRequirementFixedCost >= 0;// ignoreDigivolutionRequirementFixedCost >= 0 || ignoreRequirements;
  919. int fixedCost = -1;
  920. if (fixedCostTuple != null)
  921. {
  922. fixedCost = fixedCostTuple.Value.fixedCost;
  923. }
  924. if (ignoreDigivolutionRequirement)
  925. {
  926. fixedCost = ignoreDigivolutionRequirementFixedCost;
  927. }
  928. bool CanSelectCardCondition(CardSource cardSource)
  929. {
  930. if (cardSource.IsDigimon)
  931. {
  932. if (cardCondition == null || cardCondition(cardSource))
  933. {
  934. if (!cardSource.CanNotEvolve(targetPermanent))
  935. {
  936. if (cardSource.CanPlayCardTargetFrame(
  937. frame: targetPermanent.PermanentFrame,
  938. PayCost: payCost,
  939. cardEffect: activateClass,
  940. root: root,
  941. fixedCost: fixedCost,
  942. ignore: ignoreRequirements))
  943. {
  944. return true;
  945. }
  946. }
  947. }
  948. }
  949. return false;
  950. }
  951. #region reduce cost
  952. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  953. if (reduceCostTuple != null)
  954. {
  955. bool PermanentCondition(Permanent permanent)
  956. {
  957. return permanent == targetPermanent;
  958. }
  959. bool CardCondition(CardSource cardSource)
  960. {
  961. if (cardSource != null)
  962. {
  963. if (cardSource.Owner == owner)
  964. {
  965. if (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource))
  966. {
  967. return true;
  968. }
  969. }
  970. }
  971. return false;
  972. }
  973. getChangeCostEffect = ChangeDigivolutionCostPlayerEffect(
  974. permanentCondition: PermanentCondition,
  975. cardCondition: CardCondition,
  976. rootCondition: null,
  977. changeValue: -reduceCostTuple.Value.reduceCost,
  978. activateClass: activateClass,
  979. setFixedCost: false);
  980. if (getChangeCostEffect != null)
  981. {
  982. AddEffectToPlayer(
  983. effectDuration: EffectDuration.UntilCalculateFixedCost,
  984. card: targetPermanent.TopCard,
  985. cardEffect: null,
  986. timing: EffectTiming.None,
  987. getCardEffect: getChangeCostEffect);
  988. }
  989. }
  990. #endregion
  991. #region set fixed cost
  992. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  993. if (fixedCostTuple != null)
  994. {
  995. bool PermanentCondition(Permanent permanent)
  996. {
  997. return permanent == targetPermanent;
  998. }
  999. bool CardCondition(CardSource cardSource)
  1000. {
  1001. if (cardSource != null)
  1002. {
  1003. if (cardSource.Owner == owner)
  1004. {
  1005. if (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource))
  1006. {
  1007. return true;
  1008. }
  1009. }
  1010. }
  1011. return false;
  1012. }
  1013. getFixedCostEffect = ChangeDigivolutionCostPlayerEffect(
  1014. permanentCondition: PermanentCondition,
  1015. cardCondition: CardCondition,
  1016. rootCondition: null,
  1017. changeValue: fixedCost,
  1018. activateClass: activateClass,
  1019. setFixedCost: true);
  1020. if (getChangeCostEffect != null)
  1021. {
  1022. AddEffectToPlayer(
  1023. effectDuration: EffectDuration.UntilCalculateFixedCost,
  1024. card: targetPermanent.TopCard,
  1025. cardEffect: null,
  1026. timing: EffectTiming.None,
  1027. getCardEffect: getFixedCostEffect);
  1028. }
  1029. }
  1030. #endregion
  1031. #region ignore digivolution requirement
  1032. Func<EffectTiming, ICardEffect> getIgnoreDigivolutionRequirementEffect = null;
  1033. if (ignoreDigivolutionRequirement)
  1034. {
  1035. bool PermanentCondition(Permanent permanent)
  1036. {
  1037. return permanent == targetPermanent;
  1038. }
  1039. bool CardCondition(CardSource cardSource)
  1040. {
  1041. if (cardSource == null)
  1042. {
  1043. return false;
  1044. }
  1045. if (cardSource.Owner != owner)
  1046. {
  1047. return false;
  1048. }
  1049. if (cardCondition == null || cardCondition(cardSource))
  1050. {
  1051. return true;
  1052. }
  1053. return false;
  1054. }
  1055. getIgnoreDigivolutionRequirementEffect = GainIgnoreDigivolutionRequirementPlayerEffect(
  1056. permanentCondition: PermanentCondition,
  1057. cardCondition: CardCondition,
  1058. ignoreDigivolutionRequirement: ignoreDigivolutionRequirement,
  1059. digivolutionCost: fixedCost,
  1060. activateClass: activateClass);
  1061. if (getIgnoreDigivolutionRequirementEffect != null)
  1062. {
  1063. AddEffectToPlayer(
  1064. effectDuration: EffectDuration.UntilCalculateFixedCost,
  1065. card: targetPermanent.TopCard,
  1066. cardEffect: null,
  1067. timing: EffectTiming.None,
  1068. getCardEffect: getIgnoreDigivolutionRequirementEffect);
  1069. }
  1070. }
  1071. #endregion
  1072. List<CardSource> selectedCards = new List<CardSource>();
  1073. IEnumerator SelectCardCoroutine(CardSource cardSource)
  1074. {
  1075. selectedCards.Add(cardSource);
  1076. yield return null;
  1077. }
  1078. if (owner.ExecutingCards.Count(CanSelectCardCondition) > 1)
  1079. {
  1080. int maxCount = 1;
  1081. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  1082. selectCardEffect.SetUp(
  1083. canTargetCondition: CanSelectCardCondition,
  1084. canTargetCondition_ByPreSelecetedList: null,
  1085. canEndSelectCondition: null,
  1086. canNoSelect: () => true,
  1087. selectCardCoroutine: SelectCardCoroutine,
  1088. afterSelectCardCoroutine: null,
  1089. message: "Select 1 card to digivolve.",
  1090. maxCount: maxCount,
  1091. canEndNotMax: false,
  1092. isShowOpponent: true,
  1093. mode: SelectCardEffect.Mode.Custom,
  1094. root: SelectCardEffect.Root.Execution,
  1095. customRootCardList: null,
  1096. canLookReverseCard: true,
  1097. selectPlayer: owner,
  1098. cardEffect: activateClass);
  1099. selectCardEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
  1100. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  1101. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  1102. }
  1103. else
  1104. {
  1105. selectedCards.Add(activateClass.EffectSourceCard);
  1106. }
  1107. PlayCardClass playCardClass = new PlayCardClass(
  1108. cardSources: selectedCards,
  1109. hashtable: CardEffectHashtable(activateClass),
  1110. payCost: payCost,
  1111. targetPermanent: targetPermanent,
  1112. isTapped: false,
  1113. root: root,
  1114. activateETB: true);
  1115. playCardClass.SetIgnoreRequirements(ignoreRequirements);
  1116. if (!ignoreDigivolutionRequirement && fixedCost >= 0) playCardClass.SetFixedCost(fixedCost);
  1117. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  1118. #region release effect
  1119. if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  1120. #endregion
  1121. #region release effect
  1122. if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  1123. #endregion
  1124. #region release effect
  1125. if (getIgnoreDigivolutionRequirementEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getIgnoreDigivolutionRequirementEffect);
  1126. #endregion
  1127. if (selectedCards.Count >= 1)
  1128. {
  1129. if (IsDigivolvedByTheEffect(targetPermanent, selectedCards[0], activateClass))
  1130. {
  1131. if (successProcess != null)
  1132. {
  1133. yield return ContinuousController.instance.StartCoroutine(successProcess);
  1134. }
  1135. }
  1136. }
  1137. }
  1138. #endregion
  1139. #region Get the effect given by EffectTiming
  1140. public static Func<EffectTiming, ICardEffect> GetCardEffectByEffectTiming(EffectTiming timing, ICardEffect cardEffect) => (_timing) => _timing == timing ? cardEffect : null;
  1141. #endregion
  1142. #region Draw cards and trash cards
  1143. public static IEnumerator DrawAndDiscardCards((Player drawPlayer, Player trashPlayer) player,
  1144. int drawAmount,
  1145. int trashAmount,
  1146. CardSource card,
  1147. ICardEffect activateClass,
  1148. Func<CardSource, bool> canTrashTargetCondition = null,
  1149. Func<List<CardSource>, CardSource, bool> canTargetCondition_ByPreSelecetedList = null,
  1150. Func<List<CardSource>, bool> canEndSelectCondition = null,
  1151. bool canNoSelect = false,
  1152. bool canEndNotMax = false,
  1153. bool isShowOpponent = true,
  1154. Func<List<CardSource>, IEnumerator> afterSelectPermanentCoroutine = null)
  1155. {
  1156. // Callback Setup
  1157. Func<List<CardSource>, IEnumerator> AfterSelectCardCoroutine = afterSelectPermanentCoroutine ?? null;
  1158. // Variable setup
  1159. Func<CardSource, bool> targetTrashCondition = canTrashTargetCondition ?? (cs => true);
  1160. yield return ContinuousController.instance.StartCoroutine(new DrawClass(player.drawPlayer, drawAmount, activateClass).Draw());
  1161. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  1162. selectHandEffect.SetUp(
  1163. selectPlayer: player.trashPlayer,
  1164. canTargetCondition: targetTrashCondition,
  1165. canTargetCondition_ByPreSelecetedList: canTargetCondition_ByPreSelecetedList,
  1166. canEndSelectCondition: canEndSelectCondition,
  1167. maxCount: trashAmount,
  1168. canNoSelect: canNoSelect,
  1169. canEndNotMax: canEndNotMax,
  1170. isShowOpponent: isShowOpponent,
  1171. selectCardCoroutine: null,
  1172. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  1173. mode: SelectHandEffect.Mode.Discard,
  1174. cardEffect: activateClass);
  1175. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  1176. }
  1177. #endregion
  1178. }