CardController.cs 152 KB

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