CardController.cs 182 KB

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