CardController.cs 156 KB

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