CardController.cs 210 KB

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