CardController.cs 208 KB

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