| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.Linq;
- #region Trash cards from hand
- public class IDiscardHands
- {
- public IDiscardHands(List<IDiscardHand> discardHands, ICardEffect cardEffect)
- {
- foreach (IDiscardHand discardHand in discardHands)
- {
- this.discardHands.Add(discardHand);
- }
- this.cardEffect = cardEffect;
- }
- List<IDiscardHand> discardHands { get; set; } = new List<IDiscardHand>();
- ICardEffect cardEffect { get; set; }
- public IEnumerator DiscardHands()
- {
- foreach (IDiscardHand discardHand in discardHands)
- {
- yield return ContinuousController.instance.StartCoroutine(discardHand.Discard());
- }
- List<CardSource> discardedCards = new List<CardSource>();
- foreach (IDiscardHand discardHand in discardHands)
- {
- if (discardHand.discarded)
- {
- discardedCards.Add(discardHand.cardSource);
- }
- }
- if (discardedCards.Count >= 1)
- {
- #region "When cards are trashed from hand" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"DiscardedCards", discardedCards},
- {"CardEffect", cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardHand));
- #endregion
- }
- #region add log
- if (discardedCards.Count >= 1)
- {
- string log = "";
- log += $"\nDiscard hand:";
- foreach (CardSource cardSource in discardedCards)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- public class IDiscardHand
- {
- public IDiscardHand(CardSource cardSource, Hashtable hashtable)
- {
- this.cardSource = cardSource;
- this.hashtable = hashtable;
- }
- public CardSource cardSource { get; private set; }
- public Hashtable hashtable { get; private set; }
- public bool discarded { get; private set; } = false;
- public IEnumerator Discard()
- {
- bool oldisHand = cardSource.Owner.HandCards.Contains(cardSource);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- bool isTrash = CardEffectCommons.IsExistOnTrash(cardSource);
- if (oldisHand && isTrash)
- {
- discarded = true;
- }
- }
- }
- #endregion
- #region Play cards
- public class PlayCardClass
- {
- public PlayCardClass(List<CardSource> cardSources, Hashtable hashtable, bool payCost, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root,
- bool activateETB)
- {
- if (cardSources != null)
- {
- CardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
- }
- _hashtable = hashtable;
- PayCost = payCost;
- _targetPermanent = targetPermanent;
- _isTapped = isTapped;
- Root = root;
- _activateETB = activateETB;
- }
- public void SetJogress(int[] jogressEvoRootsFrameIDs)
- {
- if (jogressEvoRootsFrameIDs != null)
- {
- _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
- }
- }
- public void SetBurst(int BurstTamerFrameID, CardSource card)
- {
- if (0 <= BurstTamerFrameID && BurstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
- {
- _burstTamerFrameID = BurstTamerFrameID;
- }
- }
- public void SetAppFusion(int[] AppFusionFrameID)
- {
- if (AppFusionFrameID != null)
- {
- _appFusionFrameIDs = AppFusionFrameID.CloneArray(); ;
- }
- }
- public void SetShowEffect()
- {
- _showEffect = true;
- }
- public void SetIgnoreLevel()
- {
- _ignoreLevel = true;
- SetIgnoreRequirements(CardEffectCommons.IgnoreRequirement.Level);
- }
- public void SetIgnoreRequirements(CardEffectCommons.IgnoreRequirement ignore)
- {
- _ignoreRequirement = ignore;
- }
- private bool GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement ignore)
- {
- Debug.Log($"Get Ignore Requirement: {_ignoreRequirement.Equals(ignore)}, {_ignoreRequirement.Equals(CardEffectCommons.IgnoreRequirement.All)}");
- return _ignoreRequirement.Equals(ignore) || _ignoreRequirement.Equals(CardEffectCommons.IgnoreRequirement.All);
- }
-
- public void SetFixedCost(int FixedCost)
- {
- _fixedCost = FixedCost;
- }
- public void SetReducedCost(int ReducedCost)
- {
- _reducedCost = ReducedCost;
- }
- public void SetAddSecurityEndOption()
- {
- _addSecurityEndOption = true;
- }
- public void SetIsBreedingArea()
- {
- _isBreedingArea = true;
- }
- public List<CardSource> CardSources { get; private set; } = new List<CardSource>();
- Hashtable _hashtable = null;
- public bool PayCost { get; private set; }
- Permanent _targetPermanent = null;
- bool _isTapped = false;
- public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
- bool _activateETB = true;
- bool _showEffect = false;
- bool _ignoreLevel = false;
- CardEffectCommons.IgnoreRequirement _ignoreRequirement = CardEffectCommons.IgnoreRequirement.None;
- int _fixedCost = -1;
- int _reducedCost = 0;
- int[] _jogressEvoRootsFrameIDs = null;
- int _burstTamerFrameID = -1;
- int[] _appFusionFrameIDs = null;
- bool _addSecurityEndOption = false;
- bool _isBreedingArea = false;
- public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
- bool IsBurst(CardSource card)
- {
- Permanent burstTamer = BurstTamer(card);
- if (burstTamer != null)
- {
- if (burstTamer.TopCard != null)
- {
- if (card.burstDigivolutionCondition != null)
- {
- if (card.burstDigivolutionCondition.tamerCondition != null)
- {
- if (card.burstDigivolutionCondition.tamerCondition(burstTamer))
- {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- Permanent BurstTamer(CardSource card)
- {
- if (0 <= _burstTamerFrameID && _burstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
- {
- Permanent tamer = card.Owner.fieldCardFrames[_burstTamerFrameID].GetFramePermanent();
- return tamer;
- }
- return null;
- }
- bool IsAppFusion(CardSource card)
- {
- CardSource linkCard = LinkedCard(card);
- if (linkCard != null)
- {
- if (card.appFusionCondition != null)
- {
- if (card.appFusionCondition.digimonCondition != null)
- {
- Permanent digimon = card.Owner.fieldCardFrames[_appFusionFrameIDs[0]].GetFramePermanent();
- if (card.appFusionCondition.linkedCondition != null)
- {
- if (card.appFusionCondition.linkedCondition(digimon, linkCard))
- {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- public CardSource LinkedCard(CardSource card)
- {
- if (_appFusionFrameIDs != null && _appFusionFrameIDs.Length == 2)
- {
- if (0 <= _appFusionFrameIDs[0] && _appFusionFrameIDs[0] <= card.Owner.fieldCardFrames.Count - 1)
- {
- Permanent targetPermanent = card.Owner.fieldCardFrames[_appFusionFrameIDs[0]].GetFramePermanent();
- if(targetPermanent.LinkedCards.Count > _appFusionFrameIDs[1])
- {
- CardSource link = targetPermanent.LinkedCards[_appFusionFrameIDs[1]];
- return link;
- }
- }
- }
-
- return null;
- }
- public IEnumerator PlayCard()
- {
- bool burstDigivolved = false;
- bool appFusion = false;
- List<CardSource> playedCards_fixed = new List<CardSource>();
- foreach (CardSource card in CardSources)
- {
- GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
- GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
- GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
- if (card == null)
- {
- continue;
- }
- #region Set Root
- ICardEffect CardEffect = null;
- CardEffect = CardEffectCommons.GetCardEffectFromHashtable(this._hashtable);
- if (CardEffectCommons.IsExistOnTrash(card))
- {
- Root = SelectCardEffect.Root.Trash;
- }
- else if (card.Owner.HandCards.Contains(card))
- {
- Root = SelectCardEffect.Root.Hand;
- }
- else if (card.Owner.LibraryCards.Contains(card))
- {
- Root = SelectCardEffect.Root.Library;
- }
- else if (card.Owner.GetFieldPermanents().Count((permanent) => permanent.DigivolutionCards.Contains(card)) >= 1)
- {
- Root = SelectCardEffect.Root.DigivolutionCards;
- }
- else if (card.Owner.SecurityCards.Contains(card))
- {
- Root = SelectCardEffect.Root.Security;
- }
- else if (CardEffectCommons.IsExistOnExecutingArea(card))
- {
- Root = SelectCardEffect.Root.Execution;
- }
- #endregion
- #region Set target(s)
- List<Permanent> targetPermanents = new List<Permanent>();
- if (card.IsPermanent)
- {
- if (!isJogress)
- {
- if (CardEffectCommons.IsOwnerPermanent(_targetPermanent, card))
- {
- targetPermanents.Add(_targetPermanent);
- }
- }
- else
- {
- for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
- {
- int JogressFrameID = _jogressEvoRootsFrameIDs[i];
- if (0 <= JogressFrameID && JogressFrameID <= card.Owner.fieldCardFrames.Count - 1)
- {
- Permanent targetPermanent = card.Owner.fieldCardFrames[JogressFrameID].GetFramePermanent();
- targetPermanents.Add(targetPermanent);
- }
- }
- foreach (Permanent permanent in targetPermanents)
- {
- permanent.ShowingPermanentCard.SetPermanentIndexText(targetPermanents);
- }
- }
- }
- #endregion
- #region Determine if Evolution
- bool isEvolution = false;
- if (targetPermanents.Count >= 1)
- {
- if (!isJogress)
- {
- if (IsBurst(card))
- {
- if (card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
- {
- isEvolution = true;
- }
- }
- else if (IsAppFusion(card))
- {
- if (card.CanAppFusionFromTargetPermanent(targetPermanents[0], PayCost))
- {
- isEvolution = true;
- }
- }
- else
- {
- if (card.CanEvolve(targetPermanents[0], true) || GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level) || _ignoreLevel)
- {
- isEvolution = true;
- }
- }
- }
- else
- {
- if (targetPermanents.Count == 2)
- {
- isEvolution = true;
- }
- }
- }
- #endregion
- List<CardSource> oldTrashCards = new List<CardSource>();
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForNonTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.oldIsTapped_playCard = permanent.IsSuspended;
- }
- }
- foreach (CardSource cardSource in card.Owner.TrashCards)
- {
- oldTrashCards.Add(cardSource);
- }
- // effect of removing digivolution cards
- if (card.IsPermanent && !isEvolution && card.PermanentOfThisCard() != null && Root == SelectCardEffect.Root.DigivolutionCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(card, card.PermanentOfThisCard()));
- }
- #region select digivolution cost
- int baseCost = -1;
- bool costSelected = false;
- yield return ContinuousController.instance.StartCoroutine(SelectCost());
- IEnumerator SelectCost()
- {
- if (!isJogress)
- {
- if (PayCost)
- {
- if (_fixedCost < 0)
- {
- Permanent targetPermanent = null;
- if (targetPermanents.Count >= 1)
- {
- targetPermanent = targetPermanents[0];
- }
- if (targetPermanent != null)
- {
- List<int> CostList = new List<int>();
- bool isBurst = IsBurst(card);
- bool isAppFusion = IsAppFusion(card);
- if(isBurst || isAppFusion)
- {
- if(isBurst)
- CostList.Add(card.burstDigivolutionCondition.cost);
- if(isAppFusion)
- CostList.Add(card.appFusionCondition.cost);
- }
- else
- {
- foreach (int cost in card.CostList(targetPermanent, ignoreLevel: GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level), checkAvailability: false))
- {
- int evoCost = cost;
- if (_reducedCost > 0)
- evoCost -= _reducedCost;
- CostList.Add(evoCost);
- }
- }
- CostList = CostList.Distinct().ToList();
- if (CostList.Count >= 1)
- {
- if (CostList.Count == 1)
- {
- baseCost = CostList[0];
- }
- else
- {
- costSelected = true;
- bool MoveToExecuteCardEffect = true;
- if (card.Owner.HandCards.Contains(card) && card.ShowingHandCard != null)
- {
- if (card.ShowingHandCard.gameObject.activeSelf)
- {
- MoveToExecuteCardEffect = false;
- }
- }
- if (!card.Owner.isYou && GManager.instance.IsAI)
- {
- MoveToExecuteCardEffect = false;
- costSelected = false;
- }
- if (card.Owner.isYou && ContinuousController.instance.autoMinDigivolutionCost)
- {
- MoveToExecuteCardEffect = false;
- costSelected = false;
- }
- if (MoveToExecuteCardEffect)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
- }
- SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
- if (selectCountEffect != null)
- {
- selectCountEffect.SetUp(
- SelectPlayer: card.Owner,
- targetPermanent: null,
- MaxCount: 1,
- CanNoSelect: false,
- Message: "Which digivolution cost do you pay?",
- Message_Enemy: "The opponent is choosing which digivolution cost to pay.",
- SelectCountCoroutine: SelectCountCoroutine);
- selectCountEffect.SetCandidates(CostList);
- selectCountEffect.SetPreferMin(true);
- selectCountEffect.SetNotDoSync(true);
- selectCountEffect.SetIsDigivolutionCost(true);
- yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
- IEnumerator SelectCountCoroutine(int count)
- {
- baseCost = count;
- yield return null;
- }
- }
- }
- }
- }
- else
- {
- baseCost = card.BasePlayCostFromEntity;
- }
- }
- }
- }
- }
- #endregion
- #region select DNA condition
- int baseDNA = 0;
- if (isJogress)
- {
- baseDNA = GManager.instance.GetComponent<SelectDNACondition>()._selectedCount;
- }
-
- #endregion
- #region HashTable Setting
- Hashtable hashtable = CardEffectCommons.WouldEnterFieldHashtable(
- payCost: PayCost,
- card: card,
- root: Root,
- isEvolution: isEvolution,
- playCardClass: this,
- cardEffect: CardEffect,
- isJogress: isJogress,
- targetPermanents: targetPermanents
- );
- #endregion
- List<SkillInfo> skillInfos_BeforePayCost = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.BeforePayCost)
- .Concat(AutoProcessing.GetSkillInfosOfCards(hashtable, EffectTiming.BeforePayCost, new List<CardSource>() { card }
- .Filter(cardSource => !CardEffectCommons.IsExistOnHand(cardSource) && !CardEffectCommons.IsExistOnTrash(cardSource) && !CardEffectCommons.IsExistInSecurity(cardSource) && cardSource.PermanentOfThisCard() == null)))
- .ToList();
- yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.BeforePayCost));
- #region IsShowEffect()
- bool IsShowEffect()
- {
- if (skillInfos_BeforePayCost.Count >= 2)
- {
- return true;
- }
- else if (skillInfos_BeforePayCost.Count == 1)
- {
- if (skillInfos_BeforePayCost[0].CardEffect.CanActivate(skillInfos_BeforePayCost[0].Hashtable))
- {
- return true;
- }
- }
- else if (card.HasDigiXros && !isEvolution)
- {
- return true;
- }
- else if (IsBurst(card))
- {
- return true;
- }
- else if (IsAppFusion(card))
- {
- return true;
- }
- return false;
- }
- #endregion
- #region effect
- if (PayCost || IsShowEffect())
- {
- if (!costSelected)
- {
- if (card.IsOption || IsShowEffect())
- {
- bool noHandCard = true;
- if (card.Owner.HandCards.Contains(card))
- {
- if (card.ShowingHandCard != null)
- {
- if (card.ShowingHandCard.gameObject.activeSelf)
- {
- if (card.ShowingHandCard.gameObject.transform.GetChild(0).gameObject.activeSelf)
- {
- noHandCard = false;
- }
- }
- }
- }
- if (noHandCard)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
- }
- }
- else
- {
- if (CardEffect == null)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
- }
- }
- }
- }
- #endregion
- #region show expected cost
- if (PayCost)
- {
- if (!isJogress)
- {
- int cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
- }
- else
- {
- if (card.jogressCondition != null)
- {
- int cost = card.GetPayingCostWithBaseCost(card.jogressCondition[baseDNA].cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
- }
- }
- }
- #endregion
- #region process cut in effects before paying cost
- if (skillInfos_BeforePayCost.Count >= 1)
- {
- foreach (SkillInfo skillInfo in skillInfos_BeforePayCost)
- {
- GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
- }
- if (IsShowEffect())
- {
- foreach (Permanent targetPermanent in targetPermanents)
- {
- if (targetPermanent != null)
- {
- targetPermanent.ShowWillEvolutionEffect();
- }
- }
- }
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
- foreach (Permanent targetPermanent in targetPermanents)
- {
- if (targetPermanent != null)
- {
- targetPermanent.HideWillEvolutionEffect();
- }
- }
- }
- #endregion
- #region select DigiXros
- if (card.HasDigiXros && !isEvolution)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectDigiXrosClass>().Select(card));
- }
- #endregion
- #region select Assembly
- if (card.HasAssembly && !isEvolution)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectAssemblyClass>().Select(card));
- }
- #endregion
- #region Bounce Tamer of Burst digivolution
- if (IsBurst(card))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectBurstDigivolutionEffect.BounceTamer(BurstTamer(card)));
- if (!GManager.instance.selectBurstDigivolutionEffect.TamerBounced)
- {
- _burstTamerFrameID = -1;
- yield return ContinuousController.instance.StartCoroutine(SelectCost());
- }
- else
- {
- burstDigivolved = true;
- }
- }
- #endregion
- #region Add Link Card of App Fusion
- UnityEngine.Debug.Log($"PLAYING CARD: {IsAppFusion(card)}");
- if (IsAppFusion(card))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectAppFusionEffect.AddToSources(LinkedCard(card)));
- if (!GManager.instance.selectAppFusionEffect.LinkAdded)
- {
- _appFusionFrameIDs = new int[0];
- yield return ContinuousController.instance.StartCoroutine(SelectCost());
- }
- else
- {
- appFusion = true;
- }
- yield return GManager.instance.photonWaitController.StartWait("AppFuse");
- }
- #endregion
- #region fix cost to pay
- int Cost = 0;
- if (PayCost)
- {
- if (!isJogress)
- {
- Cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- Cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- }
- else
- {
- if (card.jogressCondition != null)
- {
- Cost = card.GetPayingCostWithBaseCost(card.jogressCondition[baseDNA].cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- }
- }
- GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(Cost));
- }
- #endregion
- #region end play cards
- bool endPlayCard = false;
- bool playFailed = false;
- if (PayCost)
- {
- if (Cost > card.Owner.MaxMemoryCost)
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- if (isEvolution)
- {
- if (targetPermanents != null)
- {
- if (targetPermanents.Count >= 1)
- {
- foreach (Permanent permanent in targetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard == null)
- {
- endPlayCard = true;
- }
- }
- }
- if (!endPlayCard)
- {
- if (!isJogress && !IsBurst(card) && !IsAppFusion(card))
- {
- if (!GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level) && !card.CanPlayCardTargetFrame(targetPermanents[0].PermanentFrame, PayCost, CardEffect, root: Root, fixedCost: -1))
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- else if (isJogress)
- {
- if (!card.CanJogressFromTargetPermanents(targetPermanents, PayCost))
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- else if (IsBurst(card))
- {
- if (!card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- else if (IsAppFusion(card))
- {
- if (!card.CanAppFusionFromTargetPermanent(targetPermanents[0], PayCost))
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- }
- }
- }
- }
- if (endPlayCard)
- {
- PlayLog.OnAddLog?.Invoke($"\nFailed to play:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
- GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
- GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().FailedPlayCardEffect(card));
- if (card.Owner.HandCards.Contains(card))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(new List<CardSource>() { card }, false, null));
- }
- ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
- foreach (HandCard handCard in card.Owner.brainStormObject.BrainStormHandCards)
- {
- if (handCard.gameObject.activeSelf && handCard.cardSource == card)
- {
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- }
- }
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
- {
- if (fieldPermanentCard != null)
- {
- fieldPermanentCard.OffPermanentIndexText();
- }
- }
- }
- if (playFailed)
- {
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.IsSuspended = permanent.oldIsTapped_playCard;
- }
- }
- foreach (CardSource cardSource in oldTrashCards)
- {
- if (!CardEffectCommons.IsExistOnTrash(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- }
- }
- }
- #endregion
- card.Owner.UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
- if (endPlayCard)
- {
- continue;
- }
- #region pay cost
- if (PayCost)
- {
- // memory lose
- if (Cost <= card.Owner.MaxMemoryCost)
- {
- yield return ContinuousController.instance.StartCoroutine(card.Owner.AddMemory(-1 * Cost, null));
- }
- ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
- }
- #endregion
- #region cut in effect after paying cost
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(hashtable, EffectTiming.AfterPayCost));
- // cur in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(
- false,
- AutoProcessing.HasExecutedSameEffect));
- #endregion
- // add to played cards
- playedCards_fixed.Add(card);
- }
- #region filter cards
- List<CardSource> permanentCards = playedCards_fixed.Filter(cardSource => cardSource.IsPermanent);
- List<CardSource> optionCards = playedCards_fixed.Filter(cardSource => !cardSource.IsPermanent);
- #region play permanent
- PlayPermanentClass playPermanent = new PlayPermanentClass(permanentCards, _hashtable, _targetPermanent, _isTapped, Root, _activateETB);
- if (isJogress)
- {
- playPermanent.SetJogress(_jogressEvoRootsFrameIDs);
- }
- if (burstDigivolved)
- {
- playPermanent.SetBurstDigivolved();
- }
- if (appFusion)
- playPermanent.SetAppFusion(_appFusionFrameIDs);
- if (_isBreedingArea)
- {
- playPermanent.SetIsBreedingArea();
- }
- yield return ContinuousController.instance.StartCoroutine(playPermanent.PlayPermanent());
- #endregion
- #region use option
- UseOptionClass useOption = new UseOptionClass(optionCards, _hashtable, Root)
- {
- _showEffect = _showEffect,
- _addSecurityEndOption = _addSecurityEndOption
- };
- yield return ContinuousController.instance.StartCoroutine(useOption.UseOption());
- #endregion
- #endregion
- }
- IEnumerator OffMemoryPredictionLine()
- {
- yield return new WaitForSeconds(0.5f);
- GManager.instance.memoryObject.OffMemoryPredictionLine();
- }
- }
- #endregion
- #region Hatch DigiEgg
- public class HatchDigiEggClass
- {
- public HatchDigiEggClass(Player player, Hashtable hashtable)
- {
- _player = player;
- _hashtable = hashtable;
- }
- Player _player { get; set; }
- Hashtable _hashtable { get; set; }
- public IEnumerator Hatch()
- {
- if (_player == null) yield break;
- if (!_player.CanHatch) yield break;
- CardSource card = _player.DigitamaLibraryCards[0];
- PlayPermanentClass playPermanentClass = new PlayPermanentClass(
- cardSources: new List<CardSource>() { card },
- hashtable: _hashtable,
- targetPermanent: null,
- isTapped: false,
- root: SelectCardEffect.Root.Library,
- ActivateETB: true);
- playPermanentClass.SetIsBreedingArea();
- yield return ContinuousController.instance.StartCoroutine(playPermanentClass.PlayPermanent());
- if (card.PermanentOfThisCard() != null)
- {
- card.PermanentOfThisCard().EnterFieldTurnCount = -1;
- }
- }
- }
- #endregion
- #region Play permanents
- #region Hashtable setting class
- public class OnEnterFieldHashtableParams
- {
- public OnEnterFieldHashtableParams(
- Permanent permanent,
- List<CardSource> evoRoots,
- List<CardSource> evoRootTops,
- SelectCardEffect.Root root,
- List<int> oldLevels,
- bool isFromDigimonDigivolutionCards)
- {
- Permanent = permanent;
- if (evoRoots != null)
- {
- EvoRoots = evoRoots.Clone();
- }
- if (evoRootTops != null)
- {
- EvoRootTops = evoRootTops.Clone();
- }
- Root = root;
- if (oldLevels != null)
- {
- OldLevels = oldLevels.Clone();
- }
- IsFromDigimonDigivolutionCards = isFromDigimonDigivolutionCards;
- }
- public Permanent Permanent { get; private set; } = null;
- public List<CardSource> EvoRoots = new List<CardSource>();
- public List<CardSource> EvoRootTops { get; private set; } = new List<CardSource>();
- public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
- public List<int> OldLevels { get; private set; } = new List<int>();
- public bool IsFromDigimonDigivolutionCards { get; private set; } = false;
- }
- #endregion
- public class PlayPermanentClass
- {
- public PlayPermanentClass(List<CardSource> cardSources, Hashtable hashtable, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root, bool ActivateETB)
- {
- if (cardSources != null)
- {
- _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
- }
- _hashtable = hashtable;
- _targetPermanent = targetPermanent;
- _isTapped = isTapped;
- _root = root;
- _activateETB = ActivateETB;
- }
- public void SetJogress(int[] jogressEvoRootsFrameIDs)
- {
- if (jogressEvoRootsFrameIDs != null)
- {
- _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
- }
- }
- public void SetBurstDigivolved()
- {
- _burstDigivolved = true;
- }
- public void SetAppFusion(int[] appFusionFrameIDs)
- {
- if (appFusionFrameIDs != null)
- {
- _appFusionFrameIDs = appFusionFrameIDs.CloneArray();
- }
- _appFusion = true;
- }
- public void SetIsBreedingArea()
- {
- _isBreedingArea = true;
- }
- public void SetISPlayOption()
- {
- _isPlayOption = true;
- }
- List<CardSource> _cardSources = new List<CardSource>();
- Hashtable _hashtable = null;
- Permanent _targetPermanent = null;
- bool _isTapped = false;
- SelectCardEffect.Root _root = SelectCardEffect.Root.None;
- bool _activateETB = true;
- int[] _jogressEvoRootsFrameIDs = null;
- int _digiXrosCount = 0;
- int _assemblyCount = 0;
- bool _burstDigivolved = false;
- int[] _appFusionFrameIDs = null;
- bool _appFusion = false;
- bool _isBreedingArea = false;
- bool _isPlayOption = false;
- public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
- public bool isAppFusion => _appFusionFrameIDs != null && _appFusionFrameIDs.Length == 2;
- public IEnumerator PlayPermanent()
- {
- List<OnEnterFieldHashtableParams> hashtableParams = new List<OnEnterFieldHashtableParams>();
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- bool isEvolution = false;
- foreach (CardSource card in _cardSources)
- {
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- if (GManager.instance.GetComponent<SelectDigiXrosClass>().playCard == card)
- {
- _digiXrosCount = GManager.instance.GetComponent<SelectDigiXrosClass>().selectedDigicrossCards.Count;
- }
- if (GManager.instance.GetComponent<SelectAssemblyClass>().playCard == card)
- {
- _assemblyCount = GManager.instance.GetComponent<SelectAssemblyClass>().selectedAssemblyCards.Count;
- }
- bool isFromDigimonDigivolutionCards = card.Owner.GetBattleAreaDigimons().Some((permanent) => permanent.DigivolutionCards.Contains(card));
- bool isFromSecurity = card.Owner.SecurityCards.Contains(card);
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- GManager.instance.turnStateMachine.isSync = true;
- Permanent permanent = null;
- isEvolution = false;
- List<CardSource> evoRoots = new List<CardSource>();
- List<CardSource> evoRootTops = new List<CardSource>();
- bool played = false;
- List<int> oldLevels = new List<int>();
- int frameId = -1;
- if (_targetPermanent == null)
- {
- if (_isBreedingArea)
- {
- if (card.Owner.GetBreedingAreaPermanents().Count == 0)
- {
- FieldCardFrame digieggFrame = card.Owner.fieldCardFrames.Find(fieldCardFrame =>
- fieldCardFrame.IsEmptyFrame()
- && !fieldCardFrame.IsBattleAreaFrame()
- && card.CanPlayCardTargetFrame(fieldCardFrame, false, CardEffect, isBreedingArea: _isBreedingArea));
- if (digieggFrame != null)
- {
- frameId = digieggFrame.FrameID;
- }
- }
- }
- else
- {
- FieldCardFrame preferredFrame = card.PreferredFrame();
- if (preferredFrame != null)
- {
- frameId = preferredFrame.FrameID;
- }
- }
- }
- else
- {
- frameId = _targetPermanent.PermanentFrame.FrameID;
- }
- if (!isJogress)
- {
- if (!(0 <= frameId && frameId < card.Owner.fieldCardFrames.Count))
- {
- foreach (FieldCardFrame fieldCardFrame in card.Owner.fieldCardFrames)
- {
- if (card.CanPlayCardTargetFrame(fieldCardFrame, false, CardEffect, isBreedingArea: _isBreedingArea))
- {
- if (fieldCardFrame.IsEmptyFrame())
- {
- frameId = fieldCardFrame.FrameID;
- break;
- }
- }
- }
- }
- if (0 <= frameId && frameId < card.Owner.fieldCardFrames.Count)
- {
- played = true;
- if (_targetPermanent != null)
- {
- isEvolution = true;
- }
- else
- {
- if (!CardEffectCommons.CanPlayAsNewPermanent(card, false, CardEffect, isBreedingArea: _isBreedingArea, isPlayOption: _isPlayOption))
- {
- played = false;
- }
- }
- if (played)
- {
- card.Init();
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- if (isEvolution)
- {
- oldLevels.Add(_targetPermanent.Level);
- PlayLog.OnAddLog?.Invoke($"\nEvolution:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- permanent = _targetPermanent;
- evoRoots.Add(_targetPermanent.TopCard);
- evoRootTops.Add(_targetPermanent.TopCard);
- permanent.AddCardSource(card);
- }
- else
- {
- if(card.IsToken)
- PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity} token\n");
- else
- PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = _isTapped };
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, frameId));
- permanent.EnterFieldTurnCount = GManager.instance.turnStateMachine.TurnCount;
- }
- GManager.instance.turnStateMachine.isSync = true;
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- if (!isEvolution)
- {
- #region wheter to have ETB effects
- Hashtable hashtable = CardEffectCommons.OnEnterFieldHashtable(
- hashtableParams: new List<OnEnterFieldHashtableParams>()
- {
- new OnEnterFieldHashtableParams(
- permanent: permanent,
- evoRoots: evoRoots,
- evoRootTops: evoRootTops,
- root: _root,
- oldLevels: oldLevels,
- isFromDigimonDigivolutionCards:isFromDigimonDigivolutionCards
- )
- },
- isEvolution: isEvolution,
- isJogress: isJogress,
- digiXrosCount: _digiXrosCount,
- assemblyCount: _assemblyCount,
- cardEffect: CardEffect);
- bool HasETB = permanent.EffectList(EffectTiming.OnEnterFieldAnyone).Some(cardEffect =>
- cardEffect is ActivateICardEffect && cardEffect.CanUse(hashtable) && _activateETB && cardEffect.IsOnPlay);
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, HasETB: HasETB, isDigiXros: _digiXrosCount >= 1));
- }
- else
- {
- bool isBlast = CardEffect != null && CardEffect.EffectName != null && CardEffect.EffectName.Contains("Blast");
- //effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DigivolveFieldPermanentCardEffect(permanent.ShowingPermanentCard, _burstDigivolved, isBlast, _appFusion));
- }
- }
- }
- }
- }
- else
- {
- if (_jogressEvoRootsFrameIDs.Length == 2)
- {
- played = true;
- card.Init();
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- isEvolution = true;
- List<Permanent> evoRootPermanents = new List<Permanent>();
- for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
- {
- int frameID = _jogressEvoRootsFrameIDs[i];
- Permanent evoRoot = card.Owner.fieldCardFrames[frameID].GetFramePermanent();
- if (evoRoot != null)
- {
- if (evoRoot.TopCard != null)
- {
- evoRootPermanents.Add(evoRoot);
- }
- }
- }
- int targetFrameID = evoRootPermanents[0].PermanentFrame.FrameID;
- foreach (Permanent evoRootPermanent in evoRootPermanents)
- {
- evoRoots.Add(evoRootPermanent.TopCard);
- }
- List<CardSource> newDigivolutionCards = evoRootPermanents
- .Map(evoRootPermanent => evoRootPermanent.cardSources)
- .Flat();
- foreach (Permanent evoRootPermanent in evoRootPermanents)
- {
- oldLevels.Add(evoRootPermanent.Level);
- evoRootTops.Add(evoRootPermanent.TopCard);
- }
- foreach (Permanent evoRootPermanent in evoRootPermanents)
- {
- yield return ContinuousController.instance.StartCoroutine(evoRootPermanent.DiscardEvoRoots(ignoreOverflow: true, putToTrash: false));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(evoRootPermanent, ignoreOverflow: true));
- }
- PlayLog.OnAddLog?.Invoke($"\nJogress:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = false };
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, targetFrameID));
- permanent.EnterFieldTurnCount = -1;
- newDigivolutionCards.Reverse();
- yield return ContinuousController.instance.StartCoroutine(permanent.AddDigivolutionCardsTop(newDigivolutionCards, null));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, isDigiXros: false, jogressEvoRoots: evoRootTops.ToArray()));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(evoRootTops, "DNA Digivolution Cards", true, true));
- foreach (CardSource evolutionCard in permanent.DigivolutionCards)
- {
- evolutionCard.cEntity_EffectController.InitUseCountThisTurn();
- }
- }
- }
- if (played)
- {
- if (isFromSecurity)
- {
- yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
- player: card.Owner,
- refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
- CardEffectCommons.GetCardEffectFromHashtable(_hashtable)).ReduceSecurity());
- }
- if (isEvolution)
- {
- card.Owner.DigivolveCount_ThisTurn++;
- yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, null).Draw());
- if (_burstDigivolved)
- {
- if (permanent.TopCard != null)
- {
- permanent.IsBurstDigivolved = true;
- GManager.instance.selectBurstDigivolutionEffect.AddTrashTopCardAtTurnEnd(permanent);
- }
- }
- if (_appFusion)
- {
- if (permanent.TopCard != null)
- {
- permanent.IsAppFusion = true;
- }
- }
- permanent.CardNamesJustAfterDigivolved = permanent.TopCard.CardNames.Clone();
- permanent.DigivolvingEffect = CardEffect;
- }
- else
- {
- permanent.PlayingEffect = CardEffect;
- if (permanent.TopCard.HasLevel)
- {
- permanent.LevelJustAfterPlayed = permanent.Level;
- }
- if (permanent.TopCard.HasPlayCost)
- {
- permanent.PlayCostJustAfterPlayed = permanent.TopCard.GetCostItself;
- }
- permanent.CardNamesJustAfterPlayed = permanent.TopCard.CardNames.Clone();
- permanent.TraitsJustAfterPlayed = permanent.TopCard.CardTraits.Clone();
- }
- #region move permanents (hybrid)
- if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
- {
- if (permanent.TopCard.PreferredFrame() != null)
- {
- if (permanent.PermanentFrame != permanent.TopCard.PreferredFrame())
- {
- if (permanent.TopCard.PreferredFrame().IsEmptyFrame())
- {
- bool move = false;
- if (permanent.IsDigimon)
- {
- if (permanent.TopCard.Owner.isYou)
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
- {
- move = true;
- }
- }
- else
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
- {
- move = true;
- }
- }
- }
- else if (permanent.IsTamer || permanent.TopCard.IsOption)
- {
- if (permanent.TopCard.Owner.isYou)
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
- {
- move = true;
- }
- }
- else
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
- {
- move = true;
- }
- }
- }
- if (move)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.MovePermanent(permanent.PermanentFrame));
- }
- }
- }
- }
- }
- #endregion
- yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCardsByEffect(card);
- yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCards(card);
- yield return GManager.instance.GetComponent<SelectAssemblyClass>().AddDigivolutiuonCardsByEffect(card);
- yield return GManager.instance.GetComponent<SelectAssemblyClass>().AddDigivolutiuonCards(card);
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- hashtableParams.Add(
- new OnEnterFieldHashtableParams(
- permanent: permanent,
- evoRoots: evoRoots,
- evoRootTops: evoRootTops,
- root: _root,
- oldLevels: oldLevels,
- isFromDigimonDigivolutionCards: isFromDigimonDigivolutionCards
- )
- );
- }
- }
- GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
- GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
- GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
- yield return GManager.instance.photonWaitController.StartWait("EndPlayPermanent");
- }
- // except [On Play] effect
- bool CardEffectCondition(ICardEffect cardEffect)
- {
- if (cardEffect == null)
- {
- return false;
- }
- if (!_activateETB)
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.IsOnPlay)
- {
- return false;
- }
- }
- }
- return true;
- }
- Hashtable effectHashtable = CardEffectCommons.OnEnterFieldHashtable(
- hashtableParams: hashtableParams,
- isEvolution: isEvolution,
- isJogress: isJogress,
- digiXrosCount: _digiXrosCount,
- assemblyCount: _assemblyCount,
- cardEffect: CardEffect);
- #region "When permanents are played" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
- hashtable: effectHashtable,
- timing: EffectTiming.OnEnterFieldAnyone,
- cardEffectCondition: CardEffectCondition));
- #endregion
- }
- }
- #endregion
- #region Use option
- public class UseOptionClass
- {
- public UseOptionClass(List<CardSource> cardSources, Hashtable hashtable, SelectCardEffect.Root root)
- {
- if (cardSources != null)
- {
- _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
- }
- _hashtable = hashtable;
- _root = root;
- }
- List<CardSource> _cardSources = new List<CardSource>();
- SelectCardEffect.Root _root = SelectCardEffect.Root.None;
- Hashtable _hashtable = null;
- public bool _showEffect = false;
- public bool _addSecurityEndOption = false;
- public IEnumerator UseOption()
- {
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- foreach (CardSource card in _cardSources)
- {
- if (_showEffect)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(card));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowUseHandCardEffect_PlayCard(card));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
- }
- PlayLog.OnAddLog?.Invoke($"\nPlay Option:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- card.Init();
- GManager.instance.turnStateMachine.isSync = true;
- card.SetFace("CardContoller.UseOption");
- int cost = card.GetCostItself;
- //Remove from all areas
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(card));
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.BrainStormCoroutine(card));
- #region Set HashTable
- Hashtable hashtable = new Hashtable()
- {
- {"Card", card},
- {"Root", _root},
- {"Cost", cost},
- };
- #endregion
- #region "When option is used" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseOption));
- yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.OnUseOption));
- #endregion
- #region effect process of option card
- foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.OptionSkill))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanUse(hashtable))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
- cardEffect,
- hashtable));
- }
- }
- }
- #endregion
- if (card.Owner.ExecutingCards.Contains(card))
- {
- if (_addSecurityEndOption && card.Owner.CanAddSecurity(CardEffect))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(card));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(card.Owner));
- yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(card.Owner).AddSecurity());
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(card));
- }
- }
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- yield return GManager.instance.photonWaitController.StartWait("EndPlayOption");
- }
- }
- }
- #endregion
- #region Draw cards
- public class DrawClass
- {
- public DrawClass(Player player, int drawCount, ICardEffect cardEffect)
- {
- _player = player;
- _drawCount = drawCount;
- _cardEffect = cardEffect;
- }
- Player _player = null;
- int _drawCount = 0;
- ICardEffect _cardEffect = null;
- public IEnumerator Draw()
- {
- if (_drawCount <= 0) yield break;
- if (_player.LibraryCards.Count <= 0) yield break;
- List<CardSource> DrawCards = new List<CardSource>();
- for (int i = 0; i < _drawCount; i++)
- {
- if (_player.LibraryCards.Count > 0)
- {
- CardSource DrawCard = _player.LibraryCards[0];
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(DrawCard));
- DrawCards.Add(DrawCard);
- }
- }
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(DrawCards, true, _cardEffect));
- #region add log
- if (DrawCards.Count >= 1)
- {
- PlayLog.OnAddLog?.Invoke($"\nDraw {DrawCards.Count} card{Utils.PluralFormSuffix(DrawCards.Count)}\n{_player.PlayerName}\n");
- }
- #endregion
- #region "When draw cards" effect
- if (DrawCards.Count >= 1)
- {
- #region Hashtable setting
- Hashtable _hashtable = new Hashtable()
- {
- {"Player", _player},
- {"CardEffect", _cardEffect}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnDraw));
- }
- #endregion
- }
- }
- #endregion
- #region Trash cards from deck too
- public class IAddTrashCardsFromLibraryTop
- {
- public IAddTrashCardsFromLibraryTop(int addTrashCount, Player player, ICardEffect cardEffect)
- {
- _addTrashCount = addTrashCount;
- _player = player;
- _cardEffect = cardEffect;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- int _addTrashCount;
- Player _player;
- public List<CardSource> discardedCards = new List<CardSource>();
- ICardEffect _cardEffect { get; set; } = null;
- bool _notShowCards = false;
- public IEnumerator AddTrashCardsFromLibraryTop()
- {
- if (_addTrashCount <= 0) yield break;
- if (_player.LibraryCards.Count == 0) yield break;
- string log = "";
- log += $"\nTrash cards from deck :";
- for (int i = 0; i < _addTrashCount; i++)
- {
- if (_player.LibraryCards.Count > i)
- {
- CardSource DiscardCard = _player.LibraryCards[i];
- discardedCards.Add(DiscardCard);
- log += $"\n{DiscardCard.BaseENGCardNameFromEntity}({DiscardCard.CardID})";
- }
- }
- if (discardedCards.Count >= 1)
- {
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
- }
- }
- yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(discardedCards, _cardEffect).TrashDeckCards());
- if (discardedCards.Count >= 1)
- {
- for (int i = 0; i < discardedCards.Count; i++)
- {
- ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
- yield return new WaitForSeconds(0.06f);
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- }
- }
- #endregion
- #region Add security from deck top
- public class IAddSecurityFromLibrary
- {
- public IAddSecurityFromLibrary(Player player, int addLifeCount)
- {
- _player = player;
- _addSecurityCount = addLifeCount;
- }
- Player _player = null;
- int _addSecurityCount = 0;
- public IEnumerator AddSecurity()
- {
- int count = 0;
- for (int i = 0; i < _addSecurityCount; i++)
- {
- if (_player.LibraryCards.Count > 0)
- {
- CardSource StockCard = _player.LibraryCards[0];
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(StockCard));
- count++;
- }
- }
- if (count > 0)
- {
- string log = "";
- log += $"\nAdd {count} cards to security:{_player.PlayerName}";
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(_player).AddSecurity());
- }
- }
- }
- }
- #endregion
- #region Recovery
- public class IRecovery
- {
- public IRecovery(Player player, int AddLifeCount, ICardEffect cardEffect)
- {
- _player = player;
- _addLifeCount = AddLifeCount;
- _cardEffect = cardEffect;
- }
- Player _player = null;
- int _addLifeCount = 0;
- ICardEffect _cardEffect = null;
- public IEnumerator Recovery()
- {
- if (_player.LibraryCards.Count == 0) yield break;
- if (_addLifeCount <= 0) yield break;
- if (!_player.CanAddSecurity(_cardEffect)) yield break;
- yield return ContinuousController.instance.StartCoroutine(new IAddSecurityFromLibrary(_player, _addLifeCount).AddSecurity());
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(_player));
- }
- }
- #endregion
- #region Digi-Burst
- public class IDigiBurst
- {
- public IDigiBurst(Permanent permanent, int DigiBurstCount, ICardEffect cardEffect)
- {
- _permanent = permanent;
- _digiBurstCount = DigiBurstCount;
- _cardEffect = cardEffect;
- }
- Permanent _permanent = null;
- int _digiBurstCount = 0;
- ICardEffect _cardEffect = null;
- bool _upToMaxCount = false;
- public List<CardSource> discardedCards = new List<CardSource>();
- public void SetUpToMaxCount()
- {
- _upToMaxCount = true;
- }
- public bool CanDigiBurst()
- {
- if (_permanent != null)
- {
- if (_permanent.TopCard != null)
- {
- if (_permanent.ImmuneFromStackTrashing(_cardEffect)) return false;
- if (_upToMaxCount)
- {
- if (_permanent.DigivolutionCards.Some((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)))
- {
- return true;
- }
- }
- else
- {
- if (_permanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)) >= _digiBurstCount)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- public IEnumerator DigiBurst()
- {
- if (CanDigiBurst())
- {
- discardedCards = new List<CardSource>();
- List<CardSource> selectedCards = new List<CardSource>();
- SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
- selectCardEffect.SetUp(
- canTargetCondition: (cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect),
- canTargetCondition_ByPreSelecetedList: null,
- canEndSelectCondition: CanEndSelectCondition,
- canNoSelect: () => false,
- selectCardCoroutine: SelectCardCoroutine,
- afterSelectCardCoroutine: null,
- message: "Select digivolution cards to discard.",
- maxCount: _digiBurstCount,
- canEndNotMax: _upToMaxCount,
- isShowOpponent: true,
- mode: SelectCardEffect.Mode.Custom,
- root: SelectCardEffect.Root.Custom,
- customRootCardList: _permanent.DigivolutionCards,
- canLookReverseCard: true,
- selectPlayer: _permanent.TopCard.Owner,
- cardEffect: null);
- selectCardEffect.SetUpCustomMessage("Select digivolution cards to discard.", "The opponent is selecting digivolution cards to discard.");
- yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
- bool CanEndSelectCondition(List<CardSource> cardSources)
- {
- if (CardEffectCommons.HasNoElement(cardSources))
- {
- return false;
- }
- return true;
- }
- IEnumerator SelectCardCoroutine(CardSource cardSource)
- {
- selectedCards.Add(cardSource);
- yield return null;
- }
- if (selectedCards.Count >= 1)
- {
- #region "When use Digi-Burst" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"Permanent", _permanent},
- {"CardEffect", _cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseDigiburst));
- #endregion
- // trash digivolution cards
- yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(_permanent, selectedCards, _cardEffect).TrashDigivolutionCards());
- foreach (CardSource cardSource in selectedCards)
- {
- discardedCards.Add(cardSource);
- }
- #region add log
- if (selectedCards.Count >= 1)
- {
- string log = "";
- log += $"\nDigiburst :";
- foreach (CardSource cardSource in selectedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- }
- }
- #endregion
- #region Place permanents to deck bottom
- public class DeckBottomBounceClass
- {
- public DeckBottomBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
- {
- _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
- _hashtable = hashtable;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- public bool IsDeckBounced(Permanent permanent)
- {
- return DeckBouncedPermanents.Contains(permanent);
- }
- List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
- public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
- Hashtable _hashtable = new Hashtable();
- bool _notShowCards = false;
- public IEnumerator DeckBounce()
- {
- if (_deckBounceTargetPermanents == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && (cardEffect == null ||
- (!permanent.TopCard.CanNotBeAffected(cardEffect)
- && !permanent.CannotReturnToLibrary(cardEffect)
- && permanent.CanBeRemoved())));
- if (_deckBounceTargetPermanents.Count == 0) yield break;
- _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
- #region cut in effect
- // "When permanents would return to deck" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _deckBounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenReturntoLibraryAnyone));
- // "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _deckBounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- permanent.ShowDeckBounceEffect();
- }
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- permanent.HideDeckBounceEffect();
- }
- }
- #endregion
- // fix deck bounce target permanents
- List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && permanent.willBeRemoveField);
- #region show cards
- List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
- }
- #endregion
- #region
- List<CardSource> deckBottomCards = new List<CardSource>();
- foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
- {
- #region recoed used effect
- if (permanent.TopCard != null)
- {
- permanent.LibraryBounceEffect = cardEffect;
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
- yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
- CardSource topCard = permanent.TopCard;
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
- deckBottomCards.Add(topCard);
- DeckBouncedPermanents.Add(permanent);
- }
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(deckBottomCards));
- #endregion
- #region off icon
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- permanent.willBeRemoveField = false;
- }
- }
- }
- #endregion
- }
- }
- #endregion
- #region Return permanent to hand
- public class HandBounceClaass
- {
- public HandBounceClaass(List<Permanent> bounceTargetPermanents, Hashtable hashtable)
- {
- _bounceTargetPermanents = bounceTargetPermanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
- _hashtable = hashtable;
- }
- public bool IsBounced(Permanent permanent)
- {
- return BouncedPermanents.Contains(permanent);
- }
- List<Permanent> _bounceTargetPermanents = new List<Permanent>();
- public List<Permanent> BouncedPermanents { get; private set; } = new List<Permanent>();
- Hashtable _hashtable = new Hashtable();
- bool _notShowCards = false;
- public IEnumerator Bounce()
- {
- if (_bounceTargetPermanents == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- _bounceTargetPermanents = _bounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && (cardEffect == null ||
- (!permanent.TopCard.CanNotBeAffected(cardEffect)
- && !permanent.CannotReturnToHand(cardEffect)
- && permanent.CanBeRemoved())));
- if (_bounceTargetPermanents.Count == 0) yield break;
- _bounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
- #region cut in effect
- // "When permanents would return to hand" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _bounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenReturntoHandAnyone));
- // "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _bounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- foreach (Permanent permanent in _bounceTargetPermanents)
- {
- permanent.ShowHandBounceEffect();
- }
- // shrink security Digimon display
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent permanent in _bounceTargetPermanents)
- {
- permanent.HideHandBounceEffect();
- }
- }
- #endregion
- // fix bounce target permanents
- List<Permanent> bounceTargetPermanents_Fixed = _bounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && permanent.willBeRemoveField);
- #region "When permanents returned to hand" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
- .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
- bounceTargetPermanents_Fixed,
- cardEffect,
- null,
- false
- ),
- EffectTiming.OnPermamemtReturnedToHand));
- #endregion
- #region record parameter just before bounce
- foreach (Permanent permanent in bounceTargetPermanents_Fixed)
- {
- permanent.DPJustBeforeRemoveField = permanent.DP;
- if (permanent.TopCard.HasLevel)
- {
- permanent.LevelJustBeforeRemoveField = permanent.Level;
- }
- if (permanent.TopCard.HasPlayCost)
- {
- permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
- }
- permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
- permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
- foreach (CardSource cardSource in permanent.cardSources)
- {
- cardSource.PermanentJustBeforeRemoveField = permanent;
- }
- }
- #endregion
- #region add log
- if (bounceTargetPermanents_Fixed.Count >= 1)
- {
- string log = "";
- log += $"\nReturn to hand:";
- foreach (Permanent permanent in bounceTargetPermanents_Fixed)
- {
- log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- #region show cards
- List<CardSource> returnedCards = bounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Cards returned to hand", true, true));
- }
- #endregion
- #region return permanent cards to hand
- List<CardSource> handCards = new List<CardSource>();
- foreach (Permanent permanent in bounceTargetPermanents_Fixed)
- {
- #region record used effect
- if (permanent.TopCard != null)
- {
- permanent.HandBounceEffect = cardEffect;
- }
- #endregion
- // record whether to return to hand by Burst Digivolution
- permanent.IsReturnedToHandByBurstDigivolution = CardEffectCommons.IsBurst(_hashtable);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BounceEffect(permanent, !permanent.IsReturnedToHandByBurstDigivolution));
- yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
- CardSource topCard = permanent.TopCard;
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(topCard));
- if (!topCard.IsDigiEgg)
- {
- handCards.Add(topCard);
- BouncedPermanents.Add(permanent);
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
- }
-
- }
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
- #endregion
- #region hide icon
- foreach (Permanent permanent in _bounceTargetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- permanent.willBeRemoveField = false;
- }
- }
- }
- #endregion
- }
- }
- #endregion
- #region Place permanent to another permanent's digivolution cards
- public class IPlacePermanentToDigivolutionCards
- {
- public IPlacePermanentToDigivolutionCards(
- List<Permanent[]> permanentArrays,
- bool toTop,
- ICardEffect cardEffect,
- bool skipEffectAndActivateSkill = false)
- {
- permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
- _toTop = toTop;
- _cardEffect = cardEffect;
- _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- List<Permanent[]> _permanentArrays = new List<Permanent[]>();
- ICardEffect _cardEffect = null;
- bool _toTop = false;
- bool _notShowCards = false;
- bool _skipEffectAndActivateSkill = false;
- public bool Placed { get; private set; } = false;
- public IEnumerator PlacePermanentToDigivolutionCards()
- {
- if (_permanentArrays.Count == 0)
- {
- yield break;
- }
- List<CardSource> addedDigivolutionCards = new List<CardSource>();
- List<Permanent> removeFieldPermanents = new List<Permanent>();
- foreach (Permanent[] permanentArray in _permanentArrays)
- {
- if (permanentArray.Length == 2)
- {
- Permanent DigivolutionPermanent = permanentArray[0];
- Permanent getDigivolutionPermanent = permanentArray[1];
- if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
- {
- if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
- {
- if (_cardEffect != null)
- {
- if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
- {
- continue;
- }
- }
- removeFieldPermanents.Add(DigivolutionPermanent);
- }
- }
- }
- }
- foreach (Permanent permanent in removeFieldPermanents)
- {
- permanent.willBeRemoveField = true;
- }
- if (removeFieldPermanents.Count == 0)
- {
- yield break;
- }
- #region
- List<SkillInfo> skillInfos = new List<SkillInfo>();
- Hashtable hashtable1 =
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- removeFieldPermanents,
- _cardEffect,
- null);
- #region "When permanents would remove field" effect
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- #region permanents' effects
- foreach (Permanent permanent1 in player.GetFieldPermanents())
- {
- foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanTrigger(hashtable1))
- {
- skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
- }
- }
- }
- }
- #endregion
- #region players' effects
- foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanTrigger(hashtable1))
- {
- skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
- }
- }
- }
- #endregion
- }
- #endregion
- if (skillInfos.Count >= 1)
- {
- foreach (SkillInfo skillInfo in skillInfos)
- {
- GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
- }
- bool showEffect()
- {
- if (skillInfos.Count >= 2)
- {
- return true;
- }
- else if (skillInfos.Count == 1)
- {
- if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
- {
- return true;
- }
- }
- return false;
- }
- if (showEffect())
- {
- foreach (Permanent Permanent in removeFieldPermanents)
- {
- if (Permanent != null)
- {
- if (Permanent.TopCard != null)
- {
- if (Permanent.willBeRemoveField)
- {
- if (Permanent.ShowingPermanentCard != null)
- {
- if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
- {
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
- }
- }
- }
- }
- }
- }
- #region shrink security Digimon display
- if (GManager.instance.attackProcess.IsAttacking)
- {
- if (GManager.instance.attackProcess.SecurityDigimon != null)
- {
- if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
- }
- }
- }
- #endregion
- }
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent Permanent in removeFieldPermanents)
- {
- if (Permanent != null)
- {
- if (Permanent.TopCard != null)
- {
- if (Permanent.ShowingPermanentCard != null)
- {
- if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
- {
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
- }
- }
- }
- }
- }
- }
- #endregion
- foreach (Permanent[] permanentArray in _permanentArrays)
- {
- if (permanentArray.Length == 2)
- {
- Permanent DigivolutionPermanent = permanentArray[0];
- Permanent getDigivolutionPermanent = permanentArray[1];
- if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
- {
- if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
- {
- yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
- CardSource cardSource = DigivolutionPermanent.TopCard;
- #region record used effect
- if (_cardEffect != null)
- {
- if (DigivolutionPermanent.TopCard != null)
- {
- DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
- }
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
- DigivolutionPermanent,
- ignoreOverflow: true));
- List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
- if (_toTop)
- {
- yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
- }
- cardSource.cEntity_EffectController.InitUseCountThisTurn();
- addedDigivolutionCards.Add(cardSource);
- Placed = true;
- }
- }
- }
- }
- #region add log
- if (addedDigivolutionCards.Count >= 1)
- {
- string log = "";
- log += $"\nPlace in digivolution cards:";
- foreach (CardSource cardSource in addedDigivolutionCards)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- #region hide icon
- if (addedDigivolutionCards.Count >= 1)
- {
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
- }
- }
- #endregion
- }
- }
- #endregion
- #region Place permanent to another permanent's Link cards
- public class IPlacePermanentToLinkCards
- {
- public IPlacePermanentToLinkCards(
- List<Permanent[]> permanentArrays,
- ICardEffect cardEffect,
- bool skipEffectAndActivateSkill = false)
- {
- permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
- _cardEffect = cardEffect;
- _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- List<Permanent[]> _permanentArrays = new List<Permanent[]>();
- ICardEffect _cardEffect = null;
- bool _notShowCards = false;
- bool _skipEffectAndActivateSkill = false;
- public bool Placed { get; private set; } = false;
- public IEnumerator PlacePermanentToLinkCards()
- {
- if (_permanentArrays.Count == 0)
- {
- yield break;
- }
- List<CardSource> addedLinkCards = new List<CardSource>();
- List<Permanent> removeFieldPermanents = new List<Permanent>();
- foreach (Permanent[] permanentArray in _permanentArrays)
- {
- if (permanentArray.Length == 2)
- {
- Permanent LinkedPermanent = permanentArray[0];
- Permanent getLinkPermanent = permanentArray[1];
- if (LinkedPermanent != null && getLinkPermanent != null)
- {
- if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken)
- {
- if (_cardEffect != null)
- {
- if (LinkedPermanent.TopCard.CanNotBeAffected(_cardEffect) || getLinkPermanent.TopCard.CanNotBeAffected(_cardEffect))
- {
- continue;
- }
- }
- removeFieldPermanents.Add(LinkedPermanent);
- }
- }
- }
- }
- foreach (Permanent permanent in removeFieldPermanents)
- {
- permanent.willBeRemoveField = true;
- }
- if (removeFieldPermanents.Count == 0)
- {
- yield break;
- }
- #region Cut in Effects
- List<SkillInfo> skillInfos = new List<SkillInfo>();
- Hashtable hashtable1 =
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- removeFieldPermanents,
- _cardEffect,
- null);
- #region "When permanents would remove field" effect
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- #region permanents' effects
- foreach (Permanent permanent1 in player.GetFieldPermanents())
- {
- foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanTrigger(hashtable1))
- {
- skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
- }
- }
- }
- }
- #endregion
- #region players' effects
- foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanTrigger(hashtable1))
- {
- skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
- }
- }
- }
- #endregion
- }
- #endregion
- if (skillInfos.Count >= 1)
- {
- foreach (SkillInfo skillInfo in skillInfos)
- {
- GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
- }
- bool showEffect()
- {
- if (skillInfos.Count >= 2)
- {
- return true;
- }
- else if (skillInfos.Count == 1)
- {
- if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
- {
- return true;
- }
- }
- return false;
- }
- if (showEffect())
- {
- foreach (Permanent Permanent in removeFieldPermanents)
- {
- if (Permanent != null)
- {
- if (Permanent.TopCard != null)
- {
- if (Permanent.willBeRemoveField)
- {
- if (Permanent.ShowingPermanentCard != null)
- {
- if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
- {
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
- }
- }
- }
- }
- }
- }
- #region shrink security Digimon display
- if (GManager.instance.attackProcess.IsAttacking)
- {
- if (GManager.instance.attackProcess.SecurityDigimon != null)
- {
- if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
- }
- }
- }
- #endregion
- }
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent Permanent in removeFieldPermanents)
- {
- if (Permanent != null)
- {
- if (Permanent.TopCard != null)
- {
- if (Permanent.ShowingPermanentCard != null)
- {
- if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
- {
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
- }
- }
- }
- }
- }
- }
- #endregion
- foreach (Permanent[] permanentArray in _permanentArrays)
- {
- if (permanentArray.Length == 2)
- {
- Permanent LinkedPermanent = permanentArray[0];
- Permanent getLinkPermanent = permanentArray[1];
- if (LinkedPermanent != null && getLinkPermanent != null)
- {
- if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken && LinkedPermanent.willBeRemoveField)
- {
- yield return ContinuousController.instance.StartCoroutine(LinkedPermanent.DiscardEvoRoots());
- CardSource cardSource = LinkedPermanent.TopCard;
- #region record used effect
- if (_cardEffect != null)
- {
- if (LinkedPermanent.TopCard != null)
- {
- LinkedPermanent.PlaceOtherPermanentEffect = _cardEffect;
- }
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
- LinkedPermanent,
- ignoreOverflow: true));
- yield return ContinuousController.instance.StartCoroutine(getLinkPermanent.AddLinkCard(cardSource, _cardEffect));
- cardSource.cEntity_EffectController.InitUseCountThisTurn();
- addedLinkCards.Add(cardSource);
- Placed = true;
- }
- }
- }
- }
- #region add log
- if (addedLinkCards.Count >= 1)
- {
- string log = "";
- log += $"\nLink cards:";
- foreach (CardSource cardSource in addedLinkCards)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- #region hide icon
- if (addedLinkCards.Count >= 1)
- {
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedLinkCards, "Link Cards", true, true));
- }
- }
- #endregion
- }
- }
- #endregion
- #region Place permanents to security
- public class IPutSecurityPermanent
- {
- public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop, bool isFaceup = false)
- {
- _permanent = permanent;
- _hashtable = hashtable;
- _toTop = toTop;
- _isFaceup = isFaceup;
- }
- Permanent _permanent = null;
- Hashtable _hashtable = new Hashtable();
- bool _toTop = false;
- bool _isFaceup = false;
- public IEnumerator PutSecurity()
- {
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
- if (!_permanent.CanBeRemoved()) yield break;
- _permanent.willBeRemoveField = true;
- #region "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- new List<Permanent>() { _permanent },
- cardEffect,
- null
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- _permanent.ShowWillRemoveFieldEffect();
- //effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false,null));
- _permanent.HideWillRemoveFieldEffect();
- }
- #endregion
- CardSource topCard = _permanent.TopCard;
- if (!_permanent.willBeRemoveField)
- yield break;
- if (topCard == null)
- yield break;
- #region add log
- string log = "";
- string fromString = _toTop ? "top" : "bottom";
- log += $"\nPut cards on {fromString} of security:";
- log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- #endregion
- #region show cards
- if (!topCard.IsToken)
- {
- if (_toTop)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
- }
- }
- #endregion
- #region place permanent to security
- yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
- if (!topCard.IsToken)
- {
- if (!topCard.IsDigiEgg)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard,faceUp:_isFaceup));
- if (!_isFaceup)
- topCard.SetReverse();
- else
- topCard.SetFace("CardController.PutSecurity");
- if (!_toTop)
- {
- topCard.Owner.SecurityCards.Remove(topCard);
- topCard.Owner.SecurityCards.Add(topCard);
- }
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
- yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard.Owner).AddSecurity());
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
- }
- }
- #endregion
- }
- }
- #endregion
- #region Delete permanents
- public class DestroyPermanentsClass
- {
- public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
- {
- _destroytargetPermanents = destroyTargetPermanents.Clone();
- _hashtable = hashtable;
- _notShowCards = notShowCards;
- }
- public bool IsDestroyed(Permanent permanent)
- {
- return DestroyedPermanents.Contains(permanent);
- }
- List<Permanent> _destroytargetPermanents = new List<Permanent>();
- public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
- Hashtable _hashtable = null;
- bool _notShowCards = false;
- public IEnumerator Destroy()
- {
- if (_destroytargetPermanents == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
- bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
- _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && (cardEffect == null ||
- (!permanent.TopCard.CanNotBeAffected(cardEffect)
- && permanent.CanBeDestroyedBySkill(cardEffect))));
- if (_destroytargetPermanents.Count == 0) yield break;
- _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
- #region cut in effect
- // "When permanents would be deleted" effect
-
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _destroytargetPermanents,
- cardEffect,
- battle
- ),
- EffectTiming.WhenPermanentWouldBeDeleted));
- // "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _destroytargetPermanents,
- cardEffect,
- battle
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- foreach (Permanent permanent in _destroytargetPermanents)
- {
- permanent.ShowDeleteEffect();
- }
- // effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent permanent in _destroytargetPermanents)
- {
- permanent.HideDeleteEffect();
- }
- }
- #endregion
- // fix delete target permanents
- List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && permanent.willBeRemoveField);
- #region "When permanents are deleted" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
- .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
- destroyTargetPermanents_Fixed,
- cardEffect,
- battle,
- isDPZero
- ),
- EffectTiming.OnDestroyedAnyone));
- #endregion
- #region record parameters just before deletion
- foreach (Permanent permanent in destroyTargetPermanents_Fixed)
- {
- permanent.DPJustBeforeRemoveField = permanent.DP;
- if (permanent.TopCard.HasLevel)
- {
- permanent.LevelJustBeforeRemoveField = permanent.Level;
- }
- if (permanent.TopCard.HasPlayCost)
- {
- permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
- }
- permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
- permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
- foreach (CardSource cardSource in permanent.cardSources)
- {
- cardSource.PermanentJustBeforeRemoveField = permanent;
- }
- }
- #endregion
- #region add log
- if (destroyTargetPermanents_Fixed.Count >= 1)
- {
- string log = "";
- log += $"\nDelete:";
- foreach (Permanent permanent in destroyTargetPermanents_Fixed)
- {
- log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- #region show cards
- List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
- }
- #endregion
- #region trash permanent cards
- foreach (Permanent permanent in destroyTargetPermanents_Fixed)
- {
- #region record wheter to be deleted by battle
- if (battle != null)
- {
- if (permanent.TopCard != null)
- {
- if(CardEffectCommons.GetLoserPermanentsFromHashtable(battle.hashtable).Contains(permanent))
- permanent.IsDestroyedByBattle = true;
- }
- }
- #endregion
- #region record used effect
- if (permanent.TopCard != null)
- {
- permanent.DestroyingEffect = cardEffect;
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
- yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
- CardSource topCard = permanent.TopCard;
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
- DestroyedPermanents.Add(permanent);
- }
- #endregion
- #region hide icon
- foreach (Permanent permanent in _destroytargetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- permanent.willBeRemoveField = false;
- }
- }
- }
- #endregion
- }
- }
- #endregion
- #region Security check
- public class ISecurityCheck
- {
- public ISecurityCheck(Permanent AttackingPermanent, Player player)
- {
- this.AttackingPermanent = AttackingPermanent;
- this.player = player;
- }
- Permanent AttackingPermanent { get; set; }
- Player player { get; set; }
- public IEnumerator SecurityCheck()
- {
- bool StopSecurityCheck()
- {
- if (AttackingPermanent == null)
- {
- return true;
- }
- if (AttackingPermanent.TopCard == null)
- {
- return true;
- }
- if (!AttackingPermanent.IsDigimon)
- return true;
- return false;
- }
- if (!StopSecurityCheck())
- {
- if (AttackingPermanent.Strike == 0)
- {
- yield break;
- }
- GManager.instance.turnStateMachine.IsSelecting = true;
- GManager.instance.turnStateMachine.isSecurityCehck = true;
- #region loop while there are 1 or more security cards
- if (player.SecurityCards.Count >= 1)
- {
- int checkedCount = 0;
- while (true)
- {
- if (StopSecurityCheck())
- {
- break;
- }
- if (checkedCount >= AttackingPermanent.Strike)
- {
- break;
- }
- if (player.SecurityCards.Count >= 1)
- {
- List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
- CardSource brokenSecurityCard = player.SecurityCards[0];
- Hashtable hashtable = new Hashtable()
- {
- {"AttackingPermanent", AttackingPermanent},
- {"Card", brokenSecurityCard}
- };
- foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
- {
- triggeredSkillInfos.Add(skillInfo);
- }
- checkedCount++;
- PlayLog.OnAddLog?.Invoke($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
- if (brokenSecurityCard.IsDigimon)
- {
- GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
- }
- #region effect
- player.securityObject.securityBreakGlass.ShowBlueMatarial();
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
- yield return new WaitForSeconds(0.1f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
- yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
- player: brokenSecurityCard.Owner,
- refSkillInfos: ref triggeredSkillInfos).ReduceSecurity());
- #region security effect
- List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
- foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
- {
- if (cardEffect is ActivateICardEffect)
- {
- Hashtable hashtable1 = new Hashtable();
- hashtable1.Add("Card", brokenSecurityCard);
- if (cardEffect.CanUse(hashtable1))
- {
- secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
- }
- }
- }
- List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
- bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
- if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
- {
- if (!brokenSecurityCard.IsDigimon)
- {
- yield return new WaitForSeconds(0.3f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
- }
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
- yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
- List<SkillInfo> skillInfos = new List<SkillInfo>();
- foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
- {
- skillInfos.Add(skillInfo);
- }
- List<CardSource> cardSources = new List<CardSource>();
- for (int j = 0; j < skillInfos.Count; j++)
- {
- cardSources.Add(brokenSecurityCard);
- }
- while (skillInfos.Count >= 1)
- {
- SkillInfo selectedSkillInfo = null;
- if (skillInfos.Count == 1)
- {
- selectedSkillInfo = skillInfos[0];
- }
- else
- {
- SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
- selectCardEffect.SetUp(
- canTargetCondition: (cardSource) => true,
- canTargetCondition_ByPreSelecetedList: null,
- canEndSelectCondition: null,
- canNoSelect: () => false,
- selectCardCoroutine: null,
- afterSelectCardCoroutine: null,
- message: "select security effect",
- maxCount: 1,
- canEndNotMax: false,
- isShowOpponent: false,
- mode: SelectCardEffect.Mode.Custom,
- root: SelectCardEffect.Root.Custom,
- customRootCardList: cardSources,
- canLookReverseCard: true,
- selectPlayer: player,
- cardEffect: null);
- selectCardEffect.SetUpSkillInfos(skillInfos);
- selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
- selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
- yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
- IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
- {
- if (selectedIndexes.Count == 1)
- {
- selectedSkillInfo = skillInfos[selectedIndexes[0]];
- yield return null;
- }
- }
- }
- if (selectedSkillInfo != null)
- {
- ICardEffect cardEffect = selectedSkillInfo.CardEffect;
- Hashtable hashtable2 = selectedSkillInfo.Hashtable;
- if (cardEffect.EffectSourceCard == brokenSecurityCard)
- {
- if (cardEffect is ActivateICardEffect)
- {
- skillInfos.Remove(selectedSkillInfo);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
- cardEffect,
- hashtable2));
- }
- }
- }
- }
- }
- #endregion
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- // stack effect of "When cards are removed from security" and "checks secuirty"
- foreach (SkillInfo skillInfo in triggeredSkillInfos)
- {
- GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
- }
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- if (!StopSecurityCheck())
- {
- #region battle with security Digimon
- if (brokenSecurityCard.IsDigimon)
- {
- bool doBattle = true;
- #region "ignore battle" effect
- Hashtable hashtable3 = new Hashtable()
- {
- {"Card", brokenSecurityCard}
- };
- #region the security Digimon's effect
- foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
- {
- if (cardEffect is IDontBattleSecurityDigimonEffect)
- {
- if (cardEffect.CanUse(hashtable3))
- {
- if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
- {
- doBattle = false;
- }
- }
- }
- }
- #endregion
- #region player's effect
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
- {
- if (cardEffect is IDontBattleSecurityDigimonEffect)
- {
- if (cardEffect.CanUse(hashtable3))
- {
- if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
- {
- doBattle = false;
- }
- }
- }
- }
- }
- #endregion
- #endregion
- if (doBattle)
- {
- yield return new WaitForSeconds(0.3f);
- yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
- }
- }
- #endregion
- }
- #region effect
- yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
- if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
- if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
- }
- }
- GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
- GManager.instance.attackProcess.SecurityDigimon = null;
- #endregion
- // reset effect until end of security check
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
- }
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- GManager.instance.turnStateMachine.IsSelecting = true;
- }
- else
- {
- break;
- }
- }
- }
- #endregion
- GManager.instance.turnStateMachine.isSecurityCehck = false;
- }
- }
- }
- #endregion
- #region trash cards from security
- public class IDestroySecurity
- {
- public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
- {
- _player = player;
- _destroySecurityCount = destroySecurityCount;
- _cardEffect = cardEffect;
- _fromTop = fromTop;
- }
- Player _player = null;
- int _destroySecurityCount = 0;
- ICardEffect _cardEffect = null;
- bool _fromTop = false;
- public IEnumerator DestroySecurity()
- {
- bool StopDestroySecurity()
- {
- if (_player.SecurityCards.Count == 0)
- {
- return true;
- }
- if (!_player.CanReduceSecurity())
- {
- return true;
- }
- return false;
- }
- if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
- {
- int count = 0;
- List<CardSource> discardedCards = new List<CardSource>();
- while (true)
- {
- if (StopDestroySecurity())
- {
- break;
- }
- if (count >= _destroySecurityCount)
- {
- break;
- }
- if (_player.SecurityCards.Count >= 1)
- {
- count++;
- CardSource destroyedSecurityCard = _player.SecurityCards[0];
- if (!_fromTop)
- {
- destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
- }
- discardedCards.Add(destroyedSecurityCard);
- #region effect
- _player.securityObject.securityBreakGlass.ShowBlueMatarial();
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
- yield return new WaitForSeconds(0.1f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
- yield return new WaitForSeconds(0.5f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
- }
- }
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
- if (discardedCards.Count >= 1)
- {
- yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
- player: _player,
- refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
- cardEffect: _cardEffect).ReduceSecurity());
- #region "When security cards are trashed" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"DiscardedCards", discardedCards},
- {"CardEffect", _cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
- #endregion
- }
- #region add log
- if (discardedCards.Count >= 1)
- {
- string log = "";
- string fromString = _fromTop ? "Top" : "Bottom";
- log += $"\nDiscarded From {fromString} Security Cards:";
- foreach (CardSource cardSource in discardedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- }
- #endregion
- #region Battle
- public class IBattle
- {
- public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard)
- {
- this.AttackingPermanent = AttackingPermanent;
- this.DefendingPermanent = DefendingPermanent;
- this.DefendingCard = DefendingCard;
- }
- public Permanent AttackingPermanent { get; private set; } = null;
- public Permanent DefendingPermanent { get; private set; } = null;
- CardSource DefendingCard { get; set; } = null;
- public Hashtable hashtable { get; set; } = new Hashtable();
- public Permanent enemyPermanent(Permanent permanent)
- {
- if (permanent != null)
- {
- if (permanent == AttackingPermanent)
- {
- return DefendingPermanent;
- }
- else if (permanent == DefendingPermanent)
- {
- return AttackingPermanent;
- }
- }
- return null;
- }
- public int CompareStats()
- {
- int statCheck = 0;
- if(AttackingPermanent.HasIceclad || DefendingPermanent.HasIceclad)
- statCheck = AttackingPermanent.DigivolutionCards.Count - DefendingPermanent.DigivolutionCards.Count;
- else
- statCheck = AttackingPermanent.DP - DefendingPermanent.DP;
- statCheck = Mathf.Clamp(statCheck, -1, 1);
- return statCheck;
- }
- public IEnumerator Battle()
- {
- hashtable = new Hashtable();
- if (AttackingPermanent != null)
- {
- bool IsExistingDefender()
- {
- // whether defender exists
- if ((DefendingPermanent == null) != (DefendingCard == null))
- {
- if (DefendingPermanent != null)
- {
- if (DefendingPermanent.TopCard != null)
- {
- return true;
- }
- }
- else if (DefendingCard != null)
- {
- return true;
- }
- }
- return false;
- }
- if (IsExistingDefender())
- {
- if (AttackingPermanent != null)
- {
- AttackingPermanent.battle = this;
- }
- if (DefendingPermanent != null)
- {
- DefendingPermanent.battle = this;
- }
- List<Permanent> WinnerPermanents = new List<Permanent>();
- List<Permanent> LoserPermanents = new List<Permanent>();
- CardSource LoserCard = null;
- //add log
- string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
- if (DefendingPermanent != null)
- {
- log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
- }
- else if (DefendingCard != null)
- {
- log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
- }
- PlayLog.OnAddLog?.Invoke(log);
- #region "At the start of battle" effect
- Permanent _AttackingPermanent = null;
- Permanent _DefendingPermanent = null;
- if (AttackingPermanent != null)
- {
- if (AttackingPermanent.TopCard != null)
- {
- _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
- }
- }
- if (DefendingPermanent != null)
- {
- if (DefendingPermanent.TopCard != null)
- {
- _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
- }
- }
- hashtable.Add("AttackingPermanent", _AttackingPermanent);
- hashtable.Add("DefendingPermanent", _DefendingPermanent);
- hashtable.Add("DefendingCard", DefendingCard);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
- #endregion
- #region Show effect
- bool ShowEffect()
- {
- if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
- {
- return true;
- }
- else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
- {
- if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
- {
- return true;
- }
- }
- return false;
- }
- if (ShowEffect())
- {
- if (GManager.instance.attackProcess.IsAttacking)
- {
- if (GManager.instance.attackProcess.SecurityDigimon != null)
- {
- if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
- }
- }
- }
- }
- #endregion
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- GManager.instance.turnStateMachine.IsSelecting = true;
- //Preemptive end battle if the attack process is ended
- if(GManager.instance.attackProcess.IsEndAttack)
- yield break;
-
- #region battle with permanent
- if (DefendingPermanent != null)
- {
- int battleResults = CompareStats();
- if (battleResults == 1)
- {
- WinnerPermanents.Add(AttackingPermanent);
- if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(DefendingPermanent);
- }
- else if (battleResults == 0)
- {
- WinnerPermanents.Add(AttackingPermanent);
- WinnerPermanents.Add(DefendingPermanent);
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(AttackingPermanent);
- if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(DefendingPermanent);
- }
- else if (battleResults == -1)
- {
- WinnerPermanents.Add(DefendingPermanent);
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(AttackingPermanent);
- }
- }
- #endregion
- #region battle with card
- else if (DefendingCard != null)
- {
- if (AttackingPermanent.DP > DefendingCard.CardDP)
- {
- WinnerPermanents.Add(AttackingPermanent);
- LoserCard = DefendingCard;
- }
- else if (AttackingPermanent.DP == DefendingCard.CardDP)
- {
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- {
- LoserPermanents.Add(AttackingPermanent);
- }
- LoserCard = DefendingCard;
- }
- else if (AttackingPermanent.DP < DefendingCard.CardDP)
- {
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- {
- LoserPermanents.Add(AttackingPermanent);
- }
- }
- }
- #endregion
-
- List<Permanent> _WinnerPermanents = new List<Permanent>();
- List<Permanent> _LoserPermanents = new List<Permanent>();
- foreach (Permanent permanent in WinnerPermanents)
- {
- if (permanent.TopCard != null)
- {
- _WinnerPermanents.Add(new Permanent(permanent.cardSources));
- }
- }
- foreach (Permanent permanent in LoserPermanents)
- {
- if (permanent.TopCard != null)
- {
- _LoserPermanents.Add(new Permanent(permanent.cardSources));
- }
- }
- hashtable.Add("WinnerPermanents", _WinnerPermanents);
- hashtable.Add("WinnerPermanents_real", WinnerPermanents);
- hashtable.Add("LoserPermanents", _LoserPermanents);
- hashtable.Add("LoserPermanents_real", LoserPermanents);
- hashtable.Add("LoserCard", LoserCard);
- hashtable.Add("battle", this);
- // battle effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
- yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(LoserPermanents, hashtable).Destroy());
- //Fix winner/loser permanents
- int index = -1;
- foreach (Permanent permanent in LoserPermanents)
- {
- if (permanent.TopCard != null)
- {
- index = LoserPermanents.IndexOf(permanent);
- }
- }
- if (index >= 0)
- {
- LoserPermanents.RemoveAt(index);
- _LoserPermanents.RemoveAt(index);
- hashtable["LoserPermanents"] = _LoserPermanents;
- hashtable["LoserPermanents_real"] = LoserPermanents;
- }
- //LoserPermanents = LoserPermanents.Filter(permanent => permanent.TopCard != null);
- //_LoserPermanents = _LoserPermanents.Filter(permanent => permanent.TopCard != null);
- //hashtable["LoserPermanents"] = _LoserPermanents;
- //hashtable["LoserPermanents_real"] = LoserPermanents;
- // "At the end of battle" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
- #region move up effect
- if (ShowEffect())
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
- }
- #endregion
- #region effect when determine whether to do security check
- List<SkillInfo> skillInfos_Pierce = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnDetermineDoSecurityCheck)
- .Filter(skillInfo => skillInfo.CardEffect != null && skillInfo.CardEffect.CanActivate(skillInfo.Hashtable));
- if (skillInfos_Pierce.Count >= 1)
- {
- GManager.instance.autoProcessing.PutStackedSkill(skillInfos_Pierce[0]);
- }
- #endregion
- }
- }
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- #region reset effect until the end of battle
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
- }
- player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
- }
- #endregion
- if (AttackingPermanent != null)
- {
- AttackingPermanent.battle = null;
- }
- if (DefendingPermanent != null)
- {
- DefendingPermanent.battle = null;
- }
- }
- }
- #endregion
- #region De-digivolve
- public class IDegeneration
- {
- /// <summary>
- /// De-Digivolve Class
- /// </summary>
- /// <param name="permanent">Target Permanent</param>
- /// <param name="DegenerationCount">De-Digivolve Amount</param>
- /// <param name="cardEffect">Card Effect</param>
- /// <param name="DegenerationCountRuling">Should we enforce rule to select De-digivolve amount before digimon, disabled by default</param>
- public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect, bool? DegenerationCountRuling = null)
- {
- _permanent = permanent;
- _degenerationCount = DegenerationCount;
- _cardEffect = cardEffect;
- _degenerationCountRuling = DegenerationCountRuling;
- }
- Permanent _permanent = null;
- int _degenerationCount;
- ICardEffect _cardEffect = null;
- bool? _degenerationCountRuling;
- public IEnumerator Degeneration()
- {
- if (_cardEffect == null) yield break;
- if (_cardEffect.EffectSourceCard == null) yield break;
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_permanent.ImmuneFromDeDigivolve()) yield break;
- if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
- if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
- int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
- SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
- if (selectCountEffect != null && _degenerationCountRuling == null)
- {
- Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
- selectCountEffect.SetUp(
- SelectPlayer: selectPlayer,
- targetPermanent: _permanent,
- MaxCount: maxCount,
- CanNoSelect: false,
- Message: "How many cards do you trash?",
- Message_Enemy: "The opponent is choosing how many cards to trash.",
- SelectCountCoroutine: SelectCountCoroutine);
- yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
- IEnumerator SelectCountCoroutine(int count)
- {
- _degenerationCount = count;
- yield return null;
- }
- }
- if (_degenerationCount >= 1)
- {
- int count = 0;
- List<CardSource> selectedCards = new List<CardSource>();
- while (true)
- {
- bool StopCondition()
- {
- if (_permanent.HasNoDigivolutionCards)
- {
- return true;
- }
- if (_permanent.Level == 3)
- {
- if (_permanent.TopCard != null)
- {
- if (_permanent.TopCard.HasLevel)
- {
- return true;
- }
- }
- }
- if (count >= _degenerationCount)
- {
- return true;
- }
- return false;
- }
- if (StopCondition())
- {
- break;
- }
- if (count == 0)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- }
- CardSource cardSource = _permanent.TopCard;
- selectedCards.Add(cardSource);
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- _permanent.ShowingPermanentCard.ShowPermanentData(true);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
- count++;
- }
- #region "When Top Card is Trashed" effect
- #region Hashtable Setting
- System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
- {
- {"Permanent", _permanent},
- {"CardSources", selectedCards}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
- .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
- #endregion
- #region add log
- if (selectedCards.Count >= 1)
- {
- string log = "";
- log += $"\nDe-Digivolve :";
- foreach (CardSource cardSource in selectedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- }
- #endregion
- #region Trash digivolution cards
- public class ITrashDigivolutionCards
- {
- public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
- {
- _permanent = permanent;
- _trashTargetCards = trashTargetCards.Clone();
- _cardEffect = cardEffect;
- }
- Permanent _permanent = null;
- List<CardSource> _trashTargetCards = new List<CardSource>();
- ICardEffect _cardEffect = null;
- public IEnumerator TrashDigivolutionCards()
- {
- if (_trashTargetCards == null) yield break;
- if (_cardEffect == null) yield break;
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
- if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
- if (_permanent.HasNoDigivolutionCards) yield break;
- _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
- _permanent.DigivolutionCards.Contains(cardSource) &&
- !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
- if (_trashTargetCards.Count == 0) yield break;
- _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
- string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- #region cut in effect - Would discard
- // "When digivolution cards would be trashed" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
- _permanent,
- _trashTargetCards,
- _cardEffect
- ),
- EffectTiming.WhenWouldDigivolutionCardDiscarded));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- // effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
- }
- #endregion
- //fix trash target permanent
- Permanent permanentTarget_Fixed = _permanent;
- // fix trash sources sources
- List<CardSource> trashDigivolutionCards_Fixed = _trashTargetCards.Filter(cardsource =>
- cardsource != null
- && cardsource.willBeRemoveSources);
- #region "When digivolution cards are trashed" effect
- #region Hashtable Setting
- Hashtable hashtable = new Hashtable()
- {
- {"CardEffect", _cardEffect},
- {"Permanent", permanentTarget_Fixed},
- {"DiscardedCards", trashDigivolutionCards_Fixed},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
- foreach (CardSource cardSource in trashDigivolutionCards_Fixed)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- cardSource.willBeRemoveSources = false;
- }
- }
- }
- #endregion
- #region Trash link cards
- public class ITrashLinkCards
- {
- public ITrashLinkCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
- {
- _permanent = permanent;
- _trashTargetCards = trashTargetCards.Clone();
- _cardEffect = cardEffect;
- }
- Permanent _permanent = null;
- List<CardSource> _trashTargetCards = new List<CardSource>();
- ICardEffect _cardEffect = null;
- public IEnumerator TrashLinkCards()
- {
- if (_trashTargetCards == null) yield break;
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_cardEffect != null && _permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
- if (_permanent.HasNoLinkCards) yield break;
- _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
- _permanent.LinkedCards.Contains(cardSource));
- if (_trashTargetCards.Count == 0) yield break;
- _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
- string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- #region cut in effect - Would discard
- // "When link cards would be trashed" effect
- //TODO: Create CardEffectCommons.WhenLinkCardWouldDiscard function
- /*yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
- _permanent,
- _trashTargetCards,
- _cardEffect
- ),
- EffectTiming.WhenWouldDigivolutionCardDiscarded));*/
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- // effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
- }
- #endregion
- //fix trash target permanent
- Permanent permanentTarget_Fixed = _permanent;
- // fix trash sources sources
- List<CardSource> trashLinkCards_Fixed = _trashTargetCards.Filter(cardsource =>
- cardsource != null
- && cardsource.willBeRemoveSources);
- #region "When link cards are trashed" effect
- #region Hashtable Setting
- Hashtable hashtable = new Hashtable()
- {
- {"CardEffect", _cardEffect},
- {"Permanent", permanentTarget_Fixed},
- {"DiscardedCards", trashLinkCards_Fixed},
- };
- #endregion
- //TODO: Create OnLinkCardDiscarded timing
- //yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
- foreach (CardSource cardSource in trashLinkCards_Fixed)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
- if (!cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(permanentTarget_Fixed.RemoveLinkedCard(cardSource));
- }
- cardSource.willBeRemoveSources = false;
- }
- }
- }
- #endregion
- #region Return digivolution cards to deck bottom
- public class ReturnToLibraryBottomDigivolutionCardsClass
- {
- public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
- {
- _permanent = permanent;
- _cardSources = cardSources.Clone();
- _hashtable = hashtable;
- }
- Permanent _permanent = null;
- List<CardSource> _cardSources = new List<CardSource>();
- Hashtable _hashtable = null;
- public IEnumerator ReturnToLibraryBottomDigivolutionCards()
- {
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_cardSources == null) yield break;
- _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
- if (_cardSources.Count == 0) yield break;
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
- string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- #region "When digivolution cards are returned to deck" effect
- #region Hashtable Setting
- Hashtable hashtable1 = new Hashtable()
- {
- {"Permanent", _permanent},
- {"DeckBottomCards", _cardSources},
- {"CardEffect", CardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
- }
- }
- #endregion
- #region Reduce security
- public class IReduceSecurity
- {
- public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos, ICardEffect cardEffect = null)
- {
- _player = player;
- _refSkillInfos = refSkillInfos;
- _cardEffect = cardEffect;
- }
- Player _player = null;
- List<SkillInfo> _refSkillInfos = null;
- ICardEffect _cardEffect = null;
- public IEnumerator ReduceSecurity()
- {
- GManager.OnSecurityStackChanged?.Invoke(_player);
- #region "When cards are removed from security" effect
- #region Hashtable Setting
- Hashtable hashtable = new Hashtable()
- {
- {"Player", _player},
- {"SkillInfo",_refSkillInfos },
- {"CardEffect",_cardEffect}
- };
- #endregion
- if (_refSkillInfos == null)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
- }
- else
- {
- foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
- {
- _refSkillInfos.Add(skillInfo);
- }
- }
- #endregion
- }
- }
- #endregion
- #region Add Security
- public class IAddSecurity
- {
- public IAddSecurity(Player player)
- {
- _player = player;
- }
- Player _player { get; set; }
- public IEnumerator AddSecurity()
- {
- GManager.OnSecurityStackChanged?.Invoke(_player);
- #region "When security cards are added" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"Player", _player}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
- #endregion
- }
- }
- #endregion
- #region Suspend permanents
- public class SuspendPermanentsClass
- {
- public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
- {
- _permanents = permanents;
- _hashtable = hashtable;
- }
- List<Permanent> _permanents { get; set; }
- Hashtable _hashtable { get; set; }
- public IEnumerator Tap()
- {
- if (_permanents.Count == 0) yield break;
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
- bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
- List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
- bool PermanentCondition(Permanent permanent)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- if (permanent.IsSuspended)
- {
- return false;
- }
- if (!permanent.CanSuspend)
- {
- return false;
- }
- if (CardEffect != null)
- {
- if (permanent.TopCard.CanNotBeAffected(CardEffect))
- {
- return false;
- }
- }
- }
- }
- return true;
- }
- foreach (Permanent permanent in suspendTargetPermanents)
- {
- permanent.IsSuspended = true;
- GManager.OnCardSuspendedChanged?.Invoke(true);
- permanent.DPWhenSuspended = permanent.DP;
- if (permanent.ShowingPermanentCard != null)
- {
- permanent.ShowingPermanentCard.ShowPermanentData(true);
- }
- }
- if (suspendTargetPermanents.Count >= 1)
- {
- #region "Effects when permanents suspend
- #region Hashtable Setting
- Hashtable _hashtable = new Hashtable(){
- {"Permanents", suspendTargetPermanents},
- {"IsBlock", IsBlock}
- };
- if (CardEffect != null)
- {
- _hashtable.Add("CardEffect", CardEffect);
- }
- #endregion
- if (IsAttack)
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
- else
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
- #endregion
- yield return new WaitForSeconds(0.3f);
- }
- }
- }
- #endregion
- #region Unsuspend permanents
- public class IUnsuspendPermanents
- {
- public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
- {
- _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
- _cardEffect = cardEffect;
- }
- List<Permanent> _permanents { get; set; }
- ICardEffect _cardEffect { get; set; }
- public IEnumerator Unsuspend()
- {
- //Permanent list that will unsuspend
- List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
- permanent != null
- && permanent.TopCard != null
- && permanent.IsSuspended
- && permanent.CanUnsuspend
- && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
- #region "When permanents would unsuspend" effect
- #region Hashtable Setting
- Hashtable hashtable1 = new Hashtable()
- {
- {"CardEffect", _cardEffect},
- {"Permanents", untappedPermanets},
- };
- #endregion
- List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
- if (skillInfos.Count >= 1)
- {
- foreach (SkillInfo skillInfo in skillInfos)
- {
- GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
- }
- foreach (Permanent permanent in untappedPermanets)
- {
- permanent.ShowUnsuspendEffect();
- }
- //cut in effects
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
- untappedPermanets.ForEach(permanent =>
- {
- if (permanent.ShowingPermanentCard != null)
- {
- permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
- }
- });
- }
- #endregion
- // fix unsuspend target permanents
- List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
- permanent != null
- && permanent.TopCard != null
- && permanent.IsSuspended
- && permanent.CanUnsuspend
- && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
- if (untappedPermanets_Fixed.Count >= 1)
- {
- foreach (Permanent permanent in untappedPermanets_Fixed)
- {
- permanent.IsSuspended = false;
- if (permanent.ShowingPermanentCard != null)
- {
- permanent.ShowingPermanentCard.ShowPermanentData(true);
- }
- }
- #region "When permanents are unsuspended" effect
- #region Hashtable Setting
- Hashtable hashtable2 = new Hashtable()
- {
- {"CardEffect", _cardEffect},
- {"Permanents", untappedPermanets_Fixed},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
- #endregion
- yield return new WaitForSeconds(0.3f);
- }
- foreach (Permanent permanent in untappedPermanets)
- {
- permanent.UntilNextUntapEffects = new List<Func<EffectTiming, ICardEffect>>();
- }
- }
- }
- #endregion
- #region Trash cards from deck top
- public class ITrashDeckCards
- {
- public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
- {
- this.cardSources = new List<CardSource>();
- foreach (CardSource cardSource in cardSources)
- {
- this.cardSources.Add(cardSource);
- }
- this.cardEffect = cardEffect;
- }
- List<CardSource> cardSources { get; set; } = new List<CardSource>();
- ICardEffect cardEffect { get; set; } = null;
- public IEnumerator TrashDeckCards()
- {
- List<CardSource> trashCards = new List<CardSource>();
- foreach (CardSource cardSource in cardSources)
- {
- if (cardSource.Owner.LibraryCards.Contains(cardSource))
- {
- trashCards.Add(cardSource);
- }
- }
- if (trashCards.Count >= 1)
- {
- foreach (CardSource cardSource in trashCards)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- #region "When cards are trashed from security" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"DiscardedCards", trashCards},
- {"CardEffect", cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
- hashtable, EffectTiming.OnDiscardLibrary));
- #endregion
- }
- }
- }
- #endregion
- #region Overflow of ace
- public class AceOverflowClass
- {
- public AceOverflowClass(List<CardSource> cardSources)
- {
- _cardSources = cardSources.Clone();
- }
- List<CardSource> _cardSources = new List<CardSource>();
- public IEnumerator Overflow()
- {
- _cardSources = _cardSources
- .Filter(cardSource => cardSource.IsACE && CardEffectCommons.IsExistOnBattleArea(cardSource) || CardEffectCommons.IsExistOnBreedingAreaDigimon(cardSource))
- .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
- .ToList();
- foreach (CardSource cardSource in _cardSources)
- {
- yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
- string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- }
- }
- #endregion
- #region TrashStack
- public class ITrashStack
- {
- /// <summary>
- /// Trash Stack Class
- /// </summary>
- /// <param name="permanent">Target Permanent</param>
- /// <param name="TrashCount">Amount of cards to trash</param>
- /// <param name="cardEffect">Card Effect</param>
- /// <param name="fromTop">Should trashing start from top, true by default</param>
- public ITrashStack(Permanent permanent, int TrashCount, ICardEffect cardEffect, bool fromTop = true)
- {
- _permanent = permanent;
- _trashCount = TrashCount;
- _cardEffect = cardEffect;
- _fromTop = fromTop;
- }
- Permanent _permanent = null;
- int _trashCount;
- ICardEffect _cardEffect = null;
- bool _fromTop;
- public IEnumerator TrashStack()
- {
- if (_cardEffect == null) yield break;
- if (_cardEffect.EffectSourceCard == null) yield break;
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
- if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
- _trashCount = Math.Min(_permanent.StackCards.Count, _trashCount);
- if (_trashCount >= 1)
- {
- int count = 0;
- List<CardSource> selectedCards = new List<CardSource>();
- while (true)
- {
- bool StopCondition()
- {
- if (_permanent.HasNoDigivolutionCards)
- {
- return true;
- }
- if (count >= _trashCount)
- {
- return true;
- }
- return false;
- }
- if (StopCondition())
- {
- break;
- }
- if (count == 0)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- }
- CardSource cardSource = _permanent.TopCard;
- selectedCards.Add(cardSource);
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- _permanent.ShowingPermanentCard.ShowPermanentData(true);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
- count++;
- }
- #region "When Top Card is Trashed" effect
- #region Hashtable Setting
- System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
- {
- {"Permanent", _permanent},
- {"CardSources", selectedCards}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
- .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
- #endregion
- #region add log
- if (selectedCards.Count >= 1)
- {
- string log = "";
- log += $"\nStack Trashed :";
- foreach (CardSource cardSource in selectedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- }
- #endregion
|