CardController.cs 182 KB

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