CardController.cs 194 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using System.Linq;
  6. #region Trash cards from hand
  7. public class IDiscardHands
  8. {
  9. public IDiscardHands(List<IDiscardHand> discardHands, ICardEffect cardEffect)
  10. {
  11. foreach (IDiscardHand discardHand in discardHands)
  12. {
  13. this.discardHands.Add(discardHand);
  14. }
  15. this.cardEffect = cardEffect;
  16. }
  17. List<IDiscardHand> discardHands { get; set; } = new List<IDiscardHand>();
  18. ICardEffect cardEffect { get; set; }
  19. public IEnumerator DiscardHands()
  20. {
  21. foreach (IDiscardHand discardHand in discardHands)
  22. {
  23. yield return ContinuousController.instance.StartCoroutine(discardHand.Discard());
  24. }
  25. List<CardSource> discardedCards = new List<CardSource>();
  26. foreach (IDiscardHand discardHand in discardHands)
  27. {
  28. if (discardHand.discarded)
  29. {
  30. discardedCards.Add(discardHand.cardSource);
  31. }
  32. }
  33. if (discardedCards.Count >= 1)
  34. {
  35. #region "When cards are trashed from hand" effect
  36. #region Hashtable setting
  37. Hashtable hashtable = new Hashtable()
  38. {
  39. {"DiscardedCards", discardedCards},
  40. {"CardEffect", cardEffect},
  41. };
  42. #endregion
  43. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardHand));
  44. #endregion
  45. }
  46. #region add log
  47. if (discardedCards.Count >= 1)
  48. {
  49. string log = "";
  50. log += $"\nDiscard hand:";
  51. foreach (CardSource cardSource in discardedCards)
  52. {
  53. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  54. }
  55. log += "\n";
  56. PlayLog.OnAddLog?.Invoke(log);
  57. }
  58. #endregion
  59. }
  60. }
  61. public class IDiscardHand
  62. {
  63. public IDiscardHand(CardSource cardSource, Hashtable hashtable)
  64. {
  65. this.cardSource = cardSource;
  66. this.hashtable = hashtable;
  67. }
  68. public CardSource cardSource { get; private set; }
  69. public Hashtable hashtable { get; private set; }
  70. public bool discarded { get; private set; } = false;
  71. public IEnumerator Discard()
  72. {
  73. bool oldisHand = cardSource.Owner.HandCards.Contains(cardSource);
  74. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
  75. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  76. bool isTrash = CardEffectCommons.IsExistOnTrash(cardSource);
  77. if (oldisHand && isTrash)
  78. {
  79. discarded = true;
  80. }
  81. }
  82. }
  83. #endregion
  84. #region Play cards
  85. public class PlayCardClass
  86. {
  87. public PlayCardClass(List<CardSource> cardSources, Hashtable hashtable, bool payCost, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root,
  88. bool activateETB)
  89. {
  90. if (cardSources != null)
  91. {
  92. CardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  93. }
  94. _hashtable = hashtable;
  95. PayCost = payCost;
  96. _targetPermanent = targetPermanent;
  97. _isTapped = isTapped;
  98. Root = root;
  99. _activateETB = activateETB;
  100. }
  101. public void SetJogress(int[] jogressEvoRootsFrameIDs)
  102. {
  103. if (jogressEvoRootsFrameIDs != null)
  104. {
  105. _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
  106. }
  107. }
  108. public void SetBurst(int BurstTamerFrameID, CardSource card)
  109. {
  110. if (0 <= BurstTamerFrameID && BurstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
  111. {
  112. _burstTamerFrameID = BurstTamerFrameID;
  113. }
  114. }
  115. public void SetAppFusion(int[] AppFusionFrameID)
  116. {
  117. if (AppFusionFrameID != null)
  118. {
  119. _appFusionFrameIDs = AppFusionFrameID.CloneArray(); ;
  120. }
  121. }
  122. public void SetShowEffect()
  123. {
  124. _showEffect = true;
  125. }
  126. public void SetIgnoreLevel()
  127. {
  128. _ignoreLevel = true;
  129. SetIgnoreRequirements(CardEffectCommons.IgnoreRequirement.Level);
  130. }
  131. public void SetIgnoreRequirements(CardEffectCommons.IgnoreRequirement ignore)
  132. {
  133. _ignoreRequirement = ignore;
  134. }
  135. private bool GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement ignore)
  136. {
  137. return _ignoreRequirement.Equals(ignore) || _ignoreRequirement.Equals(CardEffectCommons.IgnoreRequirement.All);
  138. }
  139. public void SetFixedCost(int FixedCost)
  140. {
  141. _fixedCost = FixedCost;
  142. }
  143. public void SetReducedCost(int ReducedCost)
  144. {
  145. _reducedCost = ReducedCost;
  146. }
  147. public void SetAddSecurityEndOption()
  148. {
  149. _addSecurityEndOption = true;
  150. }
  151. public void SetIsBreedingArea()
  152. {
  153. _isBreedingArea = true;
  154. }
  155. public List<CardSource> CardSources { get; private set; } = new List<CardSource>();
  156. Hashtable _hashtable = null;
  157. public bool PayCost { get; private set; }
  158. Permanent _targetPermanent = null;
  159. bool _isTapped = false;
  160. public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
  161. bool _activateETB = true;
  162. bool _showEffect = false;
  163. bool _ignoreLevel = false;
  164. CardEffectCommons.IgnoreRequirement _ignoreRequirement = CardEffectCommons.IgnoreRequirement.None;
  165. int _fixedCost = -1;
  166. int _reducedCost = 0;
  167. int[] _jogressEvoRootsFrameIDs = null;
  168. int _burstTamerFrameID = -1;
  169. int[] _appFusionFrameIDs = null;
  170. bool _addSecurityEndOption = false;
  171. bool _isBreedingArea = false;
  172. public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
  173. bool IsBurst(CardSource card)
  174. {
  175. Permanent burstTamer = BurstTamer(card);
  176. if (burstTamer != null)
  177. {
  178. if (burstTamer.TopCard != null)
  179. {
  180. if (card.burstDigivolutionCondition != null)
  181. {
  182. if (card.burstDigivolutionCondition.tamerCondition != null)
  183. {
  184. if (card.burstDigivolutionCondition.tamerCondition(burstTamer))
  185. {
  186. return true;
  187. }
  188. }
  189. }
  190. }
  191. }
  192. return false;
  193. }
  194. Permanent BurstTamer(CardSource card)
  195. {
  196. if (0 <= _burstTamerFrameID && _burstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
  197. {
  198. Permanent tamer = card.Owner.fieldCardFrames[_burstTamerFrameID].GetFramePermanent();
  199. return tamer;
  200. }
  201. return null;
  202. }
  203. bool IsAppFusion(CardSource card)
  204. {
  205. CardSource linkCard = LinkedCard(card);
  206. if (linkCard != null)
  207. {
  208. if (card.appFusionCondition != null)
  209. {
  210. if (card.appFusionCondition.digimonCondition != null)
  211. {
  212. Permanent digimon = card.Owner.fieldCardFrames[_appFusionFrameIDs[0]].GetFramePermanent();
  213. if (card.appFusionCondition.linkedCondition != null)
  214. {
  215. if (card.appFusionCondition.linkedCondition(digimon, linkCard))
  216. {
  217. return true;
  218. }
  219. }
  220. }
  221. }
  222. }
  223. return false;
  224. }
  225. public CardSource LinkedCard(CardSource card)
  226. {
  227. if (_appFusionFrameIDs != null && _appFusionFrameIDs.Length == 2)
  228. {
  229. if (0 <= _appFusionFrameIDs[0] && _appFusionFrameIDs[0] <= card.Owner.fieldCardFrames.Count - 1)
  230. {
  231. Permanent targetPermanent = card.Owner.fieldCardFrames[_appFusionFrameIDs[0]].GetFramePermanent();
  232. if (targetPermanent.LinkedCards.Count > _appFusionFrameIDs[1])
  233. {
  234. CardSource link = targetPermanent.LinkedCards[_appFusionFrameIDs[1]];
  235. return link;
  236. }
  237. }
  238. }
  239. return null;
  240. }
  241. public IEnumerator PlayCard()
  242. {
  243. bool burstDigivolved = false;
  244. bool appFusion = false;
  245. List<CardSource> playedCards_fixed = new List<CardSource>();
  246. foreach (CardSource card in CardSources)
  247. {
  248. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  249. GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
  250. GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
  251. if (card == null)
  252. {
  253. continue;
  254. }
  255. #region Set Root
  256. ICardEffect CardEffect = null;
  257. CardEffect = CardEffectCommons.GetCardEffectFromHashtable(this._hashtable);
  258. if (CardEffectCommons.IsExistOnTrash(card))
  259. {
  260. Root = SelectCardEffect.Root.Trash;
  261. }
  262. else if (card.Owner.HandCards.Contains(card))
  263. {
  264. Root = SelectCardEffect.Root.Hand;
  265. }
  266. else if (card.Owner.LibraryCards.Contains(card))
  267. {
  268. Root = SelectCardEffect.Root.Library;
  269. }
  270. else if (card.Owner.GetFieldPermanents().Count((permanent) => permanent.DigivolutionCards.Contains(card)) >= 1)
  271. {
  272. Root = SelectCardEffect.Root.DigivolutionCards;
  273. }
  274. else if (card.Owner.GetFieldPermanents().Count((permanent) => permanent.LinkedCards.Contains(card)) >= 1)
  275. {
  276. Root = SelectCardEffect.Root.LinkedCards;
  277. }
  278. else if (card.Owner.SecurityCards.Contains(card))
  279. {
  280. Root = SelectCardEffect.Root.Security;
  281. }
  282. else if (CardEffectCommons.IsExistOnExecutingArea(card))
  283. {
  284. Root = SelectCardEffect.Root.Execution;
  285. }
  286. #endregion
  287. #region Set target(s)
  288. List<Permanent> targetPermanents = new List<Permanent>();
  289. if (card.IsPermanent)
  290. {
  291. if (!isJogress)
  292. {
  293. if (CardEffectCommons.IsOwnerPermanent(_targetPermanent, card))
  294. {
  295. targetPermanents.Add(_targetPermanent);
  296. }
  297. }
  298. else
  299. {
  300. for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
  301. {
  302. int JogressFrameID = _jogressEvoRootsFrameIDs[i];
  303. if (0 <= JogressFrameID && JogressFrameID <= card.Owner.fieldCardFrames.Count - 1)
  304. {
  305. Permanent targetPermanent = card.Owner.fieldCardFrames[JogressFrameID].GetFramePermanent();
  306. targetPermanents.Add(targetPermanent);
  307. }
  308. }
  309. foreach (Permanent permanent in targetPermanents)
  310. {
  311. permanent.ShowingPermanentCard.SetPermanentIndexText(targetPermanents);
  312. }
  313. }
  314. }
  315. #endregion
  316. #region Determine if Evolution
  317. bool isEvolution = false;
  318. if (targetPermanents.Count >= 1)
  319. {
  320. if (!isJogress)
  321. {
  322. if (IsBurst(card))
  323. {
  324. if (card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
  325. {
  326. isEvolution = true;
  327. }
  328. }
  329. else if (IsAppFusion(card))
  330. {
  331. if (card.CanAppFusionFromTargetPermanent(targetPermanents[0], PayCost))
  332. {
  333. isEvolution = true;
  334. }
  335. }
  336. else
  337. {
  338. if (card.CanEvolve(targetPermanents[0], true) || GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level) || _ignoreLevel)
  339. {
  340. isEvolution = true;
  341. }
  342. }
  343. }
  344. else
  345. {
  346. if (targetPermanents.Count == 2)
  347. {
  348. isEvolution = true;
  349. }
  350. }
  351. }
  352. #endregion
  353. List<CardSource> oldTrashCards = new List<CardSource>();
  354. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForNonTurnPlayer)
  355. {
  356. foreach (Permanent permanent in player.GetFieldPermanents())
  357. {
  358. permanent.oldIsTapped_playCard = permanent.IsSuspended;
  359. }
  360. }
  361. foreach (CardSource cardSource in card.Owner.TrashCards)
  362. {
  363. oldTrashCards.Add(cardSource);
  364. }
  365. // effect of removing digivolution/linked cards
  366. if (card.IsPermanent && !isEvolution && card.PermanentOfThisCard() != null && (Root == SelectCardEffect.Root.DigivolutionCards || Root == SelectCardEffect.Root.LinkedCards))
  367. {
  368. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(card, card.PermanentOfThisCard()));
  369. }
  370. #region select digivolution cost
  371. int baseCost = -1;
  372. bool costSelected = false;
  373. yield return ContinuousController.instance.StartCoroutine(SelectCost());
  374. IEnumerator SelectCost()
  375. {
  376. if (!isJogress)
  377. {
  378. if (PayCost)
  379. {
  380. if (_fixedCost < 0)
  381. {
  382. Permanent targetPermanent = null;
  383. if (targetPermanents.Count >= 1)
  384. {
  385. targetPermanent = targetPermanents[0];
  386. }
  387. if (targetPermanent != null)
  388. {
  389. List<int> CostList = new List<int>();
  390. bool isBurst = IsBurst(card);
  391. bool isAppFusion = IsAppFusion(card);
  392. if (isBurst || isAppFusion)
  393. {
  394. if (isBurst)
  395. CostList.Add(card.burstDigivolutionCondition.cost);
  396. if (isAppFusion)
  397. CostList.Add(card.appFusionCondition.cost);
  398. }
  399. else
  400. {
  401. foreach (int cost in card.CostList(targetPermanent, ignoreLevel: GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level), checkAvailability: false))
  402. {
  403. int evoCost = cost;
  404. if (_reducedCost > 0)
  405. evoCost -= _reducedCost;
  406. CostList.Add(evoCost);
  407. }
  408. }
  409. CostList = CostList.Distinct().ToList();
  410. if (CostList.Count >= 1)
  411. {
  412. if (CostList.Count == 1)
  413. {
  414. baseCost = CostList[0];
  415. }
  416. else
  417. {
  418. costSelected = true;
  419. bool MoveToExecuteCardEffect = true;
  420. if (card.Owner.HandCards.Contains(card) && card.ShowingHandCard != null)
  421. {
  422. if (card.ShowingHandCard.gameObject.activeSelf)
  423. {
  424. MoveToExecuteCardEffect = false;
  425. }
  426. }
  427. if (!card.Owner.isYou && GManager.instance.IsAI)
  428. {
  429. MoveToExecuteCardEffect = false;
  430. costSelected = false;
  431. }
  432. if (card.Owner.isYou && ContinuousController.instance.autoMinDigivolutionCost)
  433. {
  434. MoveToExecuteCardEffect = false;
  435. costSelected = false;
  436. }
  437. if (MoveToExecuteCardEffect)
  438. {
  439. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  440. }
  441. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  442. if (selectCountEffect != null)
  443. {
  444. selectCountEffect.SetUp(
  445. SelectPlayer: card.Owner,
  446. targetPermanent: null,
  447. MaxCount: 1,
  448. CanNoSelect: false,
  449. Message: "Which digivolution cost do you pay?",
  450. Message_Enemy: "The opponent is choosing which digivolution cost to pay.",
  451. SelectCountCoroutine: SelectCountCoroutine);
  452. selectCountEffect.SetCandidates(CostList);
  453. selectCountEffect.SetPreferMin(true);
  454. selectCountEffect.SetNotDoSync(true);
  455. selectCountEffect.SetIsDigivolutionCost(true);
  456. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  457. IEnumerator SelectCountCoroutine(int count)
  458. {
  459. baseCost = count;
  460. yield return null;
  461. }
  462. }
  463. }
  464. }
  465. }
  466. else
  467. {
  468. baseCost = card.BasePlayCostFromEntity;
  469. }
  470. }
  471. }
  472. }
  473. }
  474. #endregion
  475. #region select DNA condition
  476. int baseDNA = 0;
  477. if (isJogress)
  478. {
  479. baseDNA = GManager.instance.GetComponent<SelectDNACondition>()._selectedCount;
  480. }
  481. #endregion
  482. #region HashTable Setting
  483. Hashtable hashtable = CardEffectCommons.WouldEnterFieldHashtable(
  484. payCost: PayCost,
  485. card: card,
  486. root: Root,
  487. isEvolution: isEvolution,
  488. playCardClass: this,
  489. cardEffect: CardEffect,
  490. isJogress: isJogress,
  491. targetPermanents: targetPermanents
  492. );
  493. #endregion
  494. List<SkillInfo> skillInfos_BeforePayCost = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.BeforePayCost)
  495. .Concat(AutoProcessing.GetSkillInfosOfCards(hashtable, EffectTiming.BeforePayCost, new List<CardSource>() { card }
  496. .Filter(cardSource => !CardEffectCommons.IsExistOnHand(cardSource) && !CardEffectCommons.IsExistOnTrash(cardSource) && !CardEffectCommons.IsExistInSecurity(cardSource) && cardSource.PermanentOfThisCard() == null)))
  497. .ToList();
  498. yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.BeforePayCost));
  499. #region IsShowEffect()
  500. bool IsShowEffect()
  501. {
  502. if (skillInfos_BeforePayCost.Count >= 2)
  503. {
  504. return true;
  505. }
  506. else if (skillInfos_BeforePayCost.Count == 1)
  507. {
  508. if (skillInfos_BeforePayCost[0].CardEffect.CanActivate(skillInfos_BeforePayCost[0].Hashtable))
  509. {
  510. return true;
  511. }
  512. }
  513. else if (card.HasDigiXros && !isEvolution)
  514. {
  515. return true;
  516. }
  517. else if (IsBurst(card))
  518. {
  519. return true;
  520. }
  521. else if (IsAppFusion(card))
  522. {
  523. return true;
  524. }
  525. return false;
  526. }
  527. #endregion
  528. #region effect
  529. if (PayCost || IsShowEffect())
  530. {
  531. if (!costSelected)
  532. {
  533. if (card.IsOption || IsShowEffect())
  534. {
  535. bool noHandCard = true;
  536. if (card.Owner.HandCards.Contains(card))
  537. {
  538. if (card.ShowingHandCard != null)
  539. {
  540. if (card.ShowingHandCard.gameObject.activeSelf)
  541. {
  542. if (card.ShowingHandCard.gameObject.transform.GetChild(0).gameObject.activeSelf)
  543. {
  544. noHandCard = false;
  545. }
  546. }
  547. }
  548. }
  549. if (noHandCard)
  550. {
  551. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  552. }
  553. }
  554. else
  555. {
  556. if (CardEffect == null)
  557. {
  558. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  559. }
  560. }
  561. }
  562. }
  563. #endregion
  564. #region show expected cost
  565. if (PayCost)
  566. {
  567. if (!isJogress)
  568. {
  569. int cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  570. GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
  571. }
  572. else
  573. {
  574. if (card.jogressCondition.Count > 0)
  575. {
  576. int cost = card.GetPayingCostWithBaseCost(card.jogressCondition[baseDNA].cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  577. GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
  578. }
  579. }
  580. }
  581. #endregion
  582. #region process cut in effects before paying cost
  583. if (skillInfos_BeforePayCost.Count >= 1)
  584. {
  585. foreach (SkillInfo skillInfo in skillInfos_BeforePayCost)
  586. {
  587. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  588. }
  589. if (IsShowEffect())
  590. {
  591. foreach (Permanent targetPermanent in targetPermanents)
  592. {
  593. if (targetPermanent != null)
  594. {
  595. targetPermanent.ShowWillEvolutionEffect();
  596. }
  597. }
  598. }
  599. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  600. foreach (Permanent targetPermanent in targetPermanents)
  601. {
  602. if (targetPermanent != null)
  603. {
  604. targetPermanent.HideWillEvolutionEffect();
  605. }
  606. }
  607. }
  608. #endregion
  609. #region select DigiXros
  610. if (card.HasDigiXros && !isEvolution)
  611. {
  612. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectDigiXrosClass>().Select(card));
  613. }
  614. #endregion
  615. #region select Assembly
  616. if (card.HasAssembly && !isEvolution)
  617. {
  618. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectAssemblyClass>().Select(card));
  619. }
  620. #endregion
  621. #region Bounce Tamer of Burst digivolution
  622. if (IsBurst(card))
  623. {
  624. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectBurstDigivolutionEffect.BounceTamer(BurstTamer(card)));
  625. if (!GManager.instance.selectBurstDigivolutionEffect.TamerBounced)
  626. {
  627. _burstTamerFrameID = -1;
  628. yield return ContinuousController.instance.StartCoroutine(SelectCost());
  629. }
  630. else
  631. {
  632. burstDigivolved = true;
  633. }
  634. }
  635. #endregion
  636. #region Add Link Card of App Fusion
  637. if (IsAppFusion(card))
  638. {
  639. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectAppFusionEffect.AddToSources(LinkedCard(card)));
  640. if (!GManager.instance.selectAppFusionEffect.LinkAdded)
  641. {
  642. _appFusionFrameIDs = new int[0];
  643. yield return ContinuousController.instance.StartCoroutine(SelectCost());
  644. }
  645. else
  646. {
  647. appFusion = true;
  648. }
  649. yield return GManager.instance.photonWaitController.StartWait("AppFuse");
  650. }
  651. #endregion
  652. #region fix cost to pay
  653. int Cost = 0;
  654. if (PayCost)
  655. {
  656. if (!isJogress)
  657. {
  658. Cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  659. Cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  660. }
  661. else
  662. {
  663. if (card.jogressCondition.Count > 0)
  664. {
  665. Cost = card.GetPayingCostWithBaseCost(card.jogressCondition[baseDNA].cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  666. }
  667. }
  668. GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(Cost));
  669. }
  670. #endregion
  671. #region end play cards
  672. bool endPlayCard = false;
  673. bool playFailed = false;
  674. if (PayCost)
  675. {
  676. if (Cost > card.Owner.MaxMemoryCost)
  677. {
  678. endPlayCard = true;
  679. playFailed = true;
  680. }
  681. }
  682. if (isEvolution)
  683. {
  684. if (targetPermanents != null)
  685. {
  686. if (targetPermanents.Count >= 1)
  687. {
  688. foreach (Permanent permanent in targetPermanents)
  689. {
  690. if (permanent != null)
  691. {
  692. if (permanent.TopCard == null)
  693. {
  694. endPlayCard = true;
  695. }
  696. }
  697. }
  698. if (!endPlayCard)
  699. {
  700. if (!isJogress && !IsBurst(card) && !IsAppFusion(card))
  701. {
  702. if (!GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level) && !card.CanPlayCardTargetFrame(targetPermanents[0].PermanentFrame, PayCost, CardEffect, root: Root, fixedCost: -1))
  703. {
  704. endPlayCard = true;
  705. playFailed = true;
  706. }
  707. }
  708. else if (isJogress)
  709. {
  710. if (!card.CanJogressFromTargetPermanents(targetPermanents, PayCost))
  711. {
  712. endPlayCard = true;
  713. playFailed = true;
  714. }
  715. }
  716. else if (IsBurst(card))
  717. {
  718. if (!card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
  719. {
  720. endPlayCard = true;
  721. playFailed = true;
  722. }
  723. }
  724. else if (IsAppFusion(card))
  725. {
  726. if (!card.CanAppFusionFromTargetPermanent(targetPermanents[0], PayCost))
  727. {
  728. endPlayCard = true;
  729. playFailed = true;
  730. }
  731. }
  732. }
  733. }
  734. }
  735. }
  736. if (endPlayCard)
  737. {
  738. PlayLog.OnAddLog?.Invoke($"\nFailed to play:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  739. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  740. GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
  741. GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
  742. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().FailedPlayCardEffect(card));
  743. if (card.Owner.HandCards.Contains(card))
  744. {
  745. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  746. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(new List<CardSource>() { card }, false, null));
  747. }
  748. ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
  749. foreach (HandCard handCard in card.Owner.brainStormObject.BrainStormHandCards)
  750. {
  751. if (handCard.gameObject.activeSelf && handCard.cardSource == card)
  752. {
  753. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  754. }
  755. }
  756. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  757. {
  758. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  759. {
  760. if (fieldPermanentCard != null)
  761. {
  762. fieldPermanentCard.OffPermanentIndexText();
  763. }
  764. }
  765. }
  766. if (playFailed)
  767. {
  768. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  769. {
  770. foreach (Permanent permanent in player.GetFieldPermanents())
  771. {
  772. permanent.IsSuspended = permanent.oldIsTapped_playCard;
  773. }
  774. }
  775. foreach (CardSource cardSource in oldTrashCards)
  776. {
  777. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  778. {
  779. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  780. }
  781. }
  782. }
  783. }
  784. #endregion
  785. card.Owner.UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
  786. if (endPlayCard)
  787. {
  788. continue;
  789. }
  790. #region pay cost
  791. if (PayCost)
  792. {
  793. // memory lose
  794. if (Cost <= card.Owner.MaxMemoryCost)
  795. {
  796. yield return ContinuousController.instance.StartCoroutine(card.Owner.AddMemory(-1 * Cost, null));
  797. }
  798. ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
  799. }
  800. #endregion
  801. #region cut in effect after paying cost
  802. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(hashtable, EffectTiming.AfterPayCost));
  803. // cur in effect process
  804. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(
  805. false,
  806. AutoProcessing.HasExecutedSameEffect));
  807. #endregion
  808. // add to played cards
  809. playedCards_fixed.Add(card);
  810. }
  811. #region filter cards
  812. List<CardSource> permanentCards = playedCards_fixed.Filter(cardSource => cardSource.IsPermanent);
  813. List<CardSource> optionCards = playedCards_fixed.Filter(cardSource => !cardSource.IsPermanent);
  814. #region play permanent
  815. PlayPermanentClass playPermanent = new PlayPermanentClass(permanentCards, _hashtable, _targetPermanent, _isTapped, Root, _activateETB);
  816. if (isJogress)
  817. {
  818. playPermanent.SetJogress(_jogressEvoRootsFrameIDs);
  819. }
  820. if (burstDigivolved)
  821. {
  822. playPermanent.SetBurstDigivolved();
  823. }
  824. if (appFusion)
  825. playPermanent.SetAppFusion(_appFusionFrameIDs);
  826. if (_isBreedingArea)
  827. {
  828. playPermanent.SetIsBreedingArea();
  829. }
  830. yield return ContinuousController.instance.StartCoroutine(playPermanent.PlayPermanent());
  831. #endregion
  832. #region use option
  833. UseOptionClass useOption = new UseOptionClass(optionCards, _hashtable, Root)
  834. {
  835. _showEffect = _showEffect,
  836. _addSecurityEndOption = _addSecurityEndOption
  837. };
  838. yield return ContinuousController.instance.StartCoroutine(useOption.UseOption());
  839. #endregion
  840. #endregion
  841. }
  842. IEnumerator OffMemoryPredictionLine()
  843. {
  844. yield return new WaitForSeconds(0.5f);
  845. GManager.instance.memoryObject.OffMemoryPredictionLine();
  846. }
  847. }
  848. #endregion
  849. #region Hatch DigiEgg
  850. public class HatchDigiEggClass
  851. {
  852. public HatchDigiEggClass(Player player, Hashtable hashtable)
  853. {
  854. _player = player;
  855. _hashtable = hashtable;
  856. }
  857. Player _player { get; set; }
  858. Hashtable _hashtable { get; set; }
  859. public IEnumerator Hatch()
  860. {
  861. if (_player == null) yield break;
  862. if (!_player.CanHatch) yield break;
  863. CardSource card = _player.DigitamaLibraryCards[0];
  864. PlayPermanentClass playPermanentClass = new PlayPermanentClass(
  865. cardSources: new List<CardSource>() { card },
  866. hashtable: _hashtable,
  867. targetPermanent: null,
  868. isTapped: false,
  869. root: SelectCardEffect.Root.Library,
  870. ActivateETB: true);
  871. playPermanentClass.SetIsBreedingArea();
  872. playPermanentClass.SetIsHatching();
  873. yield return ContinuousController.instance.StartCoroutine(playPermanentClass.PlayPermanent());
  874. if (card.PermanentOfThisCard() != null)
  875. {
  876. card.PermanentOfThisCard().EnterFieldTurnCount = -1;
  877. }
  878. }
  879. }
  880. #endregion
  881. #region Play permanents
  882. #region Hashtable setting class
  883. public class OnEnterFieldHashtableParams
  884. {
  885. public OnEnterFieldHashtableParams(
  886. Permanent permanent,
  887. List<CardSource> evoRoots,
  888. List<CardSource> evoRootTops,
  889. SelectCardEffect.Root root,
  890. List<int> oldLevels,
  891. bool isFromDigimonDigivolutionCards)
  892. {
  893. Permanent = permanent;
  894. if (evoRoots != null)
  895. {
  896. EvoRoots = evoRoots.Clone();
  897. }
  898. if (evoRootTops != null)
  899. {
  900. EvoRootTops = evoRootTops.Clone();
  901. }
  902. Root = root;
  903. if (oldLevels != null)
  904. {
  905. OldLevels = oldLevels.Clone();
  906. }
  907. IsFromDigimonDigivolutionCards = isFromDigimonDigivolutionCards;
  908. }
  909. public Permanent Permanent { get; private set; } = null;
  910. public List<CardSource> EvoRoots = new List<CardSource>();
  911. public List<CardSource> EvoRootTops { get; private set; } = new List<CardSource>();
  912. public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
  913. public List<int> OldLevels { get; private set; } = new List<int>();
  914. public bool IsFromDigimonDigivolutionCards { get; private set; } = false;
  915. }
  916. #endregion
  917. public class PlayPermanentClass
  918. {
  919. public PlayPermanentClass(List<CardSource> cardSources, Hashtable hashtable, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root, bool ActivateETB)
  920. {
  921. if (cardSources != null)
  922. {
  923. _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  924. }
  925. _hashtable = hashtable;
  926. _targetPermanent = targetPermanent;
  927. _isTapped = isTapped;
  928. _root = root;
  929. _activateETB = ActivateETB;
  930. }
  931. public void SetJogress(int[] jogressEvoRootsFrameIDs)
  932. {
  933. if (jogressEvoRootsFrameIDs != null)
  934. {
  935. _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
  936. }
  937. }
  938. public void SetBurstDigivolved()
  939. {
  940. _burstDigivolved = true;
  941. }
  942. public void SetAppFusion(int[] appFusionFrameIDs)
  943. {
  944. if (appFusionFrameIDs != null)
  945. {
  946. _appFusionFrameIDs = appFusionFrameIDs.CloneArray();
  947. }
  948. _appFusion = true;
  949. }
  950. public void SetIsBreedingArea()
  951. {
  952. _isBreedingArea = true;
  953. }
  954. public void SetIsHatching()
  955. {
  956. _isHatching = true;
  957. }
  958. public void SetISPlayOption()
  959. {
  960. _isPlayOption = true;
  961. }
  962. List<CardSource> _cardSources = new List<CardSource>();
  963. Hashtable _hashtable = null;
  964. Permanent _targetPermanent = null;
  965. bool _isTapped = false;
  966. SelectCardEffect.Root _root = SelectCardEffect.Root.None;
  967. bool _activateETB = true;
  968. int[] _jogressEvoRootsFrameIDs = null;
  969. int _digiXrosCount = 0;
  970. int _assemblyCount = 0;
  971. bool _burstDigivolved = false;
  972. int[] _appFusionFrameIDs = null;
  973. bool _appFusion = false;
  974. bool _isBreedingArea = false;
  975. bool _isHatching = false;
  976. bool _isPlayOption = false;
  977. public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
  978. public bool isAppFusion => _appFusionFrameIDs != null && _appFusionFrameIDs.Length == 2;
  979. public IEnumerator PlayPermanent()
  980. {
  981. List<OnEnterFieldHashtableParams> hashtableParams = new List<OnEnterFieldHashtableParams>();
  982. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  983. bool isEvolution = false;
  984. foreach (CardSource card in _cardSources)
  985. {
  986. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  987. if (GManager.instance.GetComponent<SelectDigiXrosClass>().playCard == card)
  988. {
  989. _digiXrosCount = GManager.instance.GetComponent<SelectDigiXrosClass>().selectedDigicrossCards.Count;
  990. }
  991. if (GManager.instance.GetComponent<SelectAssemblyClass>().playCard == card)
  992. {
  993. _assemblyCount = GManager.instance.GetComponent<SelectAssemblyClass>().selectedAssemblyCards.Count;
  994. }
  995. bool isFromDigimonDigivolutionCards = card.Owner.GetFieldPermanents().Some((permanent) => permanent.DigivolutionCards.Contains(card));
  996. bool isFromSecurity = card.Owner.SecurityCards.Contains(card);
  997. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  998. GManager.instance.turnStateMachine.isSync = true;
  999. Permanent permanent = null;
  1000. isEvolution = false;
  1001. List<CardSource> evoRoots = new List<CardSource>();
  1002. List<CardSource> evoRootTops = new List<CardSource>();
  1003. bool played = false;
  1004. List<int> oldLevels = new List<int>();
  1005. int frameId = -1;
  1006. if (_targetPermanent == null)
  1007. {
  1008. if (_isBreedingArea)
  1009. {
  1010. if (card.Owner.GetBreedingAreaPermanents().Count == 0)
  1011. {
  1012. FieldCardFrame digieggFrame = card.Owner.fieldCardFrames.Find(fieldCardFrame =>
  1013. fieldCardFrame.IsEmptyFrame() &&
  1014. !fieldCardFrame.IsBattleAreaFrame());
  1015. if (digieggFrame != null)
  1016. {
  1017. if (_isHatching)
  1018. frameId = digieggFrame.FrameID;
  1019. else if(card.CanPlayCardTargetFrame(digieggFrame, false, CardEffect, isBreedingArea: _isBreedingArea))
  1020. frameId = digieggFrame.FrameID;
  1021. }
  1022. }
  1023. }
  1024. else
  1025. {
  1026. FieldCardFrame preferredFrame = card.PreferredFrame();
  1027. if (preferredFrame != null)
  1028. {
  1029. frameId = preferredFrame.FrameID;
  1030. }
  1031. }
  1032. }
  1033. else
  1034. {
  1035. frameId = _targetPermanent.PermanentFrame.FrameID;
  1036. }
  1037. if (!isJogress)
  1038. {
  1039. if (!(0 <= frameId && frameId < card.Owner.fieldCardFrames.Count))
  1040. {
  1041. foreach (FieldCardFrame fieldCardFrame in card.Owner.fieldCardFrames)
  1042. {
  1043. if (card.CanPlayCardTargetFrame(fieldCardFrame, false, CardEffect, isBreedingArea: _isBreedingArea))
  1044. {
  1045. if (fieldCardFrame.IsEmptyFrame())
  1046. {
  1047. frameId = fieldCardFrame.FrameID;
  1048. break;
  1049. }
  1050. }
  1051. }
  1052. }
  1053. if (0 <= frameId && frameId < card.Owner.fieldCardFrames.Count)
  1054. {
  1055. played = true;
  1056. if (_targetPermanent != null)
  1057. {
  1058. isEvolution = true;
  1059. }
  1060. else
  1061. {
  1062. if (!CardEffectCommons.CanPlayAsNewPermanent(card, false, CardEffect, isBreedingArea: _isBreedingArea, isPlayOption: _isPlayOption))
  1063. {
  1064. played = false;
  1065. }
  1066. if(_isHatching)
  1067. played = _isHatching;
  1068. }
  1069. if (played)
  1070. {
  1071. card.Init();
  1072. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1073. if (isEvolution)
  1074. {
  1075. oldLevels.Add(_targetPermanent.Level);
  1076. PlayLog.OnAddLog?.Invoke($"\nEvolution:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1077. permanent = _targetPermanent;
  1078. evoRoots.Add(_targetPermanent.TopCard);
  1079. evoRootTops.Add(_targetPermanent.TopCard);
  1080. permanent.AddCardSource(card);
  1081. }
  1082. else
  1083. {
  1084. if (card.IsToken)
  1085. PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity} token\n");
  1086. else
  1087. PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1088. permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = _isTapped };
  1089. yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, frameId));
  1090. permanent.EnterFieldTurnCount = GManager.instance.turnStateMachine.TurnCount;
  1091. }
  1092. GManager.instance.turnStateMachine.isSync = true;
  1093. if (GManager.instance.turnStateMachine.DoneStartGame)
  1094. {
  1095. if (!isEvolution)
  1096. {
  1097. #region wheter to have ETB effects
  1098. Hashtable hashtable = CardEffectCommons.OnEnterFieldHashtable(
  1099. hashtableParams: new List<OnEnterFieldHashtableParams>()
  1100. {
  1101. new OnEnterFieldHashtableParams(
  1102. permanent: permanent,
  1103. evoRoots: evoRoots,
  1104. evoRootTops: evoRootTops,
  1105. root: _root,
  1106. oldLevels: oldLevels,
  1107. isFromDigimonDigivolutionCards:isFromDigimonDigivolutionCards
  1108. )
  1109. },
  1110. isEvolution: isEvolution,
  1111. isJogress: isJogress,
  1112. digiXrosCount: _digiXrosCount,
  1113. assemblyCount: _assemblyCount,
  1114. cardEffect: CardEffect);
  1115. bool HasETB = permanent.EffectList(EffectTiming.OnEnterFieldAnyone).Some(cardEffect =>
  1116. cardEffect is ActivateICardEffect && cardEffect.CanUse(hashtable) && _activateETB && cardEffect.IsOnPlay);
  1117. #endregion
  1118. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, HasETB: HasETB, isDigiXros: _digiXrosCount >= 1));
  1119. }
  1120. else
  1121. {
  1122. bool isBlast = CardEffect != null && CardEffect.EffectName != null && CardEffect.EffectName.Contains("Blast");
  1123. //effect
  1124. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DigivolveFieldPermanentCardEffect(permanent.ShowingPermanentCard, _burstDigivolved, isBlast, _appFusion));
  1125. }
  1126. }
  1127. }
  1128. }
  1129. }
  1130. else
  1131. {
  1132. if (_jogressEvoRootsFrameIDs.Length == 2)
  1133. {
  1134. played = true;
  1135. card.Init();
  1136. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1137. isEvolution = true;
  1138. List<Permanent> evoRootPermanents = new List<Permanent>();
  1139. for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
  1140. {
  1141. int frameID = _jogressEvoRootsFrameIDs[i];
  1142. Permanent evoRoot = card.Owner.fieldCardFrames[frameID].GetFramePermanent();
  1143. if (evoRoot != null)
  1144. {
  1145. if (evoRoot.TopCard != null)
  1146. {
  1147. evoRootPermanents.Add(evoRoot);
  1148. }
  1149. }
  1150. }
  1151. int targetFrameID = evoRootPermanents[0].PermanentFrame.FrameID;
  1152. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1153. {
  1154. evoRoots.Add(evoRootPermanent.TopCard);
  1155. }
  1156. List<CardSource> newDigivolutionCards = evoRootPermanents
  1157. .Map(evoRootPermanent => evoRootPermanent.StackCards)
  1158. .Flat();
  1159. List<CardSource> linkCards = evoRootPermanents
  1160. .Map(evoRootPermanent => evoRootPermanent.LinkedCards)
  1161. .Flat();
  1162. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1163. {
  1164. oldLevels.Add(evoRootPermanent.Level);
  1165. evoRootTops.Add(evoRootPermanent.TopCard);
  1166. }
  1167. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1168. {
  1169. yield return ContinuousController.instance.StartCoroutine(evoRootPermanent.DiscardEvoRoots(ignoreOverflow: true, putToTrash: false));
  1170. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(evoRootPermanent, ignoreOverflow: true));
  1171. }
  1172. foreach(CardSource linkCard in linkCards)
  1173. {
  1174. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(linkCard));
  1175. }
  1176. PlayLog.OnAddLog?.Invoke($"\nJogress:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1177. permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = false };
  1178. yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, targetFrameID));
  1179. permanent.EnterFieldTurnCount = -1;
  1180. newDigivolutionCards.Reverse();
  1181. yield return ContinuousController.instance.StartCoroutine(permanent.AddDigivolutionCardsTop(newDigivolutionCards, null));
  1182. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, isDigiXros: false, jogressEvoRoots: evoRootTops.ToArray()));
  1183. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(evoRootTops, "DNA Digivolution Cards", true, true));
  1184. foreach (CardSource evolutionCard in permanent.DigivolutionCards)
  1185. {
  1186. evolutionCard.cEntity_EffectController.InitUseCountThisTurn();
  1187. }
  1188. }
  1189. }
  1190. if (played)
  1191. {
  1192. if (isFromSecurity)
  1193. {
  1194. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  1195. player: card.Owner,
  1196. refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
  1197. CardEffectCommons.GetCardEffectFromHashtable(_hashtable)).ReduceSecurity());
  1198. }
  1199. if (isEvolution)
  1200. {
  1201. card.Owner.DigivolveCount_ThisTurn++;
  1202. yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, null).Draw());
  1203. if (_burstDigivolved)
  1204. {
  1205. if (permanent.TopCard != null)
  1206. {
  1207. permanent.IsBurstDigivolved = true;
  1208. GManager.instance.selectBurstDigivolutionEffect.AddTrashTopCardAtTurnEnd(permanent);
  1209. }
  1210. }
  1211. if (_appFusion)
  1212. {
  1213. if (permanent.TopCard != null)
  1214. {
  1215. permanent.IsAppFusion = true;
  1216. }
  1217. }
  1218. permanent.CardNamesJustAfterDigivolved = permanent.TopCard.CardNames.Clone();
  1219. permanent.DigivolvingEffect = CardEffect;
  1220. }
  1221. else
  1222. {
  1223. permanent.PlayingEffect = CardEffect;
  1224. if (permanent.TopCard.HasLevel)
  1225. {
  1226. permanent.LevelJustAfterPlayed = permanent.Level;
  1227. }
  1228. if (permanent.TopCard.HasPlayCost)
  1229. {
  1230. permanent.PlayCostJustAfterPlayed = permanent.TopCard.GetCostItself;
  1231. }
  1232. permanent.CardNamesJustAfterPlayed = permanent.TopCard.CardNames.Clone();
  1233. permanent.TraitsJustAfterPlayed = permanent.TopCard.CardTraits.Clone();
  1234. }
  1235. #region move permanents (hybrid)
  1236. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  1237. {
  1238. if (permanent.TopCard.PreferredFrame() != null)
  1239. {
  1240. if (permanent.PermanentFrame != permanent.TopCard.PreferredFrame())
  1241. {
  1242. if (permanent.TopCard.PreferredFrame().IsEmptyFrame())
  1243. {
  1244. bool move = false;
  1245. if (permanent.IsDigimon)
  1246. {
  1247. if (permanent.TopCard.Owner.isYou)
  1248. {
  1249. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1250. {
  1251. move = true;
  1252. }
  1253. }
  1254. else
  1255. {
  1256. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1257. {
  1258. move = true;
  1259. }
  1260. }
  1261. }
  1262. else if (permanent.IsTamer || permanent.TopCard.IsOption)
  1263. {
  1264. if (permanent.TopCard.Owner.isYou)
  1265. {
  1266. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1267. {
  1268. move = true;
  1269. }
  1270. }
  1271. else
  1272. {
  1273. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1274. {
  1275. move = true;
  1276. }
  1277. }
  1278. }
  1279. if (move)
  1280. {
  1281. yield return ContinuousController.instance.StartCoroutine(CardObjectController.MovePermanent(permanent.PermanentFrame));
  1282. }
  1283. }
  1284. }
  1285. }
  1286. }
  1287. #endregion
  1288. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCardsByEffect(card);
  1289. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCards(card);
  1290. yield return GManager.instance.GetComponent<SelectAssemblyClass>().AddDigivolutiuonCardsByEffect(card);
  1291. yield return GManager.instance.GetComponent<SelectAssemblyClass>().AddDigivolutiuonCards(card);
  1292. if (GManager.instance.turnStateMachine.DoneStartGame)
  1293. {
  1294. hashtableParams.Add(
  1295. new OnEnterFieldHashtableParams(
  1296. permanent: permanent,
  1297. evoRoots: evoRoots,
  1298. evoRootTops: evoRootTops,
  1299. root: _root,
  1300. oldLevels: oldLevels,
  1301. isFromDigimonDigivolutionCards: isFromDigimonDigivolutionCards
  1302. )
  1303. );
  1304. }
  1305. }
  1306. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  1307. GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
  1308. GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
  1309. yield return GManager.instance.photonWaitController.StartWait("EndPlayPermanent");
  1310. }
  1311. // except [On Play] effect
  1312. bool CardEffectCondition(ICardEffect cardEffect)
  1313. {
  1314. if (cardEffect == null)
  1315. {
  1316. return false;
  1317. }
  1318. if (!_activateETB)
  1319. {
  1320. if (cardEffect is ActivateICardEffect)
  1321. {
  1322. if (cardEffect.IsOnPlay)
  1323. {
  1324. return false;
  1325. }
  1326. }
  1327. }
  1328. return true;
  1329. }
  1330. Hashtable effectHashtable = CardEffectCommons.OnEnterFieldHashtable(
  1331. hashtableParams: hashtableParams,
  1332. isEvolution: isEvolution,
  1333. isJogress: isJogress,
  1334. digiXrosCount: _digiXrosCount,
  1335. assemblyCount: _assemblyCount,
  1336. cardEffect: CardEffect);
  1337. #region "When permanents are played" effect
  1338. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  1339. hashtable: effectHashtable,
  1340. timing: EffectTiming.OnEnterFieldAnyone,
  1341. cardEffectCondition: CardEffectCondition));
  1342. #endregion
  1343. }
  1344. }
  1345. #endregion
  1346. #region Use option
  1347. public class UseOptionClass
  1348. {
  1349. public UseOptionClass(List<CardSource> cardSources, Hashtable hashtable, SelectCardEffect.Root root)
  1350. {
  1351. if (cardSources != null)
  1352. {
  1353. _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  1354. }
  1355. _hashtable = hashtable;
  1356. _root = root;
  1357. }
  1358. List<CardSource> _cardSources = new List<CardSource>();
  1359. SelectCardEffect.Root _root = SelectCardEffect.Root.None;
  1360. Hashtable _hashtable = null;
  1361. public bool _showEffect = false;
  1362. public bool _addSecurityEndOption = false;
  1363. public IEnumerator UseOption()
  1364. {
  1365. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1366. foreach (CardSource card in _cardSources)
  1367. {
  1368. if (_showEffect)
  1369. {
  1370. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(card));
  1371. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowUseHandCardEffect_PlayCard(card));
  1372. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  1373. }
  1374. PlayLog.OnAddLog?.Invoke($"\nPlay Option:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1375. card.Init();
  1376. GManager.instance.turnStateMachine.isSync = true;
  1377. card.SetFace();
  1378. int cost = card.GetCostItself;
  1379. //Remove from all areas
  1380. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1381. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(card));
  1382. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.BrainStormCoroutine(card));
  1383. #region Set HashTable
  1384. Hashtable hashtable = new Hashtable()
  1385. {
  1386. {"Card", card},
  1387. {"Root", _root},
  1388. {"Cost", cost},
  1389. };
  1390. #endregion
  1391. #region "When option is used" effect
  1392. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseOption));
  1393. yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.OnUseOption));
  1394. #endregion
  1395. #region effect process of option card
  1396. foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.OptionSkill))
  1397. {
  1398. if (cardEffect is ActivateICardEffect)
  1399. {
  1400. if (cardEffect.CanUse(hashtable))
  1401. {
  1402. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  1403. cardEffect,
  1404. hashtable));
  1405. }
  1406. }
  1407. }
  1408. #endregion
  1409. if (card.Owner.ExecutingCards.Contains(card))
  1410. {
  1411. if (_addSecurityEndOption && card.Owner.CanAddSecurity(CardEffect))
  1412. {
  1413. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(card));
  1414. }
  1415. else
  1416. {
  1417. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(card));
  1418. }
  1419. }
  1420. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  1421. yield return GManager.instance.photonWaitController.StartWait("EndPlayOption");
  1422. }
  1423. }
  1424. }
  1425. #endregion
  1426. #region Draw cards
  1427. public class DrawClass
  1428. {
  1429. public DrawClass(Player player, int drawCount, ICardEffect cardEffect)
  1430. {
  1431. _player = player;
  1432. _drawCount = drawCount;
  1433. _cardEffect = cardEffect;
  1434. }
  1435. Player _player = null;
  1436. int _drawCount = 0;
  1437. ICardEffect _cardEffect = null;
  1438. public IEnumerator Draw()
  1439. {
  1440. if (_drawCount <= 0) yield break;
  1441. if (_player.LibraryCards.Count <= 0) yield break;
  1442. List<CardSource> DrawCards = new List<CardSource>();
  1443. for (int i = 0; i < _drawCount; i++)
  1444. {
  1445. if (_player.LibraryCards.Count > 0)
  1446. {
  1447. CardSource DrawCard = _player.LibraryCards[0];
  1448. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(DrawCard));
  1449. DrawCards.Add(DrawCard);
  1450. }
  1451. }
  1452. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(DrawCards, true, _cardEffect));
  1453. #region add log
  1454. if (DrawCards.Count >= 1)
  1455. {
  1456. PlayLog.OnAddLog?.Invoke($"\nDraw {DrawCards.Count} card{Utils.PluralFormSuffix(DrawCards.Count)}\n{_player.PlayerName}\n");
  1457. }
  1458. #endregion
  1459. #region "When draw cards" effect
  1460. if (DrawCards.Count >= 1)
  1461. {
  1462. #region Hashtable setting
  1463. Hashtable _hashtable = new Hashtable()
  1464. {
  1465. {"Player", _player},
  1466. {"CardEffect", _cardEffect}
  1467. };
  1468. #endregion
  1469. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnDraw));
  1470. }
  1471. #endregion
  1472. }
  1473. }
  1474. #endregion
  1475. #region Trash cards from deck too
  1476. public class IAddTrashCardsFromLibraryTop
  1477. {
  1478. public IAddTrashCardsFromLibraryTop(int addTrashCount, Player player, ICardEffect cardEffect)
  1479. {
  1480. _addTrashCount = addTrashCount;
  1481. _player = player;
  1482. _cardEffect = cardEffect;
  1483. }
  1484. public void SetNotShowCards()
  1485. {
  1486. _notShowCards = true;
  1487. }
  1488. int _addTrashCount;
  1489. Player _player;
  1490. public List<CardSource> discardedCards = new List<CardSource>();
  1491. ICardEffect _cardEffect { get; set; } = null;
  1492. bool _notShowCards = false;
  1493. public IEnumerator AddTrashCardsFromLibraryTop()
  1494. {
  1495. if (_addTrashCount <= 0) yield break;
  1496. if (_player.LibraryCards.Count == 0) yield break;
  1497. string log = "";
  1498. log += $"\nTrash cards from deck :";
  1499. for (int i = 0; i < _addTrashCount; i++)
  1500. {
  1501. if (_player.LibraryCards.Count > i)
  1502. {
  1503. CardSource DiscardCard = _player.LibraryCards[i];
  1504. discardedCards.Add(DiscardCard);
  1505. log += $"\n{DiscardCard.BaseENGCardNameFromEntity}({DiscardCard.CardID})";
  1506. }
  1507. }
  1508. if (discardedCards.Count >= 1)
  1509. {
  1510. if (!_notShowCards)
  1511. {
  1512. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  1513. }
  1514. }
  1515. yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(discardedCards, _cardEffect).TrashDeckCards());
  1516. if (discardedCards.Count >= 1)
  1517. {
  1518. for (int i = 0; i < discardedCards.Count; i++)
  1519. {
  1520. ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
  1521. yield return new WaitForSeconds(0.06f);
  1522. }
  1523. log += "\n";
  1524. PlayLog.OnAddLog?.Invoke(log);
  1525. }
  1526. }
  1527. }
  1528. #endregion
  1529. #region Add security from deck top
  1530. public class IAddSecurityFromLibrary
  1531. {
  1532. public IAddSecurityFromLibrary(Player player, int addLifeCount)
  1533. {
  1534. _player = player;
  1535. _addSecurityCount = addLifeCount;
  1536. }
  1537. Player _player = null;
  1538. int _addSecurityCount = 0;
  1539. public IEnumerator AddSecurity()
  1540. {
  1541. int count = 0;
  1542. for (int i = 0; i < _addSecurityCount; i++)
  1543. {
  1544. if (_player.LibraryCards.Count > 0)
  1545. {
  1546. CardSource StockCard = _player.LibraryCards[0];
  1547. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(StockCard, useEffect: (i == 0)));
  1548. count++;
  1549. }
  1550. }
  1551. if (count > 0)
  1552. {
  1553. string log = "";
  1554. log += $"\nAdd {count} cards to security:{_player.PlayerName}";
  1555. log += "\n";
  1556. PlayLog.OnAddLog?.Invoke(log);
  1557. }
  1558. }
  1559. }
  1560. #endregion
  1561. #region Recovery
  1562. public class IRecovery
  1563. {
  1564. public IRecovery(Player player, int AddLifeCount, ICardEffect cardEffect)
  1565. {
  1566. _player = player;
  1567. _addLifeCount = AddLifeCount;
  1568. _cardEffect = cardEffect;
  1569. }
  1570. Player _player = null;
  1571. int _addLifeCount = 0;
  1572. ICardEffect _cardEffect = null;
  1573. public IEnumerator Recovery()
  1574. {
  1575. if (_player.LibraryCards.Count == 0) yield break;
  1576. if (_addLifeCount <= 0) yield break;
  1577. if (!_player.CanAddSecurity(_cardEffect)) yield break;
  1578. yield return ContinuousController.instance.StartCoroutine(new IAddSecurityFromLibrary(_player, _addLifeCount).AddSecurity());
  1579. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(_player));
  1580. }
  1581. }
  1582. #endregion
  1583. #region Digi-Burst
  1584. public class IDigiBurst
  1585. {
  1586. public IDigiBurst(Permanent permanent, int DigiBurstCount, ICardEffect cardEffect)
  1587. {
  1588. _permanent = permanent;
  1589. _digiBurstCount = DigiBurstCount;
  1590. _cardEffect = cardEffect;
  1591. }
  1592. Permanent _permanent = null;
  1593. int _digiBurstCount = 0;
  1594. ICardEffect _cardEffect = null;
  1595. bool _upToMaxCount = false;
  1596. public List<CardSource> discardedCards = new List<CardSource>();
  1597. public void SetUpToMaxCount()
  1598. {
  1599. _upToMaxCount = true;
  1600. }
  1601. public bool CanDigiBurst()
  1602. {
  1603. if (_permanent != null)
  1604. {
  1605. if (_permanent.TopCard != null)
  1606. {
  1607. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) return false;
  1608. if (_upToMaxCount)
  1609. {
  1610. if (_permanent.DigivolutionCards.Some((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)))
  1611. {
  1612. return true;
  1613. }
  1614. }
  1615. else
  1616. {
  1617. if (_permanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)) >= _digiBurstCount)
  1618. {
  1619. return true;
  1620. }
  1621. }
  1622. }
  1623. }
  1624. return false;
  1625. }
  1626. public IEnumerator DigiBurst()
  1627. {
  1628. if (CanDigiBurst())
  1629. {
  1630. discardedCards = new List<CardSource>();
  1631. List<CardSource> selectedCards = new List<CardSource>();
  1632. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  1633. selectCardEffect.SetUp(
  1634. canTargetCondition: (cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect),
  1635. canTargetCondition_ByPreSelecetedList: null,
  1636. canEndSelectCondition: CanEndSelectCondition,
  1637. canNoSelect: () => false,
  1638. selectCardCoroutine: SelectCardCoroutine,
  1639. afterSelectCardCoroutine: null,
  1640. message: "Select digivolution cards to discard.",
  1641. maxCount: _digiBurstCount,
  1642. canEndNotMax: _upToMaxCount,
  1643. isShowOpponent: true,
  1644. mode: SelectCardEffect.Mode.Custom,
  1645. root: SelectCardEffect.Root.Custom,
  1646. customRootCardList: _permanent.DigivolutionCards,
  1647. canLookReverseCard: true,
  1648. selectPlayer: _permanent.TopCard.Owner,
  1649. cardEffect: null);
  1650. selectCardEffect.SetUseFaceDown();
  1651. selectCardEffect.SetUpCustomMessage("Select digivolution cards to discard.", "The opponent is selecting digivolution cards to discard.");
  1652. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  1653. bool CanEndSelectCondition(List<CardSource> cardSources)
  1654. {
  1655. if (CardEffectCommons.HasNoElement(cardSources))
  1656. {
  1657. return false;
  1658. }
  1659. return true;
  1660. }
  1661. IEnumerator SelectCardCoroutine(CardSource cardSource)
  1662. {
  1663. selectedCards.Add(cardSource);
  1664. yield return null;
  1665. }
  1666. if (selectedCards.Count >= 1)
  1667. {
  1668. #region "When use Digi-Burst" effect
  1669. #region Hashtable setting
  1670. Hashtable hashtable = new Hashtable()
  1671. {
  1672. {"Permanent", _permanent},
  1673. {"CardEffect", _cardEffect},
  1674. };
  1675. #endregion
  1676. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseDigiburst));
  1677. #endregion
  1678. // trash digivolution cards
  1679. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(_permanent, selectedCards, _cardEffect).TrashDigivolutionCards());
  1680. foreach (CardSource cardSource in selectedCards)
  1681. {
  1682. discardedCards.Add(cardSource);
  1683. }
  1684. #region add log
  1685. if (selectedCards.Count >= 1)
  1686. {
  1687. string log = "";
  1688. log += $"\nDigiburst :";
  1689. foreach (CardSource cardSource in selectedCards)
  1690. {
  1691. if (cardSource != null)
  1692. {
  1693. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  1694. }
  1695. }
  1696. log += "\n";
  1697. PlayLog.OnAddLog?.Invoke(log);
  1698. }
  1699. #endregion
  1700. }
  1701. }
  1702. }
  1703. }
  1704. #endregion
  1705. #region Place permanents to deck bottom
  1706. public class DeckBottomBounceClass
  1707. {
  1708. public DeckBottomBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
  1709. {
  1710. _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
  1711. _hashtable = hashtable;
  1712. }
  1713. public void SetNotShowCards()
  1714. {
  1715. _notShowCards = true;
  1716. }
  1717. public bool IsDeckBounced(Permanent permanent)
  1718. {
  1719. return DeckBouncedPermanents.Contains(permanent);
  1720. }
  1721. List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
  1722. public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
  1723. Hashtable _hashtable = new Hashtable();
  1724. bool _notShowCards = false;
  1725. public IEnumerator DeckBounce()
  1726. {
  1727. if (_deckBounceTargetPermanents == null) yield break;
  1728. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1729. _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
  1730. permanent != null
  1731. && permanent.TopCard != null
  1732. && (cardEffect == null ||
  1733. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1734. && !permanent.CannotReturnToLibrary(cardEffect)
  1735. && permanent.CanBeRemoved())));
  1736. if (_deckBounceTargetPermanents.Count == 0) yield break;
  1737. _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1738. #region cut in effect
  1739. // "When permanents would return to deck" effect
  1740. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1741. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1742. _deckBounceTargetPermanents,
  1743. cardEffect,
  1744. null
  1745. ),
  1746. EffectTiming.WhenReturntoLibraryAnyone));
  1747. // "When permanents would remove field" effect
  1748. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1749. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1750. _deckBounceTargetPermanents,
  1751. cardEffect,
  1752. null
  1753. ),
  1754. EffectTiming.WhenRemoveField));
  1755. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1756. {
  1757. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1758. {
  1759. permanent.ShowDeckBounceEffect();
  1760. }
  1761. // cut in effect process
  1762. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1763. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1764. {
  1765. permanent.HideDeckBounceEffect();
  1766. }
  1767. }
  1768. #endregion
  1769. // fix deck bounce target permanents
  1770. List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
  1771. permanent != null
  1772. && permanent.TopCard != null
  1773. && permanent.willBeRemoveField);
  1774. #region show cards
  1775. List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1776. if (!_notShowCards)
  1777. {
  1778. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
  1779. }
  1780. #endregion
  1781. #region "When permanents leave the battle area" effect
  1782. if (deckBounceTargetPermanents_Fixed.Count > 0) yield return ContinuousController.instance.StartCoroutine(
  1783. GManager.instance.autoProcessing.StackSkillInfos(
  1784. CardEffectCommons.OnDeletionHashtable(
  1785. deckBounceTargetPermanents_Fixed,
  1786. cardEffect,
  1787. null,
  1788. false
  1789. ),
  1790. EffectTiming.OnLeaveFieldAnyone));
  1791. #endregion
  1792. #region
  1793. List<CardSource> deckBottomCards = new List<CardSource>();
  1794. foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
  1795. {
  1796. #region recoed used effect
  1797. if (permanent.TopCard != null)
  1798. {
  1799. permanent.LibraryBounceEffect = cardEffect;
  1800. }
  1801. #endregion
  1802. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
  1803. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1804. CardSource topCard = permanent.TopCard;
  1805. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1806. deckBottomCards.Add(topCard);
  1807. DeckBouncedPermanents.Add(permanent);
  1808. }
  1809. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(deckBottomCards));
  1810. #endregion
  1811. #region off icon
  1812. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1813. {
  1814. if (permanent != null)
  1815. {
  1816. if (permanent.TopCard != null)
  1817. {
  1818. permanent.willBeRemoveField = false;
  1819. }
  1820. }
  1821. }
  1822. #endregion
  1823. }
  1824. }
  1825. #endregion
  1826. #region Place permanents to deck top
  1827. public class DeckTopBounceClass
  1828. {
  1829. public DeckTopBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
  1830. {
  1831. _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
  1832. _hashtable = hashtable;
  1833. }
  1834. public void SetNotShowCards()
  1835. {
  1836. _notShowCards = true;
  1837. }
  1838. public bool IsDeckBounced(Permanent permanent)
  1839. {
  1840. return DeckBouncedPermanents.Contains(permanent);
  1841. }
  1842. List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
  1843. public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
  1844. Hashtable _hashtable = new Hashtable();
  1845. bool _notShowCards = false;
  1846. public IEnumerator DeckBounce()
  1847. {
  1848. if (_deckBounceTargetPermanents == null) yield break;
  1849. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1850. _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
  1851. permanent != null
  1852. && permanent.TopCard != null
  1853. && (cardEffect == null ||
  1854. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1855. && !permanent.CannotReturnToLibrary(cardEffect)
  1856. && permanent.CanBeRemoved())));
  1857. if (_deckBounceTargetPermanents.Count == 0) yield break;
  1858. _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1859. #region cut in effect
  1860. // "When permanents would return to deck" effect
  1861. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1862. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1863. _deckBounceTargetPermanents,
  1864. cardEffect,
  1865. null
  1866. ),
  1867. EffectTiming.WhenReturntoLibraryAnyone));
  1868. // "When permanents would remove field" effect
  1869. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1870. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1871. _deckBounceTargetPermanents,
  1872. cardEffect,
  1873. null
  1874. ),
  1875. EffectTiming.WhenRemoveField));
  1876. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1877. {
  1878. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1879. {
  1880. permanent.ShowDeckBounceEffect();
  1881. }
  1882. // cut in effect process
  1883. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1884. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1885. {
  1886. permanent.HideDeckBounceEffect();
  1887. }
  1888. }
  1889. #endregion
  1890. // fix deck bounce target permanents
  1891. List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
  1892. permanent != null
  1893. && permanent.TopCard != null
  1894. && permanent.willBeRemoveField);
  1895. #region show cards
  1896. List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1897. if (!_notShowCards)
  1898. {
  1899. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
  1900. }
  1901. #endregion
  1902. #region "When permanents leave the battle area" effect
  1903. if (deckBounceTargetPermanents_Fixed.Count > 0) yield return ContinuousController.instance.StartCoroutine(
  1904. GManager.instance.autoProcessing.StackSkillInfos(
  1905. CardEffectCommons.OnDeletionHashtable(
  1906. deckBounceTargetPermanents_Fixed,
  1907. cardEffect,
  1908. null,
  1909. false
  1910. ),
  1911. EffectTiming.OnLeaveFieldAnyone));
  1912. #endregion
  1913. #region
  1914. List<CardSource> deckTopCards = new List<CardSource>();
  1915. foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
  1916. {
  1917. #region recoed used effect
  1918. if (permanent.TopCard != null)
  1919. {
  1920. permanent.LibraryBounceEffect = cardEffect;
  1921. }
  1922. #endregion
  1923. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
  1924. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1925. CardSource topCard = permanent.TopCard;
  1926. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1927. deckTopCards.Add(topCard);
  1928. DeckBouncedPermanents.Add(permanent);
  1929. }
  1930. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryTopCards(deckTopCards));
  1931. #endregion
  1932. #region off icon
  1933. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1934. {
  1935. if (permanent != null)
  1936. {
  1937. if (permanent.TopCard != null)
  1938. {
  1939. permanent.willBeRemoveField = false;
  1940. }
  1941. }
  1942. }
  1943. #endregion
  1944. }
  1945. }
  1946. #endregion
  1947. #region Return permanent to hand
  1948. public class HandBounceClaass
  1949. {
  1950. public HandBounceClaass(List<Permanent> bounceTargetPermanents, Hashtable hashtable)
  1951. {
  1952. _bounceTargetPermanents = bounceTargetPermanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  1953. _hashtable = hashtable;
  1954. }
  1955. public bool IsBounced(Permanent permanent)
  1956. {
  1957. return BouncedPermanents.Contains(permanent);
  1958. }
  1959. List<Permanent> _bounceTargetPermanents = new List<Permanent>();
  1960. public List<Permanent> BouncedPermanents { get; private set; } = new List<Permanent>();
  1961. Hashtable _hashtable = new Hashtable();
  1962. bool _notShowCards = false;
  1963. public IEnumerator Bounce()
  1964. {
  1965. if (_bounceTargetPermanents == null) yield break;
  1966. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1967. _bounceTargetPermanents = _bounceTargetPermanents.Filter(permanent =>
  1968. permanent != null
  1969. && permanent.TopCard != null
  1970. && (cardEffect == null ||
  1971. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1972. && !permanent.CannotReturnToHand(cardEffect)
  1973. && permanent.CanBeRemoved())));
  1974. if (_bounceTargetPermanents.Count == 0) yield break;
  1975. _bounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1976. #region cut in effect
  1977. // "When permanents would return to hand" effect
  1978. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1979. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1980. _bounceTargetPermanents,
  1981. cardEffect,
  1982. null
  1983. ),
  1984. EffectTiming.WhenReturntoHandAnyone));
  1985. // "When permanents would remove field" effect
  1986. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1987. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1988. _bounceTargetPermanents,
  1989. cardEffect,
  1990. null
  1991. ),
  1992. EffectTiming.WhenRemoveField));
  1993. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1994. {
  1995. foreach (Permanent permanent in _bounceTargetPermanents)
  1996. {
  1997. permanent.ShowHandBounceEffect();
  1998. }
  1999. // shrink security Digimon display
  2000. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2001. // cut in effect process
  2002. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2003. foreach (Permanent permanent in _bounceTargetPermanents)
  2004. {
  2005. permanent.HideHandBounceEffect();
  2006. }
  2007. }
  2008. #endregion
  2009. // fix bounce target permanents
  2010. List<Permanent> bounceTargetPermanents_Fixed = _bounceTargetPermanents.Filter(permanent =>
  2011. permanent != null
  2012. && permanent.TopCard != null
  2013. && permanent.willBeRemoveField);
  2014. #region "When permanents returned to hand" effect
  2015. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2016. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2017. bounceTargetPermanents_Fixed,
  2018. cardEffect,
  2019. null,
  2020. false
  2021. ),
  2022. EffectTiming.OnPermamemtReturnedToHand));
  2023. #endregion
  2024. #region "When permanents leave the battle area" effect
  2025. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2026. CardEffectCommons.OnDeletionHashtable(
  2027. bounceTargetPermanents_Fixed,
  2028. cardEffect,
  2029. null,
  2030. false
  2031. ),
  2032. EffectTiming.OnLeaveFieldAnyone));
  2033. #endregion
  2034. #region record parameter just before bounce
  2035. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  2036. {
  2037. permanent.DPJustBeforeRemoveField = permanent.DP;
  2038. if (permanent.TopCard.HasLevel)
  2039. {
  2040. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2041. }
  2042. if (permanent.TopCard.HasPlayCost)
  2043. {
  2044. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  2045. }
  2046. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  2047. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  2048. foreach (CardSource cardSource in permanent.cardSources)
  2049. {
  2050. cardSource.PermanentJustBeforeRemoveField = permanent;
  2051. }
  2052. }
  2053. #endregion
  2054. #region add log
  2055. if (bounceTargetPermanents_Fixed.Count >= 1)
  2056. {
  2057. string log = "";
  2058. log += $"\nReturn to hand:";
  2059. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  2060. {
  2061. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  2062. }
  2063. log += "\n";
  2064. PlayLog.OnAddLog?.Invoke(log);
  2065. }
  2066. #endregion
  2067. #region show cards
  2068. List<CardSource> returnedCards = bounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2069. if (!_notShowCards)
  2070. {
  2071. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Cards returned to hand", true, true));
  2072. }
  2073. #endregion
  2074. #region return permanent cards to hand
  2075. List<CardSource> handCards = new List<CardSource>();
  2076. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  2077. {
  2078. #region record used effect
  2079. if (permanent.TopCard != null)
  2080. {
  2081. permanent.HandBounceEffect = cardEffect;
  2082. }
  2083. #endregion
  2084. // record whether to return to hand by Burst Digivolution
  2085. permanent.IsReturnedToHandByBurstDigivolution = CardEffectCommons.IsBurst(_hashtable);
  2086. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BounceEffect(permanent, !permanent.IsReturnedToHandByBurstDigivolution));
  2087. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2088. CardSource topCard = permanent.TopCard;
  2089. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2090. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(topCard));
  2091. if (!topCard.IsDigiEgg)
  2092. {
  2093. handCards.Add(topCard);
  2094. BouncedPermanents.Add(permanent);
  2095. }
  2096. else
  2097. {
  2098. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2099. }
  2100. }
  2101. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
  2102. #endregion
  2103. #region hide icon
  2104. foreach (Permanent permanent in _bounceTargetPermanents)
  2105. {
  2106. if (permanent != null)
  2107. {
  2108. if (permanent.TopCard != null)
  2109. {
  2110. permanent.willBeRemoveField = false;
  2111. }
  2112. }
  2113. }
  2114. #endregion
  2115. }
  2116. }
  2117. #endregion
  2118. #region Place permanent to another permanent's digivolution cards
  2119. public class IPlacePermanentToDigivolutionCards
  2120. {
  2121. public IPlacePermanentToDigivolutionCards(
  2122. List<Permanent[]> permanentArrays,
  2123. bool toTop,
  2124. ICardEffect cardEffect,
  2125. bool skipEffectAndActivateSkill = false,
  2126. bool isDigixros = false)
  2127. {
  2128. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  2129. _toTop = toTop;
  2130. _cardEffect = cardEffect;
  2131. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  2132. _isDigixros = isDigixros;
  2133. }
  2134. public void SetNotShowCards()
  2135. {
  2136. _notShowCards = true;
  2137. }
  2138. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  2139. ICardEffect _cardEffect = null;
  2140. bool _toTop = false;
  2141. bool _notShowCards = false;
  2142. bool _skipEffectAndActivateSkill = false;
  2143. bool _isDigixros = false;
  2144. public bool Placed { get; private set; } = false;
  2145. public IEnumerator PlacePermanentToDigivolutionCards()
  2146. {
  2147. if (_permanentArrays.Count == 0)
  2148. {
  2149. yield break;
  2150. }
  2151. List<CardSource> addedDigivolutionCards = new List<CardSource>();
  2152. List<Permanent> removeFieldPermanents = new List<Permanent>();
  2153. foreach (Permanent[] permanentArray in _permanentArrays)
  2154. {
  2155. if (permanentArray.Length == 2)
  2156. {
  2157. Permanent DigivolutionPermanent = permanentArray[0];
  2158. Permanent getDigivolutionPermanent = permanentArray[1];
  2159. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  2160. {
  2161. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
  2162. {
  2163. if (_cardEffect != null)
  2164. {
  2165. if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
  2166. {
  2167. continue;
  2168. }
  2169. }
  2170. removeFieldPermanents.Add(DigivolutionPermanent);
  2171. }
  2172. }
  2173. }
  2174. }
  2175. foreach (Permanent permanent in removeFieldPermanents)
  2176. {
  2177. permanent.willBeRemoveField = true;
  2178. }
  2179. if (removeFieldPermanents.Count == 0)
  2180. {
  2181. yield break;
  2182. }
  2183. #region
  2184. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2185. Hashtable hashtable1 =
  2186. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2187. removeFieldPermanents,
  2188. _cardEffect,
  2189. null,
  2190. _isDigixros);
  2191. #region "When permanents would remove field" effect
  2192. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2193. {
  2194. #region permanents' effects
  2195. foreach (Permanent permanent1 in player.GetFieldPermanents())
  2196. {
  2197. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  2198. {
  2199. if (cardEffect is ActivateICardEffect)
  2200. {
  2201. if (cardEffect.CanTrigger(hashtable1))
  2202. {
  2203. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2204. }
  2205. }
  2206. }
  2207. }
  2208. #endregion
  2209. #region players' effects
  2210. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  2211. {
  2212. if (cardEffect is ActivateICardEffect)
  2213. {
  2214. if (cardEffect.CanTrigger(hashtable1))
  2215. {
  2216. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2217. }
  2218. }
  2219. }
  2220. #endregion
  2221. }
  2222. #endregion
  2223. if (skillInfos.Count >= 1)
  2224. {
  2225. foreach (SkillInfo skillInfo in skillInfos)
  2226. {
  2227. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  2228. }
  2229. bool showEffect()
  2230. {
  2231. if (skillInfos.Count >= 2)
  2232. {
  2233. return true;
  2234. }
  2235. else if (skillInfos.Count == 1)
  2236. {
  2237. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  2238. {
  2239. return true;
  2240. }
  2241. }
  2242. return false;
  2243. }
  2244. if (showEffect())
  2245. {
  2246. foreach (Permanent Permanent in removeFieldPermanents)
  2247. {
  2248. if (Permanent != null)
  2249. {
  2250. if (Permanent.TopCard != null)
  2251. {
  2252. if (Permanent.willBeRemoveField)
  2253. {
  2254. if (Permanent.ShowingPermanentCard != null)
  2255. {
  2256. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2257. {
  2258. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  2259. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  2260. }
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. #region shrink security Digimon display
  2267. if (GManager.instance.attackProcess.IsAttacking)
  2268. {
  2269. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2270. {
  2271. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2272. {
  2273. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2274. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2275. }
  2276. }
  2277. }
  2278. #endregion
  2279. }
  2280. // cut in effect process
  2281. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2282. foreach (Permanent Permanent in removeFieldPermanents)
  2283. {
  2284. if (Permanent != null)
  2285. {
  2286. if (Permanent.TopCard != null)
  2287. {
  2288. if (Permanent.ShowingPermanentCard != null)
  2289. {
  2290. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2291. {
  2292. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  2293. }
  2294. }
  2295. }
  2296. }
  2297. }
  2298. }
  2299. #endregion
  2300. foreach (Permanent[] permanentArray in _permanentArrays)
  2301. {
  2302. if (permanentArray.Length == 2)
  2303. {
  2304. Permanent DigivolutionPermanent = permanentArray[0];
  2305. Permanent getDigivolutionPermanent = permanentArray[1];
  2306. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  2307. {
  2308. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
  2309. {
  2310. yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
  2311. CardSource cardSource = DigivolutionPermanent.TopCard;
  2312. #region record used effect
  2313. if (_cardEffect != null)
  2314. {
  2315. if (DigivolutionPermanent.TopCard != null)
  2316. {
  2317. DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
  2318. }
  2319. }
  2320. #endregion
  2321. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  2322. DigivolutionPermanent,
  2323. ignoreOverflow: true));
  2324. List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
  2325. if (_toTop)
  2326. {
  2327. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
  2328. }
  2329. else
  2330. {
  2331. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
  2332. }
  2333. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  2334. addedDigivolutionCards.Add(cardSource);
  2335. Placed = true;
  2336. }
  2337. }
  2338. }
  2339. }
  2340. #region add log
  2341. if (addedDigivolutionCards.Count >= 1)
  2342. {
  2343. string log = "";
  2344. log += $"\nPlace in digivolution cards:";
  2345. foreach (CardSource cardSource in addedDigivolutionCards)
  2346. {
  2347. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2348. }
  2349. log += "\n";
  2350. PlayLog.OnAddLog?.Invoke(log);
  2351. }
  2352. #endregion
  2353. #region hide icon
  2354. if (addedDigivolutionCards.Count >= 1)
  2355. {
  2356. if (!_notShowCards)
  2357. {
  2358. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
  2359. }
  2360. }
  2361. #endregion
  2362. }
  2363. }
  2364. #endregion
  2365. #region Place permanent to another permanent's Link cards
  2366. public class IPlacePermanentToLinkCards
  2367. {
  2368. public IPlacePermanentToLinkCards(
  2369. List<Permanent[]> permanentArrays,
  2370. ICardEffect cardEffect,
  2371. bool skipEffectAndActivateSkill = false)
  2372. {
  2373. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  2374. _cardEffect = cardEffect;
  2375. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  2376. }
  2377. public void SetNotShowCards()
  2378. {
  2379. _notShowCards = true;
  2380. }
  2381. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  2382. ICardEffect _cardEffect = null;
  2383. bool _notShowCards = false;
  2384. bool _skipEffectAndActivateSkill = false;
  2385. public bool Placed { get; private set; } = false;
  2386. public IEnumerator PlacePermanentToLinkCards()
  2387. {
  2388. if (_permanentArrays.Count == 0)
  2389. {
  2390. yield break;
  2391. }
  2392. List<CardSource> addedLinkCards = new List<CardSource>();
  2393. List<Permanent> removeFieldPermanents = new List<Permanent>();
  2394. foreach (Permanent[] permanentArray in _permanentArrays)
  2395. {
  2396. if (permanentArray.Length == 2)
  2397. {
  2398. Permanent LinkedPermanent = permanentArray[0];
  2399. Permanent getLinkPermanent = permanentArray[1];
  2400. if (LinkedPermanent != null && getLinkPermanent != null)
  2401. {
  2402. if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken)
  2403. {
  2404. if (_cardEffect != null)
  2405. {
  2406. if (LinkedPermanent.TopCard.CanNotBeAffected(_cardEffect) || getLinkPermanent.TopCard.CanNotBeAffected(_cardEffect))
  2407. {
  2408. continue;
  2409. }
  2410. }
  2411. removeFieldPermanents.Add(LinkedPermanent);
  2412. }
  2413. }
  2414. }
  2415. }
  2416. foreach (Permanent permanent in removeFieldPermanents)
  2417. {
  2418. permanent.willBeRemoveField = true;
  2419. }
  2420. if (removeFieldPermanents.Count == 0)
  2421. {
  2422. yield break;
  2423. }
  2424. #region Cut in Effects
  2425. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2426. Hashtable hashtable1 =
  2427. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2428. removeFieldPermanents,
  2429. _cardEffect,
  2430. null);
  2431. #region "When permanents would remove field" effect
  2432. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2433. {
  2434. #region permanents' effects
  2435. foreach (Permanent permanent1 in player.GetFieldPermanents())
  2436. {
  2437. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  2438. {
  2439. if (cardEffect is ActivateICardEffect)
  2440. {
  2441. if (cardEffect.CanTrigger(hashtable1))
  2442. {
  2443. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2444. }
  2445. }
  2446. }
  2447. }
  2448. #endregion
  2449. #region players' effects
  2450. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  2451. {
  2452. if (cardEffect is ActivateICardEffect)
  2453. {
  2454. if (cardEffect.CanTrigger(hashtable1))
  2455. {
  2456. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2457. }
  2458. }
  2459. }
  2460. #endregion
  2461. }
  2462. #endregion
  2463. if (skillInfos.Count >= 1)
  2464. {
  2465. foreach (SkillInfo skillInfo in skillInfos)
  2466. {
  2467. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  2468. }
  2469. bool showEffect()
  2470. {
  2471. if (skillInfos.Count >= 2)
  2472. {
  2473. return true;
  2474. }
  2475. else if (skillInfos.Count == 1)
  2476. {
  2477. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  2478. {
  2479. return true;
  2480. }
  2481. }
  2482. return false;
  2483. }
  2484. if (showEffect())
  2485. {
  2486. foreach (Permanent Permanent in removeFieldPermanents)
  2487. {
  2488. if (Permanent != null)
  2489. {
  2490. if (Permanent.TopCard != null)
  2491. {
  2492. if (Permanent.willBeRemoveField)
  2493. {
  2494. if (Permanent.ShowingPermanentCard != null)
  2495. {
  2496. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2497. {
  2498. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  2499. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  2500. }
  2501. }
  2502. }
  2503. }
  2504. }
  2505. }
  2506. #region shrink security Digimon display
  2507. if (GManager.instance.attackProcess.IsAttacking)
  2508. {
  2509. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2510. {
  2511. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2512. {
  2513. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2514. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2515. }
  2516. }
  2517. }
  2518. #endregion
  2519. }
  2520. // cut in effect process
  2521. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2522. foreach (Permanent Permanent in removeFieldPermanents)
  2523. {
  2524. if (Permanent != null)
  2525. {
  2526. if (Permanent.TopCard != null)
  2527. {
  2528. if (Permanent.ShowingPermanentCard != null)
  2529. {
  2530. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2531. {
  2532. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  2533. }
  2534. }
  2535. }
  2536. }
  2537. }
  2538. }
  2539. #endregion
  2540. foreach (Permanent[] permanentArray in _permanentArrays)
  2541. {
  2542. if (permanentArray.Length == 2)
  2543. {
  2544. Permanent LinkedPermanent = permanentArray[0];
  2545. Permanent getLinkPermanent = permanentArray[1];
  2546. if (LinkedPermanent != null && getLinkPermanent != null)
  2547. {
  2548. if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken && LinkedPermanent.willBeRemoveField)
  2549. {
  2550. #region "When permanents leave the battle area" effect
  2551. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2552. CardEffectCommons.OnDeletionHashtable(
  2553. new List<Permanent> { LinkedPermanent },
  2554. _cardEffect,
  2555. null,
  2556. false
  2557. ),
  2558. EffectTiming.OnLeaveFieldAnyone));
  2559. #endregion
  2560. yield return ContinuousController.instance.StartCoroutine(LinkedPermanent.DiscardEvoRoots());
  2561. CardSource cardSource = LinkedPermanent.TopCard;
  2562. #region record used effect
  2563. if (_cardEffect != null)
  2564. {
  2565. if (LinkedPermanent.TopCard != null)
  2566. {
  2567. LinkedPermanent.PlaceOtherPermanentEffect = _cardEffect;
  2568. }
  2569. }
  2570. #endregion
  2571. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  2572. LinkedPermanent,
  2573. ignoreOverflow: true));
  2574. yield return ContinuousController.instance.StartCoroutine(getLinkPermanent.AddLinkCard(cardSource, _cardEffect));
  2575. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  2576. addedLinkCards.Add(cardSource);
  2577. Placed = true;
  2578. }
  2579. }
  2580. }
  2581. }
  2582. #region add log
  2583. if (addedLinkCards.Count >= 1)
  2584. {
  2585. string log = "";
  2586. log += $"\nLink cards:";
  2587. foreach (CardSource cardSource in addedLinkCards)
  2588. {
  2589. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2590. }
  2591. log += "\n";
  2592. PlayLog.OnAddLog?.Invoke(log);
  2593. }
  2594. #endregion
  2595. #region hide icon
  2596. if (addedLinkCards.Count >= 1)
  2597. {
  2598. if (!_notShowCards)
  2599. {
  2600. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedLinkCards, "Link Cards", true, true));
  2601. }
  2602. }
  2603. #endregion
  2604. }
  2605. }
  2606. #endregion
  2607. #region Place permanents to security
  2608. public class IPutSecurityPermanent
  2609. {
  2610. public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop, bool isFaceup = false)
  2611. {
  2612. _permanent = permanent;
  2613. _hashtable = hashtable;
  2614. _toTop = toTop;
  2615. _isFaceup = isFaceup;
  2616. }
  2617. Permanent _permanent = null;
  2618. Hashtable _hashtable = new Hashtable();
  2619. bool _toTop = false;
  2620. bool _isFaceup = false;
  2621. public bool IsPlacedSecurity = false;
  2622. public IEnumerator PutSecurity()
  2623. {
  2624. if (_permanent == null) yield break;
  2625. if (_permanent.TopCard == null) yield break;
  2626. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2627. if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
  2628. if (!_permanent.CanBeRemoved()) yield break;
  2629. _permanent.willBeRemoveField = true;
  2630. #region "When permanents would remove field" effect
  2631. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2632. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2633. new List<Permanent>() { _permanent },
  2634. cardEffect,
  2635. null
  2636. ),
  2637. EffectTiming.WhenRemoveField));
  2638. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2639. {
  2640. _permanent.ShowWillRemoveFieldEffect();
  2641. //effect
  2642. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2643. // cut in effect process
  2644. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2645. _permanent.HideWillRemoveFieldEffect();
  2646. }
  2647. #endregion
  2648. CardSource topCard = _permanent.TopCard;
  2649. if (!_permanent.willBeRemoveField)
  2650. yield break;
  2651. if (topCard == null)
  2652. yield break;
  2653. #region add log
  2654. string log = "";
  2655. string fromString = _toTop ? "top" : "bottom";
  2656. log += $"\nPut cards on {fromString} of security:";
  2657. log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
  2658. log += "\n";
  2659. PlayLog.OnAddLog?.Invoke(log);
  2660. #endregion
  2661. IsPlacedSecurity = true;
  2662. #region show cards
  2663. if (!topCard.IsToken)
  2664. {
  2665. if (_toTop)
  2666. {
  2667. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
  2668. }
  2669. else
  2670. {
  2671. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
  2672. }
  2673. }
  2674. #endregion
  2675. #region "When permanents leave the battle area" effect
  2676. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2677. CardEffectCommons.OnDeletionHashtable(
  2678. new List<Permanent> { _permanent },
  2679. cardEffect,
  2680. null,
  2681. false
  2682. ),
  2683. EffectTiming.OnLeaveFieldAnyone));
  2684. #endregion
  2685. #region place permanent to security
  2686. yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
  2687. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
  2688. if (!topCard.IsToken)
  2689. {
  2690. if (!topCard.IsDigiEgg)
  2691. {
  2692. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard, faceUp: _isFaceup));
  2693. if (!_isFaceup)
  2694. topCard.SetReverse();
  2695. else
  2696. topCard.SetFace();
  2697. if (!_toTop)
  2698. {
  2699. topCard.Owner.SecurityCards.Remove(topCard);
  2700. topCard.Owner.SecurityCards.Add(topCard);
  2701. }
  2702. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
  2703. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard).AddSecurity());
  2704. }
  2705. else
  2706. {
  2707. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2708. }
  2709. }
  2710. #endregion
  2711. }
  2712. }
  2713. #endregion
  2714. #region Delete permanents
  2715. public class DestroyPermanentsClass
  2716. {
  2717. public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
  2718. {
  2719. _destroytargetPermanents = destroyTargetPermanents.Clone();
  2720. _hashtable = hashtable;
  2721. _notShowCards = notShowCards;
  2722. }
  2723. public bool IsDestroyed(Permanent permanent)
  2724. {
  2725. return DestroyedPermanents.Contains(permanent);
  2726. }
  2727. List<Permanent> _destroytargetPermanents = new List<Permanent>();
  2728. public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
  2729. Hashtable _hashtable = null;
  2730. bool _notShowCards = false;
  2731. public IEnumerator Destroy()
  2732. {
  2733. if (_destroytargetPermanents == null) yield break;
  2734. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2735. IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
  2736. bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
  2737. _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
  2738. permanent != null
  2739. && permanent.TopCard != null
  2740. && (cardEffect == null ||
  2741. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  2742. && permanent.CanBeDestroyedBySkill(cardEffect))));
  2743. if (_destroytargetPermanents.Count == 0) yield break;
  2744. _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  2745. #region cut in effect
  2746. // "When permanents would be deleted" effect
  2747. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2748. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2749. _destroytargetPermanents,
  2750. cardEffect,
  2751. battle
  2752. ),
  2753. EffectTiming.WhenPermanentWouldBeDeleted));
  2754. // "When permanents would remove field" effect
  2755. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2756. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2757. _destroytargetPermanents,
  2758. cardEffect,
  2759. battle
  2760. ),
  2761. EffectTiming.WhenRemoveField));
  2762. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2763. {
  2764. foreach (Permanent permanent in _destroytargetPermanents)
  2765. {
  2766. permanent.ShowDeleteEffect();
  2767. }
  2768. // effect
  2769. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2770. // cut in effect process
  2771. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2772. foreach (Permanent permanent in _destroytargetPermanents)
  2773. {
  2774. permanent.HideDeleteEffect();
  2775. }
  2776. }
  2777. #endregion
  2778. // fix delete target permanents
  2779. List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
  2780. permanent != null
  2781. && permanent.TopCard != null
  2782. && permanent.willBeRemoveField);
  2783. #region "When permanents are deleted" effect
  2784. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2785. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2786. destroyTargetPermanents_Fixed,
  2787. cardEffect,
  2788. battle,
  2789. isDPZero
  2790. ),
  2791. EffectTiming.OnDestroyedAnyone));
  2792. #endregion
  2793. #region "When permanents leave the battle area" effect
  2794. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2795. CardEffectCommons.OnDeletionHashtable(
  2796. destroyTargetPermanents_Fixed,
  2797. cardEffect,
  2798. battle,
  2799. isDPZero
  2800. ),
  2801. EffectTiming.OnLeaveFieldAnyone));
  2802. #endregion
  2803. #region record parameters just before deletion
  2804. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2805. {
  2806. permanent.DPJustBeforeRemoveField = permanent.DP;
  2807. if (permanent.TopCard.HasLevel)
  2808. {
  2809. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2810. }
  2811. if (permanent.TopCard.HasPlayCost)
  2812. {
  2813. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  2814. }
  2815. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  2816. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  2817. foreach (CardSource cardSource in permanent.cardSources)
  2818. {
  2819. cardSource.PermanentJustBeforeRemoveField = permanent;
  2820. }
  2821. }
  2822. #endregion
  2823. #region add log
  2824. if (destroyTargetPermanents_Fixed.Count >= 1)
  2825. {
  2826. string log = "";
  2827. log += $"\nDelete:";
  2828. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2829. {
  2830. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  2831. }
  2832. log += "\n";
  2833. PlayLog.OnAddLog?.Invoke(log);
  2834. }
  2835. #endregion
  2836. #region show cards
  2837. List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2838. if (!_notShowCards)
  2839. {
  2840. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
  2841. }
  2842. #endregion
  2843. #region trash permanent cards
  2844. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2845. {
  2846. #region record wheter to be deleted by battle
  2847. if (battle != null)
  2848. {
  2849. if (permanent.TopCard != null)
  2850. {
  2851. if (CardEffectCommons.GetLoserPermanentsFromHashtable(battle.hashtable).Contains(permanent))
  2852. permanent.IsDestroyedByBattle = true;
  2853. }
  2854. }
  2855. #endregion
  2856. #region record used effect
  2857. if (permanent.TopCard != null)
  2858. {
  2859. permanent.DestroyingEffect = cardEffect;
  2860. }
  2861. #endregion
  2862. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
  2863. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2864. CardSource topCard = permanent.TopCard;
  2865. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2866. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
  2867. DestroyedPermanents.Add(permanent);
  2868. }
  2869. #endregion
  2870. #region hide icon
  2871. foreach (Permanent permanent in _destroytargetPermanents)
  2872. {
  2873. if (permanent != null)
  2874. {
  2875. if (permanent.TopCard != null)
  2876. {
  2877. permanent.willBeRemoveField = false;
  2878. }
  2879. }
  2880. }
  2881. #endregion
  2882. }
  2883. }
  2884. #endregion
  2885. #region Security check
  2886. public class ISecurityCheck
  2887. {
  2888. public ISecurityCheck(Permanent AttackingPermanent, Player player)
  2889. {
  2890. this.AttackingPermanent = AttackingPermanent;
  2891. this.player = player;
  2892. }
  2893. Permanent AttackingPermanent { get; set; }
  2894. Player player { get; set; }
  2895. public IEnumerator SecurityCheck()
  2896. {
  2897. bool StopSecurityCheck()
  2898. {
  2899. if (AttackingPermanent == null)
  2900. {
  2901. return true;
  2902. }
  2903. if (AttackingPermanent.TopCard == null)
  2904. {
  2905. return true;
  2906. }
  2907. if (!AttackingPermanent.IsDigimon)
  2908. return true;
  2909. return false;
  2910. }
  2911. if (!StopSecurityCheck())
  2912. {
  2913. if (AttackingPermanent.Strike == 0)
  2914. {
  2915. yield break;
  2916. }
  2917. GManager.instance.turnStateMachine.IsSelecting = true;
  2918. GManager.instance.turnStateMachine.isSecurityCehck = true;
  2919. #region loop while there are 1 or more security cards
  2920. if (player.SecurityCards.Count >= 1)
  2921. {
  2922. int checkedCount = 0;
  2923. while (true)
  2924. {
  2925. if (StopSecurityCheck())
  2926. {
  2927. break;
  2928. }
  2929. if (checkedCount >= AttackingPermanent.Strike)
  2930. {
  2931. break;
  2932. }
  2933. if (player.SecurityCards.Count >= 1)
  2934. {
  2935. List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
  2936. CardSource brokenSecurityCard = player.SecurityCards[0];
  2937. bool isFaceDown = brokenSecurityCard.IsFlipped;
  2938. Hashtable hashtable = new Hashtable()
  2939. {
  2940. {"AttackingPermanent", AttackingPermanent},
  2941. {"Card", brokenSecurityCard}
  2942. };
  2943. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
  2944. {
  2945. triggeredSkillInfos.Add(skillInfo);
  2946. }
  2947. checkedCount++;
  2948. PlayLog.OnAddLog?.Invoke($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
  2949. if (brokenSecurityCard.IsDigimon)
  2950. {
  2951. GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
  2952. }
  2953. #region effect
  2954. player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2955. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
  2956. yield return new WaitForSeconds(0.1f);
  2957. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
  2958. #endregion
  2959. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
  2960. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2961. player: brokenSecurityCard.Owner,
  2962. refSkillInfos: ref triggeredSkillInfos,
  2963. null).ReduceSecurity());
  2964. #region security effect
  2965. List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
  2966. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
  2967. {
  2968. if (cardEffect is ActivateICardEffect)
  2969. {
  2970. Hashtable hashtable1 = new Hashtable();
  2971. hashtable1.Add("Card", brokenSecurityCard);
  2972. hashtable1.Add("isFaceDown", isFaceDown);
  2973. if (cardEffect.CanUse(hashtable1))
  2974. {
  2975. secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
  2976. }
  2977. }
  2978. }
  2979. List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
  2980. bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
  2981. if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
  2982. {
  2983. if (!brokenSecurityCard.IsDigimon)
  2984. {
  2985. yield return new WaitForSeconds(0.3f);
  2986. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2987. }
  2988. }
  2989. else
  2990. {
  2991. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
  2992. yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
  2993. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2994. foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
  2995. {
  2996. skillInfos.Add(skillInfo);
  2997. }
  2998. List<CardSource> cardSources = new List<CardSource>();
  2999. for (int j = 0; j < skillInfos.Count; j++)
  3000. {
  3001. cardSources.Add(brokenSecurityCard);
  3002. }
  3003. while (skillInfos.Count >= 1)
  3004. {
  3005. SkillInfo selectedSkillInfo = null;
  3006. if (skillInfos.Count == 1)
  3007. {
  3008. selectedSkillInfo = skillInfos[0];
  3009. }
  3010. else
  3011. {
  3012. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  3013. selectCardEffect.SetUp(
  3014. canTargetCondition: (cardSource) => true,
  3015. canTargetCondition_ByPreSelecetedList: null,
  3016. canEndSelectCondition: null,
  3017. canNoSelect: () => false,
  3018. selectCardCoroutine: null,
  3019. afterSelectCardCoroutine: null,
  3020. message: "select security effect",
  3021. maxCount: 1,
  3022. canEndNotMax: false,
  3023. isShowOpponent: false,
  3024. mode: SelectCardEffect.Mode.Custom,
  3025. root: SelectCardEffect.Root.Custom,
  3026. customRootCardList: cardSources,
  3027. canLookReverseCard: true,
  3028. selectPlayer: player,
  3029. cardEffect: null);
  3030. selectCardEffect.SetUpSkillInfos(skillInfos);
  3031. selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
  3032. selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  3033. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  3034. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  3035. {
  3036. if (selectedIndexes.Count == 1)
  3037. {
  3038. selectedSkillInfo = skillInfos[selectedIndexes[0]];
  3039. yield return null;
  3040. }
  3041. }
  3042. }
  3043. if (selectedSkillInfo != null)
  3044. {
  3045. ICardEffect cardEffect = selectedSkillInfo.CardEffect;
  3046. Hashtable hashtable2 = selectedSkillInfo.Hashtable;
  3047. if (cardEffect.EffectSourceCard == brokenSecurityCard)
  3048. {
  3049. if (cardEffect is ActivateICardEffect)
  3050. {
  3051. skillInfos.Remove(selectedSkillInfo);
  3052. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  3053. cardEffect,
  3054. hashtable2));
  3055. }
  3056. }
  3057. }
  3058. }
  3059. }
  3060. #endregion
  3061. // auto process check
  3062. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3063. // stack effect of "When cards are removed from security" and "checks secuirty"
  3064. foreach (SkillInfo skillInfo in triggeredSkillInfos)
  3065. {
  3066. GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
  3067. }
  3068. // auto process check
  3069. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3070. if (!StopSecurityCheck())
  3071. {
  3072. #region battle with security Digimon
  3073. if (brokenSecurityCard.IsDigimon)
  3074. {
  3075. bool doBattle = true;
  3076. #region "ignore battle" effect
  3077. Hashtable hashtable3 = new Hashtable()
  3078. {
  3079. {"Card", brokenSecurityCard}
  3080. };
  3081. #region the security Digimon's effect
  3082. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
  3083. {
  3084. if (cardEffect is IDontBattleSecurityDigimonEffect)
  3085. {
  3086. if (cardEffect.CanUse(hashtable3))
  3087. {
  3088. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  3089. {
  3090. doBattle = false;
  3091. }
  3092. }
  3093. }
  3094. }
  3095. #endregion
  3096. #region player's effect
  3097. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3098. {
  3099. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3100. {
  3101. if (cardEffect is IDontBattleSecurityDigimonEffect)
  3102. {
  3103. if (cardEffect.CanUse(hashtable3))
  3104. {
  3105. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  3106. {
  3107. doBattle = false;
  3108. }
  3109. }
  3110. }
  3111. }
  3112. }
  3113. #endregion
  3114. #endregion
  3115. if (doBattle)
  3116. {
  3117. yield return new WaitForSeconds(0.3f);
  3118. yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
  3119. }
  3120. }
  3121. #endregion
  3122. }
  3123. #region effect
  3124. yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
  3125. if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
  3126. {
  3127. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
  3128. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
  3129. {
  3130. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  3131. }
  3132. }
  3133. GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
  3134. GManager.instance.attackProcess.SecurityDigimon = null;
  3135. #endregion
  3136. // reset effect until end of security check
  3137. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3138. {
  3139. player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  3140. }
  3141. // auto process check
  3142. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3143. GManager.instance.turnStateMachine.IsSelecting = true;
  3144. }
  3145. else
  3146. {
  3147. break;
  3148. }
  3149. }
  3150. }
  3151. #endregion
  3152. GManager.instance.turnStateMachine.isSecurityCehck = false;
  3153. }
  3154. }
  3155. }
  3156. #endregion
  3157. #region trash cards from security
  3158. public class IDestroySecurity
  3159. {
  3160. private enum TrashMode
  3161. {
  3162. TopSecurity,
  3163. BottomSecurity,
  3164. SelectedCard,
  3165. }
  3166. public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
  3167. {
  3168. _player = player;
  3169. _destroySecurityCount = destroySecurityCount;
  3170. _cardEffect = cardEffect;
  3171. _trashMode = fromTop ? TrashMode.TopSecurity : TrashMode.BottomSecurity;
  3172. }
  3173. public IDestroySecurity(Player player, CardSource card, ICardEffect cardEffect)
  3174. {
  3175. _player = player;
  3176. _destroySecurityCount = 1;
  3177. _cardEffect = cardEffect;
  3178. _trashMode = TrashMode.SelectedCard;
  3179. _selectedCard = card;
  3180. }
  3181. Player _player = null;
  3182. int _destroySecurityCount = 0;
  3183. public List<CardSource> DestroyedSecurity = new List<CardSource>();
  3184. ICardEffect _cardEffect = null;
  3185. TrashMode _trashMode = TrashMode.TopSecurity;
  3186. CardSource _selectedCard = null;
  3187. public bool IsDestroyed(CardSource cardSource)
  3188. {
  3189. return DestroyedSecurity.Contains(cardSource);
  3190. }
  3191. public IEnumerator DestroySecurity()
  3192. {
  3193. bool StopDestroySecurity()
  3194. {
  3195. if (_player.SecurityCards.Count == 0)
  3196. {
  3197. return true;
  3198. }
  3199. if (!_player.CanReduceSecurity())
  3200. {
  3201. return true;
  3202. }
  3203. return false;
  3204. }
  3205. if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
  3206. {
  3207. int count = 0;
  3208. List<CardSource> discardedCards = new List<CardSource>();
  3209. while (true)
  3210. {
  3211. if (StopDestroySecurity())
  3212. {
  3213. break;
  3214. }
  3215. if (count >= _destroySecurityCount)
  3216. {
  3217. break;
  3218. }
  3219. if (_player.SecurityCards.Count >= 1)
  3220. {
  3221. count++;
  3222. CardSource destroyedSecurityCard = null;
  3223. switch (_trashMode)
  3224. {
  3225. case TrashMode.TopSecurity:
  3226. destroyedSecurityCard = _player.SecurityCards[0];
  3227. break;
  3228. case TrashMode.BottomSecurity:
  3229. destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
  3230. break;
  3231. case TrashMode.SelectedCard:
  3232. destroyedSecurityCard = _player.SecurityCards.Contains(_selectedCard) ? _selectedCard : null;
  3233. break;
  3234. }
  3235. if (destroyedSecurityCard == null)
  3236. {
  3237. break;
  3238. }
  3239. discardedCards.Add(destroyedSecurityCard);
  3240. #region effect
  3241. _player.securityObject.securityBreakGlass.ShowBlueMatarial();
  3242. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
  3243. yield return new WaitForSeconds(0.1f);
  3244. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
  3245. yield return new WaitForSeconds(0.5f);
  3246. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
  3247. #endregion
  3248. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
  3249. DestroyedSecurity.Add(destroyedSecurityCard);
  3250. }
  3251. }
  3252. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  3253. if (discardedCards.Count >= 1)
  3254. {
  3255. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  3256. player: _player,
  3257. refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
  3258. cardEffect: _cardEffect).ReduceSecurity());
  3259. #region "When security cards are trashed" effect
  3260. #region Hashtable setting
  3261. Hashtable hashtable = new Hashtable()
  3262. {
  3263. {"DiscardedCards", discardedCards},
  3264. {"CardEffect", _cardEffect},
  3265. };
  3266. #endregion
  3267. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
  3268. #endregion
  3269. }
  3270. #region add log
  3271. if (discardedCards.Count >= 1)
  3272. {
  3273. string log = "";
  3274. string modeString = "";
  3275. switch (_trashMode)
  3276. {
  3277. case TrashMode.TopSecurity:
  3278. modeString = "Top";
  3279. break;
  3280. case TrashMode.BottomSecurity:
  3281. modeString = "Bottom";
  3282. break;
  3283. case TrashMode.SelectedCard:
  3284. modeString = "Selected";
  3285. break;
  3286. }
  3287. log += $"\nDiscarded From {modeString} Security Cards:";
  3288. foreach (CardSource cardSource in discardedCards)
  3289. {
  3290. if (cardSource != null)
  3291. {
  3292. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3293. }
  3294. }
  3295. log += "\n";
  3296. PlayLog.OnAddLog?.Invoke(log);
  3297. }
  3298. #endregion
  3299. }
  3300. }
  3301. }
  3302. #endregion
  3303. #region Battle
  3304. public class IBattle
  3305. {
  3306. public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard, bool IsWithoutAttack = false)
  3307. {
  3308. this.AttackingPermanent = AttackingPermanent;
  3309. this.DefendingPermanent = DefendingPermanent;
  3310. this.DefendingCard = DefendingCard;
  3311. this.IsWithoutAttack = IsWithoutAttack;
  3312. }
  3313. public Permanent AttackingPermanent { get; private set; } = null;
  3314. public Permanent DefendingPermanent { get; private set; } = null;
  3315. CardSource DefendingCard { get; set; } = null;
  3316. bool IsWithoutAttack { get; set; } = false;
  3317. public Hashtable hashtable { get; set; } = new Hashtable();
  3318. public Permanent enemyPermanent(Permanent permanent)
  3319. {
  3320. if (permanent != null)
  3321. {
  3322. if (permanent == AttackingPermanent)
  3323. {
  3324. return DefendingPermanent;
  3325. }
  3326. else if (permanent == DefendingPermanent)
  3327. {
  3328. return AttackingPermanent;
  3329. }
  3330. }
  3331. return null;
  3332. }
  3333. public int CompareStats()
  3334. {
  3335. int statCheck = 0;
  3336. if (AttackingPermanent.HasIceclad || DefendingPermanent.HasIceclad)
  3337. statCheck = AttackingPermanent.DigivolutionCards.Count - DefendingPermanent.DigivolutionCards.Count;
  3338. else
  3339. statCheck = AttackingPermanent.DP - DefendingPermanent.DP;
  3340. statCheck = Mathf.Clamp(statCheck, -1, 1);
  3341. return statCheck;
  3342. }
  3343. public IEnumerator Battle()
  3344. {
  3345. hashtable = new Hashtable();
  3346. if (AttackingPermanent != null)
  3347. {
  3348. bool IsExistingDefender()
  3349. {
  3350. // whether defender exists
  3351. if ((DefendingPermanent == null) != (DefendingCard == null))
  3352. {
  3353. if (DefendingPermanent != null)
  3354. {
  3355. if (DefendingPermanent.TopCard != null)
  3356. {
  3357. return true;
  3358. }
  3359. }
  3360. else if (DefendingCard != null)
  3361. {
  3362. return true;
  3363. }
  3364. }
  3365. return false;
  3366. }
  3367. if (IsExistingDefender())
  3368. {
  3369. if (AttackingPermanent != null)
  3370. {
  3371. AttackingPermanent.battle = this;
  3372. }
  3373. if (DefendingPermanent != null)
  3374. {
  3375. DefendingPermanent.battle = this;
  3376. }
  3377. List<Permanent> WinnerPermanents = new List<Permanent>();
  3378. List<Permanent> LoserPermanents = new List<Permanent>();
  3379. CardSource LoserCard = null;
  3380. bool WasTie = false;
  3381. //add log
  3382. string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
  3383. if (DefendingPermanent != null)
  3384. {
  3385. log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
  3386. }
  3387. else if (DefendingCard != null)
  3388. {
  3389. log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
  3390. }
  3391. PlayLog.OnAddLog?.Invoke(log);
  3392. #region "At the start of battle" effect
  3393. Permanent _AttackingPermanent = null;
  3394. Permanent _DefendingPermanent = null;
  3395. if (AttackingPermanent != null)
  3396. {
  3397. if (AttackingPermanent.TopCard != null)
  3398. {
  3399. _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
  3400. }
  3401. }
  3402. if (DefendingPermanent != null)
  3403. {
  3404. if (DefendingPermanent.TopCard != null)
  3405. {
  3406. _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
  3407. }
  3408. }
  3409. hashtable.Add("AttackingPermanent", _AttackingPermanent);
  3410. hashtable.Add("DefendingPermanent", _DefendingPermanent);
  3411. hashtable.Add("DefendingCard", DefendingCard);
  3412. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
  3413. #endregion
  3414. #region Show effect
  3415. bool ShowEffect()
  3416. {
  3417. if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
  3418. {
  3419. return true;
  3420. }
  3421. else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
  3422. {
  3423. if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
  3424. {
  3425. return true;
  3426. }
  3427. }
  3428. return false;
  3429. }
  3430. if (ShowEffect())
  3431. {
  3432. if (GManager.instance.attackProcess.IsAttacking)
  3433. {
  3434. if (GManager.instance.attackProcess.SecurityDigimon != null)
  3435. {
  3436. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  3437. {
  3438. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  3439. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  3440. }
  3441. }
  3442. }
  3443. }
  3444. #endregion
  3445. if (!IsWithoutAttack)//If started by effect, do not perform processing during this battle
  3446. {
  3447. // auto process check
  3448. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3449. GManager.instance.turnStateMachine.IsSelecting = true;
  3450. //Preemptive end battle if the attack process is ended
  3451. if (GManager.instance.attackProcess.IsEndAttack )
  3452. yield break;
  3453. }
  3454. #region battle with permanent
  3455. if (DefendingPermanent != null)
  3456. {
  3457. int battleResults = CompareStats();
  3458. if (battleResults == 1)
  3459. {
  3460. WinnerPermanents.Add(AttackingPermanent);
  3461. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3462. LoserPermanents.Add(DefendingPermanent);
  3463. }
  3464. else if (battleResults == 0)
  3465. {
  3466. WasTie = true;
  3467. WinnerPermanents.Add(AttackingPermanent);
  3468. WinnerPermanents.Add(DefendingPermanent);
  3469. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3470. LoserPermanents.Add(AttackingPermanent);
  3471. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3472. LoserPermanents.Add(DefendingPermanent);
  3473. }
  3474. else if (battleResults == -1)
  3475. {
  3476. WinnerPermanents.Add(DefendingPermanent);
  3477. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3478. LoserPermanents.Add(AttackingPermanent);
  3479. }
  3480. }
  3481. #endregion
  3482. #region battle with card
  3483. else if (DefendingCard != null)
  3484. {
  3485. if (AttackingPermanent.DP > DefendingCard.CardDP)
  3486. {
  3487. WinnerPermanents.Add(AttackingPermanent);
  3488. LoserCard = DefendingCard;
  3489. }
  3490. else if (AttackingPermanent.DP == DefendingCard.CardDP)
  3491. {
  3492. WasTie = true;
  3493. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3494. {
  3495. LoserPermanents.Add(AttackingPermanent);
  3496. }
  3497. LoserCard = DefendingCard;
  3498. }
  3499. else if (AttackingPermanent.DP < DefendingCard.CardDP)
  3500. {
  3501. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3502. {
  3503. LoserPermanents.Add(AttackingPermanent);
  3504. }
  3505. }
  3506. }
  3507. #endregion
  3508. List<Permanent> _WinnerPermanents = new List<Permanent>();
  3509. List<Permanent> _LoserPermanents = new List<Permanent>();
  3510. foreach (Permanent permanent in WinnerPermanents)
  3511. {
  3512. if (permanent.TopCard != null)
  3513. {
  3514. _WinnerPermanents.Add(new Permanent(permanent.cardSources));
  3515. }
  3516. }
  3517. foreach (Permanent permanent in LoserPermanents)
  3518. {
  3519. if (permanent.TopCard != null)
  3520. {
  3521. _LoserPermanents.Add(new Permanent(permanent.cardSources));
  3522. }
  3523. }
  3524. hashtable.Add("WinnerPermanents", _WinnerPermanents);
  3525. hashtable.Add("WinnerPermanents_real", WinnerPermanents);
  3526. hashtable.Add("LoserPermanents", _LoserPermanents);
  3527. hashtable.Add("LoserPermanents_real", LoserPermanents);
  3528. hashtable.Add("LoserCard", LoserCard);
  3529. hashtable.Add("WasTie", WasTie);
  3530. hashtable.Add("battle", this);
  3531. // battle effect
  3532. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
  3533. DestroyPermanentsClass destoryBattlePermanents = new DestroyPermanentsClass(LoserPermanents, hashtable);
  3534. yield return ContinuousController.instance.StartCoroutine(destoryBattlePermanents.Destroy());
  3535. //Fix Loser Permanents
  3536. if(LoserPermanents.Count != destoryBattlePermanents.DestroyedPermanents.Count)
  3537. {
  3538. LoserPermanents = destoryBattlePermanents.DestroyedPermanents;
  3539. _LoserPermanents = destoryBattlePermanents.DestroyedPermanents;
  3540. hashtable["LoserPermanents"] = _LoserPermanents;
  3541. hashtable["LoserPermanents_real"] = LoserPermanents;
  3542. }
  3543. // "At the end of battle" effect
  3544. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
  3545. #region move up effect
  3546. if (ShowEffect())
  3547. {
  3548. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
  3549. }
  3550. #endregion
  3551. #region effect when determine whether to do security check
  3552. List<SkillInfo> skillInfos_Pierce = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnDetermineDoSecurityCheck)
  3553. .Filter(skillInfo => skillInfo.CardEffect != null && skillInfo.CardEffect.CanActivate(skillInfo.Hashtable));
  3554. if (skillInfos_Pierce.Count >= 1)
  3555. {
  3556. GManager.instance.autoProcessing.PutStackedSkill(skillInfos_Pierce[0]);
  3557. }
  3558. #endregion
  3559. }
  3560. }
  3561. if (!IsWithoutAttack)//If started by effect, do not perform processing & don't reset effects relevant to the actual attack process
  3562. {
  3563. // auto process check
  3564. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3565. #region reset effect until the end of battle
  3566. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3567. {
  3568. foreach (Permanent permanent in player.GetFieldPermanents())
  3569. {
  3570. permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  3571. }
  3572. player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  3573. }
  3574. #endregion
  3575. }
  3576. if (AttackingPermanent != null)
  3577. {
  3578. AttackingPermanent.battle = null;
  3579. }
  3580. if (DefendingPermanent != null)
  3581. {
  3582. DefendingPermanent.battle = null;
  3583. }
  3584. }
  3585. }
  3586. #endregion
  3587. #region De-digivolve
  3588. public class IDegeneration
  3589. {
  3590. /// <summary>
  3591. /// De-Digivolve Class
  3592. /// </summary>
  3593. /// <param name="permanent">Target Permanent</param>
  3594. /// <param name="DegenerationCount">De-Digivolve Amount</param>
  3595. /// <param name="cardEffect">Card Effect</param>
  3596. /// <param name="DegenerationCountRuling">Should we enforce rule to select De-digivolve amount before digimon, disabled by default</param>
  3597. public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect, bool? DegenerationCountRuling = null)
  3598. {
  3599. _permanent = permanent;
  3600. _degenerationCount = DegenerationCount;
  3601. _cardEffect = cardEffect;
  3602. _degenerationCountRuling = DegenerationCountRuling;
  3603. }
  3604. Permanent _permanent = null;
  3605. int _degenerationCount;
  3606. ICardEffect _cardEffect = null;
  3607. bool? _degenerationCountRuling;
  3608. public IEnumerator Degeneration()
  3609. {
  3610. if (_cardEffect == null) yield break;
  3611. if (_cardEffect.EffectSourceCard == null) yield break;
  3612. if (_permanent == null) yield break;
  3613. if (_permanent.TopCard == null) yield break;
  3614. if (_permanent.ImmuneFromDeDigivolve()) yield break;
  3615. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
  3616. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3617. int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
  3618. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  3619. if (selectCountEffect != null && _degenerationCountRuling == null)
  3620. {
  3621. Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
  3622. selectCountEffect.SetUp(
  3623. SelectPlayer: selectPlayer,
  3624. targetPermanent: _permanent,
  3625. MaxCount: maxCount,
  3626. CanNoSelect: false,
  3627. Message: "How many cards do you trash?",
  3628. Message_Enemy: "The opponent is choosing how many cards to trash.",
  3629. SelectCountCoroutine: SelectCountCoroutine);
  3630. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  3631. IEnumerator SelectCountCoroutine(int count)
  3632. {
  3633. _degenerationCount = count;
  3634. yield return null;
  3635. }
  3636. }
  3637. if (_degenerationCount >= 1)
  3638. {
  3639. int count = 0;
  3640. List<CardSource> selectedCards = new List<CardSource>();
  3641. while (true)
  3642. {
  3643. bool StopCondition()
  3644. {
  3645. if (_permanent.HasNoDigivolutionCards)
  3646. {
  3647. return true;
  3648. }
  3649. if (_permanent.Level == 3)
  3650. {
  3651. if (_permanent.TopCard != null)
  3652. {
  3653. if (_permanent.TopCard.HasLevel)
  3654. {
  3655. return true;
  3656. }
  3657. }
  3658. }
  3659. if (count >= _degenerationCount)
  3660. {
  3661. return true;
  3662. }
  3663. return false;
  3664. }
  3665. if (StopCondition())
  3666. {
  3667. break;
  3668. }
  3669. if (count == 0)
  3670. {
  3671. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3672. }
  3673. CardSource cardSource = _permanent.TopCard;
  3674. selectedCards.Add(cardSource);
  3675. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  3676. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3677. if (!cardSource.IsToken)
  3678. {
  3679. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3680. }
  3681. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  3682. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3683. count++;
  3684. }
  3685. #region "When Top Card is Trashed" effect
  3686. #region Hashtable Setting
  3687. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  3688. {
  3689. {"Permanent", _permanent},
  3690. {"CardSources", selectedCards}
  3691. };
  3692. #endregion
  3693. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  3694. .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
  3695. #endregion
  3696. #region add log
  3697. if (selectedCards.Count >= 1)
  3698. {
  3699. string log = "";
  3700. log += $"\nDe-Digivolve :";
  3701. foreach (CardSource cardSource in selectedCards)
  3702. {
  3703. if (cardSource != null)
  3704. {
  3705. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3706. }
  3707. }
  3708. log += "\n";
  3709. PlayLog.OnAddLog?.Invoke(log);
  3710. }
  3711. #endregion
  3712. }
  3713. }
  3714. }
  3715. #endregion
  3716. #region Trash digivolution cards
  3717. public class ITrashDigivolutionCards
  3718. {
  3719. public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  3720. {
  3721. _permanent = permanent;
  3722. _trashTargetCards = trashTargetCards.Clone();
  3723. _cardEffect = cardEffect;
  3724. }
  3725. public bool IsTrashed(CardSource cardSource)
  3726. {
  3727. return TrashedCards.Contains(cardSource);
  3728. }
  3729. Permanent _permanent = null;
  3730. List<CardSource> _trashTargetCards = new List<CardSource>();
  3731. public List<CardSource> TrashedCards = new List<CardSource>();
  3732. ICardEffect _cardEffect = null;
  3733. public IEnumerator TrashDigivolutionCards()
  3734. {
  3735. if (_trashTargetCards == null) yield break;
  3736. if (_cardEffect == null) yield break;
  3737. if (_permanent == null) yield break;
  3738. if (_permanent.TopCard == null) yield break;
  3739. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
  3740. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3741. if (_permanent.HasNoDigivolutionCards) yield break;
  3742. _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
  3743. _permanent.DigivolutionCards.Contains(cardSource) &&
  3744. !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
  3745. if (_trashTargetCards.Count == 0) yield break;
  3746. _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
  3747. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  3748. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  3749. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3750. #region cut in effect - Would discard
  3751. // "When digivolution cards would be trashed" effect
  3752. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  3753. CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
  3754. _permanent,
  3755. _trashTargetCards,
  3756. _cardEffect
  3757. ),
  3758. EffectTiming.WhenWouldDigivolutionCardDiscarded));
  3759. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  3760. {
  3761. // effect
  3762. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  3763. // cut in effect process
  3764. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3765. }
  3766. #endregion
  3767. //fix trash target permanent
  3768. Permanent permanentTarget_Fixed = _permanent;
  3769. // fix trash sources sources
  3770. List<CardSource> trashDigivolutionCards_Fixed = _trashTargetCards.Filter(cardsource =>
  3771. cardsource != null
  3772. && cardsource.willBeRemoveSources);
  3773. #region "When digivolution cards are trashed" effect
  3774. #region Hashtable Setting
  3775. Hashtable hashtable = new Hashtable()
  3776. {
  3777. {"CardEffect", _cardEffect},
  3778. {"Permanent", permanentTarget_Fixed},
  3779. {"DiscardedCards", trashDigivolutionCards_Fixed},
  3780. };
  3781. #endregion
  3782. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
  3783. #endregion
  3784. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  3785. foreach (CardSource cardSource in trashDigivolutionCards_Fixed)
  3786. {
  3787. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
  3788. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3789. if (!cardSource.IsToken)
  3790. {
  3791. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3792. }
  3793. cardSource.willBeRemoveSources = false;
  3794. TrashedCards.Add(cardSource);
  3795. }
  3796. }
  3797. }
  3798. #endregion
  3799. #region Trash link cards
  3800. public class ITrashLinkCards
  3801. {
  3802. public ITrashLinkCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  3803. {
  3804. _permanent = permanent;
  3805. _trashTargetCards = trashTargetCards.Clone();
  3806. _cardEffect = cardEffect;
  3807. }
  3808. public bool IsTrashed(CardSource cardSource)
  3809. {
  3810. return TrashedLinkCards.Contains(cardSource);
  3811. }
  3812. Permanent _permanent = null;
  3813. List<CardSource> _trashTargetCards = new List<CardSource>();
  3814. public List<CardSource> TrashedLinkCards = new List<CardSource>();
  3815. ICardEffect _cardEffect = null;
  3816. public IEnumerator TrashLinkCards()
  3817. {
  3818. if (_trashTargetCards == null) yield break;
  3819. if (_permanent == null) yield break;
  3820. if (_permanent.TopCard == null) yield break;
  3821. if (_cardEffect != null && _permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3822. if (_permanent.HasNoLinkCards) yield break;
  3823. _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
  3824. _permanent.LinkedCards.Contains(cardSource));
  3825. if (_trashTargetCards.Count == 0) yield break;
  3826. _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
  3827. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  3828. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  3829. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3830. #region cut in effect - Would discard
  3831. // "When link cards would be trashed" effect
  3832. //TODO: Create CardEffectCommons.WhenLinkCardWouldDiscard function
  3833. /*yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  3834. CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
  3835. _permanent,
  3836. _trashTargetCards,
  3837. _cardEffect
  3838. ),
  3839. EffectTiming.WhenWouldDigivolutionCardDiscarded));*/
  3840. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  3841. {
  3842. // effect
  3843. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  3844. // cut in effect process
  3845. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3846. }
  3847. #endregion
  3848. //fix trash target permanent
  3849. Permanent permanentTarget_Fixed = _permanent;
  3850. // fix trash sources sources
  3851. List<CardSource> trashLinkCards_Fixed = _trashTargetCards.Filter(cardsource =>
  3852. cardsource != null
  3853. && cardsource.willBeRemoveSources);
  3854. #region "When link cards are trashed" effect
  3855. #region Hashtable Setting
  3856. Hashtable hashtable = new Hashtable()
  3857. {
  3858. {"CardEffect", _cardEffect},
  3859. {"Permanent", permanentTarget_Fixed},
  3860. {"DiscardedCards", trashLinkCards_Fixed},
  3861. };
  3862. #endregion
  3863. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLinkCardDiscarded));
  3864. #endregion
  3865. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  3866. foreach (CardSource cardSource in trashLinkCards_Fixed)
  3867. {
  3868. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
  3869. if (!cardSource.IsToken)
  3870. {
  3871. yield return ContinuousController.instance.StartCoroutine(permanentTarget_Fixed.RemoveLinkedCard(cardSource));
  3872. }
  3873. cardSource.willBeRemoveSources = false;
  3874. TrashedLinkCards.Add(cardSource);
  3875. }
  3876. }
  3877. }
  3878. #endregion
  3879. #region Return digivolution cards to deck bottom
  3880. public class ReturnToLibraryBottomDigivolutionCardsClass
  3881. {
  3882. public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
  3883. {
  3884. _permanent = permanent;
  3885. _cardSources = cardSources.Clone();
  3886. _hashtable = hashtable;
  3887. }
  3888. Permanent _permanent = null;
  3889. List<CardSource> _cardSources = new List<CardSource>();
  3890. Hashtable _hashtable = null;
  3891. public IEnumerator ReturnToLibraryBottomDigivolutionCards()
  3892. {
  3893. if (_permanent == null) yield break;
  3894. if (_permanent.TopCard == null) yield break;
  3895. if (_cardSources == null) yield break;
  3896. _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
  3897. if (_cardSources.Count == 0) yield break;
  3898. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3899. if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
  3900. string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
  3901. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
  3902. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3903. #region "When digivolution cards are returned to deck" effect
  3904. #region Hashtable Setting
  3905. Hashtable hashtable1 = new Hashtable()
  3906. {
  3907. {"Permanent", _permanent},
  3908. {"DeckBottomCards", _cardSources},
  3909. {"CardEffect", CardEffect},
  3910. };
  3911. #endregion
  3912. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
  3913. #endregion
  3914. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
  3915. }
  3916. }
  3917. #endregion
  3918. #region Reduce security
  3919. public class IReduceSecurity
  3920. {
  3921. public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos, ICardEffect cardEffect)
  3922. {
  3923. _player = player;
  3924. _refSkillInfos = refSkillInfos;
  3925. _cardEffect = cardEffect;
  3926. }
  3927. Player _player = null;
  3928. List<SkillInfo> _refSkillInfos = null;
  3929. ICardEffect _cardEffect = null;
  3930. public IEnumerator ReduceSecurity()
  3931. {
  3932. GManager.OnSecurityStackChanged?.Invoke(_player);
  3933. #region "When cards are removed from security" effect
  3934. #region Hashtable Setting
  3935. Hashtable hashtable = new Hashtable()
  3936. {
  3937. {"Player", _player},
  3938. {"SkillInfo",_refSkillInfos },
  3939. {"CardEffect",_cardEffect}
  3940. };
  3941. #endregion
  3942. if (_refSkillInfos == null)
  3943. {
  3944. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
  3945. }
  3946. else
  3947. {
  3948. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
  3949. {
  3950. _refSkillInfos.Add(skillInfo);
  3951. }
  3952. }
  3953. #endregion
  3954. }
  3955. }
  3956. #endregion
  3957. #region Add Security
  3958. public class IAddSecurity
  3959. {
  3960. public IAddSecurity(CardSource source)
  3961. {
  3962. _player = source.Owner;
  3963. _cardSource = source;
  3964. }
  3965. Player _player { get; set; }
  3966. CardSource _cardSource { get; set; }
  3967. public IEnumerator AddSecurity()
  3968. {
  3969. GManager.OnSecurityStackChanged?.Invoke(_player);
  3970. #region "When security cards are added" effect
  3971. #region Hashtable setting
  3972. Hashtable hashtable = new Hashtable()
  3973. {
  3974. {"Player", _player},
  3975. {"CardSources", new List<CardSource> { _cardSource } }
  3976. };
  3977. #endregion
  3978. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
  3979. #endregion
  3980. #region "When face up cards are added"
  3981. if (!_cardSource.IsFlipped)
  3982. {
  3983. #region Hashtable setting
  3984. Hashtable faceUpHashtable = new Hashtable()
  3985. {
  3986. {"Player", _player},
  3987. {"CardSources", new List<CardSource> { _cardSource } }
  3988. };
  3989. #endregion
  3990. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(faceUpHashtable, EffectTiming.OnFaceUpSecurityIncreased));
  3991. }
  3992. #endregion
  3993. }
  3994. }
  3995. #endregion
  3996. #region Flip Security Face Up
  3997. public class IFlipSecurity
  3998. {
  3999. public IFlipSecurity(CardSource source)
  4000. {
  4001. _player = source.Owner;
  4002. _cardSource = source;
  4003. }
  4004. Player _player { get; set; }
  4005. CardSource _cardSource { get; set; }
  4006. public IEnumerator FlipFaceUp()
  4007. {
  4008. if (!_player.SecurityCards.Contains(_cardSource) || !_cardSource.IsFlipped)
  4009. yield break;
  4010. _cardSource.SetFace();
  4011. #region "When face up cards are added"
  4012. #region Hashtable setting
  4013. Hashtable hashtable = new Hashtable()
  4014. {
  4015. {"Player", _player},
  4016. {"CardSources", new List<CardSource> { _cardSource } }
  4017. };
  4018. #endregion
  4019. if (!_cardSource.IsFlipped)
  4020. {
  4021. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnFaceUpSecurityIncreased));
  4022. }
  4023. #endregion
  4024. }
  4025. }
  4026. #endregion
  4027. #region Suspend permanents
  4028. public class SuspendPermanentsClass
  4029. {
  4030. public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
  4031. {
  4032. _permanents = permanents;
  4033. _hashtable = hashtable;
  4034. }
  4035. public bool IsSuspended(Permanent permanent)
  4036. {
  4037. return SuspendedPermanents.Contains(permanent);
  4038. }
  4039. List<Permanent> _permanents { get; set; }
  4040. public List<Permanent> SuspendedPermanents { get; private set; } = new List<Permanent>();
  4041. Hashtable _hashtable { get; set; }
  4042. public IEnumerator Tap()
  4043. {
  4044. if (_permanents.Count == 0) yield break;
  4045. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  4046. bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
  4047. bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
  4048. List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
  4049. bool PermanentCondition(Permanent permanent)
  4050. {
  4051. if (permanent != null)
  4052. {
  4053. if (permanent.TopCard != null)
  4054. {
  4055. if (permanent.IsSuspended)
  4056. {
  4057. return false;
  4058. }
  4059. if (!permanent.CanSuspend)
  4060. {
  4061. return false;
  4062. }
  4063. if (CardEffect != null)
  4064. {
  4065. if (permanent.TopCard.CanNotBeAffected(CardEffect))
  4066. {
  4067. return false;
  4068. }
  4069. }
  4070. }
  4071. }
  4072. return true;
  4073. }
  4074. foreach (Permanent permanent in suspendTargetPermanents)
  4075. {
  4076. permanent.IsSuspended = true;
  4077. permanent.DPWhenSuspended = permanent.DP;
  4078. if (permanent.ShowingPermanentCard != null)
  4079. {
  4080. permanent.ShowingPermanentCard.ShowPermanentData(true);
  4081. }
  4082. SuspendedPermanents.Add(permanent);
  4083. }
  4084. if (suspendTargetPermanents.Count >= 1)
  4085. {
  4086. #region "Effects when permanents suspend
  4087. #region Hashtable Setting
  4088. Hashtable _hashtable = new Hashtable(){
  4089. {"Permanents", suspendTargetPermanents},
  4090. {"IsBlock", IsBlock}
  4091. };
  4092. if (CardEffect != null)
  4093. {
  4094. _hashtable.Add("CardEffect", CardEffect);
  4095. }
  4096. #endregion
  4097. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  4098. #endregion
  4099. yield return new WaitForSeconds(0.3f);
  4100. }
  4101. }
  4102. }
  4103. #endregion
  4104. #region Unsuspend permanents
  4105. public class IUnsuspendPermanents
  4106. {
  4107. public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
  4108. {
  4109. _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  4110. _cardEffect = cardEffect;
  4111. }
  4112. List<Permanent> _permanents { get; set; }
  4113. ICardEffect _cardEffect { get; set; }
  4114. public IEnumerator Unsuspend()
  4115. {
  4116. //Permanent list that will unsuspend
  4117. List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
  4118. permanent != null
  4119. && permanent.TopCard != null
  4120. && permanent.IsSuspended
  4121. && permanent.CanUnsuspend
  4122. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  4123. #region "When permanents would unsuspend" effect
  4124. #region Hashtable Setting
  4125. Hashtable hashtable1 = new Hashtable()
  4126. {
  4127. {"CardEffect", _cardEffect},
  4128. {"Permanents", untappedPermanets},
  4129. };
  4130. #endregion
  4131. List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
  4132. if (skillInfos.Count >= 1)
  4133. {
  4134. foreach (SkillInfo skillInfo in skillInfos)
  4135. {
  4136. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  4137. }
  4138. foreach (Permanent permanent in untappedPermanets)
  4139. {
  4140. permanent.ShowUnsuspendEffect();
  4141. }
  4142. //cut in effects
  4143. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  4144. untappedPermanets.ForEach(permanent =>
  4145. {
  4146. if (permanent.ShowingPermanentCard != null)
  4147. {
  4148. permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
  4149. }
  4150. });
  4151. }
  4152. #endregion
  4153. // fix unsuspend target permanents
  4154. List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
  4155. permanent != null
  4156. && permanent.TopCard != null
  4157. && permanent.IsSuspended
  4158. && permanent.CanUnsuspend
  4159. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  4160. if (untappedPermanets_Fixed.Count >= 1)
  4161. {
  4162. foreach (Permanent permanent in untappedPermanets_Fixed)
  4163. {
  4164. permanent.IsSuspended = false;
  4165. if (permanent.ShowingPermanentCard != null)
  4166. {
  4167. permanent.ShowingPermanentCard.ShowPermanentData(true);
  4168. }
  4169. }
  4170. #region "When permanents are unsuspended" effect
  4171. #region Hashtable Setting
  4172. Hashtable hashtable2 = new Hashtable()
  4173. {
  4174. {"CardEffect", _cardEffect},
  4175. {"Permanents", untappedPermanets_Fixed},
  4176. };
  4177. #endregion
  4178. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
  4179. #endregion
  4180. yield return new WaitForSeconds(0.3f);
  4181. }
  4182. }
  4183. }
  4184. #endregion
  4185. #region Trash cards from deck top
  4186. public class ITrashDeckCards
  4187. {
  4188. public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
  4189. {
  4190. this.cardSources = new List<CardSource>();
  4191. foreach (CardSource cardSource in cardSources)
  4192. {
  4193. this.cardSources.Add(cardSource);
  4194. }
  4195. this.cardEffect = cardEffect;
  4196. }
  4197. List<CardSource> cardSources { get; set; } = new List<CardSource>();
  4198. ICardEffect cardEffect { get; set; } = null;
  4199. public IEnumerator TrashDeckCards()
  4200. {
  4201. List<CardSource> trashCards = new List<CardSource>();
  4202. foreach (CardSource cardSource in cardSources)
  4203. {
  4204. if (cardSource.Owner.LibraryCards.Contains(cardSource))
  4205. {
  4206. trashCards.Add(cardSource);
  4207. }
  4208. }
  4209. if (trashCards.Count >= 1)
  4210. {
  4211. foreach (CardSource cardSource in trashCards)
  4212. {
  4213. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  4214. }
  4215. #region "When cards are trashed from security" effect
  4216. #region Hashtable setting
  4217. Hashtable hashtable = new Hashtable()
  4218. {
  4219. {"DiscardedCards", trashCards},
  4220. {"CardEffect", cardEffect},
  4221. };
  4222. #endregion
  4223. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  4224. hashtable, EffectTiming.OnDiscardLibrary));
  4225. #endregion
  4226. }
  4227. }
  4228. }
  4229. #endregion
  4230. #region Overflow of ace
  4231. public class AceOverflowClass
  4232. {
  4233. public AceOverflowClass(List<CardSource> cardSources)
  4234. {
  4235. _cardSources = cardSources.Clone();
  4236. }
  4237. List<CardSource> _cardSources = new List<CardSource>();
  4238. public IEnumerator Overflow()
  4239. {
  4240. _cardSources = _cardSources
  4241. .Filter(cardSource => cardSource.IsACE && !cardSource.IsFlipped && CardEffectCommons.IsExistOnBattleArea(cardSource) || CardEffectCommons.IsExistOnBreedingAreaDigimon(cardSource))
  4242. .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
  4243. .ToList();
  4244. foreach (CardSource cardSource in _cardSources)
  4245. {
  4246. yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
  4247. string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
  4248. PlayLog.OnAddLog?.Invoke(log);
  4249. }
  4250. }
  4251. }
  4252. #endregion
  4253. #region TrashStack
  4254. public class ITrashStack
  4255. {
  4256. /// <summary>
  4257. /// Trash Stack Class
  4258. /// </summary>
  4259. /// <param name="permanent">Target Permanent</param>
  4260. /// <param name="TrashCount">Amount of cards to trash</param>
  4261. /// <param name="cardEffect">Card Effect</param>
  4262. /// <param name="fromTop">Should trashing start from top, true by default</param>
  4263. public ITrashStack(Permanent permanent, int TrashCount, ICardEffect cardEffect, bool fromTop = true)
  4264. {
  4265. _permanent = permanent;
  4266. _trashCount = TrashCount;
  4267. _cardEffect = cardEffect;
  4268. _fromTop = fromTop;
  4269. }
  4270. Permanent _permanent = null;
  4271. int _trashCount;
  4272. ICardEffect _cardEffect = null;
  4273. bool _fromTop;
  4274. public IEnumerator TrashStack()
  4275. {
  4276. if (_cardEffect == null) yield break;
  4277. if (_cardEffect.EffectSourceCard == null) yield break;
  4278. if (_permanent == null) yield break;
  4279. if (_permanent.TopCard == null) yield break;
  4280. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
  4281. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  4282. _trashCount = Math.Min(_permanent.StackCards.Count, _trashCount);
  4283. if (_trashCount >= 1)
  4284. {
  4285. int count = 0;
  4286. List<CardSource> selectedCards = new List<CardSource>();
  4287. while (true)
  4288. {
  4289. bool StopCondition()
  4290. {
  4291. if (_permanent.HasNoDigivolutionCards)
  4292. {
  4293. return true;
  4294. }
  4295. if (count >= _trashCount)
  4296. {
  4297. return true;
  4298. }
  4299. return false;
  4300. }
  4301. if (StopCondition())
  4302. {
  4303. break;
  4304. }
  4305. if (count == 0)
  4306. {
  4307. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  4308. }
  4309. CardSource cardSource = _permanent.TopCard;
  4310. selectedCards.Add(cardSource);
  4311. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  4312. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  4313. if (!cardSource.IsToken)
  4314. {
  4315. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  4316. }
  4317. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  4318. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  4319. count++;
  4320. }
  4321. #region "When Top Card is Trashed" effect
  4322. #region Hashtable Setting
  4323. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  4324. {
  4325. {"Permanent", _permanent},
  4326. {"CardSources", selectedCards}
  4327. };
  4328. #endregion
  4329. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  4330. .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
  4331. #endregion
  4332. #region add log
  4333. if (selectedCards.Count >= 1)
  4334. {
  4335. string log = "";
  4336. log += $"\nStack Trashed :";
  4337. foreach (CardSource cardSource in selectedCards)
  4338. {
  4339. if (cardSource != null)
  4340. {
  4341. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  4342. }
  4343. }
  4344. log += "\n";
  4345. PlayLog.OnAddLog?.Invoke(log);
  4346. }
  4347. #endregion
  4348. }
  4349. }
  4350. }
  4351. #endregion