CardController.cs 151 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183
  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. if (!topCard.IsDigiEgg)
  1759. {
  1760. handCards.Add(topCard);
  1761. BouncedPermanents.Add(permanent);
  1762. }
  1763. else
  1764. {
  1765. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  1766. }
  1767. }
  1768. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
  1769. #endregion
  1770. #region hide icon
  1771. foreach (Permanent permanent in _bounceTargetPermanents)
  1772. {
  1773. if (permanent != null)
  1774. {
  1775. if (permanent.TopCard != null)
  1776. {
  1777. permanent.willBeRemoveField = false;
  1778. }
  1779. }
  1780. }
  1781. #endregion
  1782. }
  1783. }
  1784. #endregion
  1785. #region Place permanent to another permanent's digivolution cards
  1786. public class IPlacePermanentToDigivolutionCards
  1787. {
  1788. public IPlacePermanentToDigivolutionCards(
  1789. List<Permanent[]> permanentArrays,
  1790. bool toTop,
  1791. ICardEffect cardEffect,
  1792. bool skipEffectAndActivateSkill = false)
  1793. {
  1794. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  1795. _toTop = toTop;
  1796. _cardEffect = cardEffect;
  1797. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  1798. }
  1799. public void SetNotShowCards()
  1800. {
  1801. _notShowCards = true;
  1802. }
  1803. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  1804. ICardEffect _cardEffect = null;
  1805. bool _toTop = false;
  1806. bool _notShowCards = false;
  1807. bool _skipEffectAndActivateSkill = false;
  1808. public bool Placed { get; private set; } = false;
  1809. public IEnumerator PlacePermanentToDigivolutionCards()
  1810. {
  1811. if (_permanentArrays.Count == 0)
  1812. {
  1813. yield break;
  1814. }
  1815. List<CardSource> addedDigivolutionCards = new List<CardSource>();
  1816. List<Permanent> removeFieldPermanents = new List<Permanent>();
  1817. foreach (Permanent[] permanentArray in _permanentArrays)
  1818. {
  1819. if (permanentArray.Length == 2)
  1820. {
  1821. Permanent DigivolutionPermanent = permanentArray[0];
  1822. Permanent getDigivolutionPermanent = permanentArray[1];
  1823. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  1824. {
  1825. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
  1826. {
  1827. if (_cardEffect != null)
  1828. {
  1829. if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
  1830. {
  1831. continue;
  1832. }
  1833. }
  1834. removeFieldPermanents.Add(DigivolutionPermanent);
  1835. }
  1836. }
  1837. }
  1838. }
  1839. foreach (Permanent permanent in removeFieldPermanents)
  1840. {
  1841. permanent.willBeRemoveField = true;
  1842. }
  1843. if (removeFieldPermanents.Count == 0)
  1844. {
  1845. yield break;
  1846. }
  1847. #region
  1848. List<SkillInfo> skillInfos = new List<SkillInfo>();
  1849. Hashtable hashtable1 =
  1850. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1851. removeFieldPermanents,
  1852. _cardEffect,
  1853. null);
  1854. #region "When permanents would remove field" effect
  1855. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1856. {
  1857. #region permanents' effects
  1858. foreach (Permanent permanent1 in player.GetFieldPermanents())
  1859. {
  1860. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  1861. {
  1862. if (cardEffect is ActivateICardEffect)
  1863. {
  1864. if (cardEffect.CanTrigger(hashtable1))
  1865. {
  1866. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1867. }
  1868. }
  1869. }
  1870. }
  1871. #endregion
  1872. #region players' effects
  1873. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  1874. {
  1875. if (cardEffect is ActivateICardEffect)
  1876. {
  1877. if (cardEffect.CanTrigger(hashtable1))
  1878. {
  1879. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1880. }
  1881. }
  1882. }
  1883. #endregion
  1884. }
  1885. #endregion
  1886. if (skillInfos.Count >= 1)
  1887. {
  1888. foreach (SkillInfo skillInfo in skillInfos)
  1889. {
  1890. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  1891. }
  1892. bool showEffect()
  1893. {
  1894. if (skillInfos.Count >= 2)
  1895. {
  1896. return true;
  1897. }
  1898. else if (skillInfos.Count == 1)
  1899. {
  1900. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  1901. {
  1902. return true;
  1903. }
  1904. }
  1905. return false;
  1906. }
  1907. if (showEffect())
  1908. {
  1909. foreach (Permanent Permanent in removeFieldPermanents)
  1910. {
  1911. if (Permanent != null)
  1912. {
  1913. if (Permanent.TopCard != null)
  1914. {
  1915. if (Permanent.willBeRemoveField)
  1916. {
  1917. if (Permanent.ShowingPermanentCard != null)
  1918. {
  1919. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  1920. {
  1921. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  1922. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  1923. }
  1924. }
  1925. }
  1926. }
  1927. }
  1928. }
  1929. #region shrink security Digimon display
  1930. if (GManager.instance.attackProcess.IsAttacking)
  1931. {
  1932. if (GManager.instance.attackProcess.SecurityDigimon != null)
  1933. {
  1934. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  1935. {
  1936. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  1937. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  1938. }
  1939. }
  1940. }
  1941. #endregion
  1942. }
  1943. // cut in effect process
  1944. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  1945. foreach (Permanent Permanent in removeFieldPermanents)
  1946. {
  1947. if (Permanent != null)
  1948. {
  1949. if (Permanent.TopCard != null)
  1950. {
  1951. if (Permanent.ShowingPermanentCard != null)
  1952. {
  1953. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  1954. {
  1955. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  1956. }
  1957. }
  1958. }
  1959. }
  1960. }
  1961. }
  1962. #endregion
  1963. foreach (Permanent[] permanentArray in _permanentArrays)
  1964. {
  1965. if (permanentArray.Length == 2)
  1966. {
  1967. Permanent DigivolutionPermanent = permanentArray[0];
  1968. Permanent getDigivolutionPermanent = permanentArray[1];
  1969. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  1970. {
  1971. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
  1972. {
  1973. yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
  1974. CardSource cardSource = DigivolutionPermanent.TopCard;
  1975. #region record used effect
  1976. if (_cardEffect != null)
  1977. {
  1978. if (DigivolutionPermanent.TopCard != null)
  1979. {
  1980. DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
  1981. }
  1982. }
  1983. #endregion
  1984. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  1985. DigivolutionPermanent,
  1986. ignoreOverflow: true));
  1987. List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
  1988. if (_toTop)
  1989. {
  1990. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
  1991. }
  1992. else
  1993. {
  1994. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
  1995. }
  1996. addedDigivolutionCards.Add(cardSource);
  1997. Placed = true;
  1998. }
  1999. }
  2000. }
  2001. }
  2002. #region add log
  2003. if (addedDigivolutionCards.Count >= 1)
  2004. {
  2005. string log = "";
  2006. log += $"\nPlace in digivolution cards:";
  2007. foreach (CardSource cardSource in addedDigivolutionCards)
  2008. {
  2009. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2010. }
  2011. log += "\n";
  2012. GManager.instance.playLog.AddLogString(log);
  2013. }
  2014. #endregion
  2015. #region hide icon
  2016. if (addedDigivolutionCards.Count >= 1)
  2017. {
  2018. if (!_notShowCards)
  2019. {
  2020. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
  2021. }
  2022. }
  2023. #endregion
  2024. }
  2025. }
  2026. #endregion
  2027. #region Place permanents to security
  2028. public class IPutSecurityPermanent
  2029. {
  2030. public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop)
  2031. {
  2032. _permanent = permanent;
  2033. _hashtable = hashtable;
  2034. _toTop = toTop;
  2035. }
  2036. Permanent _permanent = null;
  2037. Hashtable _hashtable = new Hashtable();
  2038. bool _toTop = false;
  2039. public IEnumerator PutSecurity()
  2040. {
  2041. if (_permanent == null) yield break;
  2042. if (_permanent.TopCard == null) yield break;
  2043. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2044. if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
  2045. #region "When permanents would remove field" effect
  2046. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2047. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2048. new List<Permanent>() { _permanent },
  2049. cardEffect,
  2050. null
  2051. ),
  2052. EffectTiming.WhenRemoveField));
  2053. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2054. {
  2055. _permanent.ShowWillRemoveFieldEffect();
  2056. //effect
  2057. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2058. // cut in effect process
  2059. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  2060. _permanent.HideWillRemoveFieldEffect();
  2061. }
  2062. #endregion
  2063. CardSource topCard = _permanent.TopCard;
  2064. if (topCard == null) yield break;
  2065. #region add log
  2066. string log = "";
  2067. log += $"\nPut cards on top of security:";
  2068. log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
  2069. log += "\n";
  2070. GManager.instance.playLog.AddLogString(log);
  2071. #endregion
  2072. #region show cards
  2073. if (!topCard.IsToken)
  2074. {
  2075. if (_toTop)
  2076. {
  2077. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
  2078. }
  2079. else
  2080. {
  2081. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
  2082. }
  2083. }
  2084. #endregion
  2085. #region place permanent to security
  2086. yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
  2087. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
  2088. if (!topCard.IsToken)
  2089. {
  2090. if (!topCard.IsDigiEgg)
  2091. {
  2092. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard));
  2093. if (!_toTop)
  2094. {
  2095. topCard.Owner.SecurityCards.Remove(topCard);
  2096. topCard.Owner.SecurityCards.Add(topCard);
  2097. }
  2098. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
  2099. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard.Owner).AddSecurity());
  2100. }
  2101. else
  2102. {
  2103. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2104. }
  2105. }
  2106. #endregion
  2107. }
  2108. }
  2109. #endregion
  2110. #region Delete permanents
  2111. public class DestroyPermanentsClass
  2112. {
  2113. public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
  2114. {
  2115. _destroytargetPermanents = destroyTargetPermanents.Clone();
  2116. _hashtable = hashtable;
  2117. _notShowCards = notShowCards;
  2118. }
  2119. public bool IsDestroyed(Permanent permanent)
  2120. {
  2121. return DestroyedPermanents.Contains(permanent);
  2122. }
  2123. List<Permanent> _destroytargetPermanents = new List<Permanent>();
  2124. public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
  2125. Hashtable _hashtable = null;
  2126. bool _notShowCards = false;
  2127. public IEnumerator Destroy()
  2128. {
  2129. if (_destroytargetPermanents == null) yield break;
  2130. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2131. IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
  2132. bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
  2133. _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
  2134. permanent != null
  2135. && permanent.TopCard != null
  2136. && (cardEffect == null ||
  2137. (!permanent.TopCard.CanNotBeAffected(cardEffect) && permanent.CanBeDestroyedBySkill(cardEffect))));
  2138. if (_destroytargetPermanents.Count == 0) yield break;
  2139. _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  2140. #region cut in effect
  2141. // "When permanents would be deleted" effect
  2142. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2143. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2144. _destroytargetPermanents,
  2145. cardEffect,
  2146. battle
  2147. ),
  2148. EffectTiming.WhenPermanentWouldBeDeleted));
  2149. // "When permanents would remove field" effect
  2150. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2151. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2152. _destroytargetPermanents,
  2153. cardEffect,
  2154. battle
  2155. ),
  2156. EffectTiming.WhenRemoveField));
  2157. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2158. {
  2159. foreach (Permanent permanent in _destroytargetPermanents)
  2160. {
  2161. permanent.ShowDeleteEffect();
  2162. }
  2163. // effect
  2164. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2165. // cut in effect process
  2166. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  2167. foreach (Permanent permanent in _destroytargetPermanents)
  2168. {
  2169. permanent.HideDeleteEffect();
  2170. }
  2171. }
  2172. #endregion
  2173. // fix delete target permanents
  2174. List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
  2175. permanent != null
  2176. && permanent.TopCard != null
  2177. && permanent.willBeRemoveField);
  2178. #region "When permanents are deleted" effect
  2179. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2180. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2181. destroyTargetPermanents_Fixed,
  2182. cardEffect,
  2183. battle,
  2184. isDPZero
  2185. ),
  2186. EffectTiming.OnDestroyedAnyone));
  2187. #endregion
  2188. #region record parameters just before deletion
  2189. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2190. {
  2191. permanent.DPJustBeforeRemoveField = permanent.DP;
  2192. if (permanent.TopCard.HasLevel)
  2193. {
  2194. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2195. }
  2196. if (permanent.TopCard.HasPlayCost)
  2197. {
  2198. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  2199. }
  2200. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  2201. foreach (CardSource cardSource in permanent.cardSources)
  2202. {
  2203. cardSource.PermanentJustBeforeRemoveField = permanent;
  2204. }
  2205. }
  2206. #endregion
  2207. #region add log
  2208. if (destroyTargetPermanents_Fixed.Count >= 1)
  2209. {
  2210. string log = "";
  2211. log += $"\nDelete:";
  2212. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2213. {
  2214. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  2215. }
  2216. log += "\n";
  2217. GManager.instance.playLog.AddLogString(log);
  2218. }
  2219. #endregion
  2220. #region show cards
  2221. List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2222. if (!_notShowCards)
  2223. {
  2224. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
  2225. }
  2226. #endregion
  2227. #region trash permanent cards
  2228. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2229. {
  2230. #region record wheter to be deleted by battle
  2231. if (battle != null)
  2232. {
  2233. if (permanent.TopCard != null)
  2234. {
  2235. permanent.IsDestroyedByBattle = true;
  2236. }
  2237. }
  2238. #endregion
  2239. #region record used effect
  2240. if (permanent.TopCard != null)
  2241. {
  2242. permanent.DestroyingEffect = cardEffect;
  2243. }
  2244. #endregion
  2245. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
  2246. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2247. CardSource topCard = permanent.TopCard;
  2248. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2249. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
  2250. DestroyedPermanents.Add(permanent);
  2251. }
  2252. #endregion
  2253. #region hide icon
  2254. foreach (Permanent permanent in _destroytargetPermanents)
  2255. {
  2256. if (permanent != null)
  2257. {
  2258. if (permanent.TopCard != null)
  2259. {
  2260. permanent.willBeRemoveField = false;
  2261. }
  2262. }
  2263. }
  2264. #endregion
  2265. }
  2266. }
  2267. #endregion
  2268. #region Security check
  2269. public class ISecurityCheck
  2270. {
  2271. public ISecurityCheck(Permanent AttackingPermanent, Player player)
  2272. {
  2273. this.AttackingPermanent = AttackingPermanent;
  2274. this.player = player;
  2275. }
  2276. Permanent AttackingPermanent { get; set; }
  2277. Player player { get; set; }
  2278. public IEnumerator SecurityCheck()
  2279. {
  2280. bool StopSecurityCheck()
  2281. {
  2282. if (AttackingPermanent == null)
  2283. {
  2284. return true;
  2285. }
  2286. if (AttackingPermanent.TopCard == null)
  2287. {
  2288. return true;
  2289. }
  2290. return false;
  2291. }
  2292. if (!StopSecurityCheck())
  2293. {
  2294. if (AttackingPermanent.Strike == 0)
  2295. {
  2296. yield break;
  2297. }
  2298. GManager.instance.turnStateMachine.IsSelecting = true;
  2299. GManager.instance.turnStateMachine.isSecurityCehck = true;
  2300. #region loop while there are 1 or more security cards
  2301. if (player.SecurityCards.Count >= 1)
  2302. {
  2303. int checkedCount = 0;
  2304. while (true)
  2305. {
  2306. if (StopSecurityCheck())
  2307. {
  2308. break;
  2309. }
  2310. if (checkedCount >= AttackingPermanent.Strike)
  2311. {
  2312. break;
  2313. }
  2314. if (player.SecurityCards.Count >= 1)
  2315. {
  2316. List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
  2317. CardSource brokenSecurityCard = player.SecurityCards[0];
  2318. Hashtable hashtable = new Hashtable()
  2319. {
  2320. {"AttackingPermanent", AttackingPermanent},
  2321. {"Card", brokenSecurityCard}
  2322. };
  2323. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
  2324. {
  2325. triggeredSkillInfos.Add(skillInfo);
  2326. }
  2327. checkedCount++;
  2328. GManager.instance.playLog.AddLogString($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
  2329. if (brokenSecurityCard.IsDigimon)
  2330. {
  2331. GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
  2332. }
  2333. #region effect
  2334. player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2335. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
  2336. yield return new WaitForSeconds(0.1f);
  2337. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
  2338. #endregion
  2339. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2340. player: brokenSecurityCard.Owner,
  2341. refSkillInfos: ref triggeredSkillInfos).ReduceSecurity());
  2342. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
  2343. #region security effect
  2344. List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
  2345. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
  2346. {
  2347. if (cardEffect is ActivateICardEffect)
  2348. {
  2349. Hashtable hashtable1 = new Hashtable();
  2350. hashtable1.Add("Card", brokenSecurityCard);
  2351. if (cardEffect.CanUse(hashtable1))
  2352. {
  2353. secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
  2354. }
  2355. }
  2356. }
  2357. List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
  2358. bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
  2359. if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
  2360. {
  2361. if (!brokenSecurityCard.IsDigimon)
  2362. {
  2363. yield return new WaitForSeconds(0.3f);
  2364. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2365. }
  2366. }
  2367. else
  2368. {
  2369. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
  2370. yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
  2371. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2372. foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
  2373. {
  2374. skillInfos.Add(skillInfo);
  2375. }
  2376. List<CardSource> cardSources = new List<CardSource>();
  2377. for (int j = 0; j < skillInfos.Count; j++)
  2378. {
  2379. cardSources.Add(brokenSecurityCard);
  2380. }
  2381. while (skillInfos.Count >= 1)
  2382. {
  2383. SkillInfo selectedSkillInfo = null;
  2384. if (skillInfos.Count == 1)
  2385. {
  2386. selectedSkillInfo = skillInfos[0];
  2387. }
  2388. else
  2389. {
  2390. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  2391. selectCardEffect.SetUp(
  2392. canTargetCondition: (cardSource) => true,
  2393. canTargetCondition_ByPreSelecetedList: null,
  2394. canEndSelectCondition: null,
  2395. canNoSelect: () => false,
  2396. selectCardCoroutine: null,
  2397. afterSelectCardCoroutine: null,
  2398. message: "select security effect",
  2399. maxCount: 1,
  2400. canEndNotMax: false,
  2401. isShowOpponent: false,
  2402. mode: SelectCardEffect.Mode.Custom,
  2403. root: SelectCardEffect.Root.Custom,
  2404. customRootCardList: cardSources,
  2405. canLookReverseCard: true,
  2406. selectPlayer: player,
  2407. cardEffect: null);
  2408. selectCardEffect.SetUpSkillInfos(skillInfos);
  2409. selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
  2410. selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  2411. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  2412. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  2413. {
  2414. if (selectedIndexes.Count == 1)
  2415. {
  2416. selectedSkillInfo = skillInfos[selectedIndexes[0]];
  2417. yield return null;
  2418. }
  2419. }
  2420. }
  2421. if (selectedSkillInfo != null)
  2422. {
  2423. ICardEffect cardEffect = selectedSkillInfo.CardEffect;
  2424. Hashtable hashtable2 = selectedSkillInfo.Hashtable;
  2425. if (cardEffect.EffectSourceCard == brokenSecurityCard)
  2426. {
  2427. if (cardEffect is ActivateICardEffect)
  2428. {
  2429. skillInfos.Remove(selectedSkillInfo);
  2430. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  2431. cardEffect,
  2432. hashtable2));
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. #endregion
  2439. // auto process check
  2440. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2441. // stack effect of "When cards are removed from security" and "checks secuirty"
  2442. foreach (SkillInfo skillInfo in triggeredSkillInfos)
  2443. {
  2444. GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
  2445. }
  2446. // auto process check
  2447. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2448. if (!StopSecurityCheck())
  2449. {
  2450. #region battle with security Digimon
  2451. if (brokenSecurityCard.IsDigimon)
  2452. {
  2453. bool doBattle = true;
  2454. #region "ignore battle" effect
  2455. Hashtable hashtable3 = new Hashtable()
  2456. {
  2457. {"Card", brokenSecurityCard}
  2458. };
  2459. #region the security Digimon's effect
  2460. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
  2461. {
  2462. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2463. {
  2464. if (cardEffect.CanUse(hashtable3))
  2465. {
  2466. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2467. {
  2468. doBattle = false;
  2469. }
  2470. }
  2471. }
  2472. }
  2473. #endregion
  2474. #region player's effect
  2475. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2476. {
  2477. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2478. {
  2479. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2480. {
  2481. if (cardEffect.CanUse(hashtable3))
  2482. {
  2483. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2484. {
  2485. doBattle = false;
  2486. }
  2487. }
  2488. }
  2489. }
  2490. }
  2491. #endregion
  2492. #endregion
  2493. if (doBattle)
  2494. {
  2495. yield return new WaitForSeconds(0.3f);
  2496. yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
  2497. }
  2498. }
  2499. #endregion
  2500. }
  2501. #region effect
  2502. yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
  2503. if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
  2504. {
  2505. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
  2506. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
  2507. {
  2508. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2509. }
  2510. }
  2511. GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
  2512. GManager.instance.attackProcess.SecurityDigimon = null;
  2513. #endregion
  2514. // reset effect until end of security check
  2515. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2516. {
  2517. player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2518. }
  2519. // auto process check
  2520. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2521. GManager.instance.turnStateMachine.IsSelecting = true;
  2522. }
  2523. else
  2524. {
  2525. break;
  2526. }
  2527. }
  2528. }
  2529. #endregion
  2530. GManager.instance.turnStateMachine.isSecurityCehck = false;
  2531. }
  2532. }
  2533. }
  2534. #endregion
  2535. #region trash cards from security
  2536. public class IDestroySecurity
  2537. {
  2538. public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
  2539. {
  2540. _player = player;
  2541. _destroySecurityCount = destroySecurityCount;
  2542. _cardEffect = cardEffect;
  2543. _fromTop = fromTop;
  2544. }
  2545. Player _player = null;
  2546. int _destroySecurityCount = 0;
  2547. ICardEffect _cardEffect = null;
  2548. bool _fromTop = false;
  2549. public IEnumerator DestroySecurity()
  2550. {
  2551. bool StopDestroySecurity()
  2552. {
  2553. if (_player.SecurityCards.Count == 0)
  2554. {
  2555. return true;
  2556. }
  2557. if (!_player.CanReduceSecurity())
  2558. {
  2559. return true;
  2560. }
  2561. return false;
  2562. }
  2563. if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
  2564. {
  2565. int count = 0;
  2566. List<CardSource> discardedCards = new List<CardSource>();
  2567. while (true)
  2568. {
  2569. if (StopDestroySecurity())
  2570. {
  2571. break;
  2572. }
  2573. if (count >= _destroySecurityCount)
  2574. {
  2575. break;
  2576. }
  2577. if (_player.SecurityCards.Count >= 1)
  2578. {
  2579. count++;
  2580. CardSource destroyedSecurityCard = _player.SecurityCards[0];
  2581. if (!_fromTop)
  2582. {
  2583. destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
  2584. }
  2585. discardedCards.Add(destroyedSecurityCard);
  2586. #region effect
  2587. _player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2588. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
  2589. yield return new WaitForSeconds(0.1f);
  2590. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
  2591. yield return new WaitForSeconds(0.5f);
  2592. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
  2593. #endregion
  2594. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
  2595. }
  2596. }
  2597. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  2598. if (discardedCards.Count >= 1)
  2599. {
  2600. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2601. player: _player,
  2602. refSkillInfos: ref ContinuousController.instance.nullSkillInfos).ReduceSecurity());
  2603. }
  2604. if (discardedCards.Count >= 1)
  2605. {
  2606. #region "When security cards are trashed" effect
  2607. #region Hashtable setting
  2608. Hashtable hashtable = new Hashtable()
  2609. {
  2610. {"DiscardedCards", discardedCards},
  2611. {"CardEffect", _cardEffect},
  2612. };
  2613. #endregion
  2614. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
  2615. #endregion
  2616. }
  2617. #region add log
  2618. if (discardedCards.Count >= 1)
  2619. {
  2620. string log = "";
  2621. log += $"\nDiscarded Security Cards:";
  2622. foreach (CardSource cardSource in discardedCards)
  2623. {
  2624. if (cardSource != null)
  2625. {
  2626. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2627. }
  2628. }
  2629. log += "\n";
  2630. GManager.instance.playLog.AddLogString(log);
  2631. }
  2632. #endregion
  2633. }
  2634. }
  2635. }
  2636. #endregion
  2637. #region Battle
  2638. public class IBattle
  2639. {
  2640. public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard)
  2641. {
  2642. this.AttackingPermanent = AttackingPermanent;
  2643. this.DefendingPermanent = DefendingPermanent;
  2644. this.DefendingCard = DefendingCard;
  2645. }
  2646. public Permanent AttackingPermanent { get; private set; } = null;
  2647. public Permanent DefendingPermanent { get; private set; } = null;
  2648. CardSource DefendingCard { get; set; } = null;
  2649. public Hashtable hashtable { get; set; } = new Hashtable();
  2650. public Permanent enemyPermanent(Permanent permanent)
  2651. {
  2652. if (permanent != null)
  2653. {
  2654. if (permanent == AttackingPermanent)
  2655. {
  2656. return DefendingPermanent;
  2657. }
  2658. else if (permanent == DefendingPermanent)
  2659. {
  2660. return AttackingPermanent;
  2661. }
  2662. }
  2663. return null;
  2664. }
  2665. public IEnumerator Battle()
  2666. {
  2667. hashtable = new Hashtable();
  2668. if (AttackingPermanent != null)
  2669. {
  2670. bool IsExistingDefender()
  2671. {
  2672. // whether defender exists
  2673. if ((DefendingPermanent == null) != (DefendingCard == null))
  2674. {
  2675. if (DefendingPermanent != null)
  2676. {
  2677. if (DefendingPermanent.TopCard != null)
  2678. {
  2679. return true;
  2680. }
  2681. }
  2682. else if (DefendingCard != null)
  2683. {
  2684. return true;
  2685. }
  2686. }
  2687. return false;
  2688. }
  2689. if (IsExistingDefender())
  2690. {
  2691. if (AttackingPermanent != null)
  2692. {
  2693. AttackingPermanent.battle = this;
  2694. }
  2695. if (DefendingPermanent != null)
  2696. {
  2697. DefendingPermanent.battle = this;
  2698. }
  2699. List<Permanent> WinnerPermanents = new List<Permanent>();
  2700. List<Permanent> LoserPermanents = new List<Permanent>();
  2701. CardSource LoserCard = null;
  2702. //add log
  2703. string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
  2704. if (DefendingPermanent != null)
  2705. {
  2706. log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
  2707. }
  2708. else if (DefendingCard != null)
  2709. {
  2710. log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
  2711. }
  2712. GManager.instance.playLog.AddLogString(log);
  2713. #region "At the start of battle" effect
  2714. Permanent _AttackingPermanent = null;
  2715. Permanent _DefendingPermanent = null;
  2716. if (AttackingPermanent != null)
  2717. {
  2718. if (AttackingPermanent.TopCard != null)
  2719. {
  2720. _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
  2721. }
  2722. }
  2723. if (DefendingPermanent != null)
  2724. {
  2725. if (DefendingPermanent.TopCard != null)
  2726. {
  2727. _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
  2728. }
  2729. }
  2730. hashtable.Add("AttackingPermanent", _AttackingPermanent);
  2731. hashtable.Add("DefendingPermanent", _DefendingPermanent);
  2732. hashtable.Add("DefendingCard", DefendingCard);
  2733. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
  2734. #endregion
  2735. #region Show effect
  2736. bool ShowEffect()
  2737. {
  2738. if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
  2739. {
  2740. return true;
  2741. }
  2742. else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
  2743. {
  2744. if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
  2745. {
  2746. return true;
  2747. }
  2748. }
  2749. return false;
  2750. }
  2751. if (ShowEffect())
  2752. {
  2753. if (GManager.instance.attackProcess.IsAttacking)
  2754. {
  2755. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2756. {
  2757. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2758. {
  2759. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2760. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2761. }
  2762. }
  2763. }
  2764. }
  2765. #endregion
  2766. // auto process check
  2767. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2768. GManager.instance.turnStateMachine.IsSelecting = true;
  2769. #region battle with permanent
  2770. if (DefendingPermanent != null)
  2771. {
  2772. if (AttackingPermanent.DP > DefendingPermanent.DP)
  2773. {
  2774. WinnerPermanents.Add(AttackingPermanent);
  2775. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2776. {
  2777. LoserPermanents.Add(DefendingPermanent);
  2778. }
  2779. }
  2780. else if (AttackingPermanent.DP == DefendingPermanent.DP)
  2781. {
  2782. WinnerPermanents.Add(AttackingPermanent);
  2783. WinnerPermanents.Add(DefendingPermanent);
  2784. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2785. {
  2786. LoserPermanents.Add(AttackingPermanent);
  2787. }
  2788. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2789. {
  2790. LoserPermanents.Add(DefendingPermanent);
  2791. }
  2792. }
  2793. else if (AttackingPermanent.DP < DefendingPermanent.DP)
  2794. {
  2795. WinnerPermanents.Add(DefendingPermanent);
  2796. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2797. {
  2798. LoserPermanents.Add(AttackingPermanent);
  2799. }
  2800. }
  2801. }
  2802. #endregion
  2803. #region battle with card
  2804. else if (DefendingCard != null)
  2805. {
  2806. if (AttackingPermanent.DP > DefendingCard.CardDP)
  2807. {
  2808. WinnerPermanents.Add(AttackingPermanent);
  2809. LoserCard = DefendingCard;
  2810. }
  2811. else if (AttackingPermanent.DP == DefendingCard.CardDP)
  2812. {
  2813. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2814. {
  2815. LoserPermanents.Add(AttackingPermanent);
  2816. }
  2817. LoserCard = DefendingCard;
  2818. }
  2819. else if (AttackingPermanent.DP < DefendingCard.CardDP)
  2820. {
  2821. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2822. {
  2823. LoserPermanents.Add(AttackingPermanent);
  2824. }
  2825. }
  2826. }
  2827. #endregion
  2828. List<Permanent> _WinnerPermanents = new List<Permanent>();
  2829. List<Permanent> _LoserPermanents = new List<Permanent>();
  2830. foreach (Permanent permanent in WinnerPermanents)
  2831. {
  2832. if (permanent.TopCard != null)
  2833. {
  2834. _WinnerPermanents.Add(new Permanent(permanent.cardSources));
  2835. }
  2836. }
  2837. foreach (Permanent permanent in LoserPermanents)
  2838. {
  2839. if (permanent.TopCard != null)
  2840. {
  2841. _LoserPermanents.Add(new Permanent(permanent.cardSources));
  2842. }
  2843. }
  2844. hashtable.Add("WinnerPermanents", _WinnerPermanents);
  2845. hashtable.Add("WinnerPermanents_real", WinnerPermanents);
  2846. hashtable.Add("LoserPermanents", _LoserPermanents);
  2847. hashtable.Add("LoserPermanents_real", LoserPermanents);
  2848. hashtable.Add("LoserCard", LoserCard);
  2849. hashtable.Add("battle", this);
  2850. // battle effect
  2851. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
  2852. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(LoserPermanents, hashtable).Destroy());
  2853. //Fix winner/loser permanents
  2854. int index = -1;
  2855. foreach (Permanent permanent in LoserPermanents)
  2856. {
  2857. if(permanent.TopCard != null)
  2858. {
  2859. Debug.Log($"LoserPermanents: {LoserPermanents[0]}, {LoserPermanents[0].TopCard.name}");
  2860. index = LoserPermanents.IndexOf(permanent);
  2861. }
  2862. }
  2863. if(index >= 0)
  2864. {
  2865. LoserPermanents.RemoveAt(index);
  2866. _LoserPermanents.RemoveAt(index);
  2867. Debug.Log($"LoserPermanents: {LoserPermanents.Count}, {LoserPermanents.Count}");
  2868. hashtable["LoserPermanents"] = _LoserPermanents;
  2869. hashtable["LoserPermanents_real"] = LoserPermanents;
  2870. }
  2871. // "At the end of battle" effect
  2872. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
  2873. #region move up effect
  2874. if (ShowEffect())
  2875. {
  2876. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
  2877. }
  2878. #endregion
  2879. }
  2880. }
  2881. // auto process check
  2882. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2883. #region reset effect until the end of battle
  2884. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2885. {
  2886. foreach (Permanent permanent in player.GetFieldPermanents())
  2887. {
  2888. permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  2889. }
  2890. player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  2891. }
  2892. #endregion
  2893. if (AttackingPermanent != null)
  2894. {
  2895. AttackingPermanent.battle = null;
  2896. }
  2897. if (DefendingPermanent != null)
  2898. {
  2899. DefendingPermanent.battle = null;
  2900. }
  2901. }
  2902. }
  2903. #endregion
  2904. #region De-digivolve
  2905. public class IDegeneration
  2906. {
  2907. public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect)
  2908. {
  2909. _permanent = permanent;
  2910. _degenerationCount = DegenerationCount;
  2911. _cardEffect = cardEffect;
  2912. }
  2913. Permanent _permanent = null;
  2914. int _degenerationCount = 0;
  2915. ICardEffect _cardEffect = null;
  2916. public IEnumerator Degeneration()
  2917. {
  2918. if (_cardEffect == null) yield break;
  2919. if (_cardEffect.EffectSourceCard == null) yield break;
  2920. if (_permanent == null) yield break;
  2921. if (_permanent.TopCard == null) yield break;
  2922. if (_permanent.ImmuneFromDeDigivolve()) yield break;
  2923. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  2924. int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
  2925. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  2926. if (selectCountEffect != null)
  2927. {
  2928. Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
  2929. selectCountEffect.SetUp(
  2930. SelectPlayer: selectPlayer,
  2931. targetPermanent: _permanent,
  2932. MaxCount: maxCount,
  2933. CanNoSelect: false,
  2934. Message: "How many cards do you trash?",
  2935. Message_Enemy: "The opponent is choosing how many cards to trash.",
  2936. SelectCountCoroutine: SelectCountCoroutine);
  2937. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  2938. IEnumerator SelectCountCoroutine(int count)
  2939. {
  2940. _degenerationCount = count;
  2941. yield return null;
  2942. }
  2943. }
  2944. if (_degenerationCount >= 1)
  2945. {
  2946. int count = 0;
  2947. List<CardSource> selectedCards = new List<CardSource>();
  2948. while (true)
  2949. {
  2950. bool StopCondition()
  2951. {
  2952. if (_permanent.HasNoDigivolutionCards)
  2953. {
  2954. return true;
  2955. }
  2956. if (_permanent.Level == 3)
  2957. {
  2958. if (_permanent.TopCard != null)
  2959. {
  2960. if (_permanent.TopCard.HasLevel)
  2961. {
  2962. return true;
  2963. }
  2964. }
  2965. }
  2966. if (count >= _degenerationCount)
  2967. {
  2968. return true;
  2969. }
  2970. return false;
  2971. }
  2972. if (StopCondition())
  2973. {
  2974. break;
  2975. }
  2976. if (count == 0)
  2977. {
  2978. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  2979. }
  2980. CardSource cardSource = _permanent.TopCard;
  2981. selectedCards.Add(cardSource);
  2982. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  2983. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  2984. if (!cardSource.IsToken)
  2985. {
  2986. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  2987. }
  2988. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  2989. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  2990. count++;
  2991. }
  2992. #region add log
  2993. if (selectedCards.Count >= 1)
  2994. {
  2995. string log = "";
  2996. log += $"\nDe-Digivolve :";
  2997. foreach (CardSource cardSource in selectedCards)
  2998. {
  2999. if (cardSource != null)
  3000. {
  3001. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3002. }
  3003. }
  3004. log += "\n";
  3005. GManager.instance.playLog.AddLogString(log);
  3006. }
  3007. #endregion
  3008. }
  3009. }
  3010. }
  3011. #endregion
  3012. #region Trash digivolution cards
  3013. public class ITrashDigivolutionCards
  3014. {
  3015. public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  3016. {
  3017. _permanent = permanent;
  3018. _trashTargetCards = trashTargetCards.Clone();
  3019. _cardEffect = cardEffect;
  3020. }
  3021. Permanent _permanent = null;
  3022. List<CardSource> _trashTargetCards = new List<CardSource>();
  3023. ICardEffect _cardEffect = null;
  3024. public IEnumerator TrashDigivolutionCards()
  3025. {
  3026. if (_trashTargetCards == null) yield break;
  3027. if (_cardEffect == null) yield break;
  3028. if (_permanent == null) yield break;
  3029. if (_permanent.TopCard == null) yield break;
  3030. if (_permanent.HasNoDigivolutionCards) yield break;
  3031. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3032. _trashTargetCards = _trashTargetCards.Filter((cardSource) => _permanent.DigivolutionCards.Contains(cardSource) && !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
  3033. if (_trashTargetCards.Count == 0) yield break;
  3034. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  3035. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  3036. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3037. #region "When digivolution cards are trashed" effect
  3038. #region Hashtable Setting
  3039. Hashtable hashtable = new Hashtable()
  3040. {
  3041. {"CardEffect", _cardEffect},
  3042. {"Permanent", _permanent},
  3043. {"DiscardedCards", _trashTargetCards},
  3044. };
  3045. #endregion
  3046. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
  3047. #endregion
  3048. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  3049. foreach (CardSource cardSource in _trashTargetCards)
  3050. {
  3051. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3052. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3053. if (!cardSource.IsToken)
  3054. {
  3055. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3056. }
  3057. }
  3058. }
  3059. }
  3060. #endregion
  3061. #region Return digivolution cards to deck bottom
  3062. public class ReturnToLibraryBottomDigivolutionCardsClass
  3063. {
  3064. public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
  3065. {
  3066. _permanent = permanent;
  3067. _cardSources = cardSources.Clone();
  3068. _hashtable = hashtable;
  3069. }
  3070. Permanent _permanent = null;
  3071. List<CardSource> _cardSources = new List<CardSource>();
  3072. Hashtable _hashtable = null;
  3073. public IEnumerator ReturnToLibraryBottomDigivolutionCards()
  3074. {
  3075. if (_permanent == null) yield break;
  3076. if (_permanent.TopCard == null) yield break;
  3077. if (_cardSources == null) yield break;
  3078. _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
  3079. if (_cardSources.Count == 0) yield break;
  3080. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3081. if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
  3082. string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
  3083. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
  3084. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3085. #region "When digivolution cards are returned to deck" effect
  3086. #region Hashtable Setting
  3087. Hashtable hashtable1 = new Hashtable()
  3088. {
  3089. {"Permanent", _permanent},
  3090. {"DeckBottomCards", _cardSources},
  3091. {"CardEffect", CardEffect},
  3092. };
  3093. #endregion
  3094. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
  3095. #endregion
  3096. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
  3097. }
  3098. }
  3099. #endregion
  3100. #region Reduce security
  3101. public class IReduceSecurity
  3102. {
  3103. public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos)
  3104. {
  3105. _player = player;
  3106. _refSkillInfos = refSkillInfos;
  3107. }
  3108. Player _player = null;
  3109. List<SkillInfo> _refSkillInfos = null;
  3110. public IEnumerator ReduceSecurity()
  3111. {
  3112. #region "When cards are removed from security" effect
  3113. #region Hashtable Setting
  3114. Hashtable hashtable = new Hashtable()
  3115. {
  3116. {"Player", _player}
  3117. };
  3118. #endregion
  3119. if (_refSkillInfos == null)
  3120. {
  3121. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
  3122. }
  3123. else
  3124. {
  3125. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
  3126. {
  3127. _refSkillInfos.Add(skillInfo);
  3128. }
  3129. }
  3130. #endregion
  3131. }
  3132. }
  3133. #endregion
  3134. #region Add Security
  3135. public class IAddSecurity
  3136. {
  3137. public IAddSecurity(Player player)
  3138. {
  3139. _player = player;
  3140. }
  3141. Player _player { get; set; }
  3142. public IEnumerator AddSecurity()
  3143. {
  3144. #region "When security cards are added" effect
  3145. #region Hashtable setting
  3146. Hashtable hashtable = new Hashtable()
  3147. {
  3148. {"Player", _player}
  3149. };
  3150. #endregion
  3151. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
  3152. #endregion
  3153. }
  3154. }
  3155. #endregion
  3156. #region Suspend permanents
  3157. public class SuspendPermanentsClass
  3158. {
  3159. public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
  3160. {
  3161. _permanents = permanents;
  3162. _hashtable = hashtable;
  3163. }
  3164. List<Permanent> _permanents { get; set; }
  3165. Hashtable _hashtable { get; set; }
  3166. public IEnumerator Tap()
  3167. {
  3168. if (_permanents.Count == 0) yield break;
  3169. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3170. bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
  3171. bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
  3172. List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
  3173. bool PermanentCondition(Permanent permanent)
  3174. {
  3175. if (permanent != null)
  3176. {
  3177. if (permanent.TopCard != null)
  3178. {
  3179. if (permanent.IsSuspended)
  3180. {
  3181. return false;
  3182. }
  3183. if (!permanent.CanSuspend)
  3184. {
  3185. return false;
  3186. }
  3187. if (CardEffect != null)
  3188. {
  3189. if (permanent.TopCard.CanNotBeAffected(CardEffect))
  3190. {
  3191. return false;
  3192. }
  3193. }
  3194. }
  3195. }
  3196. return true;
  3197. }
  3198. foreach (Permanent permanent in suspendTargetPermanents)
  3199. {
  3200. permanent.IsSuspended = true;
  3201. permanent.DPWhenSuspended = permanent.DP;
  3202. if (permanent.ShowingPermanentCard != null)
  3203. {
  3204. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3205. }
  3206. }
  3207. if (suspendTargetPermanents.Count >= 1)
  3208. {
  3209. #region "Effects when permanents suspend
  3210. #region Hashtable Setting
  3211. Hashtable _hashtable = new Hashtable(){
  3212. {"Permanents", suspendTargetPermanents},
  3213. {"IsBlock", IsBlock}
  3214. };
  3215. if (CardEffect != null)
  3216. {
  3217. _hashtable.Add("CardEffect", CardEffect);
  3218. }
  3219. #endregion
  3220. if (IsAttack) yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3221. else yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3222. #endregion
  3223. yield return new WaitForSeconds(0.3f);
  3224. }
  3225. }
  3226. }
  3227. #endregion
  3228. #region Unsuspend permanents
  3229. public class IUnsuspendPermanents
  3230. {
  3231. public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
  3232. {
  3233. _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  3234. _cardEffect = cardEffect;
  3235. }
  3236. List<Permanent> _permanents { get; set; }
  3237. ICardEffect _cardEffect { get; set; }
  3238. public IEnumerator Unsuspend()
  3239. {
  3240. //Permanent list that will unsuspend
  3241. List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
  3242. permanent != null
  3243. && permanent.TopCard != null
  3244. && permanent.IsSuspended
  3245. && permanent.CanUnsuspend
  3246. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3247. #region "When permanents would unsuspend" effect
  3248. #region Hashtable Setting
  3249. Hashtable hashtable1 = new Hashtable()
  3250. {
  3251. {"CardEffect", _cardEffect},
  3252. {"Permanents", untappedPermanets},
  3253. };
  3254. #endregion
  3255. List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
  3256. if (skillInfos.Count >= 1)
  3257. {
  3258. foreach (SkillInfo skillInfo in skillInfos)
  3259. {
  3260. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  3261. }
  3262. foreach (Permanent permanent in untappedPermanets)
  3263. {
  3264. permanent.ShowUnsuspendEffect();
  3265. }
  3266. //cut in effects
  3267. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3268. untappedPermanets.ForEach(permanent =>
  3269. {
  3270. if (permanent.ShowingPermanentCard != null)
  3271. {
  3272. permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
  3273. }
  3274. });
  3275. }
  3276. #endregion
  3277. // fix unsuspend target permanents
  3278. List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
  3279. permanent != null
  3280. && permanent.TopCard != null
  3281. && permanent.IsSuspended
  3282. && permanent.CanUnsuspend
  3283. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3284. if (untappedPermanets_Fixed.Count >= 1)
  3285. {
  3286. foreach (Permanent permanent in untappedPermanets_Fixed)
  3287. {
  3288. permanent.IsSuspended = false;
  3289. if (permanent.ShowingPermanentCard != null)
  3290. {
  3291. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3292. }
  3293. }
  3294. #region "When permanents are unsuspended" effect
  3295. #region Hashtable Setting
  3296. Hashtable hashtable2 = new Hashtable()
  3297. {
  3298. {"CardEffect", _cardEffect},
  3299. {"Permanents", untappedPermanets_Fixed},
  3300. };
  3301. #endregion
  3302. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
  3303. #endregion
  3304. yield return new WaitForSeconds(0.3f);
  3305. }
  3306. foreach (Permanent permanent in untappedPermanets)
  3307. {
  3308. permanent.UntilNextUntapEffects = new List<Func<EffectTiming, ICardEffect>>();
  3309. }
  3310. }
  3311. }
  3312. #endregion
  3313. #region Trash cards from deck top
  3314. public class ITrashDeckCards
  3315. {
  3316. public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
  3317. {
  3318. this.cardSources = new List<CardSource>();
  3319. foreach (CardSource cardSource in cardSources)
  3320. {
  3321. this.cardSources.Add(cardSource);
  3322. }
  3323. this.cardEffect = cardEffect;
  3324. }
  3325. List<CardSource> cardSources { get; set; } = new List<CardSource>();
  3326. ICardEffect cardEffect { get; set; } = null;
  3327. public IEnumerator TrashDeckCards()
  3328. {
  3329. List<CardSource> trashCards = new List<CardSource>();
  3330. foreach (CardSource cardSource in cardSources)
  3331. {
  3332. if (cardSource.Owner.LibraryCards.Contains(cardSource))
  3333. {
  3334. trashCards.Add(cardSource);
  3335. }
  3336. }
  3337. if (trashCards.Count >= 1)
  3338. {
  3339. foreach (CardSource cardSource in trashCards)
  3340. {
  3341. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3342. }
  3343. #region "When cards are trashed from security" effect
  3344. #region Hashtable setting
  3345. Hashtable hashtable = new Hashtable()
  3346. {
  3347. {"DiscardedCards", trashCards},
  3348. {"CardEffect", cardEffect},
  3349. };
  3350. #endregion
  3351. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  3352. hashtable, EffectTiming.OnDiscardLibrary));
  3353. #endregion
  3354. }
  3355. }
  3356. }
  3357. #endregion
  3358. #region Overflow of ace
  3359. public class AceOverflowClass
  3360. {
  3361. public AceOverflowClass(List<CardSource> cardSources)
  3362. {
  3363. _cardSources = cardSources.Clone();
  3364. }
  3365. List<CardSource> _cardSources = new List<CardSource>();
  3366. public IEnumerator Overflow()
  3367. {
  3368. _cardSources = _cardSources
  3369. .Filter(cardSource => cardSource.IsACE && CardEffectCommons.IsExistOnBattleArea(cardSource))
  3370. .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
  3371. .ToList();
  3372. foreach (CardSource cardSource in _cardSources)
  3373. {
  3374. yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
  3375. string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
  3376. GManager.instance.playLog.AddLogString(log);
  3377. }
  3378. }
  3379. }
  3380. #endregion