CardController.cs 168 KB

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