CardController.cs 179 KB

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