CardController.cs 211 KB

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