CardController.cs 196 KB

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