| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- #region Trash cards from hand
- public class IDiscardHands
- {
- public IDiscardHands(List<IDiscardHand> discardHands, ICardEffect cardEffect)
- {
- foreach (IDiscardHand discardHand in discardHands)
- {
- this.discardHands.Add(discardHand);
- }
- this.cardEffect = cardEffect;
- }
- List<IDiscardHand> discardHands { get; set; } = new List<IDiscardHand>();
- ICardEffect cardEffect { get; set; }
- public bool HasDiscarded { get; set; }
- public IEnumerator DiscardHands()
- {
- foreach (IDiscardHand discardHand in discardHands)
- {
- yield return ContinuousController.instance.StartCoroutine(discardHand.Discard());
- }
- List<CardSource> discardedCards = new List<CardSource>();
- foreach (IDiscardHand discardHand in discardHands)
- {
- if (discardHand.discarded)
- {
- discardedCards.Add(discardHand.cardSource);
- }
- }
- if (discardedCards.Count >= 1)
- {
- #region "When cards are trashed from hand" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"DiscardedCards", discardedCards},
- {"CardEffect", cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardHand));
- #endregion
- HasDiscarded = true;
- }
- #region add log
- if (discardedCards.Count >= 1)
- {
- string log = "";
- log += $"\nDiscard hand:";
- foreach (CardSource cardSource in discardedCards)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- public class IDiscardHand
- {
- public IDiscardHand(CardSource cardSource, Hashtable hashtable)
- {
- this.cardSource = cardSource;
- this.hashtable = hashtable;
- }
- public CardSource cardSource { get; private set; }
- public Hashtable hashtable { get; private set; }
- public bool discarded { get; private set; } = false;
- public IEnumerator Discard()
- {
- bool oldisHand = cardSource.Owner.HandCards.Contains(cardSource);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- bool isTrash = CardEffectCommons.IsExistOnTrash(cardSource);
- if (oldisHand && isTrash)
- {
- discarded = true;
- }
- }
- }
- #endregion
- #region Play cards
- public class PlayCardClass
- {
- public PlayCardClass(List<CardSource> cardSources, Hashtable hashtable, bool payCost, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root,
- bool activateETB)
- {
- if (cardSources != null)
- {
- CardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
- }
- _hashtable = hashtable;
- PayCost = payCost;
- _targetPermanent = targetPermanent;
- _isTapped = isTapped;
- Root = root;
- _activateETB = activateETB;
- }
- public void SetJogress(int[] jogressEvoRootsFrameIDs)
- {
- if (jogressEvoRootsFrameIDs != null)
- {
- _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
- }
- }
- public void SetBurst(int BurstTamerFrameID, CardSource card)
- {
- if (0 <= BurstTamerFrameID && BurstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
- {
- _burstTamerFrameID = BurstTamerFrameID;
- }
- }
- public void SetAppFusion(int[] AppFusionFrameID)
- {
- if (AppFusionFrameID != null)
- {
- _appFusionFrameIDs = AppFusionFrameID.CloneArray(); ;
- }
- }
- public void SetShowEffect()
- {
- _showEffect = true;
- }
- public void SetIgnoreLevel()
- {
- _ignoreLevel = true;
- SetIgnoreRequirements(CardEffectCommons.IgnoreRequirement.Level);
- }
- public void SetIgnoreRequirements(CardEffectCommons.IgnoreRequirement ignore)
- {
- _ignoreRequirement = ignore;
- }
- private bool GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement ignore)
- {
- return _ignoreRequirement.Equals(ignore) || _ignoreRequirement.Equals(CardEffectCommons.IgnoreRequirement.All);
- }
- public void SetFixedCost(int FixedCost)
- {
- _fixedCost = FixedCost;
- }
- public void SetReducedCost(int ReducedCost)
- {
- _reducedCost = ReducedCost;
- }
- public void SetIsBreedingArea()
- {
- _isBreedingArea = true;
- }
- public List<CardSource> CardSources { get; private set; } = new List<CardSource>();
- Hashtable _hashtable = null;
- public bool PayCost { get; private set; }
- Permanent _targetPermanent = null;
- bool _isTapped = false;
- public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
- bool _activateETB = true;
- bool _showEffect = false;
- bool _ignoreLevel = false;
- CardEffectCommons.IgnoreRequirement _ignoreRequirement = CardEffectCommons.IgnoreRequirement.None;
- int _fixedCost = -1;
- int _reducedCost = 0;
- int[] _jogressEvoRootsFrameIDs = null;
- int _burstTamerFrameID = -1;
- int[] _appFusionFrameIDs = null;
- bool _isBreedingArea = false;
- public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
- bool IsBurst(CardSource card)
- {
- Permanent burstTamer = BurstTamer(card);
- if (burstTamer != null)
- {
- if (burstTamer.TopCard != null)
- {
- if (card.burstDigivolutionCondition != null)
- {
- if (card.burstDigivolutionCondition.tamerCondition != null)
- {
- if (card.burstDigivolutionCondition.tamerCondition(burstTamer))
- {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- Permanent BurstTamer(CardSource card)
- {
- if (0 <= _burstTamerFrameID && _burstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
- {
- Permanent tamer = card.Owner.fieldCardFrames[_burstTamerFrameID].GetFramePermanent();
- return tamer;
- }
- return null;
- }
- bool IsAppFusion(CardSource card)
- {
- CardSource linkCard = LinkedCard(card);
- if (linkCard != null)
- {
- if (card.appFusionCondition != null)
- {
- if (card.appFusionCondition.digimonCondition != null)
- {
- Permanent digimon = card.Owner.fieldCardFrames[_appFusionFrameIDs[0]].GetFramePermanent();
- if (card.appFusionCondition.linkedCondition != null)
- {
- if (card.appFusionCondition.linkedCondition(digimon, linkCard))
- {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- public CardSource LinkedCard(CardSource card)
- {
- if (_appFusionFrameIDs != null && _appFusionFrameIDs.Length == 2)
- {
- if (0 <= _appFusionFrameIDs[0] && _appFusionFrameIDs[0] <= card.Owner.fieldCardFrames.Count - 1)
- {
- Permanent targetPermanent = card.Owner.fieldCardFrames[_appFusionFrameIDs[0]].GetFramePermanent();
- if (targetPermanent.LinkedCards.Count > _appFusionFrameIDs[1])
- {
- CardSource link = targetPermanent.LinkedCards[_appFusionFrameIDs[1]];
- return link;
- }
- }
- }
- return null;
- }
- public IEnumerator PlayCard()
- {
- bool burstDigivolved = false;
- bool appFusion = false;
- bool isEvolution = false;
- List<CardSource> playedCards_fixed = new List<CardSource>();
- foreach (CardSource card in CardSources)
- {
- GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
- GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
- GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
- if (card == null)
- {
- continue;
- }
- #region Set Root
- ICardEffect CardEffect = null;
- CardEffect = CardEffectCommons.GetCardEffectFromHashtable(this._hashtable);
- if (CardEffectCommons.IsExistOnTrash(card))
- {
- Root = SelectCardEffect.Root.Trash;
- }
- else if (card.Owner.HandCards.Contains(card))
- {
- Root = SelectCardEffect.Root.Hand;
- }
- else if (card.Owner.LibraryCards.Contains(card))
- {
- Root = SelectCardEffect.Root.Library;
- }
- else if (card.Owner.GetFieldPermanents().Count((permanent) => permanent.DigivolutionCards.Contains(card)) >= 1)
- {
- Root = SelectCardEffect.Root.DigivolutionCards;
- }
- else if (card.Owner.GetFieldPermanents().Count((permanent) => permanent.LinkedCards.Contains(card)) >= 1)
- {
- Root = SelectCardEffect.Root.LinkedCards;
- }
- else if (card.Owner.SecurityCards.Contains(card))
- {
- Root = SelectCardEffect.Root.Security;
- }
- else if (CardEffectCommons.IsExistOnExecutingArea(card))
- {
- Root = SelectCardEffect.Root.Execution;
- }
- #endregion
- #region Set target(s)
- List<Permanent> targetPermanents = new List<Permanent>();
- if (card.IsPermanent)
- {
- if (!isJogress)
- {
- if (CardEffectCommons.IsOwnerPermanent(_targetPermanent, card))
- {
- targetPermanents.Add(_targetPermanent);
- }
- }
- else
- {
- for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
- {
- int JogressFrameID = _jogressEvoRootsFrameIDs[i];
- if (0 <= JogressFrameID && JogressFrameID <= card.Owner.fieldCardFrames.Count - 1)
- {
- Permanent targetPermanent = card.Owner.fieldCardFrames[JogressFrameID].GetFramePermanent();
- targetPermanents.Add(targetPermanent);
- }
- }
- foreach (Permanent permanent in targetPermanents)
- {
- permanent.ShowingPermanentCard.SetPermanentIndexText(targetPermanents);
- }
- }
- }
- #endregion
- #region Determine if Evolution
- if (targetPermanents.Count >= 1)
- {
- if (!isJogress)
- {
- if (IsBurst(card))
- {
- if (card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
- {
- isEvolution = true;
- }
- }
- else if (IsAppFusion(card))
- {
- if (card.CanAppFusionFromTargetPermanent(targetPermanents[0], PayCost))
- {
- isEvolution = true;
- }
- }
- else
- {
- if (card.CanEvolve(targetPermanents[0], true) || GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level) || _ignoreLevel)
- {
- isEvolution = true;
- }
- }
- }
- else
- {
- if (targetPermanents.Count == 2)
- {
- isEvolution = true;
- }
- }
- }
- #endregion
- List<CardSource> oldTrashCards = new List<CardSource>();
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForNonTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.oldIsTapped_playCard = permanent.IsSuspended;
- }
- }
- foreach (CardSource cardSource in card.Owner.TrashCards)
- {
- oldTrashCards.Add(cardSource);
- }
- // effect of removing digivolution/linked cards
- if (card.IsPermanent && !isEvolution && card.PermanentOfThisCard() != null && (Root == SelectCardEffect.Root.DigivolutionCards || Root == SelectCardEffect.Root.LinkedCards))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(card, card.PermanentOfThisCard()));
- }
- #region select digivolution cost
- int baseCost = -1;
- bool costSelected = false;
- yield return ContinuousController.instance.StartCoroutine(SelectCost());
- IEnumerator SelectCost()
- {
- if (!isJogress)
- {
- if (PayCost)
- {
- if (_fixedCost < 0)
- {
- Permanent targetPermanent = null;
- if (targetPermanents.Count >= 1)
- {
- targetPermanent = targetPermanents[0];
- }
- if (targetPermanent != null)
- {
- List<int> CostList = new List<int>();
- bool isBurst = IsBurst(card);
- bool isAppFusion = IsAppFusion(card);
- if (isBurst || isAppFusion)
- {
- if (isBurst)
- CostList.Add(card.burstDigivolutionCondition.cost);
- if (isAppFusion)
- CostList.Add(card.appFusionCondition.cost);
- }
- else
- {
- foreach (int cost in card.CostList(targetPermanent, ignoreLevel: GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level), checkAvailability: false))
- {
- int evoCost = cost;
- if (_reducedCost > 0)
- evoCost -= _reducedCost;
- CostList.Add(evoCost);
- }
- }
- CostList = CostList.Distinct().ToList();
- if (CostList.Count >= 1)
- {
- if (CostList.Count == 1)
- {
- baseCost = CostList[0];
- }
- else
- {
- costSelected = true;
- bool MoveToExecuteCardEffect = true;
- if (card.Owner.HandCards.Contains(card) && card.ShowingHandCard != null)
- {
- if (card.ShowingHandCard.gameObject.activeSelf)
- {
- MoveToExecuteCardEffect = false;
- }
- }
- if (!card.Owner.isYou && GManager.instance.IsAI)
- {
- MoveToExecuteCardEffect = false;
- costSelected = false;
- }
- if (card.Owner.isYou && ContinuousController.instance.autoMinDigivolutionCost)
- {
- MoveToExecuteCardEffect = false;
- costSelected = false;
- }
- if (MoveToExecuteCardEffect)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
- }
- SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
- if (selectCountEffect != null)
- {
- selectCountEffect.SetUp(
- SelectPlayer: card.Owner,
- targetPermanent: null,
- MaxCount: 1,
- CanNoSelect: false,
- Message: "Which digivolution cost do you pay?",
- Message_Enemy: "The opponent is choosing which digivolution cost to pay.",
- SelectCountCoroutine: SelectCountCoroutine);
- selectCountEffect.SetCandidates(CostList);
- selectCountEffect.SetPreferMin(true);
- selectCountEffect.SetIsDigivolutionCost(true);
- yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
- IEnumerator SelectCountCoroutine(int count)
- {
- baseCost = count;
- yield return null;
- }
- }
- }
- }
- }
- else
- {
- baseCost = card.BasePlayCostFromEntity;
- }
- }
- }
- }
- }
- #endregion
- #region select DNA condition
- int baseDNA = 0;
- if (isJogress)
- {
- baseDNA = GManager.instance.GetComponent<SelectDNACondition>()._selectedCount;
- }
- #endregion
- #region HashTable Setting
- Hashtable hashtable = CardEffectCommons.WouldEnterFieldHashtable(
- payCost: PayCost,
- card: card,
- root: Root,
- isEvolution: isEvolution,
- playCardClass: this,
- cardEffect: CardEffect,
- isJogress: isJogress,
- targetPermanents: targetPermanents
- );
- #endregion
- List<SkillInfo> skillInfos_BeforePayCost = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.BeforePayCost)
- .Concat(AutoProcessing.GetSkillInfosOfCards(hashtable, EffectTiming.BeforePayCost, new List<CardSource>() { card }
- .Filter(cardSource => !CardEffectCommons.IsExistOnHand(cardSource) && !CardEffectCommons.IsExistOnTrash(cardSource) && !CardEffectCommons.IsExistInSecurity(cardSource) && cardSource.PermanentOfThisCard() == null)))
- .ToList();
- yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.BeforePayCost));
- #region IsShowEffect()
- bool IsShowEffect()
- {
- if (skillInfos_BeforePayCost.Count >= 2)
- {
- return true;
- }
- else if (skillInfos_BeforePayCost.Count == 1)
- {
- if (skillInfos_BeforePayCost[0].CardEffect.CanActivate(skillInfos_BeforePayCost[0].Hashtable))
- {
- return true;
- }
- }
- else if (card.HasDigiXros && !isEvolution)
- {
- return true;
- }
- else if (IsBurst(card))
- {
- return true;
- }
- else if (IsAppFusion(card))
- {
- return true;
- }
- return false;
- }
- #endregion
- #region effect
- if (PayCost || IsShowEffect())
- {
- if (!costSelected)
- {
- if (card.IsOption || IsShowEffect())
- {
- bool noHandCard = true;
- if (card.Owner.HandCards.Contains(card))
- {
- if (card.ShowingHandCard != null)
- {
- if (card.ShowingHandCard.gameObject.activeSelf)
- {
- if (card.ShowingHandCard.gameObject.transform.GetChild(0).gameObject.activeSelf)
- {
- noHandCard = false;
- }
- }
- }
- }
- if (noHandCard)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
- }
- }
- else
- {
- if (CardEffect == null)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
- }
- }
- }
- }
- #endregion
- #region show expected cost
- if (PayCost)
- {
- if (!isJogress)
- {
- int cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
- }
- else
- {
- if (card.jogressCondition.Count > 0)
- {
- int cost = card.GetPayingCostWithBaseCost(card.jogressCondition[baseDNA].cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
- }
- }
- }
- #endregion
- #region process cut in effects before paying cost
- if (skillInfos_BeforePayCost.Count >= 1)
- {
- foreach (SkillInfo skillInfo in skillInfos_BeforePayCost)
- {
- GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
- }
- if (IsShowEffect())
- {
- foreach (Permanent targetPermanent in targetPermanents)
- {
- if (targetPermanent != null)
- {
- targetPermanent.ShowWillEvolutionEffect();
- }
- }
- }
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
- foreach (Permanent targetPermanent in targetPermanents)
- {
- if (targetPermanent != null)
- {
- targetPermanent.HideWillEvolutionEffect();
- }
- }
- }
- #endregion
- 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
- {
- #region select DigiXros
- if (card.HasDigiXros && !isEvolution)
- {
- GManager.instance.GetComponent<SelectDigiXrosClass>().SetExcludedCards(CardSources);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectDigiXrosClass>().Select(card));
- }
- #endregion
- #region select Assembly
- if (card.HasAssembly && !isEvolution)
- {
- GManager.instance.GetComponent<SelectAssemblyClass>().SetExcludedCards(CardSources);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectAssemblyClass>().Select(card));
- }
- #endregion
- }
- #region Bounce Tamer of Burst digivolution
- if (IsBurst(card))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectBurstDigivolutionEffect.BounceTamer(BurstTamer(card)));
- if (!GManager.instance.selectBurstDigivolutionEffect.TamerBounced)
- {
- _burstTamerFrameID = -1;
- yield return ContinuousController.instance.StartCoroutine(SelectCost());
- }
- else
- {
- burstDigivolved = true;
- }
- }
- #endregion
- #region Add Link Card of App Fusion
- if (IsAppFusion(card))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectAppFusionEffect.AddToSources(LinkedCard(card)));
- if (!GManager.instance.selectAppFusionEffect.LinkAdded)
- {
- _appFusionFrameIDs = new int[0];
- yield return ContinuousController.instance.StartCoroutine(SelectCost());
- }
- else
- {
- appFusion = true;
- }
- }
- #endregion
- #region fix cost to pay
- int Cost = 0;
- if (PayCost)
- {
- if (!isJogress)
- {
- Cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- Cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- }
- else
- {
- if (card.jogressCondition.Count > 0)
- {
- Cost = card.GetPayingCostWithBaseCost(card.jogressCondition[baseDNA].cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- }
- }
- GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(Cost));
- }
- #endregion
- #region end play cards
- bool endPlayCard = false;
- bool playFailed = false;
- if (PayCost)
- {
- if (Cost > card.Owner.MaxMemoryCost)
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- if (isEvolution)
- {
- if (targetPermanents != null)
- {
- if (targetPermanents.Count >= 1)
- {
- foreach (Permanent permanent in targetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard == null)
- {
- endPlayCard = true;
- }
- }
- }
- if (!endPlayCard)
- {
- if (!isJogress && !IsBurst(card) && !IsAppFusion(card))
- {
- if (!GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level) && !card.CanPlayCardTargetFrame(targetPermanents[0].PermanentFrame, PayCost, CardEffect, root: Root, fixedCost: -1))
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- else if (isJogress)
- {
- if (!card.CanJogressFromTargetPermanents(targetPermanents, PayCost))
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- else if (IsBurst(card))
- {
- if (!card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- else if (IsAppFusion(card))
- {
- if (!card.CanAppFusionFromTargetPermanent(targetPermanents[0], PayCost))
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- }
- }
- }
- }
- if (endPlayCard)
- {
- PlayLog.OnAddLog?.Invoke($"\nFailed to play:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
- GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
- GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().FailedPlayCardEffect(card));
- if (card.Owner.HandCards.Contains(card))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(new List<CardSource>() { card }, false, null));
- }
- ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
- foreach (HandCard handCard in card.Owner.brainStormObject.BrainStormHandCards)
- {
- if (handCard.gameObject.activeSelf && handCard.cardSource == card)
- {
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- }
- }
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
- {
- if (fieldPermanentCard != null)
- {
- fieldPermanentCard.OffPermanentIndexText();
- }
- }
- }
- if (playFailed)
- {
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.IsSuspended = permanent.oldIsTapped_playCard;
- }
- }
- foreach (CardSource cardSource in oldTrashCards)
- {
- if (!CardEffectCommons.IsExistOnTrash(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- }
- }
- }
- #endregion
- card.Owner.UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
- if (endPlayCard)
- {
- continue;
- }
- #region pay cost
- if (PayCost)
- {
- // memory lose
- if (Cost <= card.Owner.MaxMemoryCost)
- {
- yield return ContinuousController.instance.StartCoroutine(card.Owner.AddMemory(-1 * Cost, null));
- }
- ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
- }
- #endregion
- #region cut in effect after paying cost
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(hashtable, EffectTiming.AfterPayCost));
- // cur in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(
- false,
- AutoProcessing.HasExecutedSameEffect));
- #endregion
- // add to played cards
- playedCards_fixed.Add(card);
- }
- #region filter cards
- bool isDualCardAsOption(CardSource cardSource) => cardSource.IsDigimon && cardSource.IsOption && !isEvolution;
- List<CardSource> permanentCards = playedCards_fixed.Filter(cardSource => cardSource.IsPermanent && !isDualCardAsOption(cardSource));
- List<CardSource> optionCards = playedCards_fixed.Filter(cardSource => !cardSource.IsPermanent || isDualCardAsOption(cardSource));
- #region play permanent
- PlayPermanentClass playPermanent = new PlayPermanentClass(permanentCards, _hashtable, _targetPermanent, _isTapped, Root, _activateETB);
- if (isJogress)
- {
- playPermanent.SetJogress(_jogressEvoRootsFrameIDs);
- }
- if (burstDigivolved)
- {
- playPermanent.SetBurstDigivolved();
- }
- if (appFusion)
- playPermanent.SetAppFusion(_appFusionFrameIDs);
- if (_isBreedingArea)
- {
- playPermanent.SetIsBreedingArea();
- }
- yield return ContinuousController.instance.StartCoroutine(playPermanent.PlayPermanent());
- #endregion
- #region use option
- UseOptionClass useOption = new UseOptionClass(optionCards, _hashtable, Root)
- {
- _showEffect = _showEffect
- };
- yield return ContinuousController.instance.StartCoroutine(useOption.UseOption());
- #endregion
- #endregion
- }
- IEnumerator OffMemoryPredictionLine()
- {
- yield return new WaitForSeconds(0.5f);
- GManager.instance.memoryObject.OffMemoryPredictionLine();
- }
- }
- #endregion
- #region Hatch DigiEgg
- public class HatchDigiEggClass
- {
- public HatchDigiEggClass(Player player, Hashtable hashtable)
- {
- _player = player;
- _hashtable = hashtable;
- }
- Player _player { get; set; }
- Hashtable _hashtable { get; set; }
- public IEnumerator Hatch()
- {
- if (_player == null) yield break;
- if (!_player.CanHatch) yield break;
- CardSource card = _player.DigitamaLibraryCards[0];
- PlayPermanentClass playPermanentClass = new PlayPermanentClass(
- cardSources: new List<CardSource>() { card },
- hashtable: _hashtable,
- targetPermanent: null,
- isTapped: false,
- root: SelectCardEffect.Root.Library,
- ActivateETB: true);
- playPermanentClass.SetIsBreedingArea();
- playPermanentClass.SetIsHatching();
- yield return ContinuousController.instance.StartCoroutine(playPermanentClass.PlayPermanent());
- if (card.PermanentOfThisCard() != null)
- {
- card.PermanentOfThisCard().EnterFieldTurnCount = -1;
- }
- }
- }
- #endregion
- #region Play permanents
- #region Hashtable setting class
- public class OnEnterFieldHashtableParams
- {
- public OnEnterFieldHashtableParams(
- Permanent permanent,
- List<CardSource> evoRoots,
- List<CardSource> evoRootTops,
- SelectCardEffect.Root root,
- List<int> oldLevels,
- bool isFromDigimonDigivolutionCards,
- int digiXrosCount = 0,
- int assemblyCount = 0)
- {
- Permanent = permanent;
- if (evoRoots != null)
- {
- EvoRoots = evoRoots.Clone();
- }
- if (evoRootTops != null)
- {
- EvoRootTops = evoRootTops.Clone();
- }
- Root = root;
- if (oldLevels != null)
- {
- OldLevels = oldLevels.Clone();
- }
- IsFromDigimonDigivolutionCards = isFromDigimonDigivolutionCards;
- DigixrosCount = digiXrosCount;
- AssemblyCount = assemblyCount;
- }
- public Permanent Permanent { get; private set; } = null;
- public List<CardSource> EvoRoots = new List<CardSource>();
- public List<CardSource> EvoRootTops { get; private set; } = new List<CardSource>();
- public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
- public List<int> OldLevels { get; private set; } = new List<int>();
- public bool IsFromDigimonDigivolutionCards { get; private set; } = false;
- public int DigixrosCount { get; private set; } = 0;
- public int AssemblyCount { get; private set; } = 0;
- }
- #endregion
- public class PlayPermanentClass
- {
- public PlayPermanentClass(List<CardSource> cardSources, Hashtable hashtable, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root, bool ActivateETB)
- {
- if (cardSources != null)
- {
- _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
- }
- _hashtable = hashtable;
- _targetPermanent = targetPermanent;
- _isTapped = isTapped;
- _root = root;
- _activateETB = ActivateETB;
- }
- public void SetJogress(int[] jogressEvoRootsFrameIDs)
- {
- if (jogressEvoRootsFrameIDs != null)
- {
- _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
- }
- }
- public void SetBurstDigivolved()
- {
- _burstDigivolved = true;
- }
- public void SetAppFusion(int[] appFusionFrameIDs)
- {
- if (appFusionFrameIDs != null)
- {
- _appFusionFrameIDs = appFusionFrameIDs.CloneArray();
- }
- _appFusion = true;
- }
- public void SetIsBreedingArea()
- {
- _isBreedingArea = true;
- }
- public void SetIsHatching()
- {
- _isHatching = true;
- }
- public void SetISPlayOption()
- {
- _isPlayOption = true;
- }
- List<CardSource> _cardSources = new List<CardSource>();
- Hashtable _hashtable = null;
- Permanent _targetPermanent = null;
- bool _isTapped = false;
- SelectCardEffect.Root _root = SelectCardEffect.Root.None;
- bool _activateETB = true;
- int[] _jogressEvoRootsFrameIDs = null;
- int _digiXrosCount = 0;
- int _maxDigixrosCount = 0;
- int _assemblyCount = 0;
- int _maxAssemblyCount = 0;
- bool _burstDigivolved = false;
- int[] _appFusionFrameIDs = null;
- bool _appFusion = false;
- bool _isBreedingArea = false;
- bool _isHatching = false;
- bool _isPlayOption = false;
- public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
- public bool isAppFusion => _appFusionFrameIDs != null && _appFusionFrameIDs.Length == 2;
- public IEnumerator PlayPermanent()
- {
- List<OnEnterFieldHashtableParams> hashtableParams = new List<OnEnterFieldHashtableParams>();
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- bool isEvolution = false;
- foreach (CardSource card in _cardSources)
- {
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- 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
- {
- #region select DigiXros
- if (card.HasDigiXros && !isEvolution)
- {
- GManager.instance.GetComponent<SelectDigiXrosClass>().SetExcludedCards(_cardSources);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectDigiXrosClass>().Select(card));
- }
- #endregion
- #region select Assembly
- if (card.HasAssembly && !isEvolution)
- {
- GManager.instance.GetComponent<SelectAssemblyClass>().SetExcludedCards(_cardSources);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectAssemblyClass>().Select(card));
- }
- #endregion
- }
- if (GManager.instance.GetComponent<SelectDigiXrosClass>().playCard == card)
- {
- _digiXrosCount = GManager.instance.GetComponent<SelectDigiXrosClass>().selectedDigicrossCards.Count;
- _maxDigixrosCount = Math.Max(_digiXrosCount, _maxDigixrosCount);
- }
- if (GManager.instance.GetComponent<SelectAssemblyClass>().playCard == card)
- {
- _assemblyCount = GManager.instance.GetComponent<SelectAssemblyClass>().selectedAssemblyCards.Count;
- _maxAssemblyCount = Math.Max(_assemblyCount, _maxAssemblyCount);
- }
- bool isFromDigimonDigivolutionCards = card.Owner.GetFieldPermanents().Some((permanent) => permanent.DigivolutionCards.Contains(card));
- bool isFromSecurity = card.Owner.SecurityCards.Contains(card);
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- Permanent permanent = null;
- isEvolution = false;
- List<CardSource> evoRoots = new List<CardSource>();
- List<CardSource> evoRootTops = new List<CardSource>();
- bool played = false;
- List<int> oldLevels = new List<int>();
- int frameId = -1;
- if (_targetPermanent == null)
- {
- if (_isBreedingArea)
- {
- if (card.Owner.GetBreedingAreaPermanents().Count == 0)
- {
- FieldCardFrame digieggFrame = card.Owner.fieldCardFrames.Find(fieldCardFrame =>
- fieldCardFrame.IsEmptyFrame() &&
- !fieldCardFrame.IsBattleAreaFrame());
- if (digieggFrame != null)
- {
- if (_isHatching)
- frameId = digieggFrame.FrameID;
- else if (card.CanPlayCardTargetFrame(digieggFrame, false, CardEffect, isBreedingArea: _isBreedingArea))
- frameId = digieggFrame.FrameID;
- }
- }
- }
- else
- {
- FieldCardFrame preferredFrame = card.PreferredFrame();
- if (preferredFrame != null)
- {
- frameId = preferredFrame.FrameID;
- }
- }
- }
- else
- {
- frameId = _targetPermanent.PermanentFrame.FrameID;
- }
- if (!isJogress)
- {
- if (!(0 <= frameId && frameId < card.Owner.fieldCardFrames.Count))
- {
- foreach (FieldCardFrame fieldCardFrame in card.Owner.fieldCardFrames)
- {
- if (card.CanPlayCardTargetFrame(fieldCardFrame, false, CardEffect, isBreedingArea: _isBreedingArea))
- {
- if (fieldCardFrame.IsEmptyFrame())
- {
- frameId = fieldCardFrame.FrameID;
- break;
- }
- }
- }
- }
- if (0 <= frameId && frameId < card.Owner.fieldCardFrames.Count)
- {
- played = true;
- if (_targetPermanent != null)
- {
- isEvolution = true;
- }
- else
- {
- if (!CardEffectCommons.CanPlayAsNewPermanent(card, false, CardEffect, isBreedingArea: _isBreedingArea, isPlayOption: _isPlayOption))
- {
- played = false;
- }
- if (_isHatching)
- played = _isHatching;
- }
- if (played)
- {
- card.Init();
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- if (isEvolution)
- {
- oldLevels.Add(_targetPermanent.Level);
- PlayLog.OnAddLog?.Invoke($"\nEvolution:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- permanent = _targetPermanent;
- evoRoots.Add(_targetPermanent.TopCard);
- evoRootTops.Add(_targetPermanent.TopCard);
- permanent.AddCardSource(card);
- }
- else
- {
- if (card.IsToken)
- PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity} token\n");
- else
- PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = _isTapped };
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, frameId));
- permanent.EnterFieldTurnCount = GManager.instance.turnStateMachine.TurnCount;
- }
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- if (!isEvolution)
- {
- #region wheter to have ETB effects
- Hashtable hashtable = CardEffectCommons.OnEnterFieldHashtable(
- hashtableParams: new List<OnEnterFieldHashtableParams>()
- {
- new OnEnterFieldHashtableParams(
- permanent: permanent,
- evoRoots: evoRoots,
- evoRootTops: evoRootTops,
- root: _root,
- oldLevels: oldLevels,
- isFromDigimonDigivolutionCards:isFromDigimonDigivolutionCards,
- digiXrosCount: _digiXrosCount,
- assemblyCount: _assemblyCount
- )
- },
- isEvolution: isEvolution,
- isJogress: isJogress,
- digiXrosCount: _digiXrosCount,
- assemblyCount: _assemblyCount,
- cardEffect: CardEffect);
- bool HasETB = permanent.EffectList(EffectTiming.OnEnterFieldAnyone).Some(cardEffect =>
- cardEffect is ActivateICardEffect && cardEffect.CanUse(hashtable) && _activateETB && cardEffect.IsOnPlay);
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, HasETB: HasETB, isDigiXros: _digiXrosCount >= 1));
- }
- else
- {
- bool isBlast = CardEffect != null && CardEffect.EffectName != null && CardEffect.EffectName.Contains("Blast");
- //effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DigivolveFieldPermanentCardEffect(permanent.ShowingPermanentCard, _burstDigivolved, isBlast, _appFusion));
- }
- }
- }
- }
- }
- else
- {
- if (_jogressEvoRootsFrameIDs.Length == 2)
- {
- played = true;
- card.Init();
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- isEvolution = true;
- List<Permanent> evoRootPermanents = new List<Permanent>();
- for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
- {
- int frameID = _jogressEvoRootsFrameIDs[i];
- Permanent evoRoot = card.Owner.fieldCardFrames[frameID].GetFramePermanent();
- if (evoRoot != null)
- {
- if (evoRoot.TopCard != null)
- {
- evoRootPermanents.Add(evoRoot);
- }
- }
- }
- int targetFrameID = evoRootPermanents[0].PermanentFrame.FrameID;
- foreach (Permanent evoRootPermanent in evoRootPermanents)
- {
- evoRoots.Add(evoRootPermanent.TopCard);
- }
- List<CardSource> newDigivolutionCards = evoRootPermanents
- .Map(evoRootPermanent => evoRootPermanent.StackCards)
- .Flat();
- List<CardSource> linkCards = evoRootPermanents
- .Map(evoRootPermanent => evoRootPermanent.LinkedCards)
- .Flat();
- foreach (Permanent evoRootPermanent in evoRootPermanents)
- {
- oldLevels.Add(evoRootPermanent.Level);
- evoRootTops.Add(evoRootPermanent.TopCard);
- }
- foreach (Permanent evoRootPermanent in evoRootPermanents)
- {
- yield return ContinuousController.instance.StartCoroutine(evoRootPermanent.DiscardEvoRoots(ignoreOverflow: true, putToTrash: false));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(evoRootPermanent, ignoreOverflow: true));
- }
- foreach (CardSource linkCard in linkCards)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(linkCard));
- }
- PlayLog.OnAddLog?.Invoke($"\nJogress:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = false };
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, targetFrameID));
- permanent.EnterFieldTurnCount = -1;
- newDigivolutionCards.Reverse();
- yield return ContinuousController.instance.StartCoroutine(permanent.AddDigivolutionCardsTop(newDigivolutionCards, null));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, isDigiXros: false, jogressEvoRoots: evoRootTops.ToArray()));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(evoRootTops, "DNA Digivolution Cards", true, true));
- foreach (CardSource evolutionCard in permanent.DigivolutionCards)
- {
- evolutionCard.cEntity_EffectController.InitUseCountThisTurn();
- }
- }
- }
- if (played)
- {
- if (isFromSecurity)
- {
- yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
- player: card.Owner,
- refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
- CardEffectCommons.GetCardEffectFromHashtable(_hashtable)).ReduceSecurity());
- }
- if (isEvolution)
- {
- card.Owner.DigivolveCount_ThisTurn++;
- yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, null).Draw());
- if (_burstDigivolved)
- {
- if (permanent.TopCard != null)
- {
- permanent.IsBurstDigivolved = true;
- GManager.instance.selectBurstDigivolutionEffect.AddTrashTopCardAtTurnEnd(permanent);
- }
- }
- if (_appFusion)
- {
- if (permanent.TopCard != null)
- {
- permanent.IsAppFusion = true;
- }
- }
- permanent.CardNamesJustAfterDigivolved = permanent.TopCard.CardNames.Clone();
- permanent.DigivolvingEffect = CardEffect;
- }
- else
- {
- permanent.PlayingEffect = CardEffect;
- if (permanent.TopCard.HasLevel)
- {
- permanent.LevelJustAfterPlayed = permanent.Level;
- }
- if (permanent.TopCard.HasPlayCost)
- {
- permanent.PlayCostJustAfterPlayed = permanent.TopCard.GetCostItself;
- }
- permanent.CardNamesJustAfterPlayed = permanent.TopCard.CardNames.Clone();
- permanent.TraitsJustAfterPlayed = permanent.TopCard.CardTraits.Clone();
- }
- #region move permanents (hybrid)
- if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
- {
- if (permanent.TopCard.PreferredFrame() != null)
- {
- if (permanent.PermanentFrame != permanent.TopCard.PreferredFrame())
- {
- if (permanent.TopCard.PreferredFrame().IsEmptyFrame())
- {
- bool move = false;
- if (permanent.IsDigimon)
- {
- if (permanent.TopCard.Owner.isYou)
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
- {
- move = true;
- }
- }
- else
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
- {
- move = true;
- }
- }
- }
- else if (permanent.IsTamer || permanent.TopCard.IsOption)
- {
- if (permanent.TopCard.Owner.isYou)
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
- {
- move = true;
- }
- }
- else
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
- {
- move = true;
- }
- }
- }
- if (move)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.MovePermanent(permanent.PermanentFrame));
- }
- }
- }
- }
- }
- #endregion
- yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCardsByEffect(card);
- yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCards(card);
- yield return GManager.instance.GetComponent<SelectAssemblyClass>().AddDigivolutiuonCardsByEffect(card);
- yield return GManager.instance.GetComponent<SelectAssemblyClass>().AddDigivolutiuonCards(card);
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- hashtableParams.Add(
- new OnEnterFieldHashtableParams(
- permanent: permanent,
- evoRoots: evoRoots,
- evoRootTops: evoRootTops,
- root: _root,
- oldLevels: oldLevels,
- isFromDigimonDigivolutionCards: isFromDigimonDigivolutionCards,
- digiXrosCount: _digiXrosCount,
- assemblyCount: _assemblyCount
- )
- );
- }
- }
- GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
- GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
- GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
- }
- // except [On Play] effect
- bool CardEffectCondition(ICardEffect cardEffect)
- {
- if (cardEffect == null)
- {
- return false;
- }
- if (!_activateETB)
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.IsOnPlay)
- {
- return false;
- }
- }
- }
- return true;
- }
- Hashtable effectHashtable = CardEffectCommons.OnEnterFieldHashtable(
- hashtableParams: hashtableParams,
- isEvolution: isEvolution,
- isJogress: isJogress,
- digiXrosCount: _digiXrosCount,
- assemblyCount: _assemblyCount,
- cardEffect: CardEffect);
- #region "When permanents are played" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
- hashtable: effectHashtable,
- timing: EffectTiming.OnEnterFieldAnyone,
- cardEffectCondition: CardEffectCondition));
- #endregion
- }
- }
- #endregion
- #region Use option
- public class UseOptionClass
- {
- public UseOptionClass(List<CardSource> cardSources, Hashtable hashtable, SelectCardEffect.Root root)
- {
- if (cardSources != null)
- {
- _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
- }
- _hashtable = hashtable;
- _root = root;
- }
- List<CardSource> _cardSources = new List<CardSource>();
- SelectCardEffect.Root _root = SelectCardEffect.Root.None;
- Hashtable _hashtable = null;
- public bool _showEffect = false;
- public IEnumerator UseOption()
- {
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- foreach (CardSource card in _cardSources)
- {
- if (_showEffect)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(card));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowUseHandCardEffect_PlayCard(card));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
- }
- PlayLog.OnAddLog?.Invoke($"\nPlay Option:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- card.Init();
- card.SetFace();
- int cost = card.GetCostItself;
- //Remove from all areas
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(card));
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.BrainStormCoroutine(card));
- #region Set HashTable
- Hashtable hashtable = new Hashtable()
- {
- {"Card", card},
- {"Root", _root},
- {"Cost", cost},
- };
- #endregion
- #region "When option is used" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseOption));
- yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.OnUseOption));
- #endregion
- #region effect process of option card
- foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.OptionSkill))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanUse(hashtable))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
- cardEffect,
- hashtable));
- }
- }
- }
- #endregion
- if (card.Owner.ExecutingCards.Contains(card))
- {
- List<OptionResolutionClass> optionResolutionEffects = new List<OptionResolutionClass>();
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- #region Effects of permanents in play
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
- {
- if (cardEffect is OptionResolutionClass)
- {
- if (cardEffect.CanUse(null))
- {
- optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
- }
- }
- }
- }
- #endregion
- #region Effects on the Player
- foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
- {
- if (cardEffect is OptionResolutionClass)
- {
- if (cardEffect.CanUse(null))
- {
- optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
- }
- }
- }
- #endregion
- }
- #region effects of the card itself
- foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.None))
- {
- if (cardEffect is OptionResolutionClass)
- {
- if (cardEffect.CanUse(null))
- {
- optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
- }
- }
- }
- #endregion
- while (card.Owner.ExecutingCards.Contains(card))
- {
- List<OptionResolutionClass> possibleEffects = optionResolutionEffects.Filter(effect => effect.CanResolve(card));
- if (possibleEffects.Count() == 0)
- {
- break;
- }
- else if (possibleEffects.Count() == 1)
- {
- OptionResolutionClass currentEffect = possibleEffects[0];
- if (currentEffect != null) yield return ContinuousController.instance.StartCoroutine(currentEffect.Resolve(card));
- optionResolutionEffects.Remove(currentEffect);
- }
- else
- {
- List<SkillInfo> skillInfos = possibleEffects.Map(effect => new SkillInfo(effect, null, EffectTiming.None));
- List<CardSource> rootCardSources = skillInfos.Map(skillInfo => skillInfo.CardEffect.EffectSourceCard);
- int skillIndex = -1;
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectCardPanel.OpenSelectCardPanel(
- Message: "Option has multiple resolutions instead of going to trash.\nChoose which to process.",
- RootCardSources: rootCardSources,
- _CanTargetCondition: _ => true,
- _CanTargetCondition_ByPreSelecetedList: null,
- _CanEndSelectCondition: null,
- _MaxCount: 1,
- _CanEndNotMax: false,
- _CanNoSelect: () => false,
- CanLookReverseCard: true,
- skillInfos: skillInfos,
- root: SelectCardEffect.Root.None));
- if (GManager.instance.selectCardPanel.SelectedIndex.Count > 0)
- {
- skillIndex = GManager.instance.selectCardPanel.SelectedIndex[0];
- }
- if (skillIndex >= 0)
- {
- OptionResolutionClass currentEffect = possibleEffects[skillIndex];
- if (currentEffect != null) yield return ContinuousController.instance.StartCoroutine(currentEffect.Resolve(card));
- optionResolutionEffects.Remove(currentEffect);
- }
- else
- {
- break; // Should not happen, unless we later allow denying all by no select
- }
- }
- }
- }
- if (card.Owner.ExecutingCards.Contains(card))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(card));
- }
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- }
- }
- }
- #endregion
- #region Draw cards
- public class DrawClass
- {
- public DrawClass(Player player, int drawCount, ICardEffect cardEffect)
- {
- _player = player;
- _drawCount = drawCount;
- _cardEffect = cardEffect;
- }
- Player _player = null;
- int _drawCount = 0;
- ICardEffect _cardEffect = null;
- public IEnumerator Draw()
- {
- if (_drawCount <= 0) yield break;
- if (_player.LibraryCards.Count <= 0) yield break;
- List<CardSource> DrawCards = new List<CardSource>();
- for (int i = 0; i < _drawCount; i++)
- {
- if (_player.LibraryCards.Count > 0)
- {
- CardSource DrawCard = _player.LibraryCards[0];
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(DrawCard));
- DrawCards.Add(DrawCard);
- }
- }
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(DrawCards, true, _cardEffect));
- #region add log
- if (DrawCards.Count >= 1)
- {
- PlayLog.OnAddLog?.Invoke($"\nDraw {DrawCards.Count} card{Utils.PluralFormSuffix(DrawCards.Count)}\n{_player.PlayerName}\n");
- }
- #endregion
- #region "When draw cards" effect
- if (DrawCards.Count >= 1)
- {
- #region Hashtable setting
- Hashtable _hashtable = new Hashtable()
- {
- {"Player", _player},
- {"CardEffect", _cardEffect}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnDraw));
- }
- #endregion
- }
- }
- #endregion
- #region Trash cards from deck too
- public class IAddTrashCardsFromLibraryTop
- {
- public IAddTrashCardsFromLibraryTop(int addTrashCount, Player player, ICardEffect cardEffect)
- {
- _addTrashCount = addTrashCount;
- _player = player;
- _cardEffect = cardEffect;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- int _addTrashCount;
- Player _player;
- public List<CardSource> discardedCards = new List<CardSource>();
- ICardEffect _cardEffect { get; set; } = null;
- bool _notShowCards = false;
- public IEnumerator AddTrashCardsFromLibraryTop()
- {
- if (_addTrashCount <= 0) yield break;
- if (_player.LibraryCards.Count == 0) yield break;
- string log = "";
- log += $"\nTrash cards from deck :";
- for (int i = 0; i < _addTrashCount; i++)
- {
- if (_player.LibraryCards.Count > i)
- {
- CardSource DiscardCard = _player.LibraryCards[i];
- discardedCards.Add(DiscardCard);
- log += $"\n{DiscardCard.BaseENGCardNameFromEntity}({DiscardCard.CardID})";
- }
- }
- if (discardedCards.Count >= 1)
- {
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
- }
- }
- yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(discardedCards, _cardEffect).TrashDeckCards());
- if (discardedCards.Count >= 1)
- {
- for (int i = 0; i < discardedCards.Count; i++)
- {
- ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
- yield return new WaitForSeconds(0.06f);
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- }
- }
- #endregion
- #region Add security from deck top
- public class IAddSecurityFromLibrary
- {
- public IAddSecurityFromLibrary(Player player, int addLifeCount)
- {
- _player = player;
- _addSecurityCount = addLifeCount;
- }
- Player _player = null;
- int _addSecurityCount = 0;
- public IEnumerator AddSecurity()
- {
- int count = 0;
- for (int i = 0; i < _addSecurityCount; i++)
- {
- if (_player.LibraryCards.Count > 0)
- {
- CardSource StockCard = _player.LibraryCards[0];
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(StockCard, useEffect: (i == 0)));
- count++;
- }
- }
- if (count > 0)
- {
- string log = "";
- log += $"\nAdd {count} cards to security:{_player.PlayerName}";
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- }
- }
- #endregion
- #region Recovery
- public class IRecovery
- {
- public IRecovery(Player player, int AddLifeCount, ICardEffect cardEffect)
- {
- _player = player;
- _addLifeCount = AddLifeCount;
- _cardEffect = cardEffect;
- }
- Player _player = null;
- int _addLifeCount = 0;
- ICardEffect _cardEffect = null;
- public IEnumerator Recovery()
- {
- if (_player.LibraryCards.Count == 0) yield break;
- if (_addLifeCount <= 0) yield break;
- if (!_player.CanAddSecurity(_cardEffect)) yield break;
- yield return ContinuousController.instance.StartCoroutine(new IAddSecurityFromLibrary(_player, _addLifeCount).AddSecurity());
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(_player));
- }
- }
- #endregion
- #region Digi-Burst
- public class IDigiBurst
- {
- public IDigiBurst(Permanent permanent, int DigiBurstCount, ICardEffect cardEffect)
- {
- _permanent = permanent;
- _digiBurstCount = DigiBurstCount;
- _cardEffect = cardEffect;
- }
- Permanent _permanent = null;
- int _digiBurstCount = 0;
- ICardEffect _cardEffect = null;
- bool _upToMaxCount = false;
- public List<CardSource> discardedCards = new List<CardSource>();
- public void SetUpToMaxCount()
- {
- _upToMaxCount = true;
- }
- public bool CanDigiBurst()
- {
- if (_permanent != null)
- {
- if (_permanent.TopCard != null)
- {
- if (_permanent.ImmuneFromStackTrashing(_cardEffect)) return false;
- if (_upToMaxCount)
- {
- if (_permanent.DigivolutionCards.Some((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)))
- {
- return true;
- }
- }
- else
- {
- if (_permanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)) >= _digiBurstCount)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- public IEnumerator DigiBurst()
- {
- if (CanDigiBurst())
- {
- discardedCards = new List<CardSource>();
- List<CardSource> selectedCards = new List<CardSource>();
- SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
- selectCardEffect.SetUp(
- canTargetCondition: (cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect),
- canTargetCondition_ByPreSelecetedList: null,
- canEndSelectCondition: CanEndSelectCondition,
- canNoSelect: () => false,
- selectCardCoroutine: SelectCardCoroutine,
- afterSelectCardCoroutine: null,
- message: "Select digivolution cards to discard.",
- maxCount: _digiBurstCount,
- canEndNotMax: _upToMaxCount,
- isShowOpponent: true,
- mode: SelectCardEffect.Mode.Custom,
- root: SelectCardEffect.Root.Custom,
- customRootCardList: _permanent.DigivolutionCards,
- canLookReverseCard: true,
- selectPlayer: _permanent.TopCard.Owner,
- cardEffect: null);
- selectCardEffect.SetUseFaceDown();
- selectCardEffect.SetUpCustomMessage("Select digivolution cards to discard.", "The opponent is selecting digivolution cards to discard.");
- yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
- bool CanEndSelectCondition(List<CardSource> cardSources)
- {
- if (CardEffectCommons.HasNoElement(cardSources))
- {
- return false;
- }
- return true;
- }
- IEnumerator SelectCardCoroutine(CardSource cardSource)
- {
- selectedCards.Add(cardSource);
- yield return null;
- }
- if (selectedCards.Count >= 1)
- {
- #region "When use Digi-Burst" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"Permanent", _permanent},
- {"CardEffect", _cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseDigiburst));
- #endregion
- // trash digivolution cards
- yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(_permanent, selectedCards, _cardEffect).TrashDigivolutionCards());
- foreach (CardSource cardSource in selectedCards)
- {
- discardedCards.Add(cardSource);
- }
- #region add log
- if (selectedCards.Count >= 1)
- {
- string log = "";
- log += $"\nDigiburst :";
- foreach (CardSource cardSource in selectedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- }
- }
- #endregion
- #region Place permanents to deck bottom
- public class DeckBottomBounceClass
- {
- public DeckBottomBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
- {
- _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
- _hashtable = hashtable;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- public bool IsDeckBounced(Permanent permanent)
- {
- return DeckBouncedPermanents.Contains(permanent);
- }
- List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
- public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
- Hashtable _hashtable = new Hashtable();
- bool _notShowCards = false;
- public IEnumerator DeckBounce()
- {
- if (_deckBounceTargetPermanents == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && (cardEffect == null ||
- (!permanent.TopCard.CanNotBeAffected(cardEffect)
- && !permanent.CannotReturnToLibrary(cardEffect)
- && permanent.CanBeRemoved())));
- if (_deckBounceTargetPermanents.Count == 0) yield break;
- _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
- #region cut in effect
- // "When permanents would return to deck" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _deckBounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenReturntoLibraryAnyone));
- // "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _deckBounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- permanent.ShowDeckBounceEffect();
- }
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- permanent.HideDeckBounceEffect();
- }
- }
- #endregion
- // fix deck bounce target permanents
- List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && permanent.willBeRemoveField);
- #region show cards
- List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
- }
- #endregion
- #region "When permanents leave the battle area" effect
- if (deckBounceTargetPermanents_Fixed.Count > 0) yield return ContinuousController.instance.StartCoroutine(
- GManager.instance.autoProcessing.StackSkillInfos(
- CardEffectCommons.OnDeletionHashtable(
- deckBounceTargetPermanents_Fixed,
- cardEffect,
- null,
- false
- ),
- EffectTiming.OnLeaveFieldAnyone));
- #endregion
- #region
- List<CardSource> deckBottomCards = new List<CardSource>();
- foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
- {
- #region recoed used effect
- if (permanent.TopCard != null)
- {
- permanent.LibraryBounceEffect = cardEffect;
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
- yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
- CardSource topCard = permanent.TopCard;
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
- deckBottomCards.Add(topCard);
- DeckBouncedPermanents.Add(permanent);
- }
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(deckBottomCards));
- #endregion
- #region off icon
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- permanent.willBeRemoveField = false;
- }
- }
- }
- #endregion
- }
- }
- #endregion
- #region Place permanents to deck top
- public class DeckTopBounceClass
- {
- public DeckTopBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
- {
- _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
- _hashtable = hashtable;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- public bool IsDeckBounced(Permanent permanent)
- {
- return DeckBouncedPermanents.Contains(permanent);
- }
- List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
- public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
- Hashtable _hashtable = new Hashtable();
- bool _notShowCards = false;
- public IEnumerator DeckBounce()
- {
- if (_deckBounceTargetPermanents == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && (cardEffect == null ||
- (!permanent.TopCard.CanNotBeAffected(cardEffect)
- && !permanent.CannotReturnToLibrary(cardEffect)
- && permanent.CanBeRemoved())));
- if (_deckBounceTargetPermanents.Count == 0) yield break;
- _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
- #region cut in effect
- // "When permanents would return to deck" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _deckBounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenReturntoLibraryAnyone));
- // "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _deckBounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- permanent.ShowDeckBounceEffect();
- }
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- permanent.HideDeckBounceEffect();
- }
- }
- #endregion
- // fix deck bounce target permanents
- List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && permanent.willBeRemoveField);
- #region show cards
- List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
- }
- #endregion
- #region "When permanents leave the battle area" effect
- if (deckBounceTargetPermanents_Fixed.Count > 0) yield return ContinuousController.instance.StartCoroutine(
- GManager.instance.autoProcessing.StackSkillInfos(
- CardEffectCommons.OnDeletionHashtable(
- deckBounceTargetPermanents_Fixed,
- cardEffect,
- null,
- false
- ),
- EffectTiming.OnLeaveFieldAnyone));
- #endregion
- #region
- List<CardSource> deckTopCards = new List<CardSource>();
- foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
- {
- #region recoed used effect
- if (permanent.TopCard != null)
- {
- permanent.LibraryBounceEffect = cardEffect;
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
- yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
- CardSource topCard = permanent.TopCard;
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
- deckTopCards.Add(topCard);
- DeckBouncedPermanents.Add(permanent);
- }
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryTopCards(deckTopCards));
- #endregion
- #region off icon
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- permanent.willBeRemoveField = false;
- }
- }
- }
- #endregion
- }
- }
- #endregion
- #region Return permanent to hand
- public class HandBounceClaass
- {
- public HandBounceClaass(List<Permanent> bounceTargetPermanents, Hashtable hashtable)
- {
- _bounceTargetPermanents = bounceTargetPermanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
- _hashtable = hashtable;
- }
- public bool IsBounced(Permanent permanent)
- {
- return BouncedPermanents.Contains(permanent);
- }
- List<Permanent> _bounceTargetPermanents = new List<Permanent>();
- public List<Permanent> BouncedPermanents { get; private set; } = new List<Permanent>();
- Hashtable _hashtable = new Hashtable();
- bool _notShowCards = false;
- public IEnumerator Bounce()
- {
- if (_bounceTargetPermanents == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- _bounceTargetPermanents = _bounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && (cardEffect == null ||
- (!permanent.TopCard.CanNotBeAffected(cardEffect)
- && !permanent.CannotReturnToHand(cardEffect)
- && permanent.CanBeRemoved())));
- if (_bounceTargetPermanents.Count == 0) yield break;
- _bounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
- #region cut in effect
- // "When permanents would return to hand" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _bounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenReturntoHandAnyone));
- // "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _bounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- foreach (Permanent permanent in _bounceTargetPermanents)
- {
- permanent.ShowHandBounceEffect();
- }
- // shrink security Digimon display
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent permanent in _bounceTargetPermanents)
- {
- permanent.HideHandBounceEffect();
- }
- }
- #endregion
- // fix bounce target permanents
- List<Permanent> bounceTargetPermanents_Fixed = _bounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && permanent.willBeRemoveField);
- #region "When permanents returned to hand" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
- .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
- bounceTargetPermanents_Fixed,
- cardEffect,
- null,
- false
- ),
- EffectTiming.OnPermamemtReturnedToHand));
- #endregion
- #region "When permanents leave the battle area" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
- CardEffectCommons.OnDeletionHashtable(
- bounceTargetPermanents_Fixed,
- cardEffect,
- null,
- false
- ),
- EffectTiming.OnLeaveFieldAnyone));
- #endregion
- #region record parameter just before bounce
- foreach (Permanent permanent in bounceTargetPermanents_Fixed)
- {
- permanent.DPJustBeforeRemoveField = permanent.DP;
- if (permanent.TopCard.HasLevel)
- {
- permanent.LevelJustBeforeRemoveField = permanent.Level;
- }
- if (permanent.TopCard.HasPlayCost)
- {
- permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
- }
- permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
- permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
- foreach (CardSource cardSource in permanent.cardSources)
- {
- cardSource.PermanentJustBeforeRemoveField = permanent;
- }
- }
- #endregion
- #region add log
- if (bounceTargetPermanents_Fixed.Count >= 1)
- {
- string log = "";
- log += $"\nReturn to hand:";
- foreach (Permanent permanent in bounceTargetPermanents_Fixed)
- {
- log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- #region show cards
- List<CardSource> returnedCards = bounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Cards returned to hand", true, true));
- }
- #endregion
- #region return permanent cards to hand
- List<CardSource> handCards = new List<CardSource>();
- foreach (Permanent permanent in bounceTargetPermanents_Fixed)
- {
- #region record used effect
- if (permanent.TopCard != null)
- {
- permanent.HandBounceEffect = cardEffect;
- }
- #endregion
- // record whether to return to hand by Burst Digivolution
- permanent.IsReturnedToHandByBurstDigivolution = CardEffectCommons.IsBurst(_hashtable);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BounceEffect(permanent, !permanent.IsReturnedToHandByBurstDigivolution));
- yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
- CardSource topCard = permanent.TopCard;
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(topCard));
- if (!topCard.IsDigiEgg)
- {
- handCards.Add(topCard);
- BouncedPermanents.Add(permanent);
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
- }
- }
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
- #endregion
- #region hide icon
- foreach (Permanent permanent in _bounceTargetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- permanent.willBeRemoveField = false;
- }
- }
- }
- #endregion
- }
- }
- #endregion
- #region Place permanent to another permanent's digivolution cards
- public class IPlacePermanentToDigivolutionCards
- {
- public IPlacePermanentToDigivolutionCards(
- List<Permanent[]> permanentArrays,
- bool toTop,
- ICardEffect cardEffect,
- bool skipEffectAndActivateSkill = false,
- bool isDigixros = false)
- {
- permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
- _toTop = toTop;
- _cardEffect = cardEffect;
- _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
- _isDigixros = isDigixros;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- List<Permanent[]> _permanentArrays = new List<Permanent[]>();
- ICardEffect _cardEffect = null;
- bool _toTop = false;
- bool _notShowCards = false;
- bool _skipEffectAndActivateSkill = false;
- bool _isDigixros = false;
- public bool Placed { get; private set; } = false;
- public IEnumerator PlacePermanentToDigivolutionCards()
- {
- if (_permanentArrays.Count == 0)
- {
- yield break;
- }
- List<CardSource> addedDigivolutionCards = new List<CardSource>();
- List<Permanent> removeFieldPermanents = new List<Permanent>();
- foreach (Permanent[] permanentArray in _permanentArrays)
- {
- if (permanentArray.Length == 2)
- {
- Permanent DigivolutionPermanent = permanentArray[0];
- Permanent getDigivolutionPermanent = permanentArray[1];
- if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
- {
- if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
- {
- if (_cardEffect != null)
- {
- if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
- {
- continue;
- }
- }
- removeFieldPermanents.Add(DigivolutionPermanent);
- }
- }
- }
- }
- foreach (Permanent permanent in removeFieldPermanents)
- {
- permanent.willBeRemoveField = true;
- }
- if (removeFieldPermanents.Count == 0)
- {
- yield break;
- }
- #region
- List<SkillInfo> skillInfos = new List<SkillInfo>();
- Hashtable hashtable1 =
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- removeFieldPermanents,
- _cardEffect,
- null,
- _isDigixros);
- #region "When permanents would remove field" effect
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- #region permanents' effects
- foreach (Permanent permanent1 in player.GetFieldPermanents())
- {
- foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanTrigger(hashtable1))
- {
- skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
- }
- }
- }
- }
- #endregion
- #region players' effects
- foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanTrigger(hashtable1))
- {
- skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
- }
- }
- }
- #endregion
- }
- #endregion
- if (skillInfos.Count >= 1)
- {
- foreach (SkillInfo skillInfo in skillInfos)
- {
- GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
- }
- bool showEffect()
- {
- if (skillInfos.Count >= 2)
- {
- return true;
- }
- else if (skillInfos.Count == 1)
- {
- if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
- {
- return true;
- }
- }
- return false;
- }
- if (showEffect())
- {
- foreach (Permanent Permanent in removeFieldPermanents)
- {
- if (Permanent != null)
- {
- if (Permanent.TopCard != null)
- {
- if (Permanent.willBeRemoveField)
- {
- if (Permanent.ShowingPermanentCard != null)
- {
- if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
- {
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
- }
- }
- }
- }
- }
- }
- #region shrink security Digimon display
- if (GManager.instance.attackProcess.IsAttacking)
- {
- if (GManager.instance.attackProcess.SecurityDigimon != null)
- {
- if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
- }
- }
- }
- #endregion
- }
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent Permanent in removeFieldPermanents)
- {
- if (Permanent != null)
- {
- if (Permanent.TopCard != null)
- {
- if (Permanent.ShowingPermanentCard != null)
- {
- if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
- {
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
- }
- }
- }
- }
- }
- }
- #endregion
- foreach (Permanent[] permanentArray in _permanentArrays)
- {
- if (permanentArray.Length == 2)
- {
- Permanent DigivolutionPermanent = permanentArray[0];
- Permanent getDigivolutionPermanent = permanentArray[1];
- if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
- {
- if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
- {
- yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
- CardSource cardSource = DigivolutionPermanent.TopCard;
- #region record used effect
- if (_cardEffect != null)
- {
- if (DigivolutionPermanent.TopCard != null)
- {
- DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
- }
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
- DigivolutionPermanent,
- ignoreOverflow: true));
- List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
- if (_toTop)
- {
- yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
- }
- cardSource.cEntity_EffectController.InitUseCountThisTurn();
- addedDigivolutionCards.Add(cardSource);
- Placed = true;
- }
- }
- }
- }
- #region add log
- if (addedDigivolutionCards.Count >= 1)
- {
- string log = "";
- log += $"\nPlace in digivolution cards:";
- foreach (CardSource cardSource in addedDigivolutionCards)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- #region hide icon
- if (addedDigivolutionCards.Count >= 1)
- {
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
- }
- }
- #endregion
- }
- }
- #endregion
- #region Place permanent to another permanent's Link cards
- public class IPlacePermanentToLinkCards
- {
- public IPlacePermanentToLinkCards(
- List<Permanent[]> permanentArrays,
- ICardEffect cardEffect,
- bool skipEffectAndActivateSkill = false)
- {
- permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
- _cardEffect = cardEffect;
- _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- List<Permanent[]> _permanentArrays = new List<Permanent[]>();
- ICardEffect _cardEffect = null;
- bool _notShowCards = false;
- bool _skipEffectAndActivateSkill = false;
- public bool Placed { get; private set; } = false;
- public IEnumerator PlacePermanentToLinkCards()
- {
- if (_permanentArrays.Count == 0)
- {
- yield break;
- }
- List<CardSource> addedLinkCards = new List<CardSource>();
- List<Permanent> removeFieldPermanents = new List<Permanent>();
- foreach (Permanent[] permanentArray in _permanentArrays)
- {
- if (permanentArray.Length == 2)
- {
- Permanent LinkedPermanent = permanentArray[0];
- Permanent getLinkPermanent = permanentArray[1];
- if (LinkedPermanent != null && getLinkPermanent != null)
- {
- if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken)
- {
- if (_cardEffect != null)
- {
- if (LinkedPermanent.TopCard.CanNotBeAffected(_cardEffect) || getLinkPermanent.TopCard.CanNotBeAffected(_cardEffect))
- {
- continue;
- }
- }
- removeFieldPermanents.Add(LinkedPermanent);
- }
- }
- }
- }
- foreach (Permanent permanent in removeFieldPermanents)
- {
- permanent.willBeRemoveField = true;
- }
- if (removeFieldPermanents.Count == 0)
- {
- yield break;
- }
- #region Cut in Effects
- List<SkillInfo> skillInfos = new List<SkillInfo>();
- Hashtable hashtable1 =
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- removeFieldPermanents,
- _cardEffect,
- null);
- #region "When permanents would remove field" effect
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- #region permanents' effects
- foreach (Permanent permanent1 in player.GetFieldPermanents())
- {
- foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanTrigger(hashtable1))
- {
- skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
- }
- }
- }
- }
- #endregion
- #region players' effects
- foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanTrigger(hashtable1))
- {
- skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
- }
- }
- }
- #endregion
- }
- #endregion
- if (skillInfos.Count >= 1)
- {
- foreach (SkillInfo skillInfo in skillInfos)
- {
- GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
- }
- bool showEffect()
- {
- if (skillInfos.Count >= 2)
- {
- return true;
- }
- else if (skillInfos.Count == 1)
- {
- if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
- {
- return true;
- }
- }
- return false;
- }
- if (showEffect())
- {
- foreach (Permanent Permanent in removeFieldPermanents)
- {
- if (Permanent != null)
- {
- if (Permanent.TopCard != null)
- {
- if (Permanent.willBeRemoveField)
- {
- if (Permanent.ShowingPermanentCard != null)
- {
- if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
- {
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
- }
- }
- }
- }
- }
- }
- #region shrink security Digimon display
- if (GManager.instance.attackProcess.IsAttacking)
- {
- if (GManager.instance.attackProcess.SecurityDigimon != null)
- {
- if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
- }
- }
- }
- #endregion
- }
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent Permanent in removeFieldPermanents)
- {
- if (Permanent != null)
- {
- if (Permanent.TopCard != null)
- {
- if (Permanent.ShowingPermanentCard != null)
- {
- if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
- {
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
- }
- }
- }
- }
- }
- }
- #endregion
- foreach (Permanent[] permanentArray in _permanentArrays)
- {
- if (permanentArray.Length == 2)
- {
- Permanent LinkedPermanent = permanentArray[0];
- Permanent getLinkPermanent = permanentArray[1];
- if (LinkedPermanent != null && getLinkPermanent != null)
- {
- if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken && LinkedPermanent.willBeRemoveField)
- {
- #region "When permanents leave the battle area" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
- CardEffectCommons.OnDeletionHashtable(
- new List<Permanent> { LinkedPermanent },
- _cardEffect,
- null,
- false
- ),
- EffectTiming.OnLeaveFieldAnyone));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(LinkedPermanent.DiscardEvoRoots());
- CardSource cardSource = LinkedPermanent.TopCard;
- #region record used effect
- if (_cardEffect != null)
- {
- if (LinkedPermanent.TopCard != null)
- {
- LinkedPermanent.PlaceOtherPermanentEffect = _cardEffect;
- }
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
- LinkedPermanent,
- ignoreOverflow: true));
- yield return ContinuousController.instance.StartCoroutine(getLinkPermanent.AddLinkCard(cardSource, _cardEffect));
- cardSource.cEntity_EffectController.InitUseCountThisTurn();
- addedLinkCards.Add(cardSource);
- Placed = true;
- }
- }
- }
- }
- #region add log
- if (addedLinkCards.Count >= 1)
- {
- string log = "";
- log += $"\nLink cards:";
- foreach (CardSource cardSource in addedLinkCards)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- #region hide icon
- if (addedLinkCards.Count >= 1)
- {
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedLinkCards, "Link Cards", true, true));
- }
- }
- #endregion
- }
- }
- #endregion
- #region Link a Card to a Permanent
- public class ILinkCard
- {
- public ILinkCard(bool payCost, CardSource card, Permanent permanent, ICardEffect cardEffect)
- {
- _payCost = payCost;
- _linkCard = card;
- _permanent = permanent;
- _cardEffect = cardEffect;
- }
- bool _payCost = false;
- CardSource _linkCard = null;
- Permanent _permanent = null;
- ICardEffect _cardEffect = null;
- public bool WasLinked = false;
- public IEnumerator LinkCard()
- {
- if (_linkCard == null) yield break;
- if (_permanent == null || _permanent.TopCard == null) yield break;
- if (_cardEffect == null) yield break;
- #region Trigger When Would Link effects
- SelectCardEffect.Root root;
- if (CardEffectCommons.IsExistOnHand(_linkCard))
- root = SelectCardEffect.Root.Hand;
- else if (CardEffectCommons.IsExistInAnyTrash(_linkCard))
- root = SelectCardEffect.Root.Trash;
- else if (CardEffectCommons.IsExistDigivolutionCards(_linkCard))
- root = SelectCardEffect.Root.DigivolutionCards;
- else if (CardEffectCommons.IsExistLinked(_linkCard))
- root = SelectCardEffect.Root.LinkedCards;
- else
- root = SelectCardEffect.Root.None;
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WouldLinkHashtable(_linkCard, _permanent, root, null),
- EffectTiming.WhenWouldLink));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- #endregion
- if (_payCost)
- {
- int Cost = _linkCard.GetChangedLinkCost(_permanent, root);
- yield return ContinuousController.instance.StartCoroutine(_linkCard.Owner.AddMemory(-1 * Cost, _cardEffect));
- }
- if (root == SelectCardEffect.Root.None)
- yield return ContinuousController.instance.StartCoroutine(new IPlacePermanentToLinkCards(new List<Permanent[]>() { new Permanent[] { _linkCard.PermanentOfThisCard(), _permanent } }, _cardEffect).PlacePermanentToLinkCards());
- else
- yield return ContinuousController.instance.StartCoroutine(_permanent.AddLinkCard(_linkCard, _cardEffect));
- WasLinked = _permanent.LinkedCards.Contains(_linkCard);
- _linkCard.Owner.UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
- }
- }
- #endregion
- #region Place permanents to security
- public class IPutSecurityPermanent
- {
- public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop, bool isFaceup = false)
- {
- _permanent = permanent;
- _hashtable = hashtable;
- _toTop = toTop;
- _isFaceup = isFaceup;
- }
- Permanent _permanent = null;
- Hashtable _hashtable = new Hashtable();
- bool _toTop = false;
- bool _isFaceup = false;
- public bool IsPlacedSecurity = false;
- public IEnumerator PutSecurity()
- {
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
- if (!_permanent.CanBeRemoved()) yield break;
- _permanent.willBeRemoveField = true;
- #region "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- new List<Permanent>() { _permanent },
- cardEffect,
- null
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- _permanent.ShowWillRemoveFieldEffect();
- //effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- _permanent.HideWillRemoveFieldEffect();
- }
- #endregion
- CardSource topCard = _permanent.TopCard;
- if (!_permanent.willBeRemoveField)
- yield break;
- if (topCard == null)
- yield break;
- #region add log
- string log = "";
- string fromString = _toTop ? "top" : "bottom";
- log += $"\nPut cards on {fromString} of security:";
- log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- #endregion
- IsPlacedSecurity = true;
- #region show cards
- if (!topCard.IsToken)
- {
- if (_toTop)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
- }
- }
- #endregion
- #region "When permanents leave the battle area" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
- CardEffectCommons.OnDeletionHashtable(
- new List<Permanent> { _permanent },
- cardEffect,
- null,
- false
- ),
- EffectTiming.OnLeaveFieldAnyone));
- #endregion
- #region place permanent to security
- yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
- if (!topCard.IsToken)
- {
- if (!topCard.IsDigiEgg)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard, faceUp: _isFaceup));
- if (!_isFaceup)
- topCard.SetReverse();
- else
- topCard.SetFace();
- if (!_toTop)
- {
- topCard.Owner.SecurityCards.Remove(topCard);
- topCard.Owner.SecurityCards.Add(topCard);
- }
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
- yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard).AddSecurity());
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
- }
- }
- #endregion
- }
- }
- #endregion
- #region Delete permanents
- public class DestroyPermanentsClass
- {
- public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
- {
- _destroytargetPermanents = destroyTargetPermanents.Clone();
- _hashtable = hashtable;
- _notShowCards = notShowCards;
- }
- public bool IsDestroyed(Permanent permanent)
- {
- return DestroyedPermanents.Contains(permanent);
- }
- List<Permanent> _destroytargetPermanents = new List<Permanent>();
- public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
- Hashtable _hashtable = null;
- bool _notShowCards = false;
- public IEnumerator Destroy()
- {
- if (_destroytargetPermanents == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
- bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
- _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && (cardEffect == null ||
- (!permanent.TopCard.CanNotBeAffected(cardEffect)
- && permanent.CanBeDestroyedBySkill(cardEffect))));
- if (_destroytargetPermanents.Count == 0) yield break;
- _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
- #region cut in effect
- // "When permanents would be deleted" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _destroytargetPermanents,
- cardEffect,
- battle
- ),
- EffectTiming.WhenPermanentWouldBeDeleted));
- // "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _destroytargetPermanents,
- cardEffect,
- battle
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- foreach (Permanent permanent in _destroytargetPermanents)
- {
- permanent.ShowDeleteEffect();
- }
- // effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent permanent in _destroytargetPermanents)
- {
- permanent.HideDeleteEffect();
- }
- }
- #endregion
- // fix delete target permanents
- List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && permanent.willBeRemoveField);
- #region "When permanents are deleted" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
- .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
- destroyTargetPermanents_Fixed,
- cardEffect,
- battle,
- isDPZero
- ),
- EffectTiming.OnDestroyedAnyone));
- #endregion
- #region "When permanents leave the battle area" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
- CardEffectCommons.OnDeletionHashtable(
- destroyTargetPermanents_Fixed,
- cardEffect,
- battle,
- isDPZero
- ),
- EffectTiming.OnLeaveFieldAnyone));
- #endregion
- #region record parameters just before deletion
- foreach (Permanent permanent in destroyTargetPermanents_Fixed)
- {
- permanent.DPJustBeforeRemoveField = permanent.DP;
- if (permanent.TopCard.HasLevel)
- {
- permanent.LevelJustBeforeRemoveField = permanent.Level;
- }
- if (permanent.TopCard.HasPlayCost)
- {
- permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
- }
- permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
- permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
- foreach (CardSource cardSource in permanent.cardSources)
- {
- cardSource.PermanentJustBeforeRemoveField = permanent;
- }
- }
- #endregion
- #region add log
- if (destroyTargetPermanents_Fixed.Count >= 1)
- {
- string log = "";
- log += $"\nDelete:";
- foreach (Permanent permanent in destroyTargetPermanents_Fixed)
- {
- log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- #region show cards
- List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
- }
- #endregion
- #region trash permanent cards
- foreach (Permanent permanent in destroyTargetPermanents_Fixed)
- {
- #region record wheter to be deleted by battle
- if (battle != null)
- {
- if (permanent.TopCard != null)
- {
- if (CardEffectCommons.GetLoserPermanentsFromHashtable(battle.hashtable).Contains(permanent))
- permanent.IsDestroyedByBattle = true;
- }
- }
- #endregion
- #region record used effect
- if (permanent.TopCard != null)
- {
- permanent.DestroyingEffect = cardEffect;
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
- yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
- CardSource topCard = permanent.TopCard;
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
- DestroyedPermanents.Add(permanent);
- }
- #endregion
- #region hide icon
- foreach (Permanent permanent in _destroytargetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- permanent.willBeRemoveField = false;
- }
- }
- }
- #endregion
- }
- }
- #endregion
- #region Security check
- public class ISecurityCheck
- {
- public ISecurityCheck(Permanent AttackingPermanent, Player player)
- {
- this.AttackingPermanent = AttackingPermanent;
- this.player = player;
- }
- Permanent AttackingPermanent { get; set; }
- Player player { get; set; }
- public IEnumerator SecurityCheck()
- {
- bool StopSecurityCheck()
- {
- if (AttackingPermanent == null)
- {
- return true;
- }
- if (AttackingPermanent.TopCard == null)
- {
- return true;
- }
- if (!AttackingPermanent.IsDigimon)
- return true;
- return false;
- }
- if (!StopSecurityCheck())
- {
- if (AttackingPermanent.Strike == 0)
- {
- yield break;
- }
- GManager.instance.turnStateMachine.IsSelecting = true;
- GManager.instance.turnStateMachine.isSecurityCehck = true;
- #region loop while there are 1 or more security cards
- if (player.SecurityCards.Count >= 1)
- {
- int checkedCount = 0;
- while (true)
- {
- if (StopSecurityCheck())
- {
- break;
- }
- if (checkedCount >= AttackingPermanent.Strike)
- {
- break;
- }
- if (player.SecurityCards.Count >= 1)
- {
- List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
- CardSource brokenSecurityCard = player.SecurityCards[0];
- bool isFaceDown = brokenSecurityCard.IsFlipped;
- Hashtable hashtable = new Hashtable()
- {
- {"AttackingPermanent", AttackingPermanent},
- {"Card", brokenSecurityCard}
- };
- foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
- {
- triggeredSkillInfos.Add(skillInfo);
- }
- checkedCount++;
- PlayLog.OnAddLog?.Invoke($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
- if (brokenSecurityCard.IsDigimon)
- {
- GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
- }
- #region effect
- player.securityObject.securityBreakGlass.ShowBlueMatarial();
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
- yield return new WaitForSeconds(0.1f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
- yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
- player: brokenSecurityCard.Owner,
- refSkillInfos: ref triggeredSkillInfos,
- null).ReduceSecurity());
- #region security effect
- List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
- foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
- {
- if (cardEffect is ActivateICardEffect)
- {
- Hashtable hashtable1 = new Hashtable();
- hashtable1.Add("Card", brokenSecurityCard);
- hashtable1.Add("isFaceDown", isFaceDown);
- if (cardEffect.CanUse(hashtable1))
- {
- secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
- }
- }
- }
- List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
- bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
- if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
- {
- if (!brokenSecurityCard.IsDigimon)
- {
- yield return new WaitForSeconds(0.3f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
- }
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
- yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
- List<SkillInfo> skillInfos = new List<SkillInfo>();
- foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
- {
- skillInfos.Add(skillInfo);
- }
- List<CardSource> cardSources = new List<CardSource>();
- for (int j = 0; j < skillInfos.Count; j++)
- {
- cardSources.Add(brokenSecurityCard);
- }
- while (skillInfos.Count >= 1)
- {
- SkillInfo selectedSkillInfo = null;
- if (skillInfos.Count == 1)
- {
- selectedSkillInfo = skillInfos[0];
- }
- else
- {
- SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
- selectCardEffect.SetUp(
- canTargetCondition: (cardSource) => true,
- canTargetCondition_ByPreSelecetedList: null,
- canEndSelectCondition: null,
- canNoSelect: () => false,
- selectCardCoroutine: null,
- afterSelectCardCoroutine: null,
- message: "select security effect",
- maxCount: 1,
- canEndNotMax: false,
- isShowOpponent: false,
- mode: SelectCardEffect.Mode.Custom,
- root: SelectCardEffect.Root.Custom,
- customRootCardList: cardSources,
- canLookReverseCard: true,
- selectPlayer: player,
- cardEffect: null);
- selectCardEffect.SetUpSkillInfos(skillInfos);
- selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
- selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
- yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
- IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
- {
- if (selectedIndexes.Count == 1)
- {
- selectedSkillInfo = skillInfos[selectedIndexes[0]];
- yield return null;
- }
- }
- }
- if (selectedSkillInfo != null)
- {
- ICardEffect cardEffect = selectedSkillInfo.CardEffect;
- Hashtable hashtable2 = selectedSkillInfo.Hashtable;
- if (cardEffect.EffectSourceCard == brokenSecurityCard)
- {
- if (cardEffect is ActivateICardEffect)
- {
- skillInfos.Remove(selectedSkillInfo);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
- cardEffect,
- hashtable2));
- }
- }
- }
- }
- }
- #endregion
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- // stack effect of "When cards are removed from security" and "checks secuirty"
- foreach (SkillInfo skillInfo in triggeredSkillInfos)
- {
- GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
- }
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- if (!StopSecurityCheck())
- {
- #region battle with security Digimon
- if (brokenSecurityCard.IsDigimon)
- {
- bool doBattle = true;
- #region "ignore battle" effect
- Hashtable hashtable3 = new Hashtable()
- {
- {"Card", brokenSecurityCard}
- };
- #region the security Digimon's effect
- foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
- {
- if (cardEffect is IDontBattleSecurityDigimonEffect)
- {
- if (cardEffect.CanUse(hashtable3))
- {
- if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
- {
- doBattle = false;
- }
- }
- }
- }
- #endregion
- #region player's effect
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
- {
- if (cardEffect is IDontBattleSecurityDigimonEffect)
- {
- if (cardEffect.CanUse(hashtable3))
- {
- if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
- {
- doBattle = false;
- }
- }
- }
- }
- }
- #endregion
- #endregion
- if (doBattle)
- {
- yield return new WaitForSeconds(0.3f);
- yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
- }
- }
- #endregion
- }
- #region effect
- yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
- if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
- if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
- }
- }
- GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
- GManager.instance.attackProcess.SecurityDigimon = null;
- #endregion
- // reset effect until end of security check
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
- }
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- GManager.instance.turnStateMachine.IsSelecting = true;
- }
- else
- {
- break;
- }
- }
- }
- #endregion
- GManager.instance.turnStateMachine.isSecurityCehck = false;
- }
- }
- }
- #endregion
- #region trash cards from security
- public class IDestroySecurity
- {
- private enum TrashMode
- {
- TopSecurity,
- BottomSecurity,
- SelectedCard,
- }
- public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
- {
- _player = player;
- _destroySecurityCount = destroySecurityCount;
- _cardEffect = cardEffect;
- _trashMode = fromTop ? TrashMode.TopSecurity : TrashMode.BottomSecurity;
- }
- public IDestroySecurity(Player player, CardSource card, ICardEffect cardEffect)
- {
- _player = player;
- _destroySecurityCount = 1;
- _cardEffect = cardEffect;
- _trashMode = TrashMode.SelectedCard;
- _selectedCard = card;
- }
- Player _player = null;
- int _destroySecurityCount = 0;
- public List<CardSource> DestroyedSecurity = new List<CardSource>();
- ICardEffect _cardEffect = null;
- TrashMode _trashMode = TrashMode.TopSecurity;
- CardSource _selectedCard = null;
- public bool IsDestroyed(CardSource cardSource)
- {
- return DestroyedSecurity.Contains(cardSource);
- }
- public IEnumerator DestroySecurity()
- {
- bool StopDestroySecurity()
- {
- if (_player.SecurityCards.Count == 0)
- {
- return true;
- }
- if (!_player.CanReduceSecurity())
- {
- return true;
- }
- return false;
- }
- if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
- {
- int count = 0;
- List<CardSource> discardedCards = new List<CardSource>();
- while (true)
- {
- if (StopDestroySecurity())
- {
- break;
- }
- if (count >= _destroySecurityCount)
- {
- break;
- }
- if (_player.SecurityCards.Count >= 1)
- {
- count++;
- CardSource destroyedSecurityCard = null;
- switch (_trashMode)
- {
- case TrashMode.TopSecurity:
- destroyedSecurityCard = _player.SecurityCards[0];
- break;
- case TrashMode.BottomSecurity:
- destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
- break;
- case TrashMode.SelectedCard:
- destroyedSecurityCard = _player.SecurityCards.Contains(_selectedCard) ? _selectedCard : null;
- break;
- }
- if (destroyedSecurityCard == null)
- {
- break;
- }
- discardedCards.Add(destroyedSecurityCard);
- #region effect
- _player.securityObject.securityBreakGlass.ShowBlueMatarial();
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
- yield return new WaitForSeconds(0.1f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
- yield return new WaitForSeconds(0.5f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
- DestroyedSecurity.Add(destroyedSecurityCard);
- }
- }
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
- if (discardedCards.Count >= 1)
- {
- yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
- player: _player,
- refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
- cardEffect: _cardEffect).ReduceSecurity());
- #region "When security cards are trashed" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"DiscardedCards", discardedCards},
- {"CardEffect", _cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
- #endregion
- }
- #region add log
- if (discardedCards.Count >= 1)
- {
- string log = "";
- string modeString = "";
- switch (_trashMode)
- {
- case TrashMode.TopSecurity:
- modeString = "Top";
- break;
- case TrashMode.BottomSecurity:
- modeString = "Bottom";
- break;
- case TrashMode.SelectedCard:
- modeString = "Selected";
- break;
- }
- log += $"\nDiscarded From {modeString} Security Cards:";
- foreach (CardSource cardSource in discardedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- }
- #endregion
- #region Battle
- public class IBattle
- {
- public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard, bool IsWithoutAttack = false)
- {
- this.AttackingPermanent = AttackingPermanent;
- this.DefendingPermanent = DefendingPermanent;
- this.DefendingCard = DefendingCard;
- this.IsWithoutAttack = IsWithoutAttack;
- }
- public Permanent AttackingPermanent { get; private set; } = null;
- public Permanent DefendingPermanent { get; private set; } = null;
- CardSource DefendingCard { get; set; } = null;
- bool IsWithoutAttack { get; set; } = false;
- public Hashtable hashtable { get; set; } = new Hashtable();
- public Permanent enemyPermanent(Permanent permanent)
- {
- if (permanent != null)
- {
- if (permanent == AttackingPermanent)
- {
- return DefendingPermanent;
- }
- else if (permanent == DefendingPermanent)
- {
- return AttackingPermanent;
- }
- }
- return null;
- }
- public int CompareStats()
- {
- int statCheck = 0;
- if (AttackingPermanent.HasIceclad || DefendingPermanent.HasIceclad)
- statCheck = AttackingPermanent.DigivolutionCards.Count - DefendingPermanent.DigivolutionCards.Count;
- else
- statCheck = AttackingPermanent.DP - DefendingPermanent.DP;
- statCheck = Mathf.Clamp(statCheck, -1, 1);
- return statCheck;
- }
- public IEnumerator Battle()
- {
- hashtable = new Hashtable();
- if (AttackingPermanent != null && AttackingPermanent.TopCard.HasDP)
- {
- bool IsExistingDefender()
- {
- // whether defender exists
- if ((DefendingPermanent == null) != (DefendingCard == null))
- {
- if (DefendingPermanent != null)
- {
- if (DefendingPermanent.TopCard != null)
- {
- return DefendingPermanent.TopCard.HasDP;
- }
- }
- else if (DefendingCard != null)
- {
- return DefendingCard.HasDP;
- }
- }
- return false;
- }
- if (IsExistingDefender())
- {
- if (AttackingPermanent != null)
- {
- AttackingPermanent.battle = this;
- }
- if (DefendingPermanent != null)
- {
- DefendingPermanent.battle = this;
- }
- List<Permanent> WinnerPermanents = new List<Permanent>();
- List<Permanent> LoserPermanents = new List<Permanent>();
- CardSource LoserCard = null;
- bool WasTie = false;
- //add log
- string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
- if (DefendingPermanent != null)
- {
- log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
- }
- else if (DefendingCard != null)
- {
- log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
- }
- PlayLog.OnAddLog?.Invoke(log);
- #region "At the start of battle" effect
- Permanent _AttackingPermanent = null;
- Permanent _DefendingPermanent = null;
- if (AttackingPermanent != null)
- {
- if (AttackingPermanent.TopCard != null)
- {
- _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
- }
- }
- if (DefendingPermanent != null)
- {
- if (DefendingPermanent.TopCard != null)
- {
- _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
- }
- }
- hashtable.Add("AttackingPermanent", _AttackingPermanent);
- hashtable.Add("DefendingPermanent", _DefendingPermanent);
- hashtable.Add("DefendingCard", DefendingCard);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
- #endregion
- #region Show effect
- bool ShowEffect()
- {
- if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
- {
- return true;
- }
- else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
- {
- if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
- {
- return true;
- }
- }
- return false;
- }
- if (ShowEffect())
- {
- if (GManager.instance.attackProcess.IsAttacking)
- {
- if (GManager.instance.attackProcess.SecurityDigimon != null)
- {
- if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
- }
- }
- }
- }
- #endregion
- if (!IsWithoutAttack)//If started by effect, do not perform processing during this battle
- {
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- GManager.instance.turnStateMachine.IsSelecting = true;
- //Preemptive end battle if the attack process is ended
- if (GManager.instance.attackProcess.IsEndAttack)
- yield break;
- }
- #region battle with permanent
- if (DefendingPermanent != null)
- {
- int battleResults = CompareStats();
- if (battleResults == 1)
- {
- WinnerPermanents.Add(AttackingPermanent);
- if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(DefendingPermanent);
- }
- else if (battleResults == 0)
- {
- WasTie = true;
- WinnerPermanents.Add(AttackingPermanent);
- WinnerPermanents.Add(DefendingPermanent);
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(AttackingPermanent);
- if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(DefendingPermanent);
- }
- else if (battleResults == -1)
- {
- WinnerPermanents.Add(DefendingPermanent);
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(AttackingPermanent);
- }
- }
- #endregion
- #region battle with card
- else if (DefendingCard != null)
- {
- if (AttackingPermanent.DP > DefendingCard.CardDP)
- {
- WinnerPermanents.Add(AttackingPermanent);
- LoserCard = DefendingCard;
- }
- else if (AttackingPermanent.DP == DefendingCard.CardDP)
- {
- WasTie = true;
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- {
- LoserPermanents.Add(AttackingPermanent);
- }
- LoserCard = DefendingCard;
- }
- else if (AttackingPermanent.DP < DefendingCard.CardDP)
- {
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- {
- LoserPermanents.Add(AttackingPermanent);
- }
- }
- }
- #endregion
- List<Permanent> _WinnerPermanents = new List<Permanent>();
- List<Permanent> _LoserPermanents = new List<Permanent>();
- foreach (Permanent permanent in WinnerPermanents)
- {
- if (permanent.TopCard != null)
- {
- _WinnerPermanents.Add(new Permanent(permanent.cardSources));
- }
- }
- foreach (Permanent permanent in LoserPermanents)
- {
- if (permanent.TopCard != null)
- {
- _LoserPermanents.Add(new Permanent(permanent.cardSources));
- }
- }
- hashtable.Add("WinnerPermanents", _WinnerPermanents);
- hashtable.Add("WinnerPermanents_real", WinnerPermanents);
- hashtable.Add("LoserPermanents", _LoserPermanents);
- hashtable.Add("LoserPermanents_real", LoserPermanents);
- hashtable.Add("LoserCard", LoserCard);
- hashtable.Add("WasTie", WasTie);
- hashtable.Add("battle", this);
- // battle effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
- DestroyPermanentsClass destoryBattlePermanents = new DestroyPermanentsClass(LoserPermanents, hashtable);
- yield return ContinuousController.instance.StartCoroutine(destoryBattlePermanents.Destroy());
- //Fix Loser Permanents
- if (LoserPermanents.Count != destoryBattlePermanents.DestroyedPermanents.Count)
- {
- LoserPermanents = destoryBattlePermanents.DestroyedPermanents;
- _LoserPermanents = destoryBattlePermanents.DestroyedPermanents;
- hashtable["LoserPermanents"] = _LoserPermanents;
- hashtable["LoserPermanents_real"] = LoserPermanents;
- }
- // "At the end of battle" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
- #region move up effect
- if (ShowEffect())
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
- }
- #endregion
- #region effect when determine whether to do security check
- List<SkillInfo> skillInfos_Pierce = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnDetermineDoSecurityCheck)
- .Filter(skillInfo => skillInfo.CardEffect != null && skillInfo.CardEffect.CanActivate(skillInfo.Hashtable));
- if (skillInfos_Pierce.Count >= 1)
- {
- GManager.instance.autoProcessing.PutStackedSkill(skillInfos_Pierce[0]);
- }
- #endregion
- }
- }
- if (!IsWithoutAttack)//If started by effect, do not perform processing & don't reset effects relevant to the actual attack process
- {
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- #region reset effect until the end of battle
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
- }
- player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
- }
- #endregion
- }
- if (AttackingPermanent != null)
- {
- AttackingPermanent.battle = null;
- }
- if (DefendingPermanent != null)
- {
- DefendingPermanent.battle = null;
- }
- }
- }
- #endregion
- #region De-digivolve
- public class IDegeneration
- {
- /// <summary>
- /// De-Digivolve Class
- /// </summary>
- /// <param name="permanent">Target Permanent</param>
- /// <param name="DegenerationCount">De-Digivolve Amount</param>
- /// <param name="cardEffect">Card Effect</param>
- /// <param name="DegenerationCountRuling">Should we enforce rule to select De-digivolve amount before digimon, disabled by default</param>
- public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect, bool? DegenerationCountRuling = null)
- {
- _permanent = permanent;
- _degenerationCount = DegenerationCount;
- _cardEffect = cardEffect;
- _degenerationCountRuling = DegenerationCountRuling;
- }
- Permanent _permanent = null;
- int _degenerationCount;
- ICardEffect _cardEffect = null;
- bool? _degenerationCountRuling;
- public IEnumerator Degeneration()
- {
- if (_cardEffect == null) yield break;
- if (_cardEffect.EffectSourceCard == null) yield break;
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_permanent.ImmuneFromDeDigivolve()) yield break;
- if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
- if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
- int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
- SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
- if (selectCountEffect != null && _degenerationCountRuling == null)
- {
- Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
- selectCountEffect.SetUp(
- SelectPlayer: selectPlayer,
- targetPermanent: _permanent,
- MaxCount: maxCount,
- CanNoSelect: false,
- Message: "How many cards do you trash?",
- Message_Enemy: "The opponent is choosing how many cards to trash.",
- SelectCountCoroutine: SelectCountCoroutine);
- yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
- IEnumerator SelectCountCoroutine(int count)
- {
- _degenerationCount = count;
- yield return null;
- }
- }
- if (_degenerationCount >= 1)
- {
- int count = 0;
- List<CardSource> selectedCards = new List<CardSource>();
- while (true)
- {
- bool StopCondition()
- {
- if (_permanent.HasNoDigivolutionCards)
- {
- return true;
- }
- if (_permanent.Level == 3)
- {
- if (_permanent.TopCard != null)
- {
- if (_permanent.TopCard.HasLevel)
- {
- return true;
- }
- }
- }
- if (count >= _degenerationCount)
- {
- return true;
- }
- return false;
- }
- if (StopCondition())
- {
- break;
- }
- if (count == 0)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- }
- CardSource cardSource = _permanent.TopCard;
- selectedCards.Add(cardSource);
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- _permanent.ShowingPermanentCard.ShowPermanentData(true);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
- count++;
- }
- #region "When Top Card is Trashed" effect
- #region Hashtable Setting
- System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
- {
- {"Permanent", _permanent},
- {"CardSources", selectedCards}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
- .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
- #endregion
- #region add log
- if (selectedCards.Count >= 1)
- {
- string log = "";
- log += $"\nDe-Digivolve :";
- foreach (CardSource cardSource in selectedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- }
- public class IMassDegeneration
- {
- /// <summary>
- /// De-Digivolve Class for applying simultaneous De-digivolve to multiple digimon at once
- /// to behave correctly around immunity effects, especially blanket immunity
- /// </summary>
- /// <param name="permanents">Target Permanents</param>
- /// <param name="DegenerationCount">De-Digivolve Amount</param>
- /// <param name="cardEffect">Card Effect</param>
- /// <param name="DegenerationCountRuling">Should we enforce rule to select De-digivolve amount before digimon, disabled by default.</param>
- public IMassDegeneration(List<Permanent> permanents, int DegenerationCount, ICardEffect cardEffect, bool? DegenerationCountRuling = null)
- {
- _permanents = permanents;
- _degenerationCount = DegenerationCount;
- _cardEffect = cardEffect;
- _degenerationCountRuling = DegenerationCountRuling;
- }
- List<Permanent> _permanents = null;
- int _degenerationCount;
- ICardEffect _cardEffect = null;
- bool? _degenerationCountRuling;
- public IEnumerator Degeneration()
- {
- if (_cardEffect == null) yield break;
- if (_cardEffect.EffectSourceCard == null) yield break;
- bool ValidTarget(Permanent permanent)
- {
- return permanent != null
- && permanent.TopCard != null
- && !permanent.ImmuneFromDeDigivolve()
- && !permanent.ImmuneFromStackTrashing(_cardEffect)
- && !permanent.TopCard.CanNotBeAffected(_cardEffect);
- }
- List<Permanent> permanents_Fixed = _permanents.Filter(ValidTarget);
- // 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.
- // 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.
- // SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
- // if (selectCountEffect != null && _degenerationCountRuling == null && _degenerationCount > 1)
- // {
- // Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
- // selectCountEffect.SetUp(
- // SelectPlayer: selectPlayer,
- // targetPermanent: _permanent,
- // MaxCount: maxCount,
- // CanNoSelect: false,
- // Message: "How many cards do you trash?",
- // Message_Enemy: "The opponent is choosing how many cards to trash.",
- // SelectCountCoroutine: SelectCountCoroutine);
- // yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
- // IEnumerator SelectCountCoroutine(int count)
- // {
- // _degenerationCount = count;
- // yield return null;
- // }
- // }
- if (_degenerationCount >= 1)
- {
- foreach(Permanent _permanent in permanents_Fixed)
- {
- int count = 0;
- int maxCount = Math.Min(_degenerationCount, _permanent.DigivolutionCards.Count);
- List<CardSource> selectedCards = new List<CardSource>();
- while (true)
- {
- bool StopCondition()
- {
- if (_permanent.HasNoDigivolutionCards)
- {
- return true;
- }
- if (_permanent.Level == 3)
- {
- if (_permanent.TopCard != null)
- {
- if (_permanent.TopCard.HasLevel)
- {
- return true;
- }
- }
- }
- if (count >= maxCount)
- {
- return true;
- }
- return false;
- }
- if (StopCondition())
- {
- break;
- }
- if (count == 0)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- }
- CardSource cardSource = _permanent.TopCard;
- selectedCards.Add(cardSource);
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- _permanent.ShowingPermanentCard.ShowPermanentData(true);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
- count++;
- }
- #region "When Top Card is Trashed" effect
- #region Hashtable Setting
- System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
- {
- {"Permanent", _permanent},
- {"CardSources", selectedCards}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
- .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
- #endregion
- #region add log
- if (selectedCards.Count >= 1)
- {
- string log = "";
- log += $"\nDe-Digivolve :";
- foreach (CardSource cardSource in selectedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
-
- #endregion
- }
- }
- }
- }
- #endregion
- #region Trash digivolution cards
- public class ITrashDigivolutionCards
- {
- public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
- {
- _permanent = permanent;
- _trashTargetCards = trashTargetCards.Clone();
- _cardEffect = cardEffect;
- }
- public bool IsTrashed(CardSource cardSource)
- {
- return TrashedCards.Contains(cardSource);
- }
- Permanent _permanent = null;
- List<CardSource> _trashTargetCards = new List<CardSource>();
- public List<CardSource> TrashedCards = new List<CardSource>();
- ICardEffect _cardEffect = null;
- public IEnumerator TrashDigivolutionCards()
- {
- if (_trashTargetCards == null) yield break;
- if (_cardEffect == null) yield break;
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
- if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
- if (_permanent.HasNoDigivolutionCards) yield break;
- _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
- _permanent.DigivolutionCards.Contains(cardSource) &&
- !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
- if (_trashTargetCards.Count == 0) yield break;
- _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
- string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- #region cut in effect - Would discard
- // "When digivolution cards would be trashed" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
- _permanent,
- _trashTargetCards,
- _cardEffect
- ),
- EffectTiming.WhenWouldDigivolutionCardDiscarded));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- // effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
- }
- #endregion
- //fix trash target permanent
- Permanent permanentTarget_Fixed = _permanent;
- // fix trash sources sources
- List<CardSource> trashDigivolutionCards_Fixed = _trashTargetCards.Filter(cardsource =>
- cardsource != null
- && cardsource.willBeRemoveSources);
- #region "When digivolution cards are trashed" effect
- #region Hashtable Setting
- Hashtable hashtable = new Hashtable()
- {
- {"CardEffect", _cardEffect},
- {"Permanent", permanentTarget_Fixed},
- {"DiscardedCards", trashDigivolutionCards_Fixed},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
- foreach (CardSource cardSource in trashDigivolutionCards_Fixed)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- cardSource.willBeRemoveSources = false;
- TrashedCards.Add(cardSource);
- }
- }
- }
- #endregion
- #region Trash link cards
- public class ITrashLinkCards
- {
- public ITrashLinkCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
- {
- _permanent = permanent;
- _trashTargetCards = trashTargetCards.Clone();
- _cardEffect = cardEffect;
- }
- public bool IsTrashed(CardSource cardSource)
- {
- return TrashedLinkCards.Contains(cardSource);
- }
- Permanent _permanent = null;
- List<CardSource> _trashTargetCards = new List<CardSource>();
- public List<CardSource> TrashedLinkCards = new List<CardSource>();
- ICardEffect _cardEffect = null;
- public IEnumerator TrashLinkCards()
- {
- if (_trashTargetCards == null) yield break;
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_cardEffect != null && _permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
- if (_permanent.HasNoLinkCards) yield break;
- _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
- _permanent.LinkedCards.Contains(cardSource));
- if (_trashTargetCards.Count == 0) yield break;
- _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
- string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- #region cut in effect - Would discard
- // "When link cards would be trashed" effect
- //TODO: Create CardEffectCommons.WhenLinkCardWouldDiscard function
- /*yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
- _permanent,
- _trashTargetCards,
- _cardEffect
- ),
- EffectTiming.WhenWouldDigivolutionCardDiscarded));*/
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- // effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
- }
- #endregion
- //fix trash target permanent
- Permanent permanentTarget_Fixed = _permanent;
- // fix trash sources sources
- List<CardSource> trashLinkCards_Fixed = _trashTargetCards.Filter(cardsource =>
- cardsource != null
- && cardsource.willBeRemoveSources);
- #region "When link cards are trashed" effect
- #region Hashtable Setting
- Hashtable hashtable = new Hashtable()
- {
- {"CardEffect", _cardEffect},
- {"Permanent", permanentTarget_Fixed},
- {"DiscardedCards", trashLinkCards_Fixed},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLinkCardDiscarded));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
- foreach (CardSource cardSource in trashLinkCards_Fixed)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
- if (!cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(permanentTarget_Fixed.RemoveLinkedCard(cardSource));
- }
- cardSource.willBeRemoveSources = false;
- TrashedLinkCards.Add(cardSource);
- }
- }
- }
- #endregion
- #region Return digivolution cards to deck bottom
- public class ReturnToLibraryBottomDigivolutionCardsClass
- {
- public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
- {
- _permanent = permanent;
- _cardSources = cardSources.Clone();
- _hashtable = hashtable;
- }
- Permanent _permanent = null;
- List<CardSource> _cardSources = new List<CardSource>();
- Hashtable _hashtable = null;
- public IEnumerator ReturnToLibraryBottomDigivolutionCards()
- {
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_cardSources == null) yield break;
- _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
- if (_cardSources.Count == 0) yield break;
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
- string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- #region "When digivolution cards are returned to deck" effect
- #region Hashtable Setting
- Hashtable hashtable1 = new Hashtable()
- {
- {"Permanent", _permanent},
- {"DeckBottomCards", _cardSources},
- {"CardEffect", CardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
- }
- }
- #endregion
- #region Reduce security
- public class IReduceSecurity
- {
- public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos, ICardEffect cardEffect)
- {
- _player = player;
- _refSkillInfos = refSkillInfos;
- _cardEffect = cardEffect;
- }
- Player _player = null;
- List<SkillInfo> _refSkillInfos = null;
- ICardEffect _cardEffect = null;
- public IEnumerator ReduceSecurity()
- {
- GManager.OnSecurityStackChanged?.Invoke(_player);
- #region "When cards are removed from security" effect
- #region Hashtable Setting
- Hashtable hashtable = new Hashtable()
- {
- {"Player", _player},
- {"SkillInfo",_refSkillInfos },
- {"CardEffect",_cardEffect}
- };
- #endregion
- if (_refSkillInfos == null)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
- }
- else
- {
- foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
- {
- _refSkillInfos.Add(skillInfo);
- }
- }
- #endregion
- }
- }
- #endregion
- #region Add Security
- public class IAddSecurity
- {
- public IAddSecurity(CardSource source)
- {
- _player = source.Owner;
- _cardSource = source;
- }
- Player _player { get; set; }
- CardSource _cardSource { get; set; }
- public IEnumerator AddSecurity()
- {
- GManager.OnSecurityStackChanged?.Invoke(_player);
- #region "When security cards are added" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"Player", _player},
- {"CardSources", new List<CardSource> { _cardSource } }
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
- #endregion
- #region "When face up cards are added"
- if (!_cardSource.IsFlipped)
- {
- #region Hashtable setting
- Hashtable faceUpHashtable = new Hashtable()
- {
- {"Player", _player},
- {"CardSources", new List<CardSource> { _cardSource } }
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(faceUpHashtable, EffectTiming.OnFaceUpSecurityIncreased));
- }
- #endregion
- }
- }
- #endregion
- #region Flip Security Face Up
- public class IFlipSecurity
- {
- public IFlipSecurity(CardSource source)
- {
- _player = source.Owner;
- _cardSource = source;
- }
- Player _player { get; set; }
- CardSource _cardSource { get; set; }
- public IEnumerator FlipFaceUp()
- {
- if (!_player.SecurityCards.Contains(_cardSource) || !_cardSource.IsFlipped)
- yield break;
- _cardSource.SetFace();
- #region "When face up cards are added"
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"Player", _player},
- {"CardSources", new List<CardSource> { _cardSource } }
- };
- #endregion
- if (!_cardSource.IsFlipped)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnFaceUpSecurityIncreased));
- }
- #endregion
- }
- }
- #endregion
- #region Suspend permanents
- public class SuspendPermanentsClass
- {
- public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
- {
- _permanents = permanents;
- _hashtable = hashtable;
- }
- public bool IsSuspended(Permanent permanent)
- {
- return SuspendedPermanents.Contains(permanent);
- }
- List<Permanent> _permanents { get; set; }
- public List<Permanent> SuspendedPermanents { get; private set; } = new List<Permanent>();
- Hashtable _hashtable { get; set; }
- public IEnumerator Tap()
- {
- if (_permanents.Count == 0) yield break;
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
- bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
- List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
- bool PermanentCondition(Permanent permanent)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- if (permanent.IsSuspended)
- {
- return false;
- }
- if (!permanent.CanSuspend)
- {
- return false;
- }
- if (CardEffect != null)
- {
- if (permanent.TopCard.CanNotBeAffected(CardEffect))
- {
- return false;
- }
- }
- }
- }
- return true;
- }
- foreach (Permanent permanent in suspendTargetPermanents)
- {
- permanent.IsSuspended = true;
- permanent.DPWhenSuspended = permanent.DP;
- if (permanent.ShowingPermanentCard != null)
- {
- permanent.ShowingPermanentCard.ShowPermanentData(true);
- }
- SuspendedPermanents.Add(permanent);
- }
- if (suspendTargetPermanents.Count >= 1)
- {
- #region "Effects when permanents suspend
- #region Hashtable Setting
- Hashtable _hashtable = new Hashtable(){
- {"Permanents", suspendTargetPermanents},
- {"IsBlock", IsBlock}
- };
- if (CardEffect != null)
- {
- _hashtable.Add("CardEffect", CardEffect);
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
- #endregion
- yield return new WaitForSeconds(0.3f);
- }
- }
- }
- #endregion
- #region Unsuspend permanents
- public class IUnsuspendPermanents
- {
- public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
- {
- _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
- _cardEffect = cardEffect;
- }
- List<Permanent> _permanents { get; set; }
- ICardEffect _cardEffect { get; set; }
- public IEnumerator Unsuspend()
- {
- //Permanent list that will unsuspend
- List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
- permanent != null
- && permanent.TopCard != null
- && permanent.IsSuspended
- && permanent.CanUnsuspend
- && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
- #region "When permanents would unsuspend" effect
- #region Hashtable Setting
- Hashtable hashtable1 = new Hashtable()
- {
- {"CardEffect", _cardEffect},
- {"Permanents", untappedPermanets},
- };
- #endregion
- List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
- if (skillInfos.Count >= 1)
- {
- foreach (SkillInfo skillInfo in skillInfos)
- {
- GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
- }
- foreach (Permanent permanent in untappedPermanets)
- {
- permanent.ShowUnsuspendEffect();
- }
- //cut in effects
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
- untappedPermanets.ForEach(permanent =>
- {
- if (permanent.ShowingPermanentCard != null)
- {
- permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
- }
- });
- }
- #endregion
- // fix unsuspend target permanents
- List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
- permanent != null
- && permanent.TopCard != null
- && permanent.IsSuspended
- && permanent.CanUnsuspend
- && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
- if (untappedPermanets_Fixed.Count >= 1)
- {
- foreach (Permanent permanent in untappedPermanets_Fixed)
- {
- permanent.IsSuspended = false;
- if (permanent.ShowingPermanentCard != null)
- {
- permanent.ShowingPermanentCard.ShowPermanentData(true);
- }
- }
- #region "When permanents are unsuspended" effect
- #region Hashtable Setting
- Hashtable hashtable2 = new Hashtable()
- {
- {"CardEffect", _cardEffect},
- {"Permanents", untappedPermanets_Fixed},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
- #endregion
- yield return new WaitForSeconds(0.3f);
- }
- }
- }
- #endregion
- #region Trash cards from deck top
- public class ITrashDeckCards
- {
- public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
- {
- this.cardSources = new List<CardSource>();
- foreach (CardSource cardSource in cardSources)
- {
- this.cardSources.Add(cardSource);
- }
- this.cardEffect = cardEffect;
- }
- List<CardSource> cardSources { get; set; } = new List<CardSource>();
- ICardEffect cardEffect { get; set; } = null;
- public IEnumerator TrashDeckCards()
- {
- List<CardSource> trashCards = new List<CardSource>();
- foreach (CardSource cardSource in cardSources)
- {
- if (cardSource.Owner.LibraryCards.Contains(cardSource))
- {
- trashCards.Add(cardSource);
- }
- }
- if (trashCards.Count >= 1)
- {
- foreach (CardSource cardSource in trashCards)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- #region "When cards are trashed from security" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"DiscardedCards", trashCards},
- {"CardEffect", cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
- hashtable, EffectTiming.OnDiscardLibrary));
- #endregion
- }
- }
- }
- #endregion
- #region Overflow of ace
- public class AceOverflowClass
- {
- public AceOverflowClass(List<CardSource> cardSources)
- {
- _cardSources = cardSources.Clone();
- }
- List<CardSource> _cardSources = new List<CardSource>();
- public IEnumerator Overflow()
- {
- _cardSources = _cardSources
- .Filter(cardSource => cardSource.IsACE && !cardSource.IsFlipped && CardEffectCommons.IsExistOnBattleArea(cardSource) || CardEffectCommons.IsExistOnBreedingAreaDigimon(cardSource))
- .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
- .ToList();
- foreach (CardSource cardSource in _cardSources)
- {
- yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
- string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- }
- }
- #endregion
- #region TrashStack
- public class ITrashStack
- {
- /// <summary>
- /// Trash Stack Class
- /// </summary>
- /// <param name="permanent">Target Permanent</param>
- /// <param name="TrashCount">Amount of cards to trash</param>
- /// <param name="cardEffect">Card Effect</param>
- /// <param name="fromTop">Should trashing start from top, true by default</param>
- public ITrashStack(Permanent permanent, int TrashCount, ICardEffect cardEffect, bool fromTop = true)
- {
- _permanent = permanent;
- _trashCount = TrashCount;
- _cardEffect = cardEffect;
- _fromTop = fromTop;
- }
- Permanent _permanent = null;
- int _trashCount;
- ICardEffect _cardEffect = null;
- bool _fromTop;
- public IEnumerator TrashStack()
- {
- if (_cardEffect == null) yield break;
- if (_cardEffect.EffectSourceCard == null) yield break;
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
- if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
- _trashCount = Math.Min(_permanent.StackCards.Count, _trashCount);
- if (_trashCount >= 1)
- {
- int count = 0;
- List<CardSource> selectedCards = new List<CardSource>();
- while (true)
- {
- bool StopCondition()
- {
- if (_permanent.HasNoDigivolutionCards)
- {
- return true;
- }
- if (count >= _trashCount)
- {
- return true;
- }
- return false;
- }
- if (StopCondition())
- {
- break;
- }
- if (count == 0)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- }
- CardSource cardSource = _permanent.TopCard;
- selectedCards.Add(cardSource);
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- _permanent.ShowingPermanentCard.ShowPermanentData(true);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
- count++;
- }
- #region "When Top Card is Trashed" effect
- #region Hashtable Setting
- System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
- {
- {"Permanent", _permanent},
- {"CardSources", selectedCards}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
- .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
- #endregion
- #region add log
- if (selectedCards.Count >= 1)
- {
- string log = "";
- log += $"\nStack Trashed :";
- foreach (CardSource cardSource in selectedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- }
- #endregion
|