CardController.cs 201 KB

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