CardController.cs 161 KB

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