CardController.cs 161 KB

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