CardController.cs 156 KB

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