CardController.cs 151 KB

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