CardController.cs 179 KB

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