CardController.cs 210 KB

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