CardController.cs 149 KB

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