CardController.cs 179 KB

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