CardController.cs 168 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using System.Linq;
  6. #region Trash cards from hand
  7. public class IDiscardHands
  8. {
  9. public IDiscardHands(List<IDiscardHand> discardHands, ICardEffect cardEffect)
  10. {
  11. foreach (IDiscardHand discardHand in discardHands)
  12. {
  13. this.discardHands.Add(discardHand);
  14. }
  15. this.cardEffect = cardEffect;
  16. }
  17. List<IDiscardHand> discardHands { get; set; } = new List<IDiscardHand>();
  18. ICardEffect cardEffect { get; set; }
  19. public IEnumerator DiscardHands()
  20. {
  21. foreach (IDiscardHand discardHand in discardHands)
  22. {
  23. yield return ContinuousController.instance.StartCoroutine(discardHand.Discard());
  24. }
  25. List<CardSource> discardedCards = new List<CardSource>();
  26. foreach (IDiscardHand discardHand in discardHands)
  27. {
  28. if (discardHand.discarded)
  29. {
  30. discardedCards.Add(discardHand.cardSource);
  31. }
  32. }
  33. if (discardedCards.Count >= 1)
  34. {
  35. #region "When cards are trashed from hand" effect
  36. #region Hashtable setting
  37. Hashtable hashtable = new Hashtable()
  38. {
  39. {"DiscardedCards", discardedCards},
  40. {"CardEffect", cardEffect},
  41. };
  42. #endregion
  43. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardHand));
  44. #endregion
  45. }
  46. #region add log
  47. if (discardedCards.Count >= 1)
  48. {
  49. string log = "";
  50. log += $"\nDiscard hand:";
  51. foreach (CardSource cardSource in discardedCards)
  52. {
  53. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  54. }
  55. log += "\n";
  56. PlayLog.OnAddLog?.Invoke(log);
  57. }
  58. #endregion
  59. }
  60. }
  61. public class IDiscardHand
  62. {
  63. public IDiscardHand(CardSource cardSource, Hashtable hashtable)
  64. {
  65. this.cardSource = cardSource;
  66. this.hashtable = hashtable;
  67. }
  68. public CardSource cardSource { get; private set; }
  69. public Hashtable hashtable { get; private set; }
  70. public bool discarded { get; private set; } = false;
  71. public IEnumerator Discard()
  72. {
  73. bool oldisHand = cardSource.Owner.HandCards.Contains(cardSource);
  74. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
  75. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  76. bool isTrash = CardEffectCommons.IsExistOnTrash(cardSource);
  77. if (oldisHand && isTrash)
  78. {
  79. discarded = true;
  80. }
  81. }
  82. }
  83. #endregion
  84. #region Play cards
  85. public class PlayCardClass
  86. {
  87. public PlayCardClass(List<CardSource> cardSources, Hashtable hashtable, bool payCost, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root,
  88. bool activateETB)
  89. {
  90. if (cardSources != null)
  91. {
  92. CardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  93. }
  94. _hashtable = hashtable;
  95. PayCost = payCost;
  96. _targetPermanent = targetPermanent;
  97. _isTapped = isTapped;
  98. Root = root;
  99. _activateETB = activateETB;
  100. }
  101. public void SetJogress(int[] jogressEvoRootsFrameIDs)
  102. {
  103. if (jogressEvoRootsFrameIDs != null)
  104. {
  105. _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
  106. }
  107. }
  108. public void SetBurst(int BurstTamerFrameID, CardSource card)
  109. {
  110. if (0 <= BurstTamerFrameID && BurstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
  111. {
  112. _burstTamerFrameID = BurstTamerFrameID;
  113. }
  114. }
  115. public void SetAppFusion(int AppFusionFrameID, CardSource card)
  116. {
  117. if (0 >= AppFusionFrameID && AppFusionFrameID <= card.Owner.fieldCardFrames.Count - 1)
  118. {
  119. _appFusionFrameID = AppFusionFrameID;
  120. }
  121. }
  122. public void SetShowEffect()
  123. {
  124. _showEffect = true;
  125. }
  126. public void SetIgnoreLevel()
  127. {
  128. _ignoreLevel = true;
  129. SetIgnoreRequirements(CardEffectCommons.IgnoreRequirement.Level);
  130. }
  131. public void SetIgnoreRequirements(CardEffectCommons.IgnoreRequirement ignore)
  132. {
  133. _ignoreRequirement = ignore;
  134. }
  135. private bool GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement ignore)
  136. {
  137. Debug.Log($"Get Ignore Requirement: {_ignoreRequirement.Equals(ignore)}, {_ignoreRequirement.Equals(CardEffectCommons.IgnoreRequirement.All)}");
  138. return _ignoreRequirement.Equals(ignore) || _ignoreRequirement.Equals(CardEffectCommons.IgnoreRequirement.All);
  139. }
  140. public void SetFixedCost(int FixedCost)
  141. {
  142. _fixedCost = FixedCost;
  143. }
  144. public void SetReducedCost(int ReducedCost)
  145. {
  146. _reducedCost = ReducedCost;
  147. }
  148. public void SetAddSecurityEndOption()
  149. {
  150. _addSecurityEndOption = true;
  151. }
  152. public void SetIsBreedingArea()
  153. {
  154. _isBreedingArea = true;
  155. }
  156. public List<CardSource> CardSources { get; private set; } = new List<CardSource>();
  157. Hashtable _hashtable = null;
  158. public bool PayCost { get; private set; }
  159. Permanent _targetPermanent = null;
  160. bool _isTapped = false;
  161. public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
  162. bool _activateETB = true;
  163. bool _showEffect = false;
  164. bool _ignoreLevel = false;
  165. CardEffectCommons.IgnoreRequirement _ignoreRequirement = CardEffectCommons.IgnoreRequirement.None;
  166. int _fixedCost = -1;
  167. int _reducedCost = 0;
  168. int[] _jogressEvoRootsFrameIDs = null;
  169. int _burstTamerFrameID = -1;
  170. int _appFusionFrameID = -1;
  171. bool _addSecurityEndOption = false;
  172. bool _isBreedingArea = false;
  173. public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
  174. bool IsBurst(CardSource card)
  175. {
  176. Permanent burstTamer = BurstTamer(card);
  177. if (burstTamer != null)
  178. {
  179. if (burstTamer.TopCard != null)
  180. {
  181. if (card.burstDigivolutionCondition != null)
  182. {
  183. if (card.burstDigivolutionCondition.tamerCondition != null)
  184. {
  185. if (card.burstDigivolutionCondition.tamerCondition(burstTamer))
  186. {
  187. return true;
  188. }
  189. }
  190. }
  191. }
  192. }
  193. return false;
  194. }
  195. Permanent BurstTamer(CardSource card)
  196. {
  197. if (0 <= _burstTamerFrameID && _burstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
  198. {
  199. Permanent tamer = card.Owner.fieldCardFrames[_burstTamerFrameID].GetFramePermanent();
  200. return tamer;
  201. }
  202. return null;
  203. }
  204. bool IsAppFusion(CardSource card)
  205. {
  206. CardSource linkCard = GManager.instance.selectAppFusionEffect.selectedLink;
  207. if (linkCard != null)
  208. {
  209. if (card.appFusionCondition != null)
  210. {
  211. if (card.appFusionCondition.linkedCondition != null)
  212. {
  213. if (card.appFusionCondition.digimonCondition(GManager.instance.selectAppFusionEffect.EvoRoot.PermanentOfThisCard()))
  214. {
  215. if (card.appFusionCondition.linkedCondition != null)
  216. {
  217. if (card.appFusionCondition.linkedCondition(GManager.instance.selectAppFusionEffect.EvoRoot.PermanentOfThisCard(), linkCard))
  218. {
  219. return true;
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. return false;
  227. }
  228. public IEnumerator PlayCard()
  229. {
  230. bool burstDigivolved = false;
  231. bool appFusion = false;
  232. List<CardSource> playedCards_fixed = new List<CardSource>();
  233. foreach (CardSource card in CardSources)
  234. {
  235. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  236. if (card == null)
  237. {
  238. continue;
  239. }
  240. ICardEffect CardEffect = null;
  241. CardEffect = CardEffectCommons.GetCardEffectFromHashtable(this._hashtable);
  242. if (CardEffectCommons.IsExistOnTrash(card))
  243. {
  244. Root = SelectCardEffect.Root.Trash;
  245. }
  246. else if (card.Owner.HandCards.Contains(card))
  247. {
  248. Root = SelectCardEffect.Root.Hand;
  249. }
  250. else if (card.Owner.LibraryCards.Contains(card))
  251. {
  252. Root = SelectCardEffect.Root.Library;
  253. }
  254. else if (card.Owner.GetFieldPermanents().Count((permanent) => permanent.DigivolutionCards.Contains(card)) >= 1)
  255. {
  256. Root = SelectCardEffect.Root.DigivolutionCards;
  257. }
  258. else if (card.Owner.SecurityCards.Contains(card))
  259. {
  260. Root = SelectCardEffect.Root.Security;
  261. }
  262. else if (CardEffectCommons.IsExistOnExecutingArea(card))
  263. {
  264. Root = SelectCardEffect.Root.Execution;
  265. }
  266. List<Permanent> targetPermanents = new List<Permanent>();
  267. if (card.IsPermanent)
  268. {
  269. if (!isJogress)
  270. {
  271. if (CardEffectCommons.IsOwnerPermanent(_targetPermanent, card))
  272. {
  273. targetPermanents.Add(_targetPermanent);
  274. }
  275. }
  276. else
  277. {
  278. for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
  279. {
  280. int JogressFrameID = _jogressEvoRootsFrameIDs[i];
  281. if (0 <= JogressFrameID && JogressFrameID <= card.Owner.fieldCardFrames.Count - 1)
  282. {
  283. Permanent targetPermanent = card.Owner.fieldCardFrames[JogressFrameID].GetFramePermanent();
  284. targetPermanents.Add(targetPermanent);
  285. }
  286. }
  287. foreach (Permanent permanent in targetPermanents)
  288. {
  289. permanent.ShowingPermanentCard.SetPermanentIndexText(targetPermanents);
  290. }
  291. }
  292. }
  293. bool isEvolution = false;
  294. if (targetPermanents.Count >= 1)
  295. {
  296. if (!isJogress)
  297. {
  298. if (IsBurst(card))
  299. {
  300. if (card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
  301. {
  302. isEvolution = true;
  303. }
  304. }
  305. else if (IsAppFusion(card))
  306. {
  307. if (card.CanAppFusionFromTargetPermanent(targetPermanents[0], PayCost))
  308. {
  309. isEvolution = true;
  310. }
  311. }
  312. else
  313. {
  314. if (card.CanEvolve(targetPermanents[0], true) || GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level) || _ignoreLevel)
  315. {
  316. isEvolution = true;
  317. }
  318. }
  319. }
  320. else
  321. {
  322. if (targetPermanents.Count == 2)
  323. {
  324. isEvolution = true;
  325. }
  326. }
  327. }
  328. List<CardSource> oldTrashCards = new List<CardSource>();
  329. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForNonTurnPlayer)
  330. {
  331. foreach (Permanent permanent in player.GetFieldPermanents())
  332. {
  333. permanent.oldIsTapped_playCard = permanent.IsSuspended;
  334. }
  335. }
  336. foreach (CardSource cardSource in card.Owner.TrashCards)
  337. {
  338. oldTrashCards.Add(cardSource);
  339. }
  340. // effect of removing digivolution cards
  341. if (card.IsPermanent && !isEvolution && card.PermanentOfThisCard() != null && Root == SelectCardEffect.Root.DigivolutionCards)
  342. {
  343. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(card, card.PermanentOfThisCard()));
  344. }
  345. #region select digivolution cost
  346. int baseCost = -1;
  347. bool costSelected = false;
  348. yield return ContinuousController.instance.StartCoroutine(SelectCost());
  349. IEnumerator SelectCost()
  350. {
  351. if (!isJogress)
  352. {
  353. if (PayCost)
  354. {
  355. if (_fixedCost < 0)
  356. {
  357. Permanent targetPermanent = null;
  358. if (targetPermanents.Count >= 1)
  359. {
  360. targetPermanent = targetPermanents[0];
  361. }
  362. if (targetPermanent != null)
  363. {
  364. List<int> CostList = new List<int>();
  365. bool isBurst = IsBurst(card);
  366. bool isAppFusion = IsAppFusion(card);
  367. if(isBurst || isAppFusion)
  368. {
  369. if(isBurst)
  370. CostList.Add(card.burstDigivolutionCondition.cost);
  371. if(isAppFusion)
  372. CostList.Add(card.appFusionCondition.cost);
  373. }
  374. else
  375. {
  376. foreach (int cost in card.CostList(targetPermanent, ignoreLevel: GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level), checkAvailability: false))
  377. {
  378. int evoCost = cost;
  379. if (_reducedCost > 0)
  380. evoCost -= _reducedCost;
  381. CostList.Add(evoCost);
  382. }
  383. }
  384. CostList = CostList.Distinct().ToList();
  385. if (CostList.Count >= 1)
  386. {
  387. if (CostList.Count == 1)
  388. {
  389. baseCost = CostList[0];
  390. }
  391. else
  392. {
  393. costSelected = true;
  394. bool MoveToExecuteCardEffect = true;
  395. if (card.Owner.HandCards.Contains(card) && card.ShowingHandCard != null)
  396. {
  397. if (card.ShowingHandCard.gameObject.activeSelf)
  398. {
  399. MoveToExecuteCardEffect = false;
  400. }
  401. }
  402. if (!card.Owner.isYou && GManager.instance.IsAI)
  403. {
  404. MoveToExecuteCardEffect = false;
  405. costSelected = false;
  406. }
  407. if (card.Owner.isYou && ContinuousController.instance.autoMinDigivolutionCost)
  408. {
  409. MoveToExecuteCardEffect = false;
  410. costSelected = false;
  411. }
  412. if (MoveToExecuteCardEffect)
  413. {
  414. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  415. }
  416. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  417. if (selectCountEffect != null)
  418. {
  419. selectCountEffect.SetUp(
  420. SelectPlayer: card.Owner,
  421. targetPermanent: null,
  422. MaxCount: 1,
  423. CanNoSelect: false,
  424. Message: "Which digivolution cost do you pay?",
  425. Message_Enemy: "The opponent is choosing which digivolution cost to pay.",
  426. SelectCountCoroutine: SelectCountCoroutine);
  427. selectCountEffect.SetCandidates(CostList);
  428. selectCountEffect.SetPreferMin(true);
  429. selectCountEffect.SetNotDoSync(true);
  430. selectCountEffect.SetIsDigivolutionCost(true);
  431. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  432. IEnumerator SelectCountCoroutine(int count)
  433. {
  434. baseCost = count;
  435. yield return null;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. else
  442. {
  443. baseCost = card.BasePlayCostFromEntity;
  444. }
  445. }
  446. }
  447. }
  448. }
  449. #endregion
  450. #region HashTable Setting
  451. Hashtable hashtable = CardEffectCommons.WouldEnterFieldHashtable(
  452. payCost: PayCost,
  453. card: card,
  454. root: Root,
  455. isEvolution: isEvolution,
  456. playCardClass: this,
  457. cardEffect: CardEffect,
  458. isJogress: isJogress,
  459. targetPermanents: targetPermanents
  460. );
  461. #endregion
  462. List<SkillInfo> skillInfos_BeforePayCost = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.BeforePayCost)
  463. .Concat(AutoProcessing.GetSkillInfosOfCards(hashtable, EffectTiming.BeforePayCost, new List<CardSource>() { card }
  464. .Filter(cardSource => !CardEffectCommons.IsExistOnHand(cardSource) && !CardEffectCommons.IsExistOnTrash(cardSource) && !CardEffectCommons.IsExistInSecurity(cardSource) && cardSource.PermanentOfThisCard() == null)))
  465. .ToList();
  466. yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.BeforePayCost));
  467. #region IsShowEffect()
  468. bool IsShowEffect()
  469. {
  470. if (skillInfos_BeforePayCost.Count >= 2)
  471. {
  472. return true;
  473. }
  474. else if (skillInfos_BeforePayCost.Count == 1)
  475. {
  476. if (skillInfos_BeforePayCost[0].CardEffect.CanActivate(skillInfos_BeforePayCost[0].Hashtable))
  477. {
  478. return true;
  479. }
  480. }
  481. else if (card.HasDigiXros && !isEvolution)
  482. {
  483. return true;
  484. }
  485. else if (IsBurst(card))
  486. {
  487. return true;
  488. }
  489. return false;
  490. }
  491. #endregion
  492. #region effect
  493. if (PayCost || IsShowEffect())
  494. {
  495. if (!costSelected)
  496. {
  497. if (card.IsOption || IsShowEffect())
  498. {
  499. bool noHandCard = true;
  500. if (card.Owner.HandCards.Contains(card))
  501. {
  502. if (card.ShowingHandCard != null)
  503. {
  504. if (card.ShowingHandCard.gameObject.activeSelf)
  505. {
  506. if (card.ShowingHandCard.gameObject.transform.GetChild(0).gameObject.activeSelf)
  507. {
  508. noHandCard = false;
  509. }
  510. }
  511. }
  512. }
  513. if (noHandCard)
  514. {
  515. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  516. }
  517. }
  518. else
  519. {
  520. if (CardEffect == null)
  521. {
  522. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  523. }
  524. }
  525. }
  526. }
  527. #endregion
  528. #region show expected cost
  529. if (PayCost)
  530. {
  531. if (!isJogress)
  532. {
  533. int cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  534. GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
  535. }
  536. else
  537. {
  538. if (card.jogressCondition != null)
  539. {
  540. int cost = card.GetPayingCostWithBaseCost(card.jogressCondition.cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  541. GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
  542. }
  543. }
  544. }
  545. #endregion
  546. #region process cut in effects before paying cost
  547. if (skillInfos_BeforePayCost.Count >= 1)
  548. {
  549. foreach (SkillInfo skillInfo in skillInfos_BeforePayCost)
  550. {
  551. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  552. }
  553. if (IsShowEffect())
  554. {
  555. foreach (Permanent targetPermanent in targetPermanents)
  556. {
  557. if (targetPermanent != null)
  558. {
  559. targetPermanent.ShowWillEvolutionEffect();
  560. }
  561. }
  562. }
  563. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  564. foreach (Permanent targetPermanent in targetPermanents)
  565. {
  566. if (targetPermanent != null)
  567. {
  568. targetPermanent.HideWillEvolutionEffect();
  569. }
  570. }
  571. }
  572. #endregion
  573. #region select DigiXros
  574. if (card.HasDigiXros && !isEvolution)
  575. {
  576. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectDigiXrosClass>().Select(card));
  577. }
  578. #endregion
  579. #region Bounce Tamer of Burst digivolution
  580. if (IsBurst(card))
  581. {
  582. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectBurstDigivolutionEffect.BounceTamer(BurstTamer(card)));
  583. if (!GManager.instance.selectBurstDigivolutionEffect.TamerBounced)
  584. {
  585. _burstTamerFrameID = -1;
  586. yield return ContinuousController.instance.StartCoroutine(SelectCost());
  587. }
  588. else
  589. {
  590. burstDigivolved = true;
  591. }
  592. }
  593. #endregion
  594. #region Add Link Card of App Fusion
  595. if (IsAppFusion(card))
  596. {
  597. UnityEngine.Debug.Log($"PLAYING: {card}");
  598. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectAppFusionEffect.AddToSources());
  599. if (!GManager.instance.selectAppFusionEffect.LinkAdded)
  600. {
  601. _appFusionFrameID = -1;
  602. yield return ContinuousController.instance.StartCoroutine(SelectCost());
  603. }
  604. else
  605. {
  606. appFusion = true;
  607. }
  608. }
  609. #endregion
  610. #region fix cost to pay
  611. int Cost = 0;
  612. if (PayCost)
  613. {
  614. if (!isJogress)
  615. {
  616. Cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  617. }
  618. else
  619. {
  620. if (card.jogressCondition != null)
  621. {
  622. Cost = card.GetPayingCostWithBaseCost(card.jogressCondition.cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  623. }
  624. }
  625. GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(Cost));
  626. }
  627. #endregion
  628. #region end play cards
  629. bool endPlayCard = false;
  630. bool playFailed = false;
  631. if (PayCost)
  632. {
  633. if (Cost > card.Owner.MaxMemoryCost)
  634. {
  635. endPlayCard = true;
  636. playFailed = true;
  637. }
  638. }
  639. if (isEvolution)
  640. {
  641. if (targetPermanents != null)
  642. {
  643. if (targetPermanents.Count >= 1)
  644. {
  645. foreach (Permanent permanent in targetPermanents)
  646. {
  647. if (permanent != null)
  648. {
  649. if (permanent.TopCard == null)
  650. {
  651. endPlayCard = true;
  652. }
  653. }
  654. }
  655. if (!endPlayCard)
  656. {
  657. if (!isJogress && !IsBurst(card) && !IsAppFusion(card))
  658. {
  659. if (!GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level) && !card.CanPlayCardTargetFrame(targetPermanents[0].PermanentFrame, PayCost, CardEffect, root: Root, fixedCost: -1))
  660. {
  661. endPlayCard = true;
  662. playFailed = true;
  663. }
  664. }
  665. else if (isJogress)
  666. {
  667. if (!card.CanJogressFromTargetPermanents(targetPermanents, PayCost))
  668. {
  669. endPlayCard = true;
  670. playFailed = true;
  671. }
  672. }
  673. else if (IsBurst(card))
  674. {
  675. if (!card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
  676. {
  677. endPlayCard = true;
  678. playFailed = true;
  679. }
  680. }
  681. else if (IsAppFusion(card))
  682. {
  683. if (!card.CanAppFusionFromTargetPermanent(targetPermanents[0], PayCost))
  684. {
  685. endPlayCard = true;
  686. playFailed = true;
  687. }
  688. }
  689. }
  690. }
  691. }
  692. }
  693. if (endPlayCard)
  694. {
  695. PlayLog.OnAddLog?.Invoke($"\nFailed to play:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  696. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  697. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().FailedPlayCardEffect(card));
  698. if (card.Owner.HandCards.Contains(card))
  699. {
  700. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  701. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(new List<CardSource>() { card }, false, null));
  702. }
  703. ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
  704. foreach (HandCard handCard in card.Owner.brainStormObject.BrainStormHandCards)
  705. {
  706. if (handCard.gameObject.activeSelf && handCard.cardSource == card)
  707. {
  708. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  709. }
  710. }
  711. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  712. {
  713. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  714. {
  715. if (fieldPermanentCard != null)
  716. {
  717. fieldPermanentCard.OffPermanentIndexText();
  718. }
  719. }
  720. }
  721. if (playFailed)
  722. {
  723. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  724. {
  725. foreach (Permanent permanent in player.GetFieldPermanents())
  726. {
  727. permanent.IsSuspended = permanent.oldIsTapped_playCard;
  728. }
  729. }
  730. foreach (CardSource cardSource in oldTrashCards)
  731. {
  732. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  733. {
  734. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  735. }
  736. }
  737. }
  738. }
  739. #endregion
  740. card.Owner.UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
  741. if (endPlayCard)
  742. {
  743. continue;
  744. }
  745. #region pay cost
  746. if (PayCost)
  747. {
  748. // memory lose
  749. if (Cost <= card.Owner.MaxMemoryCost)
  750. {
  751. yield return ContinuousController.instance.StartCoroutine(card.Owner.AddMemory(-1 * Cost, null));
  752. }
  753. ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
  754. }
  755. #endregion
  756. #region cut in effect after paying cost
  757. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(hashtable, EffectTiming.AfterPayCost));
  758. // cur in effect process
  759. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(
  760. false,
  761. AutoProcessing.HasExecutedSameEffect));
  762. #endregion
  763. // add to played cards
  764. playedCards_fixed.Add(card);
  765. }
  766. #region filter cards
  767. List<CardSource> permanentCards = playedCards_fixed.Filter(cardSource => cardSource.IsPermanent);
  768. List<CardSource> optionCards = playedCards_fixed.Filter(cardSource => !cardSource.IsPermanent);
  769. #region play permanent
  770. PlayPermanentClass playPermanent = new PlayPermanentClass(permanentCards, _hashtable, _targetPermanent, _isTapped, Root, _activateETB);
  771. if (isJogress)
  772. {
  773. playPermanent.SetJogress(_jogressEvoRootsFrameIDs);
  774. }
  775. if (burstDigivolved)
  776. {
  777. playPermanent.SetBurstDigivolved();
  778. }
  779. if (_isBreedingArea)
  780. {
  781. playPermanent.SetIsBreedingArea();
  782. }
  783. yield return ContinuousController.instance.StartCoroutine(playPermanent.PlayPermanent());
  784. #endregion
  785. #region use option
  786. UseOptionClass useOption = new UseOptionClass(optionCards, _hashtable, Root)
  787. {
  788. _showEffect = _showEffect,
  789. _addSecurityEndOption = _addSecurityEndOption
  790. };
  791. yield return ContinuousController.instance.StartCoroutine(useOption.UseOption());
  792. #endregion
  793. #endregion
  794. }
  795. IEnumerator OffMemoryPredictionLine()
  796. {
  797. yield return new WaitForSeconds(0.5f);
  798. GManager.instance.memoryObject.OffMemoryPredictionLine();
  799. }
  800. }
  801. #endregion
  802. #region Hatch DigiEgg
  803. public class HatchDigiEggClass
  804. {
  805. public HatchDigiEggClass(Player player, Hashtable hashtable)
  806. {
  807. _player = player;
  808. _hashtable = hashtable;
  809. }
  810. Player _player { get; set; }
  811. Hashtable _hashtable { get; set; }
  812. public IEnumerator Hatch()
  813. {
  814. if (_player == null) yield break;
  815. if (!_player.CanHatch) yield break;
  816. CardSource card = _player.DigitamaLibraryCards[0];
  817. PlayPermanentClass playPermanentClass = new PlayPermanentClass(
  818. cardSources: new List<CardSource>() { card },
  819. hashtable: _hashtable,
  820. targetPermanent: null,
  821. isTapped: false,
  822. root: SelectCardEffect.Root.Library,
  823. ActivateETB: true);
  824. playPermanentClass.SetIsBreedingArea();
  825. yield return ContinuousController.instance.StartCoroutine(playPermanentClass.PlayPermanent());
  826. if (card.PermanentOfThisCard() != null)
  827. {
  828. card.PermanentOfThisCard().EnterFieldTurnCount = -1;
  829. }
  830. }
  831. }
  832. #endregion
  833. #region Play permanents
  834. #region Hashtable setting class
  835. public class OnEnterFieldHashtableParams
  836. {
  837. public OnEnterFieldHashtableParams(
  838. Permanent permanent,
  839. List<CardSource> evoRoots,
  840. List<CardSource> evoRootTops,
  841. SelectCardEffect.Root root,
  842. List<int> oldLevels,
  843. bool isFromDigimonDigivolutionCards)
  844. {
  845. Permanent = permanent;
  846. if (evoRoots != null)
  847. {
  848. EvoRoots = evoRoots.Clone();
  849. }
  850. if (evoRootTops != null)
  851. {
  852. EvoRootTops = evoRootTops.Clone();
  853. }
  854. Root = root;
  855. if (oldLevels != null)
  856. {
  857. OldLevels = oldLevels.Clone();
  858. }
  859. IsFromDigimonDigivolutionCards = isFromDigimonDigivolutionCards;
  860. }
  861. public Permanent Permanent { get; private set; } = null;
  862. public List<CardSource> EvoRoots = new List<CardSource>();
  863. public List<CardSource> EvoRootTops { get; private set; } = new List<CardSource>();
  864. public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
  865. public List<int> OldLevels { get; private set; } = new List<int>();
  866. public bool IsFromDigimonDigivolutionCards { get; private set; } = false;
  867. }
  868. #endregion
  869. public class PlayPermanentClass
  870. {
  871. public PlayPermanentClass(List<CardSource> cardSources, Hashtable hashtable, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root, bool ActivateETB)
  872. {
  873. if (cardSources != null)
  874. {
  875. _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  876. }
  877. _hashtable = hashtable;
  878. _targetPermanent = targetPermanent;
  879. _isTapped = isTapped;
  880. _root = root;
  881. _activateETB = ActivateETB;
  882. }
  883. public void SetJogress(int[] jogressEvoRootsFrameIDs)
  884. {
  885. if (jogressEvoRootsFrameIDs != null)
  886. {
  887. _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
  888. }
  889. }
  890. public void SetBurstDigivolved()
  891. {
  892. _burstDigivolved = true;
  893. }
  894. public void SetIsBreedingArea()
  895. {
  896. _isBreedingArea = true;
  897. }
  898. public void SetISPlayOption()
  899. {
  900. _isPlayOption = true;
  901. }
  902. List<CardSource> _cardSources = new List<CardSource>();
  903. Hashtable _hashtable = null;
  904. Permanent _targetPermanent = null;
  905. bool _isTapped = false;
  906. SelectCardEffect.Root _root = SelectCardEffect.Root.None;
  907. bool _activateETB = true;
  908. int[] _jogressEvoRootsFrameIDs = null;
  909. int _digiXrosCount = 0;
  910. bool _burstDigivolved = false;
  911. bool _isBreedingArea = false;
  912. bool _isPlayOption = false;
  913. public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
  914. public IEnumerator PlayPermanent()
  915. {
  916. List<OnEnterFieldHashtableParams> hashtableParams = new List<OnEnterFieldHashtableParams>();
  917. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  918. bool isEvolution = false;
  919. foreach (CardSource card in _cardSources)
  920. {
  921. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  922. if (GManager.instance.GetComponent<SelectDigiXrosClass>().playCard == card)
  923. {
  924. _digiXrosCount = GManager.instance.GetComponent<SelectDigiXrosClass>().selectedDigicrossCards.Count;
  925. }
  926. bool isFromDigimonDigivolutionCards = card.Owner.GetBattleAreaDigimons().Some((permanent) => permanent.DigivolutionCards.Contains(card));
  927. bool isFromSecurity = card.Owner.SecurityCards.Contains(card);
  928. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  929. GManager.instance.turnStateMachine.isSync = true;
  930. Permanent permanent = null;
  931. isEvolution = false;
  932. List<CardSource> evoRoots = new List<CardSource>();
  933. List<CardSource> evoRootTops = new List<CardSource>();
  934. bool played = false;
  935. List<int> oldLevels = new List<int>();
  936. int frameId = -1;
  937. if (_targetPermanent == null)
  938. {
  939. if (_isBreedingArea)
  940. {
  941. if (card.Owner.GetBreedingAreaPermanents().Count == 0)
  942. {
  943. FieldCardFrame digieggFrame = card.Owner.fieldCardFrames.Find(fieldCardFrame =>
  944. fieldCardFrame.IsEmptyFrame()
  945. && !fieldCardFrame.IsBattleAreaFrame()
  946. && card.CanPlayCardTargetFrame(fieldCardFrame, false, CardEffect, isBreedingArea: _isBreedingArea));
  947. if (digieggFrame != null)
  948. {
  949. frameId = digieggFrame.FrameID;
  950. }
  951. }
  952. }
  953. else
  954. {
  955. FieldCardFrame preferredFrame = card.PreferredFrame();
  956. if (preferredFrame != null)
  957. {
  958. frameId = preferredFrame.FrameID;
  959. }
  960. }
  961. }
  962. else
  963. {
  964. frameId = _targetPermanent.PermanentFrame.FrameID;
  965. }
  966. if (!isJogress)
  967. {
  968. if (!(0 <= frameId && frameId < card.Owner.fieldCardFrames.Count))
  969. {
  970. foreach (FieldCardFrame fieldCardFrame in card.Owner.fieldCardFrames)
  971. {
  972. if (card.CanPlayCardTargetFrame(fieldCardFrame, false, CardEffect, isBreedingArea: _isBreedingArea))
  973. {
  974. if (fieldCardFrame.IsEmptyFrame())
  975. {
  976. frameId = fieldCardFrame.FrameID;
  977. break;
  978. }
  979. }
  980. }
  981. }
  982. if (0 <= frameId && frameId < card.Owner.fieldCardFrames.Count)
  983. {
  984. played = true;
  985. if (_targetPermanent != null)
  986. {
  987. isEvolution = true;
  988. }
  989. else
  990. {
  991. if (!CardEffectCommons.CanPlayAsNewPermanent(card, false, CardEffect, isBreedingArea: _isBreedingArea, isPlayOption: _isPlayOption))
  992. {
  993. played = false;
  994. }
  995. }
  996. if (played)
  997. {
  998. card.Init();
  999. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1000. if (isEvolution)
  1001. {
  1002. oldLevels.Add(_targetPermanent.Level);
  1003. PlayLog.OnAddLog?.Invoke($"\nEvolution:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1004. permanent = _targetPermanent;
  1005. evoRoots.Add(_targetPermanent.TopCard);
  1006. evoRootTops.Add(_targetPermanent.TopCard);
  1007. permanent.AddCardSource(card);
  1008. }
  1009. else
  1010. {
  1011. if(card.IsToken)
  1012. PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity} token\n");
  1013. else
  1014. PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1015. permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = _isTapped };
  1016. yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, frameId));
  1017. permanent.EnterFieldTurnCount = GManager.instance.turnStateMachine.TurnCount;
  1018. }
  1019. GManager.instance.turnStateMachine.isSync = true;
  1020. if (GManager.instance.turnStateMachine.DoneStartGame)
  1021. {
  1022. if (!isEvolution)
  1023. {
  1024. #region wheter to have ETB effects
  1025. Hashtable hashtable = CardEffectCommons.OnEnterFieldHashtable(
  1026. hashtableParams: new List<OnEnterFieldHashtableParams>()
  1027. {
  1028. new OnEnterFieldHashtableParams(
  1029. permanent: permanent,
  1030. evoRoots: evoRoots,
  1031. evoRootTops: evoRootTops,
  1032. root: _root,
  1033. oldLevels: oldLevels,
  1034. isFromDigimonDigivolutionCards:isFromDigimonDigivolutionCards
  1035. )
  1036. },
  1037. isEvolution: isEvolution,
  1038. isJogress: isJogress,
  1039. digiXrosCount: _digiXrosCount,
  1040. cardEffect: CardEffect);
  1041. bool HasETB = permanent.EffectList(EffectTiming.OnEnterFieldAnyone).Some(cardEffect =>
  1042. cardEffect is ActivateICardEffect && cardEffect.CanUse(hashtable) && _activateETB && cardEffect.IsOnPlay);
  1043. #endregion
  1044. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, HasETB: HasETB, isDigiXros: _digiXrosCount >= 1));
  1045. }
  1046. else
  1047. {
  1048. bool isBlast = CardEffect != null && CardEffect.EffectName != null && CardEffect.EffectName.Contains("Blast");
  1049. //effect
  1050. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DigivolveFieldPermanentCardEffect(permanent.ShowingPermanentCard, _burstDigivolved, isBlast));
  1051. }
  1052. }
  1053. }
  1054. }
  1055. }
  1056. else
  1057. {
  1058. if (_jogressEvoRootsFrameIDs.Length == 2)
  1059. {
  1060. played = true;
  1061. card.Init();
  1062. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1063. isEvolution = true;
  1064. List<Permanent> evoRootPermanents = new List<Permanent>();
  1065. for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
  1066. {
  1067. int frameID = _jogressEvoRootsFrameIDs[i];
  1068. Permanent evoRoot = card.Owner.fieldCardFrames[frameID].GetFramePermanent();
  1069. if (evoRoot != null)
  1070. {
  1071. if (evoRoot.TopCard != null)
  1072. {
  1073. evoRootPermanents.Add(evoRoot);
  1074. }
  1075. }
  1076. }
  1077. int targetFrameID = evoRootPermanents[0].PermanentFrame.FrameID;
  1078. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1079. {
  1080. evoRoots.Add(evoRootPermanent.TopCard);
  1081. }
  1082. List<CardSource> newDigivolutionCards = evoRootPermanents
  1083. .Map(evoRootPermanent => evoRootPermanent.cardSources)
  1084. .Flat();
  1085. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1086. {
  1087. oldLevels.Add(evoRootPermanent.Level);
  1088. evoRootTops.Add(evoRootPermanent.TopCard);
  1089. }
  1090. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1091. {
  1092. yield return ContinuousController.instance.StartCoroutine(evoRootPermanent.DiscardEvoRoots(ignoreOverflow: true, putToTrash: false));
  1093. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(evoRootPermanent, ignoreOverflow: true));
  1094. }
  1095. PlayLog.OnAddLog?.Invoke($"\nJogress:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1096. permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = false };
  1097. yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, targetFrameID));
  1098. permanent.EnterFieldTurnCount = -1;
  1099. newDigivolutionCards.Reverse();
  1100. yield return ContinuousController.instance.StartCoroutine(permanent.AddDigivolutionCardsTop(newDigivolutionCards, null));
  1101. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, isDigiXros: false, jogressEvoRoots: evoRootTops.ToArray()));
  1102. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(evoRootTops, "DNA Digivolution Cards", true, true));
  1103. foreach (CardSource evolutionCard in permanent.DigivolutionCards)
  1104. {
  1105. evolutionCard.cEntity_EffectController.InitUseCountThisTurn();
  1106. }
  1107. }
  1108. }
  1109. if (played)
  1110. {
  1111. if (isFromSecurity)
  1112. {
  1113. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  1114. player: card.Owner,
  1115. refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
  1116. CardEffectCommons.GetCardEffectFromHashtable(_hashtable)).ReduceSecurity());
  1117. }
  1118. if (isEvolution)
  1119. {
  1120. card.Owner.DigivolveCount_ThisTurn++;
  1121. yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, null).Draw());
  1122. if (_burstDigivolved)
  1123. {
  1124. if (permanent.TopCard != null)
  1125. {
  1126. permanent.IsBurstDigivolved = true;
  1127. GManager.instance.selectBurstDigivolutionEffect.AddTrashTopCardAtTurnEnd(permanent);
  1128. }
  1129. }
  1130. permanent.CardNamesJustAfterDigivolved = permanent.TopCard.CardNames.Clone();
  1131. permanent.DigivolvingEffect = CardEffect;
  1132. }
  1133. else
  1134. {
  1135. permanent.PlayingEffect = CardEffect;
  1136. if (permanent.TopCard.HasLevel)
  1137. {
  1138. permanent.LevelJustAfterPlayed = permanent.Level;
  1139. }
  1140. if (permanent.TopCard.HasPlayCost)
  1141. {
  1142. permanent.PlayCostJustAfterPlayed = permanent.TopCard.GetCostItself;
  1143. }
  1144. permanent.CardNamesJustAfterPlayed = permanent.TopCard.CardNames.Clone();
  1145. permanent.TraitsJustAfterPlayed = permanent.TopCard.CardTraits.Clone();
  1146. }
  1147. #region move permanents (hybrid)
  1148. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  1149. {
  1150. if (permanent.TopCard.PreferredFrame() != null)
  1151. {
  1152. if (permanent.PermanentFrame != permanent.TopCard.PreferredFrame())
  1153. {
  1154. if (permanent.TopCard.PreferredFrame().IsEmptyFrame())
  1155. {
  1156. bool move = false;
  1157. if (permanent.IsDigimon)
  1158. {
  1159. if (permanent.TopCard.Owner.isYou)
  1160. {
  1161. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1162. {
  1163. move = true;
  1164. }
  1165. }
  1166. else
  1167. {
  1168. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1169. {
  1170. move = true;
  1171. }
  1172. }
  1173. }
  1174. else if (permanent.IsTamer || permanent.TopCard.IsOption)
  1175. {
  1176. if (permanent.TopCard.Owner.isYou)
  1177. {
  1178. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1179. {
  1180. move = true;
  1181. }
  1182. }
  1183. else
  1184. {
  1185. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1186. {
  1187. move = true;
  1188. }
  1189. }
  1190. }
  1191. if (move)
  1192. {
  1193. yield return ContinuousController.instance.StartCoroutine(CardObjectController.MovePermanent(permanent.PermanentFrame));
  1194. }
  1195. }
  1196. }
  1197. }
  1198. }
  1199. #endregion
  1200. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCardsByEffect(card);
  1201. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCards(card);
  1202. if (GManager.instance.turnStateMachine.DoneStartGame)
  1203. {
  1204. hashtableParams.Add(
  1205. new OnEnterFieldHashtableParams(
  1206. permanent: permanent,
  1207. evoRoots: evoRoots,
  1208. evoRootTops: evoRootTops,
  1209. root: _root,
  1210. oldLevels: oldLevels,
  1211. isFromDigimonDigivolutionCards: isFromDigimonDigivolutionCards
  1212. )
  1213. );
  1214. }
  1215. }
  1216. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  1217. yield return GManager.instance.photonWaitController.StartWait("EndPlayPermanent");
  1218. }
  1219. // except [On Play] effect
  1220. bool CardEffectCondition(ICardEffect cardEffect)
  1221. {
  1222. if (cardEffect == null)
  1223. {
  1224. return false;
  1225. }
  1226. if (!_activateETB)
  1227. {
  1228. if (cardEffect is ActivateICardEffect)
  1229. {
  1230. if (cardEffect.IsOnPlay)
  1231. {
  1232. return false;
  1233. }
  1234. }
  1235. }
  1236. return true;
  1237. }
  1238. Hashtable effectHashtable = CardEffectCommons.OnEnterFieldHashtable(
  1239. hashtableParams: hashtableParams,
  1240. isEvolution: isEvolution,
  1241. isJogress: isJogress,
  1242. digiXrosCount: _digiXrosCount,
  1243. cardEffect: CardEffect);
  1244. #region "When permanents are played" effect
  1245. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  1246. hashtable: effectHashtable,
  1247. timing: EffectTiming.OnEnterFieldAnyone,
  1248. cardEffectCondition: CardEffectCondition));
  1249. #endregion
  1250. }
  1251. }
  1252. #endregion
  1253. #region Use option
  1254. public class UseOptionClass
  1255. {
  1256. public UseOptionClass(List<CardSource> cardSources, Hashtable hashtable, SelectCardEffect.Root root)
  1257. {
  1258. if (cardSources != null)
  1259. {
  1260. _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  1261. }
  1262. _hashtable = hashtable;
  1263. _root = root;
  1264. }
  1265. List<CardSource> _cardSources = new List<CardSource>();
  1266. SelectCardEffect.Root _root = SelectCardEffect.Root.None;
  1267. Hashtable _hashtable = null;
  1268. public bool _showEffect = false;
  1269. public bool _addSecurityEndOption = false;
  1270. public IEnumerator UseOption()
  1271. {
  1272. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1273. foreach (CardSource card in _cardSources)
  1274. {
  1275. if (_showEffect)
  1276. {
  1277. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(card));
  1278. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowUseHandCardEffect_PlayCard(card));
  1279. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  1280. }
  1281. PlayLog.OnAddLog?.Invoke($"\nPlay Option:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1282. card.Init();
  1283. GManager.instance.turnStateMachine.isSync = true;
  1284. card.SetFace();
  1285. int cost = card.GetCostItself;
  1286. //Remove from all areas
  1287. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1288. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(card));
  1289. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.BrainStormCoroutine(card));
  1290. #region Set HashTable
  1291. Hashtable hashtable = new Hashtable()
  1292. {
  1293. {"Card", card},
  1294. {"Root", _root},
  1295. {"Cost", cost},
  1296. };
  1297. #endregion
  1298. #region "When option is used" effect
  1299. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseOption));
  1300. yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.OnUseOption));
  1301. #endregion
  1302. #region effect process of option card
  1303. foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.OptionSkill))
  1304. {
  1305. if (cardEffect is ActivateICardEffect)
  1306. {
  1307. if (cardEffect.CanUse(hashtable))
  1308. {
  1309. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  1310. cardEffect,
  1311. hashtable));
  1312. }
  1313. }
  1314. }
  1315. #endregion
  1316. if (card.Owner.ExecutingCards.Contains(card))
  1317. {
  1318. if (_addSecurityEndOption && card.Owner.CanAddSecurity(CardEffect))
  1319. {
  1320. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(card));
  1321. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(card.Owner));
  1322. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(card.Owner).AddSecurity());
  1323. }
  1324. else
  1325. {
  1326. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(card));
  1327. }
  1328. }
  1329. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  1330. yield return GManager.instance.photonWaitController.StartWait("EndPlayOption");
  1331. }
  1332. }
  1333. }
  1334. #endregion
  1335. #region Draw cards
  1336. public class DrawClass
  1337. {
  1338. public DrawClass(Player player, int drawCount, ICardEffect cardEffect)
  1339. {
  1340. _player = player;
  1341. _drawCount = drawCount;
  1342. _cardEffect = cardEffect;
  1343. }
  1344. Player _player = null;
  1345. int _drawCount = 0;
  1346. ICardEffect _cardEffect = null;
  1347. public IEnumerator Draw()
  1348. {
  1349. if (_drawCount <= 0) yield break;
  1350. if (_player.LibraryCards.Count <= 0) yield break;
  1351. List<CardSource> DrawCards = new List<CardSource>();
  1352. for (int i = 0; i < _drawCount; i++)
  1353. {
  1354. if (_player.LibraryCards.Count > 0)
  1355. {
  1356. CardSource DrawCard = _player.LibraryCards[0];
  1357. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(DrawCard));
  1358. DrawCards.Add(DrawCard);
  1359. }
  1360. }
  1361. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(DrawCards, true, _cardEffect));
  1362. #region add log
  1363. if (DrawCards.Count >= 1)
  1364. {
  1365. PlayLog.OnAddLog?.Invoke($"\nDraw {DrawCards.Count} card{Utils.PluralFormSuffix(DrawCards.Count)}\n{_player.PlayerName}\n");
  1366. }
  1367. #endregion
  1368. #region "When draw cards" effect
  1369. if (DrawCards.Count >= 1)
  1370. {
  1371. #region Hashtable setting
  1372. Hashtable _hashtable = new Hashtable()
  1373. {
  1374. {"Player", _player},
  1375. {"CardEffect", _cardEffect}
  1376. };
  1377. #endregion
  1378. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnDraw));
  1379. }
  1380. #endregion
  1381. }
  1382. }
  1383. #endregion
  1384. #region Trash cards from deck too
  1385. public class IAddTrashCardsFromLibraryTop
  1386. {
  1387. public IAddTrashCardsFromLibraryTop(int addTrashCount, Player player, ICardEffect cardEffect)
  1388. {
  1389. _addTrashCount = addTrashCount;
  1390. _player = player;
  1391. _cardEffect = cardEffect;
  1392. }
  1393. public void SetNotShowCards()
  1394. {
  1395. _notShowCards = true;
  1396. }
  1397. int _addTrashCount;
  1398. Player _player;
  1399. public List<CardSource> discardedCards = new List<CardSource>();
  1400. ICardEffect _cardEffect { get; set; } = null;
  1401. bool _notShowCards = false;
  1402. public IEnumerator AddTrashCardsFromLibraryTop()
  1403. {
  1404. if (_addTrashCount <= 0) yield break;
  1405. if (_player.LibraryCards.Count == 0) yield break;
  1406. string log = "";
  1407. log += $"\nTrash cards from deck :";
  1408. for (int i = 0; i < _addTrashCount; i++)
  1409. {
  1410. if (_player.LibraryCards.Count > i)
  1411. {
  1412. CardSource DiscardCard = _player.LibraryCards[i];
  1413. discardedCards.Add(DiscardCard);
  1414. log += $"\n{DiscardCard.BaseENGCardNameFromEntity}({DiscardCard.CardID})";
  1415. }
  1416. }
  1417. if (discardedCards.Count >= 1)
  1418. {
  1419. if (!_notShowCards)
  1420. {
  1421. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  1422. }
  1423. }
  1424. yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(discardedCards, _cardEffect).TrashDeckCards());
  1425. if (discardedCards.Count >= 1)
  1426. {
  1427. for (int i = 0; i < discardedCards.Count; i++)
  1428. {
  1429. ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
  1430. yield return new WaitForSeconds(0.06f);
  1431. }
  1432. log += "\n";
  1433. PlayLog.OnAddLog?.Invoke(log);
  1434. }
  1435. }
  1436. }
  1437. #endregion
  1438. #region Add security from deck top
  1439. public class IAddSecurityFromLibrary
  1440. {
  1441. public IAddSecurityFromLibrary(Player player, int addLifeCount)
  1442. {
  1443. _player = player;
  1444. _addSecurityCount = addLifeCount;
  1445. }
  1446. Player _player = null;
  1447. int _addSecurityCount = 0;
  1448. public IEnumerator AddSecurity()
  1449. {
  1450. int count = 0;
  1451. for (int i = 0; i < _addSecurityCount; i++)
  1452. {
  1453. if (_player.LibraryCards.Count > 0)
  1454. {
  1455. CardSource StockCard = _player.LibraryCards[0];
  1456. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(StockCard));
  1457. count++;
  1458. }
  1459. }
  1460. if (count > 0)
  1461. {
  1462. string log = "";
  1463. log += $"\nAdd {count} cards to security:{_player.PlayerName}";
  1464. log += "\n";
  1465. PlayLog.OnAddLog?.Invoke(log);
  1466. if (GManager.instance.turnStateMachine.DoneStartGame)
  1467. {
  1468. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(_player).AddSecurity());
  1469. }
  1470. }
  1471. }
  1472. }
  1473. #endregion
  1474. #region Recovery
  1475. public class IRecovery
  1476. {
  1477. public IRecovery(Player player, int AddLifeCount, ICardEffect cardEffect)
  1478. {
  1479. _player = player;
  1480. _addLifeCount = AddLifeCount;
  1481. _cardEffect = cardEffect;
  1482. }
  1483. Player _player = null;
  1484. int _addLifeCount = 0;
  1485. ICardEffect _cardEffect = null;
  1486. public IEnumerator Recovery()
  1487. {
  1488. if (_player.LibraryCards.Count == 0) yield break;
  1489. if (_addLifeCount <= 0) yield break;
  1490. if (!_player.CanAddSecurity(_cardEffect)) yield break;
  1491. yield return ContinuousController.instance.StartCoroutine(new IAddSecurityFromLibrary(_player, _addLifeCount).AddSecurity());
  1492. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(_player));
  1493. }
  1494. }
  1495. #endregion
  1496. #region Digi-Burst
  1497. public class IDigiBurst
  1498. {
  1499. public IDigiBurst(Permanent permanent, int DigiBurstCount, ICardEffect cardEffect)
  1500. {
  1501. _permanent = permanent;
  1502. _digiBurstCount = DigiBurstCount;
  1503. _cardEffect = cardEffect;
  1504. }
  1505. Permanent _permanent = null;
  1506. int _digiBurstCount = 0;
  1507. ICardEffect _cardEffect = null;
  1508. bool _upToMaxCount = false;
  1509. public List<CardSource> discardedCards = new List<CardSource>();
  1510. public void SetUpToMaxCount()
  1511. {
  1512. _upToMaxCount = true;
  1513. }
  1514. public bool CanDigiBurst()
  1515. {
  1516. if (_permanent != null)
  1517. {
  1518. if (_permanent.TopCard != null)
  1519. {
  1520. if (_permanent.ImmuneFromStackTrashing()) return false;
  1521. if (_upToMaxCount)
  1522. {
  1523. if (_permanent.DigivolutionCards.Some((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)))
  1524. {
  1525. return true;
  1526. }
  1527. }
  1528. else
  1529. {
  1530. if (_permanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)) >= _digiBurstCount)
  1531. {
  1532. return true;
  1533. }
  1534. }
  1535. }
  1536. }
  1537. return false;
  1538. }
  1539. public IEnumerator DigiBurst()
  1540. {
  1541. if (CanDigiBurst())
  1542. {
  1543. discardedCards = new List<CardSource>();
  1544. List<CardSource> selectedCards = new List<CardSource>();
  1545. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  1546. selectCardEffect.SetUp(
  1547. canTargetCondition: (cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect),
  1548. canTargetCondition_ByPreSelecetedList: null,
  1549. canEndSelectCondition: CanEndSelectCondition,
  1550. canNoSelect: () => false,
  1551. selectCardCoroutine: SelectCardCoroutine,
  1552. afterSelectCardCoroutine: null,
  1553. message: "Select digivolution cards to discard.",
  1554. maxCount: _digiBurstCount,
  1555. canEndNotMax: _upToMaxCount,
  1556. isShowOpponent: true,
  1557. mode: SelectCardEffect.Mode.Custom,
  1558. root: SelectCardEffect.Root.Custom,
  1559. customRootCardList: _permanent.DigivolutionCards,
  1560. canLookReverseCard: true,
  1561. selectPlayer: _permanent.TopCard.Owner,
  1562. cardEffect: null);
  1563. selectCardEffect.SetUpCustomMessage("Select digivolution cards to discard.", "The opponent is selecting digivolution cards to discard.");
  1564. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  1565. bool CanEndSelectCondition(List<CardSource> cardSources)
  1566. {
  1567. if (CardEffectCommons.HasNoElement(cardSources))
  1568. {
  1569. return false;
  1570. }
  1571. return true;
  1572. }
  1573. IEnumerator SelectCardCoroutine(CardSource cardSource)
  1574. {
  1575. selectedCards.Add(cardSource);
  1576. yield return null;
  1577. }
  1578. if (selectedCards.Count >= 1)
  1579. {
  1580. #region "When use Digi-Burst" effect
  1581. #region Hashtable setting
  1582. Hashtable hashtable = new Hashtable()
  1583. {
  1584. {"Permanent", _permanent},
  1585. {"CardEffect", _cardEffect},
  1586. };
  1587. #endregion
  1588. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseDigiburst));
  1589. #endregion
  1590. // trash digivolution cards
  1591. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(_permanent, selectedCards, _cardEffect).TrashDigivolutionCards());
  1592. foreach (CardSource cardSource in selectedCards)
  1593. {
  1594. discardedCards.Add(cardSource);
  1595. }
  1596. #region add log
  1597. if (selectedCards.Count >= 1)
  1598. {
  1599. string log = "";
  1600. log += $"\nDigiburst :";
  1601. foreach (CardSource cardSource in selectedCards)
  1602. {
  1603. if (cardSource != null)
  1604. {
  1605. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  1606. }
  1607. }
  1608. log += "\n";
  1609. PlayLog.OnAddLog?.Invoke(log);
  1610. }
  1611. #endregion
  1612. }
  1613. }
  1614. }
  1615. }
  1616. #endregion
  1617. #region Place permanents to deck bottom
  1618. public class DeckBottomBounceClass
  1619. {
  1620. public DeckBottomBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
  1621. {
  1622. _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
  1623. _hashtable = hashtable;
  1624. }
  1625. public void SetNotShowCards()
  1626. {
  1627. _notShowCards = true;
  1628. }
  1629. public bool IsDeckBounced(Permanent permanent)
  1630. {
  1631. return DeckBouncedPermanents.Contains(permanent);
  1632. }
  1633. List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
  1634. public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
  1635. Hashtable _hashtable = new Hashtable();
  1636. bool _notShowCards = false;
  1637. public IEnumerator DeckBounce()
  1638. {
  1639. if (_deckBounceTargetPermanents == null) yield break;
  1640. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1641. _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
  1642. permanent != null
  1643. && permanent.TopCard != null
  1644. && (cardEffect == null ||
  1645. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1646. && !permanent.CannotReturnToLibrary(cardEffect)
  1647. && permanent.CanBeRemoved())));
  1648. if (_deckBounceTargetPermanents.Count == 0) yield break;
  1649. _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1650. #region cut in effect
  1651. // "When permanents would return to deck" effect
  1652. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1653. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1654. _deckBounceTargetPermanents,
  1655. cardEffect,
  1656. null
  1657. ),
  1658. EffectTiming.WhenReturntoLibraryAnyone));
  1659. // "When permanents would remove field" effect
  1660. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1661. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1662. _deckBounceTargetPermanents,
  1663. cardEffect,
  1664. null
  1665. ),
  1666. EffectTiming.WhenRemoveField));
  1667. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1668. {
  1669. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1670. {
  1671. permanent.ShowDeckBounceEffect();
  1672. }
  1673. // cut in effect process
  1674. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1675. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1676. {
  1677. permanent.HideDeckBounceEffect();
  1678. }
  1679. }
  1680. #endregion
  1681. // fix deck bounce target permanents
  1682. List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
  1683. permanent != null
  1684. && permanent.TopCard != null
  1685. && permanent.willBeRemoveField);
  1686. #region show cards
  1687. List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1688. if (!_notShowCards)
  1689. {
  1690. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
  1691. }
  1692. #endregion
  1693. #region
  1694. List<CardSource> deckBottomCards = new List<CardSource>();
  1695. foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
  1696. {
  1697. #region recoed used effect
  1698. if (permanent.TopCard != null)
  1699. {
  1700. permanent.LibraryBounceEffect = cardEffect;
  1701. }
  1702. #endregion
  1703. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
  1704. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1705. CardSource topCard = permanent.TopCard;
  1706. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1707. deckBottomCards.Add(topCard);
  1708. DeckBouncedPermanents.Add(permanent);
  1709. }
  1710. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(deckBottomCards));
  1711. #endregion
  1712. #region off icon
  1713. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1714. {
  1715. if (permanent != null)
  1716. {
  1717. if (permanent.TopCard != null)
  1718. {
  1719. permanent.willBeRemoveField = false;
  1720. }
  1721. }
  1722. }
  1723. #endregion
  1724. }
  1725. }
  1726. #endregion
  1727. #region Return permanent to hand
  1728. public class HandBounceClaass
  1729. {
  1730. public HandBounceClaass(List<Permanent> bounceTargetPermanents, Hashtable hashtable)
  1731. {
  1732. _bounceTargetPermanents = bounceTargetPermanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  1733. _hashtable = hashtable;
  1734. }
  1735. public bool IsBounced(Permanent permanent)
  1736. {
  1737. return BouncedPermanents.Contains(permanent);
  1738. }
  1739. List<Permanent> _bounceTargetPermanents = new List<Permanent>();
  1740. public List<Permanent> BouncedPermanents { get; private set; } = new List<Permanent>();
  1741. Hashtable _hashtable = new Hashtable();
  1742. bool _notShowCards = false;
  1743. public IEnumerator Bounce()
  1744. {
  1745. if (_bounceTargetPermanents == null) yield break;
  1746. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1747. _bounceTargetPermanents = _bounceTargetPermanents.Filter(permanent =>
  1748. permanent != null
  1749. && permanent.TopCard != null
  1750. && (cardEffect == null ||
  1751. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1752. && !permanent.CannotReturnToHand(cardEffect)
  1753. && permanent.CanBeRemoved())));
  1754. if (_bounceTargetPermanents.Count == 0) yield break;
  1755. _bounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1756. #region cut in effect
  1757. // "When permanents would return to hand" effect
  1758. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1759. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1760. _bounceTargetPermanents,
  1761. cardEffect,
  1762. null
  1763. ),
  1764. EffectTiming.WhenReturntoHandAnyone));
  1765. // "When permanents would remove field" effect
  1766. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1767. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1768. _bounceTargetPermanents,
  1769. cardEffect,
  1770. null
  1771. ),
  1772. EffectTiming.WhenRemoveField));
  1773. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1774. {
  1775. foreach (Permanent permanent in _bounceTargetPermanents)
  1776. {
  1777. permanent.ShowHandBounceEffect();
  1778. }
  1779. // shrink security Digimon display
  1780. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  1781. // cut in effect process
  1782. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1783. foreach (Permanent permanent in _bounceTargetPermanents)
  1784. {
  1785. permanent.HideHandBounceEffect();
  1786. }
  1787. }
  1788. #endregion
  1789. // fix bounce target permanents
  1790. List<Permanent> bounceTargetPermanents_Fixed = _bounceTargetPermanents.Filter(permanent =>
  1791. permanent != null
  1792. && permanent.TopCard != null
  1793. && permanent.willBeRemoveField);
  1794. #region "When permanents returned to hand" effect
  1795. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  1796. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  1797. bounceTargetPermanents_Fixed,
  1798. cardEffect,
  1799. null,
  1800. false
  1801. ),
  1802. EffectTiming.OnPermamemtReturnedToHand));
  1803. #endregion
  1804. #region record parameter just before bounce
  1805. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1806. {
  1807. permanent.DPJustBeforeRemoveField = permanent.DP;
  1808. if (permanent.TopCard.HasLevel)
  1809. {
  1810. permanent.LevelJustBeforeRemoveField = permanent.Level;
  1811. }
  1812. if (permanent.TopCard.HasPlayCost)
  1813. {
  1814. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  1815. }
  1816. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  1817. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  1818. foreach (CardSource cardSource in permanent.cardSources)
  1819. {
  1820. cardSource.PermanentJustBeforeRemoveField = permanent;
  1821. }
  1822. }
  1823. #endregion
  1824. #region add log
  1825. if (bounceTargetPermanents_Fixed.Count >= 1)
  1826. {
  1827. string log = "";
  1828. log += $"\nReturn to hand:";
  1829. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1830. {
  1831. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  1832. }
  1833. log += "\n";
  1834. PlayLog.OnAddLog?.Invoke(log);
  1835. }
  1836. #endregion
  1837. #region show cards
  1838. List<CardSource> returnedCards = bounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1839. if (!_notShowCards)
  1840. {
  1841. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Cards returned to hand", true, true));
  1842. }
  1843. #endregion
  1844. #region return permanent cards to hand
  1845. List<CardSource> handCards = new List<CardSource>();
  1846. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1847. {
  1848. #region record used effect
  1849. if (permanent.TopCard != null)
  1850. {
  1851. permanent.HandBounceEffect = cardEffect;
  1852. }
  1853. #endregion
  1854. // record whether to return to hand by Burst Digivolution
  1855. permanent.IsReturnedToHandByBurstDigivolution = CardEffectCommons.IsBurst(_hashtable);
  1856. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BounceEffect(permanent, !permanent.IsReturnedToHandByBurstDigivolution));
  1857. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1858. CardSource topCard = permanent.TopCard;
  1859. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1860. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(topCard));
  1861. if (!topCard.IsDigiEgg)
  1862. {
  1863. handCards.Add(topCard);
  1864. BouncedPermanents.Add(permanent);
  1865. }
  1866. else
  1867. {
  1868. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  1869. }
  1870. }
  1871. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
  1872. #endregion
  1873. #region hide icon
  1874. foreach (Permanent permanent in _bounceTargetPermanents)
  1875. {
  1876. if (permanent != null)
  1877. {
  1878. if (permanent.TopCard != null)
  1879. {
  1880. permanent.willBeRemoveField = false;
  1881. }
  1882. }
  1883. }
  1884. #endregion
  1885. }
  1886. }
  1887. #endregion
  1888. #region Place permanent to another permanent's digivolution cards
  1889. public class IPlacePermanentToDigivolutionCards
  1890. {
  1891. public IPlacePermanentToDigivolutionCards(
  1892. List<Permanent[]> permanentArrays,
  1893. bool toTop,
  1894. ICardEffect cardEffect,
  1895. bool skipEffectAndActivateSkill = false)
  1896. {
  1897. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  1898. _toTop = toTop;
  1899. _cardEffect = cardEffect;
  1900. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  1901. }
  1902. public void SetNotShowCards()
  1903. {
  1904. _notShowCards = true;
  1905. }
  1906. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  1907. ICardEffect _cardEffect = null;
  1908. bool _toTop = false;
  1909. bool _notShowCards = false;
  1910. bool _skipEffectAndActivateSkill = false;
  1911. public bool Placed { get; private set; } = false;
  1912. public IEnumerator PlacePermanentToDigivolutionCards()
  1913. {
  1914. if (_permanentArrays.Count == 0)
  1915. {
  1916. yield break;
  1917. }
  1918. List<CardSource> addedDigivolutionCards = new List<CardSource>();
  1919. List<Permanent> removeFieldPermanents = new List<Permanent>();
  1920. foreach (Permanent[] permanentArray in _permanentArrays)
  1921. {
  1922. if (permanentArray.Length == 2)
  1923. {
  1924. Permanent DigivolutionPermanent = permanentArray[0];
  1925. Permanent getDigivolutionPermanent = permanentArray[1];
  1926. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  1927. {
  1928. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
  1929. {
  1930. if (_cardEffect != null)
  1931. {
  1932. if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
  1933. {
  1934. continue;
  1935. }
  1936. }
  1937. removeFieldPermanents.Add(DigivolutionPermanent);
  1938. }
  1939. }
  1940. }
  1941. }
  1942. foreach (Permanent permanent in removeFieldPermanents)
  1943. {
  1944. permanent.willBeRemoveField = true;
  1945. }
  1946. if (removeFieldPermanents.Count == 0)
  1947. {
  1948. yield break;
  1949. }
  1950. #region
  1951. List<SkillInfo> skillInfos = new List<SkillInfo>();
  1952. Hashtable hashtable1 =
  1953. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1954. removeFieldPermanents,
  1955. _cardEffect,
  1956. null);
  1957. #region "When permanents would remove field" effect
  1958. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1959. {
  1960. #region permanents' effects
  1961. foreach (Permanent permanent1 in player.GetFieldPermanents())
  1962. {
  1963. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  1964. {
  1965. if (cardEffect is ActivateICardEffect)
  1966. {
  1967. if (cardEffect.CanTrigger(hashtable1))
  1968. {
  1969. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1970. }
  1971. }
  1972. }
  1973. }
  1974. #endregion
  1975. #region players' effects
  1976. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  1977. {
  1978. if (cardEffect is ActivateICardEffect)
  1979. {
  1980. if (cardEffect.CanTrigger(hashtable1))
  1981. {
  1982. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1983. }
  1984. }
  1985. }
  1986. #endregion
  1987. }
  1988. #endregion
  1989. if (skillInfos.Count >= 1)
  1990. {
  1991. foreach (SkillInfo skillInfo in skillInfos)
  1992. {
  1993. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  1994. }
  1995. bool showEffect()
  1996. {
  1997. if (skillInfos.Count >= 2)
  1998. {
  1999. return true;
  2000. }
  2001. else if (skillInfos.Count == 1)
  2002. {
  2003. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  2004. {
  2005. return true;
  2006. }
  2007. }
  2008. return false;
  2009. }
  2010. if (showEffect())
  2011. {
  2012. foreach (Permanent Permanent in removeFieldPermanents)
  2013. {
  2014. if (Permanent != null)
  2015. {
  2016. if (Permanent.TopCard != null)
  2017. {
  2018. if (Permanent.willBeRemoveField)
  2019. {
  2020. if (Permanent.ShowingPermanentCard != null)
  2021. {
  2022. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2023. {
  2024. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  2025. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  2026. }
  2027. }
  2028. }
  2029. }
  2030. }
  2031. }
  2032. #region shrink security Digimon display
  2033. if (GManager.instance.attackProcess.IsAttacking)
  2034. {
  2035. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2036. {
  2037. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2038. {
  2039. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2040. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2041. }
  2042. }
  2043. }
  2044. #endregion
  2045. }
  2046. // cut in effect process
  2047. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2048. foreach (Permanent Permanent in removeFieldPermanents)
  2049. {
  2050. if (Permanent != null)
  2051. {
  2052. if (Permanent.TopCard != null)
  2053. {
  2054. if (Permanent.ShowingPermanentCard != null)
  2055. {
  2056. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2057. {
  2058. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. #endregion
  2066. foreach (Permanent[] permanentArray in _permanentArrays)
  2067. {
  2068. if (permanentArray.Length == 2)
  2069. {
  2070. Permanent DigivolutionPermanent = permanentArray[0];
  2071. Permanent getDigivolutionPermanent = permanentArray[1];
  2072. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  2073. {
  2074. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
  2075. {
  2076. yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
  2077. CardSource cardSource = DigivolutionPermanent.TopCard;
  2078. #region record used effect
  2079. if (_cardEffect != null)
  2080. {
  2081. if (DigivolutionPermanent.TopCard != null)
  2082. {
  2083. DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
  2084. }
  2085. }
  2086. #endregion
  2087. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  2088. DigivolutionPermanent,
  2089. ignoreOverflow: true));
  2090. List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
  2091. if (_toTop)
  2092. {
  2093. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
  2094. }
  2095. else
  2096. {
  2097. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
  2098. }
  2099. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  2100. addedDigivolutionCards.Add(cardSource);
  2101. Placed = true;
  2102. }
  2103. }
  2104. }
  2105. }
  2106. #region add log
  2107. if (addedDigivolutionCards.Count >= 1)
  2108. {
  2109. string log = "";
  2110. log += $"\nPlace in digivolution cards:";
  2111. foreach (CardSource cardSource in addedDigivolutionCards)
  2112. {
  2113. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2114. }
  2115. log += "\n";
  2116. PlayLog.OnAddLog?.Invoke(log);
  2117. }
  2118. #endregion
  2119. #region hide icon
  2120. if (addedDigivolutionCards.Count >= 1)
  2121. {
  2122. if (!_notShowCards)
  2123. {
  2124. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
  2125. }
  2126. }
  2127. #endregion
  2128. }
  2129. }
  2130. #endregion
  2131. #region Place permanents to security
  2132. public class IPutSecurityPermanent
  2133. {
  2134. public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop, bool isFaceup = false)
  2135. {
  2136. _permanent = permanent;
  2137. _hashtable = hashtable;
  2138. _toTop = toTop;
  2139. _isFaceup = isFaceup;
  2140. }
  2141. Permanent _permanent = null;
  2142. Hashtable _hashtable = new Hashtable();
  2143. bool _toTop = false;
  2144. bool _isFaceup = false;
  2145. public IEnumerator PutSecurity()
  2146. {
  2147. if (_permanent == null) yield break;
  2148. if (_permanent.TopCard == null) yield break;
  2149. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2150. if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
  2151. if (!_permanent.CanBeRemoved()) yield break;
  2152. _permanent.willBeRemoveField = true;
  2153. #region "When permanents would remove field" effect
  2154. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2155. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2156. new List<Permanent>() { _permanent },
  2157. cardEffect,
  2158. null
  2159. ),
  2160. EffectTiming.WhenRemoveField));
  2161. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2162. {
  2163. _permanent.ShowWillRemoveFieldEffect();
  2164. //effect
  2165. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2166. // cut in effect process
  2167. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false,null));
  2168. _permanent.HideWillRemoveFieldEffect();
  2169. }
  2170. #endregion
  2171. CardSource topCard = _permanent.TopCard;
  2172. if (!_permanent.willBeRemoveField)
  2173. yield break;
  2174. if (topCard == null)
  2175. yield break;
  2176. #region add log
  2177. string log = "";
  2178. string fromString = _toTop ? "top" : "bottom";
  2179. log += $"\nPut cards on {fromString} of security:";
  2180. log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
  2181. log += "\n";
  2182. PlayLog.OnAddLog?.Invoke(log);
  2183. #endregion
  2184. #region show cards
  2185. if (!topCard.IsToken)
  2186. {
  2187. if (_toTop)
  2188. {
  2189. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
  2190. }
  2191. else
  2192. {
  2193. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
  2194. }
  2195. }
  2196. #endregion
  2197. #region place permanent to security
  2198. yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
  2199. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
  2200. if (!topCard.IsToken)
  2201. {
  2202. if (!topCard.IsDigiEgg)
  2203. {
  2204. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard,faceUp:_isFaceup));
  2205. if (!_isFaceup)
  2206. topCard.SetReverse();
  2207. else
  2208. topCard.SetFace();
  2209. if (!_toTop)
  2210. {
  2211. topCard.Owner.SecurityCards.Remove(topCard);
  2212. topCard.Owner.SecurityCards.Add(topCard);
  2213. }
  2214. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
  2215. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard.Owner).AddSecurity());
  2216. }
  2217. else
  2218. {
  2219. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2220. }
  2221. }
  2222. #endregion
  2223. }
  2224. }
  2225. #endregion
  2226. #region Delete permanents
  2227. public class DestroyPermanentsClass
  2228. {
  2229. public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
  2230. {
  2231. _destroytargetPermanents = destroyTargetPermanents.Clone();
  2232. _hashtable = hashtable;
  2233. _notShowCards = notShowCards;
  2234. }
  2235. public bool IsDestroyed(Permanent permanent)
  2236. {
  2237. return DestroyedPermanents.Contains(permanent);
  2238. }
  2239. List<Permanent> _destroytargetPermanents = new List<Permanent>();
  2240. public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
  2241. Hashtable _hashtable = null;
  2242. bool _notShowCards = false;
  2243. public IEnumerator Destroy()
  2244. {
  2245. if (_destroytargetPermanents == null) yield break;
  2246. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2247. IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
  2248. bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
  2249. _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
  2250. permanent != null
  2251. && permanent.TopCard != null
  2252. && (cardEffect == null ||
  2253. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  2254. && permanent.CanBeDestroyedBySkill(cardEffect))));
  2255. if (_destroytargetPermanents.Count == 0) yield break;
  2256. _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  2257. #region cut in effect
  2258. // "When permanents would be deleted" effect
  2259. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2260. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2261. _destroytargetPermanents,
  2262. cardEffect,
  2263. battle
  2264. ),
  2265. EffectTiming.WhenPermanentWouldBeDeleted));
  2266. // "When permanents would remove field" effect
  2267. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2268. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2269. _destroytargetPermanents,
  2270. cardEffect,
  2271. battle
  2272. ),
  2273. EffectTiming.WhenRemoveField));
  2274. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2275. {
  2276. foreach (Permanent permanent in _destroytargetPermanents)
  2277. {
  2278. permanent.ShowDeleteEffect();
  2279. }
  2280. // effect
  2281. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2282. // cut in effect process
  2283. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2284. foreach (Permanent permanent in _destroytargetPermanents)
  2285. {
  2286. permanent.HideDeleteEffect();
  2287. }
  2288. }
  2289. #endregion
  2290. // fix delete target permanents
  2291. List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
  2292. permanent != null
  2293. && permanent.TopCard != null
  2294. && permanent.willBeRemoveField);
  2295. #region "When permanents are deleted" effect
  2296. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2297. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2298. destroyTargetPermanents_Fixed,
  2299. cardEffect,
  2300. battle,
  2301. isDPZero
  2302. ),
  2303. EffectTiming.OnDestroyedAnyone));
  2304. #endregion
  2305. #region record parameters just before deletion
  2306. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2307. {
  2308. permanent.DPJustBeforeRemoveField = permanent.DP;
  2309. if (permanent.TopCard.HasLevel)
  2310. {
  2311. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2312. }
  2313. if (permanent.TopCard.HasPlayCost)
  2314. {
  2315. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  2316. }
  2317. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  2318. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  2319. foreach (CardSource cardSource in permanent.cardSources)
  2320. {
  2321. cardSource.PermanentJustBeforeRemoveField = permanent;
  2322. }
  2323. }
  2324. #endregion
  2325. #region add log
  2326. if (destroyTargetPermanents_Fixed.Count >= 1)
  2327. {
  2328. string log = "";
  2329. log += $"\nDelete:";
  2330. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2331. {
  2332. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  2333. }
  2334. log += "\n";
  2335. PlayLog.OnAddLog?.Invoke(log);
  2336. }
  2337. #endregion
  2338. #region show cards
  2339. List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2340. if (!_notShowCards)
  2341. {
  2342. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
  2343. }
  2344. #endregion
  2345. #region trash permanent cards
  2346. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2347. {
  2348. #region record wheter to be deleted by battle
  2349. if (battle != null)
  2350. {
  2351. if (permanent.TopCard != null)
  2352. {
  2353. if(CardEffectCommons.GetLoserPermanentsFromHashtable(battle.hashtable).Contains(permanent))
  2354. permanent.IsDestroyedByBattle = true;
  2355. }
  2356. }
  2357. #endregion
  2358. #region record used effect
  2359. if (permanent.TopCard != null)
  2360. {
  2361. permanent.DestroyingEffect = cardEffect;
  2362. }
  2363. #endregion
  2364. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
  2365. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2366. CardSource topCard = permanent.TopCard;
  2367. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2368. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
  2369. DestroyedPermanents.Add(permanent);
  2370. }
  2371. #endregion
  2372. #region hide icon
  2373. foreach (Permanent permanent in _destroytargetPermanents)
  2374. {
  2375. if (permanent != null)
  2376. {
  2377. if (permanent.TopCard != null)
  2378. {
  2379. permanent.willBeRemoveField = false;
  2380. }
  2381. }
  2382. }
  2383. #endregion
  2384. }
  2385. }
  2386. #endregion
  2387. #region Security check
  2388. public class ISecurityCheck
  2389. {
  2390. public ISecurityCheck(Permanent AttackingPermanent, Player player)
  2391. {
  2392. this.AttackingPermanent = AttackingPermanent;
  2393. this.player = player;
  2394. }
  2395. Permanent AttackingPermanent { get; set; }
  2396. Player player { get; set; }
  2397. public IEnumerator SecurityCheck()
  2398. {
  2399. bool StopSecurityCheck()
  2400. {
  2401. if (AttackingPermanent == null)
  2402. {
  2403. return true;
  2404. }
  2405. if (AttackingPermanent.TopCard == null)
  2406. {
  2407. return true;
  2408. }
  2409. if (!AttackingPermanent.IsDigimon)
  2410. return true;
  2411. return false;
  2412. }
  2413. if (!StopSecurityCheck())
  2414. {
  2415. if (AttackingPermanent.Strike == 0)
  2416. {
  2417. yield break;
  2418. }
  2419. GManager.instance.turnStateMachine.IsSelecting = true;
  2420. GManager.instance.turnStateMachine.isSecurityCehck = true;
  2421. #region loop while there are 1 or more security cards
  2422. if (player.SecurityCards.Count >= 1)
  2423. {
  2424. int checkedCount = 0;
  2425. while (true)
  2426. {
  2427. if (StopSecurityCheck())
  2428. {
  2429. break;
  2430. }
  2431. if (checkedCount >= AttackingPermanent.Strike)
  2432. {
  2433. break;
  2434. }
  2435. if (player.SecurityCards.Count >= 1)
  2436. {
  2437. List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
  2438. CardSource brokenSecurityCard = player.SecurityCards[0];
  2439. Hashtable hashtable = new Hashtable()
  2440. {
  2441. {"AttackingPermanent", AttackingPermanent},
  2442. {"Card", brokenSecurityCard}
  2443. };
  2444. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
  2445. {
  2446. triggeredSkillInfos.Add(skillInfo);
  2447. }
  2448. checkedCount++;
  2449. PlayLog.OnAddLog?.Invoke($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
  2450. if (brokenSecurityCard.IsDigimon)
  2451. {
  2452. GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
  2453. }
  2454. #region effect
  2455. player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2456. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
  2457. yield return new WaitForSeconds(0.1f);
  2458. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
  2459. #endregion
  2460. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
  2461. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2462. player: brokenSecurityCard.Owner,
  2463. refSkillInfos: ref triggeredSkillInfos).ReduceSecurity());
  2464. #region security effect
  2465. List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
  2466. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
  2467. {
  2468. if (cardEffect is ActivateICardEffect)
  2469. {
  2470. Hashtable hashtable1 = new Hashtable();
  2471. hashtable1.Add("Card", brokenSecurityCard);
  2472. if (cardEffect.CanUse(hashtable1))
  2473. {
  2474. secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
  2475. }
  2476. }
  2477. }
  2478. List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
  2479. bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
  2480. if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
  2481. {
  2482. if (!brokenSecurityCard.IsDigimon)
  2483. {
  2484. yield return new WaitForSeconds(0.3f);
  2485. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2486. }
  2487. }
  2488. else
  2489. {
  2490. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
  2491. yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
  2492. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2493. foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
  2494. {
  2495. skillInfos.Add(skillInfo);
  2496. }
  2497. List<CardSource> cardSources = new List<CardSource>();
  2498. for (int j = 0; j < skillInfos.Count; j++)
  2499. {
  2500. cardSources.Add(brokenSecurityCard);
  2501. }
  2502. while (skillInfos.Count >= 1)
  2503. {
  2504. SkillInfo selectedSkillInfo = null;
  2505. if (skillInfos.Count == 1)
  2506. {
  2507. selectedSkillInfo = skillInfos[0];
  2508. }
  2509. else
  2510. {
  2511. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  2512. selectCardEffect.SetUp(
  2513. canTargetCondition: (cardSource) => true,
  2514. canTargetCondition_ByPreSelecetedList: null,
  2515. canEndSelectCondition: null,
  2516. canNoSelect: () => false,
  2517. selectCardCoroutine: null,
  2518. afterSelectCardCoroutine: null,
  2519. message: "select security effect",
  2520. maxCount: 1,
  2521. canEndNotMax: false,
  2522. isShowOpponent: false,
  2523. mode: SelectCardEffect.Mode.Custom,
  2524. root: SelectCardEffect.Root.Custom,
  2525. customRootCardList: cardSources,
  2526. canLookReverseCard: true,
  2527. selectPlayer: player,
  2528. cardEffect: null);
  2529. selectCardEffect.SetUpSkillInfos(skillInfos);
  2530. selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
  2531. selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  2532. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  2533. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  2534. {
  2535. if (selectedIndexes.Count == 1)
  2536. {
  2537. selectedSkillInfo = skillInfos[selectedIndexes[0]];
  2538. yield return null;
  2539. }
  2540. }
  2541. }
  2542. if (selectedSkillInfo != null)
  2543. {
  2544. ICardEffect cardEffect = selectedSkillInfo.CardEffect;
  2545. Hashtable hashtable2 = selectedSkillInfo.Hashtable;
  2546. if (cardEffect.EffectSourceCard == brokenSecurityCard)
  2547. {
  2548. if (cardEffect is ActivateICardEffect)
  2549. {
  2550. skillInfos.Remove(selectedSkillInfo);
  2551. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  2552. cardEffect,
  2553. hashtable2));
  2554. }
  2555. }
  2556. }
  2557. }
  2558. }
  2559. #endregion
  2560. // auto process check
  2561. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2562. // stack effect of "When cards are removed from security" and "checks secuirty"
  2563. foreach (SkillInfo skillInfo in triggeredSkillInfos)
  2564. {
  2565. GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
  2566. }
  2567. // auto process check
  2568. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2569. if (!StopSecurityCheck())
  2570. {
  2571. #region battle with security Digimon
  2572. if (brokenSecurityCard.IsDigimon)
  2573. {
  2574. bool doBattle = true;
  2575. #region "ignore battle" effect
  2576. Hashtable hashtable3 = new Hashtable()
  2577. {
  2578. {"Card", brokenSecurityCard}
  2579. };
  2580. #region the security Digimon's effect
  2581. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
  2582. {
  2583. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2584. {
  2585. if (cardEffect.CanUse(hashtable3))
  2586. {
  2587. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2588. {
  2589. doBattle = false;
  2590. }
  2591. }
  2592. }
  2593. }
  2594. #endregion
  2595. #region player's effect
  2596. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2597. {
  2598. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2599. {
  2600. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2601. {
  2602. if (cardEffect.CanUse(hashtable3))
  2603. {
  2604. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2605. {
  2606. doBattle = false;
  2607. }
  2608. }
  2609. }
  2610. }
  2611. }
  2612. #endregion
  2613. #endregion
  2614. if (doBattle)
  2615. {
  2616. yield return new WaitForSeconds(0.3f);
  2617. yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
  2618. }
  2619. }
  2620. #endregion
  2621. }
  2622. #region effect
  2623. yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
  2624. if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
  2625. {
  2626. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
  2627. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
  2628. {
  2629. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2630. }
  2631. }
  2632. GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
  2633. GManager.instance.attackProcess.SecurityDigimon = null;
  2634. #endregion
  2635. // reset effect until end of security check
  2636. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2637. {
  2638. player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2639. }
  2640. // auto process check
  2641. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2642. GManager.instance.turnStateMachine.IsSelecting = true;
  2643. }
  2644. else
  2645. {
  2646. break;
  2647. }
  2648. }
  2649. }
  2650. #endregion
  2651. GManager.instance.turnStateMachine.isSecurityCehck = false;
  2652. }
  2653. }
  2654. }
  2655. #endregion
  2656. #region trash cards from security
  2657. public class IDestroySecurity
  2658. {
  2659. public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
  2660. {
  2661. _player = player;
  2662. _destroySecurityCount = destroySecurityCount;
  2663. _cardEffect = cardEffect;
  2664. _fromTop = fromTop;
  2665. }
  2666. Player _player = null;
  2667. int _destroySecurityCount = 0;
  2668. ICardEffect _cardEffect = null;
  2669. bool _fromTop = false;
  2670. public IEnumerator DestroySecurity()
  2671. {
  2672. bool StopDestroySecurity()
  2673. {
  2674. if (_player.SecurityCards.Count == 0)
  2675. {
  2676. return true;
  2677. }
  2678. if (!_player.CanReduceSecurity())
  2679. {
  2680. return true;
  2681. }
  2682. return false;
  2683. }
  2684. if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
  2685. {
  2686. int count = 0;
  2687. List<CardSource> discardedCards = new List<CardSource>();
  2688. while (true)
  2689. {
  2690. if (StopDestroySecurity())
  2691. {
  2692. break;
  2693. }
  2694. if (count >= _destroySecurityCount)
  2695. {
  2696. break;
  2697. }
  2698. if (_player.SecurityCards.Count >= 1)
  2699. {
  2700. count++;
  2701. CardSource destroyedSecurityCard = _player.SecurityCards[0];
  2702. if (!_fromTop)
  2703. {
  2704. destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
  2705. }
  2706. discardedCards.Add(destroyedSecurityCard);
  2707. #region effect
  2708. _player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2709. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
  2710. yield return new WaitForSeconds(0.1f);
  2711. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
  2712. yield return new WaitForSeconds(0.5f);
  2713. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
  2714. #endregion
  2715. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
  2716. }
  2717. }
  2718. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  2719. if (discardedCards.Count >= 1)
  2720. {
  2721. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2722. player: _player,
  2723. refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
  2724. cardEffect: _cardEffect).ReduceSecurity());
  2725. #region "When security cards are trashed" effect
  2726. #region Hashtable setting
  2727. Hashtable hashtable = new Hashtable()
  2728. {
  2729. {"DiscardedCards", discardedCards},
  2730. {"CardEffect", _cardEffect},
  2731. };
  2732. #endregion
  2733. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
  2734. #endregion
  2735. }
  2736. #region add log
  2737. if (discardedCards.Count >= 1)
  2738. {
  2739. string log = "";
  2740. string fromString = _fromTop ? "Top" : "Bottom";
  2741. log += $"\nDiscarded From {fromString} Security Cards:";
  2742. foreach (CardSource cardSource in discardedCards)
  2743. {
  2744. if (cardSource != null)
  2745. {
  2746. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2747. }
  2748. }
  2749. log += "\n";
  2750. PlayLog.OnAddLog?.Invoke(log);
  2751. }
  2752. #endregion
  2753. }
  2754. }
  2755. }
  2756. #endregion
  2757. #region Battle
  2758. public class IBattle
  2759. {
  2760. public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard)
  2761. {
  2762. this.AttackingPermanent = AttackingPermanent;
  2763. this.DefendingPermanent = DefendingPermanent;
  2764. this.DefendingCard = DefendingCard;
  2765. }
  2766. public Permanent AttackingPermanent { get; private set; } = null;
  2767. public Permanent DefendingPermanent { get; private set; } = null;
  2768. CardSource DefendingCard { get; set; } = null;
  2769. public Hashtable hashtable { get; set; } = new Hashtable();
  2770. public Permanent enemyPermanent(Permanent permanent)
  2771. {
  2772. if (permanent != null)
  2773. {
  2774. if (permanent == AttackingPermanent)
  2775. {
  2776. return DefendingPermanent;
  2777. }
  2778. else if (permanent == DefendingPermanent)
  2779. {
  2780. return AttackingPermanent;
  2781. }
  2782. }
  2783. return null;
  2784. }
  2785. public int CompareStats()
  2786. {
  2787. int statCheck = 0;
  2788. if(AttackingPermanent.HasIceclad || DefendingPermanent.HasIceclad)
  2789. statCheck = AttackingPermanent.DigivolutionCards.Count - DefendingPermanent.DigivolutionCards.Count;
  2790. else
  2791. statCheck = AttackingPermanent.DP - DefendingPermanent.DP;
  2792. statCheck = Mathf.Clamp(statCheck, -1, 1);
  2793. return statCheck;
  2794. }
  2795. public IEnumerator Battle()
  2796. {
  2797. hashtable = new Hashtable();
  2798. if (AttackingPermanent != null)
  2799. {
  2800. bool IsExistingDefender()
  2801. {
  2802. // whether defender exists
  2803. if ((DefendingPermanent == null) != (DefendingCard == null))
  2804. {
  2805. if (DefendingPermanent != null)
  2806. {
  2807. if (DefendingPermanent.TopCard != null)
  2808. {
  2809. return true;
  2810. }
  2811. }
  2812. else if (DefendingCard != null)
  2813. {
  2814. return true;
  2815. }
  2816. }
  2817. return false;
  2818. }
  2819. if (IsExistingDefender())
  2820. {
  2821. if (AttackingPermanent != null)
  2822. {
  2823. AttackingPermanent.battle = this;
  2824. }
  2825. if (DefendingPermanent != null)
  2826. {
  2827. DefendingPermanent.battle = this;
  2828. }
  2829. List<Permanent> WinnerPermanents = new List<Permanent>();
  2830. List<Permanent> LoserPermanents = new List<Permanent>();
  2831. CardSource LoserCard = null;
  2832. //add log
  2833. string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
  2834. if (DefendingPermanent != null)
  2835. {
  2836. log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
  2837. }
  2838. else if (DefendingCard != null)
  2839. {
  2840. log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
  2841. }
  2842. PlayLog.OnAddLog?.Invoke(log);
  2843. #region "At the start of battle" effect
  2844. Permanent _AttackingPermanent = null;
  2845. Permanent _DefendingPermanent = null;
  2846. if (AttackingPermanent != null)
  2847. {
  2848. if (AttackingPermanent.TopCard != null)
  2849. {
  2850. _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
  2851. }
  2852. }
  2853. if (DefendingPermanent != null)
  2854. {
  2855. if (DefendingPermanent.TopCard != null)
  2856. {
  2857. _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
  2858. }
  2859. }
  2860. hashtable.Add("AttackingPermanent", _AttackingPermanent);
  2861. hashtable.Add("DefendingPermanent", _DefendingPermanent);
  2862. hashtable.Add("DefendingCard", DefendingCard);
  2863. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
  2864. #endregion
  2865. #region Show effect
  2866. bool ShowEffect()
  2867. {
  2868. if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
  2869. {
  2870. return true;
  2871. }
  2872. else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
  2873. {
  2874. if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
  2875. {
  2876. return true;
  2877. }
  2878. }
  2879. return false;
  2880. }
  2881. if (ShowEffect())
  2882. {
  2883. if (GManager.instance.attackProcess.IsAttacking)
  2884. {
  2885. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2886. {
  2887. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2888. {
  2889. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2890. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2891. }
  2892. }
  2893. }
  2894. }
  2895. #endregion
  2896. // auto process check
  2897. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2898. GManager.instance.turnStateMachine.IsSelecting = true;
  2899. //Preemptive end battle if the attack process is ended
  2900. if(GManager.instance.attackProcess.IsEndAttack)
  2901. yield break;
  2902. #region battle with permanent
  2903. if (DefendingPermanent != null)
  2904. {
  2905. int battleResults = CompareStats();
  2906. if (battleResults == 1)
  2907. {
  2908. WinnerPermanents.Add(AttackingPermanent);
  2909. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2910. LoserPermanents.Add(DefendingPermanent);
  2911. }
  2912. else if (battleResults == 0)
  2913. {
  2914. WinnerPermanents.Add(AttackingPermanent);
  2915. WinnerPermanents.Add(DefendingPermanent);
  2916. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2917. LoserPermanents.Add(AttackingPermanent);
  2918. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2919. LoserPermanents.Add(DefendingPermanent);
  2920. }
  2921. else if (battleResults == -1)
  2922. {
  2923. WinnerPermanents.Add(DefendingPermanent);
  2924. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2925. LoserPermanents.Add(AttackingPermanent);
  2926. }
  2927. }
  2928. #endregion
  2929. #region battle with card
  2930. else if (DefendingCard != null)
  2931. {
  2932. if (AttackingPermanent.DP > DefendingCard.CardDP)
  2933. {
  2934. WinnerPermanents.Add(AttackingPermanent);
  2935. LoserCard = DefendingCard;
  2936. }
  2937. else if (AttackingPermanent.DP == DefendingCard.CardDP)
  2938. {
  2939. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2940. {
  2941. LoserPermanents.Add(AttackingPermanent);
  2942. }
  2943. LoserCard = DefendingCard;
  2944. }
  2945. else if (AttackingPermanent.DP < DefendingCard.CardDP)
  2946. {
  2947. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2948. {
  2949. LoserPermanents.Add(AttackingPermanent);
  2950. }
  2951. }
  2952. }
  2953. #endregion
  2954. List<Permanent> _WinnerPermanents = new List<Permanent>();
  2955. List<Permanent> _LoserPermanents = new List<Permanent>();
  2956. foreach (Permanent permanent in WinnerPermanents)
  2957. {
  2958. if (permanent.TopCard != null)
  2959. {
  2960. _WinnerPermanents.Add(new Permanent(permanent.cardSources));
  2961. }
  2962. }
  2963. foreach (Permanent permanent in LoserPermanents)
  2964. {
  2965. if (permanent.TopCard != null)
  2966. {
  2967. _LoserPermanents.Add(new Permanent(permanent.cardSources));
  2968. }
  2969. }
  2970. hashtable.Add("WinnerPermanents", _WinnerPermanents);
  2971. hashtable.Add("WinnerPermanents_real", WinnerPermanents);
  2972. hashtable.Add("LoserPermanents", _LoserPermanents);
  2973. hashtable.Add("LoserPermanents_real", LoserPermanents);
  2974. hashtable.Add("LoserCard", LoserCard);
  2975. hashtable.Add("battle", this);
  2976. // battle effect
  2977. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
  2978. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(LoserPermanents, hashtable).Destroy());
  2979. //Fix winner/loser permanents
  2980. int index = -1;
  2981. foreach (Permanent permanent in LoserPermanents)
  2982. {
  2983. if (permanent.TopCard != null)
  2984. {
  2985. index = LoserPermanents.IndexOf(permanent);
  2986. }
  2987. }
  2988. if (index >= 0)
  2989. {
  2990. LoserPermanents.RemoveAt(index);
  2991. _LoserPermanents.RemoveAt(index);
  2992. hashtable["LoserPermanents"] = _LoserPermanents;
  2993. hashtable["LoserPermanents_real"] = LoserPermanents;
  2994. }
  2995. //LoserPermanents = LoserPermanents.Filter(permanent => permanent.TopCard != null);
  2996. //_LoserPermanents = _LoserPermanents.Filter(permanent => permanent.TopCard != null);
  2997. //hashtable["LoserPermanents"] = _LoserPermanents;
  2998. //hashtable["LoserPermanents_real"] = LoserPermanents;
  2999. // "At the end of battle" effect
  3000. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
  3001. #region move up effect
  3002. if (ShowEffect())
  3003. {
  3004. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
  3005. }
  3006. #endregion
  3007. #region effect when determine whether to do security check
  3008. List<SkillInfo> skillInfos_Pierce = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnDetermineDoSecurityCheck)
  3009. .Filter(skillInfo => skillInfo.CardEffect != null && skillInfo.CardEffect.CanActivate(skillInfo.Hashtable));
  3010. if (skillInfos_Pierce.Count >= 1)
  3011. {
  3012. GManager.instance.autoProcessing.PutStackedSkill(skillInfos_Pierce[0]);
  3013. }
  3014. #endregion
  3015. }
  3016. }
  3017. // auto process check
  3018. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3019. #region reset effect until the end of battle
  3020. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3021. {
  3022. foreach (Permanent permanent in player.GetFieldPermanents())
  3023. {
  3024. permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  3025. }
  3026. player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  3027. }
  3028. #endregion
  3029. if (AttackingPermanent != null)
  3030. {
  3031. AttackingPermanent.battle = null;
  3032. }
  3033. if (DefendingPermanent != null)
  3034. {
  3035. DefendingPermanent.battle = null;
  3036. }
  3037. }
  3038. }
  3039. #endregion
  3040. #region De-digivolve
  3041. public class IDegeneration
  3042. {
  3043. /// <summary>
  3044. /// De-Digivolve Class
  3045. /// </summary>
  3046. /// <param name="permanent">Target Permanent</param>
  3047. /// <param name="DegenerationCount">De-Digivolve Amount</param>
  3048. /// <param name="cardEffect">Card Effect</param>
  3049. /// <param name="DegenerationCountRuling">Should we enforce rule to select De-digivolve amount before digimon, disabled by default</param>
  3050. public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect, bool? DegenerationCountRuling = null)
  3051. {
  3052. _permanent = permanent;
  3053. _degenerationCount = DegenerationCount;
  3054. _cardEffect = cardEffect;
  3055. _degenerationCountRuling = DegenerationCountRuling;
  3056. }
  3057. Permanent _permanent = null;
  3058. int _degenerationCount;
  3059. ICardEffect _cardEffect = null;
  3060. bool? _degenerationCountRuling;
  3061. public IEnumerator Degeneration()
  3062. {
  3063. if (_cardEffect == null) yield break;
  3064. if (_cardEffect.EffectSourceCard == null) yield break;
  3065. if (_permanent == null) yield break;
  3066. if (_permanent.TopCard == null) yield break;
  3067. if (_permanent.ImmuneFromDeDigivolve()) yield break;
  3068. if (_permanent.ImmuneFromStackTrashing()) yield break;
  3069. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3070. int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
  3071. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  3072. if (selectCountEffect != null && _degenerationCountRuling == null)
  3073. {
  3074. Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
  3075. selectCountEffect.SetUp(
  3076. SelectPlayer: selectPlayer,
  3077. targetPermanent: _permanent,
  3078. MaxCount: maxCount,
  3079. CanNoSelect: false,
  3080. Message: "How many cards do you trash?",
  3081. Message_Enemy: "The opponent is choosing how many cards to trash.",
  3082. SelectCountCoroutine: SelectCountCoroutine);
  3083. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  3084. IEnumerator SelectCountCoroutine(int count)
  3085. {
  3086. _degenerationCount = count;
  3087. yield return null;
  3088. }
  3089. }
  3090. if (_degenerationCount >= 1)
  3091. {
  3092. int count = 0;
  3093. List<CardSource> selectedCards = new List<CardSource>();
  3094. while (true)
  3095. {
  3096. bool StopCondition()
  3097. {
  3098. if (_permanent.HasNoDigivolutionCards)
  3099. {
  3100. return true;
  3101. }
  3102. if (_permanent.Level == 3)
  3103. {
  3104. if (_permanent.TopCard != null)
  3105. {
  3106. if (_permanent.TopCard.HasLevel)
  3107. {
  3108. return true;
  3109. }
  3110. }
  3111. }
  3112. if (count >= _degenerationCount)
  3113. {
  3114. return true;
  3115. }
  3116. return false;
  3117. }
  3118. if (StopCondition())
  3119. {
  3120. break;
  3121. }
  3122. if (count == 0)
  3123. {
  3124. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3125. }
  3126. CardSource cardSource = _permanent.TopCard;
  3127. selectedCards.Add(cardSource);
  3128. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  3129. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3130. if (!cardSource.IsToken)
  3131. {
  3132. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3133. }
  3134. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  3135. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3136. count++;
  3137. }
  3138. #region "When Top Card is Trashed" effect
  3139. #region Hashtable Setting
  3140. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  3141. {
  3142. {"Permanent", _permanent},
  3143. {"CardSources", selectedCards}
  3144. };
  3145. #endregion
  3146. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  3147. .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
  3148. #endregion
  3149. #region add log
  3150. if (selectedCards.Count >= 1)
  3151. {
  3152. string log = "";
  3153. log += $"\nDe-Digivolve :";
  3154. foreach (CardSource cardSource in selectedCards)
  3155. {
  3156. if (cardSource != null)
  3157. {
  3158. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3159. }
  3160. }
  3161. log += "\n";
  3162. PlayLog.OnAddLog?.Invoke(log);
  3163. }
  3164. #endregion
  3165. }
  3166. }
  3167. }
  3168. #endregion
  3169. #region Trash digivolution cards
  3170. public class ITrashDigivolutionCards
  3171. {
  3172. public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  3173. {
  3174. _permanent = permanent;
  3175. _trashTargetCards = trashTargetCards.Clone();
  3176. _cardEffect = cardEffect;
  3177. }
  3178. Permanent _permanent = null;
  3179. List<CardSource> _trashTargetCards = new List<CardSource>();
  3180. ICardEffect _cardEffect = null;
  3181. public IEnumerator TrashDigivolutionCards()
  3182. {
  3183. if (_trashTargetCards == null) yield break;
  3184. if (_cardEffect == null) yield break;
  3185. if (_permanent == null) yield break;
  3186. if (_permanent.TopCard == null) yield break;
  3187. if (_permanent.ImmuneFromStackTrashing()) yield break;
  3188. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3189. if (_permanent.HasNoDigivolutionCards) yield break;
  3190. _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
  3191. _permanent.DigivolutionCards.Contains(cardSource) &&
  3192. !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
  3193. if (_trashTargetCards.Count == 0) yield break;
  3194. _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
  3195. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  3196. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  3197. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3198. #region cut in effect - Would discard
  3199. // "When digivolution cards would be trashed" effect
  3200. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  3201. CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
  3202. _permanent,
  3203. _trashTargetCards,
  3204. _cardEffect
  3205. ),
  3206. EffectTiming.WhenWouldDigivolutionCardDiscarded));
  3207. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  3208. {
  3209. // effect
  3210. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  3211. // cut in effect process
  3212. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3213. }
  3214. #endregion
  3215. //fix trash target permanent
  3216. Permanent permanentTarget_Fixed = _permanent;
  3217. // fix trash sources sources
  3218. List<CardSource> trashDigivolutionCards_Fixed = _trashTargetCards.Filter(cardsource =>
  3219. cardsource != null
  3220. && cardsource.willBeRemoveSources);
  3221. #region "When digivolution cards are trashed" effect
  3222. #region Hashtable Setting
  3223. Hashtable hashtable = new Hashtable()
  3224. {
  3225. {"CardEffect", _cardEffect},
  3226. {"Permanent", permanentTarget_Fixed},
  3227. {"DiscardedCards", trashDigivolutionCards_Fixed},
  3228. };
  3229. #endregion
  3230. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
  3231. #endregion
  3232. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  3233. foreach (CardSource cardSource in trashDigivolutionCards_Fixed)
  3234. {
  3235. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
  3236. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3237. if (!cardSource.IsToken)
  3238. {
  3239. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3240. }
  3241. cardSource.willBeRemoveSources = false;
  3242. }
  3243. }
  3244. }
  3245. #endregion
  3246. #region Trash link cards
  3247. public class ITrashLinkCards
  3248. {
  3249. public ITrashLinkCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  3250. {
  3251. _permanent = permanent;
  3252. _trashTargetCards = trashTargetCards.Clone();
  3253. _cardEffect = cardEffect;
  3254. }
  3255. Permanent _permanent = null;
  3256. List<CardSource> _trashTargetCards = new List<CardSource>();
  3257. ICardEffect _cardEffect = null;
  3258. public IEnumerator TrashLinkCards()
  3259. {
  3260. if (_trashTargetCards == null) yield break;
  3261. if (_cardEffect == null) yield break;
  3262. if (_permanent == null) yield break;
  3263. if (_permanent.TopCard == null) yield break;
  3264. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3265. if (_permanent.HasNoDigivolutionCards) yield break;
  3266. _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
  3267. _permanent.DigivolutionCards.Contains(cardSource) &&
  3268. !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
  3269. if (_trashTargetCards.Count == 0) yield break;
  3270. _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
  3271. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  3272. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  3273. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3274. #region cut in effect - Would discard
  3275. // "When link cards would be trashed" effect
  3276. //TODO: Create CardEffectCommons.WhenLinkCardWouldDiscard function
  3277. /*yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  3278. CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
  3279. _permanent,
  3280. _trashTargetCards,
  3281. _cardEffect
  3282. ),
  3283. EffectTiming.WhenWouldDigivolutionCardDiscarded));*/
  3284. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  3285. {
  3286. // effect
  3287. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  3288. // cut in effect process
  3289. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3290. }
  3291. #endregion
  3292. //fix trash target permanent
  3293. Permanent permanentTarget_Fixed = _permanent;
  3294. // fix trash sources sources
  3295. List<CardSource> trashLinkCards_Fixed = _trashTargetCards.Filter(cardsource =>
  3296. cardsource != null
  3297. && cardsource.willBeRemoveSources);
  3298. #region "When link cards are trashed" effect
  3299. #region Hashtable Setting
  3300. Hashtable hashtable = new Hashtable()
  3301. {
  3302. {"CardEffect", _cardEffect},
  3303. {"Permanent", permanentTarget_Fixed},
  3304. {"DiscardedCards", trashLinkCards_Fixed},
  3305. };
  3306. #endregion
  3307. //TODO: Create OnLinkCardDiscarded timing
  3308. //yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
  3309. #endregion
  3310. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  3311. foreach (CardSource cardSource in trashLinkCards_Fixed)
  3312. {
  3313. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
  3314. if (!cardSource.IsToken)
  3315. {
  3316. yield return ContinuousController.instance.StartCoroutine(permanentTarget_Fixed.RemoveLinkedCard(cardSource));
  3317. }
  3318. cardSource.willBeRemoveSources = false;
  3319. }
  3320. }
  3321. }
  3322. #endregion
  3323. #region Return digivolution cards to deck bottom
  3324. public class ReturnToLibraryBottomDigivolutionCardsClass
  3325. {
  3326. public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
  3327. {
  3328. _permanent = permanent;
  3329. _cardSources = cardSources.Clone();
  3330. _hashtable = hashtable;
  3331. }
  3332. Permanent _permanent = null;
  3333. List<CardSource> _cardSources = new List<CardSource>();
  3334. Hashtable _hashtable = null;
  3335. public IEnumerator ReturnToLibraryBottomDigivolutionCards()
  3336. {
  3337. if (_permanent == null) yield break;
  3338. if (_permanent.TopCard == null) yield break;
  3339. if (_cardSources == null) yield break;
  3340. _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
  3341. if (_cardSources.Count == 0) yield break;
  3342. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3343. if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
  3344. string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
  3345. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
  3346. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3347. #region "When digivolution cards are returned to deck" effect
  3348. #region Hashtable Setting
  3349. Hashtable hashtable1 = new Hashtable()
  3350. {
  3351. {"Permanent", _permanent},
  3352. {"DeckBottomCards", _cardSources},
  3353. {"CardEffect", CardEffect},
  3354. };
  3355. #endregion
  3356. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
  3357. #endregion
  3358. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
  3359. }
  3360. }
  3361. #endregion
  3362. #region Reduce security
  3363. public class IReduceSecurity
  3364. {
  3365. public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos, ICardEffect cardEffect = null)
  3366. {
  3367. _player = player;
  3368. _refSkillInfos = refSkillInfos;
  3369. _cardEffect = cardEffect;
  3370. }
  3371. Player _player = null;
  3372. List<SkillInfo> _refSkillInfos = null;
  3373. ICardEffect _cardEffect = null;
  3374. public IEnumerator ReduceSecurity()
  3375. {
  3376. GManager.OnSecurityStackChanged?.Invoke(_player);
  3377. #region "When cards are removed from security" effect
  3378. #region Hashtable Setting
  3379. Hashtable hashtable = new Hashtable()
  3380. {
  3381. {"Player", _player},
  3382. {"SkillInfo",_refSkillInfos },
  3383. {"CardEffect",_cardEffect}
  3384. };
  3385. #endregion
  3386. if (_refSkillInfos == null)
  3387. {
  3388. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
  3389. }
  3390. else
  3391. {
  3392. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
  3393. {
  3394. _refSkillInfos.Add(skillInfo);
  3395. }
  3396. }
  3397. #endregion
  3398. }
  3399. }
  3400. #endregion
  3401. #region Add Security
  3402. public class IAddSecurity
  3403. {
  3404. public IAddSecurity(Player player)
  3405. {
  3406. _player = player;
  3407. }
  3408. Player _player { get; set; }
  3409. public IEnumerator AddSecurity()
  3410. {
  3411. GManager.OnSecurityStackChanged?.Invoke(_player);
  3412. #region "When security cards are added" effect
  3413. #region Hashtable setting
  3414. Hashtable hashtable = new Hashtable()
  3415. {
  3416. {"Player", _player}
  3417. };
  3418. #endregion
  3419. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
  3420. #endregion
  3421. }
  3422. }
  3423. #endregion
  3424. #region Suspend permanents
  3425. public class SuspendPermanentsClass
  3426. {
  3427. public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
  3428. {
  3429. _permanents = permanents;
  3430. _hashtable = hashtable;
  3431. }
  3432. List<Permanent> _permanents { get; set; }
  3433. Hashtable _hashtable { get; set; }
  3434. public IEnumerator Tap()
  3435. {
  3436. if (_permanents.Count == 0) yield break;
  3437. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3438. bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
  3439. bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
  3440. List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
  3441. bool PermanentCondition(Permanent permanent)
  3442. {
  3443. if (permanent != null)
  3444. {
  3445. if (permanent.TopCard != null)
  3446. {
  3447. if (permanent.IsSuspended)
  3448. {
  3449. return false;
  3450. }
  3451. if (!permanent.CanSuspend)
  3452. {
  3453. return false;
  3454. }
  3455. if (CardEffect != null)
  3456. {
  3457. if (permanent.TopCard.CanNotBeAffected(CardEffect))
  3458. {
  3459. return false;
  3460. }
  3461. }
  3462. }
  3463. }
  3464. return true;
  3465. }
  3466. foreach (Permanent permanent in suspendTargetPermanents)
  3467. {
  3468. permanent.IsSuspended = true;
  3469. GManager.OnCardSuspendedChanged?.Invoke(true);
  3470. permanent.DPWhenSuspended = permanent.DP;
  3471. if (permanent.ShowingPermanentCard != null)
  3472. {
  3473. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3474. }
  3475. }
  3476. if (suspendTargetPermanents.Count >= 1)
  3477. {
  3478. #region "Effects when permanents suspend
  3479. #region Hashtable Setting
  3480. Hashtable _hashtable = new Hashtable(){
  3481. {"Permanents", suspendTargetPermanents},
  3482. {"IsBlock", IsBlock}
  3483. };
  3484. if (CardEffect != null)
  3485. {
  3486. _hashtable.Add("CardEffect", CardEffect);
  3487. }
  3488. #endregion
  3489. if (IsAttack) yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3490. else yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3491. #endregion
  3492. yield return new WaitForSeconds(0.3f);
  3493. }
  3494. }
  3495. }
  3496. #endregion
  3497. #region Unsuspend permanents
  3498. public class IUnsuspendPermanents
  3499. {
  3500. public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
  3501. {
  3502. _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  3503. _cardEffect = cardEffect;
  3504. }
  3505. List<Permanent> _permanents { get; set; }
  3506. ICardEffect _cardEffect { get; set; }
  3507. public IEnumerator Unsuspend()
  3508. {
  3509. //Permanent list that will unsuspend
  3510. List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
  3511. permanent != null
  3512. && permanent.TopCard != null
  3513. && permanent.IsSuspended
  3514. && permanent.CanUnsuspend
  3515. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3516. #region "When permanents would unsuspend" effect
  3517. #region Hashtable Setting
  3518. Hashtable hashtable1 = new Hashtable()
  3519. {
  3520. {"CardEffect", _cardEffect},
  3521. {"Permanents", untappedPermanets},
  3522. };
  3523. #endregion
  3524. List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
  3525. if (skillInfos.Count >= 1)
  3526. {
  3527. foreach (SkillInfo skillInfo in skillInfos)
  3528. {
  3529. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  3530. }
  3531. foreach (Permanent permanent in untappedPermanets)
  3532. {
  3533. permanent.ShowUnsuspendEffect();
  3534. }
  3535. //cut in effects
  3536. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3537. untappedPermanets.ForEach(permanent =>
  3538. {
  3539. if (permanent.ShowingPermanentCard != null)
  3540. {
  3541. permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
  3542. }
  3543. });
  3544. }
  3545. #endregion
  3546. // fix unsuspend target permanents
  3547. List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
  3548. permanent != null
  3549. && permanent.TopCard != null
  3550. && permanent.IsSuspended
  3551. && permanent.CanUnsuspend
  3552. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3553. if (untappedPermanets_Fixed.Count >= 1)
  3554. {
  3555. foreach (Permanent permanent in untappedPermanets_Fixed)
  3556. {
  3557. permanent.IsSuspended = false;
  3558. if (permanent.ShowingPermanentCard != null)
  3559. {
  3560. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3561. }
  3562. }
  3563. #region "When permanents are unsuspended" effect
  3564. #region Hashtable Setting
  3565. Hashtable hashtable2 = new Hashtable()
  3566. {
  3567. {"CardEffect", _cardEffect},
  3568. {"Permanents", untappedPermanets_Fixed},
  3569. };
  3570. #endregion
  3571. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
  3572. #endregion
  3573. yield return new WaitForSeconds(0.3f);
  3574. }
  3575. foreach (Permanent permanent in untappedPermanets)
  3576. {
  3577. permanent.UntilNextUntapEffects = new List<Func<EffectTiming, ICardEffect>>();
  3578. }
  3579. }
  3580. }
  3581. #endregion
  3582. #region Trash cards from deck top
  3583. public class ITrashDeckCards
  3584. {
  3585. public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
  3586. {
  3587. this.cardSources = new List<CardSource>();
  3588. foreach (CardSource cardSource in cardSources)
  3589. {
  3590. this.cardSources.Add(cardSource);
  3591. }
  3592. this.cardEffect = cardEffect;
  3593. }
  3594. List<CardSource> cardSources { get; set; } = new List<CardSource>();
  3595. ICardEffect cardEffect { get; set; } = null;
  3596. public IEnumerator TrashDeckCards()
  3597. {
  3598. List<CardSource> trashCards = new List<CardSource>();
  3599. foreach (CardSource cardSource in cardSources)
  3600. {
  3601. if (cardSource.Owner.LibraryCards.Contains(cardSource))
  3602. {
  3603. trashCards.Add(cardSource);
  3604. }
  3605. }
  3606. if (trashCards.Count >= 1)
  3607. {
  3608. foreach (CardSource cardSource in trashCards)
  3609. {
  3610. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3611. }
  3612. #region "When cards are trashed from security" effect
  3613. #region Hashtable setting
  3614. Hashtable hashtable = new Hashtable()
  3615. {
  3616. {"DiscardedCards", trashCards},
  3617. {"CardEffect", cardEffect},
  3618. };
  3619. #endregion
  3620. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  3621. hashtable, EffectTiming.OnDiscardLibrary));
  3622. #endregion
  3623. }
  3624. }
  3625. }
  3626. #endregion
  3627. #region Overflow of ace
  3628. public class AceOverflowClass
  3629. {
  3630. public AceOverflowClass(List<CardSource> cardSources)
  3631. {
  3632. _cardSources = cardSources.Clone();
  3633. }
  3634. List<CardSource> _cardSources = new List<CardSource>();
  3635. public IEnumerator Overflow()
  3636. {
  3637. _cardSources = _cardSources
  3638. .Filter(cardSource => cardSource.IsACE && CardEffectCommons.IsExistOnBattleArea(cardSource) || CardEffectCommons.IsExistOnBreedingAreaDigimon(cardSource))
  3639. .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
  3640. .ToList();
  3641. foreach (CardSource cardSource in _cardSources)
  3642. {
  3643. yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
  3644. string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
  3645. PlayLog.OnAddLog?.Invoke(log);
  3646. }
  3647. }
  3648. }
  3649. #endregion
  3650. #region TrashStack
  3651. public class ITrashStack
  3652. {
  3653. /// <summary>
  3654. /// Trash Stack Class
  3655. /// </summary>
  3656. /// <param name="permanent">Target Permanent</param>
  3657. /// <param name="TrashCount">Amount of cards to trash</param>
  3658. /// <param name="cardEffect">Card Effect</param>
  3659. /// <param name="fromTop">Should trashing start from top, true by default</param>
  3660. public ITrashStack(Permanent permanent, int TrashCount, ICardEffect cardEffect, bool fromTop = true)
  3661. {
  3662. _permanent = permanent;
  3663. _trashCount = TrashCount;
  3664. _cardEffect = cardEffect;
  3665. _fromTop = fromTop;
  3666. }
  3667. Permanent _permanent = null;
  3668. int _trashCount;
  3669. ICardEffect _cardEffect = null;
  3670. bool _fromTop;
  3671. public IEnumerator TrashStack()
  3672. {
  3673. if (_cardEffect == null) yield break;
  3674. if (_cardEffect.EffectSourceCard == null) yield break;
  3675. if (_permanent == null) yield break;
  3676. if (_permanent.TopCard == null) yield break;
  3677. if (_permanent.ImmuneFromStackTrashing()) yield break;
  3678. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3679. _trashCount = Math.Min(_permanent.StackCards.Count, _trashCount);
  3680. if (_trashCount >= 1)
  3681. {
  3682. int count = 0;
  3683. List<CardSource> selectedCards = new List<CardSource>();
  3684. while (true)
  3685. {
  3686. bool StopCondition()
  3687. {
  3688. if (_permanent.HasNoDigivolutionCards)
  3689. {
  3690. return true;
  3691. }
  3692. if (count >= _trashCount)
  3693. {
  3694. return true;
  3695. }
  3696. return false;
  3697. }
  3698. if (StopCondition())
  3699. {
  3700. break;
  3701. }
  3702. if (count == 0)
  3703. {
  3704. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3705. }
  3706. CardSource cardSource = _permanent.TopCard;
  3707. selectedCards.Add(cardSource);
  3708. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  3709. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3710. if (!cardSource.IsToken)
  3711. {
  3712. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3713. }
  3714. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  3715. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3716. count++;
  3717. }
  3718. #region "When Top Card is Trashed" effect
  3719. #region Hashtable Setting
  3720. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  3721. {
  3722. {"Permanent", _permanent},
  3723. {"CardSources", selectedCards}
  3724. };
  3725. #endregion
  3726. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  3727. .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
  3728. #endregion
  3729. #region add log
  3730. if (selectedCards.Count >= 1)
  3731. {
  3732. string log = "";
  3733. log += $"\nStack Trashed :";
  3734. foreach (CardSource cardSource in selectedCards)
  3735. {
  3736. if (cardSource != null)
  3737. {
  3738. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3739. }
  3740. }
  3741. log += "\n";
  3742. PlayLog.OnAddLog?.Invoke(log);
  3743. }
  3744. #endregion
  3745. }
  3746. }
  3747. }
  3748. #endregion