CardController.cs 152 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206
  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)
  1560. && !permanent.CannotReturnToLibrary(cardEffect)
  1561. && !permanent.CanBeRemoved())));
  1562. if (_deckBounceTargetPermanents.Count == 0) yield break;
  1563. _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1564. #region cut in effect
  1565. // "When permanents would return to deck" effect
  1566. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1567. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1568. _deckBounceTargetPermanents,
  1569. cardEffect,
  1570. null
  1571. ),
  1572. EffectTiming.WhenReturntoLibraryAnyone));
  1573. // "When permanents would remove field" effect
  1574. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1575. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1576. _deckBounceTargetPermanents,
  1577. cardEffect,
  1578. null
  1579. ),
  1580. EffectTiming.WhenRemoveField));
  1581. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1582. {
  1583. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1584. {
  1585. permanent.ShowDeckBounceEffect();
  1586. }
  1587. // cut in effect process
  1588. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  1589. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1590. {
  1591. permanent.HideDeckBounceEffect();
  1592. }
  1593. }
  1594. #endregion
  1595. // fix deck bounce target permanents
  1596. List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
  1597. permanent != null
  1598. && permanent.TopCard != null
  1599. && permanent.willBeRemoveField);
  1600. #region show cards
  1601. List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1602. if (!_notShowCards)
  1603. {
  1604. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
  1605. }
  1606. #endregion
  1607. #region
  1608. List<CardSource> deckBottomCards = new List<CardSource>();
  1609. foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
  1610. {
  1611. #region recoed used effect
  1612. if (permanent.TopCard != null)
  1613. {
  1614. permanent.LibraryBounceEffect = cardEffect;
  1615. }
  1616. #endregion
  1617. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
  1618. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1619. CardSource topCard = permanent.TopCard;
  1620. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1621. deckBottomCards.Add(topCard);
  1622. DeckBouncedPermanents.Add(permanent);
  1623. }
  1624. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(deckBottomCards));
  1625. #endregion
  1626. #region off icon
  1627. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1628. {
  1629. if (permanent != null)
  1630. {
  1631. if (permanent.TopCard != null)
  1632. {
  1633. permanent.willBeRemoveField = false;
  1634. }
  1635. }
  1636. }
  1637. #endregion
  1638. }
  1639. }
  1640. #endregion
  1641. #region Return permanent to hand
  1642. public class HandBounceClaass
  1643. {
  1644. public HandBounceClaass(List<Permanent> bounceTargetPermanents, Hashtable hashtable)
  1645. {
  1646. _bounceTargetPermanents = bounceTargetPermanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  1647. _hashtable = hashtable;
  1648. }
  1649. public bool IsBounced(Permanent permanent)
  1650. {
  1651. return BouncedPermanents.Contains(permanent);
  1652. }
  1653. List<Permanent> _bounceTargetPermanents = new List<Permanent>();
  1654. public List<Permanent> BouncedPermanents { get; private set; } = new List<Permanent>();
  1655. Hashtable _hashtable = new Hashtable();
  1656. bool _notShowCards = false;
  1657. public IEnumerator Bounce()
  1658. {
  1659. if (_bounceTargetPermanents == null) yield break;
  1660. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1661. _bounceTargetPermanents = _bounceTargetPermanents.Filter(permanent =>
  1662. permanent != null
  1663. && permanent.TopCard != null
  1664. && (cardEffect == null ||
  1665. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1666. && !permanent.CannotReturnToHand(cardEffect)
  1667. && !permanent.CanBeRemoved())));
  1668. if (_bounceTargetPermanents.Count == 0) yield break;
  1669. _bounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1670. #region cut in effect
  1671. // "When permanents would return to hand" effect
  1672. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1673. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1674. _bounceTargetPermanents,
  1675. cardEffect,
  1676. null
  1677. ),
  1678. EffectTiming.WhenReturntoHandAnyone));
  1679. // "When permanents would remove field" effect
  1680. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1681. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1682. _bounceTargetPermanents,
  1683. cardEffect,
  1684. null
  1685. ),
  1686. EffectTiming.WhenRemoveField));
  1687. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1688. {
  1689. foreach (Permanent permanent in _bounceTargetPermanents)
  1690. {
  1691. permanent.ShowHandBounceEffect();
  1692. }
  1693. // shrink security Digimon display
  1694. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  1695. // cut in effect process
  1696. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  1697. foreach (Permanent permanent in _bounceTargetPermanents)
  1698. {
  1699. permanent.HideHandBounceEffect();
  1700. }
  1701. }
  1702. #endregion
  1703. // fix bounce target permanents
  1704. List<Permanent> bounceTargetPermanents_Fixed = _bounceTargetPermanents.Filter(permanent =>
  1705. permanent != null
  1706. && permanent.TopCard != null
  1707. && permanent.willBeRemoveField);
  1708. #region "When permanents returned to hand" effect
  1709. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  1710. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  1711. bounceTargetPermanents_Fixed,
  1712. cardEffect,
  1713. null,
  1714. false
  1715. ),
  1716. EffectTiming.OnPermamemtReturnedToHand));
  1717. #endregion
  1718. #region record parameter just before bounce
  1719. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1720. {
  1721. permanent.DPJustBeforeRemoveField = permanent.DP;
  1722. if (permanent.TopCard.HasLevel)
  1723. {
  1724. permanent.LevelJustBeforeRemoveField = permanent.Level;
  1725. }
  1726. if (permanent.TopCard.HasPlayCost)
  1727. {
  1728. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  1729. }
  1730. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  1731. foreach (CardSource cardSource in permanent.cardSources)
  1732. {
  1733. cardSource.PermanentJustBeforeRemoveField = permanent;
  1734. }
  1735. }
  1736. #endregion
  1737. #region add log
  1738. if (bounceTargetPermanents_Fixed.Count >= 1)
  1739. {
  1740. string log = "";
  1741. log += $"\nReturn to hand:";
  1742. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1743. {
  1744. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  1745. }
  1746. log += "\n";
  1747. GManager.instance.playLog.AddLogString(log);
  1748. }
  1749. #endregion
  1750. #region show cards
  1751. List<CardSource> returnedCards = bounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1752. if (!_notShowCards)
  1753. {
  1754. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Cards returned to hand", true, true));
  1755. }
  1756. #endregion
  1757. #region return permanent cards to hand
  1758. List<CardSource> handCards = new List<CardSource>();
  1759. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1760. {
  1761. #region record used effect
  1762. if (permanent.TopCard != null)
  1763. {
  1764. permanent.HandBounceEffect = cardEffect;
  1765. }
  1766. #endregion
  1767. // record whether to return to hand by Burst Digivolution
  1768. permanent.IsReturnedToHandByBurstDigivolution = CardEffectCommons.IsBurst(_hashtable);
  1769. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BounceEffect(permanent, !permanent.IsReturnedToHandByBurstDigivolution));
  1770. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1771. CardSource topCard = permanent.TopCard;
  1772. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1773. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(topCard));
  1774. if (!topCard.IsDigiEgg)
  1775. {
  1776. handCards.Add(topCard);
  1777. BouncedPermanents.Add(permanent);
  1778. }
  1779. else
  1780. {
  1781. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  1782. }
  1783. }
  1784. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
  1785. #endregion
  1786. #region hide icon
  1787. foreach (Permanent permanent in _bounceTargetPermanents)
  1788. {
  1789. if (permanent != null)
  1790. {
  1791. if (permanent.TopCard != null)
  1792. {
  1793. permanent.willBeRemoveField = false;
  1794. }
  1795. }
  1796. }
  1797. #endregion
  1798. }
  1799. }
  1800. #endregion
  1801. #region Place permanent to another permanent's digivolution cards
  1802. public class IPlacePermanentToDigivolutionCards
  1803. {
  1804. public IPlacePermanentToDigivolutionCards(
  1805. List<Permanent[]> permanentArrays,
  1806. bool toTop,
  1807. ICardEffect cardEffect,
  1808. bool skipEffectAndActivateSkill = false)
  1809. {
  1810. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  1811. _toTop = toTop;
  1812. _cardEffect = cardEffect;
  1813. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  1814. }
  1815. public void SetNotShowCards()
  1816. {
  1817. _notShowCards = true;
  1818. }
  1819. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  1820. ICardEffect _cardEffect = null;
  1821. bool _toTop = false;
  1822. bool _notShowCards = false;
  1823. bool _skipEffectAndActivateSkill = false;
  1824. public bool Placed { get; private set; } = false;
  1825. public IEnumerator PlacePermanentToDigivolutionCards()
  1826. {
  1827. if (_permanentArrays.Count == 0)
  1828. {
  1829. yield break;
  1830. }
  1831. List<CardSource> addedDigivolutionCards = new List<CardSource>();
  1832. List<Permanent> removeFieldPermanents = new List<Permanent>();
  1833. foreach (Permanent[] permanentArray in _permanentArrays)
  1834. {
  1835. if (permanentArray.Length == 2)
  1836. {
  1837. Permanent DigivolutionPermanent = permanentArray[0];
  1838. Permanent getDigivolutionPermanent = permanentArray[1];
  1839. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  1840. {
  1841. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
  1842. {
  1843. if (_cardEffect != null)
  1844. {
  1845. if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
  1846. {
  1847. continue;
  1848. }
  1849. }
  1850. removeFieldPermanents.Add(DigivolutionPermanent);
  1851. }
  1852. }
  1853. }
  1854. }
  1855. foreach (Permanent permanent in removeFieldPermanents)
  1856. {
  1857. permanent.willBeRemoveField = true;
  1858. }
  1859. if (removeFieldPermanents.Count == 0)
  1860. {
  1861. yield break;
  1862. }
  1863. #region
  1864. List<SkillInfo> skillInfos = new List<SkillInfo>();
  1865. Hashtable hashtable1 =
  1866. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1867. removeFieldPermanents,
  1868. _cardEffect,
  1869. null);
  1870. #region "When permanents would remove field" effect
  1871. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1872. {
  1873. #region permanents' effects
  1874. foreach (Permanent permanent1 in player.GetFieldPermanents())
  1875. {
  1876. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  1877. {
  1878. if (cardEffect is ActivateICardEffect)
  1879. {
  1880. if (cardEffect.CanTrigger(hashtable1))
  1881. {
  1882. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1883. }
  1884. }
  1885. }
  1886. }
  1887. #endregion
  1888. #region players' effects
  1889. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  1890. {
  1891. if (cardEffect is ActivateICardEffect)
  1892. {
  1893. if (cardEffect.CanTrigger(hashtable1))
  1894. {
  1895. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1896. }
  1897. }
  1898. }
  1899. #endregion
  1900. }
  1901. #endregion
  1902. if (skillInfos.Count >= 1)
  1903. {
  1904. foreach (SkillInfo skillInfo in skillInfos)
  1905. {
  1906. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  1907. }
  1908. bool showEffect()
  1909. {
  1910. if (skillInfos.Count >= 2)
  1911. {
  1912. return true;
  1913. }
  1914. else if (skillInfos.Count == 1)
  1915. {
  1916. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  1917. {
  1918. return true;
  1919. }
  1920. }
  1921. return false;
  1922. }
  1923. if (showEffect())
  1924. {
  1925. foreach (Permanent Permanent in removeFieldPermanents)
  1926. {
  1927. if (Permanent != null)
  1928. {
  1929. if (Permanent.TopCard != null)
  1930. {
  1931. if (Permanent.willBeRemoveField)
  1932. {
  1933. if (Permanent.ShowingPermanentCard != null)
  1934. {
  1935. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  1936. {
  1937. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  1938. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  1939. }
  1940. }
  1941. }
  1942. }
  1943. }
  1944. }
  1945. #region shrink security Digimon display
  1946. if (GManager.instance.attackProcess.IsAttacking)
  1947. {
  1948. if (GManager.instance.attackProcess.SecurityDigimon != null)
  1949. {
  1950. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  1951. {
  1952. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  1953. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  1954. }
  1955. }
  1956. }
  1957. #endregion
  1958. }
  1959. // cut in effect process
  1960. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  1961. foreach (Permanent Permanent in removeFieldPermanents)
  1962. {
  1963. if (Permanent != null)
  1964. {
  1965. if (Permanent.TopCard != null)
  1966. {
  1967. if (Permanent.ShowingPermanentCard != null)
  1968. {
  1969. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  1970. {
  1971. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  1972. }
  1973. }
  1974. }
  1975. }
  1976. }
  1977. }
  1978. #endregion
  1979. foreach (Permanent[] permanentArray in _permanentArrays)
  1980. {
  1981. if (permanentArray.Length == 2)
  1982. {
  1983. Permanent DigivolutionPermanent = permanentArray[0];
  1984. Permanent getDigivolutionPermanent = permanentArray[1];
  1985. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  1986. {
  1987. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
  1988. {
  1989. yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
  1990. CardSource cardSource = DigivolutionPermanent.TopCard;
  1991. #region record used effect
  1992. if (_cardEffect != null)
  1993. {
  1994. if (DigivolutionPermanent.TopCard != null)
  1995. {
  1996. DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
  1997. }
  1998. }
  1999. #endregion
  2000. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  2001. DigivolutionPermanent,
  2002. ignoreOverflow: true));
  2003. List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
  2004. if (_toTop)
  2005. {
  2006. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
  2007. }
  2008. else
  2009. {
  2010. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
  2011. }
  2012. addedDigivolutionCards.Add(cardSource);
  2013. Placed = true;
  2014. }
  2015. }
  2016. }
  2017. }
  2018. #region add log
  2019. if (addedDigivolutionCards.Count >= 1)
  2020. {
  2021. string log = "";
  2022. log += $"\nPlace in digivolution cards:";
  2023. foreach (CardSource cardSource in addedDigivolutionCards)
  2024. {
  2025. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2026. }
  2027. log += "\n";
  2028. GManager.instance.playLog.AddLogString(log);
  2029. }
  2030. #endregion
  2031. #region hide icon
  2032. if (addedDigivolutionCards.Count >= 1)
  2033. {
  2034. if (!_notShowCards)
  2035. {
  2036. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
  2037. }
  2038. }
  2039. #endregion
  2040. }
  2041. }
  2042. #endregion
  2043. #region Place permanents to security
  2044. public class IPutSecurityPermanent
  2045. {
  2046. public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop)
  2047. {
  2048. _permanent = permanent;
  2049. _hashtable = hashtable;
  2050. _toTop = toTop;
  2051. }
  2052. Permanent _permanent = null;
  2053. Hashtable _hashtable = new Hashtable();
  2054. bool _toTop = false;
  2055. public IEnumerator PutSecurity()
  2056. {
  2057. if (_permanent == null) yield break;
  2058. if (_permanent.TopCard == null) yield break;
  2059. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2060. if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
  2061. #region "When permanents would remove field" effect
  2062. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2063. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2064. new List<Permanent>() { _permanent },
  2065. cardEffect,
  2066. null
  2067. ),
  2068. EffectTiming.WhenRemoveField));
  2069. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2070. {
  2071. _permanent.ShowWillRemoveFieldEffect();
  2072. //effect
  2073. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2074. // cut in effect process
  2075. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  2076. _permanent.HideWillRemoveFieldEffect();
  2077. }
  2078. #endregion
  2079. CardSource topCard = _permanent.TopCard;
  2080. if (!_permanent.willBeRemoveField)
  2081. yield break;
  2082. if (topCard == null)
  2083. yield break;
  2084. #region add log
  2085. string log = "";
  2086. log += $"\nPut cards on top of security:";
  2087. log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
  2088. log += "\n";
  2089. GManager.instance.playLog.AddLogString(log);
  2090. #endregion
  2091. #region show cards
  2092. if (!topCard.IsToken)
  2093. {
  2094. if (_toTop)
  2095. {
  2096. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
  2097. }
  2098. else
  2099. {
  2100. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
  2101. }
  2102. }
  2103. #endregion
  2104. #region place permanent to security
  2105. yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
  2106. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
  2107. if (!topCard.IsToken)
  2108. {
  2109. if (!topCard.IsDigiEgg)
  2110. {
  2111. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard));
  2112. if (!_toTop)
  2113. {
  2114. topCard.Owner.SecurityCards.Remove(topCard);
  2115. topCard.Owner.SecurityCards.Add(topCard);
  2116. }
  2117. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
  2118. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard.Owner).AddSecurity());
  2119. }
  2120. else
  2121. {
  2122. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2123. }
  2124. }
  2125. #endregion
  2126. }
  2127. }
  2128. #endregion
  2129. #region Delete permanents
  2130. public class DestroyPermanentsClass
  2131. {
  2132. public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
  2133. {
  2134. _destroytargetPermanents = destroyTargetPermanents.Clone();
  2135. _hashtable = hashtable;
  2136. _notShowCards = notShowCards;
  2137. }
  2138. public bool IsDestroyed(Permanent permanent)
  2139. {
  2140. return DestroyedPermanents.Contains(permanent);
  2141. }
  2142. List<Permanent> _destroytargetPermanents = new List<Permanent>();
  2143. public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
  2144. Hashtable _hashtable = null;
  2145. bool _notShowCards = false;
  2146. public IEnumerator Destroy()
  2147. {
  2148. if (_destroytargetPermanents == null) yield break;
  2149. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2150. IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
  2151. bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
  2152. _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
  2153. permanent != null
  2154. && permanent.TopCard != null
  2155. && (cardEffect == null ||
  2156. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  2157. && permanent.CanBeDestroyedBySkill(cardEffect)
  2158. && permanent.CanBeRemoved())));
  2159. if (_destroytargetPermanents.Count == 0) yield break;
  2160. _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  2161. #region cut in effect
  2162. // "When permanents would be deleted" effect
  2163. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2164. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2165. _destroytargetPermanents,
  2166. cardEffect,
  2167. battle
  2168. ),
  2169. EffectTiming.WhenPermanentWouldBeDeleted));
  2170. // "When permanents would remove field" effect
  2171. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2172. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2173. _destroytargetPermanents,
  2174. cardEffect,
  2175. battle
  2176. ),
  2177. EffectTiming.WhenRemoveField));
  2178. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2179. {
  2180. foreach (Permanent permanent in _destroytargetPermanents)
  2181. {
  2182. permanent.ShowDeleteEffect();
  2183. }
  2184. // effect
  2185. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2186. // cut in effect process
  2187. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  2188. foreach (Permanent permanent in _destroytargetPermanents)
  2189. {
  2190. permanent.HideDeleteEffect();
  2191. }
  2192. }
  2193. #endregion
  2194. // fix delete target permanents
  2195. List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
  2196. permanent != null
  2197. && permanent.TopCard != null
  2198. && permanent.willBeRemoveField);
  2199. #region "When permanents are deleted" effect
  2200. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2201. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2202. destroyTargetPermanents_Fixed,
  2203. cardEffect,
  2204. battle,
  2205. isDPZero
  2206. ),
  2207. EffectTiming.OnDestroyedAnyone));
  2208. #endregion
  2209. #region record parameters just before deletion
  2210. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2211. {
  2212. permanent.DPJustBeforeRemoveField = permanent.DP;
  2213. if (permanent.TopCard.HasLevel)
  2214. {
  2215. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2216. }
  2217. if (permanent.TopCard.HasPlayCost)
  2218. {
  2219. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  2220. }
  2221. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  2222. foreach (CardSource cardSource in permanent.cardSources)
  2223. {
  2224. cardSource.PermanentJustBeforeRemoveField = permanent;
  2225. }
  2226. }
  2227. #endregion
  2228. #region add log
  2229. if (destroyTargetPermanents_Fixed.Count >= 1)
  2230. {
  2231. string log = "";
  2232. log += $"\nDelete:";
  2233. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2234. {
  2235. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  2236. }
  2237. log += "\n";
  2238. GManager.instance.playLog.AddLogString(log);
  2239. }
  2240. #endregion
  2241. #region show cards
  2242. List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2243. if (!_notShowCards)
  2244. {
  2245. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
  2246. }
  2247. #endregion
  2248. #region trash permanent cards
  2249. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2250. {
  2251. #region record wheter to be deleted by battle
  2252. if (battle != null)
  2253. {
  2254. if (permanent.TopCard != null)
  2255. {
  2256. permanent.IsDestroyedByBattle = true;
  2257. }
  2258. }
  2259. #endregion
  2260. #region record used effect
  2261. if (permanent.TopCard != null)
  2262. {
  2263. permanent.DestroyingEffect = cardEffect;
  2264. }
  2265. #endregion
  2266. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
  2267. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2268. CardSource topCard = permanent.TopCard;
  2269. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2270. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
  2271. DestroyedPermanents.Add(permanent);
  2272. }
  2273. #endregion
  2274. #region hide icon
  2275. foreach (Permanent permanent in _destroytargetPermanents)
  2276. {
  2277. if (permanent != null)
  2278. {
  2279. if (permanent.TopCard != null)
  2280. {
  2281. permanent.willBeRemoveField = false;
  2282. }
  2283. }
  2284. }
  2285. #endregion
  2286. }
  2287. }
  2288. #endregion
  2289. #region Security check
  2290. public class ISecurityCheck
  2291. {
  2292. public ISecurityCheck(Permanent AttackingPermanent, Player player)
  2293. {
  2294. this.AttackingPermanent = AttackingPermanent;
  2295. this.player = player;
  2296. }
  2297. Permanent AttackingPermanent { get; set; }
  2298. Player player { get; set; }
  2299. public IEnumerator SecurityCheck()
  2300. {
  2301. bool StopSecurityCheck()
  2302. {
  2303. if (AttackingPermanent == null)
  2304. {
  2305. return true;
  2306. }
  2307. if (AttackingPermanent.TopCard == null)
  2308. {
  2309. return true;
  2310. }
  2311. return false;
  2312. }
  2313. if (!StopSecurityCheck())
  2314. {
  2315. if (AttackingPermanent.Strike == 0)
  2316. {
  2317. yield break;
  2318. }
  2319. GManager.instance.turnStateMachine.IsSelecting = true;
  2320. GManager.instance.turnStateMachine.isSecurityCehck = true;
  2321. #region loop while there are 1 or more security cards
  2322. if (player.SecurityCards.Count >= 1)
  2323. {
  2324. int checkedCount = 0;
  2325. while (true)
  2326. {
  2327. if (StopSecurityCheck())
  2328. {
  2329. break;
  2330. }
  2331. if (checkedCount >= AttackingPermanent.Strike)
  2332. {
  2333. break;
  2334. }
  2335. if (player.SecurityCards.Count >= 1)
  2336. {
  2337. List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
  2338. CardSource brokenSecurityCard = player.SecurityCards[0];
  2339. Hashtable hashtable = new Hashtable()
  2340. {
  2341. {"AttackingPermanent", AttackingPermanent},
  2342. {"Card", brokenSecurityCard}
  2343. };
  2344. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
  2345. {
  2346. triggeredSkillInfos.Add(skillInfo);
  2347. }
  2348. checkedCount++;
  2349. GManager.instance.playLog.AddLogString($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
  2350. if (brokenSecurityCard.IsDigimon)
  2351. {
  2352. GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
  2353. }
  2354. #region effect
  2355. player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2356. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
  2357. yield return new WaitForSeconds(0.1f);
  2358. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
  2359. #endregion
  2360. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2361. player: brokenSecurityCard.Owner,
  2362. refSkillInfos: ref triggeredSkillInfos).ReduceSecurity());
  2363. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
  2364. #region security effect
  2365. List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
  2366. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
  2367. {
  2368. if (cardEffect is ActivateICardEffect)
  2369. {
  2370. Hashtable hashtable1 = new Hashtable();
  2371. hashtable1.Add("Card", brokenSecurityCard);
  2372. if (cardEffect.CanUse(hashtable1))
  2373. {
  2374. secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
  2375. }
  2376. }
  2377. }
  2378. List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
  2379. bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
  2380. if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
  2381. {
  2382. if (!brokenSecurityCard.IsDigimon)
  2383. {
  2384. yield return new WaitForSeconds(0.3f);
  2385. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2386. }
  2387. }
  2388. else
  2389. {
  2390. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
  2391. yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
  2392. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2393. foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
  2394. {
  2395. skillInfos.Add(skillInfo);
  2396. }
  2397. List<CardSource> cardSources = new List<CardSource>();
  2398. for (int j = 0; j < skillInfos.Count; j++)
  2399. {
  2400. cardSources.Add(brokenSecurityCard);
  2401. }
  2402. while (skillInfos.Count >= 1)
  2403. {
  2404. SkillInfo selectedSkillInfo = null;
  2405. if (skillInfos.Count == 1)
  2406. {
  2407. selectedSkillInfo = skillInfos[0];
  2408. }
  2409. else
  2410. {
  2411. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  2412. selectCardEffect.SetUp(
  2413. canTargetCondition: (cardSource) => true,
  2414. canTargetCondition_ByPreSelecetedList: null,
  2415. canEndSelectCondition: null,
  2416. canNoSelect: () => false,
  2417. selectCardCoroutine: null,
  2418. afterSelectCardCoroutine: null,
  2419. message: "select security effect",
  2420. maxCount: 1,
  2421. canEndNotMax: false,
  2422. isShowOpponent: false,
  2423. mode: SelectCardEffect.Mode.Custom,
  2424. root: SelectCardEffect.Root.Custom,
  2425. customRootCardList: cardSources,
  2426. canLookReverseCard: true,
  2427. selectPlayer: player,
  2428. cardEffect: null);
  2429. selectCardEffect.SetUpSkillInfos(skillInfos);
  2430. selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
  2431. selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  2432. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  2433. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  2434. {
  2435. if (selectedIndexes.Count == 1)
  2436. {
  2437. selectedSkillInfo = skillInfos[selectedIndexes[0]];
  2438. yield return null;
  2439. }
  2440. }
  2441. }
  2442. if (selectedSkillInfo != null)
  2443. {
  2444. ICardEffect cardEffect = selectedSkillInfo.CardEffect;
  2445. Hashtable hashtable2 = selectedSkillInfo.Hashtable;
  2446. if (cardEffect.EffectSourceCard == brokenSecurityCard)
  2447. {
  2448. if (cardEffect is ActivateICardEffect)
  2449. {
  2450. skillInfos.Remove(selectedSkillInfo);
  2451. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  2452. cardEffect,
  2453. hashtable2));
  2454. }
  2455. }
  2456. }
  2457. }
  2458. }
  2459. #endregion
  2460. // auto process check
  2461. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2462. // stack effect of "When cards are removed from security" and "checks secuirty"
  2463. foreach (SkillInfo skillInfo in triggeredSkillInfos)
  2464. {
  2465. GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
  2466. }
  2467. // auto process check
  2468. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2469. if (!StopSecurityCheck())
  2470. {
  2471. #region battle with security Digimon
  2472. if (brokenSecurityCard.IsDigimon)
  2473. {
  2474. bool doBattle = true;
  2475. #region "ignore battle" effect
  2476. Hashtable hashtable3 = new Hashtable()
  2477. {
  2478. {"Card", brokenSecurityCard}
  2479. };
  2480. #region the security Digimon's effect
  2481. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
  2482. {
  2483. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2484. {
  2485. if (cardEffect.CanUse(hashtable3))
  2486. {
  2487. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2488. {
  2489. doBattle = false;
  2490. }
  2491. }
  2492. }
  2493. }
  2494. #endregion
  2495. #region player's effect
  2496. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2497. {
  2498. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2499. {
  2500. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2501. {
  2502. if (cardEffect.CanUse(hashtable3))
  2503. {
  2504. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2505. {
  2506. doBattle = false;
  2507. }
  2508. }
  2509. }
  2510. }
  2511. }
  2512. #endregion
  2513. #endregion
  2514. if (doBattle)
  2515. {
  2516. yield return new WaitForSeconds(0.3f);
  2517. yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
  2518. }
  2519. }
  2520. #endregion
  2521. }
  2522. #region effect
  2523. yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
  2524. if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
  2525. {
  2526. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
  2527. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
  2528. {
  2529. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2530. }
  2531. }
  2532. GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
  2533. GManager.instance.attackProcess.SecurityDigimon = null;
  2534. #endregion
  2535. // reset effect until end of security check
  2536. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2537. {
  2538. player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2539. }
  2540. // auto process check
  2541. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2542. GManager.instance.turnStateMachine.IsSelecting = true;
  2543. }
  2544. else
  2545. {
  2546. break;
  2547. }
  2548. }
  2549. }
  2550. #endregion
  2551. GManager.instance.turnStateMachine.isSecurityCehck = false;
  2552. }
  2553. }
  2554. }
  2555. #endregion
  2556. #region trash cards from security
  2557. public class IDestroySecurity
  2558. {
  2559. public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
  2560. {
  2561. _player = player;
  2562. _destroySecurityCount = destroySecurityCount;
  2563. _cardEffect = cardEffect;
  2564. _fromTop = fromTop;
  2565. }
  2566. Player _player = null;
  2567. int _destroySecurityCount = 0;
  2568. ICardEffect _cardEffect = null;
  2569. bool _fromTop = false;
  2570. public IEnumerator DestroySecurity()
  2571. {
  2572. bool StopDestroySecurity()
  2573. {
  2574. if (_player.SecurityCards.Count == 0)
  2575. {
  2576. return true;
  2577. }
  2578. if (!_player.CanReduceSecurity())
  2579. {
  2580. return true;
  2581. }
  2582. return false;
  2583. }
  2584. if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
  2585. {
  2586. int count = 0;
  2587. List<CardSource> discardedCards = new List<CardSource>();
  2588. while (true)
  2589. {
  2590. if (StopDestroySecurity())
  2591. {
  2592. break;
  2593. }
  2594. if (count >= _destroySecurityCount)
  2595. {
  2596. break;
  2597. }
  2598. if (_player.SecurityCards.Count >= 1)
  2599. {
  2600. count++;
  2601. CardSource destroyedSecurityCard = _player.SecurityCards[0];
  2602. if (!_fromTop)
  2603. {
  2604. destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
  2605. }
  2606. discardedCards.Add(destroyedSecurityCard);
  2607. #region effect
  2608. _player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2609. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
  2610. yield return new WaitForSeconds(0.1f);
  2611. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
  2612. yield return new WaitForSeconds(0.5f);
  2613. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
  2614. #endregion
  2615. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
  2616. }
  2617. }
  2618. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  2619. if (discardedCards.Count >= 1)
  2620. {
  2621. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2622. player: _player,
  2623. refSkillInfos: ref ContinuousController.instance.nullSkillInfos).ReduceSecurity());
  2624. }
  2625. if (discardedCards.Count >= 1)
  2626. {
  2627. #region "When security cards are trashed" effect
  2628. #region Hashtable setting
  2629. Hashtable hashtable = new Hashtable()
  2630. {
  2631. {"DiscardedCards", discardedCards},
  2632. {"CardEffect", _cardEffect},
  2633. };
  2634. #endregion
  2635. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
  2636. #endregion
  2637. }
  2638. #region add log
  2639. if (discardedCards.Count >= 1)
  2640. {
  2641. string log = "";
  2642. log += $"\nDiscarded Security Cards:";
  2643. foreach (CardSource cardSource in discardedCards)
  2644. {
  2645. if (cardSource != null)
  2646. {
  2647. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2648. }
  2649. }
  2650. log += "\n";
  2651. GManager.instance.playLog.AddLogString(log);
  2652. }
  2653. #endregion
  2654. }
  2655. }
  2656. }
  2657. #endregion
  2658. #region Battle
  2659. public class IBattle
  2660. {
  2661. public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard)
  2662. {
  2663. this.AttackingPermanent = AttackingPermanent;
  2664. this.DefendingPermanent = DefendingPermanent;
  2665. this.DefendingCard = DefendingCard;
  2666. }
  2667. public Permanent AttackingPermanent { get; private set; } = null;
  2668. public Permanent DefendingPermanent { get; private set; } = null;
  2669. CardSource DefendingCard { get; set; } = null;
  2670. public Hashtable hashtable { get; set; } = new Hashtable();
  2671. public Permanent enemyPermanent(Permanent permanent)
  2672. {
  2673. if (permanent != null)
  2674. {
  2675. if (permanent == AttackingPermanent)
  2676. {
  2677. return DefendingPermanent;
  2678. }
  2679. else if (permanent == DefendingPermanent)
  2680. {
  2681. return AttackingPermanent;
  2682. }
  2683. }
  2684. return null;
  2685. }
  2686. public IEnumerator Battle()
  2687. {
  2688. hashtable = new Hashtable();
  2689. if (AttackingPermanent != null)
  2690. {
  2691. bool IsExistingDefender()
  2692. {
  2693. // whether defender exists
  2694. if ((DefendingPermanent == null) != (DefendingCard == null))
  2695. {
  2696. if (DefendingPermanent != null)
  2697. {
  2698. if (DefendingPermanent.TopCard != null)
  2699. {
  2700. return true;
  2701. }
  2702. }
  2703. else if (DefendingCard != null)
  2704. {
  2705. return true;
  2706. }
  2707. }
  2708. return false;
  2709. }
  2710. if (IsExistingDefender())
  2711. {
  2712. if (AttackingPermanent != null)
  2713. {
  2714. AttackingPermanent.battle = this;
  2715. }
  2716. if (DefendingPermanent != null)
  2717. {
  2718. DefendingPermanent.battle = this;
  2719. }
  2720. List<Permanent> WinnerPermanents = new List<Permanent>();
  2721. List<Permanent> LoserPermanents = new List<Permanent>();
  2722. CardSource LoserCard = null;
  2723. //add log
  2724. string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
  2725. if (DefendingPermanent != null)
  2726. {
  2727. log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
  2728. }
  2729. else if (DefendingCard != null)
  2730. {
  2731. log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
  2732. }
  2733. GManager.instance.playLog.AddLogString(log);
  2734. #region "At the start of battle" effect
  2735. Permanent _AttackingPermanent = null;
  2736. Permanent _DefendingPermanent = null;
  2737. if (AttackingPermanent != null)
  2738. {
  2739. if (AttackingPermanent.TopCard != null)
  2740. {
  2741. _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
  2742. }
  2743. }
  2744. if (DefendingPermanent != null)
  2745. {
  2746. if (DefendingPermanent.TopCard != null)
  2747. {
  2748. _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
  2749. }
  2750. }
  2751. hashtable.Add("AttackingPermanent", _AttackingPermanent);
  2752. hashtable.Add("DefendingPermanent", _DefendingPermanent);
  2753. hashtable.Add("DefendingCard", DefendingCard);
  2754. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
  2755. #endregion
  2756. #region Show effect
  2757. bool ShowEffect()
  2758. {
  2759. if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
  2760. {
  2761. return true;
  2762. }
  2763. else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
  2764. {
  2765. if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
  2766. {
  2767. return true;
  2768. }
  2769. }
  2770. return false;
  2771. }
  2772. if (ShowEffect())
  2773. {
  2774. if (GManager.instance.attackProcess.IsAttacking)
  2775. {
  2776. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2777. {
  2778. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2779. {
  2780. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2781. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2782. }
  2783. }
  2784. }
  2785. }
  2786. #endregion
  2787. // auto process check
  2788. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2789. GManager.instance.turnStateMachine.IsSelecting = true;
  2790. //Preemptive end battle if the attack process is ended
  2791. if(GManager.instance.attackProcess.IsEndAttack)
  2792. yield break;
  2793. #region battle with permanent
  2794. if (DefendingPermanent != null)
  2795. {
  2796. if (AttackingPermanent.DP > DefendingPermanent.DP)
  2797. {
  2798. WinnerPermanents.Add(AttackingPermanent);
  2799. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2800. {
  2801. LoserPermanents.Add(DefendingPermanent);
  2802. }
  2803. }
  2804. else if (AttackingPermanent.DP == DefendingPermanent.DP)
  2805. {
  2806. WinnerPermanents.Add(AttackingPermanent);
  2807. WinnerPermanents.Add(DefendingPermanent);
  2808. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2809. {
  2810. LoserPermanents.Add(AttackingPermanent);
  2811. }
  2812. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2813. {
  2814. LoserPermanents.Add(DefendingPermanent);
  2815. }
  2816. }
  2817. else if (AttackingPermanent.DP < DefendingPermanent.DP)
  2818. {
  2819. WinnerPermanents.Add(DefendingPermanent);
  2820. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2821. {
  2822. LoserPermanents.Add(AttackingPermanent);
  2823. }
  2824. }
  2825. }
  2826. #endregion
  2827. #region battle with card
  2828. else if (DefendingCard != null)
  2829. {
  2830. if (AttackingPermanent.DP > DefendingCard.CardDP)
  2831. {
  2832. WinnerPermanents.Add(AttackingPermanent);
  2833. LoserCard = DefendingCard;
  2834. }
  2835. else if (AttackingPermanent.DP == DefendingCard.CardDP)
  2836. {
  2837. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2838. {
  2839. LoserPermanents.Add(AttackingPermanent);
  2840. }
  2841. LoserCard = DefendingCard;
  2842. }
  2843. else if (AttackingPermanent.DP < DefendingCard.CardDP)
  2844. {
  2845. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2846. {
  2847. LoserPermanents.Add(AttackingPermanent);
  2848. }
  2849. }
  2850. }
  2851. #endregion
  2852. List<Permanent> _WinnerPermanents = new List<Permanent>();
  2853. List<Permanent> _LoserPermanents = new List<Permanent>();
  2854. foreach (Permanent permanent in WinnerPermanents)
  2855. {
  2856. if (permanent.TopCard != null)
  2857. {
  2858. _WinnerPermanents.Add(new Permanent(permanent.cardSources));
  2859. }
  2860. }
  2861. foreach (Permanent permanent in LoserPermanents)
  2862. {
  2863. if (permanent.TopCard != null)
  2864. {
  2865. _LoserPermanents.Add(new Permanent(permanent.cardSources));
  2866. }
  2867. }
  2868. hashtable.Add("WinnerPermanents", _WinnerPermanents);
  2869. hashtable.Add("WinnerPermanents_real", WinnerPermanents);
  2870. hashtable.Add("LoserPermanents", _LoserPermanents);
  2871. hashtable.Add("LoserPermanents_real", LoserPermanents);
  2872. hashtable.Add("LoserCard", LoserCard);
  2873. hashtable.Add("battle", this);
  2874. // battle effect
  2875. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
  2876. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(LoserPermanents, hashtable).Destroy());
  2877. //Fix winner/loser permanents
  2878. int index = -1;
  2879. foreach (Permanent permanent in LoserPermanents)
  2880. {
  2881. if(permanent.TopCard != null)
  2882. {
  2883. index = LoserPermanents.IndexOf(permanent);
  2884. }
  2885. }
  2886. if(index >= 0)
  2887. {
  2888. LoserPermanents.RemoveAt(index);
  2889. _LoserPermanents.RemoveAt(index);
  2890. hashtable["LoserPermanents"] = _LoserPermanents;
  2891. hashtable["LoserPermanents_real"] = LoserPermanents;
  2892. }
  2893. // "At the end of battle" effect
  2894. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
  2895. #region move up effect
  2896. if (ShowEffect())
  2897. {
  2898. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
  2899. }
  2900. #endregion
  2901. }
  2902. }
  2903. // auto process check
  2904. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2905. #region reset effect until the end of battle
  2906. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2907. {
  2908. foreach (Permanent permanent in player.GetFieldPermanents())
  2909. {
  2910. permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  2911. }
  2912. player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  2913. }
  2914. #endregion
  2915. if (AttackingPermanent != null)
  2916. {
  2917. AttackingPermanent.battle = null;
  2918. }
  2919. if (DefendingPermanent != null)
  2920. {
  2921. DefendingPermanent.battle = null;
  2922. }
  2923. }
  2924. }
  2925. #endregion
  2926. #region De-digivolve
  2927. public class IDegeneration
  2928. {
  2929. public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect)
  2930. {
  2931. _permanent = permanent;
  2932. _degenerationCount = DegenerationCount;
  2933. _cardEffect = cardEffect;
  2934. }
  2935. Permanent _permanent = null;
  2936. int _degenerationCount = 0;
  2937. ICardEffect _cardEffect = null;
  2938. public IEnumerator Degeneration()
  2939. {
  2940. if (_cardEffect == null) yield break;
  2941. if (_cardEffect.EffectSourceCard == null) yield break;
  2942. if (_permanent == null) yield break;
  2943. if (_permanent.TopCard == null) yield break;
  2944. if (_permanent.ImmuneFromDeDigivolve()) yield break;
  2945. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  2946. int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
  2947. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  2948. if (selectCountEffect != null)
  2949. {
  2950. Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
  2951. selectCountEffect.SetUp(
  2952. SelectPlayer: selectPlayer,
  2953. targetPermanent: _permanent,
  2954. MaxCount: maxCount,
  2955. CanNoSelect: false,
  2956. Message: "How many cards do you trash?",
  2957. Message_Enemy: "The opponent is choosing how many cards to trash.",
  2958. SelectCountCoroutine: SelectCountCoroutine);
  2959. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  2960. IEnumerator SelectCountCoroutine(int count)
  2961. {
  2962. _degenerationCount = count;
  2963. yield return null;
  2964. }
  2965. }
  2966. if (_degenerationCount >= 1)
  2967. {
  2968. int count = 0;
  2969. List<CardSource> selectedCards = new List<CardSource>();
  2970. while (true)
  2971. {
  2972. bool StopCondition()
  2973. {
  2974. if (_permanent.HasNoDigivolutionCards)
  2975. {
  2976. return true;
  2977. }
  2978. if (_permanent.Level == 3)
  2979. {
  2980. if (_permanent.TopCard != null)
  2981. {
  2982. if (_permanent.TopCard.HasLevel)
  2983. {
  2984. return true;
  2985. }
  2986. }
  2987. }
  2988. if (count >= _degenerationCount)
  2989. {
  2990. return true;
  2991. }
  2992. return false;
  2993. }
  2994. if (StopCondition())
  2995. {
  2996. break;
  2997. }
  2998. if (count == 0)
  2999. {
  3000. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3001. }
  3002. CardSource cardSource = _permanent.TopCard;
  3003. selectedCards.Add(cardSource);
  3004. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  3005. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3006. if (!cardSource.IsToken)
  3007. {
  3008. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3009. }
  3010. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  3011. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3012. count++;
  3013. }
  3014. #region add log
  3015. if (selectedCards.Count >= 1)
  3016. {
  3017. string log = "";
  3018. log += $"\nDe-Digivolve :";
  3019. foreach (CardSource cardSource in selectedCards)
  3020. {
  3021. if (cardSource != null)
  3022. {
  3023. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3024. }
  3025. }
  3026. log += "\n";
  3027. GManager.instance.playLog.AddLogString(log);
  3028. }
  3029. #endregion
  3030. }
  3031. }
  3032. }
  3033. #endregion
  3034. #region Trash digivolution cards
  3035. public class ITrashDigivolutionCards
  3036. {
  3037. public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  3038. {
  3039. _permanent = permanent;
  3040. _trashTargetCards = trashTargetCards.Clone();
  3041. _cardEffect = cardEffect;
  3042. }
  3043. Permanent _permanent = null;
  3044. List<CardSource> _trashTargetCards = new List<CardSource>();
  3045. ICardEffect _cardEffect = null;
  3046. public IEnumerator TrashDigivolutionCards()
  3047. {
  3048. if (_trashTargetCards == null) yield break;
  3049. if (_cardEffect == null) yield break;
  3050. if (_permanent == null) yield break;
  3051. if (_permanent.TopCard == null) yield break;
  3052. if (_permanent.HasNoDigivolutionCards) yield break;
  3053. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3054. _trashTargetCards = _trashTargetCards.Filter((cardSource) => _permanent.DigivolutionCards.Contains(cardSource) && !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
  3055. if (_trashTargetCards.Count == 0) yield break;
  3056. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  3057. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  3058. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3059. #region "When digivolution cards are trashed" effect
  3060. #region Hashtable Setting
  3061. Hashtable hashtable = new Hashtable()
  3062. {
  3063. {"CardEffect", _cardEffect},
  3064. {"Permanent", _permanent},
  3065. {"DiscardedCards", _trashTargetCards},
  3066. };
  3067. #endregion
  3068. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
  3069. #endregion
  3070. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  3071. foreach (CardSource cardSource in _trashTargetCards)
  3072. {
  3073. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3074. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3075. if (!cardSource.IsToken)
  3076. {
  3077. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3078. }
  3079. }
  3080. }
  3081. }
  3082. #endregion
  3083. #region Return digivolution cards to deck bottom
  3084. public class ReturnToLibraryBottomDigivolutionCardsClass
  3085. {
  3086. public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
  3087. {
  3088. _permanent = permanent;
  3089. _cardSources = cardSources.Clone();
  3090. _hashtable = hashtable;
  3091. }
  3092. Permanent _permanent = null;
  3093. List<CardSource> _cardSources = new List<CardSource>();
  3094. Hashtable _hashtable = null;
  3095. public IEnumerator ReturnToLibraryBottomDigivolutionCards()
  3096. {
  3097. if (_permanent == null) yield break;
  3098. if (_permanent.TopCard == null) yield break;
  3099. if (_cardSources == null) yield break;
  3100. _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
  3101. if (_cardSources.Count == 0) yield break;
  3102. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3103. if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
  3104. string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
  3105. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
  3106. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3107. #region "When digivolution cards are returned to deck" effect
  3108. #region Hashtable Setting
  3109. Hashtable hashtable1 = new Hashtable()
  3110. {
  3111. {"Permanent", _permanent},
  3112. {"DeckBottomCards", _cardSources},
  3113. {"CardEffect", CardEffect},
  3114. };
  3115. #endregion
  3116. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
  3117. #endregion
  3118. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
  3119. }
  3120. }
  3121. #endregion
  3122. #region Reduce security
  3123. public class IReduceSecurity
  3124. {
  3125. public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos)
  3126. {
  3127. _player = player;
  3128. _refSkillInfos = refSkillInfos;
  3129. }
  3130. Player _player = null;
  3131. List<SkillInfo> _refSkillInfos = null;
  3132. public IEnumerator ReduceSecurity()
  3133. {
  3134. #region "When cards are removed from security" effect
  3135. #region Hashtable Setting
  3136. Hashtable hashtable = new Hashtable()
  3137. {
  3138. {"Player", _player}
  3139. };
  3140. #endregion
  3141. if (_refSkillInfos == null)
  3142. {
  3143. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
  3144. }
  3145. else
  3146. {
  3147. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
  3148. {
  3149. _refSkillInfos.Add(skillInfo);
  3150. }
  3151. }
  3152. #endregion
  3153. }
  3154. }
  3155. #endregion
  3156. #region Add Security
  3157. public class IAddSecurity
  3158. {
  3159. public IAddSecurity(Player player)
  3160. {
  3161. _player = player;
  3162. }
  3163. Player _player { get; set; }
  3164. public IEnumerator AddSecurity()
  3165. {
  3166. #region "When security cards are added" effect
  3167. #region Hashtable setting
  3168. Hashtable hashtable = new Hashtable()
  3169. {
  3170. {"Player", _player}
  3171. };
  3172. #endregion
  3173. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
  3174. #endregion
  3175. }
  3176. }
  3177. #endregion
  3178. #region Suspend permanents
  3179. public class SuspendPermanentsClass
  3180. {
  3181. public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
  3182. {
  3183. _permanents = permanents;
  3184. _hashtable = hashtable;
  3185. }
  3186. List<Permanent> _permanents { get; set; }
  3187. Hashtable _hashtable { get; set; }
  3188. public IEnumerator Tap()
  3189. {
  3190. if (_permanents.Count == 0) yield break;
  3191. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3192. bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
  3193. bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
  3194. List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
  3195. bool PermanentCondition(Permanent permanent)
  3196. {
  3197. if (permanent != null)
  3198. {
  3199. if (permanent.TopCard != null)
  3200. {
  3201. if (permanent.IsSuspended)
  3202. {
  3203. return false;
  3204. }
  3205. if (!permanent.CanSuspend)
  3206. {
  3207. return false;
  3208. }
  3209. if (CardEffect != null)
  3210. {
  3211. if (permanent.TopCard.CanNotBeAffected(CardEffect))
  3212. {
  3213. return false;
  3214. }
  3215. }
  3216. }
  3217. }
  3218. return true;
  3219. }
  3220. foreach (Permanent permanent in suspendTargetPermanents)
  3221. {
  3222. permanent.IsSuspended = true;
  3223. permanent.DPWhenSuspended = permanent.DP;
  3224. if (permanent.ShowingPermanentCard != null)
  3225. {
  3226. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3227. }
  3228. }
  3229. if (suspendTargetPermanents.Count >= 1)
  3230. {
  3231. #region "Effects when permanents suspend
  3232. #region Hashtable Setting
  3233. Hashtable _hashtable = new Hashtable(){
  3234. {"Permanents", suspendTargetPermanents},
  3235. {"IsBlock", IsBlock}
  3236. };
  3237. if (CardEffect != null)
  3238. {
  3239. _hashtable.Add("CardEffect", CardEffect);
  3240. }
  3241. #endregion
  3242. if (IsAttack) yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3243. else yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3244. #endregion
  3245. yield return new WaitForSeconds(0.3f);
  3246. }
  3247. }
  3248. }
  3249. #endregion
  3250. #region Unsuspend permanents
  3251. public class IUnsuspendPermanents
  3252. {
  3253. public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
  3254. {
  3255. _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  3256. _cardEffect = cardEffect;
  3257. }
  3258. List<Permanent> _permanents { get; set; }
  3259. ICardEffect _cardEffect { get; set; }
  3260. public IEnumerator Unsuspend()
  3261. {
  3262. //Permanent list that will unsuspend
  3263. List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
  3264. permanent != null
  3265. && permanent.TopCard != null
  3266. && permanent.IsSuspended
  3267. && permanent.CanUnsuspend
  3268. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3269. #region "When permanents would unsuspend" effect
  3270. #region Hashtable Setting
  3271. Hashtable hashtable1 = new Hashtable()
  3272. {
  3273. {"CardEffect", _cardEffect},
  3274. {"Permanents", untappedPermanets},
  3275. };
  3276. #endregion
  3277. List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
  3278. if (skillInfos.Count >= 1)
  3279. {
  3280. foreach (SkillInfo skillInfo in skillInfos)
  3281. {
  3282. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  3283. }
  3284. foreach (Permanent permanent in untappedPermanets)
  3285. {
  3286. permanent.ShowUnsuspendEffect();
  3287. }
  3288. //cut in effects
  3289. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3290. untappedPermanets.ForEach(permanent =>
  3291. {
  3292. if (permanent.ShowingPermanentCard != null)
  3293. {
  3294. permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
  3295. }
  3296. });
  3297. }
  3298. #endregion
  3299. // fix unsuspend target permanents
  3300. List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
  3301. permanent != null
  3302. && permanent.TopCard != null
  3303. && permanent.IsSuspended
  3304. && permanent.CanUnsuspend
  3305. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3306. if (untappedPermanets_Fixed.Count >= 1)
  3307. {
  3308. foreach (Permanent permanent in untappedPermanets_Fixed)
  3309. {
  3310. permanent.IsSuspended = false;
  3311. if (permanent.ShowingPermanentCard != null)
  3312. {
  3313. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3314. }
  3315. }
  3316. #region "When permanents are unsuspended" effect
  3317. #region Hashtable Setting
  3318. Hashtable hashtable2 = new Hashtable()
  3319. {
  3320. {"CardEffect", _cardEffect},
  3321. {"Permanents", untappedPermanets_Fixed},
  3322. };
  3323. #endregion
  3324. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
  3325. #endregion
  3326. yield return new WaitForSeconds(0.3f);
  3327. }
  3328. foreach (Permanent permanent in untappedPermanets)
  3329. {
  3330. permanent.UntilNextUntapEffects = new List<Func<EffectTiming, ICardEffect>>();
  3331. }
  3332. }
  3333. }
  3334. #endregion
  3335. #region Trash cards from deck top
  3336. public class ITrashDeckCards
  3337. {
  3338. public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
  3339. {
  3340. this.cardSources = new List<CardSource>();
  3341. foreach (CardSource cardSource in cardSources)
  3342. {
  3343. this.cardSources.Add(cardSource);
  3344. }
  3345. this.cardEffect = cardEffect;
  3346. }
  3347. List<CardSource> cardSources { get; set; } = new List<CardSource>();
  3348. ICardEffect cardEffect { get; set; } = null;
  3349. public IEnumerator TrashDeckCards()
  3350. {
  3351. List<CardSource> trashCards = new List<CardSource>();
  3352. foreach (CardSource cardSource in cardSources)
  3353. {
  3354. if (cardSource.Owner.LibraryCards.Contains(cardSource))
  3355. {
  3356. trashCards.Add(cardSource);
  3357. }
  3358. }
  3359. if (trashCards.Count >= 1)
  3360. {
  3361. foreach (CardSource cardSource in trashCards)
  3362. {
  3363. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3364. }
  3365. #region "When cards are trashed from security" effect
  3366. #region Hashtable setting
  3367. Hashtable hashtable = new Hashtable()
  3368. {
  3369. {"DiscardedCards", trashCards},
  3370. {"CardEffect", cardEffect},
  3371. };
  3372. #endregion
  3373. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  3374. hashtable, EffectTiming.OnDiscardLibrary));
  3375. #endregion
  3376. }
  3377. }
  3378. }
  3379. #endregion
  3380. #region Overflow of ace
  3381. public class AceOverflowClass
  3382. {
  3383. public AceOverflowClass(List<CardSource> cardSources)
  3384. {
  3385. _cardSources = cardSources.Clone();
  3386. }
  3387. List<CardSource> _cardSources = new List<CardSource>();
  3388. public IEnumerator Overflow()
  3389. {
  3390. _cardSources = _cardSources
  3391. .Filter(cardSource => cardSource.IsACE && CardEffectCommons.IsExistOnBattleArea(cardSource))
  3392. .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
  3393. .ToList();
  3394. foreach (CardSource cardSource in _cardSources)
  3395. {
  3396. yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
  3397. string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
  3398. GManager.instance.playLog.AddLogString(log);
  3399. }
  3400. }
  3401. }
  3402. #endregion