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. }
  1012. }
  1013. if (played)
  1014. {
  1015. if (isFromSecurity)
  1016. {
  1017. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  1018. player: card.Owner,
  1019. refSkillInfos: ref ContinuousController.instance.nullSkillInfos).ReduceSecurity());
  1020. }
  1021. if (isEvolution)
  1022. {
  1023. card.Owner.DigivolveCount_ThisTurn++;
  1024. yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, null).Draw());
  1025. if (_burstDigivolved)
  1026. {
  1027. if (permanent.TopCard != null)
  1028. {
  1029. permanent.IsBurstDigivolved = true;
  1030. GManager.instance.selectBurstDigivolutionEffect.AddTrashTopCardAtTurnEnd(permanent);
  1031. }
  1032. }
  1033. permanent.CardNamesJustAfterDigivolved = permanent.TopCard.CardNames.Clone();
  1034. permanent.DigivolvingEffect = CardEffect;
  1035. }
  1036. else
  1037. {
  1038. permanent.PlayingEffect = CardEffect;
  1039. if (permanent.TopCard.HasLevel)
  1040. {
  1041. permanent.LevelJustAfterPlayed = permanent.Level;
  1042. }
  1043. if (permanent.TopCard.HasPlayCost)
  1044. {
  1045. permanent.PlayCostJustAfterPlayed = permanent.TopCard.GetCostItself;
  1046. }
  1047. permanent.CardNamesJustAfterPlayed = permanent.TopCard.CardNames.Clone();
  1048. permanent.TraitsJustAfterPlayed = permanent.TopCard.CardTraits.Clone();
  1049. }
  1050. #region move permanents (hybrid)
  1051. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  1052. {
  1053. if (permanent.TopCard.PreferredFrame() != null)
  1054. {
  1055. if (permanent.PermanentFrame != permanent.TopCard.PreferredFrame())
  1056. {
  1057. if (permanent.TopCard.PreferredFrame().IsEmptyFrame())
  1058. {
  1059. bool move = false;
  1060. if (permanent.IsDigimon)
  1061. {
  1062. if (permanent.TopCard.Owner.isYou)
  1063. {
  1064. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1065. {
  1066. move = true;
  1067. }
  1068. }
  1069. else
  1070. {
  1071. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1072. {
  1073. move = true;
  1074. }
  1075. }
  1076. }
  1077. else if (permanent.IsTamer || permanent.TopCard.IsOption)
  1078. {
  1079. if (permanent.TopCard.Owner.isYou)
  1080. {
  1081. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1082. {
  1083. move = true;
  1084. }
  1085. }
  1086. else
  1087. {
  1088. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1089. {
  1090. move = true;
  1091. }
  1092. }
  1093. }
  1094. if (move)
  1095. {
  1096. yield return ContinuousController.instance.StartCoroutine(CardObjectController.MovePermanent(permanent.PermanentFrame));
  1097. }
  1098. }
  1099. }
  1100. }
  1101. }
  1102. #endregion
  1103. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCardsByEffect(card);
  1104. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCards(card);
  1105. if (GManager.instance.turnStateMachine.DoneStartGame)
  1106. {
  1107. hashtableParams.Add(
  1108. new OnEnterFieldHashtableParams(
  1109. permanent: permanent,
  1110. evoRoots: evoRoots,
  1111. evoRootTops: evoRootTops,
  1112. root: _root,
  1113. oldLevels: oldLevels,
  1114. isFromDigimonDigivolutionCards: isFromDigimonDigivolutionCards
  1115. )
  1116. );
  1117. }
  1118. }
  1119. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  1120. yield return GManager.instance.photonWaitController.StartWait("EndPlayPermanent");
  1121. }
  1122. // except [On Play] effect
  1123. bool CardEffectCondition(ICardEffect cardEffect)
  1124. {
  1125. if (cardEffect == null)
  1126. {
  1127. return false;
  1128. }
  1129. if (!_activateETB)
  1130. {
  1131. if (cardEffect is ActivateICardEffect)
  1132. {
  1133. if (cardEffect.IsOnPlay)
  1134. {
  1135. return false;
  1136. }
  1137. }
  1138. }
  1139. return true;
  1140. }
  1141. Hashtable effectHashtable = CardEffectCommons.OnEnterFieldHashtable(
  1142. hashtableParams: hashtableParams,
  1143. isEvolution: isEvolution,
  1144. isJogress: isJogress,
  1145. digiXrosCount: _digiXrosCount,
  1146. cardEffect: CardEffect);
  1147. #region "When permanents are played" effect
  1148. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  1149. hashtable: effectHashtable,
  1150. timing: EffectTiming.OnEnterFieldAnyone,
  1151. cardEffectCondition: CardEffectCondition));
  1152. #endregion
  1153. }
  1154. }
  1155. #endregion
  1156. #region Use option
  1157. public class UseOptionClass
  1158. {
  1159. public UseOptionClass(List<CardSource> cardSources, Hashtable hashtable, SelectCardEffect.Root root)
  1160. {
  1161. if (cardSources != null)
  1162. {
  1163. _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  1164. }
  1165. _hashtable = hashtable;
  1166. _root = root;
  1167. }
  1168. List<CardSource> _cardSources = new List<CardSource>();
  1169. SelectCardEffect.Root _root = SelectCardEffect.Root.None;
  1170. Hashtable _hashtable = null;
  1171. public bool _showEffect = false;
  1172. public bool _addSecurityEndOption = false;
  1173. public IEnumerator UseOption()
  1174. {
  1175. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1176. foreach (CardSource card in _cardSources)
  1177. {
  1178. if (_showEffect)
  1179. {
  1180. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(card));
  1181. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowUseHandCardEffect_PlayCard(card));
  1182. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  1183. }
  1184. GManager.instance.playLog.AddLogString($"\nPlay Option:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1185. card.Init();
  1186. GManager.instance.turnStateMachine.isSync = true;
  1187. card.SetFace();
  1188. int cost = card.GetCostItself;
  1189. //Remove from all areas
  1190. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1191. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(card));
  1192. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.BrainStormCoroutine(card));
  1193. #region Set HashTable
  1194. Hashtable hashtable = new Hashtable()
  1195. {
  1196. {"Card", card},
  1197. {"Root", _root},
  1198. {"Cost", cost},
  1199. };
  1200. #endregion
  1201. #region "When option is used" effect
  1202. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseOption));
  1203. yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.OnUseOption));
  1204. #endregion
  1205. #region effect process of option card
  1206. foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.OptionSkill))
  1207. {
  1208. if (cardEffect is ActivateICardEffect)
  1209. {
  1210. if (cardEffect.CanUse(hashtable))
  1211. {
  1212. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  1213. cardEffect,
  1214. hashtable));
  1215. }
  1216. }
  1217. }
  1218. #endregion
  1219. if (card.Owner.ExecutingCards.Contains(card))
  1220. {
  1221. if (_addSecurityEndOption && card.Owner.CanAddSecurity(CardEffect))
  1222. {
  1223. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(card));
  1224. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(card.Owner));
  1225. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(card.Owner).AddSecurity());
  1226. }
  1227. else
  1228. {
  1229. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(card));
  1230. }
  1231. }
  1232. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  1233. yield return GManager.instance.photonWaitController.StartWait("EndPlayOption");
  1234. }
  1235. }
  1236. }
  1237. #endregion
  1238. #region Draw cards
  1239. public class DrawClass
  1240. {
  1241. public DrawClass(Player player, int drawCount, ICardEffect cardEffect)
  1242. {
  1243. _player = player;
  1244. _drawCount = drawCount;
  1245. _cardEffect = cardEffect;
  1246. }
  1247. Player _player = null;
  1248. int _drawCount = 0;
  1249. ICardEffect _cardEffect = null;
  1250. public IEnumerator Draw()
  1251. {
  1252. if (_drawCount <= 0) yield break;
  1253. if (_player.LibraryCards.Count <= 0) yield break;
  1254. List<CardSource> DrawCards = new List<CardSource>();
  1255. for (int i = 0; i < _drawCount; i++)
  1256. {
  1257. if (_player.LibraryCards.Count > 0)
  1258. {
  1259. CardSource DrawCard = _player.LibraryCards[0];
  1260. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(DrawCard));
  1261. DrawCards.Add(DrawCard);
  1262. }
  1263. }
  1264. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(DrawCards, true, _cardEffect));
  1265. #region add log
  1266. if (DrawCards.Count >= 1)
  1267. {
  1268. GManager.instance.playLog.AddLogString($"\nDraw {DrawCards.Count} card{Utils.PluralFormSuffix(DrawCards.Count)}\n{_player.PlayerName}\n");
  1269. }
  1270. #endregion
  1271. #region "When draw cards" effect
  1272. if (DrawCards.Count >= 1)
  1273. {
  1274. #region Hashtable setting
  1275. Hashtable _hashtable = new Hashtable()
  1276. {
  1277. {"Player", _player},
  1278. {"CardEffect", _cardEffect}
  1279. };
  1280. #endregion
  1281. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnDraw));
  1282. }
  1283. #endregion
  1284. }
  1285. }
  1286. #endregion
  1287. #region Trash cards from deck too
  1288. public class IAddTrashCardsFromLibraryTop
  1289. {
  1290. public IAddTrashCardsFromLibraryTop(int addTrashCount, Player player, ICardEffect cardEffect)
  1291. {
  1292. _addTrashCount = addTrashCount;
  1293. _player = player;
  1294. _cardEffect = cardEffect;
  1295. }
  1296. public void SetNotShowCards()
  1297. {
  1298. _notShowCards = true;
  1299. }
  1300. int _addTrashCount;
  1301. Player _player;
  1302. public List<CardSource> discardedCards = new List<CardSource>();
  1303. ICardEffect _cardEffect { get; set; } = null;
  1304. bool _notShowCards = false;
  1305. public IEnumerator AddTrashCardsFromLibraryTop()
  1306. {
  1307. if (_addTrashCount <= 0) yield break;
  1308. if (_player.LibraryCards.Count == 0) yield break;
  1309. string log = "";
  1310. log += $"\nTrash cards from deck :";
  1311. for (int i = 0; i < _addTrashCount; i++)
  1312. {
  1313. if (_player.LibraryCards.Count > i)
  1314. {
  1315. CardSource DiscardCard = _player.LibraryCards[i];
  1316. discardedCards.Add(DiscardCard);
  1317. log += $"\n{DiscardCard.BaseENGCardNameFromEntity}({DiscardCard.CardID})";
  1318. }
  1319. }
  1320. if (discardedCards.Count >= 1)
  1321. {
  1322. if (!_notShowCards)
  1323. {
  1324. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  1325. }
  1326. }
  1327. yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(discardedCards, _cardEffect).TrashDeckCards());
  1328. if (discardedCards.Count >= 1)
  1329. {
  1330. for (int i = 0; i < discardedCards.Count; i++)
  1331. {
  1332. ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
  1333. yield return new WaitForSeconds(0.06f);
  1334. }
  1335. log += "\n";
  1336. GManager.instance.playLog.AddLogString(log);
  1337. }
  1338. }
  1339. }
  1340. #endregion
  1341. #region Add security from deck top
  1342. public class IAddSecurityFromLibrary
  1343. {
  1344. public IAddSecurityFromLibrary(Player player, int addLifeCount)
  1345. {
  1346. _player = player;
  1347. _addSecurityCount = addLifeCount;
  1348. }
  1349. Player _player = null;
  1350. int _addSecurityCount = 0;
  1351. public IEnumerator AddSecurity()
  1352. {
  1353. int count = 0;
  1354. for (int i = 0; i < _addSecurityCount; i++)
  1355. {
  1356. if (_player.LibraryCards.Count > 0)
  1357. {
  1358. CardSource StockCard = _player.LibraryCards[0];
  1359. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(StockCard));
  1360. count++;
  1361. }
  1362. }
  1363. if (count > 0)
  1364. {
  1365. string log = "";
  1366. log += $"\nAdd {count} cards to security:{_player.PlayerName}";
  1367. log += "\n";
  1368. GManager.instance.playLog.AddLogString(log);
  1369. if (GManager.instance.turnStateMachine.DoneStartGame)
  1370. {
  1371. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(_player).AddSecurity());
  1372. }
  1373. }
  1374. }
  1375. }
  1376. #endregion
  1377. #region Recovery
  1378. public class IRecovery
  1379. {
  1380. public IRecovery(Player player, int AddLifeCount, ICardEffect cardEffect)
  1381. {
  1382. _player = player;
  1383. _addLifeCount = AddLifeCount;
  1384. _cardEffect = cardEffect;
  1385. }
  1386. Player _player = null;
  1387. int _addLifeCount = 0;
  1388. ICardEffect _cardEffect = null;
  1389. public IEnumerator Recovery()
  1390. {
  1391. if (_player.LibraryCards.Count == 0) yield break;
  1392. if (_addLifeCount <= 0) yield break;
  1393. if (!_player.CanAddSecurity(_cardEffect)) yield break;
  1394. yield return ContinuousController.instance.StartCoroutine(new IAddSecurityFromLibrary(_player, _addLifeCount).AddSecurity());
  1395. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(_player));
  1396. }
  1397. }
  1398. #endregion
  1399. #region Digi-Burst
  1400. public class IDigiBurst
  1401. {
  1402. public IDigiBurst(Permanent permanent, int DigiBurstCount, ICardEffect cardEffect)
  1403. {
  1404. _permanent = permanent;
  1405. _digiBurstCount = DigiBurstCount;
  1406. _cardEffect = cardEffect;
  1407. }
  1408. Permanent _permanent = null;
  1409. int _digiBurstCount = 0;
  1410. ICardEffect _cardEffect = null;
  1411. bool _upToMaxCount = false;
  1412. public List<CardSource> discardedCards = new List<CardSource>();
  1413. public void SetUpToMaxCount()
  1414. {
  1415. _upToMaxCount = true;
  1416. }
  1417. public bool CanDigiBurst()
  1418. {
  1419. if (_permanent != null)
  1420. {
  1421. if (_permanent.TopCard != null)
  1422. {
  1423. if (_upToMaxCount)
  1424. {
  1425. if (_permanent.DigivolutionCards.Some((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)))
  1426. {
  1427. return true;
  1428. }
  1429. }
  1430. else
  1431. {
  1432. if (_permanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)) >= _digiBurstCount)
  1433. {
  1434. return true;
  1435. }
  1436. }
  1437. }
  1438. }
  1439. return false;
  1440. }
  1441. public IEnumerator DigiBurst()
  1442. {
  1443. if (CanDigiBurst())
  1444. {
  1445. discardedCards = new List<CardSource>();
  1446. List<CardSource> selectedCards = new List<CardSource>();
  1447. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  1448. selectCardEffect.SetUp(
  1449. canTargetCondition: (cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect),
  1450. canTargetCondition_ByPreSelecetedList: null,
  1451. canEndSelectCondition: CanEndSelectCondition,
  1452. canNoSelect: () => false,
  1453. selectCardCoroutine: SelectCardCoroutine,
  1454. afterSelectCardCoroutine: null,
  1455. message: "Select digivolution cards to discard.",
  1456. maxCount: _digiBurstCount,
  1457. canEndNotMax: _upToMaxCount,
  1458. isShowOpponent: true,
  1459. mode: SelectCardEffect.Mode.Custom,
  1460. root: SelectCardEffect.Root.Custom,
  1461. customRootCardList: _permanent.DigivolutionCards,
  1462. canLookReverseCard: true,
  1463. selectPlayer: _permanent.TopCard.Owner,
  1464. cardEffect: null);
  1465. selectCardEffect.SetUpCustomMessage("Select digivolution cards to discard.", "The opponent is selecting digivolution cards to discard.");
  1466. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  1467. bool CanEndSelectCondition(List<CardSource> cardSources)
  1468. {
  1469. if (CardEffectCommons.HasNoElement(cardSources))
  1470. {
  1471. return false;
  1472. }
  1473. return true;
  1474. }
  1475. IEnumerator SelectCardCoroutine(CardSource cardSource)
  1476. {
  1477. selectedCards.Add(cardSource);
  1478. yield return null;
  1479. }
  1480. if (selectedCards.Count >= 1)
  1481. {
  1482. #region "When use Digi-Burst" effect
  1483. #region Hashtable setting
  1484. Hashtable hashtable = new Hashtable()
  1485. {
  1486. {"Permanent", _permanent},
  1487. {"CardEffect", _cardEffect},
  1488. };
  1489. #endregion
  1490. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseDigiburst));
  1491. #endregion
  1492. // trash digivolution cards
  1493. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(_permanent, selectedCards, _cardEffect).TrashDigivolutionCards());
  1494. foreach (CardSource cardSource in selectedCards)
  1495. {
  1496. discardedCards.Add(cardSource);
  1497. }
  1498. #region add log
  1499. if (selectedCards.Count >= 1)
  1500. {
  1501. string log = "";
  1502. log += $"\nDigiburst :";
  1503. foreach (CardSource cardSource in selectedCards)
  1504. {
  1505. if (cardSource != null)
  1506. {
  1507. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  1508. }
  1509. }
  1510. log += "\n";
  1511. GManager.instance.playLog.AddLogString(log);
  1512. }
  1513. #endregion
  1514. }
  1515. }
  1516. }
  1517. }
  1518. #endregion
  1519. #region Place permanents to deck bottom
  1520. public class DeckBottomBounceClass
  1521. {
  1522. public DeckBottomBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
  1523. {
  1524. _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
  1525. _hashtable = hashtable;
  1526. }
  1527. public void SetNotShowCards()
  1528. {
  1529. _notShowCards = true;
  1530. }
  1531. public bool IsDeckBounced(Permanent permanent)
  1532. {
  1533. return DeckBouncedPermanents.Contains(permanent);
  1534. }
  1535. List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
  1536. public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
  1537. Hashtable _hashtable = new Hashtable();
  1538. bool _notShowCards = false;
  1539. public IEnumerator DeckBounce()
  1540. {
  1541. if (_deckBounceTargetPermanents == null) yield break;
  1542. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1543. _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
  1544. permanent != null
  1545. && permanent.TopCard != null
  1546. && (cardEffect == null ||
  1547. (!permanent.TopCard.CanNotBeAffected(cardEffect) && !permanent.CannotReturnToLibrary(cardEffect))));
  1548. if (_deckBounceTargetPermanents.Count == 0) yield break;
  1549. _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1550. #region cut in effect
  1551. // "When permanents would return to deck" effect
  1552. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1553. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1554. _deckBounceTargetPermanents,
  1555. cardEffect,
  1556. null
  1557. ),
  1558. EffectTiming.WhenReturntoLibraryAnyone));
  1559. // "When permanents would remove field" effect
  1560. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1561. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1562. _deckBounceTargetPermanents,
  1563. cardEffect,
  1564. null
  1565. ),
  1566. EffectTiming.WhenRemoveField));
  1567. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1568. {
  1569. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1570. {
  1571. permanent.ShowDeckBounceEffect();
  1572. }
  1573. // cut in effect process
  1574. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  1575. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1576. {
  1577. permanent.HideDeckBounceEffect();
  1578. }
  1579. }
  1580. #endregion
  1581. // fix deck bounce target permanents
  1582. List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
  1583. permanent != null
  1584. && permanent.TopCard != null
  1585. && permanent.willBeRemoveField);
  1586. #region show cards
  1587. List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1588. if (!_notShowCards)
  1589. {
  1590. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
  1591. }
  1592. #endregion
  1593. #region
  1594. List<CardSource> deckBottomCards = new List<CardSource>();
  1595. foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
  1596. {
  1597. #region recoed used effect
  1598. if (permanent.TopCard != null)
  1599. {
  1600. permanent.LibraryBounceEffect = cardEffect;
  1601. }
  1602. #endregion
  1603. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
  1604. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1605. CardSource topCard = permanent.TopCard;
  1606. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1607. deckBottomCards.Add(topCard);
  1608. DeckBouncedPermanents.Add(permanent);
  1609. }
  1610. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(deckBottomCards));
  1611. #endregion
  1612. #region off icon
  1613. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1614. {
  1615. if (permanent != null)
  1616. {
  1617. if (permanent.TopCard != null)
  1618. {
  1619. permanent.willBeRemoveField = false;
  1620. }
  1621. }
  1622. }
  1623. #endregion
  1624. }
  1625. }
  1626. #endregion
  1627. #region Return permanent to hand
  1628. public class HandBounceClaass
  1629. {
  1630. public HandBounceClaass(List<Permanent> bounceTargetPermanents, Hashtable hashtable)
  1631. {
  1632. _bounceTargetPermanents = bounceTargetPermanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  1633. _hashtable = hashtable;
  1634. }
  1635. public bool IsBounced(Permanent permanent)
  1636. {
  1637. return BouncedPermanents.Contains(permanent);
  1638. }
  1639. List<Permanent> _bounceTargetPermanents = new List<Permanent>();
  1640. public List<Permanent> BouncedPermanents { get; private set; } = new List<Permanent>();
  1641. Hashtable _hashtable = new Hashtable();
  1642. bool _notShowCards = false;
  1643. public IEnumerator Bounce()
  1644. {
  1645. if (_bounceTargetPermanents == null) yield break;
  1646. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1647. _bounceTargetPermanents = _bounceTargetPermanents.Filter(permanent =>
  1648. permanent != null
  1649. && permanent.TopCard != null
  1650. && (cardEffect == null ||
  1651. (!permanent.TopCard.CanNotBeAffected(cardEffect) && !permanent.CannotReturnToHand(cardEffect))));
  1652. if (_bounceTargetPermanents.Count == 0) yield break;
  1653. _bounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1654. #region cut in effect
  1655. // "When permanents would return to hand" effect
  1656. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1657. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1658. _bounceTargetPermanents,
  1659. cardEffect,
  1660. null
  1661. ),
  1662. EffectTiming.WhenReturntoHandAnyone));
  1663. // "When permanents would remove field" effect
  1664. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1665. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1666. _bounceTargetPermanents,
  1667. cardEffect,
  1668. null
  1669. ),
  1670. EffectTiming.WhenRemoveField));
  1671. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1672. {
  1673. foreach (Permanent permanent in _bounceTargetPermanents)
  1674. {
  1675. permanent.ShowHandBounceEffect();
  1676. }
  1677. // shrink security Digimon display
  1678. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  1679. // cut in effect process
  1680. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  1681. foreach (Permanent permanent in _bounceTargetPermanents)
  1682. {
  1683. permanent.HideHandBounceEffect();
  1684. }
  1685. }
  1686. #endregion
  1687. // fix bounce target permanents
  1688. List<Permanent> bounceTargetPermanents_Fixed = _bounceTargetPermanents.Filter(permanent =>
  1689. permanent != null
  1690. && permanent.TopCard != null
  1691. && permanent.willBeRemoveField);
  1692. #region "When permanents returned to hand" effect
  1693. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  1694. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  1695. bounceTargetPermanents_Fixed,
  1696. cardEffect,
  1697. null,
  1698. false
  1699. ),
  1700. EffectTiming.OnPermamemtReturnedToHand));
  1701. #endregion
  1702. #region record parameter just before bounce
  1703. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1704. {
  1705. permanent.DPJustBeforeRemoveField = permanent.DP;
  1706. if (permanent.TopCard.HasLevel)
  1707. {
  1708. permanent.LevelJustBeforeRemoveField = permanent.Level;
  1709. }
  1710. if (permanent.TopCard.HasPlayCost)
  1711. {
  1712. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  1713. }
  1714. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  1715. foreach (CardSource cardSource in permanent.cardSources)
  1716. {
  1717. cardSource.PermanentJustBeforeRemoveField = permanent;
  1718. }
  1719. }
  1720. #endregion
  1721. #region add log
  1722. if (bounceTargetPermanents_Fixed.Count >= 1)
  1723. {
  1724. string log = "";
  1725. log += $"\nReturn to hand:";
  1726. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1727. {
  1728. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  1729. }
  1730. log += "\n";
  1731. GManager.instance.playLog.AddLogString(log);
  1732. }
  1733. #endregion
  1734. #region show cards
  1735. List<CardSource> returnedCards = bounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1736. if (!_notShowCards)
  1737. {
  1738. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Cards returned to hand", true, true));
  1739. }
  1740. #endregion
  1741. #region return permanent cards to hand
  1742. List<CardSource> handCards = new List<CardSource>();
  1743. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  1744. {
  1745. #region record used effect
  1746. if (permanent.TopCard != null)
  1747. {
  1748. permanent.HandBounceEffect = cardEffect;
  1749. }
  1750. #endregion
  1751. // record whether to return to hand by Burst Digivolution
  1752. permanent.IsReturnedToHandByBurstDigivolution = CardEffectCommons.IsBurst(_hashtable);
  1753. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BounceEffect(permanent, !permanent.IsReturnedToHandByBurstDigivolution));
  1754. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1755. CardSource topCard = permanent.TopCard;
  1756. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1757. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(topCard));
  1758. if (!topCard.IsDigiEgg)
  1759. {
  1760. handCards.Add(topCard);
  1761. BouncedPermanents.Add(permanent);
  1762. }
  1763. else
  1764. {
  1765. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  1766. }
  1767. }
  1768. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
  1769. #endregion
  1770. #region hide icon
  1771. foreach (Permanent permanent in _bounceTargetPermanents)
  1772. {
  1773. if (permanent != null)
  1774. {
  1775. if (permanent.TopCard != null)
  1776. {
  1777. permanent.willBeRemoveField = false;
  1778. }
  1779. }
  1780. }
  1781. #endregion
  1782. }
  1783. }
  1784. #endregion
  1785. #region Place permanent to another permanent's digivolution cards
  1786. public class IPlacePermanentToDigivolutionCards
  1787. {
  1788. public IPlacePermanentToDigivolutionCards(
  1789. List<Permanent[]> permanentArrays,
  1790. bool toTop,
  1791. ICardEffect cardEffect,
  1792. bool skipEffectAndActivateSkill = false)
  1793. {
  1794. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  1795. _toTop = toTop;
  1796. _cardEffect = cardEffect;
  1797. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  1798. }
  1799. public void SetNotShowCards()
  1800. {
  1801. _notShowCards = true;
  1802. }
  1803. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  1804. ICardEffect _cardEffect = null;
  1805. bool _toTop = false;
  1806. bool _notShowCards = false;
  1807. bool _skipEffectAndActivateSkill = false;
  1808. public bool Placed { get; private set; } = false;
  1809. public IEnumerator PlacePermanentToDigivolutionCards()
  1810. {
  1811. if (_permanentArrays.Count == 0)
  1812. {
  1813. yield break;
  1814. }
  1815. List<CardSource> addedDigivolutionCards = new List<CardSource>();
  1816. List<Permanent> removeFieldPermanents = new List<Permanent>();
  1817. foreach (Permanent[] permanentArray in _permanentArrays)
  1818. {
  1819. if (permanentArray.Length == 2)
  1820. {
  1821. Permanent DigivolutionPermanent = permanentArray[0];
  1822. Permanent getDigivolutionPermanent = permanentArray[1];
  1823. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  1824. {
  1825. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
  1826. {
  1827. if (_cardEffect != null)
  1828. {
  1829. if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
  1830. {
  1831. continue;
  1832. }
  1833. }
  1834. removeFieldPermanents.Add(DigivolutionPermanent);
  1835. }
  1836. }
  1837. }
  1838. }
  1839. foreach (Permanent permanent in removeFieldPermanents)
  1840. {
  1841. permanent.willBeRemoveField = true;
  1842. }
  1843. if (removeFieldPermanents.Count == 0)
  1844. {
  1845. yield break;
  1846. }
  1847. #region
  1848. List<SkillInfo> skillInfos = new List<SkillInfo>();
  1849. Hashtable hashtable1 =
  1850. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1851. removeFieldPermanents,
  1852. _cardEffect,
  1853. null);
  1854. #region "When permanents would remove field" effect
  1855. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1856. {
  1857. #region permanents' effects
  1858. foreach (Permanent permanent1 in player.GetFieldPermanents())
  1859. {
  1860. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  1861. {
  1862. if (cardEffect is ActivateICardEffect)
  1863. {
  1864. if (cardEffect.CanTrigger(hashtable1))
  1865. {
  1866. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1867. }
  1868. }
  1869. }
  1870. }
  1871. #endregion
  1872. #region players' effects
  1873. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  1874. {
  1875. if (cardEffect is ActivateICardEffect)
  1876. {
  1877. if (cardEffect.CanTrigger(hashtable1))
  1878. {
  1879. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  1880. }
  1881. }
  1882. }
  1883. #endregion
  1884. }
  1885. #endregion
  1886. if (skillInfos.Count >= 1)
  1887. {
  1888. foreach (SkillInfo skillInfo in skillInfos)
  1889. {
  1890. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  1891. }
  1892. bool showEffect()
  1893. {
  1894. if (skillInfos.Count >= 2)
  1895. {
  1896. return true;
  1897. }
  1898. else if (skillInfos.Count == 1)
  1899. {
  1900. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  1901. {
  1902. return true;
  1903. }
  1904. }
  1905. return false;
  1906. }
  1907. if (showEffect())
  1908. {
  1909. foreach (Permanent Permanent in removeFieldPermanents)
  1910. {
  1911. if (Permanent != null)
  1912. {
  1913. if (Permanent.TopCard != null)
  1914. {
  1915. if (Permanent.willBeRemoveField)
  1916. {
  1917. if (Permanent.ShowingPermanentCard != null)
  1918. {
  1919. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  1920. {
  1921. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  1922. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  1923. }
  1924. }
  1925. }
  1926. }
  1927. }
  1928. }
  1929. #region shrink security Digimon display
  1930. if (GManager.instance.attackProcess.IsAttacking)
  1931. {
  1932. if (GManager.instance.attackProcess.SecurityDigimon != null)
  1933. {
  1934. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  1935. {
  1936. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  1937. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  1938. }
  1939. }
  1940. }
  1941. #endregion
  1942. }
  1943. // cut in effect process
  1944. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  1945. foreach (Permanent Permanent in removeFieldPermanents)
  1946. {
  1947. if (Permanent != null)
  1948. {
  1949. if (Permanent.TopCard != null)
  1950. {
  1951. if (Permanent.ShowingPermanentCard != null)
  1952. {
  1953. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  1954. {
  1955. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  1956. }
  1957. }
  1958. }
  1959. }
  1960. }
  1961. }
  1962. #endregion
  1963. foreach (Permanent[] permanentArray in _permanentArrays)
  1964. {
  1965. if (permanentArray.Length == 2)
  1966. {
  1967. Permanent DigivolutionPermanent = permanentArray[0];
  1968. Permanent getDigivolutionPermanent = permanentArray[1];
  1969. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  1970. {
  1971. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
  1972. {
  1973. yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
  1974. CardSource cardSource = DigivolutionPermanent.TopCard;
  1975. #region record used effect
  1976. if (_cardEffect != null)
  1977. {
  1978. if (DigivolutionPermanent.TopCard != null)
  1979. {
  1980. DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
  1981. }
  1982. }
  1983. #endregion
  1984. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  1985. DigivolutionPermanent,
  1986. ignoreOverflow: true));
  1987. List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
  1988. if (_toTop)
  1989. {
  1990. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
  1991. }
  1992. else
  1993. {
  1994. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
  1995. }
  1996. addedDigivolutionCards.Add(cardSource);
  1997. Placed = true;
  1998. }
  1999. }
  2000. }
  2001. }
  2002. #region add log
  2003. if (addedDigivolutionCards.Count >= 1)
  2004. {
  2005. string log = "";
  2006. log += $"\nPlace in digivolution cards:";
  2007. foreach (CardSource cardSource in addedDigivolutionCards)
  2008. {
  2009. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2010. }
  2011. log += "\n";
  2012. GManager.instance.playLog.AddLogString(log);
  2013. }
  2014. #endregion
  2015. #region hide icon
  2016. if (addedDigivolutionCards.Count >= 1)
  2017. {
  2018. if (!_notShowCards)
  2019. {
  2020. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
  2021. }
  2022. }
  2023. #endregion
  2024. }
  2025. }
  2026. #endregion
  2027. #region Place permanents to security
  2028. public class IPutSecurityPermanent
  2029. {
  2030. public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop)
  2031. {
  2032. _permanent = permanent;
  2033. _hashtable = hashtable;
  2034. _toTop = toTop;
  2035. }
  2036. Permanent _permanent = null;
  2037. Hashtable _hashtable = new Hashtable();
  2038. bool _toTop = false;
  2039. public IEnumerator PutSecurity()
  2040. {
  2041. Debug.Log("PutSecurity");
  2042. if (_permanent == null) yield break;
  2043. if (_permanent.TopCard == null) yield break;
  2044. Debug.Log("PutSecurity 1");
  2045. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2046. if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
  2047. Debug.Log("PutSecurity 2");
  2048. #region "When permanents would remove field" effect
  2049. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2050. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2051. new List<Permanent>() { _permanent },
  2052. cardEffect,
  2053. null
  2054. ),
  2055. EffectTiming.WhenRemoveField));
  2056. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2057. {
  2058. _permanent.ShowWillRemoveFieldEffect();
  2059. //effect
  2060. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2061. // cut in effect process
  2062. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  2063. _permanent.HideWillRemoveFieldEffect();
  2064. }
  2065. #endregion
  2066. Debug.Log("PutSecurity 3");
  2067. CardSource topCard = _permanent.TopCard;
  2068. if (topCard == null) yield break;
  2069. Debug.Log("PutSecurity 4");
  2070. #region add log
  2071. string log = "";
  2072. log += $"\nPut cards on top of security:";
  2073. log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
  2074. log += "\n";
  2075. GManager.instance.playLog.AddLogString(log);
  2076. #endregion
  2077. #region show cards
  2078. if (!topCard.IsToken)
  2079. {
  2080. if (_toTop)
  2081. {
  2082. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
  2083. }
  2084. else
  2085. {
  2086. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
  2087. }
  2088. }
  2089. #endregion
  2090. Debug.Log("PutSecurity 5");
  2091. #region place permanent to security
  2092. yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
  2093. Debug.Log("PutSecurity 6");
  2094. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
  2095. Debug.Log("PutSecurity 7");
  2096. if (!topCard.IsToken)
  2097. {
  2098. Debug.Log("PutSecurity 8");
  2099. if (!topCard.IsDigiEgg)
  2100. {
  2101. Debug.Log("PutSecurity 9");
  2102. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard));
  2103. Debug.Log("PutSecurity 10");
  2104. if (!_toTop)
  2105. {
  2106. topCard.Owner.SecurityCards.Remove(topCard);
  2107. topCard.Owner.SecurityCards.Add(topCard);
  2108. }
  2109. Debug.Log("PutSecurity 11");
  2110. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
  2111. Debug.Log("PutSecurity 12");
  2112. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard.Owner).AddSecurity());
  2113. }
  2114. else
  2115. {
  2116. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2117. }
  2118. }
  2119. Debug.Log("PutSecurity 13");
  2120. #endregion
  2121. }
  2122. }
  2123. #endregion
  2124. #region Delete permanents
  2125. public class DestroyPermanentsClass
  2126. {
  2127. public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
  2128. {
  2129. _destroytargetPermanents = destroyTargetPermanents.Clone();
  2130. _hashtable = hashtable;
  2131. _notShowCards = notShowCards;
  2132. }
  2133. public bool IsDestroyed(Permanent permanent)
  2134. {
  2135. return DestroyedPermanents.Contains(permanent);
  2136. }
  2137. List<Permanent> _destroytargetPermanents = new List<Permanent>();
  2138. public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
  2139. Hashtable _hashtable = null;
  2140. bool _notShowCards = false;
  2141. public IEnumerator Destroy()
  2142. {
  2143. if (_destroytargetPermanents == null) yield break;
  2144. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2145. IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
  2146. bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
  2147. _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
  2148. permanent != null
  2149. && permanent.TopCard != null
  2150. && (cardEffect == null ||
  2151. (!permanent.TopCard.CanNotBeAffected(cardEffect) && permanent.CanBeDestroyedBySkill(cardEffect))));
  2152. if (_destroytargetPermanents.Count == 0) yield break;
  2153. _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  2154. #region cut in effect
  2155. // "When permanents would be deleted" effect
  2156. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2157. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2158. _destroytargetPermanents,
  2159. cardEffect,
  2160. battle
  2161. ),
  2162. EffectTiming.WhenPermanentWouldBeDeleted));
  2163. // "When permanents would remove field" effect
  2164. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2165. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2166. _destroytargetPermanents,
  2167. cardEffect,
  2168. battle
  2169. ),
  2170. EffectTiming.WhenRemoveField));
  2171. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2172. {
  2173. foreach (Permanent permanent in _destroytargetPermanents)
  2174. {
  2175. permanent.ShowDeleteEffect();
  2176. }
  2177. // effect
  2178. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2179. // cut in effect process
  2180. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  2181. foreach (Permanent permanent in _destroytargetPermanents)
  2182. {
  2183. permanent.HideDeleteEffect();
  2184. }
  2185. }
  2186. #endregion
  2187. // fix delete target permanents
  2188. List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
  2189. permanent != null
  2190. && permanent.TopCard != null
  2191. && permanent.willBeRemoveField);
  2192. #region "When permanents are deleted" effect
  2193. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2194. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2195. destroyTargetPermanents_Fixed,
  2196. cardEffect,
  2197. battle,
  2198. isDPZero
  2199. ),
  2200. EffectTiming.OnDestroyedAnyone));
  2201. #endregion
  2202. #region record parameters just before deletion
  2203. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2204. {
  2205. permanent.DPJustBeforeRemoveField = permanent.DP;
  2206. if (permanent.TopCard.HasLevel)
  2207. {
  2208. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2209. }
  2210. if (permanent.TopCard.HasPlayCost)
  2211. {
  2212. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  2213. }
  2214. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  2215. foreach (CardSource cardSource in permanent.cardSources)
  2216. {
  2217. cardSource.PermanentJustBeforeRemoveField = permanent;
  2218. }
  2219. }
  2220. #endregion
  2221. #region add log
  2222. if (destroyTargetPermanents_Fixed.Count >= 1)
  2223. {
  2224. string log = "";
  2225. log += $"\nDelete:";
  2226. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2227. {
  2228. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  2229. }
  2230. log += "\n";
  2231. GManager.instance.playLog.AddLogString(log);
  2232. }
  2233. #endregion
  2234. #region show cards
  2235. List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2236. if (!_notShowCards)
  2237. {
  2238. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
  2239. }
  2240. #endregion
  2241. #region trash permanent cards
  2242. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2243. {
  2244. #region record wheter to be deleted by battle
  2245. if (battle != null)
  2246. {
  2247. if (permanent.TopCard != null)
  2248. {
  2249. permanent.IsDestroyedByBattle = true;
  2250. }
  2251. }
  2252. #endregion
  2253. #region record used effect
  2254. if (permanent.TopCard != null)
  2255. {
  2256. permanent.DestroyingEffect = cardEffect;
  2257. }
  2258. #endregion
  2259. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
  2260. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2261. CardSource topCard = permanent.TopCard;
  2262. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2263. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
  2264. DestroyedPermanents.Add(permanent);
  2265. }
  2266. #endregion
  2267. #region hide icon
  2268. foreach (Permanent permanent in _destroytargetPermanents)
  2269. {
  2270. if (permanent != null)
  2271. {
  2272. if (permanent.TopCard != null)
  2273. {
  2274. permanent.willBeRemoveField = false;
  2275. }
  2276. }
  2277. }
  2278. #endregion
  2279. }
  2280. }
  2281. #endregion
  2282. #region Security check
  2283. public class ISecurityCheck
  2284. {
  2285. public ISecurityCheck(Permanent AttackingPermanent, Player player)
  2286. {
  2287. this.AttackingPermanent = AttackingPermanent;
  2288. this.player = player;
  2289. }
  2290. Permanent AttackingPermanent { get; set; }
  2291. Player player { get; set; }
  2292. public IEnumerator SecurityCheck()
  2293. {
  2294. bool StopSecurityCheck()
  2295. {
  2296. if (AttackingPermanent == null)
  2297. {
  2298. return true;
  2299. }
  2300. if (AttackingPermanent.TopCard == null)
  2301. {
  2302. return true;
  2303. }
  2304. return false;
  2305. }
  2306. if (!StopSecurityCheck())
  2307. {
  2308. if (AttackingPermanent.Strike == 0)
  2309. {
  2310. yield break;
  2311. }
  2312. GManager.instance.turnStateMachine.IsSelecting = true;
  2313. GManager.instance.turnStateMachine.isSecurityCehck = true;
  2314. #region loop while there are 1 or more security cards
  2315. if (player.SecurityCards.Count >= 1)
  2316. {
  2317. int checkedCount = 0;
  2318. while (true)
  2319. {
  2320. if (StopSecurityCheck())
  2321. {
  2322. break;
  2323. }
  2324. if (checkedCount >= AttackingPermanent.Strike)
  2325. {
  2326. break;
  2327. }
  2328. if (player.SecurityCards.Count >= 1)
  2329. {
  2330. List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
  2331. CardSource brokenSecurityCard = player.SecurityCards[0];
  2332. Hashtable hashtable = new Hashtable()
  2333. {
  2334. {"AttackingPermanent", AttackingPermanent},
  2335. {"Card", brokenSecurityCard}
  2336. };
  2337. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
  2338. {
  2339. triggeredSkillInfos.Add(skillInfo);
  2340. }
  2341. checkedCount++;
  2342. GManager.instance.playLog.AddLogString($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
  2343. if (brokenSecurityCard.IsDigimon)
  2344. {
  2345. GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
  2346. }
  2347. #region effect
  2348. player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2349. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
  2350. yield return new WaitForSeconds(0.1f);
  2351. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
  2352. #endregion
  2353. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2354. player: brokenSecurityCard.Owner,
  2355. refSkillInfos: ref triggeredSkillInfos).ReduceSecurity());
  2356. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
  2357. #region security effect
  2358. List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
  2359. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
  2360. {
  2361. if (cardEffect is ActivateICardEffect)
  2362. {
  2363. Hashtable hashtable1 = new Hashtable();
  2364. hashtable1.Add("Card", brokenSecurityCard);
  2365. if (cardEffect.CanUse(hashtable1))
  2366. {
  2367. secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
  2368. }
  2369. }
  2370. }
  2371. List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
  2372. bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
  2373. if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
  2374. {
  2375. if (!brokenSecurityCard.IsDigimon)
  2376. {
  2377. yield return new WaitForSeconds(0.3f);
  2378. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2379. }
  2380. }
  2381. else
  2382. {
  2383. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
  2384. yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
  2385. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2386. foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
  2387. {
  2388. skillInfos.Add(skillInfo);
  2389. }
  2390. List<CardSource> cardSources = new List<CardSource>();
  2391. for (int j = 0; j < skillInfos.Count; j++)
  2392. {
  2393. cardSources.Add(brokenSecurityCard);
  2394. }
  2395. while (skillInfos.Count >= 1)
  2396. {
  2397. SkillInfo selectedSkillInfo = null;
  2398. if (skillInfos.Count == 1)
  2399. {
  2400. selectedSkillInfo = skillInfos[0];
  2401. }
  2402. else
  2403. {
  2404. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  2405. selectCardEffect.SetUp(
  2406. canTargetCondition: (cardSource) => true,
  2407. canTargetCondition_ByPreSelecetedList: null,
  2408. canEndSelectCondition: null,
  2409. canNoSelect: () => false,
  2410. selectCardCoroutine: null,
  2411. afterSelectCardCoroutine: null,
  2412. message: "select security effect",
  2413. maxCount: 1,
  2414. canEndNotMax: false,
  2415. isShowOpponent: false,
  2416. mode: SelectCardEffect.Mode.Custom,
  2417. root: SelectCardEffect.Root.Custom,
  2418. customRootCardList: cardSources,
  2419. canLookReverseCard: true,
  2420. selectPlayer: player,
  2421. cardEffect: null);
  2422. selectCardEffect.SetUpSkillInfos(skillInfos);
  2423. selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
  2424. selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  2425. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  2426. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  2427. {
  2428. if (selectedIndexes.Count == 1)
  2429. {
  2430. selectedSkillInfo = skillInfos[selectedIndexes[0]];
  2431. yield return null;
  2432. }
  2433. }
  2434. }
  2435. if (selectedSkillInfo != null)
  2436. {
  2437. ICardEffect cardEffect = selectedSkillInfo.CardEffect;
  2438. Hashtable hashtable2 = selectedSkillInfo.Hashtable;
  2439. if (cardEffect.EffectSourceCard == brokenSecurityCard)
  2440. {
  2441. if (cardEffect is ActivateICardEffect)
  2442. {
  2443. skillInfos.Remove(selectedSkillInfo);
  2444. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  2445. cardEffect,
  2446. hashtable2));
  2447. }
  2448. }
  2449. }
  2450. }
  2451. }
  2452. #endregion
  2453. // auto process check
  2454. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2455. // stack effect of "When cards are removed from security" and "checks secuirty"
  2456. foreach (SkillInfo skillInfo in triggeredSkillInfos)
  2457. {
  2458. GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
  2459. }
  2460. // auto process check
  2461. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2462. if (!StopSecurityCheck())
  2463. {
  2464. #region battle with security Digimon
  2465. if (brokenSecurityCard.IsDigimon)
  2466. {
  2467. bool doBattle = true;
  2468. #region "ignore battle" effect
  2469. Hashtable hashtable3 = new Hashtable()
  2470. {
  2471. {"Card", brokenSecurityCard}
  2472. };
  2473. #region the security Digimon's effect
  2474. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
  2475. {
  2476. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2477. {
  2478. if (cardEffect.CanUse(hashtable3))
  2479. {
  2480. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2481. {
  2482. doBattle = false;
  2483. }
  2484. }
  2485. }
  2486. }
  2487. #endregion
  2488. #region player's effect
  2489. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2490. {
  2491. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2492. {
  2493. if (cardEffect is IDontBattleSecurityDigimonEffect)
  2494. {
  2495. if (cardEffect.CanUse(hashtable3))
  2496. {
  2497. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  2498. {
  2499. doBattle = false;
  2500. }
  2501. }
  2502. }
  2503. }
  2504. }
  2505. #endregion
  2506. #endregion
  2507. if (doBattle)
  2508. {
  2509. yield return new WaitForSeconds(0.3f);
  2510. yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
  2511. }
  2512. }
  2513. #endregion
  2514. }
  2515. #region effect
  2516. yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
  2517. if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
  2518. {
  2519. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
  2520. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
  2521. {
  2522. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  2523. }
  2524. }
  2525. GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
  2526. GManager.instance.attackProcess.SecurityDigimon = null;
  2527. #endregion
  2528. // reset effect until end of security check
  2529. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2530. {
  2531. player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  2532. }
  2533. // auto process check
  2534. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2535. GManager.instance.turnStateMachine.IsSelecting = true;
  2536. }
  2537. else
  2538. {
  2539. break;
  2540. }
  2541. }
  2542. }
  2543. #endregion
  2544. GManager.instance.turnStateMachine.isSecurityCehck = false;
  2545. }
  2546. }
  2547. }
  2548. #endregion
  2549. #region trash cards from security
  2550. public class IDestroySecurity
  2551. {
  2552. public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
  2553. {
  2554. _player = player;
  2555. _destroySecurityCount = destroySecurityCount;
  2556. _cardEffect = cardEffect;
  2557. _fromTop = fromTop;
  2558. }
  2559. Player _player = null;
  2560. int _destroySecurityCount = 0;
  2561. ICardEffect _cardEffect = null;
  2562. bool _fromTop = false;
  2563. public IEnumerator DestroySecurity()
  2564. {
  2565. bool StopDestroySecurity()
  2566. {
  2567. if (_player.SecurityCards.Count == 0)
  2568. {
  2569. return true;
  2570. }
  2571. if (!_player.CanReduceSecurity())
  2572. {
  2573. return true;
  2574. }
  2575. return false;
  2576. }
  2577. if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
  2578. {
  2579. int count = 0;
  2580. List<CardSource> discardedCards = new List<CardSource>();
  2581. while (true)
  2582. {
  2583. if (StopDestroySecurity())
  2584. {
  2585. break;
  2586. }
  2587. if (count >= _destroySecurityCount)
  2588. {
  2589. break;
  2590. }
  2591. if (_player.SecurityCards.Count >= 1)
  2592. {
  2593. count++;
  2594. CardSource destroyedSecurityCard = _player.SecurityCards[0];
  2595. if (!_fromTop)
  2596. {
  2597. destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
  2598. }
  2599. discardedCards.Add(destroyedSecurityCard);
  2600. #region effect
  2601. _player.securityObject.securityBreakGlass.ShowBlueMatarial();
  2602. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
  2603. yield return new WaitForSeconds(0.1f);
  2604. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
  2605. yield return new WaitForSeconds(0.5f);
  2606. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
  2607. #endregion
  2608. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
  2609. }
  2610. }
  2611. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  2612. if (discardedCards.Count >= 1)
  2613. {
  2614. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  2615. player: _player,
  2616. refSkillInfos: ref ContinuousController.instance.nullSkillInfos).ReduceSecurity());
  2617. }
  2618. if (discardedCards.Count >= 1)
  2619. {
  2620. #region "When security cards are trashed" effect
  2621. #region Hashtable setting
  2622. Hashtable hashtable = new Hashtable()
  2623. {
  2624. {"DiscardedCards", discardedCards},
  2625. {"CardEffect", _cardEffect},
  2626. };
  2627. #endregion
  2628. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
  2629. #endregion
  2630. }
  2631. #region add log
  2632. if (discardedCards.Count >= 1)
  2633. {
  2634. string log = "";
  2635. log += $"\nDiscarded Security Cards:";
  2636. foreach (CardSource cardSource in discardedCards)
  2637. {
  2638. if (cardSource != null)
  2639. {
  2640. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2641. }
  2642. }
  2643. log += "\n";
  2644. GManager.instance.playLog.AddLogString(log);
  2645. }
  2646. #endregion
  2647. }
  2648. }
  2649. }
  2650. #endregion
  2651. #region Battle
  2652. public class IBattle
  2653. {
  2654. public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard)
  2655. {
  2656. this.AttackingPermanent = AttackingPermanent;
  2657. this.DefendingPermanent = DefendingPermanent;
  2658. this.DefendingCard = DefendingCard;
  2659. }
  2660. public Permanent AttackingPermanent { get; private set; } = null;
  2661. public Permanent DefendingPermanent { get; private set; } = null;
  2662. CardSource DefendingCard { get; set; } = null;
  2663. public Hashtable hashtable { get; set; } = new Hashtable();
  2664. public Permanent enemyPermanent(Permanent permanent)
  2665. {
  2666. if (permanent != null)
  2667. {
  2668. if (permanent == AttackingPermanent)
  2669. {
  2670. return DefendingPermanent;
  2671. }
  2672. else if (permanent == DefendingPermanent)
  2673. {
  2674. return AttackingPermanent;
  2675. }
  2676. }
  2677. return null;
  2678. }
  2679. public IEnumerator Battle()
  2680. {
  2681. hashtable = new Hashtable();
  2682. if (AttackingPermanent != null)
  2683. {
  2684. bool IsExistingDefender()
  2685. {
  2686. // whether defender exists
  2687. if ((DefendingPermanent == null) != (DefendingCard == null))
  2688. {
  2689. if (DefendingPermanent != null)
  2690. {
  2691. if (DefendingPermanent.TopCard != null)
  2692. {
  2693. return true;
  2694. }
  2695. }
  2696. else if (DefendingCard != null)
  2697. {
  2698. return true;
  2699. }
  2700. }
  2701. return false;
  2702. }
  2703. if (IsExistingDefender())
  2704. {
  2705. if (AttackingPermanent != null)
  2706. {
  2707. AttackingPermanent.battle = this;
  2708. }
  2709. if (DefendingPermanent != null)
  2710. {
  2711. DefendingPermanent.battle = this;
  2712. }
  2713. List<Permanent> WinnerPermanents = new List<Permanent>();
  2714. List<Permanent> LoserPermanents = new List<Permanent>();
  2715. CardSource LoserCard = null;
  2716. //add log
  2717. string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
  2718. if (DefendingPermanent != null)
  2719. {
  2720. log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
  2721. }
  2722. else if (DefendingCard != null)
  2723. {
  2724. log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
  2725. }
  2726. GManager.instance.playLog.AddLogString(log);
  2727. #region "At the start of battle" effect
  2728. Permanent _AttackingPermanent = null;
  2729. Permanent _DefendingPermanent = null;
  2730. if (AttackingPermanent != null)
  2731. {
  2732. if (AttackingPermanent.TopCard != null)
  2733. {
  2734. _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
  2735. }
  2736. }
  2737. if (DefendingPermanent != null)
  2738. {
  2739. if (DefendingPermanent.TopCard != null)
  2740. {
  2741. _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
  2742. }
  2743. }
  2744. hashtable.Add("AttackingPermanent", _AttackingPermanent);
  2745. hashtable.Add("DefendingPermanent", _DefendingPermanent);
  2746. hashtable.Add("DefendingCard", DefendingCard);
  2747. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
  2748. #endregion
  2749. #region Show effect
  2750. bool ShowEffect()
  2751. {
  2752. if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
  2753. {
  2754. return true;
  2755. }
  2756. else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
  2757. {
  2758. if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
  2759. {
  2760. return true;
  2761. }
  2762. }
  2763. return false;
  2764. }
  2765. if (ShowEffect())
  2766. {
  2767. if (GManager.instance.attackProcess.IsAttacking)
  2768. {
  2769. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2770. {
  2771. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2772. {
  2773. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2774. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2775. }
  2776. }
  2777. }
  2778. }
  2779. #endregion
  2780. // auto process check
  2781. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2782. GManager.instance.turnStateMachine.IsSelecting = true;
  2783. #region battle with permanent
  2784. if (DefendingPermanent != null)
  2785. {
  2786. if (AttackingPermanent.DP > DefendingPermanent.DP)
  2787. {
  2788. WinnerPermanents.Add(AttackingPermanent);
  2789. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2790. {
  2791. LoserPermanents.Add(DefendingPermanent);
  2792. }
  2793. }
  2794. else if (AttackingPermanent.DP == DefendingPermanent.DP)
  2795. {
  2796. WinnerPermanents.Add(AttackingPermanent);
  2797. WinnerPermanents.Add(DefendingPermanent);
  2798. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2799. {
  2800. LoserPermanents.Add(AttackingPermanent);
  2801. }
  2802. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2803. {
  2804. LoserPermanents.Add(DefendingPermanent);
  2805. }
  2806. }
  2807. else if (AttackingPermanent.DP < DefendingPermanent.DP)
  2808. {
  2809. WinnerPermanents.Add(DefendingPermanent);
  2810. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2811. {
  2812. LoserPermanents.Add(AttackingPermanent);
  2813. }
  2814. }
  2815. }
  2816. #endregion
  2817. #region battle with card
  2818. else if (DefendingCard != null)
  2819. {
  2820. if (AttackingPermanent.DP > DefendingCard.CardDP)
  2821. {
  2822. WinnerPermanents.Add(AttackingPermanent);
  2823. LoserCard = DefendingCard;
  2824. }
  2825. else if (AttackingPermanent.DP == DefendingCard.CardDP)
  2826. {
  2827. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2828. {
  2829. LoserPermanents.Add(AttackingPermanent);
  2830. }
  2831. LoserCard = DefendingCard;
  2832. }
  2833. else if (AttackingPermanent.DP < DefendingCard.CardDP)
  2834. {
  2835. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  2836. {
  2837. LoserPermanents.Add(AttackingPermanent);
  2838. }
  2839. }
  2840. }
  2841. #endregion
  2842. List<Permanent> _WinnerPermanents = new List<Permanent>();
  2843. List<Permanent> _LoserPermanents = new List<Permanent>();
  2844. foreach (Permanent permanent in WinnerPermanents)
  2845. {
  2846. if (permanent.TopCard != null)
  2847. {
  2848. _WinnerPermanents.Add(new Permanent(permanent.cardSources));
  2849. }
  2850. }
  2851. foreach (Permanent permanent in LoserPermanents)
  2852. {
  2853. if (permanent.TopCard != null)
  2854. {
  2855. _LoserPermanents.Add(new Permanent(permanent.cardSources));
  2856. }
  2857. }
  2858. hashtable.Add("WinnerPermanents", _WinnerPermanents);
  2859. hashtable.Add("WinnerPermanents_real", WinnerPermanents);
  2860. hashtable.Add("LoserPermanents", _LoserPermanents);
  2861. hashtable.Add("LoserPermanents_real", LoserPermanents);
  2862. hashtable.Add("LoserCard", LoserCard);
  2863. hashtable.Add("battle", this);
  2864. // battle effect
  2865. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
  2866. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(LoserPermanents, hashtable).Destroy());
  2867. //Fix winner/loser permanents
  2868. int index = -1;
  2869. foreach (Permanent permanent in LoserPermanents)
  2870. {
  2871. if(permanent.TopCard != null)
  2872. {
  2873. index = LoserPermanents.IndexOf(permanent);
  2874. }
  2875. }
  2876. if(index >= 0)
  2877. {
  2878. LoserPermanents.RemoveAt(index);
  2879. _LoserPermanents.RemoveAt(index);
  2880. hashtable["LoserPermanents"] = _LoserPermanents;
  2881. hashtable["LoserPermanents_real"] = LoserPermanents;
  2882. }
  2883. // "At the end of battle" effect
  2884. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
  2885. #region move up effect
  2886. if (ShowEffect())
  2887. {
  2888. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
  2889. }
  2890. #endregion
  2891. }
  2892. }
  2893. // auto process check
  2894. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  2895. #region reset effect until the end of battle
  2896. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2897. {
  2898. foreach (Permanent permanent in player.GetFieldPermanents())
  2899. {
  2900. permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  2901. }
  2902. player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  2903. }
  2904. #endregion
  2905. if (AttackingPermanent != null)
  2906. {
  2907. AttackingPermanent.battle = null;
  2908. }
  2909. if (DefendingPermanent != null)
  2910. {
  2911. DefendingPermanent.battle = null;
  2912. }
  2913. }
  2914. }
  2915. #endregion
  2916. #region De-digivolve
  2917. public class IDegeneration
  2918. {
  2919. public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect)
  2920. {
  2921. _permanent = permanent;
  2922. _degenerationCount = DegenerationCount;
  2923. _cardEffect = cardEffect;
  2924. }
  2925. Permanent _permanent = null;
  2926. int _degenerationCount = 0;
  2927. ICardEffect _cardEffect = null;
  2928. public IEnumerator Degeneration()
  2929. {
  2930. if (_cardEffect == null) yield break;
  2931. if (_cardEffect.EffectSourceCard == null) yield break;
  2932. if (_permanent == null) yield break;
  2933. if (_permanent.TopCard == null) yield break;
  2934. if (_permanent.ImmuneFromDeDigivolve()) yield break;
  2935. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  2936. int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
  2937. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  2938. if (selectCountEffect != null)
  2939. {
  2940. Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
  2941. selectCountEffect.SetUp(
  2942. SelectPlayer: selectPlayer,
  2943. targetPermanent: _permanent,
  2944. MaxCount: maxCount,
  2945. CanNoSelect: false,
  2946. Message: "How many cards do you trash?",
  2947. Message_Enemy: "The opponent is choosing how many cards to trash.",
  2948. SelectCountCoroutine: SelectCountCoroutine);
  2949. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  2950. IEnumerator SelectCountCoroutine(int count)
  2951. {
  2952. _degenerationCount = count;
  2953. yield return null;
  2954. }
  2955. }
  2956. if (_degenerationCount >= 1)
  2957. {
  2958. int count = 0;
  2959. List<CardSource> selectedCards = new List<CardSource>();
  2960. while (true)
  2961. {
  2962. bool StopCondition()
  2963. {
  2964. if (_permanent.HasNoDigivolutionCards)
  2965. {
  2966. return true;
  2967. }
  2968. if (_permanent.Level == 3)
  2969. {
  2970. if (_permanent.TopCard != null)
  2971. {
  2972. if (_permanent.TopCard.HasLevel)
  2973. {
  2974. return true;
  2975. }
  2976. }
  2977. }
  2978. if (count >= _degenerationCount)
  2979. {
  2980. return true;
  2981. }
  2982. return false;
  2983. }
  2984. if (StopCondition())
  2985. {
  2986. break;
  2987. }
  2988. if (count == 0)
  2989. {
  2990. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  2991. }
  2992. CardSource cardSource = _permanent.TopCard;
  2993. selectedCards.Add(cardSource);
  2994. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  2995. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  2996. if (!cardSource.IsToken)
  2997. {
  2998. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  2999. }
  3000. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  3001. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3002. count++;
  3003. }
  3004. #region add log
  3005. if (selectedCards.Count >= 1)
  3006. {
  3007. string log = "";
  3008. log += $"\nDe-Digivolve :";
  3009. foreach (CardSource cardSource in selectedCards)
  3010. {
  3011. if (cardSource != null)
  3012. {
  3013. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3014. }
  3015. }
  3016. log += "\n";
  3017. GManager.instance.playLog.AddLogString(log);
  3018. }
  3019. #endregion
  3020. }
  3021. }
  3022. }
  3023. #endregion
  3024. #region Trash digivolution cards
  3025. public class ITrashDigivolutionCards
  3026. {
  3027. public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  3028. {
  3029. _permanent = permanent;
  3030. _trashTargetCards = trashTargetCards.Clone();
  3031. _cardEffect = cardEffect;
  3032. }
  3033. Permanent _permanent = null;
  3034. List<CardSource> _trashTargetCards = new List<CardSource>();
  3035. ICardEffect _cardEffect = null;
  3036. public IEnumerator TrashDigivolutionCards()
  3037. {
  3038. if (_trashTargetCards == null) yield break;
  3039. if (_cardEffect == null) yield break;
  3040. if (_permanent == null) yield break;
  3041. if (_permanent.TopCard == null) yield break;
  3042. if (_permanent.HasNoDigivolutionCards) yield break;
  3043. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3044. _trashTargetCards = _trashTargetCards.Filter((cardSource) => _permanent.DigivolutionCards.Contains(cardSource) && !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
  3045. if (_trashTargetCards.Count == 0) yield break;
  3046. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  3047. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  3048. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3049. #region "When digivolution cards are trashed" effect
  3050. #region Hashtable Setting
  3051. Hashtable hashtable = new Hashtable()
  3052. {
  3053. {"CardEffect", _cardEffect},
  3054. {"Permanent", _permanent},
  3055. {"DiscardedCards", _trashTargetCards},
  3056. };
  3057. #endregion
  3058. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
  3059. #endregion
  3060. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  3061. foreach (CardSource cardSource in _trashTargetCards)
  3062. {
  3063. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3064. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3065. if (!cardSource.IsToken)
  3066. {
  3067. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3068. }
  3069. }
  3070. }
  3071. }
  3072. #endregion
  3073. #region Return digivolution cards to deck bottom
  3074. public class ReturnToLibraryBottomDigivolutionCardsClass
  3075. {
  3076. public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
  3077. {
  3078. _permanent = permanent;
  3079. _cardSources = cardSources.Clone();
  3080. _hashtable = hashtable;
  3081. }
  3082. Permanent _permanent = null;
  3083. List<CardSource> _cardSources = new List<CardSource>();
  3084. Hashtable _hashtable = null;
  3085. public IEnumerator ReturnToLibraryBottomDigivolutionCards()
  3086. {
  3087. if (_permanent == null) yield break;
  3088. if (_permanent.TopCard == null) yield break;
  3089. if (_cardSources == null) yield break;
  3090. _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
  3091. if (_cardSources.Count == 0) yield break;
  3092. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3093. if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
  3094. string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
  3095. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
  3096. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3097. #region "When digivolution cards are returned to deck" effect
  3098. #region Hashtable Setting
  3099. Hashtable hashtable1 = new Hashtable()
  3100. {
  3101. {"Permanent", _permanent},
  3102. {"DeckBottomCards", _cardSources},
  3103. {"CardEffect", CardEffect},
  3104. };
  3105. #endregion
  3106. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
  3107. #endregion
  3108. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
  3109. }
  3110. }
  3111. #endregion
  3112. #region Reduce security
  3113. public class IReduceSecurity
  3114. {
  3115. public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos)
  3116. {
  3117. _player = player;
  3118. _refSkillInfos = refSkillInfos;
  3119. }
  3120. Player _player = null;
  3121. List<SkillInfo> _refSkillInfos = null;
  3122. public IEnumerator ReduceSecurity()
  3123. {
  3124. #region "When cards are removed from security" effect
  3125. #region Hashtable Setting
  3126. Hashtable hashtable = new Hashtable()
  3127. {
  3128. {"Player", _player}
  3129. };
  3130. #endregion
  3131. if (_refSkillInfos == null)
  3132. {
  3133. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
  3134. }
  3135. else
  3136. {
  3137. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
  3138. {
  3139. _refSkillInfos.Add(skillInfo);
  3140. }
  3141. }
  3142. #endregion
  3143. }
  3144. }
  3145. #endregion
  3146. #region Add Security
  3147. public class IAddSecurity
  3148. {
  3149. public IAddSecurity(Player player)
  3150. {
  3151. _player = player;
  3152. }
  3153. Player _player { get; set; }
  3154. public IEnumerator AddSecurity()
  3155. {
  3156. #region "When security cards are added" effect
  3157. #region Hashtable setting
  3158. Hashtable hashtable = new Hashtable()
  3159. {
  3160. {"Player", _player}
  3161. };
  3162. #endregion
  3163. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
  3164. #endregion
  3165. }
  3166. }
  3167. #endregion
  3168. #region Suspend permanents
  3169. public class SuspendPermanentsClass
  3170. {
  3171. public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
  3172. {
  3173. _permanents = permanents;
  3174. _hashtable = hashtable;
  3175. }
  3176. List<Permanent> _permanents { get; set; }
  3177. Hashtable _hashtable { get; set; }
  3178. public IEnumerator Tap()
  3179. {
  3180. if (_permanents.Count == 0) yield break;
  3181. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  3182. bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
  3183. bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
  3184. List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
  3185. bool PermanentCondition(Permanent permanent)
  3186. {
  3187. if (permanent != null)
  3188. {
  3189. if (permanent.TopCard != null)
  3190. {
  3191. if (permanent.IsSuspended)
  3192. {
  3193. return false;
  3194. }
  3195. if (!permanent.CanSuspend)
  3196. {
  3197. return false;
  3198. }
  3199. if (CardEffect != null)
  3200. {
  3201. if (permanent.TopCard.CanNotBeAffected(CardEffect))
  3202. {
  3203. return false;
  3204. }
  3205. }
  3206. }
  3207. }
  3208. return true;
  3209. }
  3210. foreach (Permanent permanent in suspendTargetPermanents)
  3211. {
  3212. permanent.IsSuspended = true;
  3213. permanent.DPWhenSuspended = permanent.DP;
  3214. if (permanent.ShowingPermanentCard != null)
  3215. {
  3216. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3217. }
  3218. }
  3219. if (suspendTargetPermanents.Count >= 1)
  3220. {
  3221. #region "Effects when permanents suspend
  3222. #region Hashtable Setting
  3223. Hashtable _hashtable = new Hashtable(){
  3224. {"Permanents", suspendTargetPermanents},
  3225. {"IsBlock", IsBlock}
  3226. };
  3227. if (CardEffect != null)
  3228. {
  3229. _hashtable.Add("CardEffect", CardEffect);
  3230. }
  3231. #endregion
  3232. if (IsAttack) yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3233. else yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  3234. #endregion
  3235. yield return new WaitForSeconds(0.3f);
  3236. }
  3237. }
  3238. }
  3239. #endregion
  3240. #region Unsuspend permanents
  3241. public class IUnsuspendPermanents
  3242. {
  3243. public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
  3244. {
  3245. _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  3246. _cardEffect = cardEffect;
  3247. }
  3248. List<Permanent> _permanents { get; set; }
  3249. ICardEffect _cardEffect { get; set; }
  3250. public IEnumerator Unsuspend()
  3251. {
  3252. //Permanent list that will unsuspend
  3253. List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
  3254. permanent != null
  3255. && permanent.TopCard != null
  3256. && permanent.IsSuspended
  3257. && permanent.CanUnsuspend
  3258. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3259. #region "When permanents would unsuspend" effect
  3260. #region Hashtable Setting
  3261. Hashtable hashtable1 = new Hashtable()
  3262. {
  3263. {"CardEffect", _cardEffect},
  3264. {"Permanents", untappedPermanets},
  3265. };
  3266. #endregion
  3267. List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
  3268. if (skillInfos.Count >= 1)
  3269. {
  3270. foreach (SkillInfo skillInfo in skillInfos)
  3271. {
  3272. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  3273. }
  3274. foreach (Permanent permanent in untappedPermanets)
  3275. {
  3276. permanent.ShowUnsuspendEffect();
  3277. }
  3278. //cut in effects
  3279. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3280. untappedPermanets.ForEach(permanent =>
  3281. {
  3282. if (permanent.ShowingPermanentCard != null)
  3283. {
  3284. permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
  3285. }
  3286. });
  3287. }
  3288. #endregion
  3289. // fix unsuspend target permanents
  3290. List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
  3291. permanent != null
  3292. && permanent.TopCard != null
  3293. && permanent.IsSuspended
  3294. && permanent.CanUnsuspend
  3295. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  3296. if (untappedPermanets_Fixed.Count >= 1)
  3297. {
  3298. foreach (Permanent permanent in untappedPermanets_Fixed)
  3299. {
  3300. permanent.IsSuspended = false;
  3301. if (permanent.ShowingPermanentCard != null)
  3302. {
  3303. permanent.ShowingPermanentCard.ShowPermanentData(true);
  3304. }
  3305. }
  3306. #region "When permanents are unsuspended" effect
  3307. #region Hashtable Setting
  3308. Hashtable hashtable2 = new Hashtable()
  3309. {
  3310. {"CardEffect", _cardEffect},
  3311. {"Permanents", untappedPermanets_Fixed},
  3312. };
  3313. #endregion
  3314. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
  3315. #endregion
  3316. yield return new WaitForSeconds(0.3f);
  3317. }
  3318. foreach (Permanent permanent in untappedPermanets)
  3319. {
  3320. permanent.UntilNextUntapEffects = new List<Func<EffectTiming, ICardEffect>>();
  3321. }
  3322. }
  3323. }
  3324. #endregion
  3325. #region Trash cards from deck top
  3326. public class ITrashDeckCards
  3327. {
  3328. public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
  3329. {
  3330. this.cardSources = new List<CardSource>();
  3331. foreach (CardSource cardSource in cardSources)
  3332. {
  3333. this.cardSources.Add(cardSource);
  3334. }
  3335. this.cardEffect = cardEffect;
  3336. }
  3337. List<CardSource> cardSources { get; set; } = new List<CardSource>();
  3338. ICardEffect cardEffect { get; set; } = null;
  3339. public IEnumerator TrashDeckCards()
  3340. {
  3341. List<CardSource> trashCards = new List<CardSource>();
  3342. foreach (CardSource cardSource in cardSources)
  3343. {
  3344. if (cardSource.Owner.LibraryCards.Contains(cardSource))
  3345. {
  3346. trashCards.Add(cardSource);
  3347. }
  3348. }
  3349. if (trashCards.Count >= 1)
  3350. {
  3351. foreach (CardSource cardSource in trashCards)
  3352. {
  3353. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3354. }
  3355. #region "When cards are trashed from security" effect
  3356. #region Hashtable setting
  3357. Hashtable hashtable = new Hashtable()
  3358. {
  3359. {"DiscardedCards", trashCards},
  3360. {"CardEffect", cardEffect},
  3361. };
  3362. #endregion
  3363. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  3364. hashtable, EffectTiming.OnDiscardLibrary));
  3365. #endregion
  3366. }
  3367. }
  3368. }
  3369. #endregion
  3370. #region Overflow of ace
  3371. public class AceOverflowClass
  3372. {
  3373. public AceOverflowClass(List<CardSource> cardSources)
  3374. {
  3375. _cardSources = cardSources.Clone();
  3376. }
  3377. List<CardSource> _cardSources = new List<CardSource>();
  3378. public IEnumerator Overflow()
  3379. {
  3380. _cardSources = _cardSources
  3381. .Filter(cardSource => cardSource.IsACE && CardEffectCommons.IsExistOnBattleArea(cardSource))
  3382. .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
  3383. .ToList();
  3384. foreach (CardSource cardSource in _cardSources)
  3385. {
  3386. yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
  3387. string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
  3388. GManager.instance.playLog.AddLogString(log);
  3389. }
  3390. }
  3391. }
  3392. #endregion