CardController.cs 212 KB

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