CardController.cs 151 KB

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