CardController.cs 182 KB

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