CardController.cs 156 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300
  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,
  1040. CardEffectCommons.GetCardEffectFromHashtable(_hashtable)).ReduceSecurity());
  1041. }
  1042. if (isEvolution)
  1043. {
  1044. card.Owner.DigivolveCount_ThisTurn++;
  1045. yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, null).Draw());
  1046. if (_burstDigivolved)
  1047. {
  1048. if (permanent.TopCard != null)
  1049. {
  1050. permanent.IsBurstDigivolved = true;
  1051. GManager.instance.selectBurstDigivolutionEffect.AddTrashTopCardAtTurnEnd(permanent);
  1052. }
  1053. }
  1054. permanent.CardNamesJustAfterDigivolved = permanent.TopCard.CardNames.Clone();
  1055. permanent.DigivolvingEffect = CardEffect;
  1056. }
  1057. else
  1058. {
  1059. permanent.PlayingEffect = CardEffect;
  1060. if (permanent.TopCard.HasLevel)
  1061. {
  1062. permanent.LevelJustAfterPlayed = permanent.Level;
  1063. }
  1064. if (permanent.TopCard.HasPlayCost)
  1065. {
  1066. permanent.PlayCostJustAfterPlayed = permanent.TopCard.GetCostItself;
  1067. }
  1068. permanent.CardNamesJustAfterPlayed = permanent.TopCard.CardNames.Clone();
  1069. permanent.TraitsJustAfterPlayed = permanent.TopCard.CardTraits.Clone();
  1070. }
  1071. #region move permanents (hybrid)
  1072. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  1073. {
  1074. if (permanent.TopCard.PreferredFrame() != null)
  1075. {
  1076. if (permanent.PermanentFrame != permanent.TopCard.PreferredFrame())
  1077. {
  1078. if (permanent.TopCard.PreferredFrame().IsEmptyFrame())
  1079. {
  1080. bool move = false;
  1081. if (permanent.IsDigimon)
  1082. {
  1083. if (permanent.TopCard.Owner.isYou)
  1084. {
  1085. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1086. {
  1087. move = true;
  1088. }
  1089. }
  1090. else
  1091. {
  1092. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1093. {
  1094. move = true;
  1095. }
  1096. }
  1097. }
  1098. else if (permanent.IsTamer || permanent.TopCard.IsOption)
  1099. {
  1100. if (permanent.TopCard.Owner.isYou)
  1101. {
  1102. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1103. {
  1104. move = true;
  1105. }
  1106. }
  1107. else
  1108. {
  1109. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1110. {
  1111. move = true;
  1112. }
  1113. }
  1114. }
  1115. if (move)
  1116. {
  1117. yield return ContinuousController.instance.StartCoroutine(CardObjectController.MovePermanent(permanent.PermanentFrame));
  1118. }
  1119. }
  1120. }
  1121. }
  1122. }
  1123. #endregion
  1124. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCardsByEffect(card);
  1125. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCards(card);
  1126. if (GManager.instance.turnStateMachine.DoneStartGame)
  1127. {
  1128. hashtableParams.Add(
  1129. new OnEnterFieldHashtableParams(
  1130. permanent: permanent,
  1131. evoRoots: evoRoots,
  1132. evoRootTops: evoRootTops,
  1133. root: _root,
  1134. oldLevels: oldLevels,
  1135. isFromDigimonDigivolutionCards: isFromDigimonDigivolutionCards
  1136. )
  1137. );
  1138. }
  1139. }
  1140. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  1141. yield return GManager.instance.photonWaitController.StartWait("EndPlayPermanent");
  1142. }
  1143. // except [On Play] effect
  1144. bool CardEffectCondition(ICardEffect cardEffect)
  1145. {
  1146. if (cardEffect == null)
  1147. {
  1148. return false;
  1149. }
  1150. if (!_activateETB)
  1151. {
  1152. if (cardEffect is ActivateICardEffect)
  1153. {
  1154. if (cardEffect.IsOnPlay)
  1155. {
  1156. return false;
  1157. }
  1158. }
  1159. }
  1160. return true;
  1161. }
  1162. Hashtable effectHashtable = CardEffectCommons.OnEnterFieldHashtable(
  1163. hashtableParams: hashtableParams,
  1164. isEvolution: isEvolution,
  1165. isJogress: isJogress,
  1166. digiXrosCount: _digiXrosCount,
  1167. cardEffect: CardEffect);
  1168. #region "When permanents are played" effect
  1169. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  1170. hashtable: effectHashtable,
  1171. timing: EffectTiming.OnEnterFieldAnyone,
  1172. cardEffectCondition: CardEffectCondition));
  1173. #endregion
  1174. }
  1175. }
  1176. #endregion
  1177. #region Use option
  1178. public class UseOptionClass
  1179. {
  1180. public UseOptionClass(List<CardSource> cardSources, Hashtable hashtable, SelectCardEffect.Root root)
  1181. {
  1182. if (cardSources != null)
  1183. {
  1184. _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  1185. }
  1186. _hashtable = hashtable;
  1187. _root = root;
  1188. }
  1189. List<CardSource> _cardSources = new List<CardSource>();
  1190. SelectCardEffect.Root _root = SelectCardEffect.Root.None;
  1191. Hashtable _hashtable = null;
  1192. public bool _showEffect = false;
  1193. public bool _addSecurityEndOption = false;
  1194. public IEnumerator UseOption()
  1195. {
  1196. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1197. foreach (CardSource card in _cardSources)
  1198. {
  1199. if (_showEffect)
  1200. {
  1201. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(card));
  1202. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowUseHandCardEffect_PlayCard(card));
  1203. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  1204. }
  1205. PlayLog.OnAddLog?.Invoke($"\nPlay Option:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1206. card.Init();
  1207. GManager.instance.turnStateMachine.isSync = true;
  1208. card.SetFace();
  1209. int cost = card.GetCostItself;
  1210. //Remove from all areas
  1211. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1212. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(card));
  1213. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.BrainStormCoroutine(card));
  1214. #region Set HashTable
  1215. Hashtable hashtable = new Hashtable()
  1216. {
  1217. {"Card", card},
  1218. {"Root", _root},
  1219. {"Cost", cost},
  1220. };
  1221. #endregion
  1222. #region "When option is used" effect
  1223. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseOption));
  1224. yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.OnUseOption));
  1225. #endregion
  1226. #region effect process of option card
  1227. foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.OptionSkill))
  1228. {
  1229. if (cardEffect is ActivateICardEffect)
  1230. {
  1231. if (cardEffect.CanUse(hashtable))
  1232. {
  1233. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  1234. cardEffect,
  1235. hashtable));
  1236. }
  1237. }
  1238. }
  1239. #endregion
  1240. if (card.Owner.ExecutingCards.Contains(card))
  1241. {
  1242. if (_addSecurityEndOption && card.Owner.CanAddSecurity(CardEffect))
  1243. {
  1244. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(card));
  1245. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(card.Owner));
  1246. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(card.Owner).AddSecurity());
  1247. }
  1248. else
  1249. {
  1250. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(card));
  1251. }
  1252. }
  1253. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  1254. yield return GManager.instance.photonWaitController.StartWait("EndPlayOption");
  1255. }
  1256. }
  1257. }
  1258. #endregion
  1259. #region Draw cards
  1260. public class DrawClass
  1261. {
  1262. public DrawClass(Player player, int drawCount, ICardEffect cardEffect)
  1263. {
  1264. _player = player;
  1265. _drawCount = drawCount;
  1266. _cardEffect = cardEffect;
  1267. }
  1268. Player _player = null;
  1269. int _drawCount = 0;
  1270. ICardEffect _cardEffect = null;
  1271. public IEnumerator Draw()
  1272. {
  1273. if (_drawCount <= 0) yield break;
  1274. if (_player.LibraryCards.Count <= 0) yield break;
  1275. List<CardSource> DrawCards = new List<CardSource>();
  1276. for (int i = 0; i < _drawCount; i++)
  1277. {
  1278. if (_player.LibraryCards.Count > 0)
  1279. {
  1280. CardSource DrawCard = _player.LibraryCards[0];
  1281. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(DrawCard));
  1282. DrawCards.Add(DrawCard);
  1283. }
  1284. }
  1285. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(DrawCards, true, _cardEffect));
  1286. #region add log
  1287. if (DrawCards.Count >= 1)
  1288. {
  1289. PlayLog.OnAddLog?.Invoke($"\nDraw {DrawCards.Count} card{Utils.PluralFormSuffix(DrawCards.Count)}\n{_player.PlayerName}\n");
  1290. }
  1291. #endregion
  1292. #region "When draw cards" effect
  1293. if (DrawCards.Count >= 1)
  1294. {
  1295. #region Hashtable setting
  1296. Hashtable _hashtable = new Hashtable()
  1297. {
  1298. {"Player", _player},
  1299. {"CardEffect", _cardEffect}
  1300. };
  1301. #endregion
  1302. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnDraw));
  1303. }
  1304. #endregion
  1305. }
  1306. }
  1307. #endregion
  1308. #region Trash cards from deck too
  1309. public class IAddTrashCardsFromLibraryTop
  1310. {
  1311. public IAddTrashCardsFromLibraryTop(int addTrashCount, Player player, ICardEffect cardEffect)
  1312. {
  1313. _addTrashCount = addTrashCount;
  1314. _player = player;
  1315. _cardEffect = cardEffect;
  1316. }
  1317. public void SetNotShowCards()
  1318. {
  1319. _notShowCards = true;
  1320. }
  1321. int _addTrashCount;
  1322. Player _player;
  1323. public List<CardSource> discardedCards = new List<CardSource>();
  1324. ICardEffect _cardEffect { get; set; } = null;
  1325. bool _notShowCards = false;
  1326. public IEnumerator AddTrashCardsFromLibraryTop()
  1327. {
  1328. if (_addTrashCount <= 0) yield break;
  1329. if (_player.LibraryCards.Count == 0) yield break;
  1330. string log = "";
  1331. log += $"\nTrash cards from deck :";
  1332. for (int i = 0; i < _addTrashCount; i++)
  1333. {
  1334. if (_player.LibraryCards.Count > i)
  1335. {
  1336. CardSource DiscardCard = _player.LibraryCards[i];
  1337. discardedCards.Add(DiscardCard);
  1338. log += $"\n{DiscardCard.BaseENGCardNameFromEntity}({DiscardCard.CardID})";
  1339. }
  1340. }
  1341. if (discardedCards.Count >= 1)
  1342. {
  1343. if (!_notShowCards)
  1344. {
  1345. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  1346. }
  1347. }
  1348. yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(discardedCards, _cardEffect).TrashDeckCards());
  1349. if (discardedCards.Count >= 1)
  1350. {
  1351. for (int i = 0; i < discardedCards.Count; i++)
  1352. {
  1353. ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
  1354. yield return new WaitForSeconds(0.06f);
  1355. }
  1356. log += "\n";
  1357. PlayLog.OnAddLog?.Invoke(log);
  1358. }
  1359. }
  1360. }
  1361. #endregion
  1362. #region Add security from deck top
  1363. public class IAddSecurityFromLibrary
  1364. {
  1365. public IAddSecurityFromLibrary(Player player, int addLifeCount)
  1366. {
  1367. _player = player;
  1368. _addSecurityCount = addLifeCount;
  1369. }
  1370. Player _player = null;
  1371. int _addSecurityCount = 0;
  1372. public IEnumerator AddSecurity()
  1373. {
  1374. int count = 0;
  1375. for (int i = 0; i < _addSecurityCount; i++)
  1376. {
  1377. if (_player.LibraryCards.Count > 0)
  1378. {
  1379. CardSource StockCard = _player.LibraryCards[0];
  1380. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(StockCard));
  1381. count++;
  1382. }
  1383. }
  1384. if (count > 0)
  1385. {
  1386. string log = "";
  1387. log += $"\nAdd {count} cards to security:{_player.PlayerName}";
  1388. log += "\n";
  1389. PlayLog.OnAddLog?.Invoke(log);
  1390. if (GManager.instance.turnStateMachine.DoneStartGame)
  1391. {
  1392. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(_player).AddSecurity());
  1393. }
  1394. }
  1395. }
  1396. }
  1397. #endregion
  1398. #region Recovery
  1399. public class IRecovery
  1400. {
  1401. public IRecovery(Player player, int AddLifeCount, ICardEffect cardEffect)
  1402. {
  1403. _player = player;
  1404. _addLifeCount = AddLifeCount;
  1405. _cardEffect = cardEffect;
  1406. }
  1407. Player _player = null;
  1408. int _addLifeCount = 0;
  1409. ICardEffect _cardEffect = null;
  1410. public IEnumerator Recovery()
  1411. {
  1412. if (_player.LibraryCards.Count == 0) yield break;
  1413. if (_addLifeCount <= 0) yield break;
  1414. if (!_player.CanAddSecurity(_cardEffect)) yield break;
  1415. yield return ContinuousController.instance.StartCoroutine(new IAddSecurityFromLibrary(_player, _addLifeCount).AddSecurity());
  1416. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(_player));
  1417. }
  1418. }
  1419. #endregion
  1420. #region Digi-Burst
  1421. public class IDigiBurst
  1422. {
  1423. public IDigiBurst(Permanent permanent, int DigiBurstCount, ICardEffect cardEffect)
  1424. {
  1425. _permanent = permanent;
  1426. _digiBurstCount = DigiBurstCount;
  1427. _cardEffect = cardEffect;
  1428. }
  1429. Permanent _permanent = null;
  1430. int _digiBurstCount = 0;
  1431. ICardEffect _cardEffect = null;
  1432. bool _upToMaxCount = false;
  1433. public List<CardSource> discardedCards = new List<CardSource>();
  1434. public void SetUpToMaxCount()
  1435. {
  1436. _upToMaxCount = true;
  1437. }
  1438. public bool CanDigiBurst()
  1439. {
  1440. if (_permanent != null)
  1441. {
  1442. if (_permanent.TopCard != null)
  1443. {
  1444. if (_upToMaxCount)
  1445. {
  1446. if (_permanent.DigivolutionCards.Some((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)))
  1447. {
  1448. return true;
  1449. }
  1450. }
  1451. else
  1452. {
  1453. if (_permanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)) >= _digiBurstCount)
  1454. {
  1455. return true;
  1456. }
  1457. }
  1458. }
  1459. }
  1460. return false;
  1461. }
  1462. public IEnumerator DigiBurst()
  1463. {
  1464. if (CanDigiBurst())
  1465. {
  1466. discardedCards = new List<CardSource>();
  1467. List<CardSource> selectedCards = new List<CardSource>();
  1468. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  1469. selectCardEffect.SetUp(
  1470. canTargetCondition: (cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect),
  1471. canTargetCondition_ByPreSelecetedList: null,
  1472. canEndSelectCondition: CanEndSelectCondition,
  1473. canNoSelect: () => false,
  1474. selectCardCoroutine: SelectCardCoroutine,
  1475. afterSelectCardCoroutine: null,
  1476. message: "Select digivolution cards to discard.",
  1477. maxCount: _digiBurstCount,
  1478. canEndNotMax: _upToMaxCount,
  1479. isShowOpponent: true,
  1480. mode: SelectCardEffect.Mode.Custom,
  1481. root: SelectCardEffect.Root.Custom,
  1482. customRootCardList: _permanent.DigivolutionCards,
  1483. canLookReverseCard: true,
  1484. selectPlayer: _permanent.TopCard.Owner,
  1485. cardEffect: null);
  1486. selectCardEffect.SetUpCustomMessage("Select digivolution cards to discard.", "The opponent is selecting digivolution cards to discard.");
  1487. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  1488. bool CanEndSelectCondition(List<CardSource> cardSources)
  1489. {
  1490. if (CardEffectCommons.HasNoElement(cardSources))
  1491. {
  1492. return false;
  1493. }
  1494. return true;
  1495. }
  1496. IEnumerator SelectCardCoroutine(CardSource cardSource)
  1497. {
  1498. selectedCards.Add(cardSource);
  1499. yield return null;
  1500. }
  1501. if (selectedCards.Count >= 1)
  1502. {
  1503. #region "When use Digi-Burst" effect
  1504. #region Hashtable setting
  1505. Hashtable hashtable = new Hashtable()
  1506. {
  1507. {"Permanent", _permanent},
  1508. {"CardEffect", _cardEffect},
  1509. };
  1510. #endregion
  1511. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseDigiburst));
  1512. #endregion
  1513. // trash digivolution cards
  1514. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(_permanent, selectedCards, _cardEffect).TrashDigivolutionCards());
  1515. foreach (CardSource cardSource in selectedCards)
  1516. {
  1517. discardedCards.Add(cardSource);
  1518. }
  1519. #region add log
  1520. if (selectedCards.Count >= 1)
  1521. {
  1522. string log = "";
  1523. log += $"\nDigiburst :";
  1524. foreach (CardSource cardSource in selectedCards)
  1525. {
  1526. if (cardSource != null)
  1527. {
  1528. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  1529. }
  1530. }
  1531. log += "\n";
  1532. PlayLog.OnAddLog?.Invoke(log);
  1533. }
  1534. #endregion
  1535. }
  1536. }
  1537. }
  1538. }
  1539. #endregion
  1540. #region Place permanents to deck bottom
  1541. public class DeckBottomBounceClass
  1542. {
  1543. public DeckBottomBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
  1544. {
  1545. _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
  1546. _hashtable = hashtable;
  1547. }
  1548. public void SetNotShowCards()
  1549. {
  1550. _notShowCards = true;
  1551. }
  1552. public bool IsDeckBounced(Permanent permanent)
  1553. {
  1554. return DeckBouncedPermanents.Contains(permanent);
  1555. }
  1556. List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
  1557. public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
  1558. Hashtable _hashtable = new Hashtable();
  1559. bool _notShowCards = false;
  1560. public IEnumerator DeckBounce()
  1561. {
  1562. if (_deckBounceTargetPermanents == null) yield break;
  1563. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1564. _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
  1565. permanent != null
  1566. && permanent.TopCard != null
  1567. && (cardEffect == null ||
  1568. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1569. && !permanent.CannotReturnToLibrary(cardEffect)
  1570. && permanent.CanBeRemoved())));
  1571. if (_deckBounceTargetPermanents.Count == 0) yield break;
  1572. _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1573. #region cut in effect
  1574. // "When permanents would return to deck" effect
  1575. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1576. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1577. _deckBounceTargetPermanents,
  1578. cardEffect,
  1579. null
  1580. ),
  1581. EffectTiming.WhenReturntoLibraryAnyone));
  1582. // "When permanents would remove field" effect
  1583. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1584. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1585. _deckBounceTargetPermanents,
  1586. cardEffect,
  1587. null
  1588. ),
  1589. EffectTiming.WhenRemoveField));
  1590. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1591. {
  1592. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1593. {
  1594. permanent.ShowDeckBounceEffect();
  1595. }
  1596. // cut in effect process
  1597. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1598. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1599. {
  1600. permanent.HideDeckBounceEffect();
  1601. }
  1602. }
  1603. #endregion
  1604. // fix deck bounce target permanents
  1605. List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
  1606. permanent != null
  1607. && permanent.TopCard != null
  1608. && permanent.willBeRemoveField);
  1609. #region show cards
  1610. List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1611. if (!_notShowCards)
  1612. {
  1613. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
  1614. }
  1615. #endregion
  1616. #region
  1617. List<CardSource> deckBottomCards = new List<CardSource>();
  1618. foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
  1619. {
  1620. #region recoed used effect
  1621. if (permanent.TopCard != null)
  1622. {
  1623. permanent.LibraryBounceEffect = cardEffect;
  1624. }
  1625. #endregion
  1626. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
  1627. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1628. CardSource topCard = permanent.TopCard;
  1629. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1630. deckBottomCards.Add(topCard);
  1631. DeckBouncedPermanents.Add(permanent);
  1632. }
  1633. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(deckBottomCards));
  1634. #endregion
  1635. #region off icon
  1636. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1637. {
  1638. if (permanent != null)
  1639. {
  1640. if (permanent.TopCard != null)
  1641. {
  1642. permanent.willBeRemoveField = false;
  1643. }
  1644. }
  1645. }
  1646. #endregion
  1647. }
  1648. }
  1649. #endregion
  1650. #region Return permanent to hand
  1651. public class HandBounceClaass
  1652. {
  1653. public HandBounceClaass(List<Permanent> bounceTargetPermanents, Hashtable hashtable)
  1654. {
  1655. _bounceTargetPermanents = bounceTargetPermanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  1656. _hashtable = hashtable;
  1657. }
  1658. public bool IsBounced(Permanent permanent)
  1659. {
  1660. return BouncedPermanents.Contains(permanent);
  1661. }
  1662. List<Permanent> _bounceTargetPermanents = new List<Permanent>();
  1663. public List<Permanent> BouncedPermanents { get; private set; } = new List<Permanent>();
  1664. Hashtable _hashtable = new Hashtable();
  1665. bool _notShowCards = false;
  1666. public IEnumerator Bounce()
  1667. {
  1668. if (_bounceTargetPermanents == null) yield break;
  1669. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1670. _bounceTargetPermanents = _bounceTargetPermanents.Filter(permanent =>
  1671. permanent != null
  1672. && permanent.TopCard != null
  1673. && (cardEffect == null ||
  1674. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1675. && !permanent.CannotReturnToHand(cardEffect)
  1676. && permanent.CanBeRemoved())));
  1677. if (_bounceTargetPermanents.Count == 0) yield break;
  1678. _bounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1679. #region cut in effect
  1680. // "When permanents would return to hand" effect
  1681. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1682. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1683. _bounceTargetPermanents,
  1684. cardEffect,
  1685. null
  1686. ),
  1687. EffectTiming.WhenReturntoHandAnyone));
  1688. // "When permanents would remove field" effect
  1689. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1690. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1691. _bounceTargetPermanents,
  1692. cardEffect,
  1693. null
  1694. ),
  1695. EffectTiming.WhenRemoveField));
  1696. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1697. {
  1698. foreach (Permanent permanent in _bounceTargetPermanents)
  1699. {
  1700. permanent.ShowHandBounceEffect();
  1701. }
  1702. // shrink security Digimon display
  1703. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  1704. // cut in effect process
  1705. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1706. foreach (Permanent permanent in _bounceTargetPermanents)
  1707. {
  1708. permanent.HideHandBounceEffect();
  1709. }
  1710. }
  1711. #endregion
  1712. // fix bounce target permanents
  1713. List<Permanent> bounceTargetPermanents_Fixed = _bounceTargetPermanents.Filter(permanent =>
  1714. permanent != null
  1715. && permanent.TopCard != null
  1716. && permanent.willBeRemoveField);
  1717. #region "When permanents returned to hand" effect
  1718. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  1719. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  1720. bounceTargetPermanents_Fixed,
  1721. cardEffect,
  1722. null,
  1723. false
  1724. ),
  1725. EffectTiming.OnPermamemtReturnedToHand));
  1726. #endregion
  1727. #region record parameter just before bounce
  1728. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1729. {
  1730. permanent.DPJustBeforeRemoveField = permanent.DP;
  1731. if (permanent.TopCard.HasLevel)
  1732. {
  1733. permanent.LevelJustBeforeRemoveField = permanent.Level;
  1734. }
  1735. if (permanent.TopCard.HasPlayCost)
  1736. {
  1737. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  1738. }
  1739. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  1740. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  1741. foreach (CardSource cardSource in permanent.cardSources)
  1742. {
  1743. cardSource.PermanentJustBeforeRemoveField = permanent;
  1744. }
  1745. }
  1746. #endregion
  1747. #region add log
  1748. if (bounceTargetPermanents_Fixed.Count >= 1)
  1749. {
  1750. string log = "";
  1751. log += $"\nReturn to hand:";
  1752. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1753. {
  1754. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  1755. }
  1756. log += "\n";
  1757. PlayLog.OnAddLog?.Invoke(log);
  1758. }
  1759. #endregion
  1760. #region show cards
  1761. List<CardSource> returnedCards = bounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1762. if (!_notShowCards)
  1763. {
  1764. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Cards returned to hand", true, true));
  1765. }
  1766. #endregion
  1767. #region return permanent cards to hand
  1768. List<CardSource> handCards = new List<CardSource>();
  1769. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1770. {
  1771. #region record used effect
  1772. if (permanent.TopCard != null)
  1773. {
  1774. permanent.HandBounceEffect = cardEffect;
  1775. }
  1776. #endregion
  1777. // record whether to return to hand by Burst Digivolution
  1778. permanent.IsReturnedToHandByBurstDigivolution = CardEffectCommons.IsBurst(_hashtable);
  1779. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BounceEffect(permanent, !permanent.IsReturnedToHandByBurstDigivolution));
  1780. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1781. CardSource topCard = permanent.TopCard;
  1782. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1783. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(topCard));
  1784. if (!topCard.IsDigiEgg)
  1785. {
  1786. handCards.Add(topCard);
  1787. BouncedPermanents.Add(permanent);
  1788. }
  1789. else
  1790. {
  1791. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  1792. }
  1793. }
  1794. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
  1795. #endregion
  1796. #region hide icon
  1797. foreach (Permanent permanent in _bounceTargetPermanents)
  1798. {
  1799. if (permanent != null)
  1800. {
  1801. if (permanent.TopCard != null)
  1802. {
  1803. permanent.willBeRemoveField = false;
  1804. }
  1805. }
  1806. }
  1807. #endregion
  1808. }
  1809. }
  1810. #endregion
  1811. #region Place permanent to another permanent's digivolution cards
  1812. public class IPlacePermanentToDigivolutionCards
  1813. {
  1814. public IPlacePermanentToDigivolutionCards(
  1815. List<Permanent[]> permanentArrays,
  1816. bool toTop,
  1817. ICardEffect cardEffect,
  1818. bool skipEffectAndActivateSkill = false)
  1819. {
  1820. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  1821. _toTop = toTop;
  1822. _cardEffect = cardEffect;
  1823. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  1824. }
  1825. public void SetNotShowCards()
  1826. {
  1827. _notShowCards = true;
  1828. }
  1829. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  1830. ICardEffect _cardEffect = null;
  1831. bool _toTop = false;
  1832. bool _notShowCards = false;
  1833. bool _skipEffectAndActivateSkill = false;
  1834. public bool Placed { get; private set; } = false;
  1835. public IEnumerator PlacePermanentToDigivolutionCards()
  1836. {
  1837. if (_permanentArrays.Count == 0)
  1838. {
  1839. yield break;
  1840. }
  1841. List<CardSource> addedDigivolutionCards = new List<CardSource>();
  1842. List<Permanent> removeFieldPermanents = new List<Permanent>();
  1843. foreach (Permanent[] permanentArray in _permanentArrays)
  1844. {
  1845. if (permanentArray.Length == 2)
  1846. {
  1847. Permanent DigivolutionPermanent = permanentArray[0];
  1848. Permanent getDigivolutionPermanent = permanentArray[1];
  1849. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  1850. {
  1851. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
  1852. {
  1853. if (_cardEffect != null)
  1854. {
  1855. if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
  1856. {
  1857. continue;
  1858. }
  1859. }
  1860. removeFieldPermanents.Add(DigivolutionPermanent);
  1861. }
  1862. }
  1863. }
  1864. }
  1865. foreach (Permanent permanent in removeFieldPermanents)
  1866. {
  1867. permanent.willBeRemoveField = true;
  1868. }
  1869. if (removeFieldPermanents.Count == 0)
  1870. {
  1871. yield break;
  1872. }
  1873. #region
  1874. List<SkillInfo> skillInfos = new List<SkillInfo>();
  1875. Hashtable hashtable1 =
  1876. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1877. removeFieldPermanents,
  1878. _cardEffect,
  1879. null);
  1880. #region "When permanents would remove field" effect
  1881. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1882. {
  1883. #region permanents' effects
  1884. foreach (Permanent permanent1 in player.GetFieldPermanents())
  1885. {
  1886. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  1887. {
  1888. if (cardEffect is ActivateICardEffect)
  1889. {
  1890. if (cardEffect.CanTrigger(hashtable1))
  1891. {
  1892. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1893. }
  1894. }
  1895. }
  1896. }
  1897. #endregion
  1898. #region players' effects
  1899. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  1900. {
  1901. if (cardEffect is ActivateICardEffect)
  1902. {
  1903. if (cardEffect.CanTrigger(hashtable1))
  1904. {
  1905. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1906. }
  1907. }
  1908. }
  1909. #endregion
  1910. }
  1911. #endregion
  1912. if (skillInfos.Count >= 1)
  1913. {
  1914. foreach (SkillInfo skillInfo in skillInfos)
  1915. {
  1916. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  1917. }
  1918. bool showEffect()
  1919. {
  1920. if (skillInfos.Count >= 2)
  1921. {
  1922. return true;
  1923. }
  1924. else if (skillInfos.Count == 1)
  1925. {
  1926. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  1927. {
  1928. return true;
  1929. }
  1930. }
  1931. return false;
  1932. }
  1933. if (showEffect())
  1934. {
  1935. foreach (Permanent Permanent in removeFieldPermanents)
  1936. {
  1937. if (Permanent != null)
  1938. {
  1939. if (Permanent.TopCard != null)
  1940. {
  1941. if (Permanent.willBeRemoveField)
  1942. {
  1943. if (Permanent.ShowingPermanentCard != null)
  1944. {
  1945. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  1946. {
  1947. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  1948. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  1949. }
  1950. }
  1951. }
  1952. }
  1953. }
  1954. }
  1955. #region shrink security Digimon display
  1956. if (GManager.instance.attackProcess.IsAttacking)
  1957. {
  1958. if (GManager.instance.attackProcess.SecurityDigimon != null)
  1959. {
  1960. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  1961. {
  1962. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  1963. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  1964. }
  1965. }
  1966. }
  1967. #endregion
  1968. }
  1969. // cut in effect process
  1970. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1971. foreach (Permanent Permanent in removeFieldPermanents)
  1972. {
  1973. if (Permanent != null)
  1974. {
  1975. if (Permanent.TopCard != null)
  1976. {
  1977. if (Permanent.ShowingPermanentCard != null)
  1978. {
  1979. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  1980. {
  1981. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  1982. }
  1983. }
  1984. }
  1985. }
  1986. }
  1987. }
  1988. #endregion
  1989. foreach (Permanent[] permanentArray in _permanentArrays)
  1990. {
  1991. if (permanentArray.Length == 2)
  1992. {
  1993. Permanent DigivolutionPermanent = permanentArray[0];
  1994. Permanent getDigivolutionPermanent = permanentArray[1];
  1995. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  1996. {
  1997. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
  1998. {
  1999. yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
  2000. CardSource cardSource = DigivolutionPermanent.TopCard;
  2001. #region record used effect
  2002. if (_cardEffect != null)
  2003. {
  2004. if (DigivolutionPermanent.TopCard != null)
  2005. {
  2006. DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
  2007. }
  2008. }
  2009. #endregion
  2010. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  2011. DigivolutionPermanent,
  2012. ignoreOverflow: true));
  2013. List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
  2014. if (_toTop)
  2015. {
  2016. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
  2017. }
  2018. else
  2019. {
  2020. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
  2021. }
  2022. addedDigivolutionCards.Add(cardSource);
  2023. Placed = true;
  2024. }
  2025. }
  2026. }
  2027. }
  2028. #region add log
  2029. if (addedDigivolutionCards.Count >= 1)
  2030. {
  2031. string log = "";
  2032. log += $"\nPlace in digivolution cards:";
  2033. foreach (CardSource cardSource in addedDigivolutionCards)
  2034. {
  2035. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2036. }
  2037. log += "\n";
  2038. PlayLog.OnAddLog?.Invoke(log);
  2039. }
  2040. #endregion
  2041. #region hide icon
  2042. if (addedDigivolutionCards.Count >= 1)
  2043. {
  2044. if (!_notShowCards)
  2045. {
  2046. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
  2047. }
  2048. }
  2049. #endregion
  2050. }
  2051. }
  2052. #endregion
  2053. #region Place permanents to security
  2054. public class IPutSecurityPermanent
  2055. {
  2056. public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop, bool isFaceup = false)
  2057. {
  2058. _permanent = permanent;
  2059. _hashtable = hashtable;
  2060. _toTop = toTop;
  2061. _isFaceup = isFaceup;
  2062. }
  2063. Permanent _permanent = null;
  2064. Hashtable _hashtable = new Hashtable();
  2065. bool _toTop = false;
  2066. bool _isFaceup = false;
  2067. public IEnumerator PutSecurity()
  2068. {
  2069. if (_permanent == null) yield break;
  2070. if (_permanent.TopCard == null) yield break;
  2071. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2072. if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
  2073. if (!_permanent.CanBeRemoved()) yield break;
  2074. _permanent.willBeRemoveField = true;
  2075. #region "When permanents would remove field" effect
  2076. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2077. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2078. new List<Permanent>() { _permanent },
  2079. cardEffect,
  2080. null
  2081. ),
  2082. EffectTiming.WhenRemoveField));
  2083. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2084. {
  2085. _permanent.ShowWillRemoveFieldEffect();
  2086. //effect
  2087. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2088. // cut in effect process
  2089. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false,null));
  2090. _permanent.HideWillRemoveFieldEffect();
  2091. }
  2092. #endregion
  2093. CardSource topCard = _permanent.TopCard;
  2094. if (!_permanent.willBeRemoveField)
  2095. yield break;
  2096. if (topCard == null)
  2097. yield break;
  2098. #region add log
  2099. string log = "";
  2100. string fromString = _toTop ? "top" : "bottom";
  2101. log += $"\nPut cards on {fromString} of security:";
  2102. log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
  2103. log += "\n";
  2104. PlayLog.OnAddLog?.Invoke(log);
  2105. #endregion
  2106. #region show cards
  2107. if (!topCard.IsToken)
  2108. {
  2109. if (_toTop)
  2110. {
  2111. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
  2112. }
  2113. else
  2114. {
  2115. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
  2116. }
  2117. }
  2118. #endregion
  2119. #region place permanent to security
  2120. yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
  2121. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
  2122. if (!topCard.IsToken)
  2123. {
  2124. if (!topCard.IsDigiEgg)
  2125. {
  2126. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard,faceUp:_isFaceup));
  2127. if (!_isFaceup)
  2128. topCard.SetReverse();
  2129. else
  2130. topCard.SetFace();
  2131. if (!_toTop)
  2132. {
  2133. topCard.Owner.SecurityCards.Remove(topCard);
  2134. topCard.Owner.SecurityCards.Add(topCard);
  2135. }
  2136. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
  2137. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard.Owner).AddSecurity());
  2138. }
  2139. else
  2140. {
  2141. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2142. }
  2143. }
  2144. #endregion
  2145. }
  2146. }
  2147. #endregion
  2148. #region Delete permanents
  2149. public class DestroyPermanentsClass
  2150. {
  2151. public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
  2152. {
  2153. _destroytargetPermanents = destroyTargetPermanents.Clone();
  2154. _hashtable = hashtable;
  2155. _notShowCards = notShowCards;
  2156. }
  2157. public bool IsDestroyed(Permanent permanent)
  2158. {
  2159. return DestroyedPermanents.Contains(permanent);
  2160. }
  2161. List<Permanent> _destroytargetPermanents = new List<Permanent>();
  2162. public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
  2163. Hashtable _hashtable = null;
  2164. bool _notShowCards = false;
  2165. public IEnumerator Destroy()
  2166. {
  2167. if (_destroytargetPermanents == null) yield break;
  2168. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2169. IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
  2170. bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
  2171. _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
  2172. permanent != null
  2173. && permanent.TopCard != null
  2174. && (cardEffect == null ||
  2175. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  2176. && permanent.CanBeDestroyedBySkill(cardEffect))));
  2177. if (_destroytargetPermanents.Count == 0) yield break;
  2178. _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  2179. #region cut in effect
  2180. // "When permanents would be deleted" effect
  2181. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2182. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2183. _destroytargetPermanents,
  2184. cardEffect,
  2185. battle
  2186. ),
  2187. EffectTiming.WhenPermanentWouldBeDeleted));
  2188. // "When permanents would remove field" effect
  2189. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2190. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2191. _destroytargetPermanents,
  2192. cardEffect,
  2193. battle
  2194. ),
  2195. EffectTiming.WhenRemoveField));
  2196. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2197. {
  2198. foreach (Permanent permanent in _destroytargetPermanents)
  2199. {
  2200. permanent.ShowDeleteEffect();
  2201. }
  2202. // effect
  2203. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2204. // cut in effect process
  2205. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2206. foreach (Permanent permanent in _destroytargetPermanents)
  2207. {
  2208. permanent.HideDeleteEffect();
  2209. }
  2210. }
  2211. #endregion
  2212. // fix delete target permanents
  2213. List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
  2214. permanent != null
  2215. && permanent.TopCard != null
  2216. && permanent.willBeRemoveField);
  2217. #region "When permanents are deleted" effect
  2218. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2219. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2220. destroyTargetPermanents_Fixed,
  2221. cardEffect,
  2222. battle,
  2223. isDPZero
  2224. ),
  2225. EffectTiming.OnDestroyedAnyone));
  2226. #endregion
  2227. #region record parameters just before deletion
  2228. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2229. {
  2230. permanent.DPJustBeforeRemoveField = permanent.DP;
  2231. if (permanent.TopCard.HasLevel)
  2232. {
  2233. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2234. }
  2235. if (permanent.TopCard.HasPlayCost)
  2236. {
  2237. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  2238. }
  2239. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  2240. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  2241. foreach (CardSource cardSource in permanent.cardSources)
  2242. {
  2243. cardSource.PermanentJustBeforeRemoveField = permanent;
  2244. }
  2245. }
  2246. #endregion
  2247. #region add log
  2248. if (destroyTargetPermanents_Fixed.Count >= 1)
  2249. {
  2250. string log = "";
  2251. log += $"\nDelete:";
  2252. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2253. {
  2254. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  2255. }
  2256. log += "\n";
  2257. PlayLog.OnAddLog?.Invoke(log);
  2258. }
  2259. #endregion
  2260. #region show cards
  2261. List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2262. if (!_notShowCards)
  2263. {
  2264. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
  2265. }
  2266. #endregion
  2267. #region trash permanent cards
  2268. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2269. {
  2270. #region record wheter to be deleted by battle
  2271. if (battle != null)
  2272. {
  2273. if (permanent.TopCard != null)
  2274. {
  2275. if(CardEffectCommons.GetLoserPermanentsFromHashtable(battle.hashtable).Contains(permanent))
  2276. permanent.IsDestroyedByBattle = true;
  2277. }
  2278. }
  2279. #endregion
  2280. #region record used effect
  2281. if (permanent.TopCard != null)
  2282. {
  2283. permanent.DestroyingEffect = cardEffect;
  2284. }
  2285. #endregion
  2286. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
  2287. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2288. CardSource topCard = permanent.TopCard;
  2289. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2290. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
  2291. DestroyedPermanents.Add(permanent);
  2292. }
  2293. #endregion
  2294. #region hide icon
  2295. foreach (Permanent permanent in _destroytargetPermanents)
  2296. {
  2297. if (permanent != null)
  2298. {
  2299. if (permanent.TopCard != null)
  2300. {
  2301. permanent.willBeRemoveField = false;
  2302. }
  2303. }
  2304. }
  2305. #endregion
  2306. }
  2307. }
  2308. #endregion
  2309. #region Security check
  2310. public class ISecurityCheck
  2311. {
  2312. public ISecurityCheck(Permanent AttackingPermanent, Player player)
  2313. {
  2314. this.AttackingPermanent = AttackingPermanent;
  2315. this.player = player;
  2316. }
  2317. Permanent AttackingPermanent { get; set; }
  2318. Player player { get; set; }
  2319. public IEnumerator SecurityCheck()
  2320. {
  2321. bool StopSecurityCheck()
  2322. {
  2323. if (AttackingPermanent == null)
  2324. {
  2325. return true;
  2326. }
  2327. if (AttackingPermanent.TopCard == null)
  2328. {
  2329. return true;
  2330. }
  2331. if (!AttackingPermanent.IsDigimon)
  2332. return true;
  2333. return false;
  2334. }
  2335. if (!StopSecurityCheck())
  2336. {
  2337. if (AttackingPermanent.Strike == 0)
  2338. {
  2339. yield break;
  2340. }
  2341. GManager.instance.turnStateMachine.IsSelecting = true;
  2342. GManager.instance.turnStateMachine.isSecurityCehck = true;
  2343. #region loop while there are 1 or more security cards
  2344. if (player.SecurityCards.Count >= 1)
  2345. {
  2346. int checkedCount = 0;
  2347. while (true)
  2348. {
  2349. if (StopSecurityCheck())
  2350. {
  2351. break;
  2352. }
  2353. if (checkedCount >= AttackingPermanent.Strike)
  2354. {
  2355. break;
  2356. }
  2357. if (player.SecurityCards.Count >= 1)
  2358. {
  2359. List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
  2360. CardSource brokenSecurityCard = player.SecurityCards[0];
  2361. Hashtable hashtable = new Hashtable()
  2362. {
  2363. {"AttackingPermanent", AttackingPermanent},
  2364. {"Card", brokenSecurityCard}
  2365. };
  2366. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
  2367. {
  2368. triggeredSkillInfos.Add(skillInfo);
  2369. }
  2370. checkedCount++;
  2371. PlayLog.OnAddLog?.Invoke($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
  2372. if (brokenSecurityCard.IsDigimon)
  2373. {
  2374. GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
  2375. }
  2376. #region effect
  2377. player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2378. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
  2379. yield return new WaitForSeconds(0.1f);
  2380. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
  2381. #endregion
  2382. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
  2383. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2384. player: brokenSecurityCard.Owner,
  2385. refSkillInfos: ref triggeredSkillInfos).ReduceSecurity());
  2386. #region security effect
  2387. List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
  2388. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
  2389. {
  2390. if (cardEffect is ActivateICardEffect)
  2391. {
  2392. Hashtable hashtable1 = new Hashtable();
  2393. hashtable1.Add("Card", brokenSecurityCard);
  2394. if (cardEffect.CanUse(hashtable1))
  2395. {
  2396. secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
  2397. }
  2398. }
  2399. }
  2400. List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
  2401. bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
  2402. if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
  2403. {
  2404. if (!brokenSecurityCard.IsDigimon)
  2405. {
  2406. yield return new WaitForSeconds(0.3f);
  2407. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2408. }
  2409. }
  2410. else
  2411. {
  2412. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
  2413. yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
  2414. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2415. foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
  2416. {
  2417. skillInfos.Add(skillInfo);
  2418. }
  2419. List<CardSource> cardSources = new List<CardSource>();
  2420. for (int j = 0; j < skillInfos.Count; j++)
  2421. {
  2422. cardSources.Add(brokenSecurityCard);
  2423. }
  2424. while (skillInfos.Count >= 1)
  2425. {
  2426. SkillInfo selectedSkillInfo = null;
  2427. if (skillInfos.Count == 1)
  2428. {
  2429. selectedSkillInfo = skillInfos[0];
  2430. }
  2431. else
  2432. {
  2433. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  2434. selectCardEffect.SetUp(
  2435. canTargetCondition: (cardSource) => true,
  2436. canTargetCondition_ByPreSelecetedList: null,
  2437. canEndSelectCondition: null,
  2438. canNoSelect: () => false,
  2439. selectCardCoroutine: null,
  2440. afterSelectCardCoroutine: null,
  2441. message: "select security effect",
  2442. maxCount: 1,
  2443. canEndNotMax: false,
  2444. isShowOpponent: false,
  2445. mode: SelectCardEffect.Mode.Custom,
  2446. root: SelectCardEffect.Root.Custom,
  2447. customRootCardList: cardSources,
  2448. canLookReverseCard: true,
  2449. selectPlayer: player,
  2450. cardEffect: null);
  2451. selectCardEffect.SetUpSkillInfos(skillInfos);
  2452. selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
  2453. selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  2454. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  2455. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  2456. {
  2457. if (selectedIndexes.Count == 1)
  2458. {
  2459. selectedSkillInfo = skillInfos[selectedIndexes[0]];
  2460. yield return null;
  2461. }
  2462. }
  2463. }
  2464. if (selectedSkillInfo != null)
  2465. {
  2466. ICardEffect cardEffect = selectedSkillInfo.CardEffect;
  2467. Hashtable hashtable2 = selectedSkillInfo.Hashtable;
  2468. if (cardEffect.EffectSourceCard == brokenSecurityCard)
  2469. {
  2470. if (cardEffect is ActivateICardEffect)
  2471. {
  2472. skillInfos.Remove(selectedSkillInfo);
  2473. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  2474. cardEffect,
  2475. hashtable2));
  2476. }
  2477. }
  2478. }
  2479. }
  2480. }
  2481. #endregion
  2482. // auto process check
  2483. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2484. // stack effect of "When cards are removed from security" and "checks secuirty"
  2485. foreach (SkillInfo skillInfo in triggeredSkillInfos)
  2486. {
  2487. GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
  2488. }
  2489. // auto process check
  2490. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2491. if (!StopSecurityCheck())
  2492. {
  2493. #region battle with security Digimon
  2494. if (brokenSecurityCard.IsDigimon)
  2495. {
  2496. bool doBattle = true;
  2497. #region "ignore battle" effect
  2498. Hashtable hashtable3 = new Hashtable()
  2499. {
  2500. {"Card", brokenSecurityCard}
  2501. };
  2502. #region the security Digimon's effect
  2503. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
  2504. {
  2505. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2506. {
  2507. if (cardEffect.CanUse(hashtable3))
  2508. {
  2509. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2510. {
  2511. doBattle = false;
  2512. }
  2513. }
  2514. }
  2515. }
  2516. #endregion
  2517. #region player's effect
  2518. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2519. {
  2520. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2521. {
  2522. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2523. {
  2524. if (cardEffect.CanUse(hashtable3))
  2525. {
  2526. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2527. {
  2528. doBattle = false;
  2529. }
  2530. }
  2531. }
  2532. }
  2533. }
  2534. #endregion
  2535. #endregion
  2536. if (doBattle)
  2537. {
  2538. yield return new WaitForSeconds(0.3f);
  2539. yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
  2540. }
  2541. }
  2542. #endregion
  2543. }
  2544. #region effect
  2545. yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
  2546. if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
  2547. {
  2548. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
  2549. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
  2550. {
  2551. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2552. }
  2553. }
  2554. GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
  2555. GManager.instance.attackProcess.SecurityDigimon = null;
  2556. #endregion
  2557. // reset effect until end of security check
  2558. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2559. {
  2560. player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2561. }
  2562. // auto process check
  2563. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2564. GManager.instance.turnStateMachine.IsSelecting = true;
  2565. }
  2566. else
  2567. {
  2568. break;
  2569. }
  2570. }
  2571. }
  2572. #endregion
  2573. GManager.instance.turnStateMachine.isSecurityCehck = false;
  2574. }
  2575. }
  2576. }
  2577. #endregion
  2578. #region trash cards from security
  2579. public class IDestroySecurity
  2580. {
  2581. public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
  2582. {
  2583. _player = player;
  2584. _destroySecurityCount = destroySecurityCount;
  2585. _cardEffect = cardEffect;
  2586. _fromTop = fromTop;
  2587. }
  2588. Player _player = null;
  2589. int _destroySecurityCount = 0;
  2590. ICardEffect _cardEffect = null;
  2591. bool _fromTop = false;
  2592. public IEnumerator DestroySecurity()
  2593. {
  2594. bool StopDestroySecurity()
  2595. {
  2596. if (_player.SecurityCards.Count == 0)
  2597. {
  2598. return true;
  2599. }
  2600. if (!_player.CanReduceSecurity())
  2601. {
  2602. return true;
  2603. }
  2604. return false;
  2605. }
  2606. if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
  2607. {
  2608. int count = 0;
  2609. List<CardSource> discardedCards = new List<CardSource>();
  2610. while (true)
  2611. {
  2612. if (StopDestroySecurity())
  2613. {
  2614. break;
  2615. }
  2616. if (count >= _destroySecurityCount)
  2617. {
  2618. break;
  2619. }
  2620. if (_player.SecurityCards.Count >= 1)
  2621. {
  2622. count++;
  2623. CardSource destroyedSecurityCard = _player.SecurityCards[0];
  2624. if (!_fromTop)
  2625. {
  2626. destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
  2627. }
  2628. discardedCards.Add(destroyedSecurityCard);
  2629. #region effect
  2630. _player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2631. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
  2632. yield return new WaitForSeconds(0.1f);
  2633. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
  2634. yield return new WaitForSeconds(0.5f);
  2635. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
  2636. #endregion
  2637. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
  2638. }
  2639. }
  2640. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  2641. if (discardedCards.Count >= 1)
  2642. {
  2643. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2644. player: _player,
  2645. refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
  2646. cardEffect: _cardEffect).ReduceSecurity());
  2647. #region "When security cards are trashed" effect
  2648. #region Hashtable setting
  2649. Hashtable hashtable = new Hashtable()
  2650. {
  2651. {"DiscardedCards", discardedCards},
  2652. {"CardEffect", _cardEffect},
  2653. };
  2654. #endregion
  2655. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
  2656. #endregion
  2657. }
  2658. #region add log
  2659. if (discardedCards.Count >= 1)
  2660. {
  2661. string log = "";
  2662. string fromString = _fromTop ? "Top" : "Bottom";
  2663. log += $"\nDiscarded From {fromString} Security Cards:";
  2664. foreach (CardSource cardSource in discardedCards)
  2665. {
  2666. if (cardSource != null)
  2667. {
  2668. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2669. }
  2670. }
  2671. log += "\n";
  2672. PlayLog.OnAddLog?.Invoke(log);
  2673. }
  2674. #endregion
  2675. }
  2676. }
  2677. }
  2678. #endregion
  2679. #region Battle
  2680. public class IBattle
  2681. {
  2682. public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard)
  2683. {
  2684. this.AttackingPermanent = AttackingPermanent;
  2685. this.DefendingPermanent = DefendingPermanent;
  2686. this.DefendingCard = DefendingCard;
  2687. }
  2688. public Permanent AttackingPermanent { get; private set; } = null;
  2689. public Permanent DefendingPermanent { get; private set; } = null;
  2690. CardSource DefendingCard { get; set; } = null;
  2691. public Hashtable hashtable { get; set; } = new Hashtable();
  2692. public Permanent enemyPermanent(Permanent permanent)
  2693. {
  2694. if (permanent != null)
  2695. {
  2696. if (permanent == AttackingPermanent)
  2697. {
  2698. return DefendingPermanent;
  2699. }
  2700. else if (permanent == DefendingPermanent)
  2701. {
  2702. return AttackingPermanent;
  2703. }
  2704. }
  2705. return null;
  2706. }
  2707. public int CompareStats()
  2708. {
  2709. int statCheck = 0;
  2710. if(AttackingPermanent.HasIceclad || DefendingPermanent.HasIceclad)
  2711. statCheck = AttackingPermanent.DigivolutionCards.Count - DefendingPermanent.DigivolutionCards.Count;
  2712. else
  2713. statCheck = AttackingPermanent.DP - DefendingPermanent.DP;
  2714. statCheck = Mathf.Clamp(statCheck, -1, 1);
  2715. return statCheck;
  2716. }
  2717. public IEnumerator Battle()
  2718. {
  2719. hashtable = new Hashtable();
  2720. if (AttackingPermanent != null)
  2721. {
  2722. bool IsExistingDefender()
  2723. {
  2724. // whether defender exists
  2725. if ((DefendingPermanent == null) != (DefendingCard == null))
  2726. {
  2727. if (DefendingPermanent != null)
  2728. {
  2729. if (DefendingPermanent.TopCard != null)
  2730. {
  2731. return true;
  2732. }
  2733. }
  2734. else if (DefendingCard != null)
  2735. {
  2736. return true;
  2737. }
  2738. }
  2739. return false;
  2740. }
  2741. if (IsExistingDefender())
  2742. {
  2743. if (AttackingPermanent != null)
  2744. {
  2745. AttackingPermanent.battle = this;
  2746. }
  2747. if (DefendingPermanent != null)
  2748. {
  2749. DefendingPermanent.battle = this;
  2750. }
  2751. List<Permanent> WinnerPermanents = new List<Permanent>();
  2752. List<Permanent> LoserPermanents = new List<Permanent>();
  2753. CardSource LoserCard = null;
  2754. //add log
  2755. string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
  2756. if (DefendingPermanent != null)
  2757. {
  2758. log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
  2759. }
  2760. else if (DefendingCard != null)
  2761. {
  2762. log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
  2763. }
  2764. PlayLog.OnAddLog?.Invoke(log);
  2765. #region "At the start of battle" effect
  2766. Permanent _AttackingPermanent = null;
  2767. Permanent _DefendingPermanent = null;
  2768. if (AttackingPermanent != null)
  2769. {
  2770. if (AttackingPermanent.TopCard != null)
  2771. {
  2772. _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
  2773. }
  2774. }
  2775. if (DefendingPermanent != null)
  2776. {
  2777. if (DefendingPermanent.TopCard != null)
  2778. {
  2779. _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
  2780. }
  2781. }
  2782. hashtable.Add("AttackingPermanent", _AttackingPermanent);
  2783. hashtable.Add("DefendingPermanent", _DefendingPermanent);
  2784. hashtable.Add("DefendingCard", DefendingCard);
  2785. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
  2786. #endregion
  2787. #region Show effect
  2788. bool ShowEffect()
  2789. {
  2790. if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
  2791. {
  2792. return true;
  2793. }
  2794. else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
  2795. {
  2796. if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
  2797. {
  2798. return true;
  2799. }
  2800. }
  2801. return false;
  2802. }
  2803. if (ShowEffect())
  2804. {
  2805. if (GManager.instance.attackProcess.IsAttacking)
  2806. {
  2807. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2808. {
  2809. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2810. {
  2811. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2812. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2813. }
  2814. }
  2815. }
  2816. }
  2817. #endregion
  2818. // auto process check
  2819. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2820. GManager.instance.turnStateMachine.IsSelecting = true;
  2821. //Preemptive end battle if the attack process is ended
  2822. if(GManager.instance.attackProcess.IsEndAttack)
  2823. yield break;
  2824. #region battle with permanent
  2825. if (DefendingPermanent != null)
  2826. {
  2827. int battleResults = CompareStats();
  2828. if (battleResults == 1)
  2829. {
  2830. WinnerPermanents.Add(AttackingPermanent);
  2831. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2832. LoserPermanents.Add(DefendingPermanent);
  2833. }
  2834. else if (battleResults == 0)
  2835. {
  2836. WinnerPermanents.Add(AttackingPermanent);
  2837. WinnerPermanents.Add(DefendingPermanent);
  2838. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2839. LoserPermanents.Add(AttackingPermanent);
  2840. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2841. LoserPermanents.Add(DefendingPermanent);
  2842. }
  2843. else if (battleResults == -1)
  2844. {
  2845. WinnerPermanents.Add(DefendingPermanent);
  2846. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2847. LoserPermanents.Add(AttackingPermanent);
  2848. }
  2849. }
  2850. #endregion
  2851. #region battle with card
  2852. else if (DefendingCard != null)
  2853. {
  2854. if (AttackingPermanent.DP > DefendingCard.CardDP)
  2855. {
  2856. WinnerPermanents.Add(AttackingPermanent);
  2857. LoserCard = DefendingCard;
  2858. }
  2859. else if (AttackingPermanent.DP == DefendingCard.CardDP)
  2860. {
  2861. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2862. {
  2863. LoserPermanents.Add(AttackingPermanent);
  2864. }
  2865. LoserCard = DefendingCard;
  2866. }
  2867. else if (AttackingPermanent.DP < DefendingCard.CardDP)
  2868. {
  2869. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2870. {
  2871. LoserPermanents.Add(AttackingPermanent);
  2872. }
  2873. }
  2874. }
  2875. #endregion
  2876. List<Permanent> _WinnerPermanents = new List<Permanent>();
  2877. List<Permanent> _LoserPermanents = new List<Permanent>();
  2878. foreach (Permanent permanent in WinnerPermanents)
  2879. {
  2880. if (permanent.TopCard != null)
  2881. {
  2882. _WinnerPermanents.Add(new Permanent(permanent.cardSources));
  2883. }
  2884. }
  2885. foreach (Permanent permanent in LoserPermanents)
  2886. {
  2887. if (permanent.TopCard != null)
  2888. {
  2889. _LoserPermanents.Add(new Permanent(permanent.cardSources));
  2890. }
  2891. }
  2892. hashtable.Add("WinnerPermanents", _WinnerPermanents);
  2893. hashtable.Add("WinnerPermanents_real", WinnerPermanents);
  2894. hashtable.Add("LoserPermanents", _LoserPermanents);
  2895. hashtable.Add("LoserPermanents_real", LoserPermanents);
  2896. hashtable.Add("LoserCard", LoserCard);
  2897. hashtable.Add("battle", this);
  2898. // battle effect
  2899. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
  2900. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(LoserPermanents, hashtable).Destroy());
  2901. //Fix winner/loser permanents
  2902. int index = -1;
  2903. foreach (Permanent permanent in LoserPermanents)
  2904. {
  2905. if (permanent.TopCard != null)
  2906. {
  2907. index = LoserPermanents.IndexOf(permanent);
  2908. }
  2909. }
  2910. if (index >= 0)
  2911. {
  2912. LoserPermanents.RemoveAt(index);
  2913. _LoserPermanents.RemoveAt(index);
  2914. hashtable["LoserPermanents"] = _LoserPermanents;
  2915. hashtable["LoserPermanents_real"] = LoserPermanents;
  2916. }
  2917. //LoserPermanents = LoserPermanents.Filter(permanent => permanent.TopCard != null);
  2918. //_LoserPermanents = _LoserPermanents.Filter(permanent => permanent.TopCard != null);
  2919. //hashtable["LoserPermanents"] = _LoserPermanents;
  2920. //hashtable["LoserPermanents_real"] = LoserPermanents;
  2921. // "At the end of battle" effect
  2922. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
  2923. #region move up effect
  2924. if (ShowEffect())
  2925. {
  2926. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
  2927. }
  2928. #endregion
  2929. #region effect when determine whether to do security check
  2930. List<SkillInfo> skillInfos_Pierce = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnDetermineDoSecurityCheck)
  2931. .Filter(skillInfo => skillInfo.CardEffect != null && skillInfo.CardEffect.CanActivate(skillInfo.Hashtable));
  2932. if (skillInfos_Pierce.Count >= 1)
  2933. {
  2934. GManager.instance.autoProcessing.PutStackedSkill(skillInfos_Pierce[0]);
  2935. }
  2936. #endregion
  2937. }
  2938. }
  2939. // auto process check
  2940. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2941. #region reset effect until the end of battle
  2942. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2943. {
  2944. foreach (Permanent permanent in player.GetFieldPermanents())
  2945. {
  2946. permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  2947. }
  2948. player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  2949. }
  2950. #endregion
  2951. if (AttackingPermanent != null)
  2952. {
  2953. AttackingPermanent.battle = null;
  2954. }
  2955. if (DefendingPermanent != null)
  2956. {
  2957. DefendingPermanent.battle = null;
  2958. }
  2959. }
  2960. }
  2961. #endregion
  2962. #region De-digivolve
  2963. public class IDegeneration
  2964. {
  2965. public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect)
  2966. {
  2967. _permanent = permanent;
  2968. _degenerationCount = DegenerationCount;
  2969. _cardEffect = cardEffect;
  2970. }
  2971. Permanent _permanent = null;
  2972. int _degenerationCount = 0;
  2973. ICardEffect _cardEffect = null;
  2974. public IEnumerator Degeneration()
  2975. {
  2976. if (_cardEffect == null) yield break;
  2977. if (_cardEffect.EffectSourceCard == null) yield break;
  2978. if (_permanent == null) yield break;
  2979. if (_permanent.TopCard == null) yield break;
  2980. if (_permanent.ImmuneFromDeDigivolve()) yield break;
  2981. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  2982. int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
  2983. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  2984. if (selectCountEffect != null)
  2985. {
  2986. Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
  2987. selectCountEffect.SetUp(
  2988. SelectPlayer: selectPlayer,
  2989. targetPermanent: _permanent,
  2990. MaxCount: maxCount,
  2991. CanNoSelect: false,
  2992. Message: "How many cards do you trash?",
  2993. Message_Enemy: "The opponent is choosing how many cards to trash.",
  2994. SelectCountCoroutine: SelectCountCoroutine);
  2995. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  2996. IEnumerator SelectCountCoroutine(int count)
  2997. {
  2998. _degenerationCount = count;
  2999. yield return null;
  3000. }
  3001. }
  3002. if (_degenerationCount >= 1)
  3003. {
  3004. int count = 0;
  3005. List<CardSource> selectedCards = new List<CardSource>();
  3006. while (true)
  3007. {
  3008. bool StopCondition()
  3009. {
  3010. if (_permanent.HasNoDigivolutionCards)
  3011. {
  3012. return true;
  3013. }
  3014. if (_permanent.Level == 3)
  3015. {
  3016. if (_permanent.TopCard != null)
  3017. {
  3018. if (_permanent.TopCard.HasLevel)
  3019. {
  3020. return true;
  3021. }
  3022. }
  3023. }
  3024. if (count >= _degenerationCount)
  3025. {
  3026. return true;
  3027. }
  3028. return false;
  3029. }
  3030. if (StopCondition())
  3031. {
  3032. break;
  3033. }
  3034. if (count == 0)
  3035. {
  3036. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3037. }
  3038. CardSource cardSource = _permanent.TopCard;
  3039. selectedCards.Add(cardSource);
  3040. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  3041. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3042. if (!cardSource.IsToken)
  3043. {
  3044. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3045. }
  3046. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  3047. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3048. count++;
  3049. }
  3050. #region add log
  3051. if (selectedCards.Count >= 1)
  3052. {
  3053. string log = "";
  3054. log += $"\nDe-Digivolve :";
  3055. foreach (CardSource cardSource in selectedCards)
  3056. {
  3057. if (cardSource != null)
  3058. {
  3059. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3060. }
  3061. }
  3062. log += "\n";
  3063. PlayLog.OnAddLog?.Invoke(log);
  3064. }
  3065. #endregion
  3066. }
  3067. }
  3068. }
  3069. #endregion
  3070. #region Trash digivolution cards
  3071. public class ITrashDigivolutionCards
  3072. {
  3073. public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  3074. {
  3075. _permanent = permanent;
  3076. _trashTargetCards = trashTargetCards.Clone();
  3077. _cardEffect = cardEffect;
  3078. }
  3079. Permanent _permanent = null;
  3080. List<CardSource> _trashTargetCards = new List<CardSource>();
  3081. ICardEffect _cardEffect = null;
  3082. public IEnumerator TrashDigivolutionCards()
  3083. {
  3084. if (_trashTargetCards == null) yield break;
  3085. if (_cardEffect == null) yield break;
  3086. if (_permanent == null) yield break;
  3087. if (_permanent.TopCard == null) yield break;
  3088. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3089. if (_permanent.HasNoDigivolutionCards) yield break;
  3090. _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
  3091. _permanent.DigivolutionCards.Contains(cardSource) &&
  3092. !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
  3093. if (_trashTargetCards.Count == 0) yield break;
  3094. _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
  3095. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  3096. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  3097. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3098. #region cut in effect - Would discard
  3099. // "When digivolution cards would be trashed" effect
  3100. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  3101. CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
  3102. _permanent,
  3103. _trashTargetCards,
  3104. _cardEffect
  3105. ),
  3106. EffectTiming.WhenWouldDigivolutionCardDiscarded));
  3107. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  3108. {
  3109. // effect
  3110. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  3111. // cut in effect process
  3112. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3113. }
  3114. #endregion
  3115. //fix trash target permanent
  3116. Permanent permanentTarget_Fixed = _permanent;
  3117. // fix trash sources sources
  3118. List<CardSource> trashDigivolutionCards_Fixed = _trashTargetCards.Filter(cardsource =>
  3119. cardsource != null
  3120. && cardsource.willBeRemoveSources);
  3121. #region "When digivolution cards are trashed" effect
  3122. #region Hashtable Setting
  3123. Hashtable hashtable = new Hashtable()
  3124. {
  3125. {"CardEffect", _cardEffect},
  3126. {"Permanent", permanentTarget_Fixed},
  3127. {"DiscardedCards", trashDigivolutionCards_Fixed},
  3128. };
  3129. #endregion
  3130. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
  3131. #endregion
  3132. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  3133. foreach (CardSource cardSource in trashDigivolutionCards_Fixed)
  3134. {
  3135. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
  3136. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3137. if (!cardSource.IsToken)
  3138. {
  3139. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3140. }
  3141. cardSource.willBeRemoveSources = false;
  3142. }
  3143. }
  3144. }
  3145. #endregion
  3146. #region Return digivolution cards to deck bottom
  3147. public class ReturnToLibraryBottomDigivolutionCardsClass
  3148. {
  3149. public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
  3150. {
  3151. _permanent = permanent;
  3152. _cardSources = cardSources.Clone();
  3153. _hashtable = hashtable;
  3154. }
  3155. Permanent _permanent = null;
  3156. List<CardSource> _cardSources = new List<CardSource>();
  3157. Hashtable _hashtable = null;
  3158. public IEnumerator ReturnToLibraryBottomDigivolutionCards()
  3159. {
  3160. if (_permanent == null) yield break;
  3161. if (_permanent.TopCard == null) yield break;
  3162. if (_cardSources == null) yield break;
  3163. _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
  3164. if (_cardSources.Count == 0) yield break;
  3165. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3166. if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
  3167. string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
  3168. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
  3169. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3170. #region "When digivolution cards are returned to deck" effect
  3171. #region Hashtable Setting
  3172. Hashtable hashtable1 = new Hashtable()
  3173. {
  3174. {"Permanent", _permanent},
  3175. {"DeckBottomCards", _cardSources},
  3176. {"CardEffect", CardEffect},
  3177. };
  3178. #endregion
  3179. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
  3180. #endregion
  3181. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
  3182. }
  3183. }
  3184. #endregion
  3185. #region Reduce security
  3186. public class IReduceSecurity
  3187. {
  3188. public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos, ICardEffect cardEffect = null)
  3189. {
  3190. _player = player;
  3191. _refSkillInfos = refSkillInfos;
  3192. _cardEffect = cardEffect;
  3193. }
  3194. Player _player = null;
  3195. List<SkillInfo> _refSkillInfos = null;
  3196. ICardEffect _cardEffect = null;
  3197. public IEnumerator ReduceSecurity()
  3198. {
  3199. #region "When cards are removed from security" effect
  3200. #region Hashtable Setting
  3201. Hashtable hashtable = new Hashtable()
  3202. {
  3203. {"Player", _player},
  3204. {"SkillInfo",_refSkillInfos },
  3205. {"CardEffect",_cardEffect}
  3206. };
  3207. #endregion
  3208. if (_refSkillInfos == null)
  3209. {
  3210. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
  3211. }
  3212. else
  3213. {
  3214. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
  3215. {
  3216. _refSkillInfos.Add(skillInfo);
  3217. }
  3218. }
  3219. #endregion
  3220. }
  3221. }
  3222. #endregion
  3223. #region Add Security
  3224. public class IAddSecurity
  3225. {
  3226. public IAddSecurity(Player player)
  3227. {
  3228. _player = player;
  3229. }
  3230. Player _player { get; set; }
  3231. public IEnumerator AddSecurity()
  3232. {
  3233. #region "When security cards are added" effect
  3234. #region Hashtable setting
  3235. Hashtable hashtable = new Hashtable()
  3236. {
  3237. {"Player", _player}
  3238. };
  3239. #endregion
  3240. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
  3241. #endregion
  3242. }
  3243. }
  3244. #endregion
  3245. #region Suspend permanents
  3246. public class SuspendPermanentsClass
  3247. {
  3248. public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
  3249. {
  3250. _permanents = permanents;
  3251. _hashtable = hashtable;
  3252. }
  3253. List<Permanent> _permanents { get; set; }
  3254. Hashtable _hashtable { get; set; }
  3255. public IEnumerator Tap()
  3256. {
  3257. if (_permanents.Count == 0) yield break;
  3258. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3259. bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
  3260. bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
  3261. List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
  3262. bool PermanentCondition(Permanent permanent)
  3263. {
  3264. if (permanent != null)
  3265. {
  3266. if (permanent.TopCard != null)
  3267. {
  3268. if (permanent.IsSuspended)
  3269. {
  3270. return false;
  3271. }
  3272. if (!permanent.CanSuspend)
  3273. {
  3274. return false;
  3275. }
  3276. if (CardEffect != null)
  3277. {
  3278. if (permanent.TopCard.CanNotBeAffected(CardEffect))
  3279. {
  3280. return false;
  3281. }
  3282. }
  3283. }
  3284. }
  3285. return true;
  3286. }
  3287. foreach (Permanent permanent in suspendTargetPermanents)
  3288. {
  3289. permanent.IsSuspended = true;
  3290. GManager.OnCardSuspendedChanged?.Invoke(true);
  3291. permanent.DPWhenSuspended = permanent.DP;
  3292. if (permanent.ShowingPermanentCard != null)
  3293. {
  3294. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3295. }
  3296. }
  3297. if (suspendTargetPermanents.Count >= 1)
  3298. {
  3299. #region "Effects when permanents suspend
  3300. #region Hashtable Setting
  3301. Hashtable _hashtable = new Hashtable(){
  3302. {"Permanents", suspendTargetPermanents},
  3303. {"IsBlock", IsBlock}
  3304. };
  3305. if (CardEffect != null)
  3306. {
  3307. _hashtable.Add("CardEffect", CardEffect);
  3308. }
  3309. #endregion
  3310. if (IsAttack) yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3311. else yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3312. #endregion
  3313. yield return new WaitForSeconds(0.3f);
  3314. }
  3315. }
  3316. }
  3317. #endregion
  3318. #region Unsuspend permanents
  3319. public class IUnsuspendPermanents
  3320. {
  3321. public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
  3322. {
  3323. _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  3324. _cardEffect = cardEffect;
  3325. }
  3326. List<Permanent> _permanents { get; set; }
  3327. ICardEffect _cardEffect { get; set; }
  3328. public IEnumerator Unsuspend()
  3329. {
  3330. //Permanent list that will unsuspend
  3331. List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
  3332. permanent != null
  3333. && permanent.TopCard != null
  3334. && permanent.IsSuspended
  3335. && permanent.CanUnsuspend
  3336. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3337. #region "When permanents would unsuspend" effect
  3338. #region Hashtable Setting
  3339. Hashtable hashtable1 = new Hashtable()
  3340. {
  3341. {"CardEffect", _cardEffect},
  3342. {"Permanents", untappedPermanets},
  3343. };
  3344. #endregion
  3345. List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
  3346. if (skillInfos.Count >= 1)
  3347. {
  3348. foreach (SkillInfo skillInfo in skillInfos)
  3349. {
  3350. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  3351. }
  3352. foreach (Permanent permanent in untappedPermanets)
  3353. {
  3354. permanent.ShowUnsuspendEffect();
  3355. }
  3356. //cut in effects
  3357. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3358. untappedPermanets.ForEach(permanent =>
  3359. {
  3360. if (permanent.ShowingPermanentCard != null)
  3361. {
  3362. permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
  3363. }
  3364. });
  3365. }
  3366. #endregion
  3367. // fix unsuspend target permanents
  3368. List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
  3369. permanent != null
  3370. && permanent.TopCard != null
  3371. && permanent.IsSuspended
  3372. && permanent.CanUnsuspend
  3373. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3374. if (untappedPermanets_Fixed.Count >= 1)
  3375. {
  3376. foreach (Permanent permanent in untappedPermanets_Fixed)
  3377. {
  3378. permanent.IsSuspended = false;
  3379. if (permanent.ShowingPermanentCard != null)
  3380. {
  3381. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3382. }
  3383. }
  3384. #region "When permanents are unsuspended" effect
  3385. #region Hashtable Setting
  3386. Hashtable hashtable2 = new Hashtable()
  3387. {
  3388. {"CardEffect", _cardEffect},
  3389. {"Permanents", untappedPermanets_Fixed},
  3390. };
  3391. #endregion
  3392. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
  3393. #endregion
  3394. yield return new WaitForSeconds(0.3f);
  3395. }
  3396. foreach (Permanent permanent in untappedPermanets)
  3397. {
  3398. permanent.UntilNextUntapEffects = new List<Func<EffectTiming, ICardEffect>>();
  3399. }
  3400. }
  3401. }
  3402. #endregion
  3403. #region Trash cards from deck top
  3404. public class ITrashDeckCards
  3405. {
  3406. public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
  3407. {
  3408. this.cardSources = new List<CardSource>();
  3409. foreach (CardSource cardSource in cardSources)
  3410. {
  3411. this.cardSources.Add(cardSource);
  3412. }
  3413. this.cardEffect = cardEffect;
  3414. }
  3415. List<CardSource> cardSources { get; set; } = new List<CardSource>();
  3416. ICardEffect cardEffect { get; set; } = null;
  3417. public IEnumerator TrashDeckCards()
  3418. {
  3419. List<CardSource> trashCards = new List<CardSource>();
  3420. foreach (CardSource cardSource in cardSources)
  3421. {
  3422. if (cardSource.Owner.LibraryCards.Contains(cardSource))
  3423. {
  3424. trashCards.Add(cardSource);
  3425. }
  3426. }
  3427. if (trashCards.Count >= 1)
  3428. {
  3429. foreach (CardSource cardSource in trashCards)
  3430. {
  3431. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3432. }
  3433. #region "When cards are trashed from security" effect
  3434. #region Hashtable setting
  3435. Hashtable hashtable = new Hashtable()
  3436. {
  3437. {"DiscardedCards", trashCards},
  3438. {"CardEffect", cardEffect},
  3439. };
  3440. #endregion
  3441. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  3442. hashtable, EffectTiming.OnDiscardLibrary));
  3443. #endregion
  3444. }
  3445. }
  3446. }
  3447. #endregion
  3448. #region Overflow of ace
  3449. public class AceOverflowClass
  3450. {
  3451. public AceOverflowClass(List<CardSource> cardSources)
  3452. {
  3453. _cardSources = cardSources.Clone();
  3454. }
  3455. List<CardSource> _cardSources = new List<CardSource>();
  3456. public IEnumerator Overflow()
  3457. {
  3458. _cardSources = _cardSources
  3459. .Filter(cardSource => cardSource.IsACE && CardEffectCommons.IsExistOnBattleArea(cardSource) || CardEffectCommons.IsExistOnBreedingAreaDigimon(cardSource))
  3460. .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
  3461. .ToList();
  3462. foreach (CardSource cardSource in _cardSources)
  3463. {
  3464. yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
  3465. string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
  3466. PlayLog.OnAddLog?.Invoke(log);
  3467. }
  3468. }
  3469. }
  3470. #endregion