CardController.cs 189 KB

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