CardController.cs 211 KB

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