CardController.cs 207 KB

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