CardController.cs 210 KB

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