CardController.cs 155 KB

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