CardController.cs 181 KB

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