CardController.cs 156 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302
  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. if(card.IsToken)
  939. PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity} token\n");
  940. else
  941. PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  942. permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = _isTapped };
  943. yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, frameId));
  944. permanent.EnterFieldTurnCount = GManager.instance.turnStateMachine.TurnCount;
  945. }
  946. GManager.instance.turnStateMachine.isSync = true;
  947. if (GManager.instance.turnStateMachine.DoneStartGame)
  948. {
  949. if (!isEvolution)
  950. {
  951. #region wheter to have ETB effects
  952. Hashtable hashtable = CardEffectCommons.OnEnterFieldHashtable(
  953. hashtableParams: new List<OnEnterFieldHashtableParams>()
  954. {
  955. new OnEnterFieldHashtableParams(
  956. permanent: permanent,
  957. evoRoots: evoRoots,
  958. evoRootTops: evoRootTops,
  959. root: _root,
  960. oldLevels: oldLevels,
  961. isFromDigimonDigivolutionCards:isFromDigimonDigivolutionCards
  962. )
  963. },
  964. isEvolution: isEvolution,
  965. isJogress: isJogress,
  966. digiXrosCount: _digiXrosCount,
  967. cardEffect: CardEffect);
  968. bool HasETB = permanent.EffectList(EffectTiming.OnEnterFieldAnyone).Some(cardEffect =>
  969. cardEffect is ActivateICardEffect && cardEffect.CanUse(hashtable) && _activateETB && cardEffect.IsOnPlay);
  970. #endregion
  971. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, HasETB: HasETB, isDigiXros: _digiXrosCount >= 1));
  972. }
  973. else
  974. {
  975. bool isBlast = CardEffect != null && CardEffect.EffectName != null && CardEffect.EffectName.Contains("Blast");
  976. //effect
  977. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DigivolveFieldPermanentCardEffect(permanent.ShowingPermanentCard, _burstDigivolved, isBlast));
  978. }
  979. }
  980. }
  981. }
  982. }
  983. else
  984. {
  985. if (_jogressEvoRootsFrameIDs.Length == 2)
  986. {
  987. played = true;
  988. card.Init();
  989. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  990. isEvolution = true;
  991. List<Permanent> evoRootPermanents = new List<Permanent>();
  992. for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
  993. {
  994. int frameID = _jogressEvoRootsFrameIDs[i];
  995. Permanent evoRoot = card.Owner.fieldCardFrames[frameID].GetFramePermanent();
  996. if (evoRoot != null)
  997. {
  998. if (evoRoot.TopCard != null)
  999. {
  1000. evoRootPermanents.Add(evoRoot);
  1001. }
  1002. }
  1003. }
  1004. int targetFrameID = evoRootPermanents[0].PermanentFrame.FrameID;
  1005. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1006. {
  1007. evoRoots.Add(evoRootPermanent.TopCard);
  1008. }
  1009. List<CardSource> newDigivolutionCards = evoRootPermanents
  1010. .Map(evoRootPermanent => evoRootPermanent.cardSources)
  1011. .Flat();
  1012. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1013. {
  1014. oldLevels.Add(evoRootPermanent.Level);
  1015. evoRootTops.Add(evoRootPermanent.TopCard);
  1016. }
  1017. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1018. {
  1019. yield return ContinuousController.instance.StartCoroutine(evoRootPermanent.DiscardEvoRoots(ignoreOverflow: true, putToTrash: false));
  1020. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(evoRootPermanent, ignoreOverflow: true));
  1021. }
  1022. PlayLog.OnAddLog?.Invoke($"\nJogress:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1023. permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = false };
  1024. yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, targetFrameID));
  1025. permanent.EnterFieldTurnCount = -1;
  1026. newDigivolutionCards.Reverse();
  1027. yield return ContinuousController.instance.StartCoroutine(permanent.AddDigivolutionCardsTop(newDigivolutionCards, null));
  1028. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, isDigiXros: false, jogressEvoRoots: evoRootTops.ToArray()));
  1029. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(evoRootTops, "DNA Digivolution Cards", true, true));
  1030. foreach (CardSource evolutionCard in permanent.DigivolutionCards)
  1031. {
  1032. evolutionCard.cEntity_EffectController.InitUseCountThisTurn();
  1033. }
  1034. }
  1035. }
  1036. if (played)
  1037. {
  1038. if (isFromSecurity)
  1039. {
  1040. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  1041. player: card.Owner,
  1042. refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
  1043. CardEffectCommons.GetCardEffectFromHashtable(_hashtable)).ReduceSecurity());
  1044. }
  1045. if (isEvolution)
  1046. {
  1047. card.Owner.DigivolveCount_ThisTurn++;
  1048. yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, null).Draw());
  1049. if (_burstDigivolved)
  1050. {
  1051. if (permanent.TopCard != null)
  1052. {
  1053. permanent.IsBurstDigivolved = true;
  1054. GManager.instance.selectBurstDigivolutionEffect.AddTrashTopCardAtTurnEnd(permanent);
  1055. }
  1056. }
  1057. permanent.CardNamesJustAfterDigivolved = permanent.TopCard.CardNames.Clone();
  1058. permanent.DigivolvingEffect = CardEffect;
  1059. }
  1060. else
  1061. {
  1062. permanent.PlayingEffect = CardEffect;
  1063. if (permanent.TopCard.HasLevel)
  1064. {
  1065. permanent.LevelJustAfterPlayed = permanent.Level;
  1066. }
  1067. if (permanent.TopCard.HasPlayCost)
  1068. {
  1069. permanent.PlayCostJustAfterPlayed = permanent.TopCard.GetCostItself;
  1070. }
  1071. permanent.CardNamesJustAfterPlayed = permanent.TopCard.CardNames.Clone();
  1072. permanent.TraitsJustAfterPlayed = permanent.TopCard.CardTraits.Clone();
  1073. }
  1074. #region move permanents (hybrid)
  1075. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  1076. {
  1077. if (permanent.TopCard.PreferredFrame() != null)
  1078. {
  1079. if (permanent.PermanentFrame != permanent.TopCard.PreferredFrame())
  1080. {
  1081. if (permanent.TopCard.PreferredFrame().IsEmptyFrame())
  1082. {
  1083. bool move = false;
  1084. if (permanent.IsDigimon)
  1085. {
  1086. if (permanent.TopCard.Owner.isYou)
  1087. {
  1088. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1089. {
  1090. move = true;
  1091. }
  1092. }
  1093. else
  1094. {
  1095. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1096. {
  1097. move = true;
  1098. }
  1099. }
  1100. }
  1101. else if (permanent.IsTamer || permanent.TopCard.IsOption)
  1102. {
  1103. if (permanent.TopCard.Owner.isYou)
  1104. {
  1105. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1106. {
  1107. move = true;
  1108. }
  1109. }
  1110. else
  1111. {
  1112. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1113. {
  1114. move = true;
  1115. }
  1116. }
  1117. }
  1118. if (move)
  1119. {
  1120. yield return ContinuousController.instance.StartCoroutine(CardObjectController.MovePermanent(permanent.PermanentFrame));
  1121. }
  1122. }
  1123. }
  1124. }
  1125. }
  1126. #endregion
  1127. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCardsByEffect(card);
  1128. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCards(card);
  1129. if (GManager.instance.turnStateMachine.DoneStartGame)
  1130. {
  1131. hashtableParams.Add(
  1132. new OnEnterFieldHashtableParams(
  1133. permanent: permanent,
  1134. evoRoots: evoRoots,
  1135. evoRootTops: evoRootTops,
  1136. root: _root,
  1137. oldLevels: oldLevels,
  1138. isFromDigimonDigivolutionCards: isFromDigimonDigivolutionCards
  1139. )
  1140. );
  1141. }
  1142. }
  1143. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  1144. yield return GManager.instance.photonWaitController.StartWait("EndPlayPermanent");
  1145. }
  1146. // except [On Play] effect
  1147. bool CardEffectCondition(ICardEffect cardEffect)
  1148. {
  1149. if (cardEffect == null)
  1150. {
  1151. return false;
  1152. }
  1153. if (!_activateETB)
  1154. {
  1155. if (cardEffect is ActivateICardEffect)
  1156. {
  1157. if (cardEffect.IsOnPlay)
  1158. {
  1159. return false;
  1160. }
  1161. }
  1162. }
  1163. return true;
  1164. }
  1165. Hashtable effectHashtable = CardEffectCommons.OnEnterFieldHashtable(
  1166. hashtableParams: hashtableParams,
  1167. isEvolution: isEvolution,
  1168. isJogress: isJogress,
  1169. digiXrosCount: _digiXrosCount,
  1170. cardEffect: CardEffect);
  1171. #region "When permanents are played" effect
  1172. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  1173. hashtable: effectHashtable,
  1174. timing: EffectTiming.OnEnterFieldAnyone,
  1175. cardEffectCondition: CardEffectCondition));
  1176. #endregion
  1177. }
  1178. }
  1179. #endregion
  1180. #region Use option
  1181. public class UseOptionClass
  1182. {
  1183. public UseOptionClass(List<CardSource> cardSources, Hashtable hashtable, SelectCardEffect.Root root)
  1184. {
  1185. if (cardSources != null)
  1186. {
  1187. _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  1188. }
  1189. _hashtable = hashtable;
  1190. _root = root;
  1191. }
  1192. List<CardSource> _cardSources = new List<CardSource>();
  1193. SelectCardEffect.Root _root = SelectCardEffect.Root.None;
  1194. Hashtable _hashtable = null;
  1195. public bool _showEffect = false;
  1196. public bool _addSecurityEndOption = false;
  1197. public IEnumerator UseOption()
  1198. {
  1199. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1200. foreach (CardSource card in _cardSources)
  1201. {
  1202. if (_showEffect)
  1203. {
  1204. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(card));
  1205. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowUseHandCardEffect_PlayCard(card));
  1206. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  1207. }
  1208. PlayLog.OnAddLog?.Invoke($"\nPlay Option:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1209. card.Init();
  1210. GManager.instance.turnStateMachine.isSync = true;
  1211. card.SetFace();
  1212. int cost = card.GetCostItself;
  1213. //Remove from all areas
  1214. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1215. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(card));
  1216. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.BrainStormCoroutine(card));
  1217. #region Set HashTable
  1218. Hashtable hashtable = new Hashtable()
  1219. {
  1220. {"Card", card},
  1221. {"Root", _root},
  1222. {"Cost", cost},
  1223. };
  1224. #endregion
  1225. #region "When option is used" effect
  1226. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseOption));
  1227. yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.OnUseOption));
  1228. #endregion
  1229. #region effect process of option card
  1230. foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.OptionSkill))
  1231. {
  1232. if (cardEffect is ActivateICardEffect)
  1233. {
  1234. if (cardEffect.CanUse(hashtable))
  1235. {
  1236. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  1237. cardEffect,
  1238. hashtable));
  1239. }
  1240. }
  1241. }
  1242. #endregion
  1243. if (card.Owner.ExecutingCards.Contains(card))
  1244. {
  1245. if (_addSecurityEndOption && card.Owner.CanAddSecurity(CardEffect))
  1246. {
  1247. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(card));
  1248. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(card.Owner));
  1249. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(card.Owner).AddSecurity());
  1250. }
  1251. else
  1252. {
  1253. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(card));
  1254. }
  1255. }
  1256. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  1257. yield return GManager.instance.photonWaitController.StartWait("EndPlayOption");
  1258. }
  1259. }
  1260. }
  1261. #endregion
  1262. #region Draw cards
  1263. public class DrawClass
  1264. {
  1265. public DrawClass(Player player, int drawCount, ICardEffect cardEffect)
  1266. {
  1267. _player = player;
  1268. _drawCount = drawCount;
  1269. _cardEffect = cardEffect;
  1270. }
  1271. Player _player = null;
  1272. int _drawCount = 0;
  1273. ICardEffect _cardEffect = null;
  1274. public IEnumerator Draw()
  1275. {
  1276. if (_drawCount <= 0) yield break;
  1277. if (_player.LibraryCards.Count <= 0) yield break;
  1278. List<CardSource> DrawCards = new List<CardSource>();
  1279. for (int i = 0; i < _drawCount; i++)
  1280. {
  1281. if (_player.LibraryCards.Count > 0)
  1282. {
  1283. CardSource DrawCard = _player.LibraryCards[0];
  1284. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(DrawCard));
  1285. DrawCards.Add(DrawCard);
  1286. }
  1287. }
  1288. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(DrawCards, true, _cardEffect));
  1289. #region add log
  1290. if (DrawCards.Count >= 1)
  1291. {
  1292. PlayLog.OnAddLog?.Invoke($"\nDraw {DrawCards.Count} card{Utils.PluralFormSuffix(DrawCards.Count)}\n{_player.PlayerName}\n");
  1293. }
  1294. #endregion
  1295. #region "When draw cards" effect
  1296. if (DrawCards.Count >= 1)
  1297. {
  1298. #region Hashtable setting
  1299. Hashtable _hashtable = new Hashtable()
  1300. {
  1301. {"Player", _player},
  1302. {"CardEffect", _cardEffect}
  1303. };
  1304. #endregion
  1305. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnDraw));
  1306. }
  1307. #endregion
  1308. }
  1309. }
  1310. #endregion
  1311. #region Trash cards from deck too
  1312. public class IAddTrashCardsFromLibraryTop
  1313. {
  1314. public IAddTrashCardsFromLibraryTop(int addTrashCount, Player player, ICardEffect cardEffect)
  1315. {
  1316. _addTrashCount = addTrashCount;
  1317. _player = player;
  1318. _cardEffect = cardEffect;
  1319. }
  1320. public void SetNotShowCards()
  1321. {
  1322. _notShowCards = true;
  1323. }
  1324. int _addTrashCount;
  1325. Player _player;
  1326. public List<CardSource> discardedCards = new List<CardSource>();
  1327. ICardEffect _cardEffect { get; set; } = null;
  1328. bool _notShowCards = false;
  1329. public IEnumerator AddTrashCardsFromLibraryTop()
  1330. {
  1331. if (_addTrashCount <= 0) yield break;
  1332. if (_player.LibraryCards.Count == 0) yield break;
  1333. string log = "";
  1334. log += $"\nTrash cards from deck :";
  1335. for (int i = 0; i < _addTrashCount; i++)
  1336. {
  1337. if (_player.LibraryCards.Count > i)
  1338. {
  1339. CardSource DiscardCard = _player.LibraryCards[i];
  1340. discardedCards.Add(DiscardCard);
  1341. log += $"\n{DiscardCard.BaseENGCardNameFromEntity}({DiscardCard.CardID})";
  1342. }
  1343. }
  1344. if (discardedCards.Count >= 1)
  1345. {
  1346. if (!_notShowCards)
  1347. {
  1348. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  1349. }
  1350. }
  1351. yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(discardedCards, _cardEffect).TrashDeckCards());
  1352. if (discardedCards.Count >= 1)
  1353. {
  1354. for (int i = 0; i < discardedCards.Count; i++)
  1355. {
  1356. ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
  1357. yield return new WaitForSeconds(0.06f);
  1358. }
  1359. log += "\n";
  1360. PlayLog.OnAddLog?.Invoke(log);
  1361. }
  1362. }
  1363. }
  1364. #endregion
  1365. #region Add security from deck top
  1366. public class IAddSecurityFromLibrary
  1367. {
  1368. public IAddSecurityFromLibrary(Player player, int addLifeCount)
  1369. {
  1370. _player = player;
  1371. _addSecurityCount = addLifeCount;
  1372. }
  1373. Player _player = null;
  1374. int _addSecurityCount = 0;
  1375. public IEnumerator AddSecurity()
  1376. {
  1377. int count = 0;
  1378. for (int i = 0; i < _addSecurityCount; i++)
  1379. {
  1380. if (_player.LibraryCards.Count > 0)
  1381. {
  1382. CardSource StockCard = _player.LibraryCards[0];
  1383. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(StockCard));
  1384. count++;
  1385. }
  1386. }
  1387. if (count > 0)
  1388. {
  1389. string log = "";
  1390. log += $"\nAdd {count} cards to security:{_player.PlayerName}";
  1391. log += "\n";
  1392. PlayLog.OnAddLog?.Invoke(log);
  1393. if (GManager.instance.turnStateMachine.DoneStartGame)
  1394. {
  1395. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(_player).AddSecurity());
  1396. }
  1397. }
  1398. }
  1399. }
  1400. #endregion
  1401. #region Recovery
  1402. public class IRecovery
  1403. {
  1404. public IRecovery(Player player, int AddLifeCount, ICardEffect cardEffect)
  1405. {
  1406. _player = player;
  1407. _addLifeCount = AddLifeCount;
  1408. _cardEffect = cardEffect;
  1409. }
  1410. Player _player = null;
  1411. int _addLifeCount = 0;
  1412. ICardEffect _cardEffect = null;
  1413. public IEnumerator Recovery()
  1414. {
  1415. if (_player.LibraryCards.Count == 0) yield break;
  1416. if (_addLifeCount <= 0) yield break;
  1417. if (!_player.CanAddSecurity(_cardEffect)) yield break;
  1418. yield return ContinuousController.instance.StartCoroutine(new IAddSecurityFromLibrary(_player, _addLifeCount).AddSecurity());
  1419. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(_player));
  1420. }
  1421. }
  1422. #endregion
  1423. #region Digi-Burst
  1424. public class IDigiBurst
  1425. {
  1426. public IDigiBurst(Permanent permanent, int DigiBurstCount, ICardEffect cardEffect)
  1427. {
  1428. _permanent = permanent;
  1429. _digiBurstCount = DigiBurstCount;
  1430. _cardEffect = cardEffect;
  1431. }
  1432. Permanent _permanent = null;
  1433. int _digiBurstCount = 0;
  1434. ICardEffect _cardEffect = null;
  1435. bool _upToMaxCount = false;
  1436. public List<CardSource> discardedCards = new List<CardSource>();
  1437. public void SetUpToMaxCount()
  1438. {
  1439. _upToMaxCount = true;
  1440. }
  1441. public bool CanDigiBurst()
  1442. {
  1443. if (_permanent != null)
  1444. {
  1445. if (_permanent.TopCard != null)
  1446. {
  1447. if (_upToMaxCount)
  1448. {
  1449. if (_permanent.DigivolutionCards.Some((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)))
  1450. {
  1451. return true;
  1452. }
  1453. }
  1454. else
  1455. {
  1456. if (_permanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)) >= _digiBurstCount)
  1457. {
  1458. return true;
  1459. }
  1460. }
  1461. }
  1462. }
  1463. return false;
  1464. }
  1465. public IEnumerator DigiBurst()
  1466. {
  1467. if (CanDigiBurst())
  1468. {
  1469. discardedCards = new List<CardSource>();
  1470. List<CardSource> selectedCards = new List<CardSource>();
  1471. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  1472. selectCardEffect.SetUp(
  1473. canTargetCondition: (cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect),
  1474. canTargetCondition_ByPreSelecetedList: null,
  1475. canEndSelectCondition: CanEndSelectCondition,
  1476. canNoSelect: () => false,
  1477. selectCardCoroutine: SelectCardCoroutine,
  1478. afterSelectCardCoroutine: null,
  1479. message: "Select digivolution cards to discard.",
  1480. maxCount: _digiBurstCount,
  1481. canEndNotMax: _upToMaxCount,
  1482. isShowOpponent: true,
  1483. mode: SelectCardEffect.Mode.Custom,
  1484. root: SelectCardEffect.Root.Custom,
  1485. customRootCardList: _permanent.DigivolutionCards,
  1486. canLookReverseCard: true,
  1487. selectPlayer: _permanent.TopCard.Owner,
  1488. cardEffect: null);
  1489. selectCardEffect.SetUpCustomMessage("Select digivolution cards to discard.", "The opponent is selecting digivolution cards to discard.");
  1490. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  1491. bool CanEndSelectCondition(List<CardSource> cardSources)
  1492. {
  1493. if (CardEffectCommons.HasNoElement(cardSources))
  1494. {
  1495. return false;
  1496. }
  1497. return true;
  1498. }
  1499. IEnumerator SelectCardCoroutine(CardSource cardSource)
  1500. {
  1501. selectedCards.Add(cardSource);
  1502. yield return null;
  1503. }
  1504. if (selectedCards.Count >= 1)
  1505. {
  1506. #region "When use Digi-Burst" effect
  1507. #region Hashtable setting
  1508. Hashtable hashtable = new Hashtable()
  1509. {
  1510. {"Permanent", _permanent},
  1511. {"CardEffect", _cardEffect},
  1512. };
  1513. #endregion
  1514. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseDigiburst));
  1515. #endregion
  1516. // trash digivolution cards
  1517. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(_permanent, selectedCards, _cardEffect).TrashDigivolutionCards());
  1518. foreach (CardSource cardSource in selectedCards)
  1519. {
  1520. discardedCards.Add(cardSource);
  1521. }
  1522. #region add log
  1523. if (selectedCards.Count >= 1)
  1524. {
  1525. string log = "";
  1526. log += $"\nDigiburst :";
  1527. foreach (CardSource cardSource in selectedCards)
  1528. {
  1529. if (cardSource != null)
  1530. {
  1531. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  1532. }
  1533. }
  1534. log += "\n";
  1535. PlayLog.OnAddLog?.Invoke(log);
  1536. }
  1537. #endregion
  1538. }
  1539. }
  1540. }
  1541. }
  1542. #endregion
  1543. #region Place permanents to deck bottom
  1544. public class DeckBottomBounceClass
  1545. {
  1546. public DeckBottomBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
  1547. {
  1548. _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
  1549. _hashtable = hashtable;
  1550. }
  1551. public void SetNotShowCards()
  1552. {
  1553. _notShowCards = true;
  1554. }
  1555. public bool IsDeckBounced(Permanent permanent)
  1556. {
  1557. return DeckBouncedPermanents.Contains(permanent);
  1558. }
  1559. List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
  1560. public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
  1561. Hashtable _hashtable = new Hashtable();
  1562. bool _notShowCards = false;
  1563. public IEnumerator DeckBounce()
  1564. {
  1565. if (_deckBounceTargetPermanents == null) yield break;
  1566. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1567. _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
  1568. permanent != null
  1569. && permanent.TopCard != null
  1570. && (cardEffect == null ||
  1571. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1572. && !permanent.CannotReturnToLibrary(cardEffect)
  1573. && permanent.CanBeRemoved())));
  1574. if (_deckBounceTargetPermanents.Count == 0) yield break;
  1575. _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1576. #region cut in effect
  1577. // "When permanents would return to deck" effect
  1578. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1579. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1580. _deckBounceTargetPermanents,
  1581. cardEffect,
  1582. null
  1583. ),
  1584. EffectTiming.WhenReturntoLibraryAnyone));
  1585. // "When permanents would remove field" effect
  1586. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1587. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1588. _deckBounceTargetPermanents,
  1589. cardEffect,
  1590. null
  1591. ),
  1592. EffectTiming.WhenRemoveField));
  1593. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1594. {
  1595. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1596. {
  1597. permanent.ShowDeckBounceEffect();
  1598. }
  1599. // cut in effect process
  1600. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1601. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1602. {
  1603. permanent.HideDeckBounceEffect();
  1604. }
  1605. }
  1606. #endregion
  1607. // fix deck bounce target permanents
  1608. List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
  1609. permanent != null
  1610. && permanent.TopCard != null
  1611. && permanent.willBeRemoveField);
  1612. #region show cards
  1613. List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1614. if (!_notShowCards)
  1615. {
  1616. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
  1617. }
  1618. #endregion
  1619. #region
  1620. List<CardSource> deckBottomCards = new List<CardSource>();
  1621. foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
  1622. {
  1623. #region recoed used effect
  1624. if (permanent.TopCard != null)
  1625. {
  1626. permanent.LibraryBounceEffect = cardEffect;
  1627. }
  1628. #endregion
  1629. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
  1630. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1631. CardSource topCard = permanent.TopCard;
  1632. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1633. deckBottomCards.Add(topCard);
  1634. DeckBouncedPermanents.Add(permanent);
  1635. }
  1636. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(deckBottomCards));
  1637. #endregion
  1638. #region off icon
  1639. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1640. {
  1641. if (permanent != null)
  1642. {
  1643. if (permanent.TopCard != null)
  1644. {
  1645. permanent.willBeRemoveField = false;
  1646. }
  1647. }
  1648. }
  1649. #endregion
  1650. }
  1651. }
  1652. #endregion
  1653. #region Return permanent to hand
  1654. public class HandBounceClaass
  1655. {
  1656. public HandBounceClaass(List<Permanent> bounceTargetPermanents, Hashtable hashtable)
  1657. {
  1658. _bounceTargetPermanents = bounceTargetPermanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  1659. _hashtable = hashtable;
  1660. }
  1661. public bool IsBounced(Permanent permanent)
  1662. {
  1663. return BouncedPermanents.Contains(permanent);
  1664. }
  1665. List<Permanent> _bounceTargetPermanents = new List<Permanent>();
  1666. public List<Permanent> BouncedPermanents { get; private set; } = new List<Permanent>();
  1667. Hashtable _hashtable = new Hashtable();
  1668. bool _notShowCards = false;
  1669. public IEnumerator Bounce()
  1670. {
  1671. if (_bounceTargetPermanents == null) yield break;
  1672. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1673. _bounceTargetPermanents = _bounceTargetPermanents.Filter(permanent =>
  1674. permanent != null
  1675. && permanent.TopCard != null
  1676. && (cardEffect == null ||
  1677. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1678. && !permanent.CannotReturnToHand(cardEffect)
  1679. && permanent.CanBeRemoved())));
  1680. if (_bounceTargetPermanents.Count == 0) yield break;
  1681. _bounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1682. #region cut in effect
  1683. // "When permanents would return to hand" effect
  1684. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1685. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1686. _bounceTargetPermanents,
  1687. cardEffect,
  1688. null
  1689. ),
  1690. EffectTiming.WhenReturntoHandAnyone));
  1691. // "When permanents would remove field" effect
  1692. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1693. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1694. _bounceTargetPermanents,
  1695. cardEffect,
  1696. null
  1697. ),
  1698. EffectTiming.WhenRemoveField));
  1699. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1700. {
  1701. foreach (Permanent permanent in _bounceTargetPermanents)
  1702. {
  1703. permanent.ShowHandBounceEffect();
  1704. }
  1705. // shrink security Digimon display
  1706. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  1707. // cut in effect process
  1708. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1709. foreach (Permanent permanent in _bounceTargetPermanents)
  1710. {
  1711. permanent.HideHandBounceEffect();
  1712. }
  1713. }
  1714. #endregion
  1715. // fix bounce target permanents
  1716. List<Permanent> bounceTargetPermanents_Fixed = _bounceTargetPermanents.Filter(permanent =>
  1717. permanent != null
  1718. && permanent.TopCard != null
  1719. && permanent.willBeRemoveField);
  1720. #region "When permanents returned to hand" effect
  1721. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  1722. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  1723. bounceTargetPermanents_Fixed,
  1724. cardEffect,
  1725. null,
  1726. false
  1727. ),
  1728. EffectTiming.OnPermamemtReturnedToHand));
  1729. #endregion
  1730. #region record parameter just before bounce
  1731. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1732. {
  1733. permanent.DPJustBeforeRemoveField = permanent.DP;
  1734. if (permanent.TopCard.HasLevel)
  1735. {
  1736. permanent.LevelJustBeforeRemoveField = permanent.Level;
  1737. }
  1738. if (permanent.TopCard.HasPlayCost)
  1739. {
  1740. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  1741. }
  1742. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  1743. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  1744. foreach (CardSource cardSource in permanent.cardSources)
  1745. {
  1746. cardSource.PermanentJustBeforeRemoveField = permanent;
  1747. }
  1748. }
  1749. #endregion
  1750. #region add log
  1751. if (bounceTargetPermanents_Fixed.Count >= 1)
  1752. {
  1753. string log = "";
  1754. log += $"\nReturn to hand:";
  1755. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1756. {
  1757. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  1758. }
  1759. log += "\n";
  1760. PlayLog.OnAddLog?.Invoke(log);
  1761. }
  1762. #endregion
  1763. #region show cards
  1764. List<CardSource> returnedCards = bounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1765. if (!_notShowCards)
  1766. {
  1767. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Cards returned to hand", true, true));
  1768. }
  1769. #endregion
  1770. #region return permanent cards to hand
  1771. List<CardSource> handCards = new List<CardSource>();
  1772. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1773. {
  1774. #region record used effect
  1775. if (permanent.TopCard != null)
  1776. {
  1777. permanent.HandBounceEffect = cardEffect;
  1778. }
  1779. #endregion
  1780. // record whether to return to hand by Burst Digivolution
  1781. permanent.IsReturnedToHandByBurstDigivolution = CardEffectCommons.IsBurst(_hashtable);
  1782. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BounceEffect(permanent, !permanent.IsReturnedToHandByBurstDigivolution));
  1783. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1784. CardSource topCard = permanent.TopCard;
  1785. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1786. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(topCard));
  1787. if (!topCard.IsDigiEgg)
  1788. {
  1789. handCards.Add(topCard);
  1790. BouncedPermanents.Add(permanent);
  1791. }
  1792. else
  1793. {
  1794. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  1795. }
  1796. }
  1797. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
  1798. #endregion
  1799. #region hide icon
  1800. foreach (Permanent permanent in _bounceTargetPermanents)
  1801. {
  1802. if (permanent != null)
  1803. {
  1804. if (permanent.TopCard != null)
  1805. {
  1806. permanent.willBeRemoveField = false;
  1807. }
  1808. }
  1809. }
  1810. #endregion
  1811. }
  1812. }
  1813. #endregion
  1814. #region Place permanent to another permanent's digivolution cards
  1815. public class IPlacePermanentToDigivolutionCards
  1816. {
  1817. public IPlacePermanentToDigivolutionCards(
  1818. List<Permanent[]> permanentArrays,
  1819. bool toTop,
  1820. ICardEffect cardEffect,
  1821. bool skipEffectAndActivateSkill = false)
  1822. {
  1823. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  1824. _toTop = toTop;
  1825. _cardEffect = cardEffect;
  1826. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  1827. }
  1828. public void SetNotShowCards()
  1829. {
  1830. _notShowCards = true;
  1831. }
  1832. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  1833. ICardEffect _cardEffect = null;
  1834. bool _toTop = false;
  1835. bool _notShowCards = false;
  1836. bool _skipEffectAndActivateSkill = false;
  1837. public bool Placed { get; private set; } = false;
  1838. public IEnumerator PlacePermanentToDigivolutionCards()
  1839. {
  1840. if (_permanentArrays.Count == 0)
  1841. {
  1842. yield break;
  1843. }
  1844. List<CardSource> addedDigivolutionCards = new List<CardSource>();
  1845. List<Permanent> removeFieldPermanents = new List<Permanent>();
  1846. foreach (Permanent[] permanentArray in _permanentArrays)
  1847. {
  1848. if (permanentArray.Length == 2)
  1849. {
  1850. Permanent DigivolutionPermanent = permanentArray[0];
  1851. Permanent getDigivolutionPermanent = permanentArray[1];
  1852. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  1853. {
  1854. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
  1855. {
  1856. if (_cardEffect != null)
  1857. {
  1858. if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
  1859. {
  1860. continue;
  1861. }
  1862. }
  1863. removeFieldPermanents.Add(DigivolutionPermanent);
  1864. }
  1865. }
  1866. }
  1867. }
  1868. foreach (Permanent permanent in removeFieldPermanents)
  1869. {
  1870. permanent.willBeRemoveField = true;
  1871. }
  1872. if (removeFieldPermanents.Count == 0)
  1873. {
  1874. yield break;
  1875. }
  1876. #region
  1877. List<SkillInfo> skillInfos = new List<SkillInfo>();
  1878. Hashtable hashtable1 =
  1879. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1880. removeFieldPermanents,
  1881. _cardEffect,
  1882. null);
  1883. #region "When permanents would remove field" effect
  1884. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1885. {
  1886. #region permanents' effects
  1887. foreach (Permanent permanent1 in player.GetFieldPermanents())
  1888. {
  1889. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  1890. {
  1891. if (cardEffect is ActivateICardEffect)
  1892. {
  1893. if (cardEffect.CanTrigger(hashtable1))
  1894. {
  1895. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1896. }
  1897. }
  1898. }
  1899. }
  1900. #endregion
  1901. #region players' effects
  1902. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  1903. {
  1904. if (cardEffect is ActivateICardEffect)
  1905. {
  1906. if (cardEffect.CanTrigger(hashtable1))
  1907. {
  1908. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1909. }
  1910. }
  1911. }
  1912. #endregion
  1913. }
  1914. #endregion
  1915. if (skillInfos.Count >= 1)
  1916. {
  1917. foreach (SkillInfo skillInfo in skillInfos)
  1918. {
  1919. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  1920. }
  1921. bool showEffect()
  1922. {
  1923. if (skillInfos.Count >= 2)
  1924. {
  1925. return true;
  1926. }
  1927. else if (skillInfos.Count == 1)
  1928. {
  1929. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  1930. {
  1931. return true;
  1932. }
  1933. }
  1934. return false;
  1935. }
  1936. if (showEffect())
  1937. {
  1938. foreach (Permanent Permanent in removeFieldPermanents)
  1939. {
  1940. if (Permanent != null)
  1941. {
  1942. if (Permanent.TopCard != null)
  1943. {
  1944. if (Permanent.willBeRemoveField)
  1945. {
  1946. if (Permanent.ShowingPermanentCard != null)
  1947. {
  1948. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  1949. {
  1950. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  1951. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  1952. }
  1953. }
  1954. }
  1955. }
  1956. }
  1957. }
  1958. #region shrink security Digimon display
  1959. if (GManager.instance.attackProcess.IsAttacking)
  1960. {
  1961. if (GManager.instance.attackProcess.SecurityDigimon != null)
  1962. {
  1963. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  1964. {
  1965. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  1966. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  1967. }
  1968. }
  1969. }
  1970. #endregion
  1971. }
  1972. // cut in effect process
  1973. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1974. foreach (Permanent Permanent in removeFieldPermanents)
  1975. {
  1976. if (Permanent != null)
  1977. {
  1978. if (Permanent.TopCard != null)
  1979. {
  1980. if (Permanent.ShowingPermanentCard != null)
  1981. {
  1982. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  1983. {
  1984. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  1985. }
  1986. }
  1987. }
  1988. }
  1989. }
  1990. }
  1991. #endregion
  1992. foreach (Permanent[] permanentArray in _permanentArrays)
  1993. {
  1994. if (permanentArray.Length == 2)
  1995. {
  1996. Permanent DigivolutionPermanent = permanentArray[0];
  1997. Permanent getDigivolutionPermanent = permanentArray[1];
  1998. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  1999. {
  2000. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
  2001. {
  2002. yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
  2003. CardSource cardSource = DigivolutionPermanent.TopCard;
  2004. #region record used effect
  2005. if (_cardEffect != null)
  2006. {
  2007. if (DigivolutionPermanent.TopCard != null)
  2008. {
  2009. DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
  2010. }
  2011. }
  2012. #endregion
  2013. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  2014. DigivolutionPermanent,
  2015. ignoreOverflow: true));
  2016. List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
  2017. if (_toTop)
  2018. {
  2019. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
  2020. }
  2021. else
  2022. {
  2023. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
  2024. }
  2025. addedDigivolutionCards.Add(cardSource);
  2026. Placed = true;
  2027. }
  2028. }
  2029. }
  2030. }
  2031. #region add log
  2032. if (addedDigivolutionCards.Count >= 1)
  2033. {
  2034. string log = "";
  2035. log += $"\nPlace in digivolution cards:";
  2036. foreach (CardSource cardSource in addedDigivolutionCards)
  2037. {
  2038. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2039. }
  2040. log += "\n";
  2041. PlayLog.OnAddLog?.Invoke(log);
  2042. }
  2043. #endregion
  2044. #region hide icon
  2045. if (addedDigivolutionCards.Count >= 1)
  2046. {
  2047. if (!_notShowCards)
  2048. {
  2049. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
  2050. }
  2051. }
  2052. #endregion
  2053. }
  2054. }
  2055. #endregion
  2056. #region Place permanents to security
  2057. public class IPutSecurityPermanent
  2058. {
  2059. public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop, bool isFaceup = false)
  2060. {
  2061. _permanent = permanent;
  2062. _hashtable = hashtable;
  2063. _toTop = toTop;
  2064. _isFaceup = isFaceup;
  2065. }
  2066. Permanent _permanent = null;
  2067. Hashtable _hashtable = new Hashtable();
  2068. bool _toTop = false;
  2069. bool _isFaceup = false;
  2070. public IEnumerator PutSecurity()
  2071. {
  2072. if (_permanent == null) yield break;
  2073. if (_permanent.TopCard == null) yield break;
  2074. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2075. if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
  2076. if (!_permanent.CanBeRemoved()) yield break;
  2077. _permanent.willBeRemoveField = true;
  2078. #region "When permanents would remove field" effect
  2079. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2080. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2081. new List<Permanent>() { _permanent },
  2082. cardEffect,
  2083. null
  2084. ),
  2085. EffectTiming.WhenRemoveField));
  2086. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2087. {
  2088. _permanent.ShowWillRemoveFieldEffect();
  2089. //effect
  2090. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2091. // cut in effect process
  2092. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false,null));
  2093. _permanent.HideWillRemoveFieldEffect();
  2094. }
  2095. #endregion
  2096. CardSource topCard = _permanent.TopCard;
  2097. if (!_permanent.willBeRemoveField)
  2098. yield break;
  2099. if (topCard == null)
  2100. yield break;
  2101. #region add log
  2102. string log = "";
  2103. string fromString = _toTop ? "top" : "bottom";
  2104. log += $"\nPut cards on {fromString} of security:";
  2105. log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
  2106. log += "\n";
  2107. PlayLog.OnAddLog?.Invoke(log);
  2108. #endregion
  2109. #region show cards
  2110. if (!topCard.IsToken)
  2111. {
  2112. if (_toTop)
  2113. {
  2114. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
  2115. }
  2116. else
  2117. {
  2118. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
  2119. }
  2120. }
  2121. #endregion
  2122. #region place permanent to security
  2123. yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
  2124. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
  2125. if (!topCard.IsToken)
  2126. {
  2127. if (!topCard.IsDigiEgg)
  2128. {
  2129. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard,faceUp:_isFaceup));
  2130. if (!_isFaceup)
  2131. topCard.SetReverse();
  2132. else
  2133. topCard.SetFace();
  2134. if (!_toTop)
  2135. {
  2136. topCard.Owner.SecurityCards.Remove(topCard);
  2137. topCard.Owner.SecurityCards.Add(topCard);
  2138. }
  2139. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
  2140. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard.Owner).AddSecurity());
  2141. }
  2142. else
  2143. {
  2144. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2145. }
  2146. }
  2147. #endregion
  2148. }
  2149. }
  2150. #endregion
  2151. #region Delete permanents
  2152. public class DestroyPermanentsClass
  2153. {
  2154. public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
  2155. {
  2156. _destroytargetPermanents = destroyTargetPermanents.Clone();
  2157. _hashtable = hashtable;
  2158. _notShowCards = notShowCards;
  2159. }
  2160. public bool IsDestroyed(Permanent permanent)
  2161. {
  2162. return DestroyedPermanents.Contains(permanent);
  2163. }
  2164. List<Permanent> _destroytargetPermanents = new List<Permanent>();
  2165. public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
  2166. Hashtable _hashtable = null;
  2167. bool _notShowCards = false;
  2168. public IEnumerator Destroy()
  2169. {
  2170. if (_destroytargetPermanents == null) yield break;
  2171. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2172. IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
  2173. bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
  2174. _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
  2175. permanent != null
  2176. && permanent.TopCard != null
  2177. && (cardEffect == null ||
  2178. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  2179. && permanent.CanBeDestroyedBySkill(cardEffect))));
  2180. if (_destroytargetPermanents.Count == 0) yield break;
  2181. _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  2182. #region cut in effect
  2183. // "When permanents would be deleted" effect
  2184. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2185. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2186. _destroytargetPermanents,
  2187. cardEffect,
  2188. battle
  2189. ),
  2190. EffectTiming.WhenPermanentWouldBeDeleted));
  2191. // "When permanents would remove field" effect
  2192. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2193. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2194. _destroytargetPermanents,
  2195. cardEffect,
  2196. battle
  2197. ),
  2198. EffectTiming.WhenRemoveField));
  2199. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2200. {
  2201. foreach (Permanent permanent in _destroytargetPermanents)
  2202. {
  2203. permanent.ShowDeleteEffect();
  2204. }
  2205. // effect
  2206. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2207. // cut in effect process
  2208. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2209. foreach (Permanent permanent in _destroytargetPermanents)
  2210. {
  2211. permanent.HideDeleteEffect();
  2212. }
  2213. }
  2214. #endregion
  2215. // fix delete target permanents
  2216. List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
  2217. permanent != null
  2218. && permanent.TopCard != null
  2219. && permanent.willBeRemoveField);
  2220. #region "When permanents are deleted" effect
  2221. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2222. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2223. destroyTargetPermanents_Fixed,
  2224. cardEffect,
  2225. battle,
  2226. isDPZero
  2227. ),
  2228. EffectTiming.OnDestroyedAnyone));
  2229. #endregion
  2230. #region record parameters just before deletion
  2231. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2232. {
  2233. permanent.DPJustBeforeRemoveField = permanent.DP;
  2234. if (permanent.TopCard.HasLevel)
  2235. {
  2236. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2237. }
  2238. if (permanent.TopCard.HasPlayCost)
  2239. {
  2240. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  2241. }
  2242. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  2243. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  2244. foreach (CardSource cardSource in permanent.cardSources)
  2245. {
  2246. cardSource.PermanentJustBeforeRemoveField = permanent;
  2247. }
  2248. }
  2249. #endregion
  2250. #region add log
  2251. if (destroyTargetPermanents_Fixed.Count >= 1)
  2252. {
  2253. string log = "";
  2254. log += $"\nDelete:";
  2255. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2256. {
  2257. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  2258. }
  2259. log += "\n";
  2260. PlayLog.OnAddLog?.Invoke(log);
  2261. }
  2262. #endregion
  2263. #region show cards
  2264. List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2265. if (!_notShowCards)
  2266. {
  2267. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
  2268. }
  2269. #endregion
  2270. #region trash permanent cards
  2271. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2272. {
  2273. #region record wheter to be deleted by battle
  2274. if (battle != null)
  2275. {
  2276. if (permanent.TopCard != null)
  2277. {
  2278. if(CardEffectCommons.GetLoserPermanentsFromHashtable(battle.hashtable).Contains(permanent))
  2279. permanent.IsDestroyedByBattle = true;
  2280. }
  2281. }
  2282. #endregion
  2283. #region record used effect
  2284. if (permanent.TopCard != null)
  2285. {
  2286. permanent.DestroyingEffect = cardEffect;
  2287. }
  2288. #endregion
  2289. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
  2290. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2291. CardSource topCard = permanent.TopCard;
  2292. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2293. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
  2294. DestroyedPermanents.Add(permanent);
  2295. }
  2296. #endregion
  2297. #region hide icon
  2298. foreach (Permanent permanent in _destroytargetPermanents)
  2299. {
  2300. if (permanent != null)
  2301. {
  2302. if (permanent.TopCard != null)
  2303. {
  2304. permanent.willBeRemoveField = false;
  2305. }
  2306. }
  2307. }
  2308. #endregion
  2309. }
  2310. }
  2311. #endregion
  2312. #region Security check
  2313. public class ISecurityCheck
  2314. {
  2315. public ISecurityCheck(Permanent AttackingPermanent, Player player)
  2316. {
  2317. this.AttackingPermanent = AttackingPermanent;
  2318. this.player = player;
  2319. }
  2320. Permanent AttackingPermanent { get; set; }
  2321. Player player { get; set; }
  2322. public IEnumerator SecurityCheck()
  2323. {
  2324. bool StopSecurityCheck()
  2325. {
  2326. if (AttackingPermanent == null)
  2327. {
  2328. return true;
  2329. }
  2330. if (AttackingPermanent.TopCard == null)
  2331. {
  2332. return true;
  2333. }
  2334. if (!AttackingPermanent.IsDigimon)
  2335. return true;
  2336. return false;
  2337. }
  2338. if (!StopSecurityCheck())
  2339. {
  2340. if (AttackingPermanent.Strike == 0)
  2341. {
  2342. yield break;
  2343. }
  2344. GManager.instance.turnStateMachine.IsSelecting = true;
  2345. GManager.instance.turnStateMachine.isSecurityCehck = true;
  2346. #region loop while there are 1 or more security cards
  2347. if (player.SecurityCards.Count >= 1)
  2348. {
  2349. int checkedCount = 0;
  2350. while (true)
  2351. {
  2352. if (StopSecurityCheck())
  2353. {
  2354. break;
  2355. }
  2356. if (checkedCount >= AttackingPermanent.Strike)
  2357. {
  2358. break;
  2359. }
  2360. if (player.SecurityCards.Count >= 1)
  2361. {
  2362. List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
  2363. CardSource brokenSecurityCard = player.SecurityCards[0];
  2364. Hashtable hashtable = new Hashtable()
  2365. {
  2366. {"AttackingPermanent", AttackingPermanent},
  2367. {"Card", brokenSecurityCard}
  2368. };
  2369. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
  2370. {
  2371. triggeredSkillInfos.Add(skillInfo);
  2372. }
  2373. checkedCount++;
  2374. PlayLog.OnAddLog?.Invoke($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
  2375. if (brokenSecurityCard.IsDigimon)
  2376. {
  2377. GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
  2378. }
  2379. #region effect
  2380. player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2381. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
  2382. yield return new WaitForSeconds(0.1f);
  2383. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
  2384. #endregion
  2385. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
  2386. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2387. player: brokenSecurityCard.Owner,
  2388. refSkillInfos: ref triggeredSkillInfos).ReduceSecurity());
  2389. #region security effect
  2390. List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
  2391. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
  2392. {
  2393. if (cardEffect is ActivateICardEffect)
  2394. {
  2395. Hashtable hashtable1 = new Hashtable();
  2396. hashtable1.Add("Card", brokenSecurityCard);
  2397. if (cardEffect.CanUse(hashtable1))
  2398. {
  2399. secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
  2400. }
  2401. }
  2402. }
  2403. List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
  2404. bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
  2405. if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
  2406. {
  2407. if (!brokenSecurityCard.IsDigimon)
  2408. {
  2409. yield return new WaitForSeconds(0.3f);
  2410. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2411. }
  2412. }
  2413. else
  2414. {
  2415. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
  2416. yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
  2417. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2418. foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
  2419. {
  2420. skillInfos.Add(skillInfo);
  2421. }
  2422. List<CardSource> cardSources = new List<CardSource>();
  2423. for (int j = 0; j < skillInfos.Count; j++)
  2424. {
  2425. cardSources.Add(brokenSecurityCard);
  2426. }
  2427. while (skillInfos.Count >= 1)
  2428. {
  2429. SkillInfo selectedSkillInfo = null;
  2430. if (skillInfos.Count == 1)
  2431. {
  2432. selectedSkillInfo = skillInfos[0];
  2433. }
  2434. else
  2435. {
  2436. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  2437. selectCardEffect.SetUp(
  2438. canTargetCondition: (cardSource) => true,
  2439. canTargetCondition_ByPreSelecetedList: null,
  2440. canEndSelectCondition: null,
  2441. canNoSelect: () => false,
  2442. selectCardCoroutine: null,
  2443. afterSelectCardCoroutine: null,
  2444. message: "select security effect",
  2445. maxCount: 1,
  2446. canEndNotMax: false,
  2447. isShowOpponent: false,
  2448. mode: SelectCardEffect.Mode.Custom,
  2449. root: SelectCardEffect.Root.Custom,
  2450. customRootCardList: cardSources,
  2451. canLookReverseCard: true,
  2452. selectPlayer: player,
  2453. cardEffect: null);
  2454. selectCardEffect.SetUpSkillInfos(skillInfos);
  2455. selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
  2456. selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  2457. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  2458. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  2459. {
  2460. if (selectedIndexes.Count == 1)
  2461. {
  2462. selectedSkillInfo = skillInfos[selectedIndexes[0]];
  2463. yield return null;
  2464. }
  2465. }
  2466. }
  2467. if (selectedSkillInfo != null)
  2468. {
  2469. ICardEffect cardEffect = selectedSkillInfo.CardEffect;
  2470. Hashtable hashtable2 = selectedSkillInfo.Hashtable;
  2471. if (cardEffect.EffectSourceCard == brokenSecurityCard)
  2472. {
  2473. if (cardEffect is ActivateICardEffect)
  2474. {
  2475. skillInfos.Remove(selectedSkillInfo);
  2476. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  2477. cardEffect,
  2478. hashtable2));
  2479. }
  2480. }
  2481. }
  2482. }
  2483. }
  2484. #endregion
  2485. // auto process check
  2486. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2487. // stack effect of "When cards are removed from security" and "checks secuirty"
  2488. foreach (SkillInfo skillInfo in triggeredSkillInfos)
  2489. {
  2490. GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
  2491. }
  2492. // auto process check
  2493. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2494. if (!StopSecurityCheck())
  2495. {
  2496. #region battle with security Digimon
  2497. if (brokenSecurityCard.IsDigimon)
  2498. {
  2499. bool doBattle = true;
  2500. #region "ignore battle" effect
  2501. Hashtable hashtable3 = new Hashtable()
  2502. {
  2503. {"Card", brokenSecurityCard}
  2504. };
  2505. #region the security Digimon's effect
  2506. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
  2507. {
  2508. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2509. {
  2510. if (cardEffect.CanUse(hashtable3))
  2511. {
  2512. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2513. {
  2514. doBattle = false;
  2515. }
  2516. }
  2517. }
  2518. }
  2519. #endregion
  2520. #region player's effect
  2521. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2522. {
  2523. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2524. {
  2525. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2526. {
  2527. if (cardEffect.CanUse(hashtable3))
  2528. {
  2529. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2530. {
  2531. doBattle = false;
  2532. }
  2533. }
  2534. }
  2535. }
  2536. }
  2537. #endregion
  2538. #endregion
  2539. if (doBattle)
  2540. {
  2541. yield return new WaitForSeconds(0.3f);
  2542. yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
  2543. }
  2544. }
  2545. #endregion
  2546. }
  2547. #region effect
  2548. yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
  2549. if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
  2550. {
  2551. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
  2552. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
  2553. {
  2554. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2555. }
  2556. }
  2557. GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
  2558. GManager.instance.attackProcess.SecurityDigimon = null;
  2559. #endregion
  2560. // reset effect until end of security check
  2561. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2562. {
  2563. player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2564. }
  2565. // auto process check
  2566. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2567. GManager.instance.turnStateMachine.IsSelecting = true;
  2568. }
  2569. else
  2570. {
  2571. break;
  2572. }
  2573. }
  2574. }
  2575. #endregion
  2576. GManager.instance.turnStateMachine.isSecurityCehck = false;
  2577. }
  2578. }
  2579. }
  2580. #endregion
  2581. #region trash cards from security
  2582. public class IDestroySecurity
  2583. {
  2584. public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
  2585. {
  2586. _player = player;
  2587. _destroySecurityCount = destroySecurityCount;
  2588. _cardEffect = cardEffect;
  2589. _fromTop = fromTop;
  2590. }
  2591. Player _player = null;
  2592. int _destroySecurityCount = 0;
  2593. ICardEffect _cardEffect = null;
  2594. bool _fromTop = false;
  2595. public IEnumerator DestroySecurity()
  2596. {
  2597. bool StopDestroySecurity()
  2598. {
  2599. if (_player.SecurityCards.Count == 0)
  2600. {
  2601. return true;
  2602. }
  2603. if (!_player.CanReduceSecurity())
  2604. {
  2605. return true;
  2606. }
  2607. return false;
  2608. }
  2609. if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
  2610. {
  2611. int count = 0;
  2612. List<CardSource> discardedCards = new List<CardSource>();
  2613. while (true)
  2614. {
  2615. if (StopDestroySecurity())
  2616. {
  2617. break;
  2618. }
  2619. if (count >= _destroySecurityCount)
  2620. {
  2621. break;
  2622. }
  2623. if (_player.SecurityCards.Count >= 1)
  2624. {
  2625. count++;
  2626. CardSource destroyedSecurityCard = _player.SecurityCards[0];
  2627. if (!_fromTop)
  2628. {
  2629. destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
  2630. }
  2631. discardedCards.Add(destroyedSecurityCard);
  2632. #region effect
  2633. _player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2634. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
  2635. yield return new WaitForSeconds(0.1f);
  2636. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
  2637. yield return new WaitForSeconds(0.5f);
  2638. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
  2639. #endregion
  2640. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
  2641. }
  2642. }
  2643. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  2644. if (discardedCards.Count >= 1)
  2645. {
  2646. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2647. player: _player,
  2648. refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
  2649. cardEffect: _cardEffect).ReduceSecurity());
  2650. #region "When security cards are trashed" effect
  2651. #region Hashtable setting
  2652. Hashtable hashtable = new Hashtable()
  2653. {
  2654. {"DiscardedCards", discardedCards},
  2655. {"CardEffect", _cardEffect},
  2656. };
  2657. #endregion
  2658. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
  2659. #endregion
  2660. }
  2661. #region add log
  2662. if (discardedCards.Count >= 1)
  2663. {
  2664. string log = "";
  2665. string fromString = _fromTop ? "Top" : "Bottom";
  2666. log += $"\nDiscarded From {fromString} Security Cards:";
  2667. foreach (CardSource cardSource in discardedCards)
  2668. {
  2669. if (cardSource != null)
  2670. {
  2671. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2672. }
  2673. }
  2674. log += "\n";
  2675. PlayLog.OnAddLog?.Invoke(log);
  2676. }
  2677. #endregion
  2678. }
  2679. }
  2680. }
  2681. #endregion
  2682. #region Battle
  2683. public class IBattle
  2684. {
  2685. public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard)
  2686. {
  2687. this.AttackingPermanent = AttackingPermanent;
  2688. this.DefendingPermanent = DefendingPermanent;
  2689. this.DefendingCard = DefendingCard;
  2690. }
  2691. public Permanent AttackingPermanent { get; private set; } = null;
  2692. public Permanent DefendingPermanent { get; private set; } = null;
  2693. CardSource DefendingCard { get; set; } = null;
  2694. public Hashtable hashtable { get; set; } = new Hashtable();
  2695. public Permanent enemyPermanent(Permanent permanent)
  2696. {
  2697. if (permanent != null)
  2698. {
  2699. if (permanent == AttackingPermanent)
  2700. {
  2701. return DefendingPermanent;
  2702. }
  2703. else if (permanent == DefendingPermanent)
  2704. {
  2705. return AttackingPermanent;
  2706. }
  2707. }
  2708. return null;
  2709. }
  2710. public int CompareStats()
  2711. {
  2712. int statCheck = 0;
  2713. if(AttackingPermanent.HasIceclad || DefendingPermanent.HasIceclad)
  2714. statCheck = AttackingPermanent.DigivolutionCards.Count - DefendingPermanent.DigivolutionCards.Count;
  2715. else
  2716. statCheck = AttackingPermanent.DP - DefendingPermanent.DP;
  2717. statCheck = Mathf.Clamp(statCheck, -1, 1);
  2718. return statCheck;
  2719. }
  2720. public IEnumerator Battle()
  2721. {
  2722. hashtable = new Hashtable();
  2723. if (AttackingPermanent != null)
  2724. {
  2725. bool IsExistingDefender()
  2726. {
  2727. // whether defender exists
  2728. if ((DefendingPermanent == null) != (DefendingCard == null))
  2729. {
  2730. if (DefendingPermanent != null)
  2731. {
  2732. if (DefendingPermanent.TopCard != null)
  2733. {
  2734. return true;
  2735. }
  2736. }
  2737. else if (DefendingCard != null)
  2738. {
  2739. return true;
  2740. }
  2741. }
  2742. return false;
  2743. }
  2744. if (IsExistingDefender())
  2745. {
  2746. if (AttackingPermanent != null)
  2747. {
  2748. AttackingPermanent.battle = this;
  2749. }
  2750. if (DefendingPermanent != null)
  2751. {
  2752. DefendingPermanent.battle = this;
  2753. }
  2754. List<Permanent> WinnerPermanents = new List<Permanent>();
  2755. List<Permanent> LoserPermanents = new List<Permanent>();
  2756. CardSource LoserCard = null;
  2757. //add log
  2758. string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
  2759. if (DefendingPermanent != null)
  2760. {
  2761. log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
  2762. }
  2763. else if (DefendingCard != null)
  2764. {
  2765. log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
  2766. }
  2767. PlayLog.OnAddLog?.Invoke(log);
  2768. #region "At the start of battle" effect
  2769. Permanent _AttackingPermanent = null;
  2770. Permanent _DefendingPermanent = null;
  2771. if (AttackingPermanent != null)
  2772. {
  2773. if (AttackingPermanent.TopCard != null)
  2774. {
  2775. _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
  2776. }
  2777. }
  2778. if (DefendingPermanent != null)
  2779. {
  2780. if (DefendingPermanent.TopCard != null)
  2781. {
  2782. _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
  2783. }
  2784. }
  2785. hashtable.Add("AttackingPermanent", _AttackingPermanent);
  2786. hashtable.Add("DefendingPermanent", _DefendingPermanent);
  2787. hashtable.Add("DefendingCard", DefendingCard);
  2788. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
  2789. #endregion
  2790. #region Show effect
  2791. bool ShowEffect()
  2792. {
  2793. if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
  2794. {
  2795. return true;
  2796. }
  2797. else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
  2798. {
  2799. if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
  2800. {
  2801. return true;
  2802. }
  2803. }
  2804. return false;
  2805. }
  2806. if (ShowEffect())
  2807. {
  2808. if (GManager.instance.attackProcess.IsAttacking)
  2809. {
  2810. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2811. {
  2812. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2813. {
  2814. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2815. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2816. }
  2817. }
  2818. }
  2819. }
  2820. #endregion
  2821. // auto process check
  2822. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2823. GManager.instance.turnStateMachine.IsSelecting = true;
  2824. //Preemptive end battle if the attack process is ended
  2825. if(GManager.instance.attackProcess.IsEndAttack)
  2826. yield break;
  2827. #region battle with permanent
  2828. if (DefendingPermanent != null)
  2829. {
  2830. int battleResults = CompareStats();
  2831. if (battleResults == 1)
  2832. {
  2833. WinnerPermanents.Add(AttackingPermanent);
  2834. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2835. LoserPermanents.Add(DefendingPermanent);
  2836. }
  2837. else if (battleResults == 0)
  2838. {
  2839. WinnerPermanents.Add(AttackingPermanent);
  2840. WinnerPermanents.Add(DefendingPermanent);
  2841. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2842. LoserPermanents.Add(AttackingPermanent);
  2843. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2844. LoserPermanents.Add(DefendingPermanent);
  2845. }
  2846. else if (battleResults == -1)
  2847. {
  2848. WinnerPermanents.Add(DefendingPermanent);
  2849. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2850. LoserPermanents.Add(AttackingPermanent);
  2851. }
  2852. }
  2853. #endregion
  2854. #region battle with card
  2855. else if (DefendingCard != null)
  2856. {
  2857. if (AttackingPermanent.DP > DefendingCard.CardDP)
  2858. {
  2859. WinnerPermanents.Add(AttackingPermanent);
  2860. LoserCard = DefendingCard;
  2861. }
  2862. else if (AttackingPermanent.DP == DefendingCard.CardDP)
  2863. {
  2864. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2865. {
  2866. LoserPermanents.Add(AttackingPermanent);
  2867. }
  2868. LoserCard = DefendingCard;
  2869. }
  2870. else if (AttackingPermanent.DP < DefendingCard.CardDP)
  2871. {
  2872. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2873. {
  2874. LoserPermanents.Add(AttackingPermanent);
  2875. }
  2876. }
  2877. }
  2878. #endregion
  2879. List<Permanent> _WinnerPermanents = new List<Permanent>();
  2880. List<Permanent> _LoserPermanents = new List<Permanent>();
  2881. foreach (Permanent permanent in WinnerPermanents)
  2882. {
  2883. if (permanent.TopCard != null)
  2884. {
  2885. _WinnerPermanents.Add(new Permanent(permanent.cardSources));
  2886. }
  2887. }
  2888. foreach (Permanent permanent in LoserPermanents)
  2889. {
  2890. if (permanent.TopCard != null)
  2891. {
  2892. _LoserPermanents.Add(new Permanent(permanent.cardSources));
  2893. }
  2894. }
  2895. hashtable.Add("WinnerPermanents", _WinnerPermanents);
  2896. hashtable.Add("WinnerPermanents_real", WinnerPermanents);
  2897. hashtable.Add("LoserPermanents", _LoserPermanents);
  2898. hashtable.Add("LoserPermanents_real", LoserPermanents);
  2899. hashtable.Add("LoserCard", LoserCard);
  2900. hashtable.Add("battle", this);
  2901. // battle effect
  2902. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
  2903. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(LoserPermanents, hashtable).Destroy());
  2904. //Fix winner/loser permanents
  2905. int index = -1;
  2906. foreach (Permanent permanent in LoserPermanents)
  2907. {
  2908. if (permanent.TopCard != null)
  2909. {
  2910. index = LoserPermanents.IndexOf(permanent);
  2911. }
  2912. }
  2913. if (index >= 0)
  2914. {
  2915. LoserPermanents.RemoveAt(index);
  2916. _LoserPermanents.RemoveAt(index);
  2917. hashtable["LoserPermanents"] = _LoserPermanents;
  2918. hashtable["LoserPermanents_real"] = LoserPermanents;
  2919. }
  2920. //LoserPermanents = LoserPermanents.Filter(permanent => permanent.TopCard != null);
  2921. //_LoserPermanents = _LoserPermanents.Filter(permanent => permanent.TopCard != null);
  2922. //hashtable["LoserPermanents"] = _LoserPermanents;
  2923. //hashtable["LoserPermanents_real"] = LoserPermanents;
  2924. // "At the end of battle" effect
  2925. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
  2926. #region move up effect
  2927. if (ShowEffect())
  2928. {
  2929. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
  2930. }
  2931. #endregion
  2932. #region effect when determine whether to do security check
  2933. List<SkillInfo> skillInfos_Pierce = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnDetermineDoSecurityCheck)
  2934. .Filter(skillInfo => skillInfo.CardEffect != null && skillInfo.CardEffect.CanActivate(skillInfo.Hashtable));
  2935. if (skillInfos_Pierce.Count >= 1)
  2936. {
  2937. GManager.instance.autoProcessing.PutStackedSkill(skillInfos_Pierce[0]);
  2938. }
  2939. #endregion
  2940. }
  2941. }
  2942. // auto process check
  2943. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2944. #region reset effect until the end of battle
  2945. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2946. {
  2947. foreach (Permanent permanent in player.GetFieldPermanents())
  2948. {
  2949. permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  2950. }
  2951. player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  2952. }
  2953. #endregion
  2954. if (AttackingPermanent != null)
  2955. {
  2956. AttackingPermanent.battle = null;
  2957. }
  2958. if (DefendingPermanent != null)
  2959. {
  2960. DefendingPermanent.battle = null;
  2961. }
  2962. }
  2963. }
  2964. #endregion
  2965. #region De-digivolve
  2966. public class IDegeneration
  2967. {
  2968. public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect)
  2969. {
  2970. _permanent = permanent;
  2971. _degenerationCount = DegenerationCount;
  2972. _cardEffect = cardEffect;
  2973. }
  2974. Permanent _permanent = null;
  2975. int _degenerationCount = 0;
  2976. ICardEffect _cardEffect = null;
  2977. public IEnumerator Degeneration()
  2978. {
  2979. if (_cardEffect == null) yield break;
  2980. if (_cardEffect.EffectSourceCard == null) yield break;
  2981. if (_permanent == null) yield break;
  2982. if (_permanent.TopCard == null) yield break;
  2983. if (_permanent.ImmuneFromDeDigivolve()) yield break;
  2984. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  2985. int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
  2986. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  2987. if (selectCountEffect != null)
  2988. {
  2989. Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
  2990. selectCountEffect.SetUp(
  2991. SelectPlayer: selectPlayer,
  2992. targetPermanent: _permanent,
  2993. MaxCount: maxCount,
  2994. CanNoSelect: false,
  2995. Message: "How many cards do you trash?",
  2996. Message_Enemy: "The opponent is choosing how many cards to trash.",
  2997. SelectCountCoroutine: SelectCountCoroutine);
  2998. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  2999. IEnumerator SelectCountCoroutine(int count)
  3000. {
  3001. _degenerationCount = count;
  3002. yield return null;
  3003. }
  3004. }
  3005. if (_degenerationCount >= 1)
  3006. {
  3007. int count = 0;
  3008. List<CardSource> selectedCards = new List<CardSource>();
  3009. while (true)
  3010. {
  3011. bool StopCondition()
  3012. {
  3013. if (_permanent.HasNoDigivolutionCards)
  3014. {
  3015. return true;
  3016. }
  3017. if (_permanent.Level == 3)
  3018. {
  3019. if (_permanent.TopCard != null)
  3020. {
  3021. if (_permanent.TopCard.HasLevel)
  3022. {
  3023. return true;
  3024. }
  3025. }
  3026. }
  3027. if (count >= _degenerationCount)
  3028. {
  3029. return true;
  3030. }
  3031. return false;
  3032. }
  3033. if (StopCondition())
  3034. {
  3035. break;
  3036. }
  3037. if (count == 0)
  3038. {
  3039. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3040. }
  3041. CardSource cardSource = _permanent.TopCard;
  3042. selectedCards.Add(cardSource);
  3043. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  3044. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3045. if (!cardSource.IsToken)
  3046. {
  3047. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3048. }
  3049. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  3050. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3051. count++;
  3052. }
  3053. #region add log
  3054. if (selectedCards.Count >= 1)
  3055. {
  3056. string log = "";
  3057. log += $"\nDe-Digivolve :";
  3058. foreach (CardSource cardSource in selectedCards)
  3059. {
  3060. if (cardSource != null)
  3061. {
  3062. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3063. }
  3064. }
  3065. log += "\n";
  3066. PlayLog.OnAddLog?.Invoke(log);
  3067. }
  3068. #endregion
  3069. }
  3070. }
  3071. }
  3072. #endregion
  3073. #region Trash digivolution cards
  3074. public class ITrashDigivolutionCards
  3075. {
  3076. public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  3077. {
  3078. _permanent = permanent;
  3079. _trashTargetCards = trashTargetCards.Clone();
  3080. _cardEffect = cardEffect;
  3081. }
  3082. Permanent _permanent = null;
  3083. List<CardSource> _trashTargetCards = new List<CardSource>();
  3084. ICardEffect _cardEffect = null;
  3085. public IEnumerator TrashDigivolutionCards()
  3086. {
  3087. if (_trashTargetCards == null) yield break;
  3088. if (_cardEffect == null) yield break;
  3089. if (_permanent == null) yield break;
  3090. if (_permanent.TopCard == null) yield break;
  3091. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3092. if (_permanent.HasNoDigivolutionCards) yield break;
  3093. _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
  3094. _permanent.DigivolutionCards.Contains(cardSource) &&
  3095. !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
  3096. if (_trashTargetCards.Count == 0) yield break;
  3097. _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
  3098. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  3099. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  3100. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3101. #region cut in effect - Would discard
  3102. // "When digivolution cards would be trashed" effect
  3103. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  3104. CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
  3105. _permanent,
  3106. _trashTargetCards,
  3107. _cardEffect
  3108. ),
  3109. EffectTiming.WhenWouldDigivolutionCardDiscarded));
  3110. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  3111. {
  3112. // effect
  3113. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  3114. // cut in effect process
  3115. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3116. }
  3117. #endregion
  3118. //fix trash target permanent
  3119. Permanent permanentTarget_Fixed = _permanent;
  3120. // fix trash sources sources
  3121. List<CardSource> trashDigivolutionCards_Fixed = _trashTargetCards.Filter(cardsource =>
  3122. cardsource != null
  3123. && cardsource.willBeRemoveSources);
  3124. #region "When digivolution cards are trashed" effect
  3125. #region Hashtable Setting
  3126. Hashtable hashtable = new Hashtable()
  3127. {
  3128. {"CardEffect", _cardEffect},
  3129. {"Permanent", permanentTarget_Fixed},
  3130. {"DiscardedCards", trashDigivolutionCards_Fixed},
  3131. };
  3132. #endregion
  3133. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
  3134. #endregion
  3135. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  3136. foreach (CardSource cardSource in trashDigivolutionCards_Fixed)
  3137. {
  3138. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
  3139. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3140. if (!cardSource.IsToken)
  3141. {
  3142. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3143. }
  3144. cardSource.willBeRemoveSources = false;
  3145. }
  3146. }
  3147. }
  3148. #endregion
  3149. #region Return digivolution cards to deck bottom
  3150. public class ReturnToLibraryBottomDigivolutionCardsClass
  3151. {
  3152. public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
  3153. {
  3154. _permanent = permanent;
  3155. _cardSources = cardSources.Clone();
  3156. _hashtable = hashtable;
  3157. }
  3158. Permanent _permanent = null;
  3159. List<CardSource> _cardSources = new List<CardSource>();
  3160. Hashtable _hashtable = null;
  3161. public IEnumerator ReturnToLibraryBottomDigivolutionCards()
  3162. {
  3163. if (_permanent == null) yield break;
  3164. if (_permanent.TopCard == null) yield break;
  3165. if (_cardSources == null) yield break;
  3166. _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
  3167. if (_cardSources.Count == 0) yield break;
  3168. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3169. if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
  3170. string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
  3171. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
  3172. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3173. #region "When digivolution cards are returned to deck" effect
  3174. #region Hashtable Setting
  3175. Hashtable hashtable1 = new Hashtable()
  3176. {
  3177. {"Permanent", _permanent},
  3178. {"DeckBottomCards", _cardSources},
  3179. {"CardEffect", CardEffect},
  3180. };
  3181. #endregion
  3182. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
  3183. #endregion
  3184. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
  3185. }
  3186. }
  3187. #endregion
  3188. #region Reduce security
  3189. public class IReduceSecurity
  3190. {
  3191. public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos, ICardEffect cardEffect = null)
  3192. {
  3193. _player = player;
  3194. _refSkillInfos = refSkillInfos;
  3195. _cardEffect = cardEffect;
  3196. }
  3197. Player _player = null;
  3198. List<SkillInfo> _refSkillInfos = null;
  3199. ICardEffect _cardEffect = null;
  3200. public IEnumerator ReduceSecurity()
  3201. {
  3202. #region "When cards are removed from security" effect
  3203. #region Hashtable Setting
  3204. Hashtable hashtable = new Hashtable()
  3205. {
  3206. {"Player", _player},
  3207. {"SkillInfo",_refSkillInfos },
  3208. {"CardEffect",_cardEffect}
  3209. };
  3210. #endregion
  3211. if (_refSkillInfos == null)
  3212. {
  3213. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
  3214. }
  3215. else
  3216. {
  3217. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
  3218. {
  3219. _refSkillInfos.Add(skillInfo);
  3220. }
  3221. }
  3222. #endregion
  3223. }
  3224. }
  3225. #endregion
  3226. #region Add Security
  3227. public class IAddSecurity
  3228. {
  3229. public IAddSecurity(Player player)
  3230. {
  3231. _player = player;
  3232. }
  3233. Player _player { get; set; }
  3234. public IEnumerator AddSecurity()
  3235. {
  3236. #region "When security cards are added" effect
  3237. #region Hashtable setting
  3238. Hashtable hashtable = new Hashtable()
  3239. {
  3240. {"Player", _player}
  3241. };
  3242. #endregion
  3243. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
  3244. #endregion
  3245. }
  3246. }
  3247. #endregion
  3248. #region Suspend permanents
  3249. public class SuspendPermanentsClass
  3250. {
  3251. public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
  3252. {
  3253. _permanents = permanents;
  3254. _hashtable = hashtable;
  3255. }
  3256. List<Permanent> _permanents { get; set; }
  3257. Hashtable _hashtable { get; set; }
  3258. public IEnumerator Tap()
  3259. {
  3260. if (_permanents.Count == 0) yield break;
  3261. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3262. bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
  3263. bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
  3264. List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
  3265. bool PermanentCondition(Permanent permanent)
  3266. {
  3267. if (permanent != null)
  3268. {
  3269. if (permanent.TopCard != null)
  3270. {
  3271. if (permanent.IsSuspended)
  3272. {
  3273. return false;
  3274. }
  3275. if (!permanent.CanSuspend)
  3276. {
  3277. return false;
  3278. }
  3279. if (CardEffect != null)
  3280. {
  3281. if (permanent.TopCard.CanNotBeAffected(CardEffect))
  3282. {
  3283. return false;
  3284. }
  3285. }
  3286. }
  3287. }
  3288. return true;
  3289. }
  3290. foreach (Permanent permanent in suspendTargetPermanents)
  3291. {
  3292. permanent.IsSuspended = true;
  3293. GManager.OnCardSuspendedChanged?.Invoke(true);
  3294. permanent.DPWhenSuspended = permanent.DP;
  3295. if (permanent.ShowingPermanentCard != null)
  3296. {
  3297. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3298. }
  3299. }
  3300. if (suspendTargetPermanents.Count >= 1)
  3301. {
  3302. #region "Effects when permanents suspend
  3303. #region Hashtable Setting
  3304. Hashtable _hashtable = new Hashtable(){
  3305. {"Permanents", suspendTargetPermanents},
  3306. {"IsBlock", IsBlock}
  3307. };
  3308. if (CardEffect != null)
  3309. {
  3310. _hashtable.Add("CardEffect", CardEffect);
  3311. }
  3312. #endregion
  3313. if (IsAttack) yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3314. else yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3315. #endregion
  3316. yield return new WaitForSeconds(0.3f);
  3317. }
  3318. }
  3319. }
  3320. #endregion
  3321. #region Unsuspend permanents
  3322. public class IUnsuspendPermanents
  3323. {
  3324. public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
  3325. {
  3326. _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  3327. _cardEffect = cardEffect;
  3328. }
  3329. List<Permanent> _permanents { get; set; }
  3330. ICardEffect _cardEffect { get; set; }
  3331. public IEnumerator Unsuspend()
  3332. {
  3333. //Permanent list that will unsuspend
  3334. List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
  3335. permanent != null
  3336. && permanent.TopCard != null
  3337. && permanent.IsSuspended
  3338. && permanent.CanUnsuspend
  3339. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3340. #region "When permanents would unsuspend" effect
  3341. #region Hashtable Setting
  3342. Hashtable hashtable1 = new Hashtable()
  3343. {
  3344. {"CardEffect", _cardEffect},
  3345. {"Permanents", untappedPermanets},
  3346. };
  3347. #endregion
  3348. List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
  3349. if (skillInfos.Count >= 1)
  3350. {
  3351. foreach (SkillInfo skillInfo in skillInfos)
  3352. {
  3353. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  3354. }
  3355. foreach (Permanent permanent in untappedPermanets)
  3356. {
  3357. permanent.ShowUnsuspendEffect();
  3358. }
  3359. //cut in effects
  3360. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3361. untappedPermanets.ForEach(permanent =>
  3362. {
  3363. if (permanent.ShowingPermanentCard != null)
  3364. {
  3365. permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
  3366. }
  3367. });
  3368. }
  3369. #endregion
  3370. // fix unsuspend target permanents
  3371. List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
  3372. permanent != null
  3373. && permanent.TopCard != null
  3374. && permanent.IsSuspended
  3375. && permanent.CanUnsuspend
  3376. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3377. if (untappedPermanets_Fixed.Count >= 1)
  3378. {
  3379. foreach (Permanent permanent in untappedPermanets_Fixed)
  3380. {
  3381. permanent.IsSuspended = false;
  3382. if (permanent.ShowingPermanentCard != null)
  3383. {
  3384. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3385. }
  3386. }
  3387. #region "When permanents are unsuspended" effect
  3388. #region Hashtable Setting
  3389. Hashtable hashtable2 = new Hashtable()
  3390. {
  3391. {"CardEffect", _cardEffect},
  3392. {"Permanents", untappedPermanets_Fixed},
  3393. };
  3394. #endregion
  3395. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
  3396. #endregion
  3397. yield return new WaitForSeconds(0.3f);
  3398. }
  3399. foreach (Permanent permanent in untappedPermanets)
  3400. {
  3401. permanent.UntilNextUntapEffects = new List<Func<EffectTiming, ICardEffect>>();
  3402. }
  3403. }
  3404. }
  3405. #endregion
  3406. #region Trash cards from deck top
  3407. public class ITrashDeckCards
  3408. {
  3409. public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
  3410. {
  3411. this.cardSources = new List<CardSource>();
  3412. foreach (CardSource cardSource in cardSources)
  3413. {
  3414. this.cardSources.Add(cardSource);
  3415. }
  3416. this.cardEffect = cardEffect;
  3417. }
  3418. List<CardSource> cardSources { get; set; } = new List<CardSource>();
  3419. ICardEffect cardEffect { get; set; } = null;
  3420. public IEnumerator TrashDeckCards()
  3421. {
  3422. List<CardSource> trashCards = new List<CardSource>();
  3423. foreach (CardSource cardSource in cardSources)
  3424. {
  3425. if (cardSource.Owner.LibraryCards.Contains(cardSource))
  3426. {
  3427. trashCards.Add(cardSource);
  3428. }
  3429. }
  3430. if (trashCards.Count >= 1)
  3431. {
  3432. foreach (CardSource cardSource in trashCards)
  3433. {
  3434. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3435. }
  3436. #region "When cards are trashed from security" effect
  3437. #region Hashtable setting
  3438. Hashtable hashtable = new Hashtable()
  3439. {
  3440. {"DiscardedCards", trashCards},
  3441. {"CardEffect", cardEffect},
  3442. };
  3443. #endregion
  3444. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  3445. hashtable, EffectTiming.OnDiscardLibrary));
  3446. #endregion
  3447. }
  3448. }
  3449. }
  3450. #endregion
  3451. #region Overflow of ace
  3452. public class AceOverflowClass
  3453. {
  3454. public AceOverflowClass(List<CardSource> cardSources)
  3455. {
  3456. _cardSources = cardSources.Clone();
  3457. }
  3458. List<CardSource> _cardSources = new List<CardSource>();
  3459. public IEnumerator Overflow()
  3460. {
  3461. _cardSources = _cardSources
  3462. .Filter(cardSource => cardSource.IsACE && CardEffectCommons.IsExistOnBattleArea(cardSource) || CardEffectCommons.IsExistOnBreedingAreaDigimon(cardSource))
  3463. .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
  3464. .ToList();
  3465. foreach (CardSource cardSource in _cardSources)
  3466. {
  3467. yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
  3468. string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
  3469. PlayLog.OnAddLog?.Invoke(log);
  3470. }
  3471. }
  3472. }
  3473. #endregion