CardController.cs 164 KB

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