CardController.cs 153 KB

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