CardController.cs 209 KB

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