CardController.cs 201 KB

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