CardController.cs 210 KB

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