CardController.cs 201 KB

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