CardController.cs 181 KB

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