CardController.cs 166 KB

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