CardController.cs 191 KB

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