CardController.cs 181 KB

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