CardController.cs 179 KB

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