CardController.cs 180 KB

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