CardController.cs 182 KB

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