CardController.cs 180 KB

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