CardController.cs 183 KB

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