CardController.cs 180 KB

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