CardController.cs 154 KB

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