CardController.cs 211 KB

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