CardController.cs 154 KB

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