CardController.cs 180 KB

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