CardController.cs 200 KB

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