CardController.cs 201 KB

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