CardController.cs 191 KB

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