CardController.cs 211 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030
  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. if (isJogress)
  1251. {
  1252. yield return new WaitForEndOfFrame();
  1253. }
  1254. if (_burstDigivolved)
  1255. {
  1256. if (permanent.TopCard != null)
  1257. {
  1258. permanent.IsBurstDigivolved = true;
  1259. GManager.instance.selectBurstDigivolutionEffect.AddTrashTopCardAtTurnEnd(permanent);
  1260. }
  1261. }
  1262. if (_appFusion)
  1263. {
  1264. if (permanent.TopCard != null)
  1265. {
  1266. permanent.IsAppFusion = true;
  1267. }
  1268. }
  1269. permanent.CardNamesJustAfterDigivolved = permanent.TopCard.CardNames.Clone();
  1270. permanent.DigivolvingEffect = CardEffect;
  1271. }
  1272. else
  1273. {
  1274. permanent.PlayingEffect = CardEffect;
  1275. if (permanent.TopCard.HasLevel)
  1276. {
  1277. permanent.LevelJustAfterPlayed = permanent.Level;
  1278. }
  1279. if (permanent.TopCard.HasPlayCost)
  1280. {
  1281. permanent.PlayCostJustAfterPlayed = permanent.TopCard.GetCostItself;
  1282. }
  1283. permanent.CardNamesJustAfterPlayed = permanent.TopCard.CardNames.Clone();
  1284. permanent.TraitsJustAfterPlayed = permanent.TopCard.CardTraits.Clone();
  1285. }
  1286. #region move permanents (hybrid)
  1287. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  1288. {
  1289. if (permanent.TopCard.PreferredFrame() != null)
  1290. {
  1291. if (permanent.PermanentFrame != permanent.TopCard.PreferredFrame())
  1292. {
  1293. if (permanent.TopCard.PreferredFrame().IsEmptyFrame())
  1294. {
  1295. bool move = false;
  1296. if (permanent.IsDigimon)
  1297. {
  1298. if (permanent.TopCard.Owner.isYou)
  1299. {
  1300. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1301. {
  1302. move = true;
  1303. }
  1304. }
  1305. else
  1306. {
  1307. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1308. {
  1309. move = true;
  1310. }
  1311. }
  1312. }
  1313. else if (permanent.IsTamer || permanent.TopCard.IsOption)
  1314. {
  1315. if (permanent.TopCard.Owner.isYou)
  1316. {
  1317. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1318. {
  1319. move = true;
  1320. }
  1321. }
  1322. else
  1323. {
  1324. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1325. {
  1326. move = true;
  1327. }
  1328. }
  1329. }
  1330. if (move)
  1331. {
  1332. yield return ContinuousController.instance.StartCoroutine(CardObjectController.MovePermanent(permanent.PermanentFrame));
  1333. }
  1334. }
  1335. }
  1336. }
  1337. }
  1338. #endregion
  1339. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCardsByEffect(card);
  1340. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCards(card);
  1341. yield return GManager.instance.GetComponent<SelectAssemblyClass>().AddDigivolutiuonCardsByEffect(card);
  1342. yield return GManager.instance.GetComponent<SelectAssemblyClass>().AddDigivolutiuonCards(card);
  1343. if (GManager.instance.turnStateMachine.DoneStartGame)
  1344. {
  1345. hashtableParams.Add(
  1346. new OnEnterFieldHashtableParams(
  1347. permanent: permanent,
  1348. evoRoots: evoRoots,
  1349. evoRootTops: evoRootTops,
  1350. root: _root,
  1351. oldLevels: oldLevels,
  1352. isFromDigimonDigivolutionCards: isFromDigimonDigivolutionCards,
  1353. digiXrosCount: _digiXrosCount,
  1354. assemblyCount: _assemblyCount
  1355. )
  1356. );
  1357. }
  1358. }
  1359. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  1360. GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
  1361. GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
  1362. }
  1363. // except [On Play] effect
  1364. bool CardEffectCondition(ICardEffect cardEffect)
  1365. {
  1366. if (cardEffect == null)
  1367. {
  1368. return false;
  1369. }
  1370. if (!_activateETB)
  1371. {
  1372. if (cardEffect is ActivateICardEffect)
  1373. {
  1374. if (cardEffect.IsOnPlay)
  1375. {
  1376. return false;
  1377. }
  1378. }
  1379. }
  1380. return true;
  1381. }
  1382. Hashtable effectHashtable = CardEffectCommons.OnEnterFieldHashtable(
  1383. hashtableParams: hashtableParams,
  1384. isEvolution: isEvolution,
  1385. isJogress: isJogress,
  1386. digiXrosCount: _digiXrosCount,
  1387. assemblyCount: _assemblyCount,
  1388. cardEffect: CardEffect);
  1389. #region "When permanents are played" effect
  1390. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  1391. hashtable: effectHashtable,
  1392. timing: EffectTiming.OnEnterFieldAnyone,
  1393. cardEffectCondition: CardEffectCondition));
  1394. #endregion
  1395. }
  1396. }
  1397. #endregion
  1398. #region Use option
  1399. public class UseOptionClass
  1400. {
  1401. public UseOptionClass(List<CardSource> cardSources, Hashtable hashtable, SelectCardEffect.Root root)
  1402. {
  1403. if (cardSources != null)
  1404. {
  1405. _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  1406. }
  1407. _hashtable = hashtable;
  1408. _root = root;
  1409. }
  1410. List<CardSource> _cardSources = new List<CardSource>();
  1411. SelectCardEffect.Root _root = SelectCardEffect.Root.None;
  1412. Hashtable _hashtable = null;
  1413. public bool _showEffect = false;
  1414. public IEnumerator UseOption()
  1415. {
  1416. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1417. foreach (CardSource card in _cardSources)
  1418. {
  1419. if (_showEffect)
  1420. {
  1421. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(card));
  1422. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowUseHandCardEffect_PlayCard(card));
  1423. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  1424. }
  1425. PlayLog.OnAddLog?.Invoke($"\nPlay Option:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1426. card.Init();
  1427. card.SetFace();
  1428. int cost = card.GetCostItself;
  1429. //Remove from all areas
  1430. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1431. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(card));
  1432. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.BrainStormCoroutine(card));
  1433. #region Set HashTable
  1434. Hashtable hashtable = new Hashtable()
  1435. {
  1436. {"Card", card},
  1437. {"Root", _root},
  1438. {"Cost", cost},
  1439. };
  1440. #endregion
  1441. #region "When option is used" effect
  1442. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseOption));
  1443. yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.OnUseOption));
  1444. #endregion
  1445. #region effect process of option card
  1446. foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.OptionSkill))
  1447. {
  1448. if (cardEffect is ActivateICardEffect)
  1449. {
  1450. if (cardEffect.CanUse(hashtable))
  1451. {
  1452. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  1453. cardEffect,
  1454. hashtable));
  1455. }
  1456. }
  1457. }
  1458. #endregion
  1459. if (card.Owner.ExecutingCards.Contains(card))
  1460. {
  1461. List<OptionResolutionClass> optionResolutionEffects = new List<OptionResolutionClass>();
  1462. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1463. {
  1464. #region Effects of permanents in play
  1465. foreach (Permanent permanent in player.GetFieldPermanents())
  1466. {
  1467. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1468. {
  1469. if (cardEffect is OptionResolutionClass)
  1470. {
  1471. if (cardEffect.CanUse(null))
  1472. {
  1473. optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
  1474. }
  1475. }
  1476. }
  1477. }
  1478. #endregion
  1479. #region Effects on the Player
  1480. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1481. {
  1482. if (cardEffect is OptionResolutionClass)
  1483. {
  1484. if (cardEffect.CanUse(null))
  1485. {
  1486. optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
  1487. }
  1488. }
  1489. }
  1490. #endregion
  1491. }
  1492. #region effects of the card itself
  1493. foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.None))
  1494. {
  1495. if (cardEffect is OptionResolutionClass)
  1496. {
  1497. if (cardEffect.CanUse(null))
  1498. {
  1499. optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
  1500. }
  1501. }
  1502. }
  1503. #endregion
  1504. while (card.Owner.ExecutingCards.Contains(card))
  1505. {
  1506. List<OptionResolutionClass> possibleEffects = optionResolutionEffects.Filter(effect => effect.CanResolve(card));
  1507. if (possibleEffects.Count() == 0)
  1508. {
  1509. break;
  1510. }
  1511. else if (possibleEffects.Count() == 1)
  1512. {
  1513. OptionResolutionClass currentEffect = possibleEffects[0];
  1514. if (currentEffect != null) yield return ContinuousController.instance.StartCoroutine(currentEffect.Resolve(card));
  1515. optionResolutionEffects.Remove(currentEffect);
  1516. }
  1517. else
  1518. {
  1519. List<SkillInfo> skillInfos = possibleEffects.Map(effect => new SkillInfo(effect, null, EffectTiming.None));
  1520. List<CardSource> rootCardSources = skillInfos.Map(skillInfo => skillInfo.CardEffect.EffectSourceCard);
  1521. int skillIndex = -1;
  1522. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectCardPanel.OpenSelectCardPanel(
  1523. Message: "Option has multiple resolutions instead of going to trash.\nChoose which to process.",
  1524. RootCardSources: rootCardSources,
  1525. _CanTargetCondition: _ => true,
  1526. _CanTargetCondition_ByPreSelecetedList: null,
  1527. _CanEndSelectCondition: null,
  1528. _MaxCount: 1,
  1529. _CanEndNotMax: false,
  1530. _CanNoSelect: () => false,
  1531. CanLookReverseCard: true,
  1532. skillInfos: skillInfos,
  1533. root: SelectCardEffect.Root.None));
  1534. if (GManager.instance.selectCardPanel.SelectedIndex.Count > 0)
  1535. {
  1536. skillIndex = GManager.instance.selectCardPanel.SelectedIndex[0];
  1537. }
  1538. if (skillIndex >= 0)
  1539. {
  1540. OptionResolutionClass currentEffect = possibleEffects[skillIndex];
  1541. if (currentEffect != null) yield return ContinuousController.instance.StartCoroutine(currentEffect.Resolve(card));
  1542. optionResolutionEffects.Remove(currentEffect);
  1543. }
  1544. else
  1545. {
  1546. break; // Should not happen, unless we later allow denying all by no select
  1547. }
  1548. }
  1549. }
  1550. }
  1551. if (card.Owner.ExecutingCards.Contains(card))
  1552. {
  1553. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(card));
  1554. }
  1555. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  1556. }
  1557. }
  1558. }
  1559. #endregion
  1560. #region Draw cards
  1561. public class DrawClass
  1562. {
  1563. public DrawClass(Player player, int drawCount, ICardEffect cardEffect)
  1564. {
  1565. _player = player;
  1566. _drawCount = drawCount;
  1567. _cardEffect = cardEffect;
  1568. }
  1569. Player _player = null;
  1570. int _drawCount = 0;
  1571. ICardEffect _cardEffect = null;
  1572. public IEnumerator Draw()
  1573. {
  1574. if (_drawCount <= 0) yield break;
  1575. if (_player.LibraryCards.Count <= 0) yield break;
  1576. List<CardSource> DrawCards = new List<CardSource>();
  1577. for (int i = 0; i < _drawCount; i++)
  1578. {
  1579. if (_player.LibraryCards.Count > 0)
  1580. {
  1581. CardSource DrawCard = _player.LibraryCards[0];
  1582. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(DrawCard));
  1583. DrawCards.Add(DrawCard);
  1584. }
  1585. }
  1586. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(DrawCards, true, _cardEffect));
  1587. #region add log
  1588. if (DrawCards.Count >= 1)
  1589. {
  1590. PlayLog.OnAddLog?.Invoke($"\nDraw {DrawCards.Count} card{Utils.PluralFormSuffix(DrawCards.Count)}\n{_player.PlayerName}\n");
  1591. }
  1592. #endregion
  1593. #region "When draw cards" effect
  1594. if (DrawCards.Count >= 1)
  1595. {
  1596. #region Hashtable setting
  1597. Hashtable _hashtable = new Hashtable()
  1598. {
  1599. {"Player", _player},
  1600. {"CardEffect", _cardEffect}
  1601. };
  1602. #endregion
  1603. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnDraw));
  1604. }
  1605. #endregion
  1606. }
  1607. }
  1608. #endregion
  1609. #region Trash cards from deck too
  1610. public class IAddTrashCardsFromLibraryTop
  1611. {
  1612. private static WaitForSeconds _waitForSeconds0_06 = new WaitForSeconds(0.06f);
  1613. public IAddTrashCardsFromLibraryTop(int addTrashCount, Player player, ICardEffect cardEffect)
  1614. {
  1615. _addTrashCount = addTrashCount;
  1616. _player = player;
  1617. _cardEffect = cardEffect;
  1618. }
  1619. public void SetNotShowCards()
  1620. {
  1621. _notShowCards = true;
  1622. }
  1623. int _addTrashCount;
  1624. Player _player;
  1625. public List<CardSource> discardedCards = new List<CardSource>();
  1626. ICardEffect _cardEffect { get; set; } = null;
  1627. bool _notShowCards = false;
  1628. public IEnumerator AddTrashCardsFromLibraryTop()
  1629. {
  1630. if (_addTrashCount <= 0) yield break;
  1631. if (_player.LibraryCards.Count == 0) yield break;
  1632. string log = "";
  1633. log += $"\nTrash cards from deck :";
  1634. for (int i = 0; i < _addTrashCount; i++)
  1635. {
  1636. if (_player.LibraryCards.Count > i)
  1637. {
  1638. CardSource DiscardCard = _player.LibraryCards[i];
  1639. discardedCards.Add(DiscardCard);
  1640. log += $"\n{DiscardCard.BaseENGCardNameFromEntity}({DiscardCard.CardID})";
  1641. }
  1642. }
  1643. if (discardedCards.Count >= 1)
  1644. {
  1645. if (!_notShowCards)
  1646. {
  1647. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  1648. }
  1649. }
  1650. yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(discardedCards, _cardEffect).TrashDeckCards());
  1651. if (discardedCards.Count >= 1)
  1652. {
  1653. for (int i = 0; i < discardedCards.Count; i++)
  1654. {
  1655. ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
  1656. yield return _waitForSeconds0_06;
  1657. }
  1658. log += "\n";
  1659. PlayLog.OnAddLog?.Invoke(log);
  1660. }
  1661. }
  1662. }
  1663. #endregion
  1664. #region Add security from deck top
  1665. public class IAddSecurityFromLibrary
  1666. {
  1667. public IAddSecurityFromLibrary(Player player, int addLifeCount)
  1668. {
  1669. _player = player;
  1670. _addSecurityCount = addLifeCount;
  1671. }
  1672. Player _player = null;
  1673. int _addSecurityCount = 0;
  1674. public IEnumerator AddSecurity()
  1675. {
  1676. int count = 0;
  1677. for (int i = 0; i < _addSecurityCount; i++)
  1678. {
  1679. if (_player.LibraryCards.Count > 0)
  1680. {
  1681. CardSource StockCard = _player.LibraryCards[0];
  1682. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(StockCard, useEffect: (i == 0)));
  1683. count++;
  1684. }
  1685. }
  1686. if (count > 0)
  1687. {
  1688. string log = "";
  1689. log += $"\nAdd {count} cards to security:{_player.PlayerName}";
  1690. log += "\n";
  1691. PlayLog.OnAddLog?.Invoke(log);
  1692. }
  1693. }
  1694. }
  1695. #endregion
  1696. #region Recovery
  1697. public class IRecovery
  1698. {
  1699. public IRecovery(Player player, int AddLifeCount, ICardEffect cardEffect)
  1700. {
  1701. _player = player;
  1702. _addLifeCount = AddLifeCount;
  1703. _cardEffect = cardEffect;
  1704. }
  1705. Player _player = null;
  1706. int _addLifeCount = 0;
  1707. ICardEffect _cardEffect = null;
  1708. public IEnumerator Recovery()
  1709. {
  1710. if (_player.LibraryCards.Count == 0) yield break;
  1711. if (_addLifeCount <= 0) yield break;
  1712. if (!_player.CanAddSecurity(_cardEffect)) yield break;
  1713. yield return ContinuousController.instance.StartCoroutine(new IAddSecurityFromLibrary(_player, _addLifeCount).AddSecurity());
  1714. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(_player));
  1715. }
  1716. }
  1717. #endregion
  1718. #region Digi-Burst
  1719. public class IDigiBurst
  1720. {
  1721. public IDigiBurst(Permanent permanent, int DigiBurstCount, ICardEffect cardEffect)
  1722. {
  1723. _permanent = permanent;
  1724. _digiBurstCount = DigiBurstCount;
  1725. _cardEffect = cardEffect;
  1726. }
  1727. Permanent _permanent = null;
  1728. int _digiBurstCount = 0;
  1729. ICardEffect _cardEffect = null;
  1730. bool _upToMaxCount = false;
  1731. public List<CardSource> discardedCards = new List<CardSource>();
  1732. public void SetUpToMaxCount()
  1733. {
  1734. _upToMaxCount = true;
  1735. }
  1736. public bool CanDigiBurst()
  1737. {
  1738. if (_permanent != null)
  1739. {
  1740. if (_permanent.TopCard != null)
  1741. {
  1742. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) return false;
  1743. if (_upToMaxCount)
  1744. {
  1745. if (_permanent.DigivolutionCards.Some((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)))
  1746. {
  1747. return true;
  1748. }
  1749. }
  1750. else
  1751. {
  1752. if (_permanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)) >= _digiBurstCount)
  1753. {
  1754. return true;
  1755. }
  1756. }
  1757. }
  1758. }
  1759. return false;
  1760. }
  1761. public IEnumerator DigiBurst()
  1762. {
  1763. if (CanDigiBurst())
  1764. {
  1765. discardedCards = new List<CardSource>();
  1766. List<CardSource> selectedCards = new List<CardSource>();
  1767. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  1768. selectCardEffect.SetUp(
  1769. canTargetCondition: (cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect),
  1770. canTargetCondition_ByPreSelecetedList: null,
  1771. canEndSelectCondition: CanEndSelectCondition,
  1772. canNoSelect: () => false,
  1773. selectCardCoroutine: SelectCardCoroutine,
  1774. afterSelectCardCoroutine: null,
  1775. message: "Select digivolution cards to discard.",
  1776. maxCount: _digiBurstCount,
  1777. canEndNotMax: _upToMaxCount,
  1778. isShowOpponent: true,
  1779. mode: SelectCardEffect.Mode.Custom,
  1780. root: SelectCardEffect.Root.Custom,
  1781. customRootCardList: _permanent.DigivolutionCards,
  1782. canLookReverseCard: true,
  1783. selectPlayer: _permanent.TopCard.Owner,
  1784. cardEffect: null);
  1785. selectCardEffect.SetUseFaceDown();
  1786. selectCardEffect.SetUpCustomMessage("Select digivolution cards to discard.", "The opponent is selecting digivolution cards to discard.");
  1787. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  1788. bool CanEndSelectCondition(List<CardSource> cardSources)
  1789. {
  1790. if (CardEffectCommons.HasNoElement(cardSources))
  1791. {
  1792. return false;
  1793. }
  1794. return true;
  1795. }
  1796. IEnumerator SelectCardCoroutine(CardSource cardSource)
  1797. {
  1798. selectedCards.Add(cardSource);
  1799. yield return null;
  1800. }
  1801. if (selectedCards.Count >= 1)
  1802. {
  1803. #region "When use Digi-Burst" effect
  1804. #region Hashtable setting
  1805. Hashtable hashtable = new Hashtable()
  1806. {
  1807. {"Permanent", _permanent},
  1808. {"CardEffect", _cardEffect},
  1809. };
  1810. #endregion
  1811. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseDigiburst));
  1812. #endregion
  1813. // trash digivolution cards
  1814. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(_permanent, selectedCards, _cardEffect).TrashDigivolutionCards());
  1815. foreach (CardSource cardSource in selectedCards)
  1816. {
  1817. discardedCards.Add(cardSource);
  1818. }
  1819. #region add log
  1820. if (selectedCards.Count >= 1)
  1821. {
  1822. string log = "";
  1823. log += $"\nDigiburst :";
  1824. foreach (CardSource cardSource in selectedCards)
  1825. {
  1826. if (cardSource != null)
  1827. {
  1828. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  1829. }
  1830. }
  1831. log += "\n";
  1832. PlayLog.OnAddLog?.Invoke(log);
  1833. }
  1834. #endregion
  1835. }
  1836. }
  1837. }
  1838. }
  1839. #endregion
  1840. #region Place permanents to deck bottom
  1841. public class DeckBottomBounceClass
  1842. {
  1843. public DeckBottomBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
  1844. {
  1845. _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
  1846. _hashtable = hashtable;
  1847. }
  1848. public void SetNotShowCards()
  1849. {
  1850. _notShowCards = true;
  1851. }
  1852. public bool IsDeckBounced(Permanent permanent)
  1853. {
  1854. return DeckBouncedPermanents.Contains(permanent);
  1855. }
  1856. List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
  1857. public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
  1858. Hashtable _hashtable = new Hashtable();
  1859. bool _notShowCards = false;
  1860. public IEnumerator DeckBounce()
  1861. {
  1862. if (_deckBounceTargetPermanents == null) yield break;
  1863. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1864. _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
  1865. permanent != null
  1866. && permanent.TopCard != null
  1867. && (cardEffect == null ||
  1868. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1869. && !permanent.CannotReturnToLibrary(cardEffect)
  1870. && permanent.CanBeRemoved())));
  1871. if (_deckBounceTargetPermanents.Count == 0) yield break;
  1872. _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1873. #region cut in effect
  1874. // "When permanents would return to deck" effect
  1875. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1876. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1877. _deckBounceTargetPermanents,
  1878. cardEffect,
  1879. null
  1880. ),
  1881. EffectTiming.WhenReturntoLibraryAnyone));
  1882. // "When permanents would remove field" effect
  1883. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1884. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1885. _deckBounceTargetPermanents,
  1886. cardEffect,
  1887. null
  1888. ),
  1889. EffectTiming.WhenRemoveField));
  1890. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1891. {
  1892. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1893. {
  1894. permanent.ShowDeckBounceEffect();
  1895. }
  1896. // cut in effect process
  1897. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1898. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1899. {
  1900. permanent.HideDeckBounceEffect();
  1901. }
  1902. }
  1903. #endregion
  1904. // fix deck bounce target permanents
  1905. List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
  1906. permanent != null
  1907. && permanent.TopCard != null
  1908. && permanent.willBeRemoveField);
  1909. #region show cards
  1910. List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1911. if (!_notShowCards)
  1912. {
  1913. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
  1914. }
  1915. #endregion
  1916. #region "When permanents leave the battle area" effect
  1917. if (deckBounceTargetPermanents_Fixed.Count > 0) yield return ContinuousController.instance.StartCoroutine(
  1918. GManager.instance.autoProcessing.StackSkillInfos(
  1919. CardEffectCommons.OnDeletionHashtable(
  1920. deckBounceTargetPermanents_Fixed,
  1921. cardEffect,
  1922. null,
  1923. false
  1924. ),
  1925. EffectTiming.OnLeaveFieldAnyone));
  1926. #endregion
  1927. #region
  1928. List<CardSource> deckBottomCards = new List<CardSource>();
  1929. foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
  1930. {
  1931. #region recoed used effect
  1932. if (permanent.TopCard != null)
  1933. {
  1934. permanent.LibraryBounceEffect = cardEffect;
  1935. }
  1936. #endregion
  1937. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
  1938. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1939. CardSource topCard = permanent.TopCard;
  1940. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1941. deckBottomCards.Add(topCard);
  1942. DeckBouncedPermanents.Add(permanent);
  1943. }
  1944. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(deckBottomCards));
  1945. #endregion
  1946. #region off icon
  1947. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1948. {
  1949. if (permanent != null)
  1950. {
  1951. if (permanent.TopCard != null)
  1952. {
  1953. permanent.willBeRemoveField = false;
  1954. }
  1955. }
  1956. }
  1957. #endregion
  1958. }
  1959. }
  1960. #endregion
  1961. #region Place permanents to deck top
  1962. public class DeckTopBounceClass
  1963. {
  1964. public DeckTopBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
  1965. {
  1966. _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
  1967. _hashtable = hashtable;
  1968. }
  1969. public void SetNotShowCards()
  1970. {
  1971. _notShowCards = true;
  1972. }
  1973. public bool IsDeckBounced(Permanent permanent)
  1974. {
  1975. return DeckBouncedPermanents.Contains(permanent);
  1976. }
  1977. List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
  1978. public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
  1979. Hashtable _hashtable = new Hashtable();
  1980. bool _notShowCards = false;
  1981. public IEnumerator DeckBounce()
  1982. {
  1983. if (_deckBounceTargetPermanents == null) yield break;
  1984. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1985. _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
  1986. permanent != null
  1987. && permanent.TopCard != null
  1988. && (cardEffect == null ||
  1989. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1990. && !permanent.CannotReturnToLibrary(cardEffect)
  1991. && permanent.CanBeRemoved())));
  1992. if (_deckBounceTargetPermanents.Count == 0) yield break;
  1993. _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1994. #region cut in effect
  1995. // "When permanents would return to deck" effect
  1996. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1997. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1998. _deckBounceTargetPermanents,
  1999. cardEffect,
  2000. null
  2001. ),
  2002. EffectTiming.WhenReturntoLibraryAnyone));
  2003. // "When permanents would remove field" effect
  2004. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2005. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2006. _deckBounceTargetPermanents,
  2007. cardEffect,
  2008. null
  2009. ),
  2010. EffectTiming.WhenRemoveField));
  2011. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2012. {
  2013. foreach (Permanent permanent in _deckBounceTargetPermanents)
  2014. {
  2015. permanent.ShowDeckBounceEffect();
  2016. }
  2017. // cut in effect process
  2018. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2019. foreach (Permanent permanent in _deckBounceTargetPermanents)
  2020. {
  2021. permanent.HideDeckBounceEffect();
  2022. }
  2023. }
  2024. #endregion
  2025. // fix deck bounce target permanents
  2026. List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
  2027. permanent != null
  2028. && permanent.TopCard != null
  2029. && permanent.willBeRemoveField);
  2030. #region show cards
  2031. List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2032. if (!_notShowCards)
  2033. {
  2034. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
  2035. }
  2036. #endregion
  2037. #region "When permanents leave the battle area" effect
  2038. if (deckBounceTargetPermanents_Fixed.Count > 0) yield return ContinuousController.instance.StartCoroutine(
  2039. GManager.instance.autoProcessing.StackSkillInfos(
  2040. CardEffectCommons.OnDeletionHashtable(
  2041. deckBounceTargetPermanents_Fixed,
  2042. cardEffect,
  2043. null,
  2044. false
  2045. ),
  2046. EffectTiming.OnLeaveFieldAnyone));
  2047. #endregion
  2048. #region
  2049. List<CardSource> deckTopCards = new List<CardSource>();
  2050. foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
  2051. {
  2052. #region recoed used effect
  2053. if (permanent.TopCard != null)
  2054. {
  2055. permanent.LibraryBounceEffect = cardEffect;
  2056. }
  2057. #endregion
  2058. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
  2059. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2060. CardSource topCard = permanent.TopCard;
  2061. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2062. deckTopCards.Add(topCard);
  2063. DeckBouncedPermanents.Add(permanent);
  2064. }
  2065. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryTopCards(deckTopCards));
  2066. #endregion
  2067. #region off icon
  2068. foreach (Permanent permanent in _deckBounceTargetPermanents)
  2069. {
  2070. if (permanent != null)
  2071. {
  2072. if (permanent.TopCard != null)
  2073. {
  2074. permanent.willBeRemoveField = false;
  2075. }
  2076. }
  2077. }
  2078. #endregion
  2079. }
  2080. }
  2081. #endregion
  2082. #region Return permanent to hand
  2083. public class HandBounceClaass
  2084. {
  2085. public HandBounceClaass(List<Permanent> bounceTargetPermanents, Hashtable hashtable)
  2086. {
  2087. _bounceTargetPermanents = bounceTargetPermanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  2088. _hashtable = hashtable;
  2089. }
  2090. public bool IsBounced(Permanent permanent)
  2091. {
  2092. return BouncedPermanents.Contains(permanent);
  2093. }
  2094. List<Permanent> _bounceTargetPermanents = new List<Permanent>();
  2095. public List<Permanent> BouncedPermanents { get; private set; } = new List<Permanent>();
  2096. Hashtable _hashtable = new Hashtable();
  2097. bool _notShowCards = false;
  2098. public IEnumerator Bounce()
  2099. {
  2100. if (_bounceTargetPermanents == null) yield break;
  2101. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2102. _bounceTargetPermanents = _bounceTargetPermanents.Filter(permanent =>
  2103. permanent != null
  2104. && permanent.TopCard != null
  2105. && (cardEffect == null ||
  2106. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  2107. && !permanent.CannotReturnToHand(cardEffect)
  2108. && permanent.CanBeRemoved())));
  2109. if (_bounceTargetPermanents.Count == 0) yield break;
  2110. _bounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  2111. #region cut in effect
  2112. // "When permanents would return to hand" effect
  2113. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2114. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2115. _bounceTargetPermanents,
  2116. cardEffect,
  2117. null
  2118. ),
  2119. EffectTiming.WhenReturntoHandAnyone));
  2120. // "When permanents would remove field" effect
  2121. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2122. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2123. _bounceTargetPermanents,
  2124. cardEffect,
  2125. null
  2126. ),
  2127. EffectTiming.WhenRemoveField));
  2128. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2129. {
  2130. foreach (Permanent permanent in _bounceTargetPermanents)
  2131. {
  2132. permanent.ShowHandBounceEffect();
  2133. }
  2134. // shrink security Digimon display
  2135. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2136. // cut in effect process
  2137. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2138. foreach (Permanent permanent in _bounceTargetPermanents)
  2139. {
  2140. permanent.HideHandBounceEffect();
  2141. }
  2142. }
  2143. #endregion
  2144. // fix bounce target permanents
  2145. List<Permanent> bounceTargetPermanents_Fixed = _bounceTargetPermanents.Filter(permanent =>
  2146. permanent != null
  2147. && permanent.TopCard != null
  2148. && permanent.willBeRemoveField);
  2149. #region "When permanents returned to hand" effect
  2150. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2151. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2152. bounceTargetPermanents_Fixed,
  2153. cardEffect,
  2154. null,
  2155. false
  2156. ),
  2157. EffectTiming.OnPermamemtReturnedToHand));
  2158. #endregion
  2159. #region "When permanents leave the battle area" effect
  2160. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2161. CardEffectCommons.OnDeletionHashtable(
  2162. bounceTargetPermanents_Fixed,
  2163. cardEffect,
  2164. null,
  2165. false
  2166. ),
  2167. EffectTiming.OnLeaveFieldAnyone));
  2168. #endregion
  2169. #region record parameter just before bounce
  2170. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  2171. {
  2172. permanent.DPJustBeforeRemoveField = permanent.DP;
  2173. if (permanent.TopCard.HasLevel)
  2174. {
  2175. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2176. }
  2177. if (permanent.TopCard.HasPlayCost)
  2178. {
  2179. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  2180. }
  2181. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  2182. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  2183. foreach (CardSource cardSource in permanent.cardSources)
  2184. {
  2185. cardSource.PermanentJustBeforeRemoveField = permanent;
  2186. }
  2187. }
  2188. #endregion
  2189. #region add log
  2190. if (bounceTargetPermanents_Fixed.Count >= 1)
  2191. {
  2192. string log = "";
  2193. log += $"\nReturn to hand:";
  2194. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  2195. {
  2196. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  2197. }
  2198. log += "\n";
  2199. PlayLog.OnAddLog?.Invoke(log);
  2200. }
  2201. #endregion
  2202. #region show cards
  2203. List<CardSource> returnedCards = bounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2204. if (!_notShowCards)
  2205. {
  2206. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Cards returned to hand", true, true));
  2207. }
  2208. #endregion
  2209. #region return permanent cards to hand
  2210. List<CardSource> handCards = new List<CardSource>();
  2211. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  2212. {
  2213. #region record used effect
  2214. if (permanent.TopCard != null)
  2215. {
  2216. permanent.HandBounceEffect = cardEffect;
  2217. }
  2218. #endregion
  2219. // record whether to return to hand by Burst Digivolution
  2220. permanent.IsReturnedToHandByBurstDigivolution = CardEffectCommons.IsBurst(_hashtable);
  2221. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BounceEffect(permanent, !permanent.IsReturnedToHandByBurstDigivolution));
  2222. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2223. CardSource topCard = permanent.TopCard;
  2224. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2225. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(topCard));
  2226. if (!topCard.IsDigiEgg)
  2227. {
  2228. handCards.Add(topCard);
  2229. BouncedPermanents.Add(permanent);
  2230. }
  2231. else
  2232. {
  2233. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2234. }
  2235. }
  2236. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
  2237. #endregion
  2238. #region hide icon
  2239. foreach (Permanent permanent in _bounceTargetPermanents)
  2240. {
  2241. if (permanent != null)
  2242. {
  2243. if (permanent.TopCard != null)
  2244. {
  2245. permanent.willBeRemoveField = false;
  2246. }
  2247. }
  2248. }
  2249. #endregion
  2250. }
  2251. }
  2252. #endregion
  2253. #region Place permanent to another permanent's digivolution cards
  2254. public class IPlacePermanentToDigivolutionCards
  2255. {
  2256. public IPlacePermanentToDigivolutionCards(
  2257. List<Permanent[]> permanentArrays,
  2258. bool toTop,
  2259. ICardEffect cardEffect,
  2260. bool skipEffectAndActivateSkill = false,
  2261. bool isDigixros = false)
  2262. {
  2263. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  2264. _toTop = toTop;
  2265. _cardEffect = cardEffect;
  2266. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  2267. _isDigixros = isDigixros;
  2268. }
  2269. public void SetNotShowCards()
  2270. {
  2271. _notShowCards = true;
  2272. }
  2273. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  2274. ICardEffect _cardEffect = null;
  2275. bool _toTop = false;
  2276. bool _notShowCards = false;
  2277. bool _skipEffectAndActivateSkill = false;
  2278. bool _isDigixros = false;
  2279. public bool Placed { get; private set; } = false;
  2280. public IEnumerator PlacePermanentToDigivolutionCards()
  2281. {
  2282. if (_permanentArrays.Count == 0)
  2283. {
  2284. yield break;
  2285. }
  2286. List<CardSource> addedDigivolutionCards = new List<CardSource>();
  2287. List<Permanent> removeFieldPermanents = new List<Permanent>();
  2288. foreach (Permanent[] permanentArray in _permanentArrays)
  2289. {
  2290. if (permanentArray.Length == 2)
  2291. {
  2292. Permanent DigivolutionPermanent = permanentArray[0];
  2293. Permanent getDigivolutionPermanent = permanentArray[1];
  2294. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  2295. {
  2296. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
  2297. {
  2298. if (_cardEffect != null)
  2299. {
  2300. if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
  2301. {
  2302. continue;
  2303. }
  2304. }
  2305. removeFieldPermanents.Add(DigivolutionPermanent);
  2306. }
  2307. }
  2308. }
  2309. }
  2310. foreach (Permanent permanent in removeFieldPermanents)
  2311. {
  2312. permanent.willBeRemoveField = true;
  2313. }
  2314. if (removeFieldPermanents.Count == 0)
  2315. {
  2316. yield break;
  2317. }
  2318. #region
  2319. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2320. Hashtable hashtable1 =
  2321. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2322. removeFieldPermanents,
  2323. _cardEffect,
  2324. null,
  2325. _isDigixros);
  2326. #region "When permanents would remove field" effect
  2327. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2328. {
  2329. #region permanents' effects
  2330. foreach (Permanent permanent1 in player.GetFieldPermanents())
  2331. {
  2332. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  2333. {
  2334. if (cardEffect is ActivateICardEffect)
  2335. {
  2336. if (cardEffect.CanTrigger(hashtable1))
  2337. {
  2338. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2339. }
  2340. }
  2341. }
  2342. }
  2343. #endregion
  2344. #region players' effects
  2345. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  2346. {
  2347. if (cardEffect is ActivateICardEffect)
  2348. {
  2349. if (cardEffect.CanTrigger(hashtable1))
  2350. {
  2351. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2352. }
  2353. }
  2354. }
  2355. #endregion
  2356. }
  2357. #endregion
  2358. if (skillInfos.Count >= 1)
  2359. {
  2360. foreach (SkillInfo skillInfo in skillInfos)
  2361. {
  2362. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  2363. }
  2364. bool showEffect()
  2365. {
  2366. if (skillInfos.Count >= 2)
  2367. {
  2368. return true;
  2369. }
  2370. else if (skillInfos.Count == 1)
  2371. {
  2372. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  2373. {
  2374. return true;
  2375. }
  2376. }
  2377. return false;
  2378. }
  2379. if (showEffect())
  2380. {
  2381. foreach (Permanent Permanent in removeFieldPermanents)
  2382. {
  2383. if (Permanent != null)
  2384. {
  2385. if (Permanent.TopCard != null)
  2386. {
  2387. if (Permanent.willBeRemoveField)
  2388. {
  2389. if (Permanent.ShowingPermanentCard != null)
  2390. {
  2391. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2392. {
  2393. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  2394. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  2395. }
  2396. }
  2397. }
  2398. }
  2399. }
  2400. }
  2401. #region shrink security Digimon display
  2402. if (GManager.instance.attackProcess.IsAttacking)
  2403. {
  2404. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2405. {
  2406. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2407. {
  2408. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2409. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2410. }
  2411. }
  2412. }
  2413. #endregion
  2414. }
  2415. // cut in effect process
  2416. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2417. foreach (Permanent Permanent in removeFieldPermanents)
  2418. {
  2419. if (Permanent != null)
  2420. {
  2421. if (Permanent.TopCard != null)
  2422. {
  2423. if (Permanent.ShowingPermanentCard != null)
  2424. {
  2425. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2426. {
  2427. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. #endregion
  2435. foreach (Permanent[] permanentArray in _permanentArrays)
  2436. {
  2437. if (permanentArray.Length == 2)
  2438. {
  2439. Permanent DigivolutionPermanent = permanentArray[0];
  2440. Permanent getDigivolutionPermanent = permanentArray[1];
  2441. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  2442. {
  2443. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
  2444. {
  2445. yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
  2446. CardSource cardSource = DigivolutionPermanent.TopCard;
  2447. #region record used effect
  2448. if (_cardEffect != null)
  2449. {
  2450. if (DigivolutionPermanent.TopCard != null)
  2451. {
  2452. DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
  2453. }
  2454. }
  2455. #endregion
  2456. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  2457. DigivolutionPermanent,
  2458. ignoreOverflow: true));
  2459. List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
  2460. if (_toTop)
  2461. {
  2462. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
  2463. }
  2464. else
  2465. {
  2466. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
  2467. }
  2468. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  2469. addedDigivolutionCards.Add(cardSource);
  2470. Placed = true;
  2471. }
  2472. }
  2473. }
  2474. }
  2475. #region add log
  2476. if (addedDigivolutionCards.Count >= 1)
  2477. {
  2478. string log = "";
  2479. log += $"\nPlace in digivolution cards:";
  2480. foreach (CardSource cardSource in addedDigivolutionCards)
  2481. {
  2482. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2483. }
  2484. log += "\n";
  2485. PlayLog.OnAddLog?.Invoke(log);
  2486. }
  2487. #endregion
  2488. #region hide icon
  2489. if (addedDigivolutionCards.Count >= 1)
  2490. {
  2491. if (!_notShowCards)
  2492. {
  2493. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
  2494. }
  2495. }
  2496. #endregion
  2497. }
  2498. }
  2499. #endregion
  2500. #region Place permanent to another permanent's Link cards
  2501. public class IPlacePermanentToLinkCards
  2502. {
  2503. public IPlacePermanentToLinkCards(
  2504. List<Permanent[]> permanentArrays,
  2505. ICardEffect cardEffect,
  2506. bool skipEffectAndActivateSkill = false)
  2507. {
  2508. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  2509. _cardEffect = cardEffect;
  2510. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  2511. }
  2512. public void SetNotShowCards()
  2513. {
  2514. _notShowCards = true;
  2515. }
  2516. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  2517. ICardEffect _cardEffect = null;
  2518. bool _notShowCards = false;
  2519. bool _skipEffectAndActivateSkill = false;
  2520. public bool Placed { get; private set; } = false;
  2521. public IEnumerator PlacePermanentToLinkCards()
  2522. {
  2523. if (_permanentArrays.Count == 0)
  2524. {
  2525. yield break;
  2526. }
  2527. List<CardSource> addedLinkCards = new List<CardSource>();
  2528. List<Permanent> removeFieldPermanents = new List<Permanent>();
  2529. foreach (Permanent[] permanentArray in _permanentArrays)
  2530. {
  2531. if (permanentArray.Length == 2)
  2532. {
  2533. Permanent LinkedPermanent = permanentArray[0];
  2534. Permanent getLinkPermanent = permanentArray[1];
  2535. if (LinkedPermanent != null && getLinkPermanent != null)
  2536. {
  2537. if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken)
  2538. {
  2539. if (_cardEffect != null)
  2540. {
  2541. if (LinkedPermanent.TopCard.CanNotBeAffected(_cardEffect) || getLinkPermanent.TopCard.CanNotBeAffected(_cardEffect))
  2542. {
  2543. continue;
  2544. }
  2545. }
  2546. removeFieldPermanents.Add(LinkedPermanent);
  2547. }
  2548. }
  2549. }
  2550. }
  2551. foreach (Permanent permanent in removeFieldPermanents)
  2552. {
  2553. permanent.willBeRemoveField = true;
  2554. }
  2555. if (removeFieldPermanents.Count == 0)
  2556. {
  2557. yield break;
  2558. }
  2559. #region Cut in Effects
  2560. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2561. Hashtable hashtable1 =
  2562. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2563. removeFieldPermanents,
  2564. _cardEffect,
  2565. null);
  2566. #region "When permanents would remove field" effect
  2567. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2568. {
  2569. #region permanents' effects
  2570. foreach (Permanent permanent1 in player.GetFieldPermanents())
  2571. {
  2572. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  2573. {
  2574. if (cardEffect is ActivateICardEffect)
  2575. {
  2576. if (cardEffect.CanTrigger(hashtable1))
  2577. {
  2578. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2579. }
  2580. }
  2581. }
  2582. }
  2583. #endregion
  2584. #region players' effects
  2585. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  2586. {
  2587. if (cardEffect is ActivateICardEffect)
  2588. {
  2589. if (cardEffect.CanTrigger(hashtable1))
  2590. {
  2591. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2592. }
  2593. }
  2594. }
  2595. #endregion
  2596. }
  2597. #endregion
  2598. if (skillInfos.Count >= 1)
  2599. {
  2600. foreach (SkillInfo skillInfo in skillInfos)
  2601. {
  2602. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  2603. }
  2604. bool showEffect()
  2605. {
  2606. if (skillInfos.Count >= 2)
  2607. {
  2608. return true;
  2609. }
  2610. else if (skillInfos.Count == 1)
  2611. {
  2612. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  2613. {
  2614. return true;
  2615. }
  2616. }
  2617. return false;
  2618. }
  2619. if (showEffect())
  2620. {
  2621. foreach (Permanent Permanent in removeFieldPermanents)
  2622. {
  2623. if (Permanent != null)
  2624. {
  2625. if (Permanent.TopCard != null)
  2626. {
  2627. if (Permanent.willBeRemoveField)
  2628. {
  2629. if (Permanent.ShowingPermanentCard != null)
  2630. {
  2631. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2632. {
  2633. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  2634. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  2635. }
  2636. }
  2637. }
  2638. }
  2639. }
  2640. }
  2641. #region shrink security Digimon display
  2642. if (GManager.instance.attackProcess.IsAttacking)
  2643. {
  2644. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2645. {
  2646. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2647. {
  2648. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2649. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2650. }
  2651. }
  2652. }
  2653. #endregion
  2654. }
  2655. // cut in effect process
  2656. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2657. foreach (Permanent Permanent in removeFieldPermanents)
  2658. {
  2659. if (Permanent != null)
  2660. {
  2661. if (Permanent.TopCard != null)
  2662. {
  2663. if (Permanent.ShowingPermanentCard != null)
  2664. {
  2665. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2666. {
  2667. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  2668. }
  2669. }
  2670. }
  2671. }
  2672. }
  2673. }
  2674. #endregion
  2675. foreach (Permanent[] permanentArray in _permanentArrays)
  2676. {
  2677. if (permanentArray.Length == 2)
  2678. {
  2679. Permanent LinkedPermanent = permanentArray[0];
  2680. Permanent getLinkPermanent = permanentArray[1];
  2681. if (LinkedPermanent != null && getLinkPermanent != null)
  2682. {
  2683. if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken && LinkedPermanent.willBeRemoveField)
  2684. {
  2685. #region "When permanents leave the battle area" effect
  2686. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2687. CardEffectCommons.OnDeletionHashtable(
  2688. new List<Permanent> { LinkedPermanent },
  2689. _cardEffect,
  2690. null,
  2691. false
  2692. ),
  2693. EffectTiming.OnLeaveFieldAnyone));
  2694. #endregion
  2695. yield return ContinuousController.instance.StartCoroutine(LinkedPermanent.DiscardEvoRoots());
  2696. CardSource cardSource = LinkedPermanent.TopCard;
  2697. #region record used effect
  2698. if (_cardEffect != null)
  2699. {
  2700. if (LinkedPermanent.TopCard != null)
  2701. {
  2702. LinkedPermanent.PlaceOtherPermanentEffect = _cardEffect;
  2703. }
  2704. }
  2705. #endregion
  2706. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  2707. LinkedPermanent,
  2708. ignoreOverflow: true));
  2709. yield return ContinuousController.instance.StartCoroutine(getLinkPermanent.AddLinkCard(cardSource, _cardEffect));
  2710. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  2711. addedLinkCards.Add(cardSource);
  2712. Placed = true;
  2713. }
  2714. }
  2715. }
  2716. }
  2717. #region add log
  2718. if (addedLinkCards.Count >= 1)
  2719. {
  2720. string log = "";
  2721. log += $"\nLink cards:";
  2722. foreach (CardSource cardSource in addedLinkCards)
  2723. {
  2724. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2725. }
  2726. log += "\n";
  2727. PlayLog.OnAddLog?.Invoke(log);
  2728. }
  2729. #endregion
  2730. #region hide icon
  2731. if (addedLinkCards.Count >= 1)
  2732. {
  2733. if (!_notShowCards)
  2734. {
  2735. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedLinkCards, "Link Cards", true, true));
  2736. }
  2737. }
  2738. #endregion
  2739. }
  2740. }
  2741. #endregion
  2742. #region Link a Card to a Permanent
  2743. public class ILinkCard
  2744. {
  2745. public ILinkCard(bool payCost, CardSource card, Permanent permanent, ICardEffect cardEffect)
  2746. {
  2747. _payCost = payCost;
  2748. _linkCard = card;
  2749. _permanent = permanent;
  2750. _cardEffect = cardEffect;
  2751. }
  2752. bool _payCost = false;
  2753. CardSource _linkCard = null;
  2754. Permanent _permanent = null;
  2755. ICardEffect _cardEffect = null;
  2756. public bool WasLinked = false;
  2757. public IEnumerator LinkCard()
  2758. {
  2759. if (_linkCard == null) yield break;
  2760. if (_permanent == null || _permanent.TopCard == null) yield break;
  2761. if (_cardEffect == null) yield break;
  2762. #region Trigger When Would Link effects
  2763. SelectCardEffect.Root root;
  2764. if (CardEffectCommons.IsExistOnHand(_linkCard))
  2765. root = SelectCardEffect.Root.Hand;
  2766. else if (CardEffectCommons.IsExistInAnyTrash(_linkCard))
  2767. root = SelectCardEffect.Root.Trash;
  2768. else if (CardEffectCommons.IsExistDigivolutionCards(_linkCard))
  2769. root = SelectCardEffect.Root.DigivolutionCards;
  2770. else if (CardEffectCommons.IsExistLinked(_linkCard))
  2771. root = SelectCardEffect.Root.LinkedCards;
  2772. else
  2773. root = SelectCardEffect.Root.None;
  2774. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2775. CardEffectCommons.WouldLinkHashtable(_linkCard, _permanent, root, null),
  2776. EffectTiming.WhenWouldLink));
  2777. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2778. #endregion
  2779. if (_payCost)
  2780. {
  2781. int Cost = _linkCard.GetChangedLinkCost(_permanent, root);
  2782. yield return ContinuousController.instance.StartCoroutine(_linkCard.Owner.AddMemory(-1 * Cost, _cardEffect));
  2783. }
  2784. if (root == SelectCardEffect.Root.None)
  2785. yield return ContinuousController.instance.StartCoroutine(new IPlacePermanentToLinkCards(new List<Permanent[]>() { new Permanent[] { _linkCard.PermanentOfThisCard(), _permanent } }, _cardEffect).PlacePermanentToLinkCards());
  2786. else
  2787. yield return ContinuousController.instance.StartCoroutine(_permanent.AddLinkCard(_linkCard, _cardEffect));
  2788. WasLinked = _permanent.LinkedCards.Contains(_linkCard);
  2789. _linkCard.Owner.UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
  2790. }
  2791. }
  2792. #endregion
  2793. #region Place permanents to security
  2794. public class IPutSecurityPermanent
  2795. {
  2796. public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop, bool isFaceup = false)
  2797. {
  2798. _permanent = permanent;
  2799. _hashtable = hashtable;
  2800. _toTop = toTop;
  2801. _isFaceup = isFaceup;
  2802. }
  2803. Permanent _permanent = null;
  2804. Hashtable _hashtable = new Hashtable();
  2805. bool _toTop = false;
  2806. bool _isFaceup = false;
  2807. public bool IsPlacedSecurity = false;
  2808. public IEnumerator PutSecurity()
  2809. {
  2810. if (_permanent == null) yield break;
  2811. if (_permanent.TopCard == null) yield break;
  2812. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2813. if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
  2814. if (!_permanent.CanBeRemoved()) yield break;
  2815. _permanent.willBeRemoveField = true;
  2816. #region "When permanents would remove field" effect
  2817. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2818. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2819. new List<Permanent>() { _permanent },
  2820. cardEffect,
  2821. null
  2822. ),
  2823. EffectTiming.WhenRemoveField));
  2824. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2825. {
  2826. _permanent.ShowWillRemoveFieldEffect();
  2827. //effect
  2828. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2829. // cut in effect process
  2830. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2831. _permanent.HideWillRemoveFieldEffect();
  2832. }
  2833. #endregion
  2834. CardSource topCard = _permanent.TopCard;
  2835. if (!_permanent.willBeRemoveField)
  2836. yield break;
  2837. if (topCard == null)
  2838. yield break;
  2839. #region add log
  2840. string log = "";
  2841. string fromString = _toTop ? "top" : "bottom";
  2842. log += $"\nPut cards on {fromString} of security:";
  2843. log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
  2844. log += "\n";
  2845. PlayLog.OnAddLog?.Invoke(log);
  2846. #endregion
  2847. IsPlacedSecurity = true;
  2848. #region show cards
  2849. if (!topCard.IsToken)
  2850. {
  2851. if (_toTop)
  2852. {
  2853. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
  2854. }
  2855. else
  2856. {
  2857. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
  2858. }
  2859. }
  2860. #endregion
  2861. #region "When permanents leave the battle area" effect
  2862. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2863. CardEffectCommons.OnDeletionHashtable(
  2864. new List<Permanent> { _permanent },
  2865. cardEffect,
  2866. null,
  2867. false
  2868. ),
  2869. EffectTiming.OnLeaveFieldAnyone));
  2870. #endregion
  2871. #region place permanent to security
  2872. yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
  2873. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
  2874. if (!topCard.IsToken)
  2875. {
  2876. if (!topCard.IsDigiEgg)
  2877. {
  2878. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard, faceUp: _isFaceup));
  2879. if (!_isFaceup)
  2880. topCard.SetReverse();
  2881. else
  2882. topCard.SetFace();
  2883. if (!_toTop)
  2884. {
  2885. topCard.Owner.SecurityCards.Remove(topCard);
  2886. topCard.Owner.SecurityCards.Add(topCard);
  2887. }
  2888. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
  2889. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard).AddSecurity());
  2890. }
  2891. else
  2892. {
  2893. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2894. }
  2895. }
  2896. #endregion
  2897. }
  2898. }
  2899. #endregion
  2900. #region Delete permanents
  2901. public class DestroyPermanentsClass
  2902. {
  2903. public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
  2904. {
  2905. _destroytargetPermanents = destroyTargetPermanents.Clone();
  2906. _hashtable = hashtable;
  2907. _notShowCards = notShowCards;
  2908. }
  2909. public bool IsDestroyed(Permanent permanent)
  2910. {
  2911. return DestroyedPermanents.Contains(permanent);
  2912. }
  2913. List<Permanent> _destroytargetPermanents = new List<Permanent>();
  2914. public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
  2915. Hashtable _hashtable = null;
  2916. bool _notShowCards = false;
  2917. public IEnumerator Destroy()
  2918. {
  2919. if (_destroytargetPermanents == null) yield break;
  2920. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2921. IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
  2922. bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
  2923. _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
  2924. permanent != null
  2925. && permanent.TopCard != null
  2926. && (cardEffect == null ||
  2927. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  2928. && permanent.CanBeDestroyedBySkill(cardEffect))));
  2929. if (_destroytargetPermanents.Count == 0) yield break;
  2930. _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  2931. #region cut in effect
  2932. // "When permanents would be deleted" effect
  2933. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2934. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2935. _destroytargetPermanents,
  2936. cardEffect,
  2937. battle
  2938. ),
  2939. EffectTiming.WhenPermanentWouldBeDeleted));
  2940. // "When permanents would remove field" effect
  2941. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2942. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2943. _destroytargetPermanents,
  2944. cardEffect,
  2945. battle
  2946. ),
  2947. EffectTiming.WhenRemoveField));
  2948. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2949. {
  2950. foreach (Permanent permanent in _destroytargetPermanents)
  2951. {
  2952. permanent.ShowDeleteEffect();
  2953. }
  2954. // effect
  2955. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2956. // cut in effect process
  2957. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2958. foreach (Permanent permanent in _destroytargetPermanents)
  2959. {
  2960. permanent.HideDeleteEffect();
  2961. }
  2962. }
  2963. #endregion
  2964. // fix delete target permanents
  2965. List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
  2966. permanent != null
  2967. && permanent.TopCard != null
  2968. && permanent.willBeRemoveField);
  2969. #region "When permanents are deleted" effect
  2970. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2971. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2972. destroyTargetPermanents_Fixed,
  2973. cardEffect,
  2974. battle,
  2975. isDPZero
  2976. ),
  2977. EffectTiming.OnDestroyedAnyone));
  2978. #endregion
  2979. #region "When permanents leave the battle area" effect
  2980. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2981. CardEffectCommons.OnDeletionHashtable(
  2982. destroyTargetPermanents_Fixed,
  2983. cardEffect,
  2984. battle,
  2985. isDPZero
  2986. ),
  2987. EffectTiming.OnLeaveFieldAnyone));
  2988. #endregion
  2989. #region record parameters just before deletion
  2990. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2991. {
  2992. permanent.DPJustBeforeRemoveField = permanent.DP;
  2993. if (permanent.TopCard.HasLevel)
  2994. {
  2995. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2996. }
  2997. if (permanent.TopCard.HasPlayCost)
  2998. {
  2999. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  3000. }
  3001. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  3002. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  3003. foreach (CardSource cardSource in permanent.cardSources)
  3004. {
  3005. cardSource.PermanentJustBeforeRemoveField = permanent;
  3006. }
  3007. }
  3008. #endregion
  3009. #region add log
  3010. if (destroyTargetPermanents_Fixed.Count >= 1)
  3011. {
  3012. string log = "";
  3013. log += $"\nDelete:";
  3014. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  3015. {
  3016. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  3017. }
  3018. log += "\n";
  3019. PlayLog.OnAddLog?.Invoke(log);
  3020. }
  3021. #endregion
  3022. #region show cards
  3023. List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  3024. if (!_notShowCards)
  3025. {
  3026. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
  3027. }
  3028. #endregion
  3029. #region trash permanent cards
  3030. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  3031. {
  3032. #region record wheter to be deleted by battle
  3033. if (battle != null)
  3034. {
  3035. if (permanent.TopCard != null)
  3036. {
  3037. if (CardEffectCommons.GetLoserPermanentsFromHashtable(battle.hashtable).Contains(permanent))
  3038. permanent.IsDestroyedByBattle = true;
  3039. }
  3040. }
  3041. #endregion
  3042. #region record used effect
  3043. if (permanent.TopCard != null)
  3044. {
  3045. permanent.DestroyingEffect = cardEffect;
  3046. }
  3047. #endregion
  3048. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
  3049. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  3050. CardSource topCard = permanent.TopCard;
  3051. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  3052. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
  3053. DestroyedPermanents.Add(permanent);
  3054. }
  3055. #endregion
  3056. #region hide icon
  3057. foreach (Permanent permanent in _destroytargetPermanents)
  3058. {
  3059. if (permanent != null)
  3060. {
  3061. if (permanent.TopCard != null)
  3062. {
  3063. permanent.willBeRemoveField = false;
  3064. }
  3065. }
  3066. }
  3067. #endregion
  3068. }
  3069. }
  3070. #endregion
  3071. #region Security check
  3072. public class ISecurityCheck
  3073. {
  3074. private static WaitForSeconds _waitForSeconds0_1 = new WaitForSeconds(0.1f);
  3075. private static WaitForSeconds _waitForSeconds0_3 = new WaitForSeconds(0.3f);
  3076. public ISecurityCheck(Permanent AttackingPermanent, Player player)
  3077. {
  3078. this.AttackingPermanent = AttackingPermanent;
  3079. this.player = player;
  3080. }
  3081. Permanent AttackingPermanent { get; set; }
  3082. Player player { get; set; }
  3083. public IEnumerator SecurityCheck()
  3084. {
  3085. bool StopSecurityCheck()
  3086. {
  3087. if (AttackingPermanent == null)
  3088. {
  3089. return true;
  3090. }
  3091. if (AttackingPermanent.TopCard == null)
  3092. {
  3093. return true;
  3094. }
  3095. if (!AttackingPermanent.IsDigimon)
  3096. return true;
  3097. return false;
  3098. }
  3099. if (!StopSecurityCheck())
  3100. {
  3101. if (AttackingPermanent.Strike == 0)
  3102. {
  3103. yield break;
  3104. }
  3105. GManager.instance.turnStateMachine.IsSelecting = true;
  3106. GManager.instance.turnStateMachine.isSecurityCehck = true;
  3107. #region loop while there are 1 or more security cards
  3108. if (player.SecurityCards.Count >= 1)
  3109. {
  3110. int checkedCount = 0;
  3111. while (true)
  3112. {
  3113. if (StopSecurityCheck())
  3114. {
  3115. break;
  3116. }
  3117. if (checkedCount >= AttackingPermanent.Strike)
  3118. {
  3119. break;
  3120. }
  3121. if (player.SecurityCards.Count >= 1)
  3122. {
  3123. List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
  3124. CardSource brokenSecurityCard = player.SecurityCards[0];
  3125. bool isFaceDown = brokenSecurityCard.IsFlipped;
  3126. Hashtable hashtable = new Hashtable()
  3127. {
  3128. {"AttackingPermanent", AttackingPermanent},
  3129. {"Card", brokenSecurityCard}
  3130. };
  3131. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
  3132. {
  3133. triggeredSkillInfos.Add(skillInfo);
  3134. }
  3135. checkedCount++;
  3136. PlayLog.OnAddLog?.Invoke($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
  3137. if (brokenSecurityCard.IsDigimon)
  3138. {
  3139. GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
  3140. }
  3141. #region effect
  3142. player.securityObject.securityBreakGlass.ShowBlueMatarial();
  3143. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
  3144. yield return _waitForSeconds0_1;
  3145. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
  3146. #endregion
  3147. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
  3148. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  3149. player: brokenSecurityCard.Owner,
  3150. refSkillInfos: ref triggeredSkillInfos,
  3151. null).ReduceSecurity());
  3152. #region security effect
  3153. List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
  3154. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
  3155. {
  3156. if (cardEffect is ActivateICardEffect)
  3157. {
  3158. Hashtable hashtable1 = new Hashtable
  3159. {
  3160. { "Card", brokenSecurityCard },
  3161. { "isFaceDown", isFaceDown }
  3162. };
  3163. if (cardEffect.CanUse(hashtable1))
  3164. {
  3165. secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
  3166. }
  3167. }
  3168. }
  3169. List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
  3170. bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
  3171. if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
  3172. {
  3173. if (!brokenSecurityCard.IsDigimon)
  3174. {
  3175. yield return _waitForSeconds0_3;
  3176. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  3177. }
  3178. }
  3179. else
  3180. {
  3181. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
  3182. yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
  3183. List<SkillInfo> skillInfos = new List<SkillInfo>();
  3184. foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
  3185. {
  3186. skillInfos.Add(skillInfo);
  3187. }
  3188. List<CardSource> cardSources = new List<CardSource>();
  3189. for (int j = 0; j < skillInfos.Count; j++)
  3190. {
  3191. cardSources.Add(brokenSecurityCard);
  3192. }
  3193. while (skillInfos.Count >= 1)
  3194. {
  3195. SkillInfo selectedSkillInfo = null;
  3196. if (skillInfos.Count == 1)
  3197. {
  3198. selectedSkillInfo = skillInfos[0];
  3199. }
  3200. else
  3201. {
  3202. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  3203. selectCardEffect.SetUp(
  3204. canTargetCondition: (cardSource) => true,
  3205. canTargetCondition_ByPreSelecetedList: null,
  3206. canEndSelectCondition: null,
  3207. canNoSelect: () => false,
  3208. selectCardCoroutine: null,
  3209. afterSelectCardCoroutine: null,
  3210. message: "select security effect",
  3211. maxCount: 1,
  3212. canEndNotMax: false,
  3213. isShowOpponent: false,
  3214. mode: SelectCardEffect.Mode.Custom,
  3215. root: SelectCardEffect.Root.Custom,
  3216. customRootCardList: cardSources,
  3217. canLookReverseCard: true,
  3218. selectPlayer: player,
  3219. cardEffect: null);
  3220. selectCardEffect.SetUpSkillInfos(skillInfos);
  3221. selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
  3222. selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  3223. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  3224. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  3225. {
  3226. if (selectedIndexes.Count == 1)
  3227. {
  3228. selectedSkillInfo = skillInfos[selectedIndexes[0]];
  3229. yield return null;
  3230. }
  3231. }
  3232. }
  3233. if (selectedSkillInfo != null)
  3234. {
  3235. ICardEffect cardEffect = selectedSkillInfo.CardEffect;
  3236. Hashtable hashtable2 = selectedSkillInfo.Hashtable;
  3237. if (cardEffect.EffectSourceCard == brokenSecurityCard)
  3238. {
  3239. if (cardEffect is ActivateICardEffect)
  3240. {
  3241. skillInfos.Remove(selectedSkillInfo);
  3242. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  3243. cardEffect,
  3244. hashtable2));
  3245. }
  3246. }
  3247. }
  3248. }
  3249. }
  3250. #endregion
  3251. // auto process check
  3252. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3253. // stack effect of "When cards are removed from security" and "checks secuirty"
  3254. foreach (SkillInfo skillInfo in triggeredSkillInfos)
  3255. {
  3256. GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
  3257. }
  3258. // auto process check
  3259. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3260. if (!StopSecurityCheck())
  3261. {
  3262. #region battle with security Digimon
  3263. if (brokenSecurityCard.IsDigimon)
  3264. {
  3265. bool doBattle = true;
  3266. #region "ignore battle" effect
  3267. Hashtable hashtable3 = new Hashtable()
  3268. {
  3269. {"Card", brokenSecurityCard}
  3270. };
  3271. #region the security Digimon's effect
  3272. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
  3273. {
  3274. if (cardEffect is IDontBattleSecurityDigimonEffect)
  3275. {
  3276. if (cardEffect.CanUse(hashtable3))
  3277. {
  3278. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  3279. {
  3280. doBattle = false;
  3281. }
  3282. }
  3283. }
  3284. }
  3285. #endregion
  3286. #region player's effect
  3287. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3288. {
  3289. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3290. {
  3291. if (cardEffect is IDontBattleSecurityDigimonEffect)
  3292. {
  3293. if (cardEffect.CanUse(hashtable3))
  3294. {
  3295. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  3296. {
  3297. doBattle = false;
  3298. }
  3299. }
  3300. }
  3301. }
  3302. }
  3303. #endregion
  3304. #endregion
  3305. if (doBattle)
  3306. {
  3307. yield return _waitForSeconds0_3;
  3308. yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
  3309. }
  3310. }
  3311. #endregion
  3312. }
  3313. #region effect
  3314. yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
  3315. if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
  3316. {
  3317. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
  3318. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
  3319. {
  3320. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  3321. }
  3322. }
  3323. GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
  3324. GManager.instance.attackProcess.SecurityDigimon = null;
  3325. #endregion
  3326. // reset effect until end of security check
  3327. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3328. {
  3329. player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  3330. }
  3331. // auto process check
  3332. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3333. GManager.instance.turnStateMachine.IsSelecting = true;
  3334. }
  3335. else
  3336. {
  3337. break;
  3338. }
  3339. }
  3340. }
  3341. #endregion
  3342. GManager.instance.turnStateMachine.isSecurityCehck = false;
  3343. }
  3344. }
  3345. }
  3346. #endregion
  3347. #region trash cards from security
  3348. public class IDestroySecurity
  3349. {
  3350. private static WaitForSeconds _waitForSeconds0_1 = new WaitForSeconds(0.1f);
  3351. private static WaitForSeconds _waitForSeconds0_5 = new WaitForSeconds(0.5f);
  3352. private enum TrashMode
  3353. {
  3354. TopSecurity,
  3355. BottomSecurity,
  3356. SelectedCard,
  3357. }
  3358. public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
  3359. {
  3360. _player = player;
  3361. _destroySecurityCount = destroySecurityCount;
  3362. _cardEffect = cardEffect;
  3363. _trashMode = fromTop ? TrashMode.TopSecurity : TrashMode.BottomSecurity;
  3364. }
  3365. public IDestroySecurity(Player player, CardSource card, ICardEffect cardEffect)
  3366. {
  3367. _player = player;
  3368. _destroySecurityCount = 1;
  3369. _cardEffect = cardEffect;
  3370. _trashMode = TrashMode.SelectedCard;
  3371. _selectedCard = card;
  3372. }
  3373. Player _player = null;
  3374. int _destroySecurityCount = 0;
  3375. public List<CardSource> DestroyedSecurity = new List<CardSource>();
  3376. ICardEffect _cardEffect = null;
  3377. TrashMode _trashMode = TrashMode.TopSecurity;
  3378. CardSource _selectedCard = null;
  3379. public bool IsDestroyed(CardSource cardSource)
  3380. {
  3381. return DestroyedSecurity.Contains(cardSource);
  3382. }
  3383. public IEnumerator DestroySecurity()
  3384. {
  3385. bool StopDestroySecurity()
  3386. {
  3387. if (_player.SecurityCards.Count == 0)
  3388. {
  3389. return true;
  3390. }
  3391. if (!_player.CanReduceSecurity())
  3392. {
  3393. return true;
  3394. }
  3395. return false;
  3396. }
  3397. if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
  3398. {
  3399. int count = 0;
  3400. List<CardSource> discardedCards = new List<CardSource>();
  3401. while (true)
  3402. {
  3403. if (StopDestroySecurity())
  3404. {
  3405. break;
  3406. }
  3407. if (count >= _destroySecurityCount)
  3408. {
  3409. break;
  3410. }
  3411. if (_player.SecurityCards.Count >= 1)
  3412. {
  3413. count++;
  3414. CardSource destroyedSecurityCard = null;
  3415. switch (_trashMode)
  3416. {
  3417. case TrashMode.TopSecurity:
  3418. destroyedSecurityCard = _player.SecurityCards[0];
  3419. break;
  3420. case TrashMode.BottomSecurity:
  3421. destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
  3422. break;
  3423. case TrashMode.SelectedCard:
  3424. destroyedSecurityCard = _player.SecurityCards.Contains(_selectedCard) ? _selectedCard : null;
  3425. break;
  3426. }
  3427. if (destroyedSecurityCard == null)
  3428. {
  3429. break;
  3430. }
  3431. discardedCards.Add(destroyedSecurityCard);
  3432. #region effect
  3433. _player.securityObject.securityBreakGlass.ShowBlueMatarial();
  3434. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
  3435. yield return _waitForSeconds0_1;
  3436. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
  3437. yield return _waitForSeconds0_5;
  3438. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
  3439. #endregion
  3440. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
  3441. DestroyedSecurity.Add(destroyedSecurityCard);
  3442. }
  3443. }
  3444. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  3445. if (discardedCards.Count >= 1)
  3446. {
  3447. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  3448. player: _player,
  3449. refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
  3450. cardEffect: _cardEffect).ReduceSecurity());
  3451. #region "When security cards are trashed" effect
  3452. #region Hashtable setting
  3453. Hashtable hashtable = new Hashtable()
  3454. {
  3455. {"DiscardedCards", discardedCards},
  3456. {"CardEffect", _cardEffect},
  3457. };
  3458. #endregion
  3459. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
  3460. #endregion
  3461. }
  3462. #region add log
  3463. if (discardedCards.Count >= 1)
  3464. {
  3465. string log = "";
  3466. string modeString = "";
  3467. switch (_trashMode)
  3468. {
  3469. case TrashMode.TopSecurity:
  3470. modeString = "Top";
  3471. break;
  3472. case TrashMode.BottomSecurity:
  3473. modeString = "Bottom";
  3474. break;
  3475. case TrashMode.SelectedCard:
  3476. modeString = "Selected";
  3477. break;
  3478. }
  3479. log += $"\nDiscarded From {modeString} Security Cards:";
  3480. foreach (CardSource cardSource in discardedCards)
  3481. {
  3482. if (cardSource != null)
  3483. {
  3484. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3485. }
  3486. }
  3487. log += "\n";
  3488. PlayLog.OnAddLog?.Invoke(log);
  3489. }
  3490. #endregion
  3491. }
  3492. }
  3493. }
  3494. #endregion
  3495. #region Battle
  3496. public class IBattle
  3497. {
  3498. public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard, bool IsWithoutAttack = false)
  3499. {
  3500. this.AttackingPermanent = AttackingPermanent;
  3501. this.DefendingPermanent = DefendingPermanent;
  3502. this.DefendingCard = DefendingCard;
  3503. this.IsWithoutAttack = IsWithoutAttack;
  3504. }
  3505. public Permanent AttackingPermanent { get; private set; } = null;
  3506. public Permanent DefendingPermanent { get; private set; } = null;
  3507. CardSource DefendingCard { get; set; } = null;
  3508. bool IsWithoutAttack { get; set; } = false;
  3509. public Hashtable hashtable { get; set; } = new Hashtable();
  3510. public Permanent enemyPermanent(Permanent permanent)
  3511. {
  3512. if (permanent != null)
  3513. {
  3514. if (permanent == AttackingPermanent)
  3515. {
  3516. return DefendingPermanent;
  3517. }
  3518. else if (permanent == DefendingPermanent)
  3519. {
  3520. return AttackingPermanent;
  3521. }
  3522. }
  3523. return null;
  3524. }
  3525. public int CompareStats()
  3526. {
  3527. int statCheck;
  3528. if (AttackingPermanent.HasIceclad || DefendingPermanent.HasIceclad)
  3529. statCheck = AttackingPermanent.DigivolutionCards.Count - DefendingPermanent.DigivolutionCards.Count;
  3530. else
  3531. statCheck = AttackingPermanent.DP - DefendingPermanent.DP;
  3532. statCheck = Mathf.Clamp(statCheck, -1, 1);
  3533. return statCheck;
  3534. }
  3535. public IEnumerator Battle()
  3536. {
  3537. hashtable = new Hashtable();
  3538. if (AttackingPermanent != null && AttackingPermanent.HasDP)
  3539. {
  3540. bool IsExistingDefender()
  3541. {
  3542. // whether defender exists
  3543. if ((DefendingPermanent == null) != (DefendingCard == null))
  3544. {
  3545. if (DefendingPermanent != null)
  3546. {
  3547. if (DefendingPermanent.TopCard != null)
  3548. {
  3549. return DefendingPermanent.HasDP;
  3550. }
  3551. }
  3552. else if (DefendingCard != null)
  3553. {
  3554. return DefendingCard.HasDP;
  3555. }
  3556. }
  3557. return false;
  3558. }
  3559. if (IsExistingDefender())
  3560. {
  3561. if (AttackingPermanent != null)
  3562. {
  3563. AttackingPermanent.battle = this;
  3564. }
  3565. if (DefendingPermanent != null)
  3566. {
  3567. DefendingPermanent.battle = this;
  3568. }
  3569. List<Permanent> WinnerPermanents = new List<Permanent>();
  3570. List<Permanent> LoserPermanents = new List<Permanent>();
  3571. CardSource LoserCard = null;
  3572. bool WasTie = false;
  3573. //add log
  3574. string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
  3575. if (DefendingPermanent != null)
  3576. {
  3577. log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
  3578. }
  3579. else if (DefendingCard != null)
  3580. {
  3581. log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
  3582. }
  3583. PlayLog.OnAddLog?.Invoke(log);
  3584. #region "At the start of battle" effect
  3585. Permanent _AttackingPermanent = null;
  3586. Permanent _DefendingPermanent = null;
  3587. if (AttackingPermanent != null)
  3588. {
  3589. if (AttackingPermanent.TopCard != null)
  3590. {
  3591. _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
  3592. }
  3593. }
  3594. if (DefendingPermanent != null)
  3595. {
  3596. if (DefendingPermanent.TopCard != null)
  3597. {
  3598. _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
  3599. }
  3600. }
  3601. hashtable.Add("AttackingPermanent", _AttackingPermanent);
  3602. hashtable.Add("DefendingPermanent", _DefendingPermanent);
  3603. hashtable.Add("DefendingCard", DefendingCard);
  3604. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
  3605. #endregion
  3606. #region Show effect
  3607. bool ShowEffect()
  3608. {
  3609. if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
  3610. {
  3611. return true;
  3612. }
  3613. else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
  3614. {
  3615. if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
  3616. {
  3617. return true;
  3618. }
  3619. }
  3620. return false;
  3621. }
  3622. if (ShowEffect())
  3623. {
  3624. if (GManager.instance.attackProcess.IsAttacking)
  3625. {
  3626. if (GManager.instance.attackProcess.SecurityDigimon != null)
  3627. {
  3628. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  3629. {
  3630. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  3631. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  3632. }
  3633. }
  3634. }
  3635. }
  3636. #endregion
  3637. if (!IsWithoutAttack)//If started by effect, do not perform processing during this battle
  3638. {
  3639. // auto process check
  3640. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3641. GManager.instance.turnStateMachine.IsSelecting = true;
  3642. //Preemptive end battle if the attack process is ended
  3643. if (GManager.instance.attackProcess.IsEndAttack)
  3644. yield break;
  3645. }
  3646. #region battle with permanent
  3647. if (DefendingPermanent != null)
  3648. {
  3649. int battleResults = CompareStats();
  3650. if (battleResults == 1)
  3651. {
  3652. WinnerPermanents.Add(AttackingPermanent);
  3653. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3654. LoserPermanents.Add(DefendingPermanent);
  3655. }
  3656. else if (battleResults == 0)
  3657. {
  3658. WasTie = true;
  3659. WinnerPermanents.Add(AttackingPermanent);
  3660. WinnerPermanents.Add(DefendingPermanent);
  3661. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3662. LoserPermanents.Add(AttackingPermanent);
  3663. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3664. LoserPermanents.Add(DefendingPermanent);
  3665. }
  3666. else if (battleResults == -1)
  3667. {
  3668. WinnerPermanents.Add(DefendingPermanent);
  3669. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3670. LoserPermanents.Add(AttackingPermanent);
  3671. }
  3672. }
  3673. #endregion
  3674. #region battle with card
  3675. else if (DefendingCard != null)
  3676. {
  3677. if (AttackingPermanent.DP > DefendingCard.CardDP)
  3678. {
  3679. WinnerPermanents.Add(AttackingPermanent);
  3680. LoserCard = DefendingCard;
  3681. }
  3682. else if (AttackingPermanent.DP == DefendingCard.CardDP)
  3683. {
  3684. WasTie = true;
  3685. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3686. {
  3687. LoserPermanents.Add(AttackingPermanent);
  3688. }
  3689. LoserCard = DefendingCard;
  3690. }
  3691. else if (AttackingPermanent.DP < DefendingCard.CardDP)
  3692. {
  3693. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3694. {
  3695. LoserPermanents.Add(AttackingPermanent);
  3696. }
  3697. }
  3698. }
  3699. #endregion
  3700. List<Permanent> _WinnerPermanents = new List<Permanent>();
  3701. List<Permanent> _LoserPermanents = new List<Permanent>();
  3702. foreach (Permanent permanent in WinnerPermanents)
  3703. {
  3704. if (permanent.TopCard != null)
  3705. {
  3706. _WinnerPermanents.Add(new Permanent(permanent.cardSources));
  3707. }
  3708. }
  3709. foreach (Permanent permanent in LoserPermanents)
  3710. {
  3711. if (permanent.TopCard != null)
  3712. {
  3713. _LoserPermanents.Add(new Permanent(permanent.cardSources));
  3714. }
  3715. }
  3716. hashtable.Add("WinnerPermanents", _WinnerPermanents);
  3717. hashtable.Add("WinnerPermanents_real", WinnerPermanents);
  3718. hashtable.Add("LoserPermanents", _LoserPermanents);
  3719. hashtable.Add("LoserPermanents_real", LoserPermanents);
  3720. hashtable.Add("LoserCard", LoserCard);
  3721. hashtable.Add("WasTie", WasTie);
  3722. hashtable.Add("battle", this);
  3723. // battle effect
  3724. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
  3725. DestroyPermanentsClass destoryBattlePermanents = new DestroyPermanentsClass(LoserPermanents, hashtable);
  3726. yield return ContinuousController.instance.StartCoroutine(destoryBattlePermanents.Destroy());
  3727. //Fix Loser Permanents
  3728. if (LoserPermanents.Count != destoryBattlePermanents.DestroyedPermanents.Count)
  3729. {
  3730. LoserPermanents = destoryBattlePermanents.DestroyedPermanents;
  3731. _LoserPermanents = destoryBattlePermanents.DestroyedPermanents;
  3732. hashtable["LoserPermanents"] = _LoserPermanents;
  3733. hashtable["LoserPermanents_real"] = LoserPermanents;
  3734. }
  3735. // "At the end of battle" effect
  3736. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
  3737. #region move up effect
  3738. if (ShowEffect())
  3739. {
  3740. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
  3741. }
  3742. #endregion
  3743. #region effect when determine whether to do security check
  3744. List<SkillInfo> skillInfos_Pierce = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnDetermineDoSecurityCheck)
  3745. .Filter(skillInfo => skillInfo.CardEffect != null && skillInfo.CardEffect.CanActivate(skillInfo.Hashtable));
  3746. if (skillInfos_Pierce.Count >= 1)
  3747. {
  3748. GManager.instance.autoProcessing.PutStackedSkill(skillInfos_Pierce[0]);
  3749. }
  3750. #endregion
  3751. }
  3752. }
  3753. if (!IsWithoutAttack)//If started by effect, do not perform processing & don't reset effects relevant to the actual attack process
  3754. {
  3755. // auto process check
  3756. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3757. #region reset effect until the end of battle
  3758. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3759. {
  3760. foreach (Permanent permanent in player.GetFieldPermanents())
  3761. {
  3762. permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  3763. }
  3764. player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  3765. }
  3766. #endregion
  3767. }
  3768. if (AttackingPermanent != null)
  3769. {
  3770. AttackingPermanent.battle = null;
  3771. }
  3772. if (DefendingPermanent != null)
  3773. {
  3774. DefendingPermanent.battle = null;
  3775. }
  3776. }
  3777. }
  3778. #endregion
  3779. #region De-digivolve
  3780. public class IDegeneration
  3781. {
  3782. /// <summary>
  3783. /// De-Digivolve Class
  3784. /// </summary>
  3785. /// <param name="permanent">Target Permanent</param>
  3786. /// <param name="DegenerationCount">De-Digivolve Amount</param>
  3787. /// <param name="cardEffect">Card Effect</param>
  3788. /// <param name="DegenerationCountRuling">Should we enforce rule to select De-digivolve amount before digimon, disabled by default</param>
  3789. public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect, bool? DegenerationCountRuling = null)
  3790. {
  3791. _permanent = permanent;
  3792. _degenerationCount = DegenerationCount;
  3793. _cardEffect = cardEffect;
  3794. _degenerationCountRuling = DegenerationCountRuling;
  3795. }
  3796. Permanent _permanent = null;
  3797. int _degenerationCount;
  3798. ICardEffect _cardEffect = null;
  3799. bool? _degenerationCountRuling;
  3800. public IEnumerator Degeneration()
  3801. {
  3802. if (_cardEffect == null) yield break;
  3803. if (_cardEffect.EffectSourceCard == null) yield break;
  3804. if (_permanent == null) yield break;
  3805. if (_permanent.TopCard == null) yield break;
  3806. if (_permanent.ImmuneFromDeDigivolve()) yield break;
  3807. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
  3808. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3809. int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
  3810. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  3811. if (selectCountEffect != null && _degenerationCountRuling == null)
  3812. {
  3813. Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
  3814. selectCountEffect.SetUp(
  3815. SelectPlayer: selectPlayer,
  3816. targetPermanent: _permanent,
  3817. MaxCount: maxCount,
  3818. CanNoSelect: false,
  3819. Message: "How many cards do you trash?",
  3820. Message_Enemy: "The opponent is choosing how many cards to trash.",
  3821. SelectCountCoroutine: SelectCountCoroutine);
  3822. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  3823. IEnumerator SelectCountCoroutine(int count)
  3824. {
  3825. _degenerationCount = count;
  3826. yield return null;
  3827. }
  3828. }
  3829. if (_degenerationCount >= 1)
  3830. {
  3831. int count = 0;
  3832. List<CardSource> selectedCards = new List<CardSource>();
  3833. while (true)
  3834. {
  3835. bool StopCondition()
  3836. {
  3837. if (_permanent.HasNoDigivolutionCards)
  3838. {
  3839. return true;
  3840. }
  3841. if (_permanent.Level == 3)
  3842. {
  3843. if (_permanent.TopCard != null)
  3844. {
  3845. if (_permanent.TopCard.HasLevel)
  3846. {
  3847. return true;
  3848. }
  3849. }
  3850. }
  3851. if (count >= _degenerationCount)
  3852. {
  3853. return true;
  3854. }
  3855. return false;
  3856. }
  3857. if (StopCondition())
  3858. {
  3859. break;
  3860. }
  3861. if (count == 0)
  3862. {
  3863. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3864. }
  3865. CardSource cardSource = _permanent.TopCard;
  3866. selectedCards.Add(cardSource);
  3867. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  3868. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3869. if (!cardSource.IsToken)
  3870. {
  3871. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3872. }
  3873. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  3874. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3875. _permanent.TopCard.SetChangedLocationTime();//register that the new topcard just became a top card for the purpose of the start of timestamped continuous effects
  3876. count++;
  3877. }
  3878. #region "When Top Card is Trashed" effect
  3879. #region Hashtable Setting
  3880. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  3881. {
  3882. {"Permanent", _permanent},
  3883. {"CardSources", selectedCards}
  3884. };
  3885. #endregion
  3886. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  3887. .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
  3888. #endregion
  3889. #region add log
  3890. if (selectedCards.Count >= 1)
  3891. {
  3892. string log = "";
  3893. log += $"\nDe-Digivolve :";
  3894. foreach (CardSource cardSource in selectedCards)
  3895. {
  3896. if (cardSource != null)
  3897. {
  3898. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3899. }
  3900. }
  3901. log += "\n";
  3902. PlayLog.OnAddLog?.Invoke(log);
  3903. }
  3904. #endregion
  3905. }
  3906. }
  3907. }
  3908. public class IMassDegeneration
  3909. {
  3910. /// <summary>
  3911. /// De-Digivolve Class for applying simultaneous De-digivolve to multiple digimon at once
  3912. /// to behave correctly around immunity effects, especially blanket immunity
  3913. /// </summary>
  3914. /// <param name="permanents">Target Permanents</param>
  3915. /// <param name="DegenerationCount">De-Digivolve Amount</param>
  3916. /// <param name="cardEffect">Card Effect</param>
  3917. /// <param name="DegenerationCountRuling">Should we enforce rule to select De-digivolve amount before digimon, disabled by default.</param>
  3918. public IMassDegeneration(List<Permanent> permanents, int DegenerationCount, ICardEffect cardEffect, bool? DegenerationCountRuling = null)
  3919. {
  3920. _permanents = permanents;
  3921. _degenerationCount = DegenerationCount;
  3922. _cardEffect = cardEffect;
  3923. _degenerationCountRuling = DegenerationCountRuling;
  3924. }
  3925. List<Permanent> _permanents = null;
  3926. int _degenerationCount;
  3927. ICardEffect _cardEffect = null;
  3928. bool? _degenerationCountRuling;
  3929. public IEnumerator Degeneration()
  3930. {
  3931. if (_cardEffect == null) yield break;
  3932. if (_cardEffect.EffectSourceCard == null) yield break;
  3933. bool ValidTarget(Permanent permanent)
  3934. {
  3935. return permanent != null
  3936. && permanent.TopCard != null
  3937. && !permanent.ImmuneFromDeDigivolve()
  3938. && !permanent.ImmuneFromStackTrashing(_cardEffect)
  3939. && !permanent.TopCard.CanNotBeAffected(_cardEffect);
  3940. }
  3941. List<Permanent> permanents_Fixed = _permanents.Filter(ValidTarget);
  3942. // 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.
  3943. // 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.
  3944. // SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  3945. // if (selectCountEffect != null && _degenerationCountRuling == null && _degenerationCount > 1)
  3946. // {
  3947. // Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
  3948. // selectCountEffect.SetUp(
  3949. // SelectPlayer: selectPlayer,
  3950. // targetPermanent: _permanent,
  3951. // MaxCount: maxCount,
  3952. // CanNoSelect: false,
  3953. // Message: "How many cards do you trash?",
  3954. // Message_Enemy: "The opponent is choosing how many cards to trash.",
  3955. // SelectCountCoroutine: SelectCountCoroutine);
  3956. // yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  3957. // IEnumerator SelectCountCoroutine(int count)
  3958. // {
  3959. // _degenerationCount = count;
  3960. // yield return null;
  3961. // }
  3962. // }
  3963. if (_degenerationCount >= 1)
  3964. {
  3965. foreach (Permanent _permanent in permanents_Fixed)
  3966. {
  3967. int count = 0;
  3968. int maxCount = Math.Min(_degenerationCount, _permanent.DigivolutionCards.Count);
  3969. List<CardSource> selectedCards = new List<CardSource>();
  3970. while (true)
  3971. {
  3972. bool StopCondition()
  3973. {
  3974. if (_permanent.HasNoDigivolutionCards)
  3975. {
  3976. return true;
  3977. }
  3978. if (_permanent.Level == 3)
  3979. {
  3980. if (_permanent.TopCard != null)
  3981. {
  3982. if (_permanent.TopCard.HasLevel)
  3983. {
  3984. return true;
  3985. }
  3986. }
  3987. }
  3988. if (count >= maxCount)
  3989. {
  3990. return true;
  3991. }
  3992. return false;
  3993. }
  3994. if (StopCondition())
  3995. {
  3996. break;
  3997. }
  3998. if (count == 0)
  3999. {
  4000. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  4001. }
  4002. CardSource cardSource = _permanent.TopCard;
  4003. selectedCards.Add(cardSource);
  4004. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  4005. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  4006. if (!cardSource.IsToken)
  4007. {
  4008. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  4009. }
  4010. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  4011. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  4012. _permanent.TopCard.SetChangedLocationTime();//register that the new topcard just became a top card for the purpose of the start of timestamped continuous effects
  4013. count++;
  4014. }
  4015. #region "When Top Card is Trashed" effect
  4016. #region Hashtable Setting
  4017. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  4018. {
  4019. {"Permanent", _permanent},
  4020. {"CardSources", selectedCards}
  4021. };
  4022. #endregion
  4023. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  4024. .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
  4025. #endregion
  4026. #region add log
  4027. if (selectedCards.Count >= 1)
  4028. {
  4029. string log = "";
  4030. log += $"\nDe-Digivolve :";
  4031. foreach (CardSource cardSource in selectedCards)
  4032. {
  4033. if (cardSource != null)
  4034. {
  4035. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  4036. }
  4037. }
  4038. log += "\n";
  4039. PlayLog.OnAddLog?.Invoke(log);
  4040. }
  4041. #endregion
  4042. }
  4043. }
  4044. }
  4045. }
  4046. #endregion
  4047. #region Trash digivolution cards
  4048. public class ITrashDigivolutionCards
  4049. {
  4050. public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  4051. {
  4052. _permanent = permanent;
  4053. _trashTargetCards = trashTargetCards.Clone();
  4054. _cardEffect = cardEffect;
  4055. }
  4056. public bool IsTrashed(CardSource cardSource)
  4057. {
  4058. return TrashedCards.Contains(cardSource);
  4059. }
  4060. Permanent _permanent = null;
  4061. List<CardSource> _trashTargetCards = new List<CardSource>();
  4062. public List<CardSource> TrashedCards = new List<CardSource>();
  4063. ICardEffect _cardEffect = null;
  4064. public IEnumerator TrashDigivolutionCards()
  4065. {
  4066. if (_trashTargetCards == null) yield break;
  4067. if (_cardEffect == null) yield break;
  4068. if (_permanent == null) yield break;
  4069. if (_permanent.TopCard == null) yield break;
  4070. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
  4071. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  4072. if (_permanent.HasNoDigivolutionCards) yield break;
  4073. _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
  4074. _permanent.DigivolutionCards.Contains(cardSource) &&
  4075. !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
  4076. if (_trashTargetCards.Count == 0) yield break;
  4077. _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
  4078. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  4079. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  4080. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  4081. #region cut in effect - Would discard
  4082. // "When digivolution cards would be trashed" effect
  4083. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  4084. CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
  4085. _permanent,
  4086. _trashTargetCards,
  4087. _cardEffect
  4088. ),
  4089. EffectTiming.WhenWouldDigivolutionCardDiscarded));
  4090. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  4091. {
  4092. // effect
  4093. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  4094. // cut in effect process
  4095. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  4096. }
  4097. #endregion
  4098. //fix trash target permanent
  4099. Permanent permanentTarget_Fixed = _permanent;
  4100. // fix trash sources sources
  4101. List<CardSource> trashDigivolutionCards_Fixed = _trashTargetCards.Filter(cardsource =>
  4102. cardsource != null
  4103. && cardsource.willBeRemoveSources);
  4104. #region "When digivolution cards are trashed" effect
  4105. #region Hashtable Setting
  4106. Hashtable hashtable = new Hashtable()
  4107. {
  4108. {"CardEffect", _cardEffect},
  4109. {"Permanent", permanentTarget_Fixed},
  4110. {"DiscardedCards", trashDigivolutionCards_Fixed},
  4111. };
  4112. #endregion
  4113. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
  4114. #endregion
  4115. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  4116. foreach (CardSource cardSource in trashDigivolutionCards_Fixed)
  4117. {
  4118. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
  4119. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  4120. if (!cardSource.IsToken)
  4121. {
  4122. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  4123. }
  4124. cardSource.willBeRemoveSources = false;
  4125. TrashedCards.Add(cardSource);
  4126. }
  4127. }
  4128. }
  4129. #endregion
  4130. #region Trash link cards
  4131. public class ITrashLinkCards
  4132. {
  4133. public ITrashLinkCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  4134. {
  4135. _permanent = permanent;
  4136. _trashTargetCards = trashTargetCards.Clone();
  4137. _cardEffect = cardEffect;
  4138. }
  4139. public bool IsTrashed(CardSource cardSource)
  4140. {
  4141. return TrashedLinkCards.Contains(cardSource);
  4142. }
  4143. Permanent _permanent = null;
  4144. List<CardSource> _trashTargetCards = new List<CardSource>();
  4145. public List<CardSource> TrashedLinkCards = new List<CardSource>();
  4146. ICardEffect _cardEffect = null;
  4147. public IEnumerator TrashLinkCards()
  4148. {
  4149. if (_trashTargetCards == null) yield break;
  4150. if (_permanent == null) yield break;
  4151. if (_permanent.TopCard == null) yield break;
  4152. if (_cardEffect != null && _permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  4153. if (_permanent.HasNoLinkCards) yield break;
  4154. _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
  4155. _permanent.LinkedCards.Contains(cardSource));
  4156. if (_trashTargetCards.Count == 0) yield break;
  4157. _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
  4158. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  4159. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  4160. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  4161. #region cut in effect - Would discard
  4162. // "When link cards would be trashed" effect
  4163. //TODO: Create CardEffectCommons.WhenLinkCardWouldDiscard function
  4164. /*yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  4165. CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
  4166. _permanent,
  4167. _trashTargetCards,
  4168. _cardEffect
  4169. ),
  4170. EffectTiming.WhenWouldDigivolutionCardDiscarded));*/
  4171. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  4172. {
  4173. // effect
  4174. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  4175. // cut in effect process
  4176. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  4177. }
  4178. #endregion
  4179. //fix trash target permanent
  4180. Permanent permanentTarget_Fixed = _permanent;
  4181. // fix trash sources sources
  4182. List<CardSource> trashLinkCards_Fixed = _trashTargetCards.Filter(cardsource =>
  4183. cardsource != null
  4184. && cardsource.willBeRemoveSources);
  4185. #region "When link cards are trashed" effect
  4186. #region Hashtable Setting
  4187. Hashtable hashtable = new Hashtable()
  4188. {
  4189. {"CardEffect", _cardEffect},
  4190. {"Permanent", permanentTarget_Fixed},
  4191. {"DiscardedCards", trashLinkCards_Fixed},
  4192. };
  4193. #endregion
  4194. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLinkCardDiscarded));
  4195. #endregion
  4196. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  4197. foreach (CardSource cardSource in trashLinkCards_Fixed)
  4198. {
  4199. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
  4200. if (!cardSource.IsToken)
  4201. {
  4202. yield return ContinuousController.instance.StartCoroutine(permanentTarget_Fixed.RemoveLinkedCard(cardSource));
  4203. }
  4204. cardSource.willBeRemoveSources = false;
  4205. TrashedLinkCards.Add(cardSource);
  4206. }
  4207. }
  4208. }
  4209. #endregion
  4210. #region Return digivolution cards to deck bottom
  4211. public class ReturnToLibraryBottomDigivolutionCardsClass
  4212. {
  4213. public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
  4214. {
  4215. _permanent = permanent;
  4216. _cardSources = cardSources.Clone();
  4217. _hashtable = hashtable;
  4218. }
  4219. Permanent _permanent = null;
  4220. List<CardSource> _cardSources = new List<CardSource>();
  4221. Hashtable _hashtable = null;
  4222. public IEnumerator ReturnToLibraryBottomDigivolutionCards()
  4223. {
  4224. if (_permanent == null) yield break;
  4225. if (_permanent.TopCard == null) yield break;
  4226. if (_cardSources == null) yield break;
  4227. _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
  4228. if (_cardSources.Count == 0) yield break;
  4229. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  4230. if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
  4231. string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
  4232. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
  4233. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  4234. #region "When digivolution cards are returned to deck" effect
  4235. #region Hashtable Setting
  4236. Hashtable hashtable1 = new Hashtable()
  4237. {
  4238. {"Permanent", _permanent},
  4239. {"DeckBottomCards", _cardSources},
  4240. {"CardEffect", CardEffect},
  4241. };
  4242. #endregion
  4243. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
  4244. #endregion
  4245. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
  4246. }
  4247. }
  4248. #endregion
  4249. #region Reduce security
  4250. public class IReduceSecurity
  4251. {
  4252. public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos, ICardEffect cardEffect)
  4253. {
  4254. _player = player;
  4255. _refSkillInfos = refSkillInfos;
  4256. _cardEffect = cardEffect;
  4257. }
  4258. Player _player = null;
  4259. List<SkillInfo> _refSkillInfos = null;
  4260. ICardEffect _cardEffect = null;
  4261. public IEnumerator ReduceSecurity()
  4262. {
  4263. GManager.OnSecurityStackChanged?.Invoke(_player);
  4264. #region "When cards are removed from security" effect
  4265. #region Hashtable Setting
  4266. Hashtable hashtable = new Hashtable()
  4267. {
  4268. {"Player", _player},
  4269. {"SkillInfo",_refSkillInfos },
  4270. {"CardEffect",_cardEffect}
  4271. };
  4272. #endregion
  4273. if (_refSkillInfos == null)
  4274. {
  4275. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
  4276. }
  4277. else
  4278. {
  4279. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
  4280. {
  4281. _refSkillInfos.Add(skillInfo);
  4282. }
  4283. }
  4284. #endregion
  4285. }
  4286. }
  4287. #endregion
  4288. #region Add Security
  4289. public class IAddSecurity
  4290. {
  4291. public IAddSecurity(CardSource source)
  4292. {
  4293. _player = source.Owner;
  4294. _cardSource = source;
  4295. }
  4296. Player _player { get; set; }
  4297. CardSource _cardSource { get; set; }
  4298. public IEnumerator AddSecurity()
  4299. {
  4300. GManager.OnSecurityStackChanged?.Invoke(_player);
  4301. #region "When security cards are added" effect
  4302. #region Hashtable setting
  4303. Hashtable hashtable = new Hashtable()
  4304. {
  4305. {"Player", _player},
  4306. {"CardSources", new List<CardSource> { _cardSource } }
  4307. };
  4308. #endregion
  4309. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
  4310. #endregion
  4311. #region "When face up cards are added"
  4312. if (!_cardSource.IsFlipped)
  4313. {
  4314. #region Hashtable setting
  4315. Hashtable faceUpHashtable = new Hashtable()
  4316. {
  4317. {"Player", _player},
  4318. {"CardSources", new List<CardSource> { _cardSource } }
  4319. };
  4320. #endregion
  4321. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(faceUpHashtable, EffectTiming.OnFaceUpSecurityIncreased));
  4322. }
  4323. #endregion
  4324. }
  4325. }
  4326. #endregion
  4327. #region Flip Security Face Up
  4328. public class IFlipSecurity
  4329. {
  4330. public IFlipSecurity(CardSource source)
  4331. {
  4332. _player = source.Owner;
  4333. _cardSource = source;
  4334. }
  4335. Player _player { get; set; }
  4336. CardSource _cardSource { get; set; }
  4337. public IEnumerator FlipFaceUp()
  4338. {
  4339. if (!_player.SecurityCards.Contains(_cardSource) || !_cardSource.IsFlipped)
  4340. yield break;
  4341. _cardSource.SetFace();
  4342. #region "When face up cards are added"
  4343. #region Hashtable setting
  4344. Hashtable hashtable = new Hashtable()
  4345. {
  4346. {"Player", _player},
  4347. {"CardSources", new List<CardSource> { _cardSource } }
  4348. };
  4349. #endregion
  4350. if (!_cardSource.IsFlipped)
  4351. {
  4352. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnFaceUpSecurityIncreased));
  4353. }
  4354. #endregion
  4355. }
  4356. }
  4357. #endregion
  4358. #region Suspend permanents
  4359. public class SuspendPermanentsClass
  4360. {
  4361. private static WaitForSeconds _waitForSeconds0_3 = new WaitForSeconds(0.3f);
  4362. public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
  4363. {
  4364. _permanents = permanents;
  4365. _hashtable = hashtable;
  4366. }
  4367. public bool IsSuspended(Permanent permanent)
  4368. {
  4369. return SuspendedPermanents.Contains(permanent);
  4370. }
  4371. List<Permanent> _permanents { get; set; }
  4372. public List<Permanent> SuspendedPermanents { get; private set; } = new List<Permanent>();
  4373. Hashtable _hashtable { get; set; }
  4374. public IEnumerator Tap()
  4375. {
  4376. if (_permanents.Count == 0) yield break;
  4377. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  4378. bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
  4379. bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
  4380. List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
  4381. bool PermanentCondition(Permanent permanent)
  4382. {
  4383. if (permanent != null)
  4384. {
  4385. if (permanent.TopCard != null)
  4386. {
  4387. if (permanent.IsSuspended)
  4388. {
  4389. return false;
  4390. }
  4391. if (!permanent.CanSuspend)
  4392. {
  4393. return false;
  4394. }
  4395. if (CardEffect != null)
  4396. {
  4397. if (permanent.TopCard.CanNotBeAffected(CardEffect))
  4398. {
  4399. return false;
  4400. }
  4401. }
  4402. }
  4403. }
  4404. return true;
  4405. }
  4406. foreach (Permanent permanent in suspendTargetPermanents)
  4407. {
  4408. permanent.IsSuspended = true;
  4409. permanent.DPWhenSuspended = permanent.DP;
  4410. if (permanent.ShowingPermanentCard != null)
  4411. {
  4412. permanent.ShowingPermanentCard.ShowPermanentData(true);
  4413. }
  4414. SuspendedPermanents.Add(permanent);
  4415. }
  4416. if (suspendTargetPermanents.Count >= 1)
  4417. {
  4418. #region "Effects when permanents suspend
  4419. #region Hashtable Setting
  4420. Hashtable _hashtable = new Hashtable(){
  4421. {"Permanents", suspendTargetPermanents},
  4422. {"IsBlock", IsBlock}
  4423. };
  4424. if (CardEffect != null)
  4425. {
  4426. _hashtable.Add("CardEffect", CardEffect);
  4427. }
  4428. #endregion
  4429. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  4430. #endregion
  4431. yield return _waitForSeconds0_3;
  4432. }
  4433. }
  4434. }
  4435. #endregion
  4436. #region Unsuspend permanents
  4437. public class IUnsuspendPermanents
  4438. {
  4439. private static WaitForSeconds _waitForSeconds0_3 = new WaitForSeconds(0.3f);
  4440. public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
  4441. {
  4442. _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  4443. _cardEffect = cardEffect;
  4444. }
  4445. List<Permanent> _permanents { get; set; }
  4446. ICardEffect _cardEffect { get; set; }
  4447. public IEnumerator Unsuspend()
  4448. {
  4449. //Permanent list that will unsuspend
  4450. List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
  4451. permanent != null
  4452. && permanent.TopCard != null
  4453. && permanent.IsSuspended
  4454. && permanent.CanUnsuspend
  4455. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  4456. #region "When permanents would unsuspend" effect
  4457. #region Hashtable Setting
  4458. Hashtable hashtable1 = new Hashtable()
  4459. {
  4460. {"CardEffect", _cardEffect},
  4461. {"Permanents", untappedPermanets},
  4462. };
  4463. #endregion
  4464. List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
  4465. if (skillInfos.Count >= 1)
  4466. {
  4467. foreach (SkillInfo skillInfo in skillInfos)
  4468. {
  4469. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  4470. }
  4471. foreach (Permanent permanent in untappedPermanets)
  4472. {
  4473. permanent.ShowUnsuspendEffect();
  4474. }
  4475. //cut in effects
  4476. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  4477. untappedPermanets.ForEach(permanent =>
  4478. {
  4479. if (permanent.ShowingPermanentCard != null)
  4480. {
  4481. permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
  4482. }
  4483. });
  4484. }
  4485. #endregion
  4486. // fix unsuspend target permanents
  4487. List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
  4488. permanent != null
  4489. && permanent.TopCard != null
  4490. && permanent.IsSuspended
  4491. && permanent.CanUnsuspend
  4492. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  4493. if (untappedPermanets_Fixed.Count >= 1)
  4494. {
  4495. foreach (Permanent permanent in untappedPermanets_Fixed)
  4496. {
  4497. permanent.IsSuspended = false;
  4498. if (permanent.ShowingPermanentCard != null)
  4499. {
  4500. permanent.ShowingPermanentCard.ShowPermanentData(true);
  4501. }
  4502. }
  4503. #region "When permanents are unsuspended" effect
  4504. #region Hashtable Setting
  4505. Hashtable hashtable2 = new Hashtable()
  4506. {
  4507. {"CardEffect", _cardEffect},
  4508. {"Permanents", untappedPermanets_Fixed},
  4509. };
  4510. #endregion
  4511. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
  4512. #endregion
  4513. yield return _waitForSeconds0_3;
  4514. }
  4515. }
  4516. }
  4517. #endregion
  4518. #region Trash cards from deck top
  4519. public class ITrashDeckCards
  4520. {
  4521. public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
  4522. {
  4523. this.cardSources = new List<CardSource>();
  4524. foreach (CardSource cardSource in cardSources)
  4525. {
  4526. this.cardSources.Add(cardSource);
  4527. }
  4528. this.cardEffect = cardEffect;
  4529. }
  4530. List<CardSource> cardSources { get; set; } = new List<CardSource>();
  4531. ICardEffect cardEffect { get; set; } = null;
  4532. public IEnumerator TrashDeckCards()
  4533. {
  4534. List<CardSource> trashCards = new List<CardSource>();
  4535. foreach (CardSource cardSource in cardSources)
  4536. {
  4537. if (cardSource.Owner.LibraryCards.Contains(cardSource))
  4538. {
  4539. trashCards.Add(cardSource);
  4540. }
  4541. }
  4542. if (trashCards.Count >= 1)
  4543. {
  4544. foreach (CardSource cardSource in trashCards)
  4545. {
  4546. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  4547. }
  4548. #region "When cards are trashed from security" effect
  4549. #region Hashtable setting
  4550. Hashtable hashtable = new Hashtable()
  4551. {
  4552. {"DiscardedCards", trashCards},
  4553. {"CardEffect", cardEffect},
  4554. };
  4555. #endregion
  4556. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  4557. hashtable, EffectTiming.OnDiscardLibrary));
  4558. #endregion
  4559. }
  4560. }
  4561. }
  4562. #endregion
  4563. #region Overflow of ace
  4564. public class AceOverflowClass
  4565. {
  4566. public AceOverflowClass(List<CardSource> cardSources)
  4567. {
  4568. _cardSources = cardSources.Clone();
  4569. }
  4570. List<CardSource> _cardSources = new List<CardSource>();
  4571. public IEnumerator Overflow()
  4572. {
  4573. _cardSources = _cardSources
  4574. .Filter(cardSource => cardSource.IsACE && !cardSource.IsFlipped && CardEffectCommons.IsExistOnBattleArea(cardSource) || CardEffectCommons.IsExistOnBreedingAreaDigimon(cardSource))
  4575. .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
  4576. .ToList();
  4577. foreach (CardSource cardSource in _cardSources)
  4578. {
  4579. yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
  4580. string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
  4581. PlayLog.OnAddLog?.Invoke(log);
  4582. }
  4583. }
  4584. }
  4585. #endregion
  4586. #region TrashStack
  4587. public class ITrashStack
  4588. {
  4589. /// <summary>
  4590. /// Trash Stack Class
  4591. /// </summary>
  4592. /// <param name="permanent">Target Permanent</param>
  4593. /// <param name="TrashCount">Amount of cards to trash</param>
  4594. /// <param name="cardEffect">Card Effect</param>
  4595. /// <param name="fromTop">Should trashing start from top, true by default</param>
  4596. public ITrashStack(Permanent permanent, int TrashCount, ICardEffect cardEffect, bool fromTop = true)
  4597. {
  4598. _permanent = permanent;
  4599. _trashCount = TrashCount;
  4600. _cardEffect = cardEffect;
  4601. _fromTop = fromTop;
  4602. }
  4603. Permanent _permanent = null;
  4604. int _trashCount;
  4605. ICardEffect _cardEffect = null;
  4606. bool _fromTop;
  4607. public IEnumerator TrashStack()
  4608. {
  4609. if (_cardEffect == null) yield break;
  4610. if (_cardEffect.EffectSourceCard == null) yield break;
  4611. if (_permanent == null) yield break;
  4612. if (_permanent.TopCard == null) yield break;
  4613. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
  4614. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  4615. _trashCount = Math.Min(_permanent.StackCards.Count, _trashCount);
  4616. if (_trashCount >= 1)
  4617. {
  4618. int count = 0;
  4619. List<CardSource> selectedCards = new List<CardSource>();
  4620. while (true)
  4621. {
  4622. bool StopCondition()
  4623. {
  4624. if (_permanent.HasNoDigivolutionCards)
  4625. {
  4626. return true;
  4627. }
  4628. if (count >= _trashCount)
  4629. {
  4630. return true;
  4631. }
  4632. return false;
  4633. }
  4634. if (StopCondition())
  4635. {
  4636. break;
  4637. }
  4638. if (count == 0)
  4639. {
  4640. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  4641. }
  4642. CardSource cardSource = _permanent.TopCard;
  4643. selectedCards.Add(cardSource);
  4644. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  4645. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  4646. if (!cardSource.IsToken)
  4647. {
  4648. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  4649. }
  4650. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  4651. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  4652. _permanent.TopCard.SetChangedLocationTime();//register that the new topcard just became a top card for the purpose of the start of timestamped continuous effects
  4653. count++;
  4654. }
  4655. #region "When Top Card is Trashed" effect
  4656. #region Hashtable Setting
  4657. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  4658. {
  4659. {"Permanent", _permanent},
  4660. {"CardSources", selectedCards}
  4661. };
  4662. #endregion
  4663. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  4664. .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
  4665. #endregion
  4666. #region add log
  4667. if (selectedCards.Count >= 1)
  4668. {
  4669. string log = "";
  4670. log += $"\nStack Trashed :";
  4671. foreach (CardSource cardSource in selectedCards)
  4672. {
  4673. if (cardSource != null)
  4674. {
  4675. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  4676. }
  4677. }
  4678. log += "\n";
  4679. PlayLog.OnAddLog?.Invoke(log);
  4680. }
  4681. #endregion
  4682. }
  4683. }
  4684. }
  4685. #endregion