CardController.cs 211 KB

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