diff --git a/biome.jsonc b/biome.jsonc index c5e1d713d86..da80d8ee127 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -65,7 +65,8 @@ "useDefaultParameterLast": "off", // TODO: Fix spots in the codebase where this flag would be triggered, and then enable "useSingleVarDeclarator": "off", "useNodejsImportProtocol": "off", - "useTemplate": "off" // string concatenation is faster: https://stackoverflow.com/questions/29055518/are-es6-template-literals-faster-than-string-concatenation + "useTemplate": "off", // string concatenation is faster: https://stackoverflow.com/questions/29055518/are-es6-template-literals-faster-than-string-concatenation + "noNamespaceImport": "error" }, "suspicious": { "noDoubleEquals": "error", @@ -99,6 +100,9 @@ "rules": { "performance": { "noDelete": "off" + }, + "style": { + "noNamespaceImport": "off" } } } diff --git a/public/images/pokemon/variant/_exp_masterlist.json b/public/images/pokemon/variant/_exp_masterlist.json new file mode 100644 index 00000000000..0ef5f209439 --- /dev/null +++ b/public/images/pokemon/variant/_exp_masterlist.json @@ -0,0 +1,656 @@ +{ + "3-mega": [0, 2, 2], + "6-mega-x": [0, 2, 2], + "6-mega-y": [0, 2, 2], + "80-mega": [0, 1, 1], + "94-mega": [2, 2, 2], + "127-mega": [0, 1, 1], + "130-mega": [0, 1, 1], + "142-mega": [0, 1, 1], + "150-mega-x": [0, 1, 1], + "150-mega-y": [0, 1, 1], + "181-mega": [0, 1, 2], + "212-mega": [1, 1, 2], + "229-mega": [0, 1, 1], + "248-mega": [0, 1, 1], + "257-mega": [0, 1, 1], + "282-mega": [0, 2, 2], + "302-mega": [0, 1, 1], + "303-mega": [0, 1, 1], + "306-mega": [1, 1, 1], + "308-mega": [0, 1, 1], + "310-mega": [0, 1, 1], + "334-mega": [0, 2, 1], + "354-mega": [0, 1, 1], + "359-mega": [0, 1, 1], + "362-mega": [0, 1, 1], + "373-mega": [0, 1, 1], + "376-mega": [0, 1, 1], + "380-mega": [0, 1, 1], + "381-mega": [0, 1, 1], + "382-primal": [0, 1, 1], + "383-primal": [0, 1, 1], + "384-mega": [0, 2, 1], + "428-mega": [0, 1, 1], + "445-mega": [1, 1, 1], + "448-mega": [1, 1, 1], + "475-mega": [0, 2, 2], + "531-mega": [0, 1, 1], + "653": [0, 1, 1], + "654": [0, 1, 1], + "655": [0, 1, 1], + "656": [0, 1, 1], + "657": [0, 1, 1], + "658": [0, 1, 1], + "658-ash": [0, 1, 1], + "664": [0, 1, 1], + "665": [0, 1, 1], + "666-archipelago": [0, 1, 1], + "666-continental": [0, 1, 1], + "666-elegant": [0, 1, 1], + "666-fancy": [0, 1, 1], + "666-garden": [0, 1, 1], + "666-high-plains": [0, 1, 1], + "666-icy-snow": [0, 1, 1], + "666-jungle": [0, 1, 1], + "666-marine": [0, 1, 1], + "666-meadow": [0, 1, 1], + "666-modern": [0, 1, 1], + "666-monsoon": [0, 1, 1], + "666-ocean": [0, 1, 1], + "666-poke-ball": [0, 1, 1], + "666-polar": [0, 1, 1], + "666-river": [0, 1, 1], + "666-sandstorm": [0, 1, 1], + "666-savanna": [0, 1, 1], + "666-sun": [0, 1, 1], + "666-tundra": [0, 1, 1], + "669-red": [0, 2, 2], + "669-blue": [0, 1, 1], + "669-white": [0, 1, 1], + "669-yellow": [0, 1, 1], + "669-orange": [0, 2, 2], + "670-white": [0, 1, 1], + "670-blue": [0, 1, 1], + "670-orange": [0, 1, 1], + "670-red": [0, 1, 1], + "670-yellow": [0, 1, 1], + "671-red": [0, 1, 2], + "671-blue": [0, 1, 2], + "671-yellow": [0, 1, 1], + "671-white": [0, 1, 2], + "671-orange": [0, 1, 2], + "672": [0, 1, 1], + "673": [0, 1, 1], + "676": [0, 1, 1], + "677": [0, 1, 1], + "678-female": [0, 1, 1], + "678": [0, 1, 1], + "682": [0, 1, 1], + "683": [0, 1, 1], + "684": [0, 1, 1], + "685": [0, 1, 1], + "688": [0, 1, 1], + "689": [0, 1, 1], + "690": [0, 1, 1], + "691": [0, 1, 1], + "696": [0, 1, 1], + "697": [0, 1, 1], + "699": [0, 1, 1], + "700": [0, 1, 1], + "702": [0, 1, 1], + "704": [0, 1, 1], + "705": [0, 1, 1], + "706": [0, 1, 1], + "709": [0, 1, 1], + "710": [0, 1, 1], + "711": [1, 1, 1], + "712": [0, 1, 1], + "713": [0, 1, 1], + "715": [0, 1, 1], + "716-active": [0, 1, 1], + "716-neutral": [0, 1, 1], + "717": [0, 2, 2], + "720-unbound": [1, 1, 1], + "720": [1, 1, 1], + "728": [0, 1, 1], + "729": [0, 1, 1], + "730": [0, 1, 1], + "734": [0, 1, 1], + "735": [0, 1, 1], + "742": [0, 2, 2], + "743": [0, 2, 2], + "747": [0, 2, 2], + "748": [0, 1, 1], + "751": [0, 1, 1], + "752": [0, 1, 1], + "753": [0, 1, 1], + "754": [0, 2, 2], + "755": [0, 1, 1], + "756": [0, 1, 1], + "761": [0, 1, 1], + "762": [0, 1, 1], + "763": [0, 1, 1], + "767": [0, 1, 1], + "768": [0, 1, 1], + "770": [0, 0, 0], + "771": [0, 2, 2], + "772": [0, 1, 1], + "773-fighting": [0, 1, 1], + "773-psychic": [0, 1, 1], + "773-poison": [0, 1, 1], + "773-ground": [0, 1, 1], + "773-ghost": [0, 1, 1], + "773-steel": [0, 1, 1], + "773-rock": [0, 1, 1], + "773-grass": [0, 1, 1], + "773-dragon": [0, 1, 1], + "773-bug": [0, 1, 1], + "773-ice": [0, 1, 1], + "773-dark": [0, 1, 1], + "773": [0, 1, 1], + "773-fairy": [0, 1, 1], + "773-water": [0, 1, 1], + "773-electric": [0, 1, 1], + "773-flying": [0, 1, 1], + "773-fire": [0, 1, 1], + "776": [0, 1, 1], + "777": [0, 1, 1], + "778-busted": [0, 1, 1], + "778-disguised": [0, 1, 1], + "779": [0, 1, 1], + "789": [1, 1, 1], + "790": [0, 1, 1], + "791": [2, 1, 1], + "792": [0, 1, 1], + "793": [0, 2, 2], + "797": [0, 1, 1], + "798": [0, 1, 1], + "800-dawn-wings": [0, 1, 1], + "800-dusk-mane": [0, 1, 1], + "800-ultra": [0, 1, 1], + "800": [0, 1, 1], + "802": [1, 1, 1], + "803": [0, 1, 1], + "804": [0, 1, 1], + "807": [0, 1, 1], + "808": [0, 1, 1], + "809": [0, 1, 1], + "816": [0, 1, 1], + "817": [0, 1, 1], + "818": [1, 1, 1], + "821": [0, 2, 2], + "822": [0, 1, 1], + "823": [0, 1, 1], + "829": [0, 1, 1], + "830": [0, 1, 1], + "835": [0, 1, 1], + "836": [0, 2, 2], + "850": [0, 1, 1], + "851": [0, 1, 1], + "854": [0, 1, 1], + "855": [0, 1, 1], + "856": [0, 1, 1], + "857": [0, 2, 2], + "858": [0, 1, 1], + "859": [0, 1, 1], + "860": [0, 1, 1], + "861": [0, 1, 1], + "862": [0, 1, 1], + "863": [0, 1, 1], + "864": [0, 1, 1], + "867": [0, 1, 1], + "872": [1, 1, 1], + "873": [1, 1, 1], + "876-female": [0, 1, 1], + "876": [0, 1, 1], + "877-hangry": [1, 1, 1], + "877": [1, 1, 1], + "880": [0, 1, 1], + "881": [0, 1, 1], + "882": [0, 2, 1], + "883": [0, 1, 1], + "884": [0, 1, 1], + "885": [1, 1, 1], + "886": [1, 1, 1], + "887": [1, 1, 1], + "888": [0, 1, 1], + "888-crowned": [0, 1, 1], + "889": [0, 1, 1], + "889-crowned": [0, 1, 1], + "890": [0, 2, 1], + "890-eternamax": [0, 1, 1], + "891": [1, 1, 1], + "892-rapid-strike": [1, 1, 1], + "892": [1, 1, 1], + "894": [0, 1, 1], + "895": [0, 1, 1], + "896": [1, 1, 1], + "897": [1, 1, 1], + "898": [1, 1, 1], + "898-ice": [1, 1, 1], + "898-shadow": [1, 1, 1], + "900": [0, 1, 1], + "901": [0, 1, 1], + "903": [0, 1, 1], + "909": [0, 1, 1], + "910": [0, 2, 2], + "911": [0, 2, 2], + "912": [0, 1, 2], + "913": [0, 1, 2], + "914": [0, 2, 1], + "919": [1, 1, 1], + "920": [1, 1, 1], + "924": [1, 1, 1], + "925-four": [1, 2, 2], + "925-three": [1, 2, 2], + "932": [0, 2, 2], + "933": [0, 2, 2], + "934": [0, 1, 1], + "935": [1, 1, 2], + "936": [2, 2, 2], + "937": [2, 2, 2], + "940": [0, 1, 1], + "941": [0, 1, 1], + "944": [0, 1, 1], + "945": [0, 1, 1], + "948": [0, 1, 1], + "949": [0, 1, 1], + "951": [0, 1, 1], + "952": [0, 1, 1], + "953": [0, 1, 1], + "954": [0, 1, 1], + "957": [2, 2, 2], + "958": [2, 2, 2], + "959": [2, 2, 2], + "962": [1, 1, 1], + "967": [0, 1, 1], + "968": [0, 1, 1], + "969": [0, 1, 1], + "970": [0, 1, 1], + "973": [1, 1, 1], + "974": [0, 1, 1], + "975": [0, 1, 1], + "978-curly": [0, 2, 2], + "978-droopy": [0, 2, 2], + "978-stretchy": [0, 2, 2], + "979": [2, 2, 2], + "981": [0, 1, 1], + "982": [0, 1, 1], + "982-three-segment": [0, 1, 1], + "987": [1, 1, 1], + "988": [0, 1, 2], + "993": [0, 1, 1], + "994": [0, 1, 2], + "995": [0, 1, 1], + "996": [0, 1, 1], + "997": [0, 2, 2], + "998": [0, 2, 2], + "999": [2, 1, 1], + "1000": [1, 1, 1], + "1001": [0, 1, 1], + "1003": [0, 1, 1], + "1004": [0, 1, 1], + "1006": [0, 2, 1], + "1007-apex-build": [0, 2, 2], + "1008-ultimate-mode": [1, 1, 1], + "2026": [0, 1, 1], + "2027": [0, 1, 1], + "2028": [0, 1, 1], + "2052": [0, 1, 1], + "2053": [0, 1, 0], + "2103": [0, 1, 1], + "4052": [0, 1, 1], + "4077": [0, 1, 1], + "4078": [0, 1, 1], + "4079": [0, 1, 1], + "4080": [2, 1, 1], + "4144": [0, 1, 1], + "4145": [0, 1, 1], + "4146": [0, 1, 1], + "4199": [2, 1, 1], + "4222": [0, 1, 1], + "4263": [0, 1, 1], + "4264": [0, 1, 1], + "4562": [0, 1, 1], + "6100": [0, 1, 1], + "6101": [0, 1, 1], + "6215": [0, 1, 1], + "6503": [0, 1, 1], + "6549": [0, 1, 1], + "6570": [0, 1, 1], + "6571": [0, 1, 1], + "6705": [0, 1, 1], + "6706": [0, 1, 1], + "6713": [0, 1, 1], + "female": { + "6215": [0, 1, 1] + }, + "back": { + "3-mega": [0, 2, 2], + "6-mega-x": [0, 2, 2], + "6-mega-y": [0, 1, 2], + "80-mega": [0, 1, 1], + "94-mega": [1, 1, 1], + "127-mega": [0, 1, 1], + "130-mega": [0, 1, 1], + "142-mega": [0, 1, 1], + "150-mega-x": [0, 1, 1], + "150-mega-y": [0, 1, 1], + "181-mega": [0, 1, 2], + "212-mega": [1, 2, 2], + "229-mega": [0, 1, 1], + "248-mega": [0, 1, 1], + "257-mega": [0, 1, 1], + "282-mega": [0, 1, 1], + "302-mega": [0, 1, 1], + "303-mega": [0, 1, 1], + "306-mega": [1, 1, 1], + "308-mega": [0, 1, 1], + "310-mega": [0, 1, 1], + "334-mega": [0, 1, 1], + "354-mega": [0, 1, 1], + "359-mega": [0, 1, 1], + "362-mega": [0, 1, 1], + "373-mega": [0, 1, 1], + "376-mega": [0, 1, 1], + "380-mega": [0, 1, 1], + "381-mega": [0, 1, 1], + "382-primal": [0, 1, 1], + "383-primal": [0, 1, 1], + "384-mega": [0, 1, 1], + "428-mega": [0, 1, 1], + "445-mega": [1, 1, 1], + "448-mega": [1, 1, 1], + "475-mega": [0, 2, 2], + "531-mega": [0, 1, 1], + "653": [0, 1, 1], + "654": [0, 1, 1], + "655": [0, 1, 1], + "656": [0, 1, 1], + "657": [0, 1, 1], + "658": [0, 1, 1], + "658-ash": [0, 1, 1], + "664": [0, 1, 1], + "665": [0, 1, 1], + "666-archipelago": [0, 1, 1], + "666-continental": [0, 1, 1], + "666-elegant": [0, 1, 1], + "666-fancy": [0, 1, 1], + "666-garden": [0, 1, 1], + "666-high-plains": [0, 1, 1], + "666-icy-snow": [0, 1, 1], + "666-jungle": [0, 1, 1], + "666-marine": [0, 1, 1], + "666-meadow": [0, 1, 1], + "666-modern": [0, 1, 1], + "666-monsoon": [0, 1, 1], + "666-ocean": [0, 1, 1], + "666-poke-ball": [0, 1, 1], + "666-polar": [0, 1, 1], + "666-river": [0, 1, 1], + "666-sandstorm": [0, 1, 1], + "666-savanna": [0, 1, 1], + "666-sun": [0, 1, 1], + "666-tundra": [0, 1, 1], + "669-red": [0, 2, 2], + "669-blue": [0, 2, 2], + "669-white": [0, 2, 2], + "669-yellow": [0, 2, 2], + "669-orange": [0, 2, 2], + "670-white": [0, 1, 1], + "670-blue": [0, 2, 2], + "670-orange": [0, 1, 1], + "670-red": [0, 1, 1], + "670-yellow": [0, 1, 1], + "671-red": [0, 1, 1], + "671-blue": [0, 1, 1], + "671-yellow": [0, 1, 1], + "671-white": [0, 1, 1], + "671-orange": [0, 1, 1], + "672": [0, 1, 1], + "673": [0, 1, 1], + "676": [0, 1, 1], + "677": [0, 1, 1], + "678-female": [0, 1, 1], + "678": [0, 1, 1], + "682": [0, 1, 1], + "683": [0, 1, 1], + "684": [0, 1, 1], + "685": [0, 1, 1], + "688": [0, 1, 1], + "689": [0, 1, 1], + "690": [0, 1, 1], + "691": [0, 1, 1], + "696": [0, 1, 1], + "697": [0, 1, 1], + "699": [0, 2, 2], + "700": [0, 1, 1], + "702": [0, 1, 1], + "704": [0, 1, 1], + "705": [0, 1, 1], + "706": [0, 1, 1], + "709": [0, 1, 1], + "710": [0, 1, 1], + "711": [1, 1, 1], + "712": [0, 1, 1], + "713": [0, 1, 1], + "715": [0, 1, 1], + "716-active": [0, 1, 1], + "716-neutral": [0, 1, 1], + "717": [0, 1, 1], + "720-unbound": [1, 1, 1], + "720": [1, 1, 1], + "728": [0, 1, 1], + "729": [0, 1, 1], + "730": [0, 1, 1], + "734": [0, 1, 1], + "735": [0, 1, 1], + "742": [0, 2, 2], + "743": [0, 2, 2], + "747": [0, 2, 2], + "748": [0, 1, 1], + "751": [0, 1, 1], + "752": [0, 1, 1], + "753": [0, 1, 1], + "754": [0, 2, 2], + "755": [0, 1, 1], + "756": [0, 1, 1], + "761": [0, 1, 1], + "762": [0, 1, 1], + "763": [0, 1, 1], + "767": [0, 1, 1], + "768": [0, 1, 1], + "771": [0, 1, 1], + "772": [0, 1, 1], + "773-fighting": [0, 1, 1], + "773-psychic": [0, 1, 1], + "773-poison": [0, 1, 1], + "773-ground": [0, 1, 1], + "773-ghost": [0, 1, 1], + "773-steel": [0, 1, 1], + "773-rock": [0, 1, 1], + "773-grass": [0, 1, 1], + "773-dragon": [0, 1, 1], + "773-bug": [0, 1, 1], + "773-ice": [0, 1, 1], + "773-dark": [0, 1, 1], + "773": [0, 1, 1], + "773-fairy": [0, 1, 1], + "773-water": [0, 1, 1], + "773-electric": [0, 1, 1], + "773-flying": [0, 1, 1], + "773-fire": [0, 1, 1], + "776": [0, 2, 2], + "777": [0, 1, 1], + "778-busted": [0, 1, 1], + "778-disguised": [0, 1, 1], + "779": [0, 1, 1], + "789": [1, 1, 1], + "790": [0, 1, 1], + "791": [1, 1, 1], + "792": [0, 1, 1], + "793": [0, 1, 1], + "797": [0, 1, 1], + "798": [0, 1, 1], + "800-dawn-wings": [0, 1, 1], + "800-dusk-mane": [0, 1, 1], + "800-ultra": [0, 1, 1], + "800": [0, 1, 1], + "802": [1, 1, 1], + "803": [0, 1, 1], + "804": [0, 1, 1], + "807": [0, 1, 1], + "808": [0, 1, 1], + "809": [0, 1, 1], + "816": [0, 1, 1], + "817": [0, 1, 1], + "818": [0, 1, 1], + "821": [0, 1, 1], + "822": [0, 1, 1], + "823": [0, 1, 1], + "829": [0, 1, 1], + "830": [0, 1, 1], + "835": [0, 1, 1], + "836": [0, 1, 1], + "850": [0, 1, 1], + "851": [0, 1, 1], + "854": [0, 1, 1], + "855": [0, 1, 1], + "856": [0, 1, 1], + "857": [0, 2, 2], + "858": [0, 1, 1], + "859": [0, 1, 1], + "860": [0, 1, 1], + "861": [0, 1, 1], + "862": [0, 1, 1], + "863": [0, 1, 1], + "864": [0, 1, 1], + "867": [0, 1, 1], + "872": [1, 1, 1], + "873": [1, 1, 1], + "876-female": [0, 1, 1], + "876": [0, 1, 1], + "877-hangry": [1, 1, 1], + "877": [1, 1, 1], + "880": [0, 1, 1], + "881": [0, 1, 1], + "882": [0, 1, 1], + "883": [0, 1, 1], + "884": [0, 1, 1], + "885": [1, 1, 1], + "886": [1, 1, 1], + "887": [1, 1, 1], + "888": [0, 1, 1], + "888-crowned": [0, 1, 1], + "889": [0, 1, 1], + "889-crowned": [0, 1, 1], + "890": [0, 1, 1], + "891": [1, 1, 1], + "892-rapid-strike": [1, 1, 1], + "892": [1, 1, 1], + "894": [0, 1, 1], + "895": [0, 1, 1], + "896": [1, 1, 1], + "897": [1, 1, 1], + "898": [1, 1, 1], + "898-ice": [1, 1, 1], + "898-shadow": [1, 1, 1], + "900": [0, 1, 1], + "901": [0, 1, 1], + "903": [0, 1, 1], + "909": [0, 1, 1], + "910": [0, 2, 2], + "911": [0, 1, 1], + "912": [0, 1, 1], + "913": [0, 1, 1], + "914": [0, 2, 2], + "919": [1, 1, 1], + "920": [1, 1, 1], + "924": [1, 1, 1], + "925-four": [1, 2, 2], + "925-three": [1, 2, 2], + "932": [0, 1, 1], + "933": [0, 1, 1], + "934": [0, 1, 1], + "935": [2, 2, 2], + "936": [2, 2, 2], + "937": [2, 2, 2], + "940": [0, 1, 1], + "941": [0, 1, 1], + "944": [0, 1, 1], + "945": [0, 1, 1], + "948": [0, 1, 1], + "949": [0, 1, 1], + "951": [0, 1, 1], + "952": [0, 2, 1], + "953": [0, 1, 1], + "954": [0, 1, 1], + "957": [1, 1, 1], + "958": [1, 1, 1], + "959": [1, 1, 1], + "962": [1, 1, 1], + "967": [0, 1, 1], + "968": [0, 2, 2], + "969": [0, 1, 1], + "970": [0, 1, 1], + "973": [1, 1, 1], + "974": [0, 1, 1], + "975": [0, 1, 1], + "978-curly": [0, 2, 2], + "978-droopy": [0, 2, 2], + "978-stretchy": [0, 1, 1], + "979": [1, 1, 1], + "981": [0, 1, 1], + "982": [0, 1, 1], + "982-three-segment": [0, 1, 1], + "987": [1, 1, 1], + "988": [0, 1, 1], + "993": [0, 1, 1], + "994": [0, 1, 1], + "995": [0, 1, 1], + "996": [0, 1, 1], + "997": [0, 1, 1], + "998": [0, 1, 1], + "999": [1, 1, 1], + "1000": [1, 1, 1], + "1001": [0, 1, 1], + "1003": [0, 1, 1], + "1004": [0, 1, 1], + "1006": [0, 2, 2], + "1007-apex-build": [0, 2, 2], + "1008-ultimate-mode": [1, 1, 1], + "2026": [0, 1, 1], + "2027": [0, 1, 1], + "2028": [0, 1, 1], + "2052": [0, 1, 1], + "2053": [0, 1, 1], + "2103": [0, 1, 1], + "4052": [0, 1, 1], + "4077": [0, 1, 1], + "4078": [0, 1, 1], + "4079": [0, 1, 1], + "4080": [2, 2, 2], + "4144": [0, 1, 1], + "4145": [0, 1, 1], + "4146": [0, 1, 1], + "4199": [2, 1, 1], + "4222": [0, 1, 1], + "4263": [0, 1, 1], + "4264": [0, 1, 1], + "4562": [0, 1, 1], + "6100": [0, 1, 1], + "6101": [0, 1, 1], + "6215": [0, 1, 1], + "6503": [0, 1, 1], + "6549": [0, 1, 1], + "6570": [0, 1, 1], + "6571": [0, 1, 1], + "6705": [0, 1, 1], + "6706": [0, 1, 1], + "6713": [0, 1, 1], + "female": { + "6215": [0, 1, 1] + } + } +} \ No newline at end of file diff --git a/public/images/pokemon/variant/_masterlist.json b/public/images/pokemon/variant/_masterlist.json index 175b56139a6..ac683d9544e 100644 --- a/public/images/pokemon/variant/_masterlist.json +++ b/public/images/pokemon/variant/_masterlist.json @@ -1813,669 +1813,5 @@ "593": [1, 1, 1], "6215": [0, 1, 1] } - }, - "exp": { - "3-mega": [0, 2, 2], - "6-mega-x": [0, 2, 2], - "6-mega-y": [0, 2, 2], - "80-mega": [0, 1, 1], - "94-mega": [2, 2, 2], - "127-mega": [0, 1, 1], - "130-mega": [0, 1, 1], - "142-mega": [0, 1, 1], - "150-mega-x": [0, 1, 1], - "150-mega-y": [0, 1, 1], - "181-mega": [0, 1, 2], - "212-mega": [1, 1, 2], - "229-mega": [0, 1, 1], - "248-mega": [0, 1, 1], - "257-mega": [0, 1, 1], - "282-mega": [0, 2, 2], - "302-mega": [0, 1, 1], - "303-mega": [0, 1, 1], - "306-mega": [1, 1, 1], - "308-mega": [0, 1, 1], - "310-mega": [0, 1, 1], - "334-mega": [0, 2, 1], - "354-mega": [0, 1, 1], - "359-mega": [0, 1, 1], - "362-mega": [0, 1, 1], - "373-mega": [0, 1, 1], - "376-mega": [0, 1, 1], - "380-mega": [0, 1, 1], - "381-mega": [0, 1, 1], - "382-primal": [0, 1, 1], - "383-primal": [0, 1, 1], - "384-mega": [0, 2, 1], - "428-mega": [0, 1, 1], - "445-mega": [1, 1, 1], - "448-mega": [1, 1, 1], - "475-mega": [0, 2, 2], - "531-mega": [0, 1, 1], - "653": [0, 1, 1], - "654": [0, 1, 1], - "655": [0, 1, 1], - "656": [0, 1, 1], - "657": [0, 1, 1], - "658": [0, 1, 1], - "658-ash": [0, 1, 1], - "664": [0, 1, 1], - "665": [0, 1, 1], - "666-archipelago": [0, 1, 1], - "666-continental": [0, 1, 1], - "666-elegant": [0, 1, 1], - "666-fancy": [0, 1, 1], - "666-garden": [0, 1, 1], - "666-high-plains": [0, 1, 1], - "666-icy-snow": [0, 1, 1], - "666-jungle": [0, 1, 1], - "666-marine": [0, 1, 1], - "666-meadow": [0, 1, 1], - "666-modern": [0, 1, 1], - "666-monsoon": [0, 1, 1], - "666-ocean": [0, 1, 1], - "666-poke-ball": [0, 1, 1], - "666-polar": [0, 1, 1], - "666-river": [0, 1, 1], - "666-sandstorm": [0, 1, 1], - "666-savanna": [0, 1, 1], - "666-sun": [0, 1, 1], - "666-tundra": [0, 1, 1], - "669-red": [0, 2, 2], - "669-blue": [0, 1, 1], - "669-white": [0, 1, 1], - "669-yellow": [0, 1, 1], - "669-orange": [0, 2, 2], - "670-white": [0, 1, 1], - "670-blue": [0, 1, 1], - "670-orange": [0, 1, 1], - "670-red": [0, 1, 1], - "670-yellow": [0, 1, 1], - "671-red": [0, 1, 2], - "671-blue": [0, 1, 2], - "671-yellow": [0, 1, 1], - "671-white": [0, 1, 2], - "671-orange": [0, 1, 2], - "672": [0, 1, 1], - "673": [0, 1, 1], - "676": [0, 1, 1], - "677": [0, 1, 1], - "678-female": [0, 1, 1], - "678": [0, 1, 1], - "682": [0, 1, 1], - "683": [0, 1, 1], - "684": [0, 1, 1], - "685": [0, 1, 1], - "688": [0, 1, 1], - "689": [0, 1, 1], - "690": [0, 1, 1], - "691": [0, 1, 1], - "696": [0, 1, 1], - "697": [0, 1, 1], - "698": [0, 1, 1], - "699": [0, 1, 1], - "700": [0, 1, 1], - "702": [0, 1, 1], - "703": [0, 1, 1], - "704": [0, 1, 1], - "705": [0, 1, 1], - "706": [0, 1, 1], - "708": [0, 1, 1], - "709": [0, 1, 1], - "710": [0, 1, 1], - "711": [1, 1, 1], - "712": [0, 1, 1], - "713": [0, 1, 1], - "714": [0, 1, 1], - "715": [0, 1, 1], - "716-active": [0, 1, 1], - "716-neutral": [0, 1, 1], - "717": [0, 2, 2], - "720-unbound": [1, 1, 1], - "720": [1, 1, 1], - "728": [0, 1, 1], - "729": [0, 1, 1], - "730": [0, 1, 1], - "734": [0, 1, 1], - "735": [0, 1, 1], - "742": [0, 2, 2], - "743": [0, 2, 2], - "747": [0, 2, 2], - "748": [0, 1, 1], - "751": [0, 1, 1], - "752": [0, 1, 1], - "753": [0, 1, 1], - "754": [0, 2, 2], - "755": [0, 1, 1], - "756": [0, 1, 1], - "761": [0, 1, 1], - "762": [0, 1, 1], - "763": [0, 1, 1], - "767": [0, 1, 1], - "768": [0, 1, 1], - "770": [0, 0, 0], - "771": [0, 2, 2], - "772": [0, 1, 1], - "773-fighting": [0, 1, 1], - "773-psychic": [0, 1, 1], - "773-poison": [0, 1, 1], - "773-ground": [0, 1, 1], - "773-ghost": [0, 1, 1], - "773-steel": [0, 1, 1], - "773-rock": [0, 1, 1], - "773-grass": [0, 1, 1], - "773-dragon": [0, 1, 1], - "773-bug": [0, 1, 1], - "773-ice": [0, 1, 1], - "773-dark": [0, 1, 1], - "773": [0, 1, 1], - "773-fairy": [0, 1, 1], - "773-water": [0, 1, 1], - "773-electric": [0, 1, 1], - "773-flying": [0, 1, 1], - "773-fire": [0, 1, 1], - "776": [0, 1, 1], - "777": [0, 1, 1], - "778-busted": [0, 1, 1], - "778-disguised": [0, 1, 1], - "779": [0, 1, 1], - "789": [1, 1, 1], - "790": [0, 1, 1], - "791": [2, 1, 1], - "792": [0, 1, 1], - "793": [0, 2, 2], - "797": [0, 1, 1], - "798": [0, 1, 1], - "800-dawn-wings": [0, 1, 1], - "800-dusk-mane": [0, 1, 1], - "800-ultra": [0, 1, 1], - "800": [0, 1, 1], - "802": [1, 1, 1], - "803": [0, 1, 1], - "804": [0, 1, 1], - "807": [0, 1, 1], - "808": [0, 1, 1], - "809": [0, 1, 1], - "816": [0, 1, 1], - "817": [0, 1, 1], - "818": [1, 1, 1], - "821": [0, 2, 2], - "822": [0, 1, 1], - "823": [0, 1, 1], - "829": [0, 1, 1], - "830": [0, 1, 1], - "835": [0, 1, 1], - "836": [0, 2, 2], - "850": [0, 1, 1], - "851": [0, 1, 1], - "854": [0, 1, 1], - "855": [0, 1, 1], - "856": [0, 1, 1], - "857": [0, 2, 2], - "858": [0, 1, 1], - "859": [0, 1, 1], - "860": [0, 1, 1], - "861": [0, 1, 1], - "862": [0, 1, 1], - "863": [0, 1, 1], - "864": [0, 1, 1], - "867": [0, 1, 1], - "872": [1, 1, 1], - "873": [1, 1, 1], - "876-female": [0, 1, 1], - "876": [0, 1, 1], - "877-hangry": [1, 1, 1], - "877": [1, 1, 1], - "880": [0, 1, 1], - "881": [0, 1, 1], - "882": [0, 2, 1], - "883": [0, 1, 1], - "884": [0, 1, 1], - "885": [1, 1, 1], - "886": [1, 1, 1], - "887": [1, 1, 1], - "888": [0, 1, 1], - "888-crowned": [0, 1, 1], - "889": [0, 1, 1], - "889-crowned": [0, 1, 1], - "890": [0, 2, 1], - "890-eternamax": [0, 1, 1], - "891": [1, 1, 1], - "892-rapid-strike": [1, 1, 1], - "892": [1, 1, 1], - "894": [0, 1, 1], - "895": [0, 1, 1], - "896": [1, 1, 1], - "897": [1, 1, 1], - "898": [1, 1, 1], - "898-ice": [1, 1, 1], - "898-shadow": [1, 1, 1], - "900": [0, 1, 1], - "901": [0, 1, 1], - "903": [0, 1, 1], - "909": [0, 1, 1], - "910": [0, 2, 2], - "911": [0, 2, 2], - "912": [0, 1, 2], - "913": [0, 1, 2], - "914": [0, 2, 1], - "919": [1, 1, 1], - "920": [1, 1, 1], - "924": [1, 1, 1], - "925-four": [1, 2, 2], - "925-three": [1, 2, 2], - "932": [0, 2, 2], - "933": [0, 2, 2], - "934": [0, 1, 1], - "935": [1, 1, 2], - "936": [2, 2, 2], - "937": [2, 2, 2], - "940": [0, 1, 1], - "941": [0, 1, 1], - "944": [0, 1, 1], - "945": [0, 1, 1], - "948": [0, 1, 1], - "949": [0, 1, 1], - "951": [0, 1, 1], - "952": [0, 1, 1], - "953": [0, 1, 1], - "954": [0, 1, 1], - "957": [2, 2, 2], - "958": [2, 2, 2], - "959": [2, 2, 2], - "962": [1, 1, 1], - "967": [0, 1, 1], - "968": [0, 1, 1], - "969": [0, 1, 1], - "970": [0, 1, 1], - "973": [1, 1, 1], - "974": [0, 1, 1], - "975": [0, 1, 1], - "978-curly": [0, 2, 2], - "978-droopy": [0, 2, 2], - "978-stretchy": [0, 2, 2], - "979": [2, 2, 2], - "981": [0, 1, 1], - "982": [0, 1, 1], - "982-three-segment": [0, 1, 1], - "987": [1, 1, 1], - "988": [0, 1, 2], - "993": [0, 1, 1], - "994": [0, 1, 2], - "995": [0, 1, 1], - "996": [0, 1, 1], - "997": [0, 2, 2], - "998": [0, 2, 2], - "999": [2, 1, 1], - "1000": [1, 1, 1], - "1001": [0, 1, 1], - "1003": [0, 1, 1], - "1004": [0, 1, 1], - "1006": [0, 2, 1], - "1007-apex-build": [0, 2, 2], - "1008-ultimate-mode": [1, 1, 1], - "2026": [0, 1, 1], - "2027": [0, 1, 1], - "2028": [0, 1, 1], - "2052": [0, 1, 1], - "2053": [0, 1, 0], - "2103": [0, 1, 1], - "4052": [0, 1, 1], - "4077": [0, 1, 1], - "4078": [0, 1, 1], - "4079": [0, 1, 1], - "4080": [2, 1, 1], - "4144": [0, 1, 1], - "4145": [0, 1, 1], - "4146": [0, 1, 1], - "4199": [2, 1, 1], - "4222": [0, 1, 1], - "4263": [0, 1, 1], - "4264": [0, 1, 1], - "4562": [0, 1, 1], - "6100": [0, 1, 1], - "6101": [0, 1, 1], - "6215": [0, 1, 1], - "6503": [0, 1, 1], - "6549": [0, 1, 1], - "6570": [0, 1, 1], - "6571": [0, 1, 1], - "6705": [0, 1, 1], - "6706": [0, 1, 1], - "6713": [0, 1, 1], - "female": { - "6215": [0, 1, 1] - }, - "back": { - "3-mega": [0, 2, 2], - "6-mega-x": [0, 2, 2], - "6-mega-y": [0, 1, 2], - "80-mega": [0, 1, 1], - "94-mega": [1, 1, 1], - "127-mega": [0, 1, 1], - "130-mega": [0, 1, 1], - "142-mega": [0, 1, 1], - "150-mega-x": [0, 1, 1], - "150-mega-y": [0, 1, 1], - "181-mega": [0, 1, 2], - "212-mega": [1, 2, 2], - "229-mega": [0, 1, 1], - "248-mega": [0, 1, 1], - "257-mega": [0, 1, 1], - "282-mega": [0, 1, 1], - "302-mega": [0, 1, 1], - "303-mega": [0, 1, 1], - "306-mega": [1, 1, 1], - "308-mega": [0, 1, 1], - "310-mega": [0, 1, 1], - "334-mega": [0, 1, 1], - "354-mega": [0, 1, 1], - "359-mega": [0, 1, 1], - "362-mega": [0, 1, 1], - "373-mega": [0, 1, 1], - "376-mega": [0, 1, 1], - "380-mega": [0, 1, 1], - "381-mega": [0, 1, 1], - "382-primal": [0, 1, 1], - "383-primal": [0, 1, 1], - "384-mega": [0, 1, 1], - "428-mega": [0, 1, 1], - "445-mega": [1, 1, 1], - "448-mega": [1, 1, 1], - "475-mega": [0, 2, 2], - "531-mega": [0, 1, 1], - "653": [0, 1, 1], - "654": [0, 1, 1], - "655": [0, 1, 1], - "656": [0, 1, 1], - "657": [0, 1, 1], - "658": [0, 1, 1], - "658-ash": [0, 1, 1], - "664": [0, 1, 1], - "665": [0, 1, 1], - "666-archipelago": [0, 1, 1], - "666-continental": [0, 1, 1], - "666-elegant": [0, 1, 1], - "666-fancy": [0, 1, 1], - "666-garden": [0, 1, 1], - "666-high-plains": [0, 1, 1], - "666-icy-snow": [0, 1, 1], - "666-jungle": [0, 1, 1], - "666-marine": [0, 1, 1], - "666-meadow": [0, 1, 1], - "666-modern": [0, 1, 1], - "666-monsoon": [0, 1, 1], - "666-ocean": [0, 1, 1], - "666-poke-ball": [0, 1, 1], - "666-polar": [0, 1, 1], - "666-river": [0, 1, 1], - "666-sandstorm": [0, 1, 1], - "666-savanna": [0, 1, 1], - "666-sun": [0, 1, 1], - "666-tundra": [0, 1, 1], - "669-red": [0, 2, 2], - "669-blue": [0, 2, 2], - "669-white": [0, 2, 2], - "669-yellow": [0, 2, 2], - "669-orange": [0, 2, 2], - "670-white": [0, 1, 1], - "670-blue": [0, 2, 2], - "670-orange": [0, 1, 1], - "670-red": [0, 1, 1], - "670-yellow": [0, 1, 1], - "671-red": [0, 1, 1], - "671-blue": [0, 1, 1], - "671-yellow": [0, 1, 1], - "671-white": [0, 1, 1], - "671-orange": [0, 1, 1], - "672": [0, 1, 1], - "673": [0, 1, 1], - "676": [0, 1, 1], - "677": [0, 1, 1], - "678-female": [0, 1, 1], - "678": [0, 1, 1], - "682": [0, 1, 1], - "683": [0, 1, 1], - "684": [0, 1, 1], - "685": [0, 1, 1], - "688": [0, 1, 1], - "689": [0, 1, 1], - "690": [0, 1, 1], - "691": [0, 1, 1], - "696": [0, 1, 1], - "697": [0, 1, 1], - "698": [0, 1, 1], - "699": [0, 2, 2], - "700": [0, 1, 1], - "702": [0, 1, 1], - "703": [0, 1, 1], - "704": [0, 1, 1], - "705": [0, 1, 1], - "706": [0, 1, 1], - "708": [0, 1, 1], - "709": [0, 1, 1], - "710": [0, 1, 1], - "711": [1, 1, 1], - "712": [0, 1, 1], - "713": [0, 1, 1], - "714": [0, 1, 1], - "715": [0, 1, 1], - "716-active": [0, 1, 1], - "716-neutral": [0, 1, 1], - "717": [0, 1, 1], - "720-unbound": [1, 1, 1], - "720": [1, 1, 1], - "728": [0, 1, 1], - "729": [0, 1, 1], - "730": [0, 1, 1], - "734": [0, 1, 1], - "735": [0, 1, 1], - "742": [0, 2, 2], - "743": [0, 2, 2], - "747": [0, 2, 2], - "748": [0, 1, 1], - "751": [0, 1, 1], - "752": [0, 1, 1], - "753": [0, 1, 1], - "754": [0, 2, 2], - "755": [0, 1, 1], - "756": [0, 1, 1], - "761": [0, 1, 1], - "762": [0, 1, 1], - "763": [0, 1, 1], - "767": [0, 1, 1], - "768": [0, 1, 1], - "771": [0, 1, 1], - "772": [0, 1, 1], - "773-fighting": [0, 1, 1], - "773-psychic": [0, 1, 1], - "773-poison": [0, 1, 1], - "773-ground": [0, 1, 1], - "773-ghost": [0, 1, 1], - "773-steel": [0, 1, 1], - "773-rock": [0, 1, 1], - "773-grass": [0, 1, 1], - "773-dragon": [0, 1, 1], - "773-bug": [0, 1, 1], - "773-ice": [0, 1, 1], - "773-dark": [0, 1, 1], - "773": [0, 1, 1], - "773-fairy": [0, 1, 1], - "773-water": [0, 1, 1], - "773-electric": [0, 1, 1], - "773-flying": [0, 1, 1], - "773-fire": [0, 1, 1], - "776": [0, 2, 2], - "777": [0, 1, 1], - "778-busted": [0, 1, 1], - "778-disguised": [0, 1, 1], - "779": [0, 1, 1], - "789": [1, 1, 1], - "790": [0, 1, 1], - "791": [1, 1, 1], - "792": [0, 1, 1], - "793": [0, 1, 1], - "797": [0, 1, 1], - "798": [0, 1, 1], - "800-dawn-wings": [0, 1, 1], - "800-dusk-mane": [0, 1, 1], - "800-ultra": [0, 1, 1], - "800": [0, 1, 1], - "802": [1, 1, 1], - "803": [0, 1, 1], - "804": [0, 1, 1], - "807": [0, 1, 1], - "808": [0, 1, 1], - "809": [0, 1, 1], - "816": [0, 1, 1], - "817": [0, 1, 1], - "818": [0, 1, 1], - "821": [0, 1, 1], - "822": [0, 1, 1], - "823": [0, 1, 1], - "829": [0, 1, 1], - "830": [0, 1, 1], - "835": [0, 1, 1], - "836": [0, 1, 1], - "850": [0, 1, 1], - "851": [0, 1, 1], - "854": [0, 1, 1], - "855": [0, 1, 1], - "856": [0, 1, 1], - "857": [0, 2, 2], - "858": [0, 1, 1], - "859": [0, 1, 1], - "860": [0, 1, 1], - "861": [0, 1, 1], - "862": [0, 1, 1], - "863": [0, 1, 1], - "864": [0, 1, 1], - "867": [0, 1, 1], - "872": [1, 1, 1], - "873": [1, 1, 1], - "876-female": [0, 1, 1], - "876": [0, 1, 1], - "877-hangry": [1, 1, 1], - "877": [1, 1, 1], - "880": [0, 1, 1], - "881": [0, 1, 1], - "882": [0, 1, 1], - "883": [0, 1, 1], - "884": [0, 1, 1], - "885": [1, 1, 1], - "886": [1, 1, 1], - "887": [1, 1, 1], - "888": [0, 1, 1], - "888-crowned": [0, 1, 1], - "889": [0, 1, 1], - "889-crowned": [0, 1, 1], - "890": [0, 1, 1], - "891": [1, 1, 1], - "892-rapid-strike": [1, 1, 1], - "892": [1, 1, 1], - "894": [0, 1, 1], - "895": [0, 1, 1], - "896": [1, 1, 1], - "897": [1, 1, 1], - "898": [1, 1, 1], - "898-ice": [1, 1, 1], - "898-shadow": [1, 1, 1], - "900": [0, 1, 1], - "901": [0, 1, 1], - "903": [0, 1, 1], - "909": [0, 1, 1], - "910": [0, 2, 2], - "911": [0, 1, 1], - "912": [0, 1, 1], - "913": [0, 1, 1], - "914": [0, 2, 2], - "919": [1, 1, 1], - "920": [1, 1, 1], - "924": [1, 1, 1], - "925-four": [1, 2, 2], - "925-three": [1, 2, 2], - "932": [0, 1, 1], - "933": [0, 1, 1], - "934": [0, 1, 1], - "935": [2, 2, 2], - "936": [2, 2, 2], - "937": [2, 2, 2], - "940": [0, 1, 1], - "941": [0, 1, 1], - "944": [0, 1, 1], - "945": [0, 1, 1], - "948": [0, 1, 1], - "949": [0, 1, 1], - "951": [0, 1, 1], - "952": [0, 2, 1], - "953": [0, 1, 1], - "954": [0, 1, 1], - "957": [1, 1, 1], - "958": [1, 1, 1], - "959": [1, 1, 1], - "962": [1, 1, 1], - "967": [0, 1, 1], - "968": [0, 2, 2], - "969": [0, 1, 1], - "970": [0, 1, 1], - "973": [1, 1, 1], - "974": [0, 1, 1], - "975": [0, 1, 1], - "978-curly": [0, 2, 2], - "978-droopy": [0, 2, 2], - "978-stretchy": [0, 1, 1], - "979": [1, 1, 1], - "981": [0, 1, 1], - "982": [0, 1, 1], - "982-three-segment": [0, 1, 1], - "987": [1, 1, 1], - "988": [0, 1, 1], - "993": [0, 1, 1], - "994": [0, 1, 1], - "995": [0, 1, 1], - "996": [0, 1, 1], - "997": [0, 1, 1], - "998": [0, 1, 1], - "999": [1, 1, 1], - "1000": [1, 1, 1], - "1001": [0, 1, 1], - "1003": [0, 1, 1], - "1004": [0, 1, 1], - "1006": [0, 2, 2], - "1007-apex-build": [0, 2, 2], - "1008-ultimate-mode": [1, 1, 1], - "2026": [0, 1, 1], - "2027": [0, 1, 1], - "2028": [0, 1, 1], - "2052": [0, 1, 1], - "2053": [0, 1, 1], - "2103": [0, 1, 1], - "4052": [0, 1, 1], - "4077": [0, 1, 1], - "4078": [0, 1, 1], - "4079": [0, 1, 1], - "4080": [2, 2, 2], - "4144": [0, 1, 1], - "4145": [0, 1, 1], - "4146": [0, 1, 1], - "4199": [2, 1, 1], - "4222": [0, 1, 1], - "4263": [0, 1, 1], - "4264": [0, 1, 1], - "4562": [0, 1, 1], - "6100": [0, 1, 1], - "6101": [0, 1, 1], - "6215": [0, 1, 1], - "6503": [0, 1, 1], - "6549": [0, 1, 1], - "6570": [0, 1, 1], - "6571": [0, 1, 1], - "6705": [0, 1, 1], - "6706": [0, 1, 1], - "6713": [0, 1, 1], - "female": { - "6215": [0, 1, 1] - } - } } } \ No newline at end of file diff --git a/public/images/pokemon/variant/exp/698.json b/public/images/pokemon/variant/exp/698.json deleted file mode 100644 index daf9b8c6f84..00000000000 --- a/public/images/pokemon/variant/exp/698.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "1": { - "cbaa84": "44827c", - "b3747e": "4b7465", - "eeffbf": "cdffb5", - "dcffb2": "8eeab9", - "ffbfca": "43bf8d", - "b7ffb2": "72d8ce", - "fff2b2": "9bffa9", - "85b4cc": "cf755d", - "a6e1ff": "efab87", - "101010": "101010", - "cacaca": "cacaca", - "537180": "b04f4b", - "2eaeec": "4dc796", - "1f75a0": "29988e", - "fdfdfd": "fdfdfd", - "d197a1": "d197a1", - "ffdce6": "ffdce6", - "217aa6": "7f99e1", - "30b2f2": "b5dcff", - "f9f9f9": "e6e3b4", - "c0c0c0": "d7cca0" - }, - "2": { - "cbaa84": "cc78db", - "b3747e": "c452a6", - "eeffbf": "ed9ff2", - "dcffb2": "d7bbf4", - "ffbfca": "faccff", - "b7ffb2": "dceeff", - "fff2b2": "eb88b9", - "85b4cc": "654a8a", - "a6e1ff": "936daa", - "101010": "101010", - "cacaca": "cacaca", - "537180": "392d65", - "2eaeec": "ad4e6e", - "1f75a0": "8d2656", - "fdfdfd": "fdfdfd", - "d197a1": "d197a1", - "ffdce6": "ffdce6", - "217aa6": "efaa51", - "30b2f2": "ffd169", - "f9f9f9": "373453", - "c0c0c0": "282747" - } -} \ No newline at end of file diff --git a/public/images/pokemon/variant/exp/703.json b/public/images/pokemon/variant/exp/703.json deleted file mode 100644 index c024feb1b30..00000000000 --- a/public/images/pokemon/variant/exp/703.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "1": { - "535763": "292638", - "306090": "c35b2a", - "c3c7d3": "68638e", - "88aacc": "e67c37", - "fefefe": "fefefe", - "a3a7b3": "4d496b", - "737783": "37344e", - "101010": "101010", - "bbddff": "ffa633", - "1fbfdf": "ff9b44", - "5f6060": "e6ac60", - "fcfefe": "ffeed6", - "bfbbbb": "ffd3a1" - }, - "2": { - "535763": "976ba9", - "306090": "a03c69", - "c3c7d3": "faecff", - "88aacc": "e25493", - "fefefe": "ffe2ee", - "a3a7b3": "e4cdf9", - "737783": "cca1db", - "101010": "101010", - "bbddff": "f591bd", - "1fbfdf": "de5f8e", - "5f6060": "5a3d84", - "fcfefe": "a473bf", - "bfbbbb": "8359a7" - } -} \ No newline at end of file diff --git a/public/images/pokemon/variant/exp/708.json b/public/images/pokemon/variant/exp/708.json deleted file mode 100644 index b32bbb79cd9..00000000000 --- a/public/images/pokemon/variant/exp/708.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "1": { - "101010": "101010", - "2b2a3a": "722023", - "603d2b": "36384f", - "215738": "4d362e", - "48484a": "a14743", - "c18760": "7c808c", - "3fa76c": "907f76", - "915e45": "575a6a", - "0b0c0b": "0b0c0b", - "da585b": "5996d2", - "ff8c8f": "87d1ff" - }, - "2": { - "101010": "101010", - "2b2a3a": "6f5f80", - "603d2b": "31161d", - "215738": "a94079", - "48484a": "9c92a4", - "c18760": "7e5658", - "3fa76c": "da7ea8", - "915e45": "56323a", - "0b0c0b": "0b0c0b", - "da585b": "e18933", - "ff8c8f": "ffc875" - } -} \ No newline at end of file diff --git a/public/images/pokemon/variant/exp/714.json b/public/images/pokemon/variant/exp/714.json deleted file mode 100644 index 018366c5381..00000000000 --- a/public/images/pokemon/variant/exp/714.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "1": { - "6a3f73": "731338", - "bd70cc": "a42c54", - "101010": "101010", - "bfacbf": "7047ba", - "8e5499": "8e1d4b", - "f2daf2": "8d7be3", - "404040": "202558", - "665c66": "2f386b", - "ccb43d": "ff8a58", - "f8f8f8": "8d7be3", - "595959": "2f386b", - "ffe14c": "ffc182", - "000000": "101010" - }, - "2": { - "6a3f73": "5f151c", - "bd70cc": "c24430", - "101010": "101010", - "bfacbf": "f9e8dd", - "8e5499": "882c27", - "f2daf2": "f8f8f8", - "404040": "5b1922", - "665c66": "7c2928", - "ccb43d": "33d8d0", - "f8f8f8": "f8f8f8", - "595959": "7c2928", - "ffe14c": "49ffcd", - "000000": "101010" - } -} \ No newline at end of file diff --git a/public/images/pokemon/variant/exp/back/698.json b/public/images/pokemon/variant/exp/back/698.json deleted file mode 100644 index af193c3bc0c..00000000000 --- a/public/images/pokemon/variant/exp/back/698.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "1": { - "b3747e": "4b7465", - "ffbfca": "43bf8d", - "fff2b2": "9bffa9", - "537180": "b04f4b", - "a6e1ff": "efab87", - "101010": "101010", - "85b4cc": "cf755d", - "217aa6": "7f99e1", - "30b2f2": "b5dcff", - "fdfdfd": "fdfdfd", - "c0c0c0": "d7cca0", - "cacaca": "cacaca", - "cbaa84": "44827c", - "dcffb2": "8eeab9", - "eeffbf": "cdffb5", - "b7ffb2": "72d8ce" - }, - "2": { - "b3747e": "c452a6", - "ffbfca": "faccff", - "fff2b2": "eb88b9", - "537180": "392d65", - "a6e1ff": "936daa", - "101010": "101010", - "85b4cc": "654a8a", - "217aa6": "efaa51", - "30b2f2": "ffd169", - "fdfdfd": "fdfdfd", - "c0c0c0": "282747", - "cacaca": "cacaca", - "cbaa84": "cc78db", - "dcffb2": "d7bbf4", - "eeffbf": "ed9ff2", - "b7ffb2": "dceeff" - } -} \ No newline at end of file diff --git a/public/images/pokemon/variant/exp/back/703.json b/public/images/pokemon/variant/exp/back/703.json deleted file mode 100644 index 376abd466d2..00000000000 --- a/public/images/pokemon/variant/exp/back/703.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "1": { - "306090": "c35b2a", - "88aacc": "e67c37", - "fefefe": "fefefe", - "535763": "292638", - "a3a7b3": "4d496b", - "737783": "37344e", - "bbddff": "ffa633", - "101010": "101010", - "5f6060": "e6ac60", - "bfbbbb": "ffd3a1", - "fcfefe": "ffeed6" - }, - "2": { - "306090": "a03c69", - "88aacc": "e25493", - "fefefe": "ffe2ee", - "535763": "976ba9", - "a3a7b3": "e4cdf9", - "737783": "cca1db", - "bbddff": "f591bd", - "101010": "101010", - "5f6060": "5a3d84", - "bfbbbb": "8359a7", - "fcfefe": "a473bf" - } -} \ No newline at end of file diff --git a/public/images/pokemon/variant/exp/back/708.json b/public/images/pokemon/variant/exp/back/708.json deleted file mode 100644 index 7d41d6d24b0..00000000000 --- a/public/images/pokemon/variant/exp/back/708.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "1": { - "1a1a1c": "1a1a1c", - "686665": "646085", - "103222": "802c26", - "221b17": "221b17", - "090606": "090606", - "4ab38e": "a14743", - "38956f": "a14743", - "ab9074": "7c808c", - "4e4e4e": "494e5b", - "917860": "7c808c", - "424244": "2b303c", - "78604c": "575a6a", - "6b5442": "40435a", - "5f4939": "36384f", - "4f2a09": "292929", - "6c4513": "36384f", - "353638": "353638" - }, - "2": { - "1a1a1c": "1a1a1c", - "686665": "ccc3cf", - "103222": "a94079", - "221b17": "221b17", - "090606": "090606", - "4ab38e": "da7ea8", - "38956f": "da7ea8", - "ab9074": "7e5658", - "4e4e4e": "9c92a4", - "917860": "7e5658", - "424244": "6f5f80", - "78604c": "56323a", - "6b5442": "47232b", - "5f4939": "31161d", - "4f2a09": "250e14", - "6c4513": "31161d", - "353638": "57496b" - } -} \ No newline at end of file diff --git a/public/images/pokemon/variant/exp/back/714.json b/public/images/pokemon/variant/exp/back/714.json deleted file mode 100644 index 22933e71338..00000000000 --- a/public/images/pokemon/variant/exp/back/714.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "1": { - "101010": "101010", - "6a3f73": "500a25", - "bd70cc": "a42c54", - "8e5499": "8e1d4b", - "404040": "202558", - "595959": "2f386b", - "bfacbf": "8d7be3", - "665c66": "2f386b", - "f2daf2": "8d7be3" - }, - "2": { - "101010": "101010", - "6a3f73": "5f151c", - "bd70cc": "c24430", - "8e5499": "882c27", - "404040": "5b1922", - "595959": "7c2928", - "bfacbf": "f9e8dd", - "665c66": "7c2928", - "f2daf2": "f9e8dd" - } -} \ No newline at end of file diff --git a/scripts/find_sprite_variant_mismatches.py b/scripts/find_sprite_variant_mismatches.py index 483695fdb66..b26058c2de3 100644 --- a/scripts/find_sprite_variant_mismatches.py +++ b/scripts/find_sprite_variant_mismatches.py @@ -22,6 +22,9 @@ from typing import Literal as L MASTERLIST_PATH = os.path.join( os.path.dirname(os.path.dirname(__file__)), "public", "images", "pokemon", "variant", "_masterlist.json" ) +EXP_MASTERLIST_PATH = os.path.join( + os.path.dirname(os.path.dirname(__file__)), "public", "images", "pokemon", "variant", "_exp_masterlist.json" +) DEFAULT_OUTPUT_PATH = "sprite-mismatches.csv" @@ -93,6 +96,7 @@ if __name__ == "__main__": help=f"The path to a file to save the output file. If not specified, will write to {DEFAULT_OUTPUT_PATH}.", ) p.add_argument("--masterlist", default=MASTERLIST_PATH, help=f"The path to the masterlist file to validate. Defaults to {MASTERLIST_PATH}.") + p.add_argument("--exp-masterlist", default=EXP_MASTERLIST_PATH, help=f"The path to the exp masterlist file to validate against. Defaults to {EXP_MASTERLIST_PATH}.") args = p.parse_args() mismatches = make_mismatch_sprite_list(args.masterlist) write_mismatch_csv(args.output, mismatches) diff --git a/src/account.ts b/src/account.ts index 96ce32714bb..7baa7d10a1a 100644 --- a/src/account.ts +++ b/src/account.ts @@ -1,11 +1,11 @@ import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; import type { UserInfo } from "#app/@types/UserInfo"; -import { bypassLogin } from "./battle-scene"; -import * as Utils from "./utils"; +import { bypassLogin } from "#app/battle-scene"; +import { randomString } from "#app/utils"; export let loggedInUser: UserInfo | null = null; // This is a random string that is used to identify the client session - unique per session (tab or window) so that the game will only save on the one that the server is expecting -export const clientSessionId = Utils.randomString(32); +export const clientSessionId = randomString(32); export function initLoggedInUser(): void { loggedInUser = { diff --git a/src/battle-scene.ts b/src/battle-scene.ts index f676ba63306..dd983f2b397 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -5,9 +5,20 @@ import { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon"; import type { PokemonSpeciesFilter } from "#app/data/pokemon-species"; import type PokemonSpecies from "#app/data/pokemon-species"; import { allSpecies, getPokemonSpecies } from "#app/data/pokemon-species"; -import type { Constructor } from "#app/utils"; -import { isNullOrUndefined, randSeedInt } from "#app/utils"; -import * as Utils from "#app/utils"; +import { + fixedInt, + deepMergeObjects, + getIvsFromId, + randSeedInt, + getEnumValues, + randomString, + NumberHolder, + shiftCharCodes, + formatMoney, + isNullOrUndefined, + BooleanHolder, + type Constructor, +} from "#app/utils"; import type { Modifier, ModifierPredicate, TurnHeldItemTransferModifier } from "./modifier/modifier"; import { ConsumableModifier, @@ -106,8 +117,8 @@ import PokemonInfoContainer from "#app/ui/pokemon-info-container"; import { biomeDepths, getBiomeName } from "#app/data/balance/biomes"; import { SceneBase } from "#app/scene-base"; import CandyBar from "#app/ui/candy-bar"; -import type { Variant, VariantSet } from "#app/data/variant"; -import { variantColorCache, variantData } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; +import { variantData, clearVariantData } from "#app/sprites/variant"; import type { Localizable } from "#app/interfaces/locales"; import Overrides from "#app/overrides"; import { InputsController } from "#app/inputs-controller"; @@ -170,6 +181,8 @@ import { StatusEffect } from "#enums/status-effect"; import { initGlobalScene } from "#app/global-scene"; import { ShowAbilityPhase } from "#app/phases/show-ability-phase"; import { HideAbilityPhase } from "#app/phases/hide-ability-phase"; +import { expSpriteKeys } from "./sprites/sprite-keys"; +import { hasExpSprite } from "./sprites/sprite-utils"; import { timedEventManager } from "./global-event-manager"; export const bypassLogin = import.meta.env.VITE_BYPASS_LOGIN === "1"; @@ -182,8 +195,6 @@ const OPP_IVS_OVERRIDE_VALIDATED: number[] = ( export const startingWave = Overrides.STARTING_WAVE_OVERRIDE || 1; -const expSpriteKeys: string[] = []; - export let starterColors: StarterColors; interface StarterColors { [key: string]: [string, string]; @@ -409,7 +420,7 @@ export default class BattleScene extends SceneBase { } const variant = atlasPath.includes("variant/") || /_[0-3]$/.test(atlasPath); if (experimental) { - experimental = this.hasExpSprite(key); + experimental = hasExpSprite(key); } if (variant) { atlasPath = atlasPath.replace("variant/", ""); @@ -421,35 +432,6 @@ export default class BattleScene extends SceneBase { ); } - /** - * Load the variant assets for the given sprite and stores them in {@linkcode variantColorCache} - */ - public async loadPokemonVariantAssets(spriteKey: string, fileRoot: string, variant?: Variant): Promise { - const useExpSprite = this.experimentalSprites && this.hasExpSprite(spriteKey); - if (useExpSprite) { - fileRoot = `exp/${fileRoot}`; - } - let variantConfig = variantData; - fileRoot.split("/").map(p => (variantConfig ? (variantConfig = variantConfig[p]) : null)); - const variantSet = variantConfig as VariantSet; - - return new Promise(resolve => { - if (variantSet && variant !== undefined && variantSet[variant] === 1) { - if (variantColorCache.hasOwnProperty(spriteKey)) { - return resolve(); - } - this.cachedFetch(`./images/pokemon/variant/${fileRoot}.json`) - .then(res => res.json()) - .then(c => { - variantColorCache[spriteKey] = c; - resolve(); - }); - } else { - resolve(); - } - }); - } - async preload() { if (DEBUG_RNG) { const originalRealInRange = Phaser.Math.RND.realInRange; @@ -762,7 +744,7 @@ export default class BattleScene extends SceneBase { } this.playTimeTimer = this.time.addEvent({ - delay: Utils.fixedInt(1000), + delay: fixedInt(1000), repeat: -1, callback: () => { if (this.gameData) { @@ -783,53 +765,36 @@ export default class BattleScene extends SceneBase { } async initExpSprites(): Promise { - if (expSpriteKeys.length) { + if (expSpriteKeys.size > 0) { return; } this.cachedFetch("./exp-sprites.json") .then(res => res.json()) .then(keys => { if (Array.isArray(keys)) { - expSpriteKeys.push(...keys); + for (const key of keys) { + expSpriteKeys.add(key); + } } Promise.resolve(); }); } + /** + * Initialize the variant data. + * If experimental sprites are enabled, their entries are replaced via this method. + */ async initVariantData(): Promise { - for (const key of Object.keys(variantData)) { - delete variantData[key]; + clearVariantData(); + const otherVariantData = await this.cachedFetch("./images/pokemon/variant/_masterlist.json").then(r => r.json()); + for (const k of Object.keys(otherVariantData)) { + variantData[k] = otherVariantData[k]; } - await this.cachedFetch("./images/pokemon/variant/_masterlist.json") - .then(res => res.json()) - .then(v => { - for (const k of Object.keys(v)) { - variantData[k] = v[k]; - } - if (this.experimentalSprites) { - const expVariantData = variantData["exp"]; - const traverseVariantData = (keys: string[]) => { - let variantTree = variantData; - let expTree = expVariantData; - keys.map((k: string, i: number) => { - if (i < keys.length - 1) { - variantTree = variantTree[k]; - expTree = expTree[k]; - } else if (variantTree.hasOwnProperty(k) && expTree.hasOwnProperty(k)) { - if (["back", "female"].includes(k)) { - traverseVariantData(keys.concat(k)); - } else { - variantTree[k] = expTree[k]; - } - } - }); - }; - for (const ek of Object.keys(expVariantData)) { - traverseVariantData([ek]); - } - } - Promise.resolve(); - }); + if (!this.experimentalSprites) { + return; + } + const expVariantData = await this.cachedFetch("./images/pokemon/variant/_exp_masterlist.json").then(r => r.json()); + deepMergeObjects(variantData, expVariantData); } cachedFetch(url: string, init?: RequestInit): Promise { @@ -843,48 +808,15 @@ export default class BattleScene extends SceneBase { return fetch(url, init); } - initStarterColors(): Promise { - return new Promise(resolve => { - if (starterColors) { - return resolve(); - } - - this.cachedFetch("./starter-colors.json") - .then(res => res.json()) - .then(sc => { - starterColors = {}; - for (const key of Object.keys(sc)) { - starterColors[key] = sc[key]; - } - - resolve(); - }); - }); - } - - hasExpSprite(key: string): boolean { - const keyMatch = /^pkmn__?(back__)?(shiny__)?(female__)?(\d+)(\-.*?)?(?:_[1-3])?$/g.exec(key); - if (!keyMatch) { - return false; + async initStarterColors(): Promise { + if (starterColors) { + return; } - - let k = keyMatch[4]!; - if (keyMatch[2]) { - k += "s"; + const sc = await this.cachedFetch("./starter-colors.json").then(res => res.json()); + starterColors = {}; + for (const key of Object.keys(sc)) { + starterColors[key] = sc[key]; } - if (keyMatch[1]) { - k += "b"; - } - if (keyMatch[3]) { - k += "f"; - } - if (keyMatch[5]) { - k += keyMatch[5]; - } - if (!expSpriteKeys.includes(k)) { - return false; - } - return true; } public getPlayerParty(): PlayerPokemon[] { @@ -1067,7 +999,7 @@ export default class BattleScene extends SceneBase { } if (boss && !dataSource) { - const secondaryIvs = Utils.getIvsFromId(Utils.randSeedInt(4294967296)); + const secondaryIvs = getIvsFromId(randSeedInt(4294967296)); for (let s = 0; s < pokemon.ivs.length; s++) { pokemon.ivs[s] = Math.round( @@ -1140,7 +1072,7 @@ export default class BattleScene extends SceneBase { container.add(icon); - if (pokemon.isFusion()) { + if (pokemon.isFusion(true)) { const fusionIcon = this.add.sprite(0, 0, pokemon.getFusionIconAtlasKey(ignoreOverride)); fusionIcon.setName("sprite-fusion-icon"); fusionIcon.setOrigin(0.5, 0); @@ -1226,7 +1158,7 @@ export default class BattleScene extends SceneBase { * Generates a random number using the current battle's seed * * This calls {@linkcode Battle.randSeedInt}({@linkcode range}, {@linkcode min}) in `src/battle.ts` - * which calls {@linkcode Utils.randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts` + * which calls {@linkcode randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts` * * @param range How large of a range of random numbers to choose from. If {@linkcode range} <= 1, returns {@linkcode min} * @param min The minimum integer to pick, default `0` @@ -1251,7 +1183,7 @@ export default class BattleScene extends SceneBase { this.lockModifierTiers = false; this.pokeballCounts = Object.fromEntries( - Utils.getEnumValues(PokeballType) + getEnumValues(PokeballType) .filter(p => p <= PokeballType.MASTER_BALL) .map(t => [t, 0]), ); @@ -1283,7 +1215,7 @@ export default class BattleScene extends SceneBase { // Reset RNG after end of game or save & quit. // This needs to happen after clearing this.currentBattle or the seed will be affected by the last wave played - this.setSeed(Overrides.SEED_OVERRIDE || Utils.randomString(24)); + this.setSeed(Overrides.SEED_OVERRIDE || randomString(24)); console.log("Seed:", this.seed); this.resetSeed(); @@ -1324,7 +1256,7 @@ export default class BattleScene extends SceneBase { ...allSpecies, ...allMoves, ...allAbilities, - ...Utils.getEnumValues(ModifierPoolType) + ...getEnumValues(ModifierPoolType) .map(mpt => getModifierPoolForType(mpt)) .flatMap(mp => Object.values(mp) @@ -1364,7 +1296,7 @@ export default class BattleScene extends SceneBase { } getDoubleBattleChance(newWaveIndex: number, playerField: PlayerPokemon[]) { - const doubleChance = new Utils.NumberHolder(newWaveIndex % 10 === 0 ? 32 : 8); + const doubleChance = new NumberHolder(newWaveIndex % 10 === 0 ? 32 : 8); this.applyModifiers(DoubleBattleChanceBoosterModifier, true, doubleChance); for (const p of playerField) { applyAbAttrs(DoubleBattleChanceAbAttr, p, null, false, doubleChance); @@ -1421,7 +1353,7 @@ export default class BattleScene extends SceneBase { if (trainerConfigs[trainerType].doubleOnly) { doubleTrainer = true; } else if (trainerConfigs[trainerType].hasDouble) { - doubleTrainer = !Utils.randSeedInt(this.getDoubleBattleChance(newWaveIndex, playerField)); + doubleTrainer = !randSeedInt(this.getDoubleBattleChance(newWaveIndex, playerField)); // Add a check that special trainers can't be double except for tate and liza - they should use the normal double chance if ( trainerConfigs[trainerType].trainerTypeDouble && @@ -1432,7 +1364,7 @@ export default class BattleScene extends SceneBase { } const variant = doubleTrainer ? TrainerVariant.DOUBLE - : Utils.randSeedInt(2) + : randSeedInt(2) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT; newTrainer = trainerData !== undefined ? trainerData.toTrainer() : new Trainer(trainerType, variant); @@ -1450,7 +1382,7 @@ export default class BattleScene extends SceneBase { if (double === undefined && newWaveIndex > 1) { if (newBattleType === BattleType.WILD && !this.gameMode.isWaveFinal(newWaveIndex)) { - newDouble = !Utils.randSeedInt(this.getDoubleBattleChance(newWaveIndex, playerField)); + newDouble = !randSeedInt(this.getDoubleBattleChance(newWaveIndex, playerField)); } else if (newBattleType === BattleType.TRAINER) { newDouble = newTrainer?.variant === TrainerVariant.DOUBLE; } @@ -1638,7 +1570,7 @@ export default class BattleScene extends SceneBase { scale: scale, x: (defaultWidth - scaledWidth) / 2, y: defaultHeight - scaledHeight, - duration: !instant ? Utils.fixedInt(Math.abs(this.field.scale - scale) * 200) : 0, + duration: !instant ? fixedInt(Math.abs(this.field.scale - scale) * 200) : 0, ease: "Sine.easeInOut", onComplete: () => resolve(), }); @@ -1735,12 +1667,12 @@ export default class BattleScene extends SceneBase { case Species.SQUAWKABILLY: case Species.TATSUGIRI: case Species.PALDEA_TAUROS: - return Utils.randSeedInt(species.forms.length); + return randSeedInt(species.forms.length); case Species.PIKACHU: if (this.currentBattle?.battleType === BattleType.TRAINER && this.currentBattle?.waveIndex < 30) { return 0; // Ban Cosplay and Partner Pika from Trainers before wave 30 } - return Utils.randSeedInt(8); + return randSeedInt(8); case Species.EEVEE: if ( this.currentBattle?.battleType === BattleType.TRAINER && @@ -1749,22 +1681,22 @@ export default class BattleScene extends SceneBase { ) { return 0; // No Partner Eevee for Wave 12 Preschoolers } - return Utils.randSeedInt(2); + return randSeedInt(2); case Species.FROAKIE: case Species.FROGADIER: case Species.GRENINJA: if (this.currentBattle?.battleType === BattleType.TRAINER && !isEggPhase) { return 0; // Don't give trainers Battle Bond Greninja, Froakie or Frogadier } - return Utils.randSeedInt(2); + return randSeedInt(2); case Species.URSHIFU: - return Utils.randSeedInt(2); + return randSeedInt(2); case Species.ZYGARDE: - return Utils.randSeedInt(4); + return randSeedInt(4); case Species.MINIOR: - return Utils.randSeedInt(7); + return randSeedInt(7); case Species.ALCREMIE: - return Utils.randSeedInt(9); + return randSeedInt(9); case Species.MEOWSTIC: case Species.INDEEDEE: case Species.BASCULEGION: @@ -1795,7 +1727,7 @@ export default class BattleScene extends SceneBase { if (this.gameMode.hasMysteryEncounters && !isEggPhase) { return 1; // Wandering form } - return Utils.randSeedInt(species.forms.length); + return randSeedInt(species.forms.length); } if (ignoreArena) { @@ -1804,7 +1736,7 @@ export default class BattleScene extends SceneBase { case Species.WORMADAM: case Species.ROTOM: case Species.LYCANROC: - return Utils.randSeedInt(species.forms.length); + return randSeedInt(species.forms.length); } return 0; } @@ -1816,7 +1748,7 @@ export default class BattleScene extends SceneBase { let ret = false; this.executeWithSeedOffset( () => { - ret = !Utils.randSeedInt(2); + ret = !randSeedInt(2); }, 0, this.seed.toString(), @@ -1828,7 +1760,7 @@ export default class BattleScene extends SceneBase { let ret = 0; this.executeWithSeedOffset( () => { - ret = Utils.randSeedInt(8) * 5; + ret = randSeedInt(8) * 5; }, 0, this.seed.toString(), @@ -1857,7 +1789,7 @@ export default class BattleScene extends SceneBase { isBoss = waveIndex % 10 === 0 || (this.gameMode.hasRandomBosses && - Utils.randSeedInt(100) < Math.min(Math.max(Math.ceil((waveIndex - 250) / 50), 0) * 2, 30)); + randSeedInt(100) < Math.min(Math.max(Math.ceil((waveIndex - 250) / 50), 0) * 2, 30)); }, waveIndex << 2); } if (!isBoss) { @@ -1884,7 +1816,7 @@ export default class BattleScene extends SceneBase { const infectedIndexes: number[] = []; const spread = (index: number, spreadTo: number) => { const partyMember = party[index + spreadTo]; - if (!partyMember.pokerus && !Utils.randSeedInt(10)) { + if (!partyMember.pokerus && !randSeedInt(10)) { partyMember.pokerus = true; infectedIndexes.push(index + spreadTo); } @@ -1910,7 +1842,7 @@ export default class BattleScene extends SceneBase { resetSeed(waveIndex?: number): void { const wave = waveIndex || this.currentBattle?.waveIndex || 0; - this.waveSeed = Utils.shiftCharCodes(this.seed, wave); + this.waveSeed = shiftCharCodes(this.seed, wave); Phaser.Math.RND.sow([this.waveSeed]); console.log("Wave Seed:", this.waveSeed, wave); this.rngCounter = 0; @@ -1929,7 +1861,7 @@ export default class BattleScene extends SceneBase { const tempRngOffset = this.rngOffset; const tempRngSeedOverride = this.rngSeedOverride; const state = Phaser.Math.RND.state(); - Phaser.Math.RND.sow([Utils.shiftCharCodes(seedOverride || this.seed, offset)]); + Phaser.Math.RND.sow([shiftCharCodes(seedOverride || this.seed, offset)]); this.rngCounter = 0; this.rngOffset = offset; this.rngSeedOverride = seedOverride || ""; @@ -2074,7 +2006,7 @@ export default class BattleScene extends SceneBase { if (this.money === undefined) { return; } - const formattedMoney = Utils.formatMoney(this.moneyFormat, this.money); + const formattedMoney = formatMoney(this.moneyFormat, this.money); this.moneyText.setText(i18next.t("battleScene:moneyOwned", { formattedMoney })); this.fieldUI.moveAbove(this.moneyText, this.luckText); if (forceVisible) { @@ -2231,12 +2163,12 @@ export default class BattleScene extends SceneBase { ), ] : allSpecies.filter(s => s.isCatchable()); - return filteredSpecies[Utils.randSeedInt(filteredSpecies.length)]; + return filteredSpecies[randSeedInt(filteredSpecies.length)]; } generateRandomBiome(waveIndex: number): Biome { const relWave = waveIndex % 250; - const biomes = Utils.getEnumValues(Biome).filter(b => b !== Biome.TOWN && b !== Biome.END); + const biomes = getEnumValues(Biome).filter(b => b !== Biome.TOWN && b !== Biome.END); const maxDepth = biomeDepths[Biome.END][0] - 2; const depthWeights = new Array(maxDepth + 1) .fill(null) @@ -2248,7 +2180,7 @@ export default class BattleScene extends SceneBase { biomeThresholds.push(totalWeight); } - const randInt = Utils.randSeedInt(totalWeight); + const randInt = randSeedInt(totalWeight); for (let i = 0; i < biomes.length; i++) { if (randInt < biomeThresholds[i]) { @@ -2256,7 +2188,7 @@ export default class BattleScene extends SceneBase { } } - return biomes[Utils.randSeedInt(biomes.length)]; + return biomes[randSeedInt(biomes.length)]; } isBgmPlaying(): boolean { @@ -2441,7 +2373,7 @@ export default class BattleScene extends SceneBase { this.bgmResumeTimer.destroy(); } if (resumeBgm) { - this.bgmResumeTimer = this.time.delayedCall(pauseDuration || Utils.fixedInt(sound.totalDuration * 1000), () => { + this.bgmResumeTimer = this.time.delayedCall(pauseDuration || fixedInt(sound.totalDuration * 1000), () => { this.resumeBgm(); this.bgmResumeTimer = null; }); @@ -3034,7 +2966,7 @@ export default class BattleScene extends SceneBase { const args: unknown[] = []; if (modifier instanceof PokemonHpRestoreModifier) { if (!(modifier as PokemonHpRestoreModifier).fainted) { - const hpRestoreMultiplier = new Utils.NumberHolder(1); + const hpRestoreMultiplier = new NumberHolder(1); this.applyModifiers(HealingBoosterModifier, true, hpRestoreMultiplier); args.push(hpRestoreMultiplier.value); } else { @@ -3042,7 +2974,7 @@ export default class BattleScene extends SceneBase { } } else if (modifier instanceof FusePokemonModifier) { args.push(this.getPokemonById(modifier.fusePokemonId) as PlayerPokemon); - } else if (modifier instanceof RememberMoveModifier && !Utils.isNullOrUndefined(cost)) { + } else if (modifier instanceof RememberMoveModifier && !isNullOrUndefined(cost)) { args.push(cost); } @@ -3111,7 +3043,7 @@ export default class BattleScene extends SceneBase { itemLost = true, ): boolean { const source = itemModifier.pokemonId ? itemModifier.getPokemon() : null; - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); if (source && source.isPlayer() !== target.isPlayer()) { applyAbAttrs(BlockItemTheftAbAttr, source, cancelled); @@ -3180,7 +3112,7 @@ export default class BattleScene extends SceneBase { canTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, transferQuantity = 1): boolean { const mod = itemModifier.clone() as PokemonHeldItemModifier; const source = mod.pokemonId ? mod.getPokemon() : null; - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); if (source && source.isPlayer() !== target.isPlayer()) { applyAbAttrs(BlockItemTheftAbAttr, source, cancelled); @@ -3274,7 +3206,7 @@ export default class BattleScene extends SceneBase { } let count = 0; for (let c = 0; c < chances; c++) { - if (!Utils.randSeedInt(this.gameMode.getEnemyModifierChance(isBoss))) { + if (!randSeedInt(this.gameMode.getEnemyModifierChance(isBoss))) { count++; } } @@ -3450,7 +3382,7 @@ export default class BattleScene extends SceneBase { if (mods.length < 1) { return mods; } - const rand = Utils.randSeedInt(mods.length); + const rand = randSeedInt(mods.length); return [mods[rand], ...shuffleModifiers(mods.filter((_, i) => i !== rand))]; }; modifiers = shuffleModifiers(modifiers); @@ -3676,7 +3608,7 @@ export default class BattleScene extends SceneBase { */ initFinalBossPhaseTwo(pokemon: Pokemon): void { if (pokemon instanceof EnemyPokemon && pokemon.isBoss() && !pokemon.formIndex && pokemon.bossSegmentIndex < 1) { - this.fadeOutBgm(Utils.fixedInt(2000), false); + this.fadeOutBgm(fixedInt(2000), false); this.ui.showDialogue( battleSpecDialogue[BattleSpec.FINAL_BOSS].firstStageWin, pokemon.species.name, @@ -3779,7 +3711,7 @@ export default class BattleScene extends SceneBase { if (Overrides.XP_MULTIPLIER_OVERRIDE !== null) { expMultiplier = Overrides.XP_MULTIPLIER_OVERRIDE; } - const pokemonExp = new Utils.NumberHolder(expValue * expMultiplier); + const pokemonExp = new NumberHolder(expValue * expMultiplier); this.applyModifiers(PokemonExpBoosterModifier, true, partyMember, pokemonExp); partyMemberExp.push(Math.floor(pokemonExp.value)); } @@ -3928,7 +3860,7 @@ export default class BattleScene extends SceneBase { while (i < this.mysteryEncounterSaveData.queuedEncounters.length && !!encounter) { const candidate = this.mysteryEncounterSaveData.queuedEncounters[i]; const forcedChance = candidate.spawnPercent; - if (Utils.randSeedInt(100) < forcedChance) { + if (randSeedInt(100) < forcedChance) { encounter = allMysteryEncounters[candidate.type]; } @@ -3961,7 +3893,7 @@ export default class BattleScene extends SceneBase { } const totalWeight = tierWeights.reduce((a, b) => a + b); - const tierValue = Utils.randSeedInt(totalWeight); + const tierValue = randSeedInt(totalWeight); const commonThreshold = totalWeight - tierWeights[0]; const greatThreshold = totalWeight - tierWeights[0] - tierWeights[1]; const ultraThreshold = totalWeight - tierWeights[0] - tierWeights[1] - tierWeights[2]; @@ -4053,7 +3985,7 @@ export default class BattleScene extends SceneBase { console.log("No Mystery Encounters found, falling back to Mysterious Challengers."); return allMysteryEncounters[MysteryEncounterType.MYSTERIOUS_CHALLENGERS]; } - encounter = availableEncounters[Utils.randSeedInt(availableEncounters.length)]; + encounter = availableEncounters[randSeedInt(availableEncounters.length)]; // New encounter object to not dirty flags encounter = new MysteryEncounter(encounter); encounter.populateDialogueTokensFromRequirements(); diff --git a/src/battle.ts b/src/battle.ts index 367c52568dc..fb5af223b8f 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -1,6 +1,14 @@ import { globalScene } from "#app/global-scene"; import type { Command } from "./ui/command-ui-handler"; -import * as Utils from "./utils"; +import { + randomString, + getEnumValues, + NumberHolder, + randSeedInt, + shiftCharCodes, + randSeedItem, + randInt, +} from "#app/utils"; import Trainer, { TrainerVariant } from "./field/trainer"; import type { GameMode } from "./game-mode"; import { MoneyMultiplierModifier, PokemonHeldItemModifier } from "./modifier/modifier"; @@ -99,7 +107,7 @@ export default class Battle { public postBattleLoot: PokemonHeldItemModifier[] = []; public escapeAttempts = 0; public lastMove: Moves; - public battleSeed: string = Utils.randomString(16, true); + public battleSeed: string = randomString(16, true); private battleSeedState: string | null = null; public moneyScattered = 0; /** Primarily for double battles, keeps track of last enemy and player pokemon that triggered its ability or used a move */ @@ -181,8 +189,8 @@ export default class Battle { incrementTurn(): void { this.turn++; - this.turnCommands = Object.fromEntries(Utils.getEnumValues(BattlerIndex).map(bt => [bt, null])); - this.preTurnCommands = Object.fromEntries(Utils.getEnumValues(BattlerIndex).map(bt => [bt, null])); + this.turnCommands = Object.fromEntries(getEnumValues(BattlerIndex).map(bt => [bt, null])); + this.preTurnCommands = Object.fromEntries(getEnumValues(BattlerIndex).map(bt => [bt, null])); this.battleSeedState = null; } @@ -211,7 +219,7 @@ export default class Battle { } pickUpScatteredMoney(): void { - const moneyAmount = new Utils.NumberHolder(globalScene.currentBattle.moneyScattered); + const moneyAmount = new NumberHolder(globalScene.currentBattle.moneyScattered); globalScene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); if (globalScene.arena.getTag(ArenaTagType.HAPPY_HOUR)) { @@ -448,7 +456,7 @@ export default class Battle { } /** - * Generates a random number using the current battle's seed. Calls {@linkcode Utils.randSeedInt} + * Generates a random number using the current battle's seed. Calls {@linkcode randSeedInt} * @param range How large of a range of random numbers to choose from. If {@linkcode range} <= 1, returns {@linkcode min} * @param min The minimum integer to pick, default `0` * @returns A random integer between {@linkcode min} and ({@linkcode min} + {@linkcode range} - 1) @@ -463,12 +471,12 @@ export default class Battle { if (this.battleSeedState) { Phaser.Math.RND.state(this.battleSeedState); } else { - Phaser.Math.RND.sow([Utils.shiftCharCodes(this.battleSeed, this.turn << 6)]); + Phaser.Math.RND.sow([shiftCharCodes(this.battleSeed, this.turn << 6)]); console.log("Battle Seed:", this.battleSeed); } globalScene.rngCounter = this.rngCounter++; globalScene.rngSeedOverride = this.battleSeed; - const ret = Utils.randSeedInt(range, min); + const ret = randSeedInt(range, min); this.battleSeedState = Phaser.Math.RND.state(); Phaser.Math.RND.state(state); globalScene.rngCounter = tempRngCounter; @@ -554,19 +562,19 @@ export function getRandomTrainerFunc( seedOffset = 0, ): GetTrainerFunc { return () => { - const rand = Utils.randSeedInt(trainerPool.length); + const rand = randSeedInt(trainerPool.length); const trainerTypes: TrainerType[] = []; globalScene.executeWithSeedOffset(() => { for (const trainerPoolEntry of trainerPool) { - const trainerType = Array.isArray(trainerPoolEntry) ? Utils.randSeedItem(trainerPoolEntry) : trainerPoolEntry; + const trainerType = Array.isArray(trainerPoolEntry) ? randSeedItem(trainerPoolEntry) : trainerPoolEntry; trainerTypes.push(trainerType); } }, seedOffset); let trainerGender = TrainerVariant.DEFAULT; if (randomGender) { - trainerGender = Utils.randInt(2) === 0 ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT; + trainerGender = randInt(2) === 0 ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT; } /* 1/3 chance for evil team grunts to be double battles */ @@ -585,7 +593,7 @@ export function getRandomTrainerFunc( const isEvilTeamGrunt = evilTeamGrunts.includes(trainerTypes[rand]); if (trainerConfigs[trainerTypes[rand]].hasDouble && isEvilTeamGrunt) { - return new Trainer(trainerTypes[rand], Utils.randInt(3) === 0 ? TrainerVariant.DOUBLE : trainerGender); + return new Trainer(trainerTypes[rand], randInt(3) === 0 ? TrainerVariant.DOUBLE : trainerGender); } return new Trainer(trainerTypes[rand], trainerGender); @@ -608,7 +616,7 @@ export const classicFixedBattles: FixedBattleConfigs = { [ClassicFixedBossWaves.TOWN_YOUNGSTER]: new FixedBattleConfig() .setBattleType(BattleType.TRAINER) .setGetTrainerFunc( - () => new Trainer(TrainerType.YOUNGSTER, Utils.randSeedInt(2) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT), + () => new Trainer(TrainerType.YOUNGSTER, randSeedInt(2) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT), ), [ClassicFixedBossWaves.RIVAL_1]: new FixedBattleConfig() .setBattleType(BattleType.TRAINER) diff --git a/src/data/ability.ts b/src/data/ability.ts index f8c9b4cb8fe..3e32a624f9f 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -2,8 +2,7 @@ import type { EnemyPokemon, PokemonMove } from "../field/pokemon"; import type Pokemon from "../field/pokemon"; import { HitResult, MoveResult, PlayerPokemon } from "../field/pokemon"; import { PokemonType } from "#enums/pokemon-type"; -import type { Constructor } from "#app/utils"; -import * as Utils from "../utils"; +import { BooleanHolder, NumberHolder, toDmgValue, isNullOrUndefined, randSeedItem, randSeedInt, type Constructor } from "#app/utils"; import { getPokemonNameWithAffix } from "../messages"; import type { Weather } from "#app/data/weather"; import type { BattlerTag } from "./battler-tags"; @@ -196,7 +195,7 @@ export abstract class AbAttr { * @param args - Extra args passed to the function. Handled by child classes. * @see {@linkcode canApply} */ - apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder | null, args: any[]): void {} + apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder | null, args: any[]): void {} getTriggerMessage(_pokemon: Pokemon, _abilityName: string, ..._args: any[]): string | null { return null; @@ -230,7 +229,7 @@ export class BlockRecoilDamageAttr extends AbAttr { super(false); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } @@ -251,10 +250,10 @@ export class DoubleBattleChanceAbAttr extends AbAttr { /** * Increases the chance of a double battle occurring - * @param args [0] {@linkcode Utils.NumberHolder} for double battle chance + * @param args [0] {@linkcode NumberHolder} for double battle chance */ - override apply(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, _cancelled: Utils.BooleanHolder, args: any[]): void { - const doubleBattleChance = args[0] as Utils.NumberHolder; + override apply(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, _cancelled: BooleanHolder, args: any[]): void { + const doubleBattleChance = args[0] as NumberHolder; // This is divided because the chance is generated as a number from 0 to doubleBattleChance.value using Utils.randSeedInt // A double battle will initiate if the generated number is 0 doubleBattleChance.value = doubleBattleChance.value / 4; @@ -299,7 +298,7 @@ export class PostTeraFormChangeStatChangeAbAttr extends AbAttr { this.stages = stages; } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder | null, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder | null, args: any[]): void { const statStageChangePhases: StatStageChangePhase[] = []; if (!simulated) { @@ -331,7 +330,7 @@ export class ClearWeatherAbAttr extends AbAttr { return globalScene.arena.canSetWeather(WeatherType.NONE); } - public override apply(pokemon: Pokemon, passive: boolean, simulated:boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + public override apply(pokemon: Pokemon, passive: boolean, simulated:boolean, cancelled: BooleanHolder, args: any[]): void { if (!simulated) { globalScene.arena.trySetWeather(WeatherType.NONE, pokemon); } @@ -357,7 +356,7 @@ export class ClearTerrainAbAttr extends AbAttr { return globalScene.arena.canSetTerrain(TerrainType.NONE); } - public override apply(pokemon: Pokemon, passive: boolean, simulated:boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + public override apply(pokemon: Pokemon, passive: boolean, simulated:boolean, cancelled: BooleanHolder, args: any[]): void { if (!simulated) { globalScene.arena.trySetTerrain(TerrainType.NONE, true, pokemon); } @@ -373,7 +372,7 @@ export class PreDefendAbAttr extends AbAttr { simulated: boolean, attacker: Pokemon, move: Move | null, - cancelled: Utils.BooleanHolder | null, + cancelled: BooleanHolder | null, args: any[]): boolean { return true; } @@ -384,19 +383,19 @@ export class PreDefendAbAttr extends AbAttr { simulated: boolean, attacker: Pokemon, move: Move | null, - cancelled: Utils.BooleanHolder | null, + cancelled: BooleanHolder | null, args: any[], ): void {} } export class PreDefendFullHpEndureAbAttr extends PreDefendAbAttr { - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move | null, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move | null, cancelled: BooleanHolder | null, args: any[]): boolean { return pokemon.isFullHp() && pokemon.getMaxHp() > 1 //Checks if pokemon has wonder_guard (which forces 1hp) - && (args[0] as Utils.NumberHolder).value >= pokemon.hp; //Damage >= hp + && (args[0] as NumberHolder).value >= pokemon.hp; //Damage >= hp } - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { if (!simulated) { pokemon.addTag(BattlerTagType.STURDY, 1); } @@ -404,7 +403,7 @@ export class PreDefendFullHpEndureAbAttr extends PreDefendAbAttr { } export class BlockItemTheftAbAttr extends AbAttr { - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } @@ -422,11 +421,11 @@ export class StabBoostAbAttr extends AbAttr { } override canApply(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - return (args[0] as Utils.NumberHolder).value > 1; + return (args[0] as NumberHolder).value > 1; } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.NumberHolder).value += 0.5; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + (args[0] as NumberHolder).value += 0.5; } } @@ -441,12 +440,12 @@ export class ReceivedMoveDamageMultiplierAbAttr extends PreDefendAbAttr { this.damageMultiplier = damageMultiplier; } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { return this.condition(pokemon, attacker, move); } - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.NumberHolder).value = Utils.toDmgValue((args[0] as Utils.NumberHolder).value * this.damageMultiplier); + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { + (args[0] as NumberHolder).value = toDmgValue((args[0] as NumberHolder).value * this.damageMultiplier); } } @@ -465,11 +464,11 @@ export class AlliedFieldDamageReductionAbAttr extends PreDefendAbAttr { /** * Handles the damage reduction * @param args - * - `[0]` {@linkcode Utils.NumberHolder} - The damage being dealt + * - `[0]` {@linkcode NumberHolder} - The damage being dealt */ - override applyPreDefend(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, _attacker: Pokemon, _move: Move, _cancelled: Utils.BooleanHolder, args: any[]): void { - const damage = args[0] as Utils.NumberHolder; - damage.value = Utils.toDmgValue(damage.value * this.damageMultiplier); + override applyPreDefend(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, _attacker: Pokemon, _move: Move, _cancelled: BooleanHolder, args: any[]): void { + const damage = args[0] as NumberHolder; + damage.value = toDmgValue(damage.value * this.damageMultiplier); } } @@ -496,7 +495,7 @@ export class TypeImmunityAbAttr extends PreDefendAbAttr { this.condition = condition ?? null; } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { return ![ MoveTarget.BOTH_SIDES, MoveTarget.ENEMY_SIDE, MoveTarget.USER_SIDE ].includes(move.moveTarget) && attacker !== pokemon && attacker.getMoveType(move) === this.immuneType; } @@ -506,12 +505,12 @@ export class TypeImmunityAbAttr extends PreDefendAbAttr { * @param passive - Whether the ability is passive. * @param attacker {@linkcode Pokemon} The attacking Pokemon. * @param move {@linkcode Move} The attacking move. - * @param cancelled {@linkcode Utils.BooleanHolder} - A holder for a boolean value indicating if the move was cancelled. - * @param args [0] {@linkcode Utils.NumberHolder} gets set to 0 if move is immuned by an ability. + * @param cancelled {@linkcode BooleanHolder} - A holder for a boolean value indicating if the move was cancelled. + * @param args [0] {@linkcode NumberHolder} gets set to 0 if move is immuned by an ability. * @param args [1] - Whether the move is simulated. */ - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.NumberHolder).value = 0; + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { + (args[0] as NumberHolder).value = 0; } getImmuneType(): PokemonType | null { @@ -528,7 +527,7 @@ export class AttackTypeImmunityAbAttr extends TypeImmunityAbAttr { super(immuneType, condition); } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { return move.category !== MoveCategory.STATUS && !move.hasAttr(NeutralDamageAgainstFlyingTypeMultiplierAttr) && super.canApplyPreDefend(pokemon, passive, simulated, attacker, move, cancelled, args); } @@ -538,7 +537,7 @@ export class AttackTypeImmunityAbAttr extends TypeImmunityAbAttr { * Type immunity abilities that do not give additional benefits (HP recovery, stat boosts, etc) are not immune to status moves of the type * Example: Levitate */ - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { // this is a hacky way to fix the Levitate/Thousand Arrows interaction, but it works for now... super.applyPreDefend(pokemon, passive, simulated, attacker, move, cancelled, args); } @@ -549,16 +548,16 @@ export class TypeImmunityHealAbAttr extends TypeImmunityAbAttr { super(immuneType); } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { return super.canApplyPreDefend(pokemon, passive, simulated, attacker, move, cancelled, args); } - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { super.applyPreDefend(pokemon, passive, simulated, attacker, move, cancelled, args); if (!pokemon.isFullHp() && !simulated) { const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name; globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), - Utils.toDmgValue(pokemon.getMaxHp() / 4), i18next.t("abilityTriggers:typeImmunityHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }), true)); + toDmgValue(pokemon.getMaxHp() / 4), i18next.t("abilityTriggers:typeImmunityHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }), true)); cancelled.value = true; // Suppresses "No Effect" message } } @@ -575,11 +574,11 @@ class TypeImmunityStatStageChangeAbAttr extends TypeImmunityAbAttr { this.stages = stages; } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { return super.canApplyPreDefend(pokemon, passive, simulated, attacker, move, cancelled, args); } - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { super.applyPreDefend(pokemon, passive, simulated, attacker, move, cancelled, args); cancelled.value = true; // Suppresses "No Effect" message if (!simulated) { @@ -599,11 +598,11 @@ class TypeImmunityAddBattlerTagAbAttr extends TypeImmunityAbAttr { this.turnCount = turnCount; } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { return super.canApplyPreDefend(pokemon, passive, simulated, attacker, move, cancelled, args); } - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { super.applyPreDefend(pokemon, passive, simulated, attacker, move, cancelled, args); cancelled.value = true; // Suppresses "No Effect" message if (!simulated) { @@ -617,16 +616,16 @@ export class NonSuperEffectiveImmunityAbAttr extends TypeImmunityAbAttr { super(null, condition); } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { const modifierValue = args.length > 0 - ? (args[0] as Utils.NumberHolder).value + ? (args[0] as NumberHolder).value : pokemon.getAttackTypeEffectiveness(attacker.getMoveType(move), attacker, undefined, undefined, move); return move instanceof AttackMove && modifierValue < 2; } - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; // Suppresses "No Effect" message - (args[0] as Utils.NumberHolder).value = 0; + (args[0] as NumberHolder).value = 0; } getTriggerMessage(pokemon: Pokemon, abilityName: string, ...args: any[]): string { @@ -644,9 +643,9 @@ export class NonSuperEffectiveImmunityAbAttr extends TypeImmunityAbAttr { */ export class FullHpResistTypeAbAttr extends PreDefendAbAttr { - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move | null, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move | null, cancelled: BooleanHolder | null, args: any[]): boolean { const typeMultiplier = args[0]; - return (typeMultiplier && typeMultiplier instanceof Utils.NumberHolder) && !(move && move.hasAttr(FixedDamageAttr)) && pokemon.isFullHp() && typeMultiplier.value > 0.5; + return (typeMultiplier && typeMultiplier instanceof NumberHolder) && !(move && move.hasAttr(FixedDamageAttr)) && pokemon.isFullHp() && typeMultiplier.value > 0.5; } /** @@ -665,7 +664,7 @@ export class FullHpResistTypeAbAttr extends PreDefendAbAttr { simulated: boolean, attacker: Pokemon, move: Move | null, - cancelled: Utils.BooleanHolder | null, + cancelled: BooleanHolder | null, args: any[]): void { const typeMultiplier = args[0]; typeMultiplier.value = 0.5; @@ -704,11 +703,11 @@ export class PostDefendAbAttr extends AbAttr { export class FieldPriorityMoveImmunityAbAttr extends PreDefendAbAttr { - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { return !(move.moveTarget === MoveTarget.USER || move.moveTarget === MoveTarget.NEAR_ALLY) && move.getPriority(attacker) > 0 && !move.isMultiTarget(); } - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } @@ -743,11 +742,11 @@ export class MoveImmunityAbAttr extends PreDefendAbAttr { this.immuneCondition = immuneCondition; } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { return this.immuneCondition(pokemon, attacker, move); } - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } @@ -768,13 +767,13 @@ export class WonderSkinAbAttr extends PreDefendAbAttr { super(false); } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { - const moveAccuracy = args[0] as Utils.NumberHolder; + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { + const moveAccuracy = args[0] as NumberHolder; return move.category === MoveCategory.STATUS && moveAccuracy.value >= 50; } - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { - const moveAccuracy = args[0] as Utils.NumberHolder; + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { + const moveAccuracy = args[0] as NumberHolder; moveAccuracy.value = 50; } } @@ -789,11 +788,11 @@ export class MoveImmunityStatStageChangeAbAttr extends MoveImmunityAbAttr { this.stages = stages; } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { return !simulated && super.canApplyPreDefend(pokemon, passive, simulated, attacker, move, cancelled, args); } - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { super.applyPreDefend(pokemon, passive, simulated, attacker, move, cancelled, args); globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ this.stat ], this.stages)); } @@ -855,7 +854,7 @@ export class PostDefendStatStageChangeAbAttr extends PostDefendAbAttr { if (this.allOthers) { const ally = pokemon.getAlly(); - const otherPokemon = !Utils.isNullOrUndefined(ally) ? pokemon.getOpponents().concat([ ally ]) : pokemon.getOpponents(); + const otherPokemon = !isNullOrUndefined(ally) ? pokemon.getOpponents().concat([ ally ]) : pokemon.getOpponents(); for (const other of otherPokemon) { globalScene.unshiftPhase(new StatStageChangePhase((other).getBattlerIndex(), false, [ this.stat ], this.stages)); } @@ -1090,8 +1089,8 @@ export class PostDefendContactDamageAbAttr extends PostDefendAbAttr { } override applyPostDefend(pokemon: Pokemon, _passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, _hitResult: HitResult, _args: any[]): void { - attacker.damageAndUpdate(Utils.toDmgValue(attacker.getMaxHp() * (1 / this.damageRatio)), { result: HitResult.INDIRECT }); - attacker.turnData.damageTaken += Utils.toDmgValue(attacker.getMaxHp() * (1 / this.damageRatio)); + attacker.damageAndUpdate(toDmgValue(attacker.getMaxHp() * (1 / this.damageRatio)), { result: HitResult.INDIRECT }); + attacker.turnData.damageTaken += toDmgValue(attacker.getMaxHp() * (1 / this.damageRatio)); } override getTriggerMessage(pokemon: Pokemon, abilityName: string, ..._args: any[]): string { @@ -1291,16 +1290,16 @@ export class MoveEffectChanceMultiplierAbAttr extends AbAttr { override canApply(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { const exceptMoves = [ Moves.ORDER_UP, Moves.ELECTRO_SHOT ]; - return !((args[0] as Utils.NumberHolder).value <= 0 || exceptMoves.includes((args[1] as Move).id)); + return !((args[0] as NumberHolder).value <= 0 || exceptMoves.includes((args[1] as Move).id)); } /** - * @param args [0]: {@linkcode Utils.NumberHolder} Move additional effect chance. Has to be higher than or equal to 0. + * @param args [0]: {@linkcode NumberHolder} Move additional effect chance. Has to be higher than or equal to 0. * [1]: {@linkcode Moves } Move used by the ability user. */ - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.NumberHolder).value *= this.chanceMultiplier; - (args[0] as Utils.NumberHolder).value = Math.min((args[0] as Utils.NumberHolder).value, 100); + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + (args[0] as NumberHolder).value *= this.chanceMultiplier; + (args[0] as NumberHolder).value = Math.min((args[0] as NumberHolder).value, 100); } } @@ -1314,15 +1313,15 @@ export class IgnoreMoveEffectsAbAttr extends PreDefendAbAttr { super(showAbility); } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move | null, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { - return (args[0] as Utils.NumberHolder).value > 0; + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move | null, cancelled: BooleanHolder | null, args: any[]): boolean { + return (args[0] as NumberHolder).value > 0; } /** - * @param args [0]: {@linkcode Utils.NumberHolder} Move additional effect chance. + * @param args [0]: {@linkcode NumberHolder} Move additional effect chance. */ - override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.NumberHolder).value = 0; + override applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder, args: any[]): void { + (args[0] as NumberHolder).value = 0; } } @@ -1337,7 +1336,7 @@ export class FieldPreventExplosiveMovesAbAttr extends AbAttr { pokemon: Pokemon, passive: boolean, simulated: boolean, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, args: any[], ): void { cancelled.value = true; @@ -1349,7 +1348,7 @@ export class FieldPreventExplosiveMovesAbAttr extends AbAttr { * If this ability cannot stack, a BooleanHolder can be used to prevent this from stacking. * @see {@link applyFieldStatMultiplierAbAttrs} * @see {@link applyFieldStat} - * @see {@link Utils.BooleanHolder} + * @see {@link BooleanHolder} */ export class FieldMultiplyStatAbAttr extends AbAttr { private stat: Stat; @@ -1364,7 +1363,7 @@ export class FieldMultiplyStatAbAttr extends AbAttr { this.canStack = canStack; } - canApplyFieldStat(pokemon: Pokemon, passive: boolean, simulated: boolean, stat: Stat, statValue: Utils.NumberHolder, checkedPokemon: Pokemon, hasApplied: Utils.BooleanHolder, args: any[]): boolean { + canApplyFieldStat(pokemon: Pokemon, passive: boolean, simulated: boolean, stat: Stat, statValue: NumberHolder, checkedPokemon: Pokemon, hasApplied: BooleanHolder, args: any[]): boolean { return this.canStack || !hasApplied.value && this.stat === stat && checkedPokemon.getAbilityAttrs(FieldMultiplyStatAbAttr).every(attr => (attr as FieldMultiplyStatAbAttr).stat !== stat); } @@ -1374,12 +1373,12 @@ export class FieldMultiplyStatAbAttr extends AbAttr { * @param pokemon {@linkcode Pokemon} the Pokemon using this ability * @param passive {@linkcode boolean} unused * @param stat {@linkcode Stat} the type of the checked stat - * @param statValue {@linkcode Utils.NumberHolder} the value of the checked stat + * @param statValue {@linkcode NumberHolder} the value of the checked stat * @param checkedPokemon {@linkcode Pokemon} the Pokemon this ability is targeting - * @param hasApplied {@linkcode Utils.BooleanHolder} whether or not another multiplier has been applied to this stat + * @param hasApplied {@linkcode BooleanHolder} whether or not another multiplier has been applied to this stat * @param args {any[]} unused */ - applyFieldStat(pokemon: Pokemon, passive: boolean, simulated: boolean, stat: Stat, statValue: Utils.NumberHolder, checkedPokemon: Pokemon, hasApplied: Utils.BooleanHolder, args: any[]): void { + applyFieldStat(pokemon: Pokemon, passive: boolean, simulated: boolean, stat: Stat, statValue: NumberHolder, checkedPokemon: Pokemon, hasApplied: BooleanHolder, args: any[]): void { statValue.value *= this.multiplier; hasApplied.value = true; } @@ -1401,10 +1400,10 @@ export class MoveTypeChangeAbAttr extends PreAttackAbAttr { // TODO: Decouple this into two attributes (type change / power boost) override applyPreAttack(pokemon: Pokemon, passive: boolean, simulated: boolean, defender: Pokemon, move: Move, args: any[]): void { - if (args[0] && args[0] instanceof Utils.NumberHolder) { + if (args[0] && args[0] instanceof NumberHolder) { args[0].value = this.newType; } - if (args[1] && args[1] instanceof Utils.NumberHolder) { + if (args[1] && args[1] instanceof NumberHolder) { args[1].value *= this.powerMultiplier; } } @@ -1482,12 +1481,12 @@ export class AddSecondStrikeAbAttr extends PreAttackAbAttr { * @param defender n/a * @param move the {@linkcode Move} used by the ability source * @param args Additional arguments: - * - `[0]` the number of strikes this move currently has ({@linkcode Utils.NumberHolder}) - * - `[1]` the damage multiplier for the current strike ({@linkcode Utils.NumberHolder}) + * - `[0]` the number of strikes this move currently has ({@linkcode NumberHolder}) + * - `[1]` the damage multiplier for the current strike ({@linkcode NumberHolder}) */ override applyPreAttack(pokemon: Pokemon, passive: boolean, simulated: boolean, defender: Pokemon, move: Move, args: any[]): void { - const hitCount = args[0] as Utils.NumberHolder; - const multiplier = args[1] as Utils.NumberHolder; + const hitCount = args[0] as NumberHolder; + const multiplier = args[1] as NumberHolder; if (hitCount?.value) { hitCount.value += 1; } @@ -1527,8 +1526,8 @@ export class DamageBoostAbAttr extends PreAttackAbAttr { * @param args Utils.NumberHolder as damage */ override applyPreAttack(pokemon: Pokemon, passive: boolean, simulated: boolean, defender: Pokemon, move: Move, args: any[]): void { - const power = args[0] as Utils.NumberHolder; - power.value = Utils.toDmgValue(power.value * this.damageMultiplier); + const power = args[0] as NumberHolder; + power.value = toDmgValue(power.value * this.damageMultiplier); } } @@ -1547,7 +1546,7 @@ export class MovePowerBoostAbAttr extends VariableMovePowerAbAttr { } override applyPreAttack(pokemon: Pokemon, passive: boolean, simulated: boolean, defender: Pokemon, move: Move, args: any[]): void { - (args[0] as Utils.NumberHolder).value *= this.powerMultiplier; + (args[0] as NumberHolder).value *= this.powerMultiplier; } } @@ -1590,7 +1589,7 @@ export class VariableMovePowerBoostAbAttr extends VariableMovePowerAbAttr { override applyPreAttack(pokemon: Pokemon, passive: boolean, simulated: boolean, defender: Pokemon, move: Move, args: any[]): void { const multiplier = this.mult(pokemon, defender, move); - (args[0] as Utils.NumberHolder).value *= multiplier; + (args[0] as NumberHolder).value *= multiplier; } } @@ -1619,7 +1618,7 @@ export class FieldMovePowerBoostAbAttr extends AbAttr { applyPreAttack(pokemon: Pokemon | null, passive: boolean | null, simulated: boolean, defender: Pokemon | null, move: Move, args: any[]): void { if (this.condition(pokemon, defender, move)) { - (args[0] as Utils.NumberHolder).value *= this.powerMultiplier; + (args[0] as NumberHolder).value *= this.powerMultiplier; } } } @@ -1682,7 +1681,7 @@ export class StatMultiplierAbAttr extends AbAttr { _passive: boolean, simulated: boolean, stat: BattleStat, - statValue: Utils.NumberHolder, + statValue: NumberHolder, args: any[]): boolean { const move = (args[0] as Move); return stat === this.stat && (!this.condition || this.condition(pokemon, null, move)); @@ -1693,7 +1692,7 @@ export class StatMultiplierAbAttr extends AbAttr { _passive: boolean, simulated: boolean, stat: BattleStat, - statValue: Utils.NumberHolder, + statValue: NumberHolder, args: any[]): void { statValue.value *= this.multiplier; } @@ -1766,13 +1765,13 @@ export class AllyStatMultiplierAbAttr extends AbAttr { * @param passive - unused * @param _simulated - Whether the ability is being simulated (unused) * @param _stat - The type of the checked {@linkcode Stat} (unused) - * @param statValue - {@linkcode Utils.NumberHolder} containing the value of the checked stat + * @param statValue - {@linkcode NumberHolder} containing the value of the checked stat * @param _checkedPokemon - The {@linkcode Pokemon} this ability is targeting (unused) * @param _ignoreAbility - Whether the ability should be ignored if possible * @param _args - unused * @returns `true` if this changed the checked stat, `false` otherwise. */ - applyAllyStat(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, _stat: BattleStat, statValue: Utils.NumberHolder, _checkedPokemon: Pokemon, _ignoreAbility: boolean, _args: any[]) { + applyAllyStat(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, _stat: BattleStat, statValue: NumberHolder, _checkedPokemon: Pokemon, _ignoreAbility: boolean, _args: any[]) { statValue.value *= this.multiplier; } @@ -1782,13 +1781,13 @@ export class AllyStatMultiplierAbAttr extends AbAttr { * @param passive - unused * @param simulated - Whether the ability is being simulated (unused) * @param stat - The type of the checked {@linkcode Stat} - * @param statValue - {@linkcode Utils.NumberHolder} containing the value of the checked stat + * @param statValue - {@linkcode NumberHolder} containing the value of the checked stat * @param checkedPokemon - The {@linkcode Pokemon} this ability is targeting (unused) * @param ignoreAbility - Whether the ability should be ignored if possible * @param args - unused * @returns `true` if this can apply to the checked stat, `false` otherwise. */ - canApplyAllyStat(pokemon: Pokemon, _passive: boolean, simulated: boolean, stat: BattleStat, statValue: Utils.NumberHolder, checkedPokemon: Pokemon, ignoreAbility: boolean, args: any[]): boolean { + canApplyAllyStat(pokemon: Pokemon, _passive: boolean, simulated: boolean, stat: BattleStat, statValue: NumberHolder, checkedPokemon: Pokemon, ignoreAbility: boolean, args: any[]): boolean { return stat === this.stat && !(ignoreAbility && this.ignorable); } } @@ -2220,8 +2219,8 @@ export class IgnoreOpponentStatStagesAbAttr extends AbAttr { * @param _cancelled n/a * @param args A BooleanHolder that represents whether or not to ignore a stat's stat changes */ - override apply(_pokemon: Pokemon, _passive: boolean, simulated: boolean, _cancelled: Utils.BooleanHolder, args: any[]): void { - (args[1] as Utils.BooleanHolder).value = true; + override apply(_pokemon: Pokemon, _passive: boolean, simulated: boolean, _cancelled: BooleanHolder, args: any[]): void { + (args[1] as BooleanHolder).value = true; } } @@ -2230,7 +2229,7 @@ export class IntimidateImmunityAbAttr extends AbAttr { super(false); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } @@ -2254,7 +2253,7 @@ export class PostIntimidateStatStageChangeAbAttr extends AbAttr { this.overwrites = !!overwrites; } - override apply(pokemon: Pokemon, passive: boolean, simulated:boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated:boolean, cancelled: BooleanHolder, args: any[]): void { if (!simulated) { globalScene.pushPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), false, this.stats, this.stages)); } @@ -2371,6 +2370,18 @@ export class PostSummonMessageAbAttr extends PostSummonAbAttr { } } +/** + * Removes illusions when a Pokemon is summoned. + */ +export class PostSummonRemoveIllusionAbAttr extends PostSummonAbAttr { + applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { + for (const pokemon of globalScene.getField(true)) { + pokemon.breakIllusion(); + } + return true; + } +} + export class PostSummonUnnamedMessageAbAttr extends PostSummonAbAttr { //Attr doesn't force pokemon name on the message private message: string; @@ -2461,7 +2472,7 @@ export class PostSummonStatStageChangeAbAttr extends PostSummonAbAttr { globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, this.stats, this.stages)); } else { for (const opponent of pokemon.getOpponents()) { - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); if (this.intimidate) { applyAbAttrs(IntimidateImmunityAbAttr, opponent, cancelled, simulated); applyAbAttrs(PostIntimidateStatStageChangeAbAttr, opponent, cancelled, simulated); @@ -2495,9 +2506,9 @@ export class PostSummonAllyHealAbAttr extends PostSummonAbAttr { override applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): void { const target = pokemon.getAlly(); - if (!simulated && !Utils.isNullOrUndefined(target)) { + if (!simulated && !isNullOrUndefined(target)) { globalScene.unshiftPhase(new PokemonHealPhase(target.getBattlerIndex(), - Utils.toDmgValue(pokemon.getMaxHp() / this.healRatio), i18next.t("abilityTriggers:postSummonAllyHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(target), pokemonName: pokemon.name }), true, !this.showAnim)); + toDmgValue(pokemon.getMaxHp() / this.healRatio), i18next.t("abilityTriggers:postSummonAllyHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(target), pokemonName: pokemon.name }), true, !this.showAnim)); } } } @@ -2521,7 +2532,7 @@ export class PostSummonClearAllyStatStagesAbAttr extends PostSummonAbAttr { override applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): void { const target = pokemon.getAlly(); - if (!simulated && !Utils.isNullOrUndefined(target)) { + if (!simulated && !isNullOrUndefined(target)) { for (const s of BATTLE_STATS) { target.setStatStage(s, 0); } @@ -2639,12 +2650,12 @@ export class PostSummonHealStatusAbAttr extends PostSummonRemoveEffectAbAttr { public override canApplyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { const status = pokemon.status?.effect; - return !Utils.isNullOrUndefined(status) && (this.immuneEffects.length < 1 || this.immuneEffects.includes(status)) + return !isNullOrUndefined(status) && (this.immuneEffects.length < 1 || this.immuneEffects.includes(status)) } public override applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): void { const status = pokemon.status?.effect; - if (!Utils.isNullOrUndefined(status)) { + if (!isNullOrUndefined(status)) { this.statusHealed = status; pokemon.resetStatus(false); pokemon.updateInfo(); @@ -2692,7 +2703,7 @@ export class PostSummonCopyAbilityAbAttr extends PostSummonAbAttr { let target: Pokemon; if (targets.length > 1) { - globalScene.executeWithSeedOffset(() => target = Utils.randSeedItem(targets), globalScene.currentBattle.waveIndex); + globalScene.executeWithSeedOffset(() => target = randSeedItem(targets), globalScene.currentBattle.waveIndex); } else { target = targets[0]; } @@ -2779,7 +2790,7 @@ export class PostSummonCopyAllyStatsAbAttr extends PostSummonAbAttr { } const ally = pokemon.getAlly(); - if (Utils.isNullOrUndefined(ally) || ally.getStatStages().every(s => s === 0)) { + if (isNullOrUndefined(ally) || ally.getStatStages().every(s => s === 0)) { return false; } @@ -2788,7 +2799,7 @@ export class PostSummonCopyAllyStatsAbAttr extends PostSummonAbAttr { override applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): void { const ally = pokemon.getAlly(); - if (!simulated && !Utils.isNullOrUndefined(ally)) { + if (!simulated && !isNullOrUndefined(ally)) { for (const s of BATTLE_STATS) { pokemon.setStatStage(s, ally.getStatStage(s)); } @@ -2813,7 +2824,7 @@ export class PostSummonTransformAbAttr extends PostSummonAbAttr { } private getTarget(targets: Pokemon[]): Pokemon { - let target: Pokemon; + let target: Pokemon = targets[0]; if (targets.length > 1) { globalScene.executeWithSeedOffset(() => { // in a double battle, if one of the opposing pokemon is fused the other one will be chosen @@ -2825,11 +2836,12 @@ export class PostSummonTransformAbAttr extends PostSummonAbAttr { target = targets[0]; return; } - target = Utils.randSeedItem(targets); + target = randSeedItem(targets); }, globalScene.currentBattle.waveIndex); } else { target = targets[0]; } + target = target!; return target; @@ -2837,6 +2849,12 @@ export class PostSummonTransformAbAttr extends PostSummonAbAttr { override canApplyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { const targets = pokemon.getOpponents(); + const target = this.getTarget(targets); + + if (!!target.summonData?.illusion) { + return false; + } + if (simulated || !targets.length) { return simulated; } @@ -2934,7 +2952,7 @@ export class CommanderAbAttr extends AbAttr { // TODO: Should this work with X + Dondozo fusions? const ally = pokemon.getAlly(); - return globalScene.currentBattle?.double && !Utils.isNullOrUndefined(ally) && ally.species.speciesId === Species.DONDOZO + return globalScene.currentBattle?.double && !isNullOrUndefined(ally) && ally.species.speciesId === Species.DONDOZO && !(ally.isFainted() || ally.getTag(BattlerTagType.COMMANDED)); } @@ -2970,7 +2988,7 @@ export class PreSwitchOutResetStatusAbAttr extends PreSwitchOutAbAttr { } override canApplyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - return !Utils.isNullOrUndefined(pokemon.status); + return !isNullOrUndefined(pokemon.status); } override applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): void { @@ -3052,7 +3070,7 @@ export class PreSwitchOutHealAbAttr extends PreSwitchOutAbAttr { override applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): void { if (!simulated) { - const healAmount = Utils.toDmgValue(pokemon.getMaxHp() * 0.33); + const healAmount = toDmgValue(pokemon.getMaxHp() * 0.33); pokemon.heal(healAmount); pokemon.updateInfo(); } @@ -3166,7 +3184,7 @@ export class PreStatStageChangeAbAttr extends AbAttr { passive: boolean, simulated: boolean, stat: BattleStat, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, args: any[]): boolean { return true; } @@ -3176,7 +3194,7 @@ export class PreStatStageChangeAbAttr extends AbAttr { passive: boolean, simulated: boolean, stat: BattleStat, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, args: any[], ): void {} } @@ -3195,10 +3213,10 @@ export class ReflectStatStageChangeAbAttr extends PreStatStageChangeAbAttr { * @param _passive N/A * @param simulated `true` if the ability is being simulated by the AI * @param stat the {@linkcode BattleStat} being affected - * @param cancelled The {@linkcode Utils.BooleanHolder} that will be set to true due to reflection + * @param cancelled The {@linkcode BooleanHolder} that will be set to true due to reflection * @param args */ - override applyPreStatStageChange(_pokemon: Pokemon, _passive: boolean, simulated: boolean, stat: BattleStat, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreStatStageChange(_pokemon: Pokemon, _passive: boolean, simulated: boolean, stat: BattleStat, cancelled: BooleanHolder, args: any[]): void { const attacker: Pokemon = args[0]; const stages = args[1]; this.reflectedStat = stat; @@ -3230,8 +3248,8 @@ export class ProtectStatAbAttr extends PreStatStageChangeAbAttr { this.protectedStat = protectedStat; } - override canApplyPreStatStageChange(pokemon: Pokemon | null, passive: boolean, simulated: boolean, stat: BattleStat, cancelled: Utils.BooleanHolder, args: any[]): boolean { - return Utils.isNullOrUndefined(this.protectedStat) || stat === this.protectedStat; + override canApplyPreStatStageChange(pokemon: Pokemon | null, passive: boolean, simulated: boolean, stat: BattleStat, cancelled: BooleanHolder, args: any[]): boolean { + return isNullOrUndefined(this.protectedStat) || stat === this.protectedStat; } /** @@ -3240,10 +3258,10 @@ export class ProtectStatAbAttr extends PreStatStageChangeAbAttr { * @param _passive * @param simulated * @param stat the {@linkcode BattleStat} being affected - * @param cancelled The {@linkcode Utils.BooleanHolder} that will be set to true if the stat is protected + * @param cancelled The {@linkcode BooleanHolder} that will be set to true if the stat is protected * @param _args */ - override applyPreStatStageChange(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, stat: BattleStat, cancelled: Utils.BooleanHolder, _args: any[]): void { + override applyPreStatStageChange(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, stat: BattleStat, cancelled: BooleanHolder, _args: any[]): void { cancelled.value = true; } @@ -3302,7 +3320,7 @@ export class PreSetStatusAbAttr extends AbAttr { passive: boolean, simulated: boolean, effect: StatusEffect | undefined, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, args: any[]): boolean { return true; } @@ -3312,7 +3330,7 @@ export class PreSetStatusAbAttr extends AbAttr { passive: boolean, simulated: boolean, effect: StatusEffect | undefined, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, args: any[], ): void {} } @@ -3332,7 +3350,7 @@ export class PreSetStatusEffectImmunityAbAttr extends PreSetStatusAbAttr { this.immuneEffects = immuneEffects; } - override canApplyPreSetStatus(pokemon: Pokemon, passive: boolean, simulated: boolean, effect: StatusEffect, cancelled: Utils.BooleanHolder, args: any[]): boolean { + override canApplyPreSetStatus(pokemon: Pokemon, passive: boolean, simulated: boolean, effect: StatusEffect, cancelled: BooleanHolder, args: any[]): boolean { return effect !== StatusEffect.FAINT && this.immuneEffects.length < 1 || this.immuneEffects.includes(effect); } @@ -3345,7 +3363,7 @@ export class PreSetStatusEffectImmunityAbAttr extends PreSetStatusAbAttr { * @param cancelled - A holder for a boolean value indicating if the status application was cancelled. * @param args - n/a */ - override applyPreSetStatus(pokemon: Pokemon, passive: boolean, simulated: boolean, effect: StatusEffect, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreSetStatus(pokemon: Pokemon, passive: boolean, simulated: boolean, effect: StatusEffect, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } @@ -3400,7 +3418,7 @@ export class ConditionalUserFieldStatusEffectImmunityAbAttr extends UserFieldSta * @param args `Args[0]` is the target of the status effect, `Args[1]` is the source. * @returns Whether the ability can be applied to cancel the status effect. */ - override canApplyPreSetStatus(pokemon: Pokemon, passive: boolean, simulated: boolean, effect: StatusEffect, cancelled: Utils.BooleanHolder, args: [Pokemon, Pokemon | null, ...any]): boolean { + override canApplyPreSetStatus(pokemon: Pokemon, passive: boolean, simulated: boolean, effect: StatusEffect, cancelled: BooleanHolder, args: [Pokemon, Pokemon | null, ...any]): boolean { return (!cancelled.value && effect !== StatusEffect.FAINT && this.immuneEffects.length < 1 || this.immuneEffects.includes(effect)) && this.condition(args[0], args[1]); } @@ -3438,12 +3456,12 @@ export class ConditionalUserFieldProtectStatAbAttr extends PreStatStageChangeAbA * @param args Args[0] is the target pokemon of the stat change. * @returns */ - override canApplyPreStatStageChange(pokemon: Pokemon, passive: boolean, simulated: boolean, stat: BattleStat, cancelled: Utils.BooleanHolder, args: [Pokemon, ...any]): boolean { + override canApplyPreStatStageChange(pokemon: Pokemon, passive: boolean, simulated: boolean, stat: BattleStat, cancelled: BooleanHolder, args: [Pokemon, ...any]): boolean { const target = args[0]; if (!target) { return false; } - return !cancelled.value && (Utils.isNullOrUndefined(this.protectedStat) || stat === this.protectedStat) && this.condition(target); + return !cancelled.value && (isNullOrUndefined(this.protectedStat) || stat === this.protectedStat) && this.condition(target); } /** @@ -3455,7 +3473,7 @@ export class ConditionalUserFieldProtectStatAbAttr extends PreStatStageChangeAbA * @param cancelled Will be set to true if the stat change is prevented * @param _args unused */ - override applyPreStatStageChange(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, _stat: BattleStat, cancelled: Utils.BooleanHolder, _args: any[]): void { + override applyPreStatStageChange(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, _stat: BattleStat, cancelled: BooleanHolder, _args: any[]): void { cancelled.value = true; } } @@ -3467,7 +3485,7 @@ export class PreApplyBattlerTagAbAttr extends AbAttr { passive: boolean, simulated: boolean, tag: BattlerTag, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, args: any[], ): boolean { return true; @@ -3478,7 +3496,7 @@ export class PreApplyBattlerTagAbAttr extends AbAttr { passive: boolean, simulated: boolean, tag: BattlerTag, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, args: any[], ): void {} } @@ -3496,13 +3514,13 @@ export class PreApplyBattlerTagImmunityAbAttr extends PreApplyBattlerTagAbAttr { this.immuneTagTypes = Array.isArray(immuneTagTypes) ? immuneTagTypes : [ immuneTagTypes ]; } - override canApplyPreApplyBattlerTag(pokemon: Pokemon, passive: boolean, simulated: boolean, tag: BattlerTag, cancelled: Utils.BooleanHolder, args: any[]): boolean { + override canApplyPreApplyBattlerTag(pokemon: Pokemon, passive: boolean, simulated: boolean, tag: BattlerTag, cancelled: BooleanHolder, args: any[]): boolean { this.battlerTag = tag; return !cancelled.value && this.immuneTagTypes.includes(tag.tagType); } - override applyPreApplyBattlerTag(pokemon: Pokemon, passive: boolean, simulated: boolean, tag: BattlerTag, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreApplyBattlerTag(pokemon: Pokemon, passive: boolean, simulated: boolean, tag: BattlerTag, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } @@ -3540,7 +3558,7 @@ export class ConditionalUserFieldBattlerTagImmunityAbAttr extends UserFieldBattl * @param args Args[0] is the target that the tag is attempting to be applied to * @returns Whether the ability can be used to cancel the battler tag */ - override canApplyPreApplyBattlerTag(pokemon: Pokemon, passive: boolean, simulated: boolean, tag: BattlerTag, cancelled: Utils.BooleanHolder, args: [Pokemon, ...any]): boolean { + override canApplyPreApplyBattlerTag(pokemon: Pokemon, passive: boolean, simulated: boolean, tag: BattlerTag, cancelled: BooleanHolder, args: [Pokemon, ...any]): boolean { return super.canApplyPreApplyBattlerTag(pokemon, passive, simulated, tag, cancelled, args) && this.condition(args[0]); } @@ -3556,8 +3574,8 @@ export class BlockCritAbAttr extends AbAttr { super(false); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.BooleanHolder).value = true; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + (args[0] as BooleanHolder).value = true; } } @@ -3575,8 +3593,8 @@ export class BonusCritAbAttr extends AbAttr { * @param cancelled Unused * @param args Args[0] is a number holder containing the crit stage. */ - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: [Utils.NumberHolder, ...any]): void { - (args[0] as Utils.NumberHolder).value += 1; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: [NumberHolder, ...any]): void { + (args[0] as NumberHolder).value += 1; } } @@ -3590,12 +3608,12 @@ export class MultCritAbAttr extends AbAttr { } override canApply(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - const critMult = args[0] as Utils.NumberHolder; + const critMult = args[0] as NumberHolder; return critMult.value > 1; } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - const critMult = args[0] as Utils.NumberHolder; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + const critMult = args[0] as NumberHolder; critMult.value *= this.multAmount; } } @@ -3622,12 +3640,12 @@ export class ConditionalCritAbAttr extends AbAttr { /** * @param pokemon {@linkcode Pokemon} user. - * @param args [0] {@linkcode Utils.BooleanHolder} If true critical hit is guaranteed. + * @param args [0] {@linkcode BooleanHolder} If true critical hit is guaranteed. * [1] {@linkcode Pokemon} Target. * [2] {@linkcode Move} used by ability user. */ - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.BooleanHolder).value = true; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + (args[0] as BooleanHolder).value = true; } } @@ -3636,7 +3654,7 @@ export class BlockNonDirectDamageAbAttr extends AbAttr { super(false); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } @@ -3666,16 +3684,16 @@ export class BlockStatusDamageAbAttr extends AbAttr { /** * @param {Pokemon} pokemon The pokemon with the ability * @param {boolean} passive N/A - * @param {Utils.BooleanHolder} cancelled Whether to cancel the status damage + * @param {BooleanHolder} cancelled Whether to cancel the status damage * @param {any[]} args N/A */ - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } export class BlockOneHitKOAbAttr extends AbAttr { - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } @@ -3704,8 +3722,8 @@ export class ChangeMovePriorityAbAttr extends AbAttr { return this.moveFunc(pokemon, args[0] as Move); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[1] as Utils.NumberHolder).value += this.changeAmount; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + (args[1] as NumberHolder).value += this.changeAmount; } } @@ -3717,7 +3735,7 @@ export class PreWeatherEffectAbAttr extends AbAttr { passive: Boolean, simulated: boolean, weather: Weather | null, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, args: any[]): boolean { return true; } @@ -3727,7 +3745,7 @@ export class PreWeatherEffectAbAttr extends AbAttr { passive: boolean, simulated: boolean, weather: Weather | null, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, args: any[], ): void {} } @@ -3743,11 +3761,11 @@ export class BlockWeatherDamageAttr extends PreWeatherDamageAbAttr { this.weatherTypes = weatherTypes; } - override canApplyPreWeatherEffect(pokemon: Pokemon, passive: Boolean, simulated: boolean, weather: Weather, cancelled: Utils.BooleanHolder, args: any[]): boolean { + override canApplyPreWeatherEffect(pokemon: Pokemon, passive: Boolean, simulated: boolean, weather: Weather, cancelled: BooleanHolder, args: any[]): boolean { return !this.weatherTypes.length || this.weatherTypes.indexOf(weather?.weatherType) > -1; } - override applyPreWeatherEffect(pokemon: Pokemon, passive: boolean, simulated: boolean, weather: Weather, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreWeatherEffect(pokemon: Pokemon, passive: boolean, simulated: boolean, weather: Weather, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } @@ -3761,11 +3779,11 @@ export class SuppressWeatherEffectAbAttr extends PreWeatherEffectAbAttr { this.affectsImmutable = !!affectsImmutable; } - override canApplyPreWeatherEffect(pokemon: Pokemon, passive: Boolean, simulated: boolean, weather: Weather, cancelled: Utils.BooleanHolder, args: any[]): boolean { + override canApplyPreWeatherEffect(pokemon: Pokemon, passive: Boolean, simulated: boolean, weather: Weather, cancelled: BooleanHolder, args: any[]): boolean { return this.affectsImmutable || weather.isImmutable(); } - override applyPreWeatherEffect(pokemon: Pokemon, passive: boolean, simulated: boolean, weather: Weather, cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreWeatherEffect(pokemon: Pokemon, passive: boolean, simulated: boolean, weather: Weather, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } @@ -4042,7 +4060,7 @@ export class PostWeatherLapseHealAbAttr extends PostWeatherLapseAbAttr { const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name; if (!simulated) { globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), - Utils.toDmgValue(pokemon.getMaxHp() / (16 / this.healFactor)), i18next.t("abilityTriggers:postWeatherLapseHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }), true)); + toDmgValue(pokemon.getMaxHp() / (16 / this.healFactor)), i18next.t("abilityTriggers:postWeatherLapseHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }), true)); } } } @@ -4064,7 +4082,7 @@ export class PostWeatherLapseDamageAbAttr extends PostWeatherLapseAbAttr { if (!simulated) { const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name; globalScene.queueMessage(i18next.t("abilityTriggers:postWeatherLapseDamage", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName })); - pokemon.damageAndUpdate(Utils.toDmgValue(pokemon.getMaxHp() / (16 / this.damageFactor)), { result: HitResult.INDIRECT }); + pokemon.damageAndUpdate(toDmgValue(pokemon.getMaxHp() / (16 / this.damageFactor)), { result: HitResult.INDIRECT }); } } } @@ -4132,7 +4150,7 @@ export class PostTurnStatusHealAbAttr extends PostTurnAbAttr { } override canApplyPostTurn(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - return !Utils.isNullOrUndefined(pokemon.status) && this.effects.includes(pokemon.status.effect) && !pokemon.isFullHp(); + return !isNullOrUndefined(pokemon.status) && this.effects.includes(pokemon.status.effect) && !pokemon.isFullHp(); } /** @@ -4144,7 +4162,7 @@ export class PostTurnStatusHealAbAttr extends PostTurnAbAttr { if (!simulated) { const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name; globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), - Utils.toDmgValue(pokemon.getMaxHp() / 8), i18next.t("abilityTriggers:poisonHeal", { pokemonName: getPokemonNameWithAffix(pokemon), abilityName }), true)); + toDmgValue(pokemon.getMaxHp() / 8), i18next.t("abilityTriggers:poisonHeal", { pokemonName: getPokemonNameWithAffix(pokemon), abilityName }), true)); } } } @@ -4168,7 +4186,7 @@ export class PostTurnResetStatusAbAttr extends PostTurnAbAttr { } else { this.target = pokemon; } - return !Utils.isNullOrUndefined(this.target?.status); + return !isNullOrUndefined(this.target?.status); } override applyPostTurn(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): void { @@ -4224,7 +4242,7 @@ export class PostTurnLootAbAttr extends PostTurnAbAttr { return true; } - const randomIdx = Utils.randSeedInt(berriesEaten.length); + const randomIdx = randSeedInt(berriesEaten.length); const chosenBerryType = berriesEaten[randomIdx]; const chosenBerry = new BerryModifierType(chosenBerryType); berriesEaten.splice(randomIdx); // Remove berry from memory @@ -4312,7 +4330,7 @@ export class PostTurnHealAbAttr extends PostTurnAbAttr { if (!simulated) { const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name; globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), - Utils.toDmgValue(pokemon.getMaxHp() / 16), i18next.t("abilityTriggers:postTurnHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }), true)); + toDmgValue(pokemon.getMaxHp() / 16), i18next.t("abilityTriggers:postTurnHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }), true)); } } } @@ -4356,7 +4374,7 @@ export class PostTurnHurtIfSleepingAbAttr extends PostTurnAbAttr { for (const opp of pokemon.getOpponents()) { if ((opp.status?.effect === StatusEffect.SLEEP || opp.hasAbility(Abilities.COMATOSE)) && !opp.hasAbilityWithAttr(BlockNonDirectDamageAbAttr) && !opp.switchOutStatus) { if (!simulated) { - opp.damageAndUpdate(Utils.toDmgValue(opp.getMaxHp() / 8), { result: HitResult.INDIRECT }); + opp.damageAndUpdate(toDmgValue(opp.getMaxHp() / 8), { result: HitResult.INDIRECT }); globalScene.queueMessage(i18next.t("abilityTriggers:badDreams", { pokemonName: getPokemonNameWithAffix(opp) })); } } @@ -4375,7 +4393,7 @@ export class FetchBallAbAttr extends PostTurnAbAttr { } override canApplyPostTurn(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - return !simulated && !Utils.isNullOrUndefined(globalScene.currentBattle.lastUsedPokeball) && !!pokemon.isPlayer; + return !simulated && !isNullOrUndefined(globalScene.currentBattle.lastUsedPokeball) && !!pokemon.isPlayer; } /** @@ -4407,7 +4425,7 @@ export class PostBiomeChangeWeatherChangeAbAttr extends PostBiomeChangeAbAttr { return ((globalScene.arena.weather?.isImmutable() ?? false) && globalScene.arena.canSetWeather(this.weatherType)); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { if (!simulated) { globalScene.arena.trySetWeather(this.weatherType, pokemon); } @@ -4427,7 +4445,7 @@ export class PostBiomeChangeTerrainChangeAbAttr extends PostBiomeChangeAbAttr { return globalScene.arena.canSetTerrain(this.terrainType); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { if (!simulated) { globalScene.arena.trySetTerrain(this.terrainType, false, pokemon); } @@ -4562,8 +4580,8 @@ export class StatStageChangeMultiplierAbAttr extends AbAttr { this.multiplier = multiplier; } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.NumberHolder).value *= this.multiplier; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + (args[0] as NumberHolder).value *= this.multiplier; } } @@ -4572,7 +4590,7 @@ export class StatStageChangeCopyAbAttr extends AbAttr { pokemon: Pokemon, passive: boolean, simulated: boolean, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, args: any[], ): void { if (!simulated) { @@ -4586,7 +4604,7 @@ export class BypassBurnDamageReductionAbAttr extends AbAttr { super(false); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } @@ -4605,21 +4623,21 @@ export class ReduceBurnDamageAbAttr extends AbAttr { * @param pokemon N/A * @param passive N/A * @param cancelled N/A - * @param args `[0]` {@linkcode Utils.NumberHolder} The damage value being modified + * @param args `[0]` {@linkcode NumberHolder} The damage value being modified */ - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.NumberHolder).value = Utils.toDmgValue((args[0] as Utils.NumberHolder).value * this.multiplier); + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + (args[0] as NumberHolder).value = toDmgValue((args[0] as NumberHolder).value * this.multiplier); } } export class DoubleBerryEffectAbAttr extends AbAttr { - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.NumberHolder).value *= 2; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + (args[0] as NumberHolder).value *= 2; } } export class PreventBerryUseAbAttr extends AbAttr { - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } @@ -4640,13 +4658,13 @@ export class HealFromBerryUseAbAttr extends AbAttr { this.healPercent = Math.max(Math.min(healPercent, 1), 0); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, ...args: [Utils.BooleanHolder, any[]]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, ...args: [BooleanHolder, any[]]): void { const { name: abilityName } = passive ? pokemon.getPassiveAbility() : pokemon.getAbility(); if (!simulated) { globalScene.unshiftPhase( new PokemonHealPhase( pokemon.getBattlerIndex(), - Utils.toDmgValue(pokemon.getMaxHp() * this.healPercent), + toDmgValue(pokemon.getMaxHp() * this.healPercent), i18next.t("abilityTriggers:healFromBerryUse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }), true ) @@ -4656,8 +4674,8 @@ export class HealFromBerryUseAbAttr extends AbAttr { } export class RunSuccessAbAttr extends AbAttr { - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.NumberHolder).value = 256; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + (args[0] as NumberHolder).value = 256; } } @@ -4681,7 +4699,7 @@ export class CheckTrappedAbAttr extends AbAttr { pokemon: Pokemon, passive: boolean, simulated: boolean, - trapped: Utils.BooleanHolder, + trapped: BooleanHolder, otherPokemon: Pokemon, args: any[]): boolean { return true; @@ -4691,7 +4709,7 @@ export class CheckTrappedAbAttr extends AbAttr { pokemon: Pokemon, passive: boolean, simulated: boolean, - trapped: Utils.BooleanHolder, + trapped: BooleanHolder, otherPokemon: Pokemon, args: any[], ): void {} @@ -4704,7 +4722,7 @@ export class CheckTrappedAbAttr extends AbAttr { * @see {@linkcode applyCheckTrapped} */ export class ArenaTrapAbAttr extends CheckTrappedAbAttr { - override canApplyCheckTrapped(pokemon: Pokemon, passive: boolean, simulated: boolean, trapped: Utils.BooleanHolder, otherPokemon: Pokemon, args: any[]): boolean { + override canApplyCheckTrapped(pokemon: Pokemon, passive: boolean, simulated: boolean, trapped: BooleanHolder, otherPokemon: Pokemon, args: any[]): boolean { return this.arenaTrapCondition(pokemon, otherPokemon) && !(otherPokemon.getTypes(true).includes(PokemonType.GHOST) || (otherPokemon.getTypes(true).includes(PokemonType.STELLAR) && otherPokemon.getTypes().includes(PokemonType.GHOST))) && !otherPokemon.hasAbility(Abilities.RUN_AWAY); @@ -4718,11 +4736,11 @@ export class ArenaTrapAbAttr extends CheckTrappedAbAttr { * If the user has Arena Trap and the enemy is not grounded, it is not trapped. * @param pokemon The {@link Pokemon} with this {@link AbAttr} * @param passive N/A - * @param trapped {@link Utils.BooleanHolder} indicating whether the other Pokemon is trapped or not + * @param trapped {@link BooleanHolder} indicating whether the other Pokemon is trapped or not * @param otherPokemon The {@link Pokemon} that is affected by an Arena Trap ability * @param args N/A */ - override applyCheckTrapped(pokemon: Pokemon, passive: boolean, simulated: boolean, trapped: Utils.BooleanHolder, otherPokemon: Pokemon, args: any[]): void { + override applyCheckTrapped(pokemon: Pokemon, passive: boolean, simulated: boolean, trapped: BooleanHolder, otherPokemon: Pokemon, args: any[]): void { trapped.value = true; } @@ -4736,14 +4754,14 @@ export class MaxMultiHitAbAttr extends AbAttr { super(false); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.NumberHolder).value = 0; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + (args[0] as NumberHolder).value = 0; } } export class PostBattleAbAttr extends AbAttr { - constructor() { - super(true); + constructor(showAbility: boolean = true) { + super(showAbility); } canApplyPostBattle(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { @@ -4759,7 +4777,7 @@ export class PostBattleLootAbAttr extends PostBattleAbAttr { override canApplyPostBattle(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { const postBattleLoot = globalScene.currentBattle.postBattleLoot; if (!simulated && postBattleLoot.length && args[0]) { - this.randItem = Utils.randSeedItem(postBattleLoot); + this.randItem = randSeedItem(postBattleLoot); return globalScene.canTransferHeldItemModifier(this.randItem, pokemon, 1); } return false; @@ -4771,7 +4789,7 @@ export class PostBattleLootAbAttr extends PostBattleAbAttr { override applyPostBattle(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): void { const postBattleLoot = globalScene.currentBattle.postBattleLoot; if (!this.randItem) { - this.randItem = Utils.randSeedItem(postBattleLoot); + this.randItem = randSeedItem(postBattleLoot); } if (globalScene.tryTransferHeldItemModifier(this.randItem, pokemon, true, 1, true, undefined, false)) { @@ -4828,7 +4846,7 @@ export class PostFaintContactDamageAbAttr extends PostFaintAbAttr { override canApplyPostFaint(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker?: Pokemon, move?: Move, hitResult?: HitResult, ...args: any[]): boolean { const diedToDirectDamage = move !== undefined && attacker !== undefined && move.doesFlagEffectApply({flag: MoveFlags.MAKES_CONTACT, user: attacker, target: pokemon}); - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); globalScene.getField(true).map(p => applyAbAttrs(FieldPreventExplosiveMovesAbAttr, p, cancelled, simulated)); if (!diedToDirectDamage || cancelled.value || attacker!.hasAbilityWithAttr(BlockNonDirectDamageAbAttr)) { return false; @@ -4839,8 +4857,8 @@ export class PostFaintContactDamageAbAttr extends PostFaintAbAttr { override applyPostFaint(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker?: Pokemon, move?: Move, hitResult?: HitResult, ...args: any[]): void { if (!simulated) { - attacker!.damageAndUpdate(Utils.toDmgValue(attacker!.getMaxHp() * (1 / this.damageRatio)), { result: HitResult.INDIRECT }); - attacker!.turnData.damageTaken += Utils.toDmgValue(attacker!.getMaxHp() * (1 / this.damageRatio)); + attacker!.damageAndUpdate(toDmgValue(attacker!.getMaxHp() * (1 / this.damageRatio)), { result: HitResult.INDIRECT }); + attacker!.turnData.damageTaken += toDmgValue(attacker!.getMaxHp() * (1 / this.damageRatio)); } } @@ -4886,13 +4904,13 @@ export class RedirectMoveAbAttr extends AbAttr { if (!this.canRedirect(args[0] as Moves, args[2] as Pokemon)) { return false; } - const target = args[1] as Utils.NumberHolder; + const target = args[1] as NumberHolder; const newTarget = pokemon.getBattlerIndex(); return target.value !== newTarget; } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - const target = args[1] as Utils.NumberHolder; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + const target = args[1] as NumberHolder; const newTarget = pokemon.getBattlerIndex(); target.value = newTarget; } @@ -4933,7 +4951,7 @@ export class ReduceStatusEffectDurationAbAttr extends AbAttr { } override canApply(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - return args[1] instanceof Utils.NumberHolder && args[0] === this.statusEffect; + return args[1] instanceof NumberHolder && args[0] === this.statusEffect; } /** @@ -4942,7 +4960,7 @@ export class ReduceStatusEffectDurationAbAttr extends AbAttr { * - `[0]` - The {@linkcode StatusEffect} of the Pokemon * - `[1]` - The number of turns remaining until the status is healed */ - override apply(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, _cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(_pokemon: Pokemon, _passive: boolean, _simulated: boolean, _cancelled: BooleanHolder, args: any[]): void { args[1].value -= 1; } } @@ -4966,7 +4984,7 @@ export class FlinchStatStageChangeAbAttr extends FlinchEffectAbAttr { this.stages = stages; } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { if (!simulated) { globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, this.stats, this.stages)); } @@ -4976,7 +4994,7 @@ export class FlinchStatStageChangeAbAttr extends FlinchEffectAbAttr { export class IncreasePpAbAttr extends AbAttr { } export class ForceSwitchOutImmunityAbAttr extends AbAttr { - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } @@ -4991,7 +5009,7 @@ export class ReduceBerryUseThresholdAbAttr extends AbAttr { return args[0].value < hpRatio; } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { args[0].value *= 2; } } @@ -5009,8 +5027,8 @@ export class WeightMultiplierAbAttr extends AbAttr { this.multiplier = multiplier; } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - (args[0] as Utils.NumberHolder).value *= this.multiplier; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + (args[0] as NumberHolder).value *= this.multiplier; } } @@ -5019,7 +5037,7 @@ export class SyncEncounterNatureAbAttr extends AbAttr { super(false); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { (args[0] as Pokemon).setNature(pokemon.getNature()); } } @@ -5037,7 +5055,7 @@ export class MoveAbilityBypassAbAttr extends AbAttr { return this.moveIgnoreFunc(pokemon, (args[0] as Move)); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } @@ -5057,7 +5075,7 @@ export class InfiltratorAbAttr extends AbAttr { } override canApply(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - return args[0] instanceof Utils.BooleanHolder; + return args[0] instanceof BooleanHolder; } /** @@ -5066,7 +5084,7 @@ export class InfiltratorAbAttr extends AbAttr { * @param passive n/a * @param simulated n/a * @param cancelled n/a - * @param args `[0]` a {@linkcode Utils.BooleanHolder | BooleanHolder} containing the flag + * @param args `[0]` a {@linkcode BooleanHolder | BooleanHolder} containing the flag */ override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: null, args: any[]): void { const bypassed = args[0]; @@ -5107,7 +5125,7 @@ export class IgnoreTypeImmunityAbAttr extends AbAttr { return this.defenderType === (args[1] as PokemonType) && this.allowedMoveTypes.includes(args[0] as PokemonType); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } @@ -5130,7 +5148,7 @@ export class IgnoreTypeStatusEffectImmunityAbAttr extends AbAttr { return this.statusEffect.includes(args[0] as StatusEffect) && this.defenderType.includes(args[1] as PokemonType); } - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { cancelled.value = true; } } @@ -5223,7 +5241,7 @@ export class FormBlockDamageAbAttr extends ReceivedMoveDamageMultiplierAbAttr { this.triggerMessageFunc = triggerMessageFunc; } - override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder | null, args: any[]): boolean { + override canApplyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: BooleanHolder | null, args: any[]): boolean { return this.condition(pokemon, attacker, move) && !move.hitsSubstitute(attacker, pokemon); } @@ -5238,9 +5256,9 @@ export class FormBlockDamageAbAttr extends ReceivedMoveDamageMultiplierAbAttr { * @param _cancelled n/a * @param args Additional arguments. */ - override applyPreDefend(pokemon: Pokemon, _passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, _cancelled: Utils.BooleanHolder, args: any[]): void { + override applyPreDefend(pokemon: Pokemon, _passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, _cancelled: BooleanHolder, args: any[]): void { if (!simulated) { - (args[0] as Utils.NumberHolder).value = this.multiplier; + (args[0] as NumberHolder).value = this.multiplier; pokemon.removeTag(this.tagType); if (this.recoilDamageFunc) { pokemon.damageAndUpdate(this.recoilDamageFunc(pokemon), { result: HitResult.INDIRECT, ignoreSegments: true, ignoreFaintPhase: true }); @@ -5260,6 +5278,92 @@ export class FormBlockDamageAbAttr extends ReceivedMoveDamageMultiplierAbAttr { } } +/** + * Base class for defining {@linkcode Ability} attributes before summon + * (should use {@linkcode PostSummonAbAttr} for most ability) + * @see {@linkcode applyPreSummon()} + */ +export class PreSummonAbAttr extends AbAttr { + applyPreSummon(pokemon: Pokemon, passive: boolean, args: any[]): void {} + + canApplyPreSummon(pokemon: Pokemon, passive: boolean, args: any[]): boolean { + return true; + } +} + +export class IllusionPreSummonAbAttr extends PreSummonAbAttr { + /** + * Apply a new illusion when summoning Zoroark if the illusion is available + * + * @param pokemon - The Pokémon with the Illusion ability. + * @param passive - N/A + * @param args - N/A + * @returns Whether the illusion was applied. + */ + override applyPreSummon(pokemon: Pokemon, passive: boolean, args: any[]): void { + const party: Pokemon[] = (pokemon.isPlayer() ? globalScene.getPlayerParty() : globalScene.getEnemyParty()).filter(p => p.isAllowedInBattle()); + const lastPokemon: Pokemon = party.filter(p => p !==pokemon).at(-1) || pokemon; + pokemon.setIllusion(lastPokemon); + } + + override canApplyPreSummon(pokemon: Pokemon, passive: boolean, args: any[]): boolean { + pokemon.initSummondata() + if(pokemon.hasTrainer()){ + const party: Pokemon[] = (pokemon.isPlayer() ? globalScene.getPlayerParty() : globalScene.getEnemyParty()).filter(p => p.isAllowedInBattle()); + const lastPokemon: Pokemon = party.filter(p => p !==pokemon).at(-1) || pokemon; + const speciesId = lastPokemon.species.speciesId; + + // If the last conscious Pokémon in the party is a Terastallized Ogerpon or Terapagos, Illusion will not activate. + // Illusion will also not activate if the Pokémon with Illusion is Terastallized and the last Pokémon in the party is Ogerpon or Terapagos. + if ( + lastPokemon === pokemon || + ((speciesId === Species.OGERPON || speciesId === Species.TERAPAGOS) && (lastPokemon.isTerastallized || pokemon.isTerastallized)) + ) { + return false; + } + } + return !pokemon.summonData.illusionBroken; + } +} + +export class IllusionBreakAbAttr extends PostDefendAbAttr { + /** + * Destroy the illusion upon taking damage + * + * @param pokemon - The Pokémon with the Illusion ability. + * @param passive - unused + * @param attacker - The attacking Pokémon. + * @param move - The move being used. + * @param hitResult - The type of hitResult the pokemon got + * @param args - unused + * @returns - Whether the illusion was destroyed. + */ + override applyPostDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, hitResult: HitResult, args: any[]): void { + pokemon.breakIllusion(); + pokemon.summonData.illusionBroken = true; + } + + override canApplyPostDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, hitResult: HitResult, args: any[]): boolean { + const breakIllusion: HitResult[] = [ HitResult.EFFECTIVE, HitResult.SUPER_EFFECTIVE, HitResult.NOT_VERY_EFFECTIVE, HitResult.ONE_HIT_KO ]; + return breakIllusion.includes(hitResult) && !!pokemon.summonData?.illusion + } +} + +export class IllusionPostBattleAbAttr extends PostBattleAbAttr { + /** + * Break the illusion once the battle ends + * + * @param pokemon - The Pokémon with the Illusion ability. + * @param passive - Unused + * @param args - Unused + * @returns - Whether the illusion was applied. + */ + override applyPostBattle(pokemon: Pokemon, passive: boolean, simulated:boolean, args: any[]): void { + pokemon.breakIllusion() + } +} + + /** * If a Pokémon with this Ability selects a damaging move, it has a 30% chance of going first in its priority bracket. If the Ability activates, this is announced at the start of the turn (after move selection). * @@ -5277,7 +5381,7 @@ export class BypassSpeedChanceAbAttr extends AbAttr { } override canApply(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - const bypassSpeed = args[0] as Utils.BooleanHolder; + const bypassSpeed = args[0] as BooleanHolder; const turnCommand = globalScene.currentBattle.turnCommands[pokemon.getBattlerIndex()]; const isCommandFight = turnCommand?.command === Command.FIGHT; const move = turnCommand?.move?.move ? allMoves[turnCommand.move.move] : null; @@ -5289,11 +5393,11 @@ export class BypassSpeedChanceAbAttr extends AbAttr { * bypass move order in their priority bracket when pokemon choose damaging move * @param {Pokemon} pokemon {@linkcode Pokemon} the Pokemon applying this ability * @param {boolean} passive N/A - * @param {Utils.BooleanHolder} cancelled N/A - * @param {any[]} args [0] {@linkcode Utils.BooleanHolder} set to true when the ability activated + * @param {BooleanHolder} cancelled N/A + * @param {any[]} args [0] {@linkcode BooleanHolder} set to true when the ability activated */ - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - const bypassSpeed = args[0] as Utils.BooleanHolder; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + const bypassSpeed = args[0] as BooleanHolder; bypassSpeed.value = true; } @@ -5328,9 +5432,9 @@ export class PreventBypassSpeedChanceAbAttr extends AbAttr { * @argument {boolean} bypassSpeed - determines if a Pokemon is able to bypass speed at the moment * @argument {boolean} canCheckHeldItems - determines if a Pokemon has access to Quick Claw's effects or not */ - override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void { - const bypassSpeed = args[0] as Utils.BooleanHolder; - const canCheckHeldItems = args[1] as Utils.BooleanHolder; + override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder, args: any[]): void { + const bypassSpeed = args[0] as BooleanHolder; + const canCheckHeldItems = args[1] as BooleanHolder; bypassSpeed.value = false; canCheckHeldItems.value = false; } @@ -5349,7 +5453,7 @@ export class TerrainEventTypeChangeAbAttr extends PostSummonAbAttr { return !pokemon.isTerastallized; } - override apply(pokemon: Pokemon, _passive: boolean, _simulated: boolean, _cancelled: Utils.BooleanHolder, _args: any[]): void { + override apply(pokemon: Pokemon, _passive: boolean, _simulated: boolean, _cancelled: BooleanHolder, _args: any[]): void { const currentTerrain = globalScene.arena.getTerrainType(); const typeChange: PokemonType[] = this.determineTypeChange(pokemon, currentTerrain); if (typeChange.length !== 0) { @@ -5400,7 +5504,7 @@ export class TerrainEventTypeChangeAbAttr extends PostSummonAbAttr { * Checks if the Pokemon should change types if summoned into an active terrain */ override applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): void { - this.apply(pokemon, passive, simulated, new Utils.BooleanHolder(false), []); + this.apply(pokemon, passive, simulated, new BooleanHolder(false), []); } override getTriggerMessage(pokemon: Pokemon, abilityName: string, ...args: any[]) { @@ -5527,7 +5631,7 @@ class ForceSwitchOutHelper { if (switchOutTarget.hp > 0) { switchOutTarget.leaveField(false); globalScene.queueMessage(i18next.t("moveTriggers:fled", { pokemonName: getPokemonNameWithAffix(switchOutTarget) }), null, true, 500); - if (globalScene.currentBattle.double && !Utils.isNullOrUndefined(allyPokemon)) { + if (globalScene.currentBattle.double && !isNullOrUndefined(allyPokemon)) { globalScene.redirectPokemonMoves(switchOutTarget, allyPokemon); } } @@ -5556,7 +5660,7 @@ class ForceSwitchOutHelper { const player = switchOutTarget instanceof PlayerPokemon; if (player) { - const blockedByAbility = new Utils.BooleanHolder(false); + const blockedByAbility = new BooleanHolder(false); applyAbAttrs(ForceSwitchOutImmunityAbAttr, opponent, blockedByAbility); return !blockedByAbility.value; } @@ -5584,7 +5688,7 @@ class ForceSwitchOutHelper { * @returns The failure message, or `null` if no failure. */ public getFailedText(target: Pokemon): string | null { - const blockedByAbility = new Utils.BooleanHolder(false); + const blockedByAbility = new BooleanHolder(false); applyAbAttrs(ForceSwitchOutImmunityAbAttr, target, blockedByAbility); return blockedByAbility.value ? i18next.t("moveTriggers:cannotBeSwitchedOut", { pokemonName: getPokemonNameWithAffix(target) }) : null; } @@ -5603,7 +5707,7 @@ class ForceSwitchOutHelper { function calculateShellBellRecovery(pokemon: Pokemon): number { const shellBellModifier = pokemon.getHeldItems().find(m => m instanceof HitHealModifier); if (shellBellModifier) { - return Utils.toDmgValue(pokemon.turnData.totalDamageDealt / 8) * shellBellModifier.stackCount; + return toDmgValue(pokemon.turnData.totalDamageDealt / 8) * shellBellModifier.stackCount; } return 0; } @@ -5743,7 +5847,7 @@ function applyAbAttrsInternal( export function applyAbAttrs( attrType: Constructor, pokemon: Pokemon, - cancelled: Utils.BooleanHolder | null, + cancelled: BooleanHolder | null, simulated = false, ...args: any[] ): void { @@ -5778,7 +5882,7 @@ export function applyPreDefendAbAttrs( pokemon: Pokemon, attacker: Pokemon, move: Move | null, - cancelled: Utils.BooleanHolder | null, + cancelled: BooleanHolder | null, simulated = false, ...args: any[] ): void { @@ -5833,7 +5937,7 @@ export function applyStatMultiplierAbAttrs( attrType: Constructor, pokemon: Pokemon, stat: BattleStat, - statValue: Utils.NumberHolder, + statValue: NumberHolder, simulated = false, ...args: any[] ): void { @@ -5851,13 +5955,13 @@ export function applyStatMultiplierAbAttrs( * @param attrType - {@linkcode AllyStatMultiplierAbAttr} should always be AllyStatMultiplierAbAttr for the time being * @param pokemon - The {@linkcode Pokemon} with the ability * @param stat - The type of the checked {@linkcode Stat} - * @param statValue - {@linkcode Utils.NumberHolder} containing the value of the checked stat + * @param statValue - {@linkcode NumberHolder} containing the value of the checked stat * @param checkedPokemon - The {@linkcode Pokemon} with the checked stat * @param ignoreAbility - Whether or not the ability should be ignored by the pokemon or its move. * @param args - unused */ export function applyAllyStatMultiplierAbAttrs(attrType: Constructor, - pokemon: Pokemon, stat: BattleStat, statValue: Utils.NumberHolder, simulated: boolean = false, checkedPokemon: Pokemon, ignoreAbility: boolean, ...args: any[] + pokemon: Pokemon, stat: BattleStat, statValue: NumberHolder, simulated: boolean = false, checkedPokemon: Pokemon, ignoreAbility: boolean, ...args: any[] ): void { return applyAbAttrsInternal( attrType, @@ -5910,18 +6014,18 @@ export function applyPostDamageAbAttrs( * @param attrType {@linkcode FieldMultiplyStatAbAttr} should always be FieldMultiplyBattleStatAbAttr for the time being * @param pokemon {@linkcode Pokemon} the Pokemon applying this ability * @param stat {@linkcode Stat} the type of the checked stat - * @param statValue {@linkcode Utils.NumberHolder} the value of the checked stat + * @param statValue {@linkcode NumberHolder} the value of the checked stat * @param checkedPokemon {@linkcode Pokemon} the Pokemon with the checked stat - * @param hasApplied {@linkcode Utils.BooleanHolder} whether or not a FieldMultiplyBattleStatAbAttr has already affected this stat + * @param hasApplied {@linkcode BooleanHolder} whether or not a FieldMultiplyBattleStatAbAttr has already affected this stat * @param args unused */ export function applyFieldStatMultiplierAbAttrs( attrType: Constructor, pokemon: Pokemon, stat: Stat, - statValue: Utils.NumberHolder, + statValue: NumberHolder, checkedPokemon: Pokemon, - hasApplied: Utils.BooleanHolder, + hasApplied: BooleanHolder, simulated = false, ...args: any[] ): void { @@ -6018,6 +6122,20 @@ export function applyPostSummonAbAttrs( ); } +export function applyPreSummonAbAttrs( + attrType: Constructor, + pokemon: Pokemon, + ...args: any[] +): void { + applyAbAttrsInternal( + attrType, + pokemon, + (attr, passive) => attr.applyPreSummon(pokemon, passive, args), + (attr, passive) => attr.canApplyPreSummon(pokemon, passive, args), + args + ); +} + export function applyPreSwitchOutAbAttrs( attrType: Constructor, pokemon: Pokemon, @@ -6055,7 +6173,7 @@ export function applyPreStatStageChangeAbAttrs, pokemon: Pokemon | null, stat: BattleStat, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, simulated = false, ...args: any[] ): void { @@ -6091,7 +6209,7 @@ export function applyPreSetStatusAbAttrs( attrType: Constructor, pokemon: Pokemon, effect: StatusEffect | undefined, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, simulated = false, ...args: any[] ): void { @@ -6109,7 +6227,7 @@ export function applyPreApplyBattlerTagAbAttrs( attrType: Constructor, pokemon: Pokemon, tag: BattlerTag, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, simulated = false, ...args: any[] ): void { @@ -6127,7 +6245,7 @@ export function applyPreWeatherEffectAbAttrs( attrType: Constructor, pokemon: Pokemon, weather: Weather | null, - cancelled: Utils.BooleanHolder, + cancelled: BooleanHolder, simulated = false, ...args: any[] ): void { @@ -6211,7 +6329,7 @@ export function applyPostTerrainChangeAbAttrs( export function applyCheckTrappedAbAttrs( attrType: Constructor, pokemon: Pokemon, - trapped: Utils.BooleanHolder, + trapped: BooleanHolder, otherPokemon: Pokemon, messages: string[], simulated = false, @@ -6539,7 +6657,7 @@ export function initAbilities() { .bypassFaint() .ignorable(), new Ability(Abilities.SHED_SKIN, 3) - .conditionalAttr(pokemon => !Utils.randSeedInt(3), PostTurnResetStatusAbAttr), + .conditionalAttr(pokemon => !randSeedInt(3), PostTurnResetStatusAbAttr), new Ability(Abilities.GUTS, 3) .attr(BypassBurnDamageReductionAbAttr) .conditionalAttr(pokemon => !!pokemon.status || pokemon.hasAbility(Abilities.COMATOSE), StatMultiplierAbAttr, Stat.ATK, 1.5), @@ -6661,7 +6779,7 @@ export function initAbilities() { .attr(ChangeMovePriorityAbAttr, (pokemon, move: Move) => true, -0.2), new Ability(Abilities.TECHNICIAN, 4) .attr(MovePowerBoostAbAttr, (user, target, move) => { - const power = new Utils.NumberHolder(move.power); + const power = new NumberHolder(move.power); applyMoveAttrs(VariablePowerAttr, user, target, move, power); return power.value <= 60; }, 1.5), @@ -6755,7 +6873,7 @@ export function initAbilities() { .attr(PostDefendMoveDisableAbAttr, 30) .bypassFaint(), new Ability(Abilities.HEALER, 5) - .conditionalAttr(pokemon => !Utils.isNullOrUndefined(pokemon.getAlly()) && Utils.randSeedInt(10) < 3, PostTurnResetStatusAbAttr, true), + .conditionalAttr(pokemon => !isNullOrUndefined(pokemon.getAlly()) && randSeedInt(10) < 3, PostTurnResetStatusAbAttr, true), new Ability(Abilities.FRIEND_GUARD, 5) .attr(AlliedFieldDamageReductionAbAttr, 0.75) .ignorable(), @@ -6809,11 +6927,17 @@ export function initAbilities() { new Ability(Abilities.ANALYTIC, 5) .attr(MovePowerBoostAbAttr, (user, target, move) => { const movePhase = globalScene.findPhase((phase) => phase instanceof MovePhase && phase.pokemon.id !== user?.id); - return Utils.isNullOrUndefined(movePhase); + return isNullOrUndefined(movePhase); }, 1.3), new Ability(Abilities.ILLUSION, 5) + //The pokemon generate an illusion if it's available + .attr(IllusionPreSummonAbAttr, false) + //The pokemon loses his illusion when he is damaged by a move + .attr(IllusionBreakAbAttr, true) + //Illusion is available again after a battle + .conditionalAttr((pokemon) => pokemon.isAllowedInBattle(), IllusionPostBattleAbAttr, false) .uncopiable() - .unimplemented(), + .bypassFaint(), new Ability(Abilities.IMPOSTER, 5) .attr(PostSummonTransformAbAttr) .uncopiable(), @@ -7032,7 +7156,7 @@ export function initAbilities() { .attr(FormBlockDamageAbAttr, (target, user, move) => !!target.getTag(BattlerTagType.DISGUISE) && target.getMoveEffectiveness(user, move) > 0, 0, BattlerTagType.DISGUISE, (pokemon, abilityName) => i18next.t("abilityTriggers:disguiseAvoidedDamage", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName: abilityName }), - (pokemon) => Utils.toDmgValue(pokemon.getMaxHp() / 8)) + (pokemon) => toDmgValue(pokemon.getMaxHp() / 8)) .attr(PostBattleInitFormChangeAbAttr, () => 0) .uncopiable() .unreplaceable() @@ -7224,6 +7348,8 @@ export function initAbilities() { .attr(PreLeaveFieldRemoveSuppressAbilitiesSourceAbAttr) .uncopiable() .attr(NoTransformAbilityAbAttr) + .attr(PostSummonMessageAbAttr, (pokemon: Pokemon) => i18next.t("abilityTriggers:postSummonNeutralizingGas", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })) + .attr(PostSummonRemoveIllusionAbAttr) .bypassFaint(), new Ability(Abilities.PASTEL_VEIL, 8) .attr(PostSummonUserFieldRemoveStatusEffectAbAttr, StatusEffect.POISON, StatusEffect.TOXIC) diff --git a/src/data/balance/biomes.ts b/src/data/balance/biomes.ts index 3dff1722af6..c722291c66d 100644 --- a/src/data/balance/biomes.ts +++ b/src/data/balance/biomes.ts @@ -1,5 +1,5 @@ import { PokemonType } from "#enums/pokemon-type"; -import * as Utils from "#app/utils"; +import { randSeedInt, getEnumValues } from "#app/utils"; import type { SpeciesFormEvolution } from "#app/data/balance/pokemon-evolutions"; import { pokemonEvolutions } from "#app/data/balance/pokemon-evolutions"; import i18next from "i18next"; @@ -7710,7 +7710,7 @@ export function initBiomes() { if (biome === Biome.END) { const biomeList = Object.keys(Biome).filter(key => !Number.isNaN(Number(key))); biomeList.pop(); // Removes Biome.END from the list - const randIndex = Utils.randSeedInt(biomeList.length, 1); // Will never be Biome.TOWN + const randIndex = randSeedInt(biomeList.length, 1); // Will never be Biome.TOWN biome = Biome[biomeList[randIndex]]; } const linkedBiomes: (Biome | [ Biome, number ])[] = Array.isArray(biomeLinks[biome]) @@ -7733,15 +7733,15 @@ export function initBiomes() { traverseBiome(Biome.TOWN, 0); biomeDepths[Biome.END] = [ Object.values(biomeDepths).map(d => d[0]).reduce((max: number, value: number) => Math.max(max, value), 0) + 1, 1 ]; - for (const biome of Utils.getEnumValues(Biome)) { + for (const biome of getEnumValues(Biome)) { biomePokemonPools[biome] = {}; biomeTrainerPools[biome] = {}; - for (const tier of Utils.getEnumValues(BiomePoolTier)) { + for (const tier of getEnumValues(BiomePoolTier)) { biomePokemonPools[biome][tier] = {}; biomeTrainerPools[biome][tier] = []; - for (const tod of Utils.getEnumValues(TimeOfDay)) { + for (const tod of getEnumValues(TimeOfDay)) { biomePokemonPools[biome][tier][tod] = []; } } diff --git a/src/data/balance/egg-moves.ts b/src/data/balance/egg-moves.ts index 19038ad824c..74f6a2c1afb 100644 --- a/src/data/balance/egg-moves.ts +++ b/src/data/balance/egg-moves.ts @@ -1,5 +1,5 @@ import { allMoves } from "#app/data/moves/move"; -import * as Utils from "#app/utils"; +import { getEnumKeys, getEnumValues } from "#app/utils"; import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; @@ -587,8 +587,8 @@ export const speciesEggMoves = { function parseEggMoves(content: string): void { let output = ""; - const speciesNames = Utils.getEnumKeys(Species); - const speciesValues = Utils.getEnumValues(Species); + const speciesNames = getEnumKeys(Species); + const speciesValues = getEnumValues(Species); const lines = content.split(/\n/g); for (const line of lines) { diff --git a/src/data/balance/pokemon-evolutions.ts b/src/data/balance/pokemon-evolutions.ts index e49bd049cd6..17f71f3c3c9 100644 --- a/src/data/balance/pokemon-evolutions.ts +++ b/src/data/balance/pokemon-evolutions.ts @@ -3,7 +3,7 @@ import { Gender } from "#app/data/gender"; import { PokeballType } from "#enums/pokeball"; import type Pokemon from "#app/field/pokemon"; import { PokemonType } from "#enums/pokemon-type"; -import * as Utils from "#app/utils"; +import { randSeedInt } from "#app/utils"; import { WeatherType } from "#enums/weather-type"; import { Nature } from "#enums/nature"; import { Biome } from "#enums/biome"; @@ -333,7 +333,7 @@ class DunsparceEvolutionCondition extends SpeciesEvolutionCondition { super(p => { let ret = false; if (p.moveset.filter(m => m.moveId === Moves.HYPER_DRILL).length > 0) { - globalScene.executeWithSeedOffset(() => ret = !Utils.randSeedInt(4), p.id); + globalScene.executeWithSeedOffset(() => ret = !randSeedInt(4), p.id); } return ret; }); @@ -346,7 +346,7 @@ class TandemausEvolutionCondition extends SpeciesEvolutionCondition { constructor() { super(p => { let ret = false; - globalScene.executeWithSeedOffset(() => ret = !Utils.randSeedInt(4), p.id); + globalScene.executeWithSeedOffset(() => ret = !randSeedInt(4), p.id); return ret; }); } diff --git a/src/data/balance/tms.ts b/src/data/balance/tms.ts index 788ffd4f273..62199fd6968 100644 --- a/src/data/balance/tms.ts +++ b/src/data/balance/tms.ts @@ -19126,6 +19126,8 @@ export const tmSpecies: TmSpecies = { Species.KROOKODILE, Species.SCRAGGY, Species.SCRAFTY, + Species.YAMASK, + Species.COFAGRIGUS, Species.SAWSBUCK, Species.LITWICK, Species.LAMPENT, @@ -19163,6 +19165,7 @@ export const tmSpecies: TmSpecies = { Species.SINISTEA, Species.POLTEAGEIST, Species.PERRSERKER, + Species.RUNERIGUS, Species.PINCURCHIN, Species.STONJOURNER, Species.CUFANT, @@ -19228,6 +19231,7 @@ export const tmSpecies: TmSpecies = { Species.GALAR_SLOWBRO, Species.GALAR_WEEZING, Species.GALAR_SLOWKING, + Species.GALAR_YAMASK, Species.HISUI_ELECTRODE, Species.HISUI_TYPHLOSION, Species.HISUI_QWILFISH, @@ -30922,6 +30926,7 @@ export const tmSpecies: TmSpecies = { Species.MURKROW, Species.SLOWKING, Species.MISDREAVUS, + Species.UNOWN, Species.GIRAFARIG, Species.PINECO, Species.FORRETRESS, @@ -40134,6 +40139,8 @@ export const tmSpecies: TmSpecies = { Species.MEOWSTIC, Species.SPRITZEE, Species.AROMATISSE, + Species.INKAY, + Species.MALAMAR, Species.SYLVEON, Species.CARBINK, Species.PHANTUMP, @@ -49173,6 +49180,7 @@ export const tmSpecies: TmSpecies = { Species.KANGASKHAN, Species.GOLDEEN, Species.SEAKING, + Species.GYARADOS, Species.LAPRAS, Species.VAPOREON, Species.KABUTOPS, @@ -52587,6 +52595,7 @@ export const tmSpecies: TmSpecies = { Species.SNORLAX, Species.MEWTWO, Species.MEW, + Species.MEGANIUM, Species.CYNDAQUIL, Species.QUILAVA, Species.TYPHLOSION, @@ -66205,7 +66214,11 @@ export const tmSpecies: TmSpecies = { Species.SQUIRTLE, Species.WARTORTLE, Species.BLASTOISE, + Species.CATERPIE, + Species.METAPOD, Species.BUTTERFREE, + Species.WEEDLE, + Species.KAKUNA, Species.BEEDRILL, Species.PIDGEY, Species.PIDGEOTTO, @@ -66451,7 +66464,10 @@ export const tmSpecies: TmSpecies = { Species.MIGHTYENA, Species.ZIGZAGOON, Species.LINOONE, + Species.WURMPLE, + Species.SILCOON, Species.BEAUTIFLY, + Species.CASCOON, Species.DUSTOX, Species.LOTAD, Species.LOMBRE, @@ -66987,6 +67003,8 @@ export const tmSpecies: TmSpecies = { Species.STAKATAKA, Species.BLACEPHALON, Species.ZERAORA, + Species.MELTAN, + Species.MELMETAL, Species.ALOLA_RATTATA, Species.ALOLA_RATICATE, Species.ALOLA_RAICHU, @@ -67020,8 +67038,19 @@ export const tmSpecies: TmSpecies = { Species.ROOKIDEE, Species.CORVISQUIRE, Species.CORVIKNIGHT, + Species.BLIPBUG, + Species.DOTTLER, + Species.ORBEETLE, + Species.NICKIT, + Species.THIEVUL, + Species.GOSSIFLEUR, + Species.ELDEGOSS, + Species.WOOLOO, + Species.DUBWOOL, Species.CHEWTLE, Species.DREDNAW, + Species.YAMPER, + Species.BOLTUND, Species.ROLYCOLY, Species.CARKOL, Species.COALOSSAL, @@ -67035,6 +67064,10 @@ export const tmSpecies: TmSpecies = { Species.BARRASKEWDA, Species.TOXEL, Species.TOXTRICITY, + Species.SIZZLIPEDE, + Species.CENTISKORCH, + Species.CLOBBOPUS, + Species.GRAPPLOCT, Species.SINISTEA, Species.POLTEAGEIST, Species.HATENNA, @@ -67043,7 +67076,14 @@ export const tmSpecies: TmSpecies = { Species.IMPIDIMP, Species.MORGREM, Species.GRIMMSNARL, + Species.OBSTAGOON, Species.PERRSERKER, + Species.CURSOLA, + Species.SIRFETCHD, + Species.MR_RIME, + Species.RUNERIGUS, + Species.MILCERY, + Species.ALCREMIE, Species.FALINKS, Species.PINCURCHIN, Species.SNOM, @@ -67054,6 +67094,11 @@ export const tmSpecies: TmSpecies = { Species.MORPEKO, Species.CUFANT, Species.COPPERAJAH, + Species.DRACOZOLT, + Species.ARCTOZOLT, + Species.DRACOVISH, + Species.ARCTOVISH, + Species.DURALUDON, Species.DREEPY, Species.DRAKLOAK, Species.DRAGAPULT, @@ -67195,13 +67240,24 @@ export const tmSpecies: TmSpecies = { Species.IRON_CROWN, Species.PECHARUNT, Species.GALAR_MEOWTH, + Species.GALAR_PONYTA, + Species.GALAR_RAPIDASH, Species.GALAR_SLOWPOKE, Species.GALAR_SLOWBRO, + Species.GALAR_FARFETCHD, Species.GALAR_WEEZING, + Species.GALAR_MR_MIME, Species.GALAR_ARTICUNO, Species.GALAR_ZAPDOS, Species.GALAR_MOLTRES, Species.GALAR_SLOWKING, + Species.GALAR_CORSOLA, + Species.GALAR_ZIGZAGOON, + Species.GALAR_LINOONE, + Species.GALAR_DARUMAKA, + Species.GALAR_DARMANITAN, + Species.GALAR_YAMASK, + Species.GALAR_STUNFISK, Species.HISUI_GROWLITHE, Species.HISUI_ARCANINE, Species.HISUI_VOLTORB, diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index 546dbb4a3db..76e91485460 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -42,7 +42,7 @@ import { Species } from "#enums/species"; import { EFFECTIVE_STATS, getStatKey, Stat, type BattleStat, type EffectiveStat } from "#enums/stat"; import { StatusEffect } from "#enums/status-effect"; import { WeatherType } from "#enums/weather-type"; -import * as Utils from "../utils"; +import { isNullOrUndefined } from "#app/utils"; export enum BattlerTagLapseType { FAINT, @@ -302,7 +302,7 @@ export class DisabledTag extends MoveRestrictionBattlerTag { super.onAdd(pokemon); const move = pokemon.getLastXMoves(-1).find(m => !m.virtual); - if (Utils.isNullOrUndefined(move) || move.move === Moves.STRUGGLE || move.move === Moves.NONE) { + if (isNullOrUndefined(move) || move.move === Moves.STRUGGLE || move.move === Moves.NONE) { return; } diff --git a/src/data/berry.ts b/src/data/berry.ts index 13820b1277b..8a58d337aa4 100644 --- a/src/data/berry.ts +++ b/src/data/berry.ts @@ -2,7 +2,7 @@ import { getPokemonNameWithAffix } from "../messages"; import type Pokemon from "../field/pokemon"; import { HitResult } from "../field/pokemon"; import { getStatusEffectHealText } from "./status-effect"; -import * as Utils from "../utils"; +import { NumberHolder, toDmgValue, randSeedInt } from "#app/utils"; import { DoubleBerryEffectAbAttr, PostItemLostAbAttr, @@ -43,7 +43,7 @@ export function getBerryPredicate(berryType: BerryType): BerryPredicate { case BerryType.APICOT: case BerryType.SALAC: return (pokemon: Pokemon) => { - const threshold = new Utils.NumberHolder(0.25); + const threshold = new NumberHolder(0.25); // Offset BerryType such that LIECHI -> Stat.ATK = 1, GANLON -> Stat.DEF = 2, so on and so forth const stat: BattleStat = berryType - BerryType.ENIGMA; applyAbAttrs(ReduceBerryUseThresholdAbAttr, pokemon, null, false, threshold); @@ -51,19 +51,19 @@ export function getBerryPredicate(berryType: BerryType): BerryPredicate { }; case BerryType.LANSAT: return (pokemon: Pokemon) => { - const threshold = new Utils.NumberHolder(0.25); + const threshold = new NumberHolder(0.25); applyAbAttrs(ReduceBerryUseThresholdAbAttr, pokemon, null, false, threshold); return pokemon.getHpRatio() < 0.25 && !pokemon.getTag(BattlerTagType.CRIT_BOOST); }; case BerryType.STARF: return (pokemon: Pokemon) => { - const threshold = new Utils.NumberHolder(0.25); + const threshold = new NumberHolder(0.25); applyAbAttrs(ReduceBerryUseThresholdAbAttr, pokemon, null, false, threshold); return pokemon.getHpRatio() < 0.25; }; case BerryType.LEPPA: return (pokemon: Pokemon) => { - const threshold = new Utils.NumberHolder(0.25); + const threshold = new NumberHolder(0.25); applyAbAttrs(ReduceBerryUseThresholdAbAttr, pokemon, null, false, threshold); return !!pokemon.getMoveset().find(m => !m.getPpRatio()); }; @@ -80,7 +80,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc { if (pokemon.battleData) { pokemon.battleData.berriesEaten.push(berryType); } - const hpHealed = new Utils.NumberHolder(Utils.toDmgValue(pokemon.getMaxHp() / 4)); + const hpHealed = new NumberHolder(toDmgValue(pokemon.getMaxHp() / 4)); applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, hpHealed); globalScene.unshiftPhase( new PokemonHealPhase( @@ -118,7 +118,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc { } // Offset BerryType such that LIECHI -> Stat.ATK = 1, GANLON -> Stat.DEF = 2, so on and so forth const stat: BattleStat = berryType - BerryType.ENIGMA; - const statStages = new Utils.NumberHolder(1); + const statStages = new NumberHolder(1); applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, statStages); globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [stat], statStages.value)); applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false); @@ -136,8 +136,8 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc { if (pokemon.battleData) { pokemon.battleData.berriesEaten.push(berryType); } - const randStat = Utils.randSeedInt(Stat.SPD, Stat.ATK); - const stages = new Utils.NumberHolder(2); + const randStat = randSeedInt(Stat.SPD, Stat.ATK); + const stages = new NumberHolder(2); applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, stages); globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [randStat], stages.value)); applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false); diff --git a/src/data/challenge.ts b/src/data/challenge.ts index 868fc7d2e60..51616c3f00f 100644 --- a/src/data/challenge.ts +++ b/src/data/challenge.ts @@ -1,4 +1,4 @@ -import * as Utils from "#app/utils"; +import { BooleanHolder, type NumberHolder, randSeedItem, deepCopy } from "#app/utils"; import i18next from "i18next"; import type { DexAttrProps, GameData } from "#app/system/game-data"; import { defaultStarterSpecies } from "#app/system/game-data"; @@ -283,30 +283,30 @@ export abstract class Challenge { /** * An apply function for STARTER_CHOICE challenges. Derived classes should alter this. * @param _pokemon {@link PokemonSpecies} The pokemon to check the validity of. - * @param _valid {@link Utils.BooleanHolder} A BooleanHolder, the value gets set to false if the pokemon isn't allowed. + * @param _valid {@link BooleanHolder} A BooleanHolder, the value gets set to false if the pokemon isn't allowed. * @param _dexAttr {@link DexAttrProps} The dex attributes of the pokemon. * @returns {@link boolean} Whether this function did anything. */ - applyStarterChoice(_pokemon: PokemonSpecies, _valid: Utils.BooleanHolder, _dexAttr: DexAttrProps): boolean { + applyStarterChoice(_pokemon: PokemonSpecies, _valid: BooleanHolder, _dexAttr: DexAttrProps): boolean { return false; } /** * An apply function for STARTER_POINTS challenges. Derived classes should alter this. - * @param _points {@link Utils.NumberHolder} The amount of points you have available. + * @param _points {@link NumberHolder} The amount of points you have available. * @returns {@link boolean} Whether this function did anything. */ - applyStarterPoints(_points: Utils.NumberHolder): boolean { + applyStarterPoints(_points: NumberHolder): boolean { return false; } /** * An apply function for STARTER_COST challenges. Derived classes should alter this. * @param _species {@link Species} The pokemon to change the cost of. - * @param _cost {@link Utils.NumberHolder} The cost of the starter. + * @param _cost {@link NumberHolder} The cost of the starter. * @returns {@link boolean} Whether this function did anything. */ - applyStarterCost(_species: Species, _cost: Utils.NumberHolder): boolean { + applyStarterCost(_species: Species, _cost: NumberHolder): boolean { return false; } @@ -322,10 +322,10 @@ export abstract class Challenge { /** * An apply function for POKEMON_IN_BATTLE challenges. Derived classes should alter this. * @param _pokemon {@link Pokemon} The pokemon to check the validity of. - * @param _valid {@link Utils.BooleanHolder} A BooleanHolder, the value gets set to false if the pokemon isn't allowed. + * @param _valid {@link BooleanHolder} A BooleanHolder, the value gets set to false if the pokemon isn't allowed. * @returns {@link boolean} Whether this function did anything. */ - applyPokemonInBattle(_pokemon: Pokemon, _valid: Utils.BooleanHolder): boolean { + applyPokemonInBattle(_pokemon: Pokemon, _valid: BooleanHolder): boolean { return false; } @@ -341,42 +341,42 @@ export abstract class Challenge { /** * An apply function for TYPE_EFFECTIVENESS challenges. Derived classes should alter this. - * @param _effectiveness {@linkcode Utils.NumberHolder} The current effectiveness of the move. + * @param _effectiveness {@linkcode NumberHolder} The current effectiveness of the move. * @returns Whether this function did anything. */ - applyTypeEffectiveness(_effectiveness: Utils.NumberHolder): boolean { + applyTypeEffectiveness(_effectiveness: NumberHolder): boolean { return false; } /** * An apply function for AI_LEVEL challenges. Derived classes should alter this. - * @param _level {@link Utils.NumberHolder} The generated level. + * @param _level {@link NumberHolder} The generated level. * @param _levelCap {@link Number} The current level cap. * @param _isTrainer {@link Boolean} Whether this is a trainer pokemon. * @param _isBoss {@link Boolean} Whether this is a non-trainer boss pokemon. * @returns {@link boolean} Whether this function did anything. */ - applyLevelChange(_level: Utils.NumberHolder, _levelCap: number, _isTrainer: boolean, _isBoss: boolean): boolean { + applyLevelChange(_level: NumberHolder, _levelCap: number, _isTrainer: boolean, _isBoss: boolean): boolean { return false; } /** * An apply function for AI_MOVE_SLOTS challenges. Derived classes should alter this. * @param pokemon {@link Pokemon} The pokemon that is being considered. - * @param moveSlots {@link Utils.NumberHolder} The amount of move slots. + * @param moveSlots {@link NumberHolder} The amount of move slots. * @returns {@link boolean} Whether this function did anything. */ - applyMoveSlot(_pokemon: Pokemon, _moveSlots: Utils.NumberHolder): boolean { + applyMoveSlot(_pokemon: Pokemon, _moveSlots: NumberHolder): boolean { return false; } /** * An apply function for PASSIVE_ACCESS challenges. Derived classes should alter this. * @param pokemon {@link Pokemon} The pokemon to change. - * @param hasPassive {@link Utils.BooleanHolder} Whether it should have its passive. + * @param hasPassive {@link BooleanHolder} Whether it should have its passive. * @returns {@link boolean} Whether this function did anything. */ - applyPassiveAccess(_pokemon: Pokemon, _hasPassive: Utils.BooleanHolder): boolean { + applyPassiveAccess(_pokemon: Pokemon, _hasPassive: BooleanHolder): boolean { return false; } @@ -393,15 +393,10 @@ export abstract class Challenge { * @param _pokemon {@link Pokemon} What pokemon would learn the move. * @param _moveSource {@link MoveSourceType} What source the pokemon would get the move from. * @param _move {@link Moves} The move in question. - * @param _level {@link Utils.NumberHolder} The level threshold for access. + * @param _level {@link NumberHolder} The level threshold for access. * @returns {@link boolean} Whether this function did anything. */ - applyMoveAccessLevel( - _pokemon: Pokemon, - _moveSource: MoveSourceType, - _move: Moves, - _level: Utils.NumberHolder, - ): boolean { + applyMoveAccessLevel(_pokemon: Pokemon, _moveSource: MoveSourceType, _move: Moves, _level: NumberHolder): boolean { return false; } @@ -410,10 +405,10 @@ export abstract class Challenge { * @param _pokemon {@link Pokemon} What pokemon would learn the move. * @param _moveSource {@link MoveSourceType} What source the pokemon would get the move from. * @param _move {@link Moves} The move in question. - * @param _weight {@link Utils.NumberHolder} The base weight of the move + * @param _weight {@link NumberHolder} The base weight of the move * @returns {@link boolean} Whether this function did anything. */ - applyMoveWeight(_pokemon: Pokemon, _moveSource: MoveSourceType, _move: Moves, _level: Utils.NumberHolder): boolean { + applyMoveWeight(_pokemon: Pokemon, _moveSource: MoveSourceType, _move: Moves, _level: NumberHolder): boolean { return false; } @@ -438,7 +433,7 @@ export class SingleGenerationChallenge extends Challenge { super(Challenges.SINGLE_GENERATION, 9); } - applyStarterChoice(pokemon: PokemonSpecies, valid: Utils.BooleanHolder): boolean { + applyStarterChoice(pokemon: PokemonSpecies, valid: BooleanHolder): boolean { if (pokemon.generation !== this.value) { valid.value = false; return true; @@ -446,7 +441,7 @@ export class SingleGenerationChallenge extends Challenge { return false; } - applyPokemonInBattle(pokemon: Pokemon, valid: Utils.BooleanHolder): boolean { + applyPokemonInBattle(pokemon: Pokemon, valid: BooleanHolder): boolean { const baseGeneration = getPokemonSpecies(pokemon.species.speciesId).generation; const fusionGeneration = pokemon.isFusion() ? getPokemonSpecies(pokemon.fusionSpecies!.speciesId).generation : 0; if ( @@ -575,7 +570,7 @@ export class SingleGenerationChallenge extends Challenge { TrainerType.AARON, TrainerType.SHAUNTAL, TrainerType.MALVA, - Utils.randSeedItem([TrainerType.HALA, TrainerType.MOLAYNE]), + randSeedItem([TrainerType.HALA, TrainerType.MOLAYNE]), TrainerType.MARNIE_ELITE, TrainerType.RIKA, ]; @@ -602,7 +597,7 @@ export class SingleGenerationChallenge extends Challenge { TrainerType.GRIMSLEY, TrainerType.WIKSTROM, TrainerType.ACEROLA, - Utils.randSeedItem([TrainerType.BEA_ELITE, TrainerType.ALLISTER_ELITE]), + randSeedItem([TrainerType.BEA_ELITE, TrainerType.ALLISTER_ELITE]), TrainerType.LARRY_ELITE, ]; break; @@ -622,14 +617,14 @@ export class SingleGenerationChallenge extends Challenge { case ClassicFixedBossWaves.CHAMPION: trainerTypes = [ TrainerType.BLUE, - Utils.randSeedItem([TrainerType.RED, TrainerType.LANCE_CHAMPION]), - Utils.randSeedItem([TrainerType.STEVEN, TrainerType.WALLACE]), + randSeedItem([TrainerType.RED, TrainerType.LANCE_CHAMPION]), + randSeedItem([TrainerType.STEVEN, TrainerType.WALLACE]), TrainerType.CYNTHIA, - Utils.randSeedItem([TrainerType.ALDER, TrainerType.IRIS]), + randSeedItem([TrainerType.ALDER, TrainerType.IRIS]), TrainerType.DIANTHA, - Utils.randSeedItem([TrainerType.KUKUI, TrainerType.HAU]), - Utils.randSeedItem([TrainerType.LEON, TrainerType.MUSTARD]), - Utils.randSeedItem([TrainerType.GEETA, TrainerType.NEMONA]), + randSeedItem([TrainerType.KUKUI, TrainerType.HAU]), + randSeedItem([TrainerType.LEON, TrainerType.MUSTARD]), + randSeedItem([TrainerType.GEETA, TrainerType.NEMONA]), ]; break; } @@ -718,7 +713,7 @@ export class SingleTypeChallenge extends Challenge { super(Challenges.SINGLE_TYPE, 18); } - override applyStarterChoice(pokemon: PokemonSpecies, valid: Utils.BooleanHolder, dexAttr: DexAttrProps): boolean { + override applyStarterChoice(pokemon: PokemonSpecies, valid: BooleanHolder, dexAttr: DexAttrProps): boolean { const speciesForm = getPokemonSpeciesForm(pokemon.speciesId, dexAttr.formIndex); const types = [speciesForm.type1, speciesForm.type2]; if (!types.includes(this.value - 1)) { @@ -728,7 +723,7 @@ export class SingleTypeChallenge extends Challenge { return false; } - applyPokemonInBattle(pokemon: Pokemon, valid: Utils.BooleanHolder): boolean { + applyPokemonInBattle(pokemon: Pokemon, valid: BooleanHolder): boolean { if ( pokemon.isPlayer() && !pokemon.isOfType(this.value - 1, false, false, true) && @@ -798,7 +793,7 @@ export class FreshStartChallenge extends Challenge { super(Challenges.FRESH_START, 1); } - applyStarterChoice(pokemon: PokemonSpecies, valid: Utils.BooleanHolder): boolean { + applyStarterChoice(pokemon: PokemonSpecies, valid: BooleanHolder): boolean { if (!defaultStarterSpecies.includes(pokemon.speciesId)) { valid.value = false; return true; @@ -806,7 +801,7 @@ export class FreshStartChallenge extends Challenge { return false; } - applyStarterCost(species: Species, cost: Utils.NumberHolder): boolean { + applyStarterCost(species: Species, cost: NumberHolder): boolean { if (defaultStarterSpecies.includes(species)) { cost.value = speciesStarterCosts[species]; return true; @@ -864,7 +859,7 @@ export class InverseBattleChallenge extends Challenge { return 0; } - applyTypeEffectiveness(effectiveness: Utils.NumberHolder): boolean { + applyTypeEffectiveness(effectiveness: NumberHolder): boolean { if (effectiveness.value < 1) { effectiveness.value = 2; return true; @@ -887,7 +882,7 @@ export class FlipStatChallenge extends Challenge { } override applyFlipStat(_pokemon: Pokemon, baseStats: number[]) { - const origStats = Utils.deepCopy(baseStats); + const origStats = deepCopy(baseStats); baseStats[0] = origStats[5]; baseStats[1] = origStats[4]; baseStats[2] = origStats[3]; @@ -923,7 +918,7 @@ export class LowerStarterMaxCostChallenge extends Challenge { return (DEFAULT_PARTY_MAX_COST - overrideValue).toString(); } - applyStarterChoice(pokemon: PokemonSpecies, valid: Utils.BooleanHolder): boolean { + applyStarterChoice(pokemon: PokemonSpecies, valid: BooleanHolder): boolean { if (speciesStarterCosts[pokemon.speciesId] > DEFAULT_PARTY_MAX_COST - this.value) { valid.value = false; return true; @@ -957,7 +952,7 @@ export class LowerStarterPointsChallenge extends Challenge { return (DEFAULT_PARTY_MAX_COST - overrideValue).toString(); } - applyStarterPoints(points: Utils.NumberHolder): boolean { + applyStarterPoints(points: NumberHolder): boolean { points.value -= this.value; return true; } @@ -974,34 +969,34 @@ export class LowerStarterPointsChallenge extends Challenge { * Apply all challenges that modify starter choice. * @param challengeType {@link ChallengeType} ChallengeType.STARTER_CHOICE * @param pokemon {@link PokemonSpecies} The pokemon to check the validity of. - * @param valid {@link Utils.BooleanHolder} A BooleanHolder, the value gets set to false if the pokemon isn't allowed. + * @param valid {@link BooleanHolder} A BooleanHolder, the value gets set to false if the pokemon isn't allowed. * @param dexAttr {@link DexAttrProps} The dex attributes of the pokemon. * @returns True if any challenge was successfully applied. */ export function applyChallenges( challengeType: ChallengeType.STARTER_CHOICE, pokemon: PokemonSpecies, - valid: Utils.BooleanHolder, + valid: BooleanHolder, dexAttr: DexAttrProps, ): boolean; /** * Apply all challenges that modify available total starter points. * @param challengeType {@link ChallengeType} ChallengeType.STARTER_POINTS - * @param points {@link Utils.NumberHolder} The amount of points you have available. + * @param points {@link NumberHolder} The amount of points you have available. * @returns True if any challenge was successfully applied. */ -export function applyChallenges(challengeType: ChallengeType.STARTER_POINTS, points: Utils.NumberHolder): boolean; +export function applyChallenges(challengeType: ChallengeType.STARTER_POINTS, points: NumberHolder): boolean; /** * Apply all challenges that modify the cost of a starter. * @param challengeType {@link ChallengeType} ChallengeType.STARTER_COST * @param species {@link Species} The pokemon to change the cost of. - * @param points {@link Utils.NumberHolder} The cost of the pokemon. + * @param points {@link NumberHolder} The cost of the pokemon. * @returns True if any challenge was successfully applied. */ export function applyChallenges( challengeType: ChallengeType.STARTER_COST, species: Species, - cost: Utils.NumberHolder, + cost: NumberHolder, ): boolean; /** * Apply all challenges that modify a starter after selection. @@ -1014,13 +1009,13 @@ export function applyChallenges(challengeType: ChallengeType.STARTER_MODIFY, pok * Apply all challenges that what pokemon you can have in battle. * @param challengeType {@link ChallengeType} ChallengeType.POKEMON_IN_BATTLE * @param pokemon {@link Pokemon} The pokemon to check the validity of. - * @param valid {@link Utils.BooleanHolder} A BooleanHolder, the value gets set to false if the pokemon isn't allowed. + * @param valid {@link BooleanHolder} A BooleanHolder, the value gets set to false if the pokemon isn't allowed. * @returns True if any challenge was successfully applied. */ export function applyChallenges( challengeType: ChallengeType.POKEMON_IN_BATTLE, pokemon: Pokemon, - valid: Utils.BooleanHolder, + valid: BooleanHolder, ): boolean; /** * Apply all challenges that modify what fixed battles there are. @@ -1037,17 +1032,14 @@ export function applyChallenges( /** * Apply all challenges that modify type effectiveness. * @param challengeType {@linkcode ChallengeType} ChallengeType.TYPE_EFFECTIVENESS - * @param effectiveness {@linkcode Utils.NumberHolder} The current effectiveness of the move. + * @param effectiveness {@linkcode NumberHolder} The current effectiveness of the move. * @returns True if any challenge was successfully applied. */ -export function applyChallenges( - challengeType: ChallengeType.TYPE_EFFECTIVENESS, - effectiveness: Utils.NumberHolder, -): boolean; +export function applyChallenges(challengeType: ChallengeType.TYPE_EFFECTIVENESS, effectiveness: NumberHolder): boolean; /** * Apply all challenges that modify what level AI are. * @param challengeType {@link ChallengeType} ChallengeType.AI_LEVEL - * @param level {@link Utils.NumberHolder} The generated level of the pokemon. + * @param level {@link NumberHolder} The generated level of the pokemon. * @param levelCap {@link Number} The maximum level cap for the current wave. * @param isTrainer {@link Boolean} Whether this is a trainer pokemon. * @param isBoss {@link Boolean} Whether this is a non-trainer boss pokemon. @@ -1055,7 +1047,7 @@ export function applyChallenges( */ export function applyChallenges( challengeType: ChallengeType.AI_LEVEL, - level: Utils.NumberHolder, + level: NumberHolder, levelCap: number, isTrainer: boolean, isBoss: boolean, @@ -1064,25 +1056,25 @@ export function applyChallenges( * Apply all challenges that modify how many move slots the AI has. * @param challengeType {@link ChallengeType} ChallengeType.AI_MOVE_SLOTS * @param pokemon {@link Pokemon} The pokemon being considered. - * @param moveSlots {@link Utils.NumberHolder} The amount of move slots. + * @param moveSlots {@link NumberHolder} The amount of move slots. * @returns True if any challenge was successfully applied. */ export function applyChallenges( challengeType: ChallengeType.AI_MOVE_SLOTS, pokemon: Pokemon, - moveSlots: Utils.NumberHolder, + moveSlots: NumberHolder, ): boolean; /** * Apply all challenges that modify whether a pokemon has its passive. * @param challengeType {@link ChallengeType} ChallengeType.PASSIVE_ACCESS * @param pokemon {@link Pokemon} The pokemon to modify. - * @param hasPassive {@link Utils.BooleanHolder} Whether it has its passive. + * @param hasPassive {@link BooleanHolder} Whether it has its passive. * @returns True if any challenge was successfully applied. */ export function applyChallenges( challengeType: ChallengeType.PASSIVE_ACCESS, pokemon: Pokemon, - hasPassive: Utils.BooleanHolder, + hasPassive: BooleanHolder, ): boolean; /** * Apply all challenges that modify the game modes settings. @@ -1096,7 +1088,7 @@ export function applyChallenges(challengeType: ChallengeType.GAME_MODE_MODIFY): * @param pokemon {@link Pokemon} What pokemon would learn the move. * @param moveSource {@link MoveSourceType} What source the pokemon would get the move from. * @param move {@link Moves} The move in question. - * @param level {@link Utils.NumberHolder} The level threshold for access. + * @param level {@link NumberHolder} The level threshold for access. * @returns True if any challenge was successfully applied. */ export function applyChallenges( @@ -1104,7 +1096,7 @@ export function applyChallenges( pokemon: Pokemon, moveSource: MoveSourceType, move: Moves, - level: Utils.NumberHolder, + level: NumberHolder, ): boolean; /** * Apply all challenges that modify what weight a pokemon gives to move generation @@ -1112,7 +1104,7 @@ export function applyChallenges( * @param pokemon {@link Pokemon} What pokemon would learn the move. * @param moveSource {@link MoveSourceType} What source the pokemon would get the move from. * @param move {@link Moves} The move in question. - * @param weight {@link Utils.NumberHolder} The weight of the move. + * @param weight {@link NumberHolder} The weight of the move. * @returns True if any challenge was successfully applied. */ export function applyChallenges( @@ -1120,7 +1112,7 @@ export function applyChallenges( pokemon: Pokemon, moveSource: MoveSourceType, move: Moves, - weight: Utils.NumberHolder, + weight: NumberHolder, ): boolean; export function applyChallenges(challengeType: ChallengeType.FLIP_STAT, pokemon: Pokemon, baseStats: number[]): boolean; @@ -1225,7 +1217,7 @@ export function initChallenges() { */ export function checkStarterValidForChallenge(species: PokemonSpecies, props: DexAttrProps, soft: boolean) { if (!soft) { - const isValidForChallenge = new Utils.BooleanHolder(true); + const isValidForChallenge = new BooleanHolder(true); applyChallenges(ChallengeType.STARTER_CHOICE, species, isValidForChallenge, props); return isValidForChallenge.value; } @@ -1263,7 +1255,7 @@ export function checkStarterValidForChallenge(species: PokemonSpecies, props: De * @returns `true` if the species is considered valid. */ function checkSpeciesValidForChallenge(species: PokemonSpecies, props: DexAttrProps, soft: boolean) { - const isValidForChallenge = new Utils.BooleanHolder(true); + const isValidForChallenge = new BooleanHolder(true); applyChallenges(ChallengeType.STARTER_CHOICE, species, isValidForChallenge, props); if (!soft || !pokemonFormChanges.hasOwnProperty(species.speciesId)) { return isValidForChallenge.value; @@ -1282,7 +1274,7 @@ function checkSpeciesValidForChallenge(species: PokemonSpecies, props: DexAttrPr return species.forms.some((f2, formIndex) => { if (f1.formKey === f2.formKey) { const formProps = { ...props, formIndex }; - const isFormValidForChallenge = new Utils.BooleanHolder(true); + const isFormValidForChallenge = new BooleanHolder(true); applyChallenges(ChallengeType.STARTER_CHOICE, species, isFormValidForChallenge, formProps); return isFormValidForChallenge.value; } diff --git a/src/data/daily-run.ts b/src/data/daily-run.ts index 22fb7db10ae..3438510d613 100644 --- a/src/data/daily-run.ts +++ b/src/data/daily-run.ts @@ -3,7 +3,7 @@ import type { Species } from "#enums/species"; import { globalScene } from "#app/global-scene"; import { PlayerPokemon } from "#app/field/pokemon"; import type { Starter } from "#app/ui/starter-select-ui-handler"; -import * as Utils from "#app/utils"; +import { randSeedGauss, randSeedInt, randSeedItem, getEnumValues } from "#app/utils"; import type { PokemonSpeciesForm } from "#app/data/pokemon-species"; import PokemonSpecies, { getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species"; import { speciesStarterCosts } from "#app/data/balance/starters"; @@ -43,8 +43,8 @@ export function getDailyRunStarters(seed: string): Starter[] { } const starterCosts: number[] = []; - starterCosts.push(Math.min(Math.round(3.5 + Math.abs(Utils.randSeedGauss(1))), 8)); - starterCosts.push(Utils.randSeedInt(9 - starterCosts[0], 1)); + starterCosts.push(Math.min(Math.round(3.5 + Math.abs(randSeedGauss(1))), 8)); + starterCosts.push(randSeedInt(9 - starterCosts[0], 1)); starterCosts.push(10 - (starterCosts[0] + starterCosts[1])); for (let c = 0; c < starterCosts.length; c++) { @@ -52,7 +52,7 @@ export function getDailyRunStarters(seed: string): Starter[] { const costSpecies = Object.keys(speciesStarterCosts) .map(s => Number.parseInt(s) as Species) .filter(s => speciesStarterCosts[s] === cost); - const randPkmSpecies = getPokemonSpecies(Utils.randSeedItem(costSpecies)); + const randPkmSpecies = getPokemonSpecies(randSeedItem(costSpecies)); const starterSpecies = getPokemonSpecies( randPkmSpecies.getTrainerSpeciesForLevel(startingLevel, true, PartyMemberStrength.STRONGER), ); @@ -143,7 +143,7 @@ const dailyBiomeWeights: BiomeWeights = { }; export function getDailyStartingBiome(): Biome { - const biomes = Utils.getEnumValues(Biome).filter(b => b !== Biome.TOWN && b !== Biome.END); + const biomes = getEnumValues(Biome).filter(b => b !== Biome.TOWN && b !== Biome.END); let totalWeight = 0; const biomeThresholds: number[] = []; @@ -155,7 +155,7 @@ export function getDailyStartingBiome(): Biome { biomeThresholds.push(totalWeight); } - const randInt = Utils.randSeedInt(totalWeight); + const randInt = randSeedInt(totalWeight); for (let i = 0; i < biomes.length; i++) { if (randInt < biomeThresholds[i]) { @@ -164,5 +164,5 @@ export function getDailyStartingBiome(): Biome { } // Fallback in case something went wrong - return biomes[Utils.randSeedInt(biomes.length)]; + return biomes[randSeedInt(biomes.length)]; } diff --git a/src/data/egg.ts b/src/data/egg.ts index 0dabf8f1119..13ab0bec479 100644 --- a/src/data/egg.ts +++ b/src/data/egg.ts @@ -4,7 +4,7 @@ import type PokemonSpecies from "#app/data/pokemon-species"; import { getPokemonSpecies } from "#app/data/pokemon-species"; import { speciesStarterCosts } from "#app/data/balance/starters"; import { VariantTier } from "#enums/variant-tier"; -import * as Utils from "#app/utils"; +import { randInt, randomString, randSeedInt, getIvsFromId } from "#app/utils"; import Overrides from "#app/overrides"; import { pokemonPrevolutions } from "#app/data/balance/pokemon-evolutions"; import type { PlayerPokemon } from "#app/field/pokemon"; @@ -171,7 +171,7 @@ export class Egg { this.checkForPityTierOverrides(); } - this._id = eggOptions?.id ?? Utils.randInt(EGG_SEED, EGG_SEED * this._tier); + this._id = eggOptions?.id ?? randInt(EGG_SEED, EGG_SEED * this._tier); this._sourceType = eggOptions?.sourceType ?? undefined; this._hatchWaves = eggOptions?.hatchWaves ?? this.getEggTierDefaultHatchWaves(); @@ -203,7 +203,7 @@ export class Egg { } }; - const seedOverride = Utils.randomString(24); + const seedOverride = randomString(24); globalScene.executeWithSeedOffset( () => { generateEggProperties(eggOptions); @@ -248,18 +248,15 @@ export class Egg { let pokemonSpecies = getPokemonSpecies(this._species); // Special condition to have Phione eggs also have a chance of generating Manaphy if (this._species === Species.PHIONE && this._sourceType === EggSourceType.SAME_SPECIES_EGG) { - pokemonSpecies = getPokemonSpecies( - Utils.randSeedInt(MANAPHY_EGG_MANAPHY_RATE) ? Species.PHIONE : Species.MANAPHY, - ); + pokemonSpecies = getPokemonSpecies(randSeedInt(MANAPHY_EGG_MANAPHY_RATE) ? Species.PHIONE : Species.MANAPHY); } // Sets the hidden ability if a hidden ability exists and // the override is set or the egg hits the chance let abilityIndex: number | undefined = undefined; const sameSpeciesEggHACheck = - this._sourceType === EggSourceType.SAME_SPECIES_EGG && !Utils.randSeedInt(SAME_SPECIES_EGG_HA_RATE); - const gachaEggHACheck = - !(this._sourceType === EggSourceType.SAME_SPECIES_EGG) && !Utils.randSeedInt(GACHA_EGG_HA_RATE); + this._sourceType === EggSourceType.SAME_SPECIES_EGG && !randSeedInt(SAME_SPECIES_EGG_HA_RATE); + const gachaEggHACheck = !(this._sourceType === EggSourceType.SAME_SPECIES_EGG) && !randSeedInt(GACHA_EGG_HA_RATE); if (pokemonSpecies.abilityHidden && (this._overrideHiddenAbility || sameSpeciesEggHACheck || gachaEggHACheck)) { abilityIndex = 2; } @@ -269,7 +266,7 @@ export class Egg { ret.shiny = this._isShiny; ret.variant = this._variantTier; - const secondaryIvs = Utils.getIvsFromId(Utils.randSeedInt(4294967295)); + const secondaryIvs = getIvsFromId(randSeedInt(4294967295)); for (let s = 0; s < ret.ivs.length; s++) { ret.ivs[s] = Math.max(ret.ivs[s], secondaryIvs[s]); @@ -370,7 +367,7 @@ export class Egg { } const tierMultiplier = this.isManaphyEgg() ? 2 : Math.pow(2, 3 - this.tier); - return Utils.randSeedInt(baseChance * tierMultiplier) ? Utils.randSeedInt(3) : 3; + return randSeedInt(baseChance * tierMultiplier) ? randSeedInt(3) : 3; } private getEggTierDefaultHatchWaves(eggTier?: EggTier): number { @@ -392,7 +389,7 @@ export class Egg { private rollEggTier(): EggTier { const tierValueOffset = this._sourceType === EggSourceType.GACHA_LEGENDARY ? GACHA_LEGENDARY_UP_THRESHOLD_OFFSET : 0; - const tierValue = Utils.randInt(256); + const tierValue = randInt(256); return tierValue >= GACHA_DEFAULT_COMMON_EGG_THRESHOLD + tierValueOffset ? EggTier.COMMON : tierValue >= GACHA_DEFAULT_RARE_EGG_THRESHOLD + tierValueOffset @@ -417,11 +414,11 @@ export class Egg { * when Utils.randSeedInt(8) = 1, and by making the generatePlayerPokemon() species * check pass when Utils.randSeedInt(8) = 0, we can tell them apart during tests. */ - const rand = Utils.randSeedInt(MANAPHY_EGG_MANAPHY_RATE) !== 1; + const rand = randSeedInt(MANAPHY_EGG_MANAPHY_RATE) !== 1; return rand ? Species.PHIONE : Species.MANAPHY; } if (this.tier === EggTier.LEGENDARY && this._sourceType === EggSourceType.GACHA_LEGENDARY) { - if (!Utils.randSeedInt(2)) { + if (!randSeedInt(2)) { return getLegendaryGachaSpeciesForTimestamp(this.timestamp); } } @@ -501,7 +498,7 @@ export class Egg { let species: Species; - const rand = Utils.randSeedInt(totalWeight); + const rand = randSeedInt(totalWeight); for (let s = 0; s < speciesWeights.length; s++) { if (rand < speciesWeights[s]) { species = speciesPool[s]; @@ -539,7 +536,7 @@ export class Egg { break; } - return !Utils.randSeedInt(shinyChance); + return !randSeedInt(shinyChance); } // Uses the same logic as pokemon.generateVariant(). I would like to only have this logic in one @@ -550,7 +547,7 @@ export class Egg { return VariantTier.STANDARD; } - const rand = Utils.randSeedInt(10); + const rand = randSeedInt(10); if (rand >= SHINY_VARIANT_CHANCE) { return VariantTier.STANDARD; // 6/10 } diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index 1af4be4fdf0..962a13bb840 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -29,9 +29,7 @@ import { } from "../status-effect"; import { getTypeDamageMultiplier } from "../type"; import { PokemonType } from "#enums/pokemon-type"; -import type { Constructor } from "#app/utils"; -import { NumberHolder } from "#app/utils"; -import * as Utils from "../../utils"; +import { BooleanHolder, NumberHolder, isNullOrUndefined, toDmgValue, randSeedItem, randSeedInt, getEnumValues, toReadableString, type Constructor } from "#app/utils"; import { WeatherType } from "#enums/weather-type"; import type { ArenaTrapTag } from "../arena-tag"; import { ArenaTagSide, WeakenMoveTypeTag } from "../arena-tag"; @@ -352,7 +350,7 @@ export default class Move implements Localizable { return false; } - const bypassed = new Utils.BooleanHolder(false); + const bypassed = new BooleanHolder(false); // TODO: Allow this to be simulated applyAbAttrs(InfiltratorAbAttr, user, null, false, bypassed); @@ -651,7 +649,7 @@ export default class Move implements Localizable { break; case MoveFlags.IGNORE_ABILITIES: if (user.hasAbilityWithAttr(MoveAbilityBypassAbAttr)) { - const abilityEffectsIgnored = new Utils.BooleanHolder(false); + const abilityEffectsIgnored = new BooleanHolder(false); applyAbAttrs(MoveAbilityBypassAbAttr, user, abilityEffectsIgnored, false, this); if (abilityEffectsIgnored.value) { return true; @@ -755,7 +753,7 @@ export default class Move implements Localizable { * @returns The calculated accuracy of the move. */ calculateBattleAccuracy(user: Pokemon, target: Pokemon, simulated: boolean = false) { - const moveAccuracy = new Utils.NumberHolder(this.accuracy); + const moveAccuracy = new NumberHolder(this.accuracy); applyMoveAttrs(VariableAccuracyAttr, user, target, this, moveAccuracy); applyPreDefendAbAttrs(WonderSkinAbAttr, target, user, this, { value: false }, simulated, moveAccuracy); @@ -797,8 +795,8 @@ export default class Move implements Localizable { return -1; } - const power = new Utils.NumberHolder(this.power); - const typeChangeMovePowerMultiplier = new Utils.NumberHolder(1); + const power = new NumberHolder(this.power); + const typeChangeMovePowerMultiplier = new NumberHolder(1); applyPreAttackAbAttrs(MoveTypeChangeAbAttr, source, target, this, true, null, typeChangeMovePowerMultiplier); @@ -809,7 +807,7 @@ export default class Move implements Localizable { applyPreAttackAbAttrs(VariableMovePowerAbAttr, source, target, this, simulated, power); const ally = source.getAlly(); - if (!Utils.isNullOrUndefined(ally)) { + if (!isNullOrUndefined(ally)) { applyPreAttackAbAttrs(AllyMoveCategoryPowerBoostAbAttr, ally, target, this, simulated, power); } @@ -850,7 +848,7 @@ export default class Move implements Localizable { } getPriority(user: Pokemon, simulated: boolean = true) { - const priority = new Utils.NumberHolder(this.priority); + const priority = new NumberHolder(this.priority); applyMoveAttrs(IncrementMovePriorityAttr, user, null, this, priority); applyAbAttrs(ChangeMovePriorityAbAttr, user, null, simulated, this, priority); @@ -932,7 +930,7 @@ export default class Move implements Localizable { // ...and cannot enhance Pollen Puff when targeting an ally. const ally = user.getAlly(); - const exceptPollenPuffAlly: boolean = this.id === Moves.POLLEN_PUFF && !Utils.isNullOrUndefined(ally) && targets.includes(ally.getBattlerIndex()) + const exceptPollenPuffAlly: boolean = this.id === Moves.POLLEN_PUFF && !isNullOrUndefined(ally) && targets.includes(ally.getBattlerIndex()) return (!restrictSpread || !isMultiTarget) && !this.isChargingMove() @@ -971,7 +969,7 @@ export class AttackMove extends Move { const effectiveness = target.getAttackTypeEffectiveness(this.type, user, undefined, undefined, this); attackScore = Math.pow(effectiveness - 1, 2) * (effectiveness < 1 ? -2 : 2); const [ thisStat, offStat ]: EffectiveStat[] = this.category === MoveCategory.PHYSICAL ? [ Stat.ATK, Stat.SPATK ] : [ Stat.SPATK, Stat.ATK ]; - const statHolder = new Utils.NumberHolder(user.getEffectiveStat(thisStat, target)); + const statHolder = new NumberHolder(user.getEffectiveStat(thisStat, target)); const offStatValue = user.getEffectiveStat(offStat, target); applyMoveAttrs(VariableAtkAttr, user, target, move, statHolder); const statRatio = offStatValue / statHolder.value; @@ -981,7 +979,7 @@ export class AttackMove extends Move { attackScore *= 1.5; } - const power = new Utils.NumberHolder(this.calculateEffectivePower()); + const power = new NumberHolder(this.calculateEffectivePower()); applyMoveAttrs(VariablePowerAttr, user, target, move, power); attackScore += Math.floor(power.value / 5); @@ -1252,7 +1250,7 @@ export class MoveEffectAttr extends MoveAttr { * @returns Move effect chance value. */ getMoveChance(user: Pokemon, target: Pokemon, move: Move, selfEffect?: Boolean, showAbility?: Boolean): number { - const moveChance = new Utils.NumberHolder(this.effectChanceOverride ?? move.chance); + const moveChance = new NumberHolder(this.effectChanceOverride ?? move.chance); applyAbAttrs(MoveEffectChanceMultiplierAbAttr, user, null, !showAbility, moveChance, move); @@ -1415,7 +1413,7 @@ export class RespectAttackTypeImmunityAttr extends MoveAttr { } export class IgnoreOpponentStatStagesAttr extends MoveAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.BooleanHolder).value = true; + (args[0] as BooleanHolder).value = true; return true; } @@ -1423,7 +1421,7 @@ export class IgnoreOpponentStatStagesAttr extends MoveAttr { export class HighCritAttr extends MoveAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.NumberHolder).value++; + (args[0] as NumberHolder).value++; return true; } @@ -1435,7 +1433,7 @@ export class HighCritAttr extends MoveAttr { export class CritOnlyAttr extends MoveAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.BooleanHolder).value = true; + (args[0] as BooleanHolder).value = true; return true; } @@ -1455,7 +1453,7 @@ export class FixedDamageAttr extends MoveAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.NumberHolder).value = this.getDamage(user, target, move); + (args[0] as NumberHolder).value = this.getDamage(user, target, move); return true; } @@ -1471,7 +1469,7 @@ export class UserHpDamageAttr extends FixedDamageAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.NumberHolder).value = user.hp; + (args[0] as NumberHolder).value = user.hp; return true; } @@ -1492,7 +1490,7 @@ export class TargetHalfHpDamageAttr extends FixedDamageAttr { const lensCount = user.getHeldItems().find(i => i instanceof PokemonMultiHitModifier)?.getStackCount() ?? 0; if (lensCount <= 0) { // no multi lenses; we can just halve the target's hp and call it a day - (args[0] as Utils.NumberHolder).value = Utils.toDmgValue(target.hp / 2); + (args[0] as NumberHolder).value = toDmgValue(target.hp / 2); return true; } @@ -1503,11 +1501,11 @@ export class TargetHalfHpDamageAttr extends FixedDamageAttr { this.initialHp = target.hp; default: // multi lens added hit; use initialHp tracker to ensure correct damage - (args[0] as Utils.NumberHolder).value = Utils.toDmgValue(this.initialHp / 2); + (args[0] as NumberHolder).value = toDmgValue(this.initialHp / 2); return true; case lensCount + 1: // parental bond added hit; calc damage as normal - (args[0] as Utils.NumberHolder).value = Utils.toDmgValue(target.hp / 2); + (args[0] as NumberHolder).value = toDmgValue(target.hp / 2); return true; } } @@ -1523,7 +1521,7 @@ export class MatchHpAttr extends FixedDamageAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.NumberHolder).value = target.hp - user.hp; + (args[0] as NumberHolder).value = target.hp - user.hp; return true; } @@ -1553,7 +1551,7 @@ export class CounterDamageAttr extends FixedDamageAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const damage = user.turnData.attacksReceived.filter(ar => this.moveFilter(allMoves[ar.move])).reduce((total: number, ar: AttackMoveResult) => total + ar.damage, 0); - (args[0] as Utils.NumberHolder).value = Utils.toDmgValue(damage * this.multiplier); + (args[0] as NumberHolder).value = toDmgValue(damage * this.multiplier); return true; } @@ -1579,13 +1577,13 @@ export class RandomLevelDamageAttr extends FixedDamageAttr { } getDamage(user: Pokemon, target: Pokemon, move: Move): number { - return Utils.toDmgValue(user.level * (user.randSeedIntRange(50, 150) * 0.01)); + return toDmgValue(user.level * (user.randSeedIntRange(50, 150) * 0.01)); } } export class ModifiedDamageAttr extends MoveAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const initialDamage = args[0] as Utils.NumberHolder; + const initialDamage = args[0] as NumberHolder; initialDamage.value = this.getModifiedDamage(user, target, move, initialDamage.value); return true; @@ -1638,7 +1636,7 @@ export class RecoilAttr extends MoveEffectAttr { return false; } - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); if (!this.unblockable) { applyAbAttrs(BlockRecoilDamageAttr, user, cancelled); applyAbAttrs(BlockNonDirectDamageAbAttr, user, cancelled); @@ -1655,7 +1653,7 @@ export class RecoilAttr extends MoveEffectAttr { const damageValue = (!this.useHp ? user.turnData.totalDamageDealt : user.getMaxHp()) * this.damageRatio; const minValue = user.turnData.totalDamageDealt ? 1 : 0; - const recoilDamage = Utils.toDmgValue(damageValue, minValue); + const recoilDamage = toDmgValue(damageValue, minValue); if (!recoilDamage) { return false; } @@ -1772,11 +1770,11 @@ export class HalfSacrificialAttr extends MoveEffectAttr { return false; } - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); // Check to see if the Pokemon has an ability that blocks non-direct damage applyAbAttrs(BlockNonDirectDamageAbAttr, user, cancelled); if (!cancelled.value) { - user.damageAndUpdate(Utils.toDmgValue(user.getMaxHp() / 2), { result: HitResult.INDIRECT, ignoreSegments: true }); + user.damageAndUpdate(toDmgValue(user.getMaxHp() / 2), { result: HitResult.INDIRECT, ignoreSegments: true }); globalScene.queueMessage(i18next.t("moveTriggers:cutHpPowerUpMove", { pokemonName: getPokemonNameWithAffix(user) })); // Queue recoil message } return true; @@ -1882,7 +1880,7 @@ export class HealAttr extends MoveEffectAttr { */ addHealPhase(target: Pokemon, healRatio: number) { globalScene.unshiftPhase(new PokemonHealPhase(target.getBattlerIndex(), - Utils.toDmgValue(target.getMaxHp() * healRatio), i18next.t("moveTriggers:healHp", { pokemonName: getPokemonNameWithAffix(target) }), true, !this.showAnim)); + toDmgValue(target.getMaxHp() * healRatio), i18next.t("moveTriggers:healHp", { pokemonName: getPokemonNameWithAffix(target) }), true, !this.showAnim)); } getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): number { @@ -1965,9 +1963,9 @@ export class FlameBurstAttr extends MoveEffectAttr { */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const targetAlly = target.getAlly(); - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); - if (!Utils.isNullOrUndefined(targetAlly)) { + if (!isNullOrUndefined(targetAlly)) { applyAbAttrs(BlockNonDirectDamageAbAttr, targetAlly, cancelled); } @@ -1980,7 +1978,7 @@ export class FlameBurstAttr extends MoveEffectAttr { } getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): number { - return !Utils.isNullOrUndefined(target.getAlly()) ? -5 : 0; + return !isNullOrUndefined(target.getAlly()) ? -5 : 0; } } @@ -2048,11 +2046,11 @@ export class IgnoreWeatherTypeDebuffAttr extends MoveAttr { * @param user {@linkcode Pokemon} that used the move * @param target N/A * @param move {@linkcode Move} with this attribute - * @param args [0] {@linkcode Utils.NumberHolder} for arenaAttackTypeMultiplier + * @param args [0] {@linkcode NumberHolder} for arenaAttackTypeMultiplier * @returns true if the function succeeds */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const weatherModifier = args[0] as Utils.NumberHolder; + const weatherModifier = args[0] as NumberHolder; //If the type-based attack power modifier due to weather (e.g. Water moves in Sun) is below 1, set it to 1 if (globalScene.arena.weather?.weatherType === this.weather) { weatherModifier.value = Math.max(weatherModifier.value, 1); @@ -2203,7 +2201,7 @@ export class HitHealAttr extends MoveEffectAttr { message = i18next.t("battle:drainMessage", { pokemonName: getPokemonNameWithAffix(target) }); } else { // Default healing formula used by draining moves like Absorb, Draining Kiss, Bitter Blade, etc. - healAmount = Utils.toDmgValue(user.turnData.singleHitDamageDealt * this.healRatio); + healAmount = toDmgValue(user.turnData.singleHitDamageDealt * this.healRatio); message = i18next.t("battle:regainHealth", { pokemonName: getPokemonNameWithAffix(user) }); } if (reverseDrain) { @@ -2261,7 +2259,7 @@ export class IncrementMovePriorityAttr extends MoveAttr { * @param user {@linkcode Pokemon} using this move * @param target {@linkcode Pokemon} target of this move * @param move {@linkcode Move} being used - * @param args [0] {@linkcode Utils.NumberHolder} for move priority. + * @param args [0] {@linkcode NumberHolder} for move priority. * @returns true if function succeeds */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { @@ -2269,7 +2267,7 @@ export class IncrementMovePriorityAttr extends MoveAttr { return false; } - (args[0] as Utils.NumberHolder).value += this.increaseAmount; + (args[0] as NumberHolder).value += this.increaseAmount; return true; } } @@ -2307,15 +2305,15 @@ export class MultiHitAttr extends MoveAttr { * @param user {@linkcode Pokemon} that used the attack * @param target {@linkcode Pokemon} targeted by the attack * @param move {@linkcode Move} being used - * @param args [0] {@linkcode Utils.NumberHolder} storing the hit count of the attack + * @param args [0] {@linkcode NumberHolder} storing the hit count of the attack * @returns True */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const hitType = new Utils.NumberHolder(this.intrinsicMultiHitType); + const hitType = new NumberHolder(this.intrinsicMultiHitType); applyMoveAttrs(ChangeMultiHitTypeAttr, user, target, move, hitType); this.multiHitType = hitType.value; - (args[0] as Utils.NumberHolder).value = this.getHitCount(user, target); + (args[0] as NumberHolder).value = this.getHitCount(user, target); return true; } @@ -2336,7 +2334,7 @@ export class MultiHitAttr extends MoveAttr { case MultiHitType._2_TO_5: { const rand = user.randSeedInt(20); - const hitValue = new Utils.NumberHolder(rand); + const hitValue = new NumberHolder(rand); applyAbAttrs(MaxMultiHitAbAttr, user, null, false, hitValue); if (hitValue.value >= 13) { return 2; @@ -2414,7 +2412,7 @@ export class ChangeMultiHitTypeAttr extends MoveAttr { export class WaterShurikenMultiHitTypeAttr extends ChangeMultiHitTypeAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (user.species.speciesId === Species.GRENINJA && user.hasAbility(Abilities.BATTLE_BOND) && user.formIndex === 2) { - (args[0] as Utils.NumberHolder).value = MultiHitType._3; + (args[0] as NumberHolder).value = MultiHitType._3; return true; } return false; @@ -2480,7 +2478,7 @@ export class MultiStatusEffectAttr extends StatusEffectAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - this.effect = Utils.randSeedItem(this.effects); + this.effect = randSeedItem(this.effects); const result = super.apply(user, target, move, args); return result; } @@ -2612,7 +2610,7 @@ export class RemoveHeldItemAttr extends MoveEffectAttr { return false; } - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); applyAbAttrs(BlockItemTheftAbAttr, target, cancelled); // Check for abilities that block item theft if (cancelled.value === true) { @@ -2686,7 +2684,7 @@ export class EatBerryAttr extends MoveEffectAttr { return false; } this.chosenBerry = heldBerries[user.randSeedInt(heldBerries.length)]; - const preserve = new Utils.BooleanHolder(false); + const preserve = new BooleanHolder(false); globalScene.applyModifiers(PreserveBerryModifier, target.isPlayer(), target, preserve); // check for berry pouch preservation if (!preserve.value) { this.reduceBerryModifier(target); @@ -2709,7 +2707,7 @@ export class EatBerryAttr extends MoveEffectAttr { eatBerry(consumer: Pokemon, berryOwner?: Pokemon) { getBerryEffectFunc(this.chosenBerry!.berryType)(consumer, berryOwner); // consumer eats the berry - applyAbAttrs(HealFromBerryUseAbAttr, consumer, new Utils.BooleanHolder(false)); + applyAbAttrs(HealFromBerryUseAbAttr, consumer, new BooleanHolder(false)); } } @@ -2733,7 +2731,7 @@ export class StealEatBerryAttr extends EatBerryAttr { if (move.hitsSubstitute(user, target)) { return false; } - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); applyAbAttrs(BlockItemTheftAbAttr, target, cancelled); // check for abilities that block item theft if (cancelled.value === true) { return false; @@ -2846,11 +2844,11 @@ export class BypassBurnDamageReductionAttr extends MoveAttr { * @param user N/A * @param target N/A * @param move {@linkcode Move} with this attribute - * @param args [0] {@linkcode Utils.BooleanHolder} for burnDamageReductionCancelled + * @param args [0] {@linkcode BooleanHolder} for burnDamageReductionCancelled * @returns true if the function succeeds */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.BooleanHolder).value = true; + (args[0] as BooleanHolder).value = true; return true; } @@ -2931,14 +2929,14 @@ export class OneHitKOAttr extends MoveAttr { return false; } - (args[0] as Utils.BooleanHolder).value = true; + (args[0] as BooleanHolder).value = true; return true; } getCondition(): MoveConditionFunc { return (user, target, move) => { - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); applyAbAttrs(BlockOneHitKOAbAttr, target, cancelled); return !cancelled.value && user.level >= target.level; }; @@ -2965,12 +2963,12 @@ export class InstantChargeAttr extends MoveAttr { * @param target n/a * @param move the {@linkcode Move} associated with this attribute * @param args - * - `[0]` a {@linkcode Utils.BooleanHolder | BooleanHolder} for the "instant charge" flag + * - `[0]` a {@linkcode BooleanHolder | BooleanHolder} for the "instant charge" flag * @returns `true` if the instant charge condition is met; `false` otherwise. */ override apply(user: Pokemon, target: Pokemon | null, move: Move, args: any[]): boolean { const instantCharge = args[0]; - if (!(instantCharge instanceof Utils.BooleanHolder)) { + if (!(instantCharge instanceof BooleanHolder)) { return false; } @@ -2992,7 +2990,7 @@ export class WeatherInstantChargeAttr extends InstantChargeAttr { super((user, move) => { const currentWeather = globalScene.arena.weather; - if (Utils.isNullOrUndefined(currentWeather?.weatherType)) { + if (isNullOrUndefined(currentWeather?.weatherType)) { return false; } else { return !currentWeather?.isEffectSuppressed() @@ -3035,7 +3033,7 @@ export class DelayedAttackAttr extends OverrideMoveEffectAttr { return true; } - const overridden = args[0] as Utils.BooleanHolder; + const overridden = args[0] as BooleanHolder; const virtual = args[1] as boolean; if (!virtual) { @@ -3069,7 +3067,7 @@ export class AwaitCombinedPledgeAttr extends OverrideMoveEffectAttr { * @param target n/a * @param move the {@linkcode Move} being used * @param args - * - [0] a {@linkcode Utils.BooleanHolder} indicating whether the move's base + * - [0] a {@linkcode BooleanHolder} indicating whether the move's base * effects should be overridden this turn. * @returns `true` if base move effects were overridden; `false` otherwise */ @@ -3080,7 +3078,7 @@ export class AwaitCombinedPledgeAttr extends OverrideMoveEffectAttr { return false; } - const overridden = args[0] as Utils.BooleanHolder; + const overridden = args[0] as BooleanHolder; const allyMovePhase = globalScene.findPhase((phase) => phase instanceof MovePhase && phase.pokemon.isPlayer() === user.isPlayer()); if (allyMovePhase) { @@ -3451,7 +3449,7 @@ export class CutHpStatStageBoostAttr extends StatStageChangeAttr { this.messageCallback = messageCallback; } override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - user.damageAndUpdate(Utils.toDmgValue(user.getMaxHp() / this.cutRatio), { result: HitResult.INDIRECT }); + user.damageAndUpdate(toDmgValue(user.getMaxHp() / this.cutRatio), { result: HitResult.INDIRECT }); user.updateInfo(); const ret = super.apply(user, target, move, args); if (this.messageCallback) { @@ -3663,7 +3661,7 @@ export class LessPPMorePowerAttr extends VariablePowerAttr { * @param user {@linkcode Pokemon} using this move * @param target {@linkcode Pokemon} target of this move * @param move {@linkcode Move} being used - * @param args [0] {@linkcode Utils.NumberHolder} of power + * @param args [0] {@linkcode NumberHolder} of power * @returns true if the function succeeds */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { @@ -3676,7 +3674,7 @@ export class LessPPMorePowerAttr extends VariablePowerAttr { ppRemains = 0; } - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; switch (ppRemains) { case 0: @@ -3709,7 +3707,7 @@ export class MovePowerMultiplierAttr extends VariablePowerAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; power.value *= this.powerMultiplierFunc(user, target, move); return true; @@ -3749,7 +3747,7 @@ export class BeatUpAttr extends VariablePowerAttr { * @returns true if the function succeeds */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; const party = user.isPlayer() ? globalScene.getPlayerParty() : globalScene.getEnemyParty(); const allyCount = party.filter(pokemon => { @@ -3764,7 +3762,7 @@ export class BeatUpAttr extends VariablePowerAttr { const doublePowerChanceMessageFunc = (user: Pokemon, target: Pokemon, move: Move) => { let message: string = ""; globalScene.executeWithSeedOffset(() => { - const rand = Utils.randSeedInt(100); + const rand = randSeedInt(100); if (rand < move.chance) { message = i18next.t("moveTriggers:goingAllOutForAttack", { pokemonName: getPokemonNameWithAffix(user) }); } @@ -3775,9 +3773,9 @@ const doublePowerChanceMessageFunc = (user: Pokemon, target: Pokemon, move: Move export class DoublePowerChanceAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { let rand: number; - globalScene.executeWithSeedOffset(() => rand = Utils.randSeedInt(100), globalScene.currentBattle.turn << 6, globalScene.waveSeed); + globalScene.executeWithSeedOffset(() => rand = randSeedInt(100), globalScene.currentBattle.turn << 6, globalScene.waveSeed); if (rand! < move.chance) { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; power.value *= 2; return true; } @@ -3831,7 +3829,7 @@ export class ConsecutiveUseMultiBasePowerAttr extends ConsecutiveUsePowerMultipl export class WeightPowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; const targetWeight = target.getWeight(); const weightThresholds = [ 10, 25, 50, 100, 200 ]; @@ -3865,7 +3863,7 @@ export class ElectroBallPowerAttr extends VariablePowerAttr { * @returns true if the function succeeds */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; const statRatio = target.getEffectiveStat(Stat.SPD) / user.getEffectiveStat(Stat.SPD); const statThresholds = [ 0.25, 1 / 3, 0.5, 1, -1 ]; @@ -3900,7 +3898,7 @@ export class GyroBallPowerAttr extends VariablePowerAttr { * @returns true if the function succeeds */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; const userSpeed = user.getEffectiveStat(Stat.SPD); if (userSpeed < 1) { // Gen 6+ always have 1 base power @@ -3915,7 +3913,7 @@ export class GyroBallPowerAttr extends VariablePowerAttr { export class LowHpPowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; const hpRatio = user.getHpRatio(); switch (true) { @@ -3945,7 +3943,7 @@ export class LowHpPowerAttr extends VariablePowerAttr { export class CompareWeightPowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; const userWeight = user.getWeight(); const targetWeight = target.getWeight(); @@ -3979,7 +3977,7 @@ export class CompareWeightPowerAttr extends VariablePowerAttr { export class HpPowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.NumberHolder).value = Utils.toDmgValue(150 * user.getHpRatio()); + (args[0] as NumberHolder).value = toDmgValue(150 * user.getHpRatio()); return true; } @@ -4007,7 +4005,7 @@ export class OpponentHighHpPowerAttr extends VariablePowerAttr { * @returns true */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.NumberHolder).value = Utils.toDmgValue(this.maxBasePower * target.getHpRatio()); + (args[0] as NumberHolder).value = toDmgValue(this.maxBasePower * target.getHpRatio()); return true; } @@ -4017,7 +4015,7 @@ export class FirstAttackDoublePowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { console.log(target.getLastXMoves(1), globalScene.currentBattle.turn); if (!target.getLastXMoves(1).find(m => m.turn === globalScene.currentBattle.turn)) { - (args[0] as Utils.NumberHolder).value *= 2; + (args[0] as NumberHolder).value *= 2; return true; } @@ -4029,7 +4027,7 @@ export class FirstAttackDoublePowerAttr extends VariablePowerAttr { export class TurnDamagedDoublePowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (user.turnData.attacksReceived.find(r => r.damage && r.sourceId === target.id)) { - (args[0] as Utils.NumberHolder).value *= 2; + (args[0] as NumberHolder).value *= 2; return true; } @@ -4042,7 +4040,7 @@ const magnitudeMessageFunc = (user: Pokemon, target: Pokemon, move: Move) => { globalScene.executeWithSeedOffset(() => { const magnitudeThresholds = [ 5, 15, 35, 65, 75, 95 ]; - const rand = Utils.randSeedInt(100); + const rand = randSeedInt(100); let m = 0; for (; m < magnitudeThresholds.length; m++) { @@ -4058,14 +4056,14 @@ const magnitudeMessageFunc = (user: Pokemon, target: Pokemon, move: Move) => { export class MagnitudePowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; const magnitudeThresholds = [ 5, 15, 35, 65, 75, 95 ]; const magnitudePowers = [ 10, 30, 50, 70, 90, 100, 110, 150 ]; let rand: number; - globalScene.executeWithSeedOffset(() => rand = Utils.randSeedInt(100), globalScene.currentBattle.turn << 6, globalScene.waveSeed); + globalScene.executeWithSeedOffset(() => rand = randSeedInt(100), globalScene.currentBattle.turn << 6, globalScene.waveSeed); let m = 0; for (; m < magnitudeThresholds.length; m++) { @@ -4083,7 +4081,7 @@ export class MagnitudePowerAttr extends VariablePowerAttr { export class AntiSunlightPowerDecreaseAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (!globalScene.arena.weather?.isEffectSuppressed()) { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; const weatherType = globalScene.arena.weather?.weatherType || WeatherType.NONE; switch (weatherType) { case WeatherType.RAIN: @@ -4110,7 +4108,7 @@ export class FriendshipPowerAttr extends VariablePowerAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; const friendshipPower = Math.floor(Math.min(user instanceof PlayerPokemon ? user.friendship : user.species.baseFriendship, 255) / 2.5); power.value = Math.max(!this.invert ? friendshipPower : 102 - friendshipPower, 1); @@ -4126,7 +4124,7 @@ export class FriendshipPowerAttr extends VariablePowerAttr { export class RageFistPowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const { hitCount, prevHitCount } = user.battleData; - const basePower: Utils.NumberHolder = args[0]; + const basePower: NumberHolder = args[0]; this.updateHitReceivedCount(user, hitCount, prevHitCount); @@ -4171,7 +4169,7 @@ export class PositiveStatStagePowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const positiveStatStages: number = countPositiveStatStages(user); - (args[0] as Utils.NumberHolder).value += positiveStatStages * 20; + (args[0] as NumberHolder).value += positiveStatStages * 20; return true; } } @@ -4194,7 +4192,7 @@ export class PunishmentPowerAttr extends VariablePowerAttr { */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const positiveStatStages: number = countPositiveStatStages(target); - (args[0] as Utils.NumberHolder).value = Math.min( + (args[0] as NumberHolder).value = Math.min( this.PUNISHMENT_MAX_BASE_POWER, this.PUNISHMENT_MIN_BASE_POWER + positiveStatStages * 20 ); @@ -4210,18 +4208,18 @@ export class PresentPowerAttr extends VariablePowerAttr { */ const firstHit = (user.turnData.hitCount === user.turnData.hitsLeft); - const powerSeed = Utils.randSeedInt(firstHit ? 100 : 80); + const powerSeed = randSeedInt(firstHit ? 100 : 80); if (powerSeed <= 40) { - (args[0] as Utils.NumberHolder).value = 40; + (args[0] as NumberHolder).value = 40; } else if (40 < powerSeed && powerSeed <= 70) { - (args[0] as Utils.NumberHolder).value = 80; + (args[0] as NumberHolder).value = 80; } else if (70 < powerSeed && powerSeed <= 80) { - (args[0] as Utils.NumberHolder).value = 120; + (args[0] as NumberHolder).value = 120; } else if (80 < powerSeed && powerSeed <= 100) { // If this move is multi-hit, disable all other hits user.stopMultiHit(); globalScene.unshiftPhase(new PokemonHealPhase(target.getBattlerIndex(), - Utils.toDmgValue(target.getMaxHp() / 4), i18next.t("moveTriggers:regainedHealth", { pokemonName: getPokemonNameWithAffix(target) }), true)); + toDmgValue(target.getMaxHp() / 4), i18next.t("moveTriggers:regainedHealth", { pokemonName: getPokemonNameWithAffix(target) }), true)); } return true; @@ -4231,7 +4229,7 @@ export class PresentPowerAttr extends VariablePowerAttr { export class WaterShurikenPowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (user.species.speciesId === Species.GRENINJA && user.hasAbility(Abilities.BATTLE_BOND) && user.formIndex === 2) { - (args[0] as Utils.NumberHolder).value = 20; + (args[0] as NumberHolder).value = 20; return true; } return false; @@ -4253,7 +4251,7 @@ export class SpitUpPowerAttr extends VariablePowerAttr { const stockpilingTag = user.getTag(StockpilingTag); if (stockpilingTag && stockpilingTag.stockpiledCount > 0) { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; power.value = this.multiplier * stockpilingTag.stockpiledCount; return true; } @@ -4321,12 +4319,12 @@ export class MultiHitPowerIncrementAttr extends VariablePowerAttr { * @param user {@linkcode Pokemon} that used the move * @param target {@linkcode Pokemon} that the move was used on * @param move {@linkcode Move} with this attribute - * @param args [0] {@linkcode Utils.NumberHolder} for final calculated power of move + * @param args [0] {@linkcode NumberHolder} for final calculated power of move * @returns true if attribute application succeeds */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const hitsTotal = user.turnData.hitCount - Math.max(user.turnData.hitsLeft, 0); - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; power.value = move.power * (1 + hitsTotal % this.maxHits); @@ -4358,11 +4356,11 @@ export class LastMoveDoublePowerAttr extends VariablePowerAttr { * @param user {@linkcode Pokemon} that used the move * @param target N/A * @param move N/A - * @param args [0] {@linkcode Utils.NumberHolder} that holds the resulting power of the move + * @param args [0] {@linkcode NumberHolder} that holds the resulting power of the move * @returns true if attribute application succeeds, false otherwise */ apply(user: Pokemon, _target: Pokemon, _move: Move, args: any[]): boolean { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; const enemy = user.getOpponent(0); const pokemonActed: Pokemon[] = []; @@ -4374,10 +4372,10 @@ export class LastMoveDoublePowerAttr extends VariablePowerAttr { const userAlly = user.getAlly(); const enemyAlly = enemy?.getAlly(); - if (!Utils.isNullOrUndefined(userAlly) && userAlly.turnData.acted) { + if (!isNullOrUndefined(userAlly) && userAlly.turnData.acted) { pokemonActed.push(userAlly); } - if (!Utils.isNullOrUndefined(enemyAlly) && enemyAlly.turnData.acted) { + if (!isNullOrUndefined(enemyAlly) && enemyAlly.turnData.acted) { pokemonActed.push(enemyAlly); } } @@ -4407,7 +4405,7 @@ export class LastMoveDoublePowerAttr extends VariablePowerAttr { export class CombinedPledgePowerAttr extends VariablePowerAttr { override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const power = args[0]; - if (!(power instanceof Utils.NumberHolder)) { + if (!(power instanceof NumberHolder)) { return false; } const combinedPledgeMove = user.turnData.combiningPledge; @@ -4426,7 +4424,7 @@ export class CombinedPledgePowerAttr extends VariablePowerAttr { export class CombinedPledgeStabBoostAttr extends MoveAttr { override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const stabMultiplier = args[0]; - if (!(stabMultiplier instanceof Utils.NumberHolder)) { + if (!(stabMultiplier instanceof NumberHolder)) { return false; } const combinedPledgeMove = user.turnData.combiningPledge; @@ -4447,7 +4445,7 @@ export class CombinedPledgeStabBoostAttr extends MoveAttr { export class RoundPowerAttr extends VariablePowerAttr { override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const power = args[0]; - if (!(power instanceof Utils.NumberHolder)) { + if (!(power instanceof NumberHolder)) { return false; } @@ -4572,7 +4570,7 @@ export class TargetAtkUserAtkAttr extends VariableAtkAttr { super(); } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.NumberHolder).value = target.getEffectiveStat(Stat.ATK, target); + (args[0] as NumberHolder).value = target.getEffectiveStat(Stat.ATK, target); return true; } } @@ -4583,7 +4581,7 @@ export class DefAtkAttr extends VariableAtkAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.NumberHolder).value = user.getEffectiveStat(Stat.DEF, target); + (args[0] as NumberHolder).value = user.getEffectiveStat(Stat.DEF, target); return true; } } @@ -4605,7 +4603,7 @@ export class DefDefAttr extends VariableDefAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.NumberHolder).value = target.getEffectiveStat(Stat.DEF, user); + (args[0] as NumberHolder).value = target.getEffectiveStat(Stat.DEF, user); return true; } } @@ -4623,7 +4621,7 @@ export class VariableAccuracyAttr extends MoveAttr { export class ThunderAccuracyAttr extends VariableAccuracyAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (!globalScene.arena.weather?.isEffectSuppressed()) { - const accuracy = args[0] as Utils.NumberHolder; + const accuracy = args[0] as NumberHolder; const weatherType = globalScene.arena.weather?.weatherType || WeatherType.NONE; switch (weatherType) { case WeatherType.SUNNY: @@ -4649,7 +4647,7 @@ export class ThunderAccuracyAttr extends VariableAccuracyAttr { export class StormAccuracyAttr extends VariableAccuracyAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (!globalScene.arena.weather?.isEffectSuppressed()) { - const accuracy = args[0] as Utils.NumberHolder; + const accuracy = args[0] as NumberHolder; const weatherType = globalScene.arena.weather?.weatherType || WeatherType.NONE; switch (weatherType) { case WeatherType.RAIN: @@ -4680,7 +4678,7 @@ export class AlwaysHitMinimizeAttr extends VariableAccuracyAttr { */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (target.getTag(BattlerTagType.MINIMIZED)) { - const accuracy = args[0] as Utils.NumberHolder; + const accuracy = args[0] as NumberHolder; accuracy.value = -1; return true; @@ -4693,7 +4691,7 @@ export class AlwaysHitMinimizeAttr extends VariableAccuracyAttr { export class ToxicAccuracyAttr extends VariableAccuracyAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (user.isOfType(PokemonType.POISON)) { - const accuracy = args[0] as Utils.NumberHolder; + const accuracy = args[0] as NumberHolder; accuracy.value = -1; return true; } @@ -4705,7 +4703,7 @@ export class ToxicAccuracyAttr extends VariableAccuracyAttr { export class BlizzardAccuracyAttr extends VariableAccuracyAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (!globalScene.arena.weather?.isEffectSuppressed()) { - const accuracy = args[0] as Utils.NumberHolder; + const accuracy = args[0] as NumberHolder; const weatherType = globalScene.arena.weather?.weatherType || WeatherType.NONE; if (weatherType === WeatherType.HAIL || weatherType === WeatherType.SNOW) { accuracy.value = -1; @@ -4725,7 +4723,7 @@ export class VariableMoveCategoryAttr extends MoveAttr { export class PhotonGeyserCategoryAttr extends VariableMoveCategoryAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const category = (args[0] as Utils.NumberHolder); + const category = (args[0] as NumberHolder); if (user.getEffectiveStat(Stat.ATK, target, move) > user.getEffectiveStat(Stat.SPATK, target, move)) { category.value = MoveCategory.PHYSICAL; @@ -4745,7 +4743,7 @@ export class PhotonGeyserCategoryAttr extends VariableMoveCategoryAttr { */ export class TeraMoveCategoryAttr extends VariableMoveCategoryAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const category = (args[0] as Utils.NumberHolder); + const category = (args[0] as NumberHolder); if (user.isTerastallized && user.getEffectiveStat(Stat.ATK, target, move, true, true, false, false, true) > user.getEffectiveStat(Stat.SPATK, target, move, true, true, false, false, true)) { @@ -4769,12 +4767,12 @@ export class TeraBlastPowerAttr extends VariablePowerAttr { * @param target n/a * @param move {@linkcode Move} the Move with this attribute (i.e. Tera Blast) * @param args - * - [0] {@linkcode Utils.NumberHolder} the applied move's power, factoring in + * - [0] {@linkcode NumberHolder} the applied move's power, factoring in * previously applied power modifiers. * @returns */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const power = args[0] as Utils.NumberHolder; + const power = args[0] as NumberHolder; if (user.isTerastallized && user.getTeraType() === PokemonType.STELLAR) { power.value = 100; return true; @@ -4794,11 +4792,11 @@ export class StatusCategoryOnAllyAttr extends VariableMoveCategoryAttr { * @param user {@linkcode Pokemon} using the move * @param target {@linkcode Pokemon} target of the move * @param move {@linkcode Move} with this attribute - * @param args [0] {@linkcode Utils.NumberHolder} The category of the move + * @param args [0] {@linkcode NumberHolder} The category of the move * @returns true if the function succeeds */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const category = (args[0] as Utils.NumberHolder); + const category = (args[0] as NumberHolder); if (user.getAlly() === target) { category.value = MoveCategory.STATUS; @@ -4811,7 +4809,7 @@ export class StatusCategoryOnAllyAttr extends VariableMoveCategoryAttr { export class ShellSideArmCategoryAttr extends VariableMoveCategoryAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const category = (args[0] as Utils.NumberHolder); + const category = (args[0] as NumberHolder); const predictedPhysDmg = target.getBaseDamage(user, move, MoveCategory.PHYSICAL, true, true, true, true); const predictedSpecDmg = target.getBaseDamage(user, move, MoveCategory.SPECIAL, true, true, true, true); @@ -4836,7 +4834,7 @@ export class VariableMoveTypeAttr extends MoveAttr { export class FormChangeItemTypeAttr extends VariableMoveTypeAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveType = args[0]; - if (!(moveType instanceof Utils.NumberHolder)) { + if (!(moveType instanceof NumberHolder)) { return false; } @@ -4854,7 +4852,7 @@ export class FormChangeItemTypeAttr extends VariableMoveTypeAttr { export class TechnoBlastTypeAttr extends VariableMoveTypeAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveType = args[0]; - if (!(moveType instanceof Utils.NumberHolder)) { + if (!(moveType instanceof NumberHolder)) { return false; } @@ -4888,7 +4886,7 @@ export class TechnoBlastTypeAttr extends VariableMoveTypeAttr { export class AuraWheelTypeAttr extends VariableMoveTypeAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveType = args[0]; - if (!(moveType instanceof Utils.NumberHolder)) { + if (!(moveType instanceof NumberHolder)) { return false; } @@ -4913,7 +4911,7 @@ export class AuraWheelTypeAttr extends VariableMoveTypeAttr { export class RagingBullTypeAttr extends VariableMoveTypeAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveType = args[0]; - if (!(moveType instanceof Utils.NumberHolder)) { + if (!(moveType instanceof NumberHolder)) { return false; } @@ -4941,7 +4939,7 @@ export class RagingBullTypeAttr extends VariableMoveTypeAttr { export class IvyCudgelTypeAttr extends VariableMoveTypeAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveType = args[0]; - if (!(moveType instanceof Utils.NumberHolder)) { + if (!(moveType instanceof NumberHolder)) { return false; } @@ -4976,7 +4974,7 @@ export class IvyCudgelTypeAttr extends VariableMoveTypeAttr { export class WeatherBallTypeAttr extends VariableMoveTypeAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveType = args[0]; - if (!(moveType instanceof Utils.NumberHolder)) { + if (!(moveType instanceof NumberHolder)) { return false; } @@ -5018,12 +5016,12 @@ export class TerrainPulseTypeAttr extends VariableMoveTypeAttr { * @param user {@linkcode Pokemon} using this move * @param target N/A * @param move N/A - * @param args [0] {@linkcode Utils.NumberHolder} The move's type to be modified + * @param args [0] {@linkcode NumberHolder} The move's type to be modified * @returns true if the function succeeds */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveType = args[0]; - if (!(moveType instanceof Utils.NumberHolder)) { + if (!(moveType instanceof NumberHolder)) { return false; } @@ -5059,7 +5057,7 @@ export class TerrainPulseTypeAttr extends VariableMoveTypeAttr { export class HiddenPowerTypeAttr extends VariableMoveTypeAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveType = args[0]; - if (!(moveType instanceof Utils.NumberHolder)) { + if (!(moveType instanceof NumberHolder)) { return false; } @@ -5094,7 +5092,7 @@ export class TeraBlastTypeAttr extends VariableMoveTypeAttr { */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveType = args[0]; - if (!(moveType instanceof Utils.NumberHolder)) { + if (!(moveType instanceof NumberHolder)) { return false; } @@ -5117,12 +5115,12 @@ export class TeraStarstormTypeAttr extends VariableMoveTypeAttr { * @param user the {@linkcode Pokemon} using the move * @param target n/a * @param move n/a - * @param args[0] {@linkcode Utils.NumberHolder} the move type + * @param args[0] {@linkcode NumberHolder} the move type * @returns `true` if the move type is changed to {@linkcode PokemonType.STELLAR}, `false` otherwise */ override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (user.isTerastallized && user.hasSpecies(Species.TERAPAGOS)) { - const moveType = args[0] as Utils.NumberHolder; + const moveType = args[0] as NumberHolder; moveType.value = PokemonType.STELLAR; return true; @@ -5134,7 +5132,7 @@ export class TeraStarstormTypeAttr extends VariableMoveTypeAttr { export class MatchUserTypeAttr extends VariableMoveTypeAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveType = args[0]; - if (!(moveType instanceof Utils.NumberHolder)) { + if (!(moveType instanceof NumberHolder)) { return false; } const userTypes = user.getTypes(true); @@ -5160,7 +5158,7 @@ export class MatchUserTypeAttr extends VariableMoveTypeAttr { export class CombinedPledgeTypeAttr extends VariableMoveTypeAttr { override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveType = args[0]; - if (!(moveType instanceof Utils.NumberHolder)) { + if (!(moveType instanceof NumberHolder)) { return false; } @@ -5203,7 +5201,7 @@ export class VariableMoveTypeMultiplierAttr extends MoveAttr { export class NeutralDamageAgainstFlyingTypeMultiplierAttr extends VariableMoveTypeMultiplierAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (!target.getTag(BattlerTagType.IGNORE_FLYING)) { - const multiplier = args[0] as Utils.NumberHolder; + const multiplier = args[0] as NumberHolder; //When a flying type is hit, the first hit is always 1x multiplier. if (target.isOfType(PokemonType.FLYING)) { multiplier.value = 1; @@ -5221,11 +5219,11 @@ export class IceNoEffectTypeAttr extends VariableMoveTypeMultiplierAttr { * @param user n/a * @param target The {@linkcode Pokemon} targeted by the move * @param move n/a - * @param args `[0]` a {@linkcode Utils.NumberHolder | NumberHolder} containing a type effectiveness multiplier + * @param args `[0]` a {@linkcode NumberHolder | NumberHolder} containing a type effectiveness multiplier * @returns `true` if this Ice-type immunity applies; `false` otherwise */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const multiplier = args[0] as Utils.NumberHolder; + const multiplier = args[0] as NumberHolder; if (target.isOfType(PokemonType.ICE)) { multiplier.value = 0; return true; @@ -5236,7 +5234,7 @@ export class IceNoEffectTypeAttr extends VariableMoveTypeMultiplierAttr { export class FlyingTypeMultiplierAttr extends VariableMoveTypeMultiplierAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const multiplier = args[0] as Utils.NumberHolder; + const multiplier = args[0] as NumberHolder; multiplier.value *= target.getAttackTypeEffectiveness(PokemonType.FLYING, user); return true; } @@ -5265,7 +5263,7 @@ export class VariableMoveTypeChartAttr extends MoveAttr { */ export class FreezeDryAttr extends VariableMoveTypeChartAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const multiplier = args[0] as Utils.NumberHolder; + const multiplier = args[0] as NumberHolder; const defType = args[1] as PokemonType; if (defType === PokemonType.WATER) { @@ -5279,7 +5277,7 @@ export class FreezeDryAttr extends VariableMoveTypeChartAttr { export class OneHitKOAccuracyAttr extends VariableAccuracyAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const accuracy = args[0] as Utils.NumberHolder; + const accuracy = args[0] as NumberHolder; if (user.level < target.level) { accuracy.value = 0; } else { @@ -5301,7 +5299,7 @@ export class SheerColdAccuracyAttr extends OneHitKOAccuracyAttr { * @returns Returns true if move is successful, false if misses. */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const accuracy = args[0] as Utils.NumberHolder; + const accuracy = args[0] as NumberHolder; if (user.level < target.level) { accuracy.value = 0; } else { @@ -5343,15 +5341,15 @@ export class NoEffectAttr extends MoveAttr { } const crashDamageFunc = (user: Pokemon, move: Move) => { - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); applyAbAttrs(BlockNonDirectDamageAbAttr, user, cancelled); if (cancelled.value) { return false; } - user.damageAndUpdate(Utils.toDmgValue(user.getMaxHp() / 2), { result: HitResult.INDIRECT }); + user.damageAndUpdate(toDmgValue(user.getMaxHp() / 2), { result: HitResult.INDIRECT }); globalScene.queueMessage(i18next.t("moveTriggers:keptGoingAndCrashed", { pokemonName: getPokemonNameWithAffix(user) })); - user.turnData.damageTaken += Utils.toDmgValue(user.getMaxHp() / 2); + user.turnData.damageTaken += toDmgValue(user.getMaxHp() / 2); return true; }; @@ -6177,10 +6175,10 @@ export class RevivalBlessingAttr extends MoveEffectAttr { const pokemon = faintedPokemon[user.randSeedInt(faintedPokemon.length)]; const slotIndex = globalScene.getEnemyParty().findIndex((p) => pokemon.id === p.id); pokemon.resetStatus(); - pokemon.heal(Math.min(Utils.toDmgValue(0.5 * pokemon.getMaxHp()), pokemon.getMaxHp())); + pokemon.heal(Math.min(toDmgValue(0.5 * pokemon.getMaxHp()), pokemon.getMaxHp())); globalScene.queueMessage(i18next.t("moveTriggers:revivalBlessing", { pokemonName: getPokemonNameWithAffix(pokemon) }), 0, true); const allyPokemon = user.getAlly(); - if (globalScene.currentBattle.double && globalScene.getEnemyParty().length > 1 && !Utils.isNullOrUndefined(allyPokemon)) { + if (globalScene.currentBattle.double && globalScene.getEnemyParty().length > 1 && !isNullOrUndefined(allyPokemon)) { // Handle cases where revived pokemon needs to get switched in on same turn if (allyPokemon.isFainted() || allyPokemon === pokemon) { // Enemy switch phase should be removed and replaced with the revived pkmn switching in @@ -6366,7 +6364,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { globalScene.queueMessage(i18next.t("moveTriggers:fled", { pokemonName: getPokemonNameWithAffix(switchOutTarget) }), null, true, 500); // in double battles redirect potential moves off fled pokemon - if (globalScene.currentBattle.double && !Utils.isNullOrUndefined(allyPokemon)) { + if (globalScene.currentBattle.double && !isNullOrUndefined(allyPokemon)) { globalScene.redirectPokemonMoves(switchOutTarget, allyPokemon); } } @@ -6389,7 +6387,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { } getFailedText(_user: Pokemon, target: Pokemon, _move: Move): string | undefined { - const blockedByAbility = new Utils.BooleanHolder(false); + const blockedByAbility = new BooleanHolder(false); applyAbAttrs(ForceSwitchOutImmunityAbAttr, target, blockedByAbility); if (blockedByAbility.value) { return i18next.t("moveTriggers:cannotBeSwitchedOut", { pokemonName: getPokemonNameWithAffix(target) }); @@ -6417,7 +6415,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { return false; } - const blockedByAbility = new Utils.BooleanHolder(false); + const blockedByAbility = new BooleanHolder(false); applyAbAttrs(ForceSwitchOutImmunityAbAttr, target, blockedByAbility); return !blockedByAbility.value; } @@ -6776,7 +6774,7 @@ export class RandomMoveAttr extends CallMoveAttr { * @param args Unused */ override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const moveIds = Utils.getEnumValues(Moves).map(m => !this.invalidMoves.has(m) && !allMoves[m].name.endsWith(" (N)") ? m : Moves.NONE); + const moveIds = getEnumValues(Moves).map(m => !this.invalidMoves.has(m) && !allMoves[m].name.endsWith(" (N)") ? m : Moves.NONE); let moveId: Moves = Moves.NONE; do { moveId = this.getMoveOverride() ?? moveIds[user.randSeedInt(moveIds.length)]; @@ -7047,7 +7045,7 @@ export class RepeatMoveAttr extends MoveEffectAttr { const firstTarget = globalScene.getField()[moveTargets[0]]; if (globalScene.currentBattle.double && moveTargets.length === 1 && firstTarget.isFainted() && firstTarget !== target.getAlly()) { const ally = firstTarget.getAlly(); - if (!Utils.isNullOrUndefined(ally) && ally.isActive()) { // ally exists, is not dead and can sponge the blast + if (!isNullOrUndefined(ally) && ally.isActive()) { // ally exists, is not dead and can sponge the blast moveTargets = [ ally.getBattlerIndex() ]; } } @@ -7391,11 +7389,13 @@ export class AbilityChangeAttr extends MoveEffectAttr { const moveTarget = this.selfTarget ? user : target; - globalScene.queueMessage(i18next.t("moveTriggers:acquiredAbility", { pokemonName: getPokemonNameWithAffix((this.selfTarget ? user : target)), abilityName: allAbilities[this.ability].name })); - + globalScene.triggerPokemonFormChange(moveTarget, SpeciesFormChangeRevertWeatherFormTrigger); + if (moveTarget.breakIllusion()) { + globalScene.queueMessage(i18next.t("abilityTriggers:illusionBreak", { pokemonName: getPokemonNameWithAffix(moveTarget) })); + } + globalScene.queueMessage(i18next.t("moveTriggers:acquiredAbility", { pokemonName: getPokemonNameWithAffix(moveTarget), abilityName: allAbilities[this.ability].name })); moveTarget.setTempAbility(allAbilities[this.ability]); globalScene.triggerPokemonFormChange(moveTarget, SpeciesFormChangeRevertWeatherFormTrigger); - return true; } @@ -7423,7 +7423,7 @@ export class AbilityCopyAttr extends MoveEffectAttr { user.setTempAbility(target.getAbility()); const ally = user.getAlly(); - if (this.copyToPartner && globalScene.currentBattle?.double && !Utils.isNullOrUndefined(ally) && ally.hp) { // TODO is this the best way to check that the ally is active? + if (this.copyToPartner && globalScene.currentBattle?.double && !isNullOrUndefined(ally) && ally.hp) { // TODO is this the best way to check that the ally is active? globalScene.queueMessage(i18next.t("moveTriggers:copiedTargetAbility", { pokemonName: getPokemonNameWithAffix(ally), targetName: getPokemonNameWithAffix(target), abilityName: allAbilities[target.getAbility().id].name })); ally.setTempAbility(target.getAbility()); } @@ -7839,7 +7839,7 @@ export class VariableTargetAttr extends MoveAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const targetVal = args[0] as Utils.NumberHolder; + const targetVal = args[0] as NumberHolder; targetVal.value = this.targetChangeFunc(user, target, move); return true; } @@ -7930,7 +7930,7 @@ const failOnBossCondition: MoveConditionFunc = (user, target, move) => !target.i const failIfSingleBattle: MoveConditionFunc = (user, target, move) => globalScene.currentBattle.double; const failIfDampCondition: MoveConditionFunc = (user, target, move) => { - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); globalScene.getField(true).map(p=>applyAbAttrs(FieldPreventExplosiveMovesAbAttr, p, cancelled)); // Queue a message if an ability prevented usage of the move if (cancelled.value) { @@ -8065,7 +8065,7 @@ export class UpperHandCondition extends MoveCondition { export class hitsSameTypeAttr extends VariableMoveTypeMultiplierAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const multiplier = args[0] as Utils.NumberHolder; + const multiplier = args[0] as NumberHolder; if (!user.getTypes().some(type => target.getTypes().includes(type))) { multiplier.value = 0; return true; @@ -8116,7 +8116,7 @@ export class ResistLastMoveTypeAttr extends MoveEffectAttr { } const type = validTypes[user.randSeedInt(validTypes.length)]; user.summonData.types = [ type ]; - globalScene.queueMessage(i18next.t("battle:transformedIntoType", { pokemonName: getPokemonNameWithAffix(user), type: Utils.toReadableString(PokemonType[type]) })); + globalScene.queueMessage(i18next.t("battle:transformedIntoType", { pokemonName: getPokemonNameWithAffix(user), type: toReadableString(PokemonType[type]) })); user.updateInfo(); return true; @@ -8190,7 +8190,7 @@ export type MoveTargetSet = { }; export function getMoveTargets(user: Pokemon, move: Moves, replaceTarget?: MoveTarget): MoveTargetSet { - const variableTarget = new Utils.NumberHolder(0); + const variableTarget = new NumberHolder(0); user.getOpponents().forEach(p => applyMoveAttrs(VariableTargetAttr, user, p, allMoves[move], variableTarget)); let moveTarget: MoveTarget | undefined; @@ -8218,7 +8218,7 @@ export function getMoveTargets(user: Pokemon, move: Moves, replaceTarget?: MoveT case MoveTarget.OTHER: case MoveTarget.ALL_NEAR_OTHERS: case MoveTarget.ALL_OTHERS: - set = !Utils.isNullOrUndefined(ally) ? (opponents.concat([ ally ])) : opponents; + set = !isNullOrUndefined(ally) ? (opponents.concat([ ally ])) : opponents; multiple = moveTarget === MoveTarget.ALL_NEAR_OTHERS || moveTarget === MoveTarget.ALL_OTHERS; break; case MoveTarget.NEAR_ENEMY: @@ -8235,21 +8235,21 @@ export function getMoveTargets(user: Pokemon, move: Moves, replaceTarget?: MoveT return { targets: [ -1 as BattlerIndex ], multiple: false }; case MoveTarget.NEAR_ALLY: case MoveTarget.ALLY: - set = !Utils.isNullOrUndefined(ally) ? [ ally ] : []; + set = !isNullOrUndefined(ally) ? [ ally ] : []; break; case MoveTarget.USER_OR_NEAR_ALLY: case MoveTarget.USER_AND_ALLIES: case MoveTarget.USER_SIDE: - set = !Utils.isNullOrUndefined(ally) ? [ user, ally ] : [ user ]; + set = !isNullOrUndefined(ally) ? [ user, ally ] : [ user ]; multiple = moveTarget !== MoveTarget.USER_OR_NEAR_ALLY; break; case MoveTarget.ALL: case MoveTarget.BOTH_SIDES: - set = (!Utils.isNullOrUndefined(ally) ? [ user, ally ] : [ user ]).concat(opponents); + set = (!isNullOrUndefined(ally) ? [ user, ally ] : [ user ]).concat(opponents); multiple = true; break; case MoveTarget.CURSE: - const extraTargets = !Utils.isNullOrUndefined(ally) ? [ ally ] : []; + const extraTargets = !isNullOrUndefined(ally) ? [ ally ] : []; set = user.getTypes(true).includes(PokemonType.GHOST) ? (opponents.concat(extraTargets)) : [ user ]; break; } @@ -8408,7 +8408,7 @@ export function initMoves() { .attr(AddBattlerTagAttr, BattlerTagType.DISABLED, false, true) .condition((user, target, move) => { const lastRealMove = target.getLastXMoves(-1).find(m => !m.virtual); - return !Utils.isNullOrUndefined(lastRealMove) && lastRealMove.move !== Moves.NONE && lastRealMove.move !== Moves.STRUGGLE; + return !isNullOrUndefined(lastRealMove) && lastRealMove.move !== Moves.NONE && lastRealMove.move !== Moves.STRUGGLE; }) .ignoresSubstitute() .reflectable(), @@ -8675,6 +8675,8 @@ export function initMoves() { .makesContact(false), new StatusMove(Moves.TRANSFORM, PokemonType.NORMAL, -1, 10, -1, 0, 1) .attr(TransformAttr) + .condition((user, target, move) => !target.getTag(BattlerTagType.SUBSTITUTE)) + .condition((user, target, move) => !target.summonData?.illusion && !user.summonData?.illusion) // transforming from or into fusion pokemon causes various problems (such as crashes) .condition((user, target, move) => !target.getTag(BattlerTagType.SUBSTITUTE) && !user.fusionSpecies && !target.fusionSpecies) .ignoresProtect(), @@ -9716,7 +9718,7 @@ export function initMoves() { .condition(failOnGravityCondition) .condition((_user, target, _move) => ![ Species.DIGLETT, Species.DUGTRIO, Species.ALOLA_DIGLETT, Species.ALOLA_DUGTRIO, Species.SANDYGAST, Species.PALOSSAND, Species.WIGLETT, Species.WUGTRIO ].includes(target.species.speciesId)) .condition((_user, target, _move) => !(target.species.speciesId === Species.GENGAR && target.getFormKey() === "mega")) - .condition((_user, target, _move) => Utils.isNullOrUndefined(target.getTag(BattlerTagType.INGRAIN)) && Utils.isNullOrUndefined(target.getTag(BattlerTagType.IGNORE_FLYING))) + .condition((_user, target, _move) => isNullOrUndefined(target.getTag(BattlerTagType.INGRAIN)) && isNullOrUndefined(target.getTag(BattlerTagType.IGNORE_FLYING))) .attr(AddBattlerTagAttr, BattlerTagType.TELEKINESIS, false, true, 3) .attr(AddBattlerTagAttr, BattlerTagType.FLOATING, false, true, 3) .reflectable(), diff --git a/src/data/mystery-encounters/encounters/mysterious-challengers-encounter.ts b/src/data/mystery-encounters/encounters/mysterious-challengers-encounter.ts index 11924f93df4..5f88ca083c0 100644 --- a/src/data/mystery-encounters/encounters/mysterious-challengers-encounter.ts +++ b/src/data/mystery-encounters/encounters/mysterious-challengers-encounter.ts @@ -12,7 +12,7 @@ import { modifierTypes } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { PartyMemberStrength } from "#enums/party-member-strength"; import { globalScene } from "#app/global-scene"; -import * as Utils from "#app/utils"; +import { randSeedInt } from "#app/utils"; import type MysteryEncounter from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; @@ -46,7 +46,7 @@ export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounter const normalConfig = trainerConfigs[normalTrainerType].clone(); let female = false; if (normalConfig.hasGenders) { - female = !!Utils.randSeedInt(2); + female = !!randSeedInt(2); } const normalSpriteKey = normalConfig.getSpriteKey(female, normalConfig.doubleOnly); encounter.enemyPartyConfigs.push({ @@ -76,7 +76,7 @@ export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounter hardConfig.setPartyTemplates(hardTemplate); female = false; if (hardConfig.hasGenders) { - female = !!Utils.randSeedInt(2); + female = !!randSeedInt(2); } const hardSpriteKey = hardConfig.getSpriteKey(female, hardConfig.doubleOnly); encounter.enemyPartyConfigs.push({ @@ -96,7 +96,7 @@ export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounter brutalConfig.partyTemplateFunc = null; // Overrides gym leader party template func female = false; if (brutalConfig.hasGenders) { - female = !!Utils.randSeedInt(2); + female = !!randSeedInt(2); } const brutalSpriteKey = brutalConfig.getSpriteKey(female, brutalConfig.doubleOnly); encounter.enemyPartyConfigs.push({ diff --git a/src/data/mystery-encounters/mystery-encounter.ts b/src/data/mystery-encounters/mystery-encounter.ts index 53e976cda8a..ff098d4d7dd 100644 --- a/src/data/mystery-encounters/mystery-encounter.ts +++ b/src/data/mystery-encounters/mystery-encounter.ts @@ -5,7 +5,7 @@ import { capitalizeFirstLetter, isNullOrUndefined } from "#app/utils"; import type { MysteryEncounterType } from "#enums/mystery-encounter-type"; import type { MysteryEncounterSpriteConfig } from "#app/field/mystery-encounter-intro"; import MysteryEncounterIntroVisuals from "#app/field/mystery-encounter-intro"; -import * as Utils from "#app/utils"; +import { randSeedInt } from "#app/utils"; import type { StatusEffect } from "#enums/status-effect"; import type { OptionTextDisplay } from "./mystery-encounter-dialogue"; import type MysteryEncounterDialogue from "./mystery-encounter-dialogue"; @@ -378,13 +378,13 @@ export default class MysteryEncounter implements IMysteryEncounter { } if (truePrimaryPool.length > 0) { // Always choose from the non-overlapping pokemon first - this.primaryPokemon = truePrimaryPool[Utils.randSeedInt(truePrimaryPool.length, 0)]; + this.primaryPokemon = truePrimaryPool[randSeedInt(truePrimaryPool.length, 0)]; return true; } // If there are multiple overlapping pokemon, we're okay - just choose one and take it out of the primary pokemon pool if (overlap.length > 1 || this.secondaryPokemon.length - overlap.length >= 1) { // is this working? - this.primaryPokemon = overlap[Utils.randSeedInt(overlap.length, 0)]; + this.primaryPokemon = overlap[randSeedInt(overlap.length, 0)]; this.secondaryPokemon = this.secondaryPokemon.filter(supp => supp !== this.primaryPokemon); return true; } @@ -394,7 +394,7 @@ export default class MysteryEncounter implements IMysteryEncounter { return false; } // this means we CAN have the same pokemon be a primary and secondary pokemon, so just choose any qualifying one randomly. - this.primaryPokemon = qualified[Utils.randSeedInt(qualified.length, 0)]; + this.primaryPokemon = qualified[randSeedInt(qualified.length, 0)]; return true; } diff --git a/src/data/mystery-encounters/utils/encounter-phase-utils.ts b/src/data/mystery-encounters/utils/encounter-phase-utils.ts index 76d07bf01ba..a9f6b787878 100644 --- a/src/data/mystery-encounters/utils/encounter-phase-utils.ts +++ b/src/data/mystery-encounters/utils/encounter-phase-utils.ts @@ -30,8 +30,7 @@ import type { OptionSelectConfig, OptionSelectItem } from "#app/ui/abstact-optio import type { PartyOption, PokemonSelectFilter } from "#app/ui/party-ui-handler"; import { PartyUiMode } from "#app/ui/party-ui-handler"; import { Mode } from "#app/ui/ui"; -import * as Utils from "#app/utils"; -import { isNullOrUndefined, randSeedInt, randSeedItem } from "#app/utils"; +import { isNullOrUndefined, randSeedInt, randomString, randSeedItem } from "#app/utils"; import type { BattlerTagType } from "#enums/battler-tag-type"; import { Biome } from "#enums/biome"; import type { TrainerType } from "#enums/trainer-type"; @@ -58,7 +57,7 @@ import { BattleEndPhase } from "#app/phases/battle-end-phase"; import { GameOverPhase } from "#app/phases/game-over-phase"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; import { PartyExpPhase } from "#app/phases/party-exp-phase"; -import type { Variant } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; import { StatusEffect } from "#enums/status-effect"; import { globalScene } from "#app/global-scene"; import { getPokemonSpecies } from "#app/data/pokemon-species"; @@ -168,7 +167,7 @@ export async function initBattleWithEnemyConfig(partyConfig: EnemyPartyConfig): const doubleTrainer = trainerConfig.doubleOnly || (trainerConfig.hasDouble && !!partyConfig.doubleBattle); doubleBattle = doubleTrainer; - const trainerFemale = isNullOrUndefined(partyConfig.female) ? !!Utils.randSeedInt(2) : partyConfig.female; + const trainerFemale = isNullOrUndefined(partyConfig.female) ? !!randSeedInt(2) : partyConfig.female; const newTrainer = new Trainer( trainerConfig.trainerType, doubleTrainer ? TrainerVariant.DOUBLE : trainerFemale ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT, @@ -286,7 +285,7 @@ export async function initBattleWithEnemyConfig(partyConfig: EnemyPartyConfig): // Generate new id, reset status and HP in case using data source if (config.dataSource) { - enemyPokemon.id = Utils.randSeedInt(4294967296); + enemyPokemon.id = randSeedInt(4294967296); } // Set form @@ -1115,7 +1114,7 @@ export function calculateMEAggregateStats(baseSpawnWeight: number) { const validMEfloorsByBiome = new Map(biomes.map(b => [b, 0])); let currentBiome = Biome.TOWN; let currentArena = globalScene.newArena(currentBiome); - globalScene.setSeed(Utils.randomString(24)); + globalScene.setSeed(randomString(24)); globalScene.resetSeed(); for (let i = 10; i < 180; i++) { // Boss @@ -1130,16 +1129,16 @@ export function calculateMEAggregateStats(baseSpawnWeight: number) { globalScene.executeWithSeedOffset(() => { biomes = (biomeLinks[currentBiome] as (Biome | [Biome, number])[]) .filter(b => { - return !Array.isArray(b) || !Utils.randSeedInt(b[1]); + return !Array.isArray(b) || !randSeedInt(b[1]); }) .map(b => (!Array.isArray(b) ? b : b[0])); }, i * 100); if (biomes! && biomes.length > 0) { const specialBiomes = biomes.filter(b => alwaysPickTheseBiomes.includes(b)); if (specialBiomes.length > 0) { - currentBiome = specialBiomes[Utils.randSeedInt(specialBiomes.length)]; + currentBiome = specialBiomes[randSeedInt(specialBiomes.length)]; } else { - currentBiome = biomes[Utils.randSeedInt(biomes.length)]; + currentBiome = biomes[randSeedInt(biomes.length)]; } } } else if (biomeLinks.hasOwnProperty(currentBiome)) { @@ -1167,7 +1166,7 @@ export function calculateMEAggregateStats(baseSpawnWeight: number) { // Otherwise, roll encounter - const roll = Utils.randSeedInt(256); + const roll = randSeedInt(256); validMEfloorsByBiome.set(Biome[currentBiome], (validMEfloorsByBiome.get(Biome[currentBiome]) ?? 0) + 1); // If total number of encounters is lower than expected for the run, slightly favor a new encounter @@ -1192,7 +1191,7 @@ export function calculateMEAggregateStats(baseSpawnWeight: number) { tierWeights[1] = tierWeights[1] - 4 * numEncounters[1]; const totalWeight = tierWeights.reduce((a, b) => a + b); - const tierValue = Utils.randSeedInt(totalWeight); + const tierValue = randSeedInt(totalWeight); const commonThreshold = totalWeight - tierWeights[0]; // 64 - 32 = 32 const uncommonThreshold = totalWeight - tierWeights[0] - tierWeights[1]; // 64 - 32 - 16 = 16 const rareThreshold = totalWeight - tierWeights[0] - tierWeights[1] - tierWeights[2]; // 64 - 32 - 16 - 10 = 6 @@ -1281,7 +1280,7 @@ export function calculateRareSpawnAggregateStats(luckValue: number) { const calculateNumRareEncounters = (): any[] => { const bossEncountersByRarity = [0, 0, 0, 0]; - globalScene.setSeed(Utils.randomString(24)); + globalScene.setSeed(randomString(24)); globalScene.resetSeed(); // There are 12 wild boss floors for (let i = 0; i < 12; i++) { @@ -1291,7 +1290,7 @@ export function calculateRareSpawnAggregateStats(luckValue: number) { if (!Number.isNaN(luckValue)) { luckModifier = luckValue * 0.5; } - const tierValue = Utils.randSeedInt(64 - luckModifier); + const tierValue = randSeedInt(64 - luckModifier); const tier = tierValue >= 20 ? BiomePoolTier.BOSS diff --git a/src/data/nature.ts b/src/data/nature.ts index e23d92c14b0..2ab4723c10d 100644 --- a/src/data/nature.ts +++ b/src/data/nature.ts @@ -1,4 +1,4 @@ -import * as Utils from "../utils"; +import { toReadableString } from "#app/utils"; import { TextStyle, getBBCodeFrag } from "../ui/text"; import { Nature } from "#enums/nature"; import { UiTheme } from "#enums/ui-theme"; @@ -12,7 +12,7 @@ export function getNatureName( ignoreBBCode = false, uiTheme: UiTheme = UiTheme.DEFAULT, ): string { - let ret = Utils.toReadableString(Nature[nature]); + let ret = toReadableString(Nature[nature]); //Translating nature if (i18next.exists(`nature:${ret}`)) { ret = i18next.t(`nature:${ret}` as any); diff --git a/src/data/pokemon-species.ts b/src/data/pokemon-species.ts index 929d632eb0b..a27c00121dc 100644 --- a/src/data/pokemon-species.ts +++ b/src/data/pokemon-species.ts @@ -8,7 +8,7 @@ import type { AnySound } from "#app/battle-scene"; import { globalScene } from "#app/global-scene"; import type { GameMode } from "#app/game-mode"; import { DexAttr, type StarterMoveset } from "#app/system/game-data"; -import * as Utils from "#app/utils"; +import { isNullOrUndefined, capitalizeString, randSeedInt, randSeedGauss, randSeedItem } from "#app/utils"; import { uncatchableSpecies } from "#app/data/balance/biomes"; import { speciesEggMoves } from "#app/data/balance/egg-moves"; import { GrowthRate } from "#app/data/exp"; @@ -26,11 +26,12 @@ import { pokemonSpeciesLevelMoves, } from "#app/data/balance/pokemon-level-moves"; import type { Stat } from "#enums/stat"; -import type { Variant, VariantSet } from "#app/data/variant"; -import { variantData } from "#app/data/variant"; +import type { Variant, VariantSet } from "#app/sprites/variant"; +import { variantData } from "#app/sprites/variant"; import { speciesStarterCosts, POKERUS_STARTER_COUNT } from "#app/data/balance/starters"; import { SpeciesFormKey } from "#enums/species-form-key"; import { starterPassiveAbilities } from "#app/data/balance/passives"; +import { loadPokemonVariantAssets } from "#app/sprites/pokemon-sprite"; export enum Region { NORMAL, @@ -289,7 +290,7 @@ export abstract class PokemonSpeciesForm { * @returns The id of the ability */ getPassiveAbility(formIndex?: number): Abilities { - if (Utils.isNullOrUndefined(formIndex)) { + if (isNullOrUndefined(formIndex)) { formIndex = this.formIndex; } let starterSpeciesId = this.speciesId; @@ -387,6 +388,7 @@ export abstract class PokemonSpeciesForm { return `${/_[1-3]$/.test(spriteId) ? "variant/" : ""}${spriteId}`; } + /** Compute the sprite ID of the pokemon form. */ getSpriteId(female: boolean, formIndex?: number, shiny?: boolean, variant = 0, back?: boolean): string { if (formIndex === undefined || this instanceof PokemonForm) { formIndex = this.formIndex; @@ -394,7 +396,9 @@ export abstract class PokemonSpeciesForm { const formSpriteKey = this.getFormSpriteKey(formIndex); const showGenderDiffs = - this.genderDiffs && female && ![SpeciesFormKey.MEGA, SpeciesFormKey.GIGANTAMAX].find(k => formSpriteKey === k); + this.genderDiffs && + female && + ![SpeciesFormKey.MEGA, SpeciesFormKey.GIGANTAMAX].includes(formSpriteKey as SpeciesFormKey); const baseSpriteKey = `${showGenderDiffs ? "female__" : ""}${this.speciesId}${formSpriteKey ? `-${formSpriteKey}` : ""}`; @@ -585,18 +589,19 @@ export abstract class PokemonSpeciesForm { return true; } - loadAssets( + async loadAssets( female: boolean, formIndex?: number, - shiny?: boolean, + shiny = false, variant?: Variant, - startLoad?: boolean, - back?: boolean, + startLoad = false, + back = false, ): Promise { - return new Promise(resolve => { - const spriteKey = this.getSpriteKey(female, formIndex, shiny, variant, back); - globalScene.loadPokemonAtlas(spriteKey, this.getSpriteAtlasPath(female, formIndex, shiny, variant, back)); - globalScene.load.audio(`${this.getCryKey(formIndex)}`, `audio/${this.getCryKey(formIndex)}.m4a`); + const spriteKey = this.getSpriteKey(female, formIndex, shiny, variant, back); + globalScene.loadPokemonAtlas(spriteKey, this.getSpriteAtlasPath(female, formIndex, shiny, variant, back)); + globalScene.load.audio(this.getCryKey(formIndex), `audio/${this.getCryKey(formIndex)}.m4a`); + + return new Promise(resolve => { globalScene.load.once(Phaser.Loader.Events.COMPLETE, () => { const originalWarn = console.warn; // Ignore warnings for missing frames, because there will be a lot @@ -621,7 +626,9 @@ export abstract class PokemonSpeciesForm { const spritePath = this.getSpriteAtlasPath(female, formIndex, shiny, variant, back) .replace("variant/", "") .replace(/_[1-3]$/, ""); - globalScene.loadPokemonVariantAssets(spriteKey, spritePath, variant).then(() => resolve()); + if (!isNullOrUndefined(variant)) { + loadPokemonVariantAssets(spriteKey, spritePath, variant).then(() => resolve()); + } }); if (startLoad) { if (!globalScene.load.isLoading()) { @@ -845,8 +852,8 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali */ getFormNameToDisplay(formIndex = 0, append = false): string { const formKey = this.forms?.[formIndex!]?.formKey; - const formText = Utils.capitalizeString(formKey, "-", false, false) || ""; - const speciesName = Utils.capitalizeString(Species[this.speciesId], "_", true, false); + const formText = capitalizeString(formKey, "-", false, false) || ""; + const speciesName = capitalizeString(Species[this.speciesId], "_", true, false); let ret = ""; const region = this.getRegion(); @@ -877,7 +884,7 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali if (i18next.exists(i18key)) { ret = i18next.t(i18key); } else { - const rootSpeciesName = Utils.capitalizeString(Species[this.getRootSpeciesId()], "_", true, false); + const rootSpeciesName = capitalizeString(Species[this.getRootSpeciesId()], "_", true, false); const i18RootKey = `pokemonForm:${rootSpeciesName}${formText}`; ret = i18next.exists(i18RootKey) ? i18next.t(i18RootKey) : formText; } @@ -1072,7 +1079,7 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali return this.speciesId; } - const randValue = evolutionPool.size === 1 ? 0 : Utils.randSeedInt(totalWeight); + const randValue = evolutionPool.size === 1 ? 0 : randSeedInt(totalWeight); for (const weight of evolutionPool.keys()) { if (randValue < weight) { @@ -1157,7 +1164,7 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali Math.min( Math.max( evolution?.level! + - Math.round(Utils.randSeedGauss(0.5, 1 + levelDiff * 0.2) * Math.max(evolution?.wildDelay!, 0.5) * 5) - + Math.round(randSeedGauss(0.5, 1 + levelDiff * 0.2) * Math.max(evolution?.wildDelay!, 0.5) * 5) - 1, 2, evolution?.level!, @@ -1175,7 +1182,7 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali Math.min( Math.max( lastPrevolutionLevel + - Math.round(Utils.randSeedGauss(0.5, 1 + levelDiff * 0.2) * Math.max(evolution?.wildDelay!, 0.5) * 5), + Math.round(randSeedGauss(0.5, 1 + levelDiff * 0.2) * Math.max(evolution?.wildDelay!, 0.5) * 5), lastPrevolutionLevel + 1, evolution?.level!, ), @@ -1360,7 +1367,7 @@ export function getPokerusStarters(): PokemonSpecies[] { globalScene.executeWithSeedOffset( () => { while (pokerusStarters.length < POKERUS_STARTER_COUNT) { - const randomSpeciesId = Number.parseInt(Utils.randSeedItem(Object.keys(speciesStarterCosts)), 10); + const randomSpeciesId = Number.parseInt(randSeedItem(Object.keys(speciesStarterCosts)), 10); const species = getPokemonSpecies(randomSpeciesId); if (!pokerusStarters.includes(species)) { pokerusStarters.push(species); diff --git a/src/data/trainer-names.ts b/src/data/trainer-names.ts index 26cea19070f..195e5041d28 100644 --- a/src/data/trainer-names.ts +++ b/src/data/trainer-names.ts @@ -1,12 +1,12 @@ import { TrainerType } from "#enums/trainer-type"; -import * as Utils from "../utils"; +import { toReadableString } from "#app/utils"; class TrainerNameConfig { public urls: string[]; public femaleUrls: string[] | null; constructor(type: TrainerType, ...urls: string[]) { - this.urls = urls.length ? urls : [Utils.toReadableString(TrainerType[type]).replace(/ /g, "_")]; + this.urls = urls.length ? urls : [toReadableString(TrainerType[type]).replace(/ /g, "_")]; } hasGenderVariant(...femaleUrls: string[]): TrainerNameConfig { diff --git a/src/data/trainers/trainer-config.ts b/src/data/trainers/trainer-config.ts index a5ba19290fe..0ab7119dab9 100644 --- a/src/data/trainers/trainer-config.ts +++ b/src/data/trainers/trainer-config.ts @@ -1,7 +1,7 @@ import { globalScene } from "#app/global-scene"; import { modifierTypes } from "#app/modifier/modifier-type"; import { PokemonMove } from "#app/field/pokemon"; -import * as Utils from "#app/utils"; +import { toReadableString, isNullOrUndefined, randSeedItem, randSeedInt } from "#app/utils"; import { pokemonEvolutions, pokemonPrevolutions } from "#app/data/balance/pokemon-evolutions"; import { getPokemonSpecies } from "#app/data/pokemon-species"; import { tmSpecies } from "#app/data/balance/tms"; @@ -139,7 +139,7 @@ export class TrainerConfig { constructor(trainerType: TrainerType, allowLegendaries?: boolean) { this.trainerType = trainerType; this.trainerAI = new TrainerAI(); - this.name = Utils.toReadableString(TrainerType[this.getDerivedType()]); + this.name = toReadableString(TrainerType[this.getDerivedType()]); this.battleBgm = "battle_trainer"; this.mixedBattleBgm = "battle_trainer"; this.victoryBgm = "victory_trainer"; @@ -482,10 +482,10 @@ export class TrainerConfig { .fill(null) .map((_, i) => i) .filter(i => shedinjaCanTera || party[i].species.speciesId !== Species.SHEDINJA); // Shedinja can only Tera on Bug specialty type (or no specialty type) - const setPartySlot = !Utils.isNullOrUndefined(slot) ? Phaser.Math.Wrap(slot, 0, party.length) : -1; // If we have a tera slot defined, wrap it to party size. + const setPartySlot = !isNullOrUndefined(slot) ? Phaser.Math.Wrap(slot, 0, party.length) : -1; // If we have a tera slot defined, wrap it to party size. for (let t = 0; t < Math.min(count(), party.length); t++) { const randomIndex = - partyMemberIndexes.indexOf(setPartySlot) > -1 ? setPartySlot : Utils.randSeedItem(partyMemberIndexes); + partyMemberIndexes.indexOf(setPartySlot) > -1 ? setPartySlot : randSeedItem(partyMemberIndexes); partyMemberIndexes.splice(partyMemberIndexes.indexOf(randomIndex), 1); if (this.hasSpecialtyType()) { party[randomIndex].teraType = this.specialtyType; @@ -555,7 +555,7 @@ export class TrainerConfig { initI18n(); } - if (!Utils.isNullOrUndefined(specialtyType)) { + if (!isNullOrUndefined(specialtyType)) { this.setSpecialtyType(specialtyType); } @@ -636,7 +636,7 @@ export class TrainerConfig { } this.setPartyMemberFunc(-(s + 1), getRandomPartyMemberFunc(speciesPool)); }); - if (!Utils.isNullOrUndefined(specialtyType)) { + if (!isNullOrUndefined(specialtyType)) { this.setSpeciesFilter(p => p.isOfType(specialtyType)); this.setSpecialtyType(specialtyType); } @@ -749,7 +749,7 @@ export class TrainerConfig { }); // Set species filter and specialty type if provided, otherwise filter by base total. - if (!Utils.isNullOrUndefined(specialtyType)) { + if (!isNullOrUndefined(specialtyType)) { this.setSpeciesFilter(p => p.isOfType(specialtyType) && p.baseTotal >= ELITE_FOUR_MINIMUM_BST); this.setSpecialtyType(specialtyType); } else { @@ -927,7 +927,7 @@ export class TrainerConfig { * @returns true if specialtyType is defined and not Type.UNKNOWN */ hasSpecialtyType(): boolean { - return !Utils.isNullOrUndefined(this.specialtyType) && this.specialtyType !== PokemonType.UNKNOWN; + return !isNullOrUndefined(this.specialtyType) && this.specialtyType !== PokemonType.UNKNOWN; } /** @@ -1006,7 +1006,7 @@ export function getRandomPartyMemberFunc( postProcess?: (enemyPokemon: EnemyPokemon) => void, ) { return (level: number, strength: PartyMemberStrength) => { - let species = Utils.randSeedItem(speciesPool); + let species = randSeedItem(speciesPool); if (!ignoreEvolution) { species = getPokemonSpecies(species).getTrainerSpeciesForLevel( level, @@ -2236,12 +2236,7 @@ export const trainerConfigs: TrainerConfigs = { Species.PHANTUMP, Species.PUMPKABOO, ], - [TrainerPoolTier.RARE]: [ - Species.SNEASEL, - Species.LITWICK, - Species.PAWNIARD, - Species.NOIBAT, - ], + [TrainerPoolTier.RARE]: [Species.SNEASEL, Species.LITWICK, Species.PAWNIARD, Species.NOIBAT], [TrainerPoolTier.SUPER_RARE]: [Species.SLIGGOO, Species.HISUI_SLIGGOO, Species.HISUI_AVALUGG], }), [TrainerType.BRYONY]: new TrainerConfig(++t) @@ -3554,7 +3549,7 @@ export const trainerConfigs: TrainerConfigs = { .setPartyMemberFunc( 5, getRandomPartyMemberFunc([Species.URSHIFU], TrainerSlot.TRAINER, true, p => { - p.formIndex = Utils.randSeedInt(2, 2); // Random G-Max Urshifu + p.formIndex = randSeedInt(2, 2); // Random G-Max Urshifu p.generateAndPopulateMoveset(); p.generateName(); p.gender = Gender.MALE; @@ -3664,10 +3659,10 @@ export const trainerConfigs: TrainerConfigs = { .setPartyMemberFunc( 4, getRandomPartyMemberFunc([Species.OGERPON], TrainerSlot.TRAINER, true, p => { - p.formIndex = Utils.randSeedInt(4); // Random Ogerpon Tera Mask + p.formIndex = randSeedInt(4); // Random Ogerpon Tera Mask p.generateAndPopulateMoveset(); p.pokeball = PokeballType.ULTRA_BALL; - if (!p.moveset.some(move => !Utils.isNullOrUndefined(move) && move.moveId === Moves.IVY_CUDGEL)) { + if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === Moves.IVY_CUDGEL)) { // Check if Ivy Cudgel is in the moveset, if not, replace the first move with Ivy Cudgel. p.moveset[0] = new PokemonMove(Moves.IVY_CUDGEL); } @@ -4718,10 +4713,10 @@ export const trainerConfigs: TrainerConfigs = { .setPartyMemberFunc( 2, getRandomPartyMemberFunc([Species.SILVALLY], TrainerSlot.TRAINER, true, p => { - p.formIndex = Utils.randSeedInt(18); // Random Silvally Form + p.formIndex = randSeedInt(18); // Random Silvally Form p.generateAndPopulateMoveset(); p.pokeball = PokeballType.ROGUE_BALL; - if (!p.moveset.some(move => !Utils.isNullOrUndefined(move) && move.moveId === Moves.MULTI_ATTACK)) { + if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === Moves.MULTI_ATTACK)) { // Check if Multi Attack is in the moveset, if not, replace the first move with Multi Attack. p.moveset[0] = new PokemonMove(Moves.MULTI_ATTACK); } @@ -4838,8 +4833,8 @@ export const trainerConfigs: TrainerConfigs = { p.setBoss(true, 2); p.generateAndPopulateMoveset(); p.pokeball = PokeballType.ULTRA_BALL; - p.formIndex = Utils.randSeedInt(4, 1); // Shock, Burn, Chill, or Douse Drive - if (!p.moveset.some(move => !Utils.isNullOrUndefined(move) && move.moveId === Moves.TECHNO_BLAST)) { + p.formIndex = randSeedInt(4, 1); // Shock, Burn, Chill, or Douse Drive + if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === Moves.TECHNO_BLAST)) { // Check if Techno Blast is in the moveset, if not, replace the first move with Techno Blast. p.moveset[2] = new PokemonMove(Moves.TECHNO_BLAST); } @@ -5011,7 +5006,7 @@ export const trainerConfigs: TrainerConfigs = { 1, getRandomPartyMemberFunc([Species.ROTOM], TrainerSlot.TRAINER, true, p => { p.generateAndPopulateMoveset(); - p.formIndex = Utils.randSeedInt(5, 1); // Heat, Wash, Frost, Fan, or Mow + p.formIndex = randSeedInt(5, 1); // Heat, Wash, Frost, Fan, or Mow }), ) .setPartyMemberFunc( @@ -5024,7 +5019,7 @@ export const trainerConfigs: TrainerConfigs = { .setPartyMemberFunc( 3, getRandomPartyMemberFunc([Species.REVAVROOM], TrainerSlot.TRAINER, true, p => { - p.formIndex = Utils.randSeedInt(5, 1); // Random Starmobile form + p.formIndex = randSeedInt(5, 1); // Random Starmobile form p.generateAndPopulateMoveset(); p.pokeball = PokeballType.ROGUE_BALL; }), diff --git a/src/data/variant.ts b/src/data/variant.ts deleted file mode 100644 index 13c11b0bb40..00000000000 --- a/src/data/variant.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { VariantTier } from "#app/enums/variant-tier"; - -export type Variant = 0 | 1 | 2; - -export type VariantSet = [Variant, Variant, Variant]; - -export const variantData: any = {}; - -export const variantColorCache = {}; - -export function getVariantTint(variant: Variant): number { - switch (variant) { - case 0: - return 0xf8c020; - case 1: - return 0x20f8f0; - case 2: - return 0xe81048; - } -} - -export function getVariantIcon(variant: Variant): number { - switch (variant) { - case 0: - return VariantTier.STANDARD; - case 1: - return VariantTier.RARE; - case 2: - return VariantTier.EPIC; - } -} diff --git a/src/data/weather.ts b/src/data/weather.ts index 34978232377..a8dd0a66492 100644 --- a/src/data/weather.ts +++ b/src/data/weather.ts @@ -5,7 +5,7 @@ import type Pokemon from "../field/pokemon"; import { PokemonType } from "#enums/pokemon-type"; import type Move from "./moves/move"; import { AttackMove } from "./moves/move"; -import * as Utils from "../utils"; +import { randSeedInt } from "#app/utils"; import { SuppressWeatherEffectAbAttr } from "./ability"; import { TerrainType, getTerrainName } from "./terrain"; import i18next from "i18next"; @@ -416,7 +416,7 @@ export function getRandomWeatherType(arena: Arena): WeatherType { totalWeight += w.weight; } - const rand = Utils.randSeedInt(totalWeight); + const rand = randSeedInt(totalWeight); let w = 0; for (const weather of weatherPool) { w += weather.weight; diff --git a/src/field/anims.ts b/src/field/anims.ts index cd6209dddff..eb895c2d8f9 100644 --- a/src/field/anims.ts +++ b/src/field/anims.ts @@ -1,6 +1,6 @@ import { globalScene } from "#app/global-scene"; import { PokeballType } from "#enums/pokeball"; -import type { Variant } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; import { getFrameMs, randGauss } from "#app/utils"; export function addPokeballOpenParticles(x: number, y: number, pokeballType: PokeballType): void { diff --git a/src/field/arena.ts b/src/field/arena.ts index cf48647e45e..adc3123ce81 100644 --- a/src/field/arena.ts +++ b/src/field/arena.ts @@ -1,8 +1,7 @@ import { globalScene } from "#app/global-scene"; import type { BiomeTierTrainerPools, PokemonPools } from "#app/data/balance/biomes"; import { biomePokemonPools, BiomePoolTier, biomeTrainerPools } from "#app/data/balance/biomes"; -import type { Constructor } from "#app/utils"; -import * as Utils from "#app/utils"; +import { randSeedInt, NumberHolder, isNullOrUndefined, type Constructor } from "#app/utils"; import type PokemonSpecies from "#app/data/pokemon-species"; import { getPokemonSpecies } from "#app/data/pokemon-species"; import { @@ -124,7 +123,7 @@ export class Arena { if (typeof luckValue !== "undefined") { luckModifier = luckValue * (isBossSpecies ? 0.5 : 2); } - const tierValue = Utils.randSeedInt(randVal - luckModifier); + const tierValue = randSeedInt(randVal - luckModifier); let tier = !isBossSpecies ? tierValue >= 156 ? BiomePoolTier.COMMON @@ -153,7 +152,7 @@ export class Arena { if (!tierPool.length) { ret = globalScene.randomSpecies(waveIndex, level); } else { - const entry = tierPool[Utils.randSeedInt(tierPool.length)]; + const entry = tierPool[randSeedInt(tierPool.length)]; let species: Species; if (typeof entry === "number") { species = entry as Species; @@ -164,7 +163,7 @@ export class Arena { if (level >= levelThreshold) { const speciesIds = entry[levelThreshold]; if (speciesIds.length > 1) { - species = speciesIds[Utils.randSeedInt(speciesIds.length)]; + species = speciesIds[randSeedInt(speciesIds.length)]; } else { species = speciesIds[0]; } @@ -211,7 +210,7 @@ export class Arena { !!this.trainerPool[BiomePoolTier.BOSS].length && (globalScene.gameMode.isTrainerBoss(waveIndex, this.biomeType, globalScene.offsetGym) || isBoss); console.log(isBoss, this.trainerPool); - const tierValue = Utils.randSeedInt(!isTrainerBoss ? 512 : 64); + const tierValue = randSeedInt(!isTrainerBoss ? 512 : 64); let tier = !isTrainerBoss ? tierValue >= 156 ? BiomePoolTier.COMMON @@ -235,7 +234,7 @@ export class Arena { tier--; } const tierPool = this.trainerPool[tier] || []; - return !tierPool.length ? TrainerType.BREEDER : tierPool[Utils.randSeedInt(tierPool.length)]; + return !tierPool.length ? TrainerType.BREEDER : tierPool[randSeedInt(tierPool.length)]; } getSpeciesFormIndex(species: PokemonSpecies): number { @@ -336,9 +335,9 @@ export class Arena { return false; } - const weatherDuration = new Utils.NumberHolder(0); + const weatherDuration = new NumberHolder(0); - if (!Utils.isNullOrUndefined(user)) { + if (!isNullOrUndefined(user)) { weatherDuration.value = 5; globalScene.applyModifier(FieldEffectModifier, user.isPlayer(), user, weatherDuration); } @@ -417,9 +416,9 @@ export class Arena { const oldTerrainType = this.terrain?.terrainType || TerrainType.NONE; - const terrainDuration = new Utils.NumberHolder(0); + const terrainDuration = new NumberHolder(0); - if (!Utils.isNullOrUndefined(user)) { + if (!isNullOrUndefined(user)) { terrainDuration.value = 5; globalScene.applyModifier(FieldEffectModifier, user.isPlayer(), user, terrainDuration); } @@ -1013,7 +1012,7 @@ export class ArenaBase extends Phaser.GameObjects.Container { if (!this.player) { globalScene.executeWithSeedOffset( () => { - this.propValue = propValue === undefined ? (hasProps ? Utils.randSeedInt(8) : 0) : propValue; + this.propValue = propValue === undefined ? (hasProps ? randSeedInt(8) : 0) : propValue; this.props.forEach((prop, p) => { const propKey = `${biomeKey}_b${hasProps ? `_${p + 1}` : ""}`; prop.setTexture(propKey); diff --git a/src/field/damage-number-handler.ts b/src/field/damage-number-handler.ts index 9e0010a0c10..a527b148fff 100644 --- a/src/field/damage-number-handler.ts +++ b/src/field/damage-number-handler.ts @@ -2,7 +2,7 @@ import { TextStyle, addTextObject } from "../ui/text"; import type { DamageResult } from "./pokemon"; import type Pokemon from "./pokemon"; import { HitResult } from "./pokemon"; -import * as Utils from "../utils"; +import { formatStat, fixedInt } from "#app/utils"; import type { BattlerIndex } from "../battle"; import { globalScene } from "#app/global-scene"; @@ -30,7 +30,7 @@ export default class DamageNumberHandler { const damageNumber = addTextObject( target.x, -(globalScene.game.canvas.height / 6) + target.y - target.getSprite().height / 2, - Utils.formatStat(amount, true), + formatStat(amount, true), TextStyle.SUMMARY, ); damageNumber.setName("text-damage-number"); @@ -86,14 +86,14 @@ export default class DamageNumberHandler { if (globalScene.damageNumbersMode === 1) { globalScene.tweens.add({ targets: damageNumber, - duration: Utils.fixedInt(750), + duration: fixedInt(750), alpha: 1, y: "-=32", }); globalScene.tweens.add({ delay: 375, targets: damageNumber, - duration: Utils.fixedInt(625), + duration: fixedInt(625), alpha: 0, ease: "Sine.easeIn", onComplete: () => { @@ -110,7 +110,7 @@ export default class DamageNumberHandler { targets: damageNumber, tweens: [ { - duration: Utils.fixedInt(250), + duration: fixedInt(250), alpha: 1, scaleX: 0.75 * baseScale, scaleY: 1.25 * baseScale, @@ -118,7 +118,7 @@ export default class DamageNumberHandler { ease: "Cubic.easeOut", }, { - duration: Utils.fixedInt(175), + duration: fixedInt(175), alpha: 1, scaleX: 0.875 * baseScale, scaleY: 1.125 * baseScale, @@ -126,59 +126,59 @@ export default class DamageNumberHandler { ease: "Cubic.easeIn", }, { - duration: Utils.fixedInt(100), + duration: fixedInt(100), scaleX: 1.25 * baseScale, scaleY: 0.75 * baseScale, ease: "Cubic.easeOut", }, { - duration: Utils.fixedInt(175), + duration: fixedInt(175), scaleX: 0.875 * baseScale, scaleY: 1.125 * baseScale, y: "-=8", ease: "Cubic.easeOut", }, { - duration: Utils.fixedInt(50), + duration: fixedInt(50), scaleX: 0.925 * baseScale, scaleY: 1.075 * baseScale, y: "+=8", ease: "Cubic.easeIn", }, { - duration: Utils.fixedInt(100), + duration: fixedInt(100), scaleX: 1.125 * baseScale, scaleY: 0.875 * baseScale, ease: "Cubic.easeOut", }, { - duration: Utils.fixedInt(175), + duration: fixedInt(175), scaleX: 0.925 * baseScale, scaleY: 1.075 * baseScale, y: "-=4", ease: "Cubic.easeOut", }, { - duration: Utils.fixedInt(50), + duration: fixedInt(50), scaleX: 0.975 * baseScale, scaleY: 1.025 * baseScale, y: "+=4", ease: "Cubic.easeIn", }, { - duration: Utils.fixedInt(100), + duration: fixedInt(100), scaleX: 1.075 * baseScale, scaleY: 0.925 * baseScale, ease: "Cubic.easeOut", }, { - duration: Utils.fixedInt(25), + duration: fixedInt(25), scaleX: baseScale, scaleY: baseScale, ease: "Cubic.easeOut", }, { - delay: Utils.fixedInt(500), + delay: fixedInt(500), alpha: 0, onComplete: () => { this.damageNumbers diff --git a/src/field/mystery-encounter-intro.ts b/src/field/mystery-encounter-intro.ts index 649a969d415..e1fb0c37074 100644 --- a/src/field/mystery-encounter-intro.ts +++ b/src/field/mystery-encounter-intro.ts @@ -4,9 +4,10 @@ import type MysteryEncounter from "#app/data/mystery-encounters/mystery-encounte import type { Species } from "#enums/species"; import { isNullOrUndefined } from "#app/utils"; import { getSpriteKeysFromSpecies } from "#app/data/mystery-encounters/utils/encounter-pokemon-utils"; -import type { Variant } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; import { doShinySparkleAnim } from "#app/field/anims"; import PlayAnimationConfig = Phaser.Types.Animations.PlayAnimationConfig; +import { loadPokemonVariantAssets } from "#app/sprites/pokemon-sprite"; type KnownFileRoot = | "arenas" @@ -233,8 +234,8 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con this.spriteConfigs.forEach(config => { if (config.isPokemon) { globalScene.loadPokemonAtlas(config.spriteKey, config.fileRoot); - if (config.isShiny) { - shinyPromises.push(globalScene.loadPokemonVariantAssets(config.spriteKey, config.fileRoot, config.variant)); + if (config.isShiny && !isNullOrUndefined(config.variant)) { + shinyPromises.push(loadPokemonVariantAssets(config.spriteKey, config.fileRoot, config.variant)); } } else if (config.isItem) { globalScene.loadAtlas("items", ""); diff --git a/src/field/pokemon-sprite-sparkle-handler.ts b/src/field/pokemon-sprite-sparkle-handler.ts index 0d5dcca7989..d2f69500258 100644 --- a/src/field/pokemon-sprite-sparkle-handler.ts +++ b/src/field/pokemon-sprite-sparkle-handler.ts @@ -1,6 +1,6 @@ import { globalScene } from "#app/global-scene"; import Pokemon from "./pokemon"; -import * as Utils from "../utils"; +import { fixedInt, randInt } from "#app/utils"; export default class PokemonSpriteSparkleHandler { private sprites: Set; @@ -9,7 +9,7 @@ export default class PokemonSpriteSparkleHandler { this.sprites = new Set(); globalScene.tweens.addCounter({ - duration: Utils.fixedInt(200), + duration: fixedInt(200), from: 0, to: 1, yoyo: true, @@ -36,7 +36,7 @@ export default class PokemonSpriteSparkleHandler { const parent = (pokemon || s).parentContainer; const texture = s.texture; const [width, height] = [texture.source[0].width, texture.source[0].height]; - const [pixelX, pixelY] = [Utils.randInt(width), Utils.randInt(height)]; + const [pixelX, pixelY] = [randInt(width), randInt(height)]; const ratioX = s.width / width; const ratioY = s.height / height; const pixel = texture.manager.getPixel(pixelX, pixelY, texture.key, "__BASE"); @@ -51,7 +51,7 @@ export default class PokemonSpriteSparkleHandler { sparkle.setName("sprite-tera-sparkle"); sparkle.play("tera_sparkle"); parent.add(sparkle); - s.scene.time.delayedCall(Utils.fixedInt(Math.floor((1000 / 12) * 13)), () => sparkle.destroy()); + s.scene.time.delayedCall(fixedInt(Math.floor((1000 / 12) * 13)), () => sparkle.destroy()); } } } diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 7d856696188..b59b7ba01fe 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -2,9 +2,9 @@ import Phaser from "phaser"; import type { AnySound } from "#app/battle-scene"; import type BattleScene from "#app/battle-scene"; import { globalScene } from "#app/global-scene"; -import type { Variant, VariantSet } from "#app/data/variant"; -import { variantColorCache } from "#app/data/variant"; -import { variantData } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; +import { populateVariantColors, variantColorCache } from "#app/sprites/variant"; +import { variantData } from "#app/sprites/variant"; import BattleInfo, { PlayerBattleInfo, EnemyBattleInfo, @@ -55,9 +55,7 @@ import { getStarterValueFriendshipCap, speciesStarterCosts, } from "#app/data/balance/starters"; -import type { Constructor } from "#app/utils"; -import { isNullOrUndefined, randSeedInt, type nil } from "#app/utils"; -import * as Utils from "#app/utils"; +import { NumberHolder, randSeedInt, getIvsFromId, BooleanHolder, randSeedItem, isNullOrUndefined, getEnumValues, toDmgValue, fixedInt, rgbaToInt, rgbHexToRgba, rgbToHsv, deltaRgb, isBetween, type nil, type Constructor } from "#app/utils"; import type { TypeDamageMultiplier } from "#app/data/type"; import { getTypeDamageMultiplier, getTypeRgb } from "#app/data/type"; import { PokemonType } from "#enums/pokemon-type"; @@ -96,7 +94,6 @@ import { } from "#app/modifier/modifier"; import { PokeballType } from "#enums/pokeball"; import { Gender } from "#app/data/gender"; -import { initMoveAnim, loadMoveAnimAssets } from "#app/data/battle-anims"; import { Status, getRandomStatus } from "#app/data/status-effect"; import type { SpeciesFormEvolution, @@ -176,10 +173,7 @@ import { MoveTypeChangeAbAttr, FullHpResistTypeAbAttr, applyCheckTrappedAbAttrs, - CheckTrappedAbAttr, - PostSetStatusAbAttr, - applyPostSetStatusAbAttrs, - InfiltratorAbAttr, + CheckTrappedAbAttr, InfiltratorAbAttr, AlliedFieldDamageReductionAbAttr, PostDamageAbAttr, applyPostDamageAbAttrs, @@ -193,7 +187,7 @@ import { PreLeaveFieldRemoveSuppressAbilitiesSourceAbAttr, applyAllyStatMultiplierAbAttrs, AllyStatMultiplierAbAttr, - MoveAbilityBypassAbAttr, + MoveAbilityBypassAbAttr } from "#app/data/ability"; import type PokemonData from "#app/system/pokemon-data"; import { BattlerIndex } from "#app/battle"; @@ -220,8 +214,7 @@ import { SpeciesFormChangeActiveTrigger, SpeciesFormChangeLapseTeraTrigger, SpeciesFormChangeMoveLearnedTrigger, - SpeciesFormChangePostMoveTrigger, - SpeciesFormChangeStatusEffectTrigger, + SpeciesFormChangePostMoveTrigger } from "#app/data/pokemon-forms"; import { TerrainType } from "#app/data/terrain"; import type { TrainerSlot } from "#enums/trainer-slot"; @@ -264,6 +257,7 @@ import { StatusEffect } from "#enums/status-effect"; import { doShinySparkleAnim } from "#app/field/anims"; import { MoveFlags } from "#enums/MoveFlags"; import { timedEventManager } from "#app/global-event-manager"; +import { loadMoveAnimations } from "#app/sprites/pokemon-asset-loader"; import { ResetStatusPhase } from "#app/phases/reset-status-phase"; export enum LearnMoveSituation { @@ -367,7 +361,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { throw `Cannot create a player Pokemon for species '${species.getName(formIndex)}'`; } - const hiddenAbilityChance = new Utils.NumberHolder( + const hiddenAbilityChance = new NumberHolder( BASE_HIDDEN_ABILITY_CHANCE, ); if (!this.hasTrainer()) { @@ -388,8 +382,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.abilityIndex = abilityIndex; // Use the provided ability index if it is defined } else { // If abilityIndex is not provided, determine it based on species and hidden ability - const hasHiddenAbility = !Utils.randSeedInt(hiddenAbilityChance.value); - const randAbilityIndex = Utils.randSeedInt(2); + const hasHiddenAbility = !randSeedInt(hiddenAbilityChance.value); + const randAbilityIndex = randSeedInt(2); if (species.abilityHidden && hasHiddenAbility) { // If the species has a hidden ability and the hidden ability is present this.abilityIndex = 2; @@ -465,8 +459,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.isTerastallized = dataSource.isTerastallized; this.stellarTypesBoosted = dataSource.stellarTypesBoosted ?? []; } else { - this.id = Utils.randSeedInt(4294967296); - this.ivs = ivs || Utils.getIvsFromId(this.id); + this.id = randSeedInt(4294967296); + this.ivs = ivs || getIvsFromId(this.id); if (this.gender === undefined) { this.generateGender(); @@ -509,7 +503,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.pokerus = false; if (level > 1) { - const fused = new Utils.BooleanHolder( + const fused = new BooleanHolder( globalScene.gameMode.isSplicedOnly, ); if (!fused.value && !this.isPlayer() && !this.hasTrainer()) { @@ -526,7 +520,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { (this.fusionShiny ? this.fusionVariant + 1 : 0); this.fusionLuck = this.luck; - this.teraType = Utils.randSeedItem(this.getTypes(false, false, true)); + this.teraType = randSeedItem(this.getTypes(false, false, true)); this.isTerastallized = false; this.stellarTypesBoosted = []; } @@ -542,21 +536,33 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } - getNameToRender() { + /** + * @param {boolean} useIllusion - Whether we want the fake name or the real name of the Pokemon (for Illusion ability). + */ + getNameToRender(useIllusion: boolean = true) { + const name: string = (!useIllusion && !!this.summonData?.illusion) ? this.summonData?.illusion.basePokemon!.name : this.name; + const nickname: string = (!useIllusion && !!this.summonData?.illusion) ? this.summonData?.illusion.basePokemon!.nickname : this.nickname; try { - if (this.nickname) { - return decodeURIComponent(escape(atob(this.nickname))); + if (nickname) { + return decodeURIComponent(escape(atob(nickname))); } - return this.name; + return name; } catch (err) { - console.error(`Failed to decode nickname for ${this.name}`, err); - return this.name; + console.error(`Failed to decode nickname for ${name}`, err); + return name; + } + } + + getPokeball(useIllusion = false){ + if(useIllusion){ + return this.summonData?.illusion?.pokeball ?? this.pokeball + } else { + return this.pokeball } } init(): void { this.fieldPosition = FieldPosition.CENTER; - this.initBattleInfo(); globalScene.fieldUI.addAt(this.battleInfo, 0); @@ -590,7 +596,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.addAt(sprite, 0); this.addAt(tintSprite, 1); - if (this.isShiny() && !this.shinySparkle) { + if (this.isShiny(true) && !this.shinySparkle) { this.initShinySparkle(); } } @@ -634,7 +640,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @returns {boolean} `true` if pokemon is allowed in battle */ public isAllowedInChallenge(): boolean { - const challengeAllowed = new Utils.BooleanHolder(true); + const challengeAllowed = new BooleanHolder(true); applyChallenges( ChallengeType.POKEMON_IN_BATTLE, this, @@ -688,6 +694,92 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } + /** + * Generate an illusion of the last pokemon in the party, as other wild pokemon in the area. + */ + setIllusion(pokemon: Pokemon): boolean { + if(!!this.summonData?.illusion){ + this.breakIllusion(); + } + if (this.hasTrainer()) { + const speciesId = pokemon.species.speciesId; + + this.summonData.illusion = { + basePokemon: { + name: this.name, + nickname: this.nickname, + shiny: this.shiny, + variant: this.variant, + fusionShiny: this.fusionShiny, + fusionVariant: this.fusionVariant + }, + species: speciesId, + formIndex: pokemon.formIndex, + gender: pokemon.gender, + pokeball: pokemon.pokeball, + fusionFormIndex: pokemon.fusionFormIndex, + fusionSpecies: pokemon.fusionSpecies || undefined, + fusionGender: pokemon.fusionGender + }; + + this.name = pokemon.name; + this.nickname = pokemon.nickname; + this.shiny = pokemon.shiny; + this.variant = pokemon.variant; + this.fusionVariant = pokemon.fusionVariant; + this.fusionShiny = pokemon.fusionShiny; + if (this.shiny) { + this.initShinySparkle(); + } + this.loadAssets(false, true).then(() => this.playAnim()); + this.updateInfo(); + } else { + const randomIllusion: PokemonSpecies = globalScene.arena.randomSpecies(globalScene.currentBattle.waveIndex, this.level); + + this.summonData.illusion = { + basePokemon: { + name: this.name, + nickname: this.nickname, + shiny: this.shiny, + variant: this.variant, + fusionShiny: this.fusionShiny, + fusionVariant: this.fusionVariant + }, + species: randomIllusion.speciesId, + formIndex: randomIllusion.formIndex, + gender: this.gender, + pokeball: this.pokeball + }; + + this.name = randomIllusion.name; + this.loadAssets(false, true).then(() => this.playAnim()); + } + return true; + } + + breakIllusion(): boolean { + if (!this.summonData?.illusion) { + return false; + } else { + this.name = this.summonData?.illusion.basePokemon.name; + this.nickname = this.summonData?.illusion.basePokemon.nickname; + this.shiny = this.summonData?.illusion.basePokemon.shiny; + this.variant = this.summonData?.illusion.basePokemon.variant; + this.fusionVariant = this.summonData?.illusion.basePokemon.fusionVariant; + this.fusionShiny = this.summonData?.illusion.basePokemon.fusionShiny; + this.summonData.illusion = null; + } + if (this.isOnField()) { + globalScene.playSound("PRSFX- Transform"); + } + if (this.shiny) { + this.initShinySparkle(); + } + this.loadAssets(false).then(() => this.playAnim()); + this.updateInfo(true); + return true; + } + abstract isPlayer(): boolean; abstract hasTrainer(): boolean; @@ -696,115 +788,91 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { abstract getBattlerIndex(): BattlerIndex; - loadAssets(ignoreOverride = true): Promise { - return new Promise(resolve => { - const moveIds = this.getMoveset().map(m => m.getMove().id); - Promise.allSettled(moveIds.map(m => initMoveAnim(m))).then(() => { - loadMoveAnimAssets(moveIds); - this.getSpeciesForm().loadAssets( - this.getGender() === Gender.FEMALE, - this.formIndex, - this.shiny, - this.variant, - ); - if (this.isPlayer() || this.getFusionSpeciesForm()) { - globalScene.loadPokemonAtlas( - this.getBattleSpriteKey(true, ignoreOverride), - this.getBattleSpriteAtlasPath(true, ignoreOverride), - ); - } - if (this.getFusionSpeciesForm()) { - this.getFusionSpeciesForm().loadAssets( - this.getFusionGender() === Gender.FEMALE, - this.fusionFormIndex, - this.fusionShiny, - this.fusionVariant, - ); - globalScene.loadPokemonAtlas( - this.getFusionBattleSpriteKey(true, ignoreOverride), - this.getFusionBattleSpriteAtlasPath(true, ignoreOverride), - ); - } - globalScene.load.once(Phaser.Loader.Events.COMPLETE, () => { - if (this.isPlayer()) { - const originalWarn = console.warn; - // Ignore warnings for missing frames, because there will be a lot - console.warn = () => {}; - const battleFrameNames = globalScene.anims.generateFrameNames( - this.getBattleSpriteKey(), - { zeroPad: 4, suffix: ".png", start: 1, end: 400 }, - ); - console.warn = originalWarn; - if (!globalScene.anims.exists(this.getBattleSpriteKey())) { - globalScene.anims.create({ - key: this.getBattleSpriteKey(), - frames: battleFrameNames, - frameRate: 10, - repeat: -1, - }); - } - } - this.playAnim(); - const updateFusionPaletteAndResolve = () => { - this.updateFusionPalette(); - if (this.summonData?.speciesForm) { - this.updateFusionPalette(true); - } - resolve(); - }; - if (this.shiny) { - const populateVariantColors = ( - isBackSprite = false, - ): Promise => { - return new Promise(async resolve => { - const battleSpritePath = this.getBattleSpriteAtlasPath( - isBackSprite, - ignoreOverride, - ) - .replace("variant/", "") - .replace(/_[1-3]$/, ""); - let config = variantData; - const useExpSprite = - globalScene.experimentalSprites && - globalScene.hasExpSprite( - this.getBattleSpriteKey(isBackSprite, ignoreOverride), - ); - battleSpritePath - .split("/") - .map(p => (config ? (config = config[p]) : null)); - const variantSet: VariantSet = config as VariantSet; - if (variantSet && variantSet[this.variant] === 1) { - const cacheKey = this.getBattleSpriteKey(isBackSprite); - if (!variantColorCache.hasOwnProperty(cacheKey)) { - await this.populateVariantColorCache( - cacheKey, - useExpSprite, - battleSpritePath, - ); - } - } - resolve(); - }); - }; - if (this.isPlayer()) { - Promise.all([ - populateVariantColors(false), - populateVariantColors(true), - ]).then(() => updateFusionPaletteAndResolve()); - } else { - populateVariantColors(false).then(() => - updateFusionPaletteAndResolve(), - ); - } - } else { - updateFusionPaletteAndResolve(); - } - }); - if (!globalScene.load.isLoading()) { - globalScene.load.start(); - } + /** +   * @param useIllusion - Whether we want the illusion or not. +   */ + async loadAssets(ignoreOverride = true, useIllusion: boolean = false): Promise { + /** Promises that are loading assets and can be run concurrently. */ + const loadPromises: Promise[] = []; + // Assets for moves + loadPromises.push(loadMoveAnimations(this.getMoveset().map(m => m.getMove().id))); + + // Load the assets for the species form + const formIndex = !!this.summonData?.illusion && useIllusion ? this.summonData?.illusion.formIndex : this.formIndex; + loadPromises.push( + this.getSpeciesForm(false, useIllusion).loadAssets( + this.getGender(useIllusion) === Gender.FEMALE, + formIndex, + this.isShiny(useIllusion), + this.getVariant(useIllusion) + ), + ); + + if (this.isPlayer() || this.getFusionSpeciesForm(false, useIllusion)) { + globalScene.loadPokemonAtlas( + this.getBattleSpriteKey(true, ignoreOverride), + this.getBattleSpriteAtlasPath(true, ignoreOverride), + ); + } + if (this.getFusionSpeciesForm()) { + const fusionFormIndex = !!this.summonData?.illusion && useIllusion ? this.summonData?.illusion.fusionFormIndex : this.fusionFormIndex; + const fusionShiny = !!this.summonData?.illusion && !useIllusion ? this.summonData?.illusion.basePokemon!.fusionShiny : this.fusionShiny; + const fusionVariant = !!this.summonData?.illusion && !useIllusion ? this.summonData?.illusion.basePokemon!.fusionVariant : this.fusionVariant; + loadPromises.push(this.getFusionSpeciesForm(false, useIllusion).loadAssets( + this.getFusionGender(false, useIllusion) === Gender.FEMALE, + fusionFormIndex, + fusionShiny, + fusionVariant + )); + globalScene.loadPokemonAtlas( + this.getFusionBattleSpriteKey(true, ignoreOverride), + this.getFusionBattleSpriteAtlasPath(true, ignoreOverride), + ); + } + + if (this.isShiny(true)) { + loadPromises.push(populateVariantColors(this, false, ignoreOverride)) + if (this.isPlayer()) { + loadPromises.push(populateVariantColors(this, true, ignoreOverride)); + } + } + + await Promise.allSettled(loadPromises); + + // Wait for the assets we queued to load to finish loading, then... + if (!globalScene.load.isLoading()) { + globalScene.load.start(); + } + // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises#creating_a_promise_around_an_old_callback_api + await new Promise(resolve => globalScene.load.once(Phaser.Loader.Events.COMPLETE, resolve)); + + // With the sprites loaded, generate the animation frame information + if (this.isPlayer()) { + const originalWarn = console.warn; + // Ignore warnings for missing frames, because there will be a lot + console.warn = () => {}; + const battleFrameNames = globalScene.anims.generateFrameNames(this.getBattleSpriteKey(), { + zeroPad: 4, + suffix: ".png", + start: 1, + end: 400, }); - }); + console.warn = originalWarn; + globalScene.anims.create({ + key: this.getBattleSpriteKey(), + frames: battleFrameNames, + frameRate: 10, + repeat: -1, + }); + } + // With everything loaded, now begin playing the animation. + this.playAnim(); + + // update the fusion palette + this.updateFusionPalette(); + if (this.summonData?.speciesForm) { + this.updateFusionPalette(true); + } } /** @@ -912,11 +980,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } getSpriteId(ignoreOverride?: boolean): string { - return this.getSpeciesForm(ignoreOverride).getSpriteId( - this.getGender(ignoreOverride) === Gender.FEMALE, - this.formIndex, - this.shiny, - this.variant, + const formIndex: integer = !!this.summonData?.illusion ? this.summonData?.illusion.formIndex! : this.formIndex; + return this.getSpeciesForm(ignoreOverride, true).getSpriteId( + this.getGender(ignoreOverride, true) === Gender.FEMALE, + formIndex, + this.shiny, + this.variant ); } @@ -924,21 +993,24 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (back === undefined) { back = this.isPlayer(); } - return this.getSpeciesForm(ignoreOverride).getSpriteId( - this.getGender(ignoreOverride) === Gender.FEMALE, - this.formIndex, - this.shiny, - this.variant, - back, + + const formIndex: integer = !!this.summonData?.illusion ? this.summonData?.illusion.formIndex! : this.formIndex; + + return this.getSpeciesForm(ignoreOverride, true).getSpriteId( + this.getGender(ignoreOverride, true) === Gender.FEMALE, + formIndex, + this.shiny, + this.variant, + back ); } getSpriteKey(ignoreOverride?: boolean): string { - return this.getSpeciesForm(ignoreOverride).getSpriteKey( + return this.getSpeciesForm(ignoreOverride, false).getSpriteKey( this.getGender(ignoreOverride) === Gender.FEMALE, this.formIndex, - this.shiny, - this.variant, + this.summonData?.illusion?.basePokemon.shiny ?? this.shiny, + this.summonData?.illusion?.basePokemon.variant ?? this.variant ); } @@ -947,11 +1019,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } getFusionSpriteId(ignoreOverride?: boolean): string { - return this.getFusionSpeciesForm(ignoreOverride).getSpriteId( - this.getFusionGender(ignoreOverride) === Gender.FEMALE, - this.fusionFormIndex, - this.fusionShiny, - this.fusionVariant, + const fusionFormIndex: integer = !!this.summonData?.illusion ? this.summonData?.illusion.fusionFormIndex! : this.fusionFormIndex; + return this.getFusionSpeciesForm(ignoreOverride, true).getSpriteId( + this.getFusionGender(ignoreOverride, true) === Gender.FEMALE, + fusionFormIndex, + this.fusionShiny, + this.fusionVariant ); } @@ -959,12 +1032,15 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (back === undefined) { back = this.isPlayer(); } - return this.getFusionSpeciesForm(ignoreOverride).getSpriteId( - this.getFusionGender(ignoreOverride) === Gender.FEMALE, - this.fusionFormIndex, - this.fusionShiny, - this.fusionVariant, - back, + + const fusionFormIndex: integer = !!this.summonData?.illusion ? this.summonData?.illusion.fusionFormIndex! : this.fusionFormIndex; + + return this.getFusionSpeciesForm(ignoreOverride, true).getSpriteId( + this.getFusionGender(ignoreOverride, true) === Gender.FEMALE, + fusionFormIndex, + this.fusionShiny, + this.fusionVariant, + back ); } @@ -983,62 +1059,77 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } getIconAtlasKey(ignoreOverride?: boolean): string { - return this.getSpeciesForm(ignoreOverride).getIconAtlasKey( - this.formIndex, - this.shiny, - this.variant, + const formIndex: integer = !!this.summonData?.illusion ? this.summonData?.illusion.formIndex : this.formIndex; + return this.getSpeciesForm(ignoreOverride, true).getIconAtlasKey( + formIndex, + this.shiny, + this.variant ); } getFusionIconAtlasKey(ignoreOverride?: boolean): string { - return this.getFusionSpeciesForm(ignoreOverride).getIconAtlasKey( - this.fusionFormIndex, - this.fusionShiny, - this.fusionVariant, + return this.getFusionSpeciesForm(ignoreOverride, true).getIconAtlasKey( + this.fusionFormIndex, + this.fusionShiny, + this.fusionVariant ); } getIconId(ignoreOverride?: boolean): string { - return this.getSpeciesForm(ignoreOverride).getIconId( - this.getGender(ignoreOverride) === Gender.FEMALE, - this.formIndex, - this.shiny, - this.variant, + const formIndex: integer = !!this.summonData?.illusion ? this.summonData?.illusion.formIndex : this.formIndex; + return this.getSpeciesForm(ignoreOverride, true).getIconId( + this.getGender(ignoreOverride, true) === Gender.FEMALE, + formIndex, + this.shiny, + this.variant ); } getFusionIconId(ignoreOverride?: boolean): string { - return this.getFusionSpeciesForm(ignoreOverride).getIconId( - this.getFusionGender(ignoreOverride) === Gender.FEMALE, - this.fusionFormIndex, - this.fusionShiny, - this.fusionVariant, + const fusionFormIndex: integer = !!this.summonData?.illusion ? this.summonData?.illusion.fusionFormIndex! : this.fusionFormIndex; + return this.getFusionSpeciesForm(ignoreOverride, true).getIconId( + this.getFusionGender(ignoreOverride, true) === Gender.FEMALE, + fusionFormIndex, + this.fusionShiny, + this.fusionVariant ); } - getSpeciesForm(ignoreOverride?: boolean): PokemonSpeciesForm { + /** + * @param {boolean} useIllusion - Whether we want the speciesForm of the illusion or not. + */ + getSpeciesForm(ignoreOverride?: boolean, useIllusion: boolean = false): PokemonSpeciesForm { + const species: PokemonSpecies = useIllusion && !!this.summonData?.illusion ? getPokemonSpecies(this.summonData?.illusion.species) : this.species; + + const formIndex: integer = useIllusion && !!this.summonData?.illusion ? this.summonData?.illusion.formIndex : this.formIndex; + if (!ignoreOverride && this.summonData?.speciesForm) { return this.summonData.speciesForm; } - if (this.species.forms && this.species.forms.length > 0) { - return this.species.forms[this.formIndex]; + if (species.forms && species.forms.length > 0) { + return species.forms[formIndex]; } - return this.species; + return species; } - getFusionSpeciesForm(ignoreOverride?: boolean): PokemonSpeciesForm { + /** + * @param {boolean} useIllusion - Whether we want the fusionSpeciesForm of the illusion or not. + */ + getFusionSpeciesForm(ignoreOverride?: boolean, useIllusion: boolean = false): PokemonSpeciesForm { + const fusionSpecies: PokemonSpecies = useIllusion && !!this.summonData?.illusion ? this.summonData?.illusion.fusionSpecies! : this.fusionSpecies!; + const fusionFormIndex: integer = useIllusion && !!this.summonData?.illusion ? this.summonData?.illusion.fusionFormIndex! : this.fusionFormIndex; + if (!ignoreOverride && this.summonData?.speciesForm) { return this.summonData.fusionSpeciesForm; } if ( - !this.fusionSpecies?.forms?.length || - this.fusionFormIndex >= this.fusionSpecies?.forms.length + !fusionSpecies?.forms?.length || + fusionFormIndex >= fusionSpecies?.forms.length ) { - //@ts-ignore - return this.fusionSpecies; // TODO: I don't even know how to fix this... A complete cluster of classes involved + null + return fusionSpecies; } - return this.fusionSpecies?.forms[this.fusionFormIndex]; + return fusionSpecies?.forms[fusionFormIndex]; } getSprite(): Phaser.GameObjects.Sprite { @@ -1349,7 +1440,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @returns the final critical-hit stage value */ getCritStage(source: Pokemon, move: Move): number { - const critStage = new Utils.NumberHolder(0); + const critStage = new NumberHolder(0); applyMoveAttrs(HighCritAttr, source, this, move, critStage); globalScene.applyModifiers( CritBoosterModifier, @@ -1404,7 +1495,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { simulated = true, ignoreHeldItems = false, ): number { - const statValue = new Utils.NumberHolder(this.getStat(stat, false)); + const statValue = new NumberHolder(this.getStat(stat, false)); if (!ignoreHeldItems) { globalScene.applyModifiers( StatBoosterModifier, @@ -1416,7 +1507,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } // The Ruin abilities here are never ignored, but they reveal themselves on summon anyway - const fieldApplied = new Utils.BooleanHolder(false); + const fieldApplied = new BooleanHolder(false); for (const pokemon of globalScene.getField(true)) { applyFieldStatMultiplierAbAttrs( FieldMultiplyStatAbAttr, @@ -1442,7 +1533,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } const ally = this.getAlly(); - if (!Utils.isNullOrUndefined(ally)) { + if (!isNullOrUndefined(ally)) { applyAllyStatMultiplierAbAttrs(AllyStatMultiplierAbAttr, ally, stat, statValue, simulated, this, move?.hasFlag(MoveFlags.IGNORE_ABILITIES) || ignoreAllyAbility); } @@ -1529,7 +1620,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const baseStats = this.calculateBaseStats(); // Using base stats, calculate and store stats one by one for (const s of PERMANENT_STATS) { - const statHolder = new Utils.NumberHolder( + const statHolder = new NumberHolder( Math.floor((2 * baseStats[s] + this.ivs[s]) * this.level * 0.01), ); if (s === Stat.HP) { @@ -1554,7 +1645,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } else { statHolder.value += 5; - const natureStatMultiplier = new Utils.NumberHolder( + const natureStatMultiplier = new NumberHolder( getNatureStatMultiplier(this.getNature(), s), ); globalScene.applyModifier( @@ -1656,9 +1747,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { generateNature(naturePool?: Nature[]): void { if (naturePool === undefined) { - naturePool = Utils.getEnumValues(Nature); + naturePool = getEnumValues(Nature); } - const nature = naturePool[Utils.randSeedInt(naturePool.length)]; + const nature = naturePool[randSeedInt(naturePool.length)]; this.setNature(nature); } @@ -1694,36 +1785,98 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } - getGender(ignoreOverride?: boolean): Gender { - if (!ignoreOverride && this.summonData?.gender !== undefined) { + /** + * @param {boolean} useIllusion - Whether we want the fake or real gender (illusion ability). + */ + getGender(ignoreOverride?: boolean, useIllusion: boolean = false): Gender { + if (useIllusion && !!this.summonData?.illusion) { + return this.summonData?.illusion.gender!; + } else if (!ignoreOverride && this.summonData?.gender !== undefined) { return this.summonData.gender; } return this.gender; } - getFusionGender(ignoreOverride?: boolean): Gender { - if (!ignoreOverride && this.summonData?.fusionGender !== undefined) { + /** + * @param {boolean} useIllusion - Whether we want the fake or real gender (illusion ability). + */ + getFusionGender(ignoreOverride?: boolean, useIllusion: boolean = false): Gender { + if (useIllusion && !!this.summonData?.illusion) { + return this.summonData?.illusion.fusionGender!; + } else if (!ignoreOverride && this.summonData?.fusionGender !== undefined) { return this.summonData.fusionGender; } return this.fusionGender; } - isShiny(): boolean { - return this.shiny || (this.isFusion() && this.fusionShiny); + /** + * @param {boolean} useIllusion - Whether we want the fake or real shininess (illusion ability). + */ + isShiny(useIllusion: boolean = false): boolean { + if (!useIllusion && !!this.summonData?.illusion) { + return this.summonData?.illusion.basePokemon?.shiny || (!!this.summonData?.illusion.fusionSpecies && this.summonData?.illusion.basePokemon?.fusionShiny) || false; + } else { + return this.shiny || (this.isFusion(useIllusion) && this.fusionShiny); + } } - getVariant(): Variant { - return !this.isFusion() - ? this.variant - : (Math.max(this.variant, this.fusionVariant) as Variant); + /** + * + * @param useIllusion - Whether we want the fake or real shininess (illusion ability). + * @returns `true` if the {@linkcode Pokemon} is shiny and the fusion is shiny as well, `false` otherwise + */ + isDoubleShiny(useIllusion: boolean = false): boolean { + if (!useIllusion && !!this.summonData?.illusion) { + return this.isFusion(false) && this.summonData?.illusion.basePokemon.shiny && this.summonData?.illusion.basePokemon.fusionShiny; + } else { + return this.isFusion(useIllusion) && this.shiny && this.fusionShiny; + } + } + + /** + * @param {boolean} useIllusion - Whether we want the fake or real variant (illusion ability). + */ + getVariant(useIllusion: boolean = false): Variant { + if (!useIllusion && !!this.summonData?.illusion) { + return !this.isFusion(false) + ? this.summonData?.illusion.basePokemon!.variant + : Math.max(this.variant, this.fusionVariant) as Variant; + } else { + return !this.isFusion(true) + ? this.variant + : Math.max(this.variant, this.fusionVariant) as Variant; + } + } + + getBaseVariant(doubleShiny: boolean): Variant { + if (doubleShiny) { + return !!this.summonData?.illusion + ? this.summonData?.illusion.basePokemon!.variant + : this.variant; + } else { + return this.getVariant(); + } } getLuck(): number { return this.luck + (this.isFusion() ? this.fusionLuck : 0); } - isFusion(): boolean { - return !!this.fusionSpecies; + isFusion(useIllusion: boolean = false): boolean { + if (useIllusion && !!this.summonData?.illusion) { + return !!this.summonData?.illusion.fusionSpecies; + } else { + return !!this.fusionSpecies; + } + } + + /** + * @param {boolean} useIllusion - Whether we want the fake name or the real name of the Pokemon (for Illusion ability). + */ + getName(useIllusion: boolean = false): string { + return (!useIllusion && !!this.summonData?.illusion && this.summonData?.illusion.basePokemon) + ? this.summonData?.illusion.basePokemon.name + : this.name; } /** @@ -1742,7 +1895,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @returns `true` if the pokemon is the species or is fused with it, `false` otherwise */ hasSpecies(species: Species, formKey?: string): boolean { - if (Utils.isNullOrUndefined(formKey)) { + if (isNullOrUndefined(formKey)) { return ( this.species.speciesId === species || this.fusionSpecies?.speciesId === species @@ -1838,12 +1991,14 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @param includeTeraType - `true` to include tera-formed type; Default: `false` * @param forDefend - `true` if the pokemon is defending from an attack; Default: `false` * @param ignoreOverride - If `true`, ignore ability changing effects; Default: `false` + * @param useIllusion - `true` to return the types of the illusion instead of the actual types; "AUTO" will depend on forDefend param; Default: "AUTO" * @returns array of {@linkcode PokemonType} */ public getTypes( - includeTeraType = false, - forDefend = false, - ignoreOverride = false, + includeTeraType = false, + forDefend: boolean = false, + ignoreOverride?: boolean, + useIllusion: boolean | "AUTO" = "AUTO" ): PokemonType[] { const types: PokemonType[] = []; @@ -1857,17 +2012,19 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } } - if (!types.length || !includeTeraType) { + + const doIllusion: boolean = (useIllusion === "AUTO") ? !forDefend : useIllusion; if ( - !ignoreOverride && - this.summonData?.types && - this.summonData.types.length > 0 + !ignoreOverride && + this.summonData?.types && + this.summonData.types.length > 0 && + (!this.summonData?.illusion || !doIllusion) ) { this.summonData.types.forEach(t => types.push(t)); } else { - const speciesForm = this.getSpeciesForm(ignoreOverride); - const fusionSpeciesForm = this.getFusionSpeciesForm(ignoreOverride); + const speciesForm = this.getSpeciesForm(ignoreOverride, doIllusion); + const fusionSpeciesForm = this.getFusionSpeciesForm(ignoreOverride, doIllusion); const customTypes = this.customPokemonData.types?.length > 0; // First type, checking for "permanently changed" types from ME @@ -1904,7 +2061,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if ( secondType === PokemonType.UNKNOWN && - Utils.isNullOrUndefined(fusionType2) + isNullOrUndefined(fusionType2) ) { // If second pokemon was monotype and shared its primary type secondType = @@ -2274,11 +2431,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { public getWeight(): number { const autotomizedTag = this.getTag(AutotomizedTag); let weightRemoved = 0; - if (!Utils.isNullOrUndefined(autotomizedTag)) { + if (!isNullOrUndefined(autotomizedTag)) { weightRemoved = 100 * autotomizedTag!.autotomizeCount; } const minWeight = 0.1; - const weight = new Utils.NumberHolder(this.species.weight - weightRemoved); + const weight = new NumberHolder(this.species.weight - weightRemoved); // This will trigger the ability overlay so only call this function when necessary applyAbAttrs(WeightMultiplierAbAttr, this, null, false, weight); @@ -2349,7 +2506,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return false; } - const trappedByAbility = new Utils.BooleanHolder(false); + const trappedByAbility = new BooleanHolder(false); /** * Contains opposing Pokemon (Enemy/Player Pokemon) depending on perspective * Afterwards, it filters out Pokemon that have been switched out of the field so trapped abilities/moves do not trigger @@ -2388,7 +2545,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @returns The {@linkcode PokemonType} of the move after attributes are applied */ public getMoveType(move: Move, simulated = true): PokemonType { - const moveTypeHolder = new Utils.NumberHolder(move.type); + const moveTypeHolder = new NumberHolder(move.type); applyMoveAttrs(VariableMoveTypeAttr, this, null, move, moveTypeHolder); applyPreAttackAbAttrs( @@ -2419,7 +2576,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @param move {@linkcode Move} The move being used by the attacking Pokémon. * @param ignoreAbility Whether to ignore abilities that might affect type effectiveness or immunity (defaults to `false`). * @param simulated Whether to apply abilities via simulated calls (defaults to `true`) - * @param cancelled {@linkcode Utils.BooleanHolder} Stores whether the move was cancelled by a non-type-based immunity. + * @param cancelled {@linkcode BooleanHolder} Stores whether the move was cancelled by a non-type-based immunity. + * @param useIllusion - Whether we want the attack move effectiveness on the illusion or not * Currently only used by {@linkcode Pokemon.apply} to determine whether a "No effect" message should be shown. * @returns The type damage multiplier, indicating the effectiveness of the move */ @@ -2428,9 +2586,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { move: Move, ignoreAbility = false, simulated = true, - cancelled?: Utils.BooleanHolder, + cancelled?: BooleanHolder, + useIllusion: boolean = false ): TypeDamageMultiplier { - if (!Utils.isNullOrUndefined(this.turnData?.moveEffectiveness)) { + if (!isNullOrUndefined(this.turnData?.moveEffectiveness)) { return this.turnData?.moveEffectiveness; } @@ -2439,18 +2598,18 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } const moveType = source.getMoveType(move); - const typeMultiplier = new Utils.NumberHolder( - move.category !== MoveCategory.STATUS || - move.hasAttr(RespectAttackTypeImmunityAttr) - ? this.getAttackTypeEffectiveness( - moveType, - source, - false, - simulated, - move, - ) - : 1, - ); + const typeMultiplier = new NumberHolder( + move.category !== MoveCategory.STATUS || + move.hasAttr(RespectAttackTypeImmunityAttr) + ? this.getAttackTypeEffectiveness( + moveType, + source, + false, + simulated, + move, + useIllusion + ) + : 1); applyMoveAttrs( VariableMoveTypeMultiplierAttr, @@ -2469,7 +2628,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { typeMultiplier.value *= 2; } - const cancelledHolder = cancelled ?? new Utils.BooleanHolder(false); + const cancelledHolder = cancelled ?? new BooleanHolder(false); if (!ignoreAbility) { applyPreDefendAbAttrs( TypeImmunityAbAttr, @@ -2554,19 +2713,21 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @param ignoreStrongWinds whether or not this ignores strong winds (anticipation, forewarn, stealth rocks) * @param simulated tag to only apply the strong winds effect message when the move is used * @param move (optional) the move whose type effectiveness is to be checked. Used for applying {@linkcode VariableMoveTypeChartAttr} + * @param useIllusion - Whether we want the attack type effectiveness on the illusion or not * @returns a multiplier for the type effectiveness */ getAttackTypeEffectiveness( - moveType: PokemonType, - source?: Pokemon, - ignoreStrongWinds = false, - simulated = true, - move?: Move, + moveType: PokemonType, + source?: Pokemon, + ignoreStrongWinds: boolean = false, + simulated: boolean = true, + move?: Move, + useIllusion: boolean = false ): TypeDamageMultiplier { if (moveType === PokemonType.STELLAR) { return this.isTerastallized ? 2 : 1; } - const types = this.getTypes(true, true); + const types = this.getTypes(true, true, undefined, useIllusion); const arena = globalScene.arena; // Handle flying v ground type immunity without removing flying type so effective types are still effective @@ -2583,7 +2744,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { let multiplier = types .map(defType => { - const multiplier = new Utils.NumberHolder( + const multiplier = new NumberHolder( getTypeDamageMultiplier(moveType, defType), ); applyChallenges( @@ -2601,7 +2762,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { ); } if (source) { - const ignoreImmunity = new Utils.BooleanHolder(false); + const ignoreImmunity = new BooleanHolder(false); if ( source.isActive(true) && source.hasAbilityWithAttr(IgnoreTypeImmunityAbAttr) @@ -2634,7 +2795,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { }) .reduce((acc, cur) => acc * cur, 1) as TypeDamageMultiplier; - const typeMultiplierAgainstFlying = new Utils.NumberHolder( + const typeMultiplierAgainstFlying = new NumberHolder( getTypeDamageMultiplier(moveType, PokemonType.FLYING), ); applyChallenges( @@ -2665,7 +2826,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { */ getMatchupScore(opponent: Pokemon): number { const types = this.getTypes(true); - const enemyTypes = opponent.getTypes(true, true); + + const enemyTypes = opponent.getTypes(true, true, false, true); /** Is this Pokemon faster than the opponent? */ const outspeed = (this.isActive(true) @@ -2676,9 +2838,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * Based on how effective this Pokemon's types are offensively against the opponent's types. * This score is increased by 25 percent if this Pokemon is faster than the opponent. */ - let atkScore = - opponent.getAttackTypeEffectiveness(types[0], this) * - (outspeed ? 1.25 : 1); + let atkScore = opponent.getAttackTypeEffectiveness(types[0], this, false, true, undefined, true) * (outspeed ? 1.25 : 1); /** * Based on how effectively this Pokemon defends against the opponent's types. * This score cannot be higher than 4. @@ -2690,12 +2850,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { atkScore *= opponent.getAttackTypeEffectiveness(types[1], this); } if (enemyTypes.length > 1) { - defScore *= - 1 / - Math.max( - this.getAttackTypeEffectiveness(enemyTypes[1], opponent), - 0.25, - ); + defScore *= (1 / Math.max(this.getAttackTypeEffectiveness(enemyTypes[1], opponent, false, false, undefined, true), 0.25)); } /** * Based on this Pokemon's HP ratio compared to that of the opponent. @@ -2977,7 +3132,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const E = globalScene.gameData.trainerId ^ globalScene.gameData.secretId; const F = rand1 ^ rand2; - const shinyThreshold = new Utils.NumberHolder(BASE_SHINY_CHANCE); + const shinyThreshold = new NumberHolder(BASE_SHINY_CHANCE); if (thresholdOverride === undefined) { if (timedEventManager.isEventActive()) { const tchance = timedEventManager.getClassicTrainerShinyChance(); @@ -3020,7 +3175,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { thresholdOverride?: number, applyModifiersToOverride?: boolean, ): boolean { - const shinyThreshold = new Utils.NumberHolder(BASE_SHINY_CHANCE); + const shinyThreshold = new NumberHolder(BASE_SHINY_CHANCE); if (thresholdOverride === undefined || applyModifiersToOverride) { if (thresholdOverride !== undefined && applyModifiersToOverride) { shinyThreshold.value = thresholdOverride; @@ -3075,10 +3230,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { ) { return 0; } - const rand = new Utils.NumberHolder(0); + const rand = new NumberHolder(0); globalScene.executeWithSeedOffset( () => { - rand.value = Utils.randSeedInt(10); + rand.value = randSeedInt(10); }, this.id, globalScene.waveSeed, @@ -3108,7 +3263,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (!this.species.abilityHidden) { return false; } - const haThreshold = new Utils.NumberHolder(BASE_HIDDEN_ABILITY_CHANCE); + const haThreshold = new NumberHolder(BASE_HIDDEN_ABILITY_CHANCE); if (thresholdOverride === undefined || applyModifiersToOverride) { if (thresholdOverride !== undefined && applyModifiersToOverride) { haThreshold.value = thresholdOverride; @@ -3132,7 +3287,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } public generateFusionSpecies(forStarter?: boolean): void { - const hiddenAbilityChance = new Utils.NumberHolder( + const hiddenAbilityChance = new NumberHolder( BASE_HIDDEN_ABILITY_CHANCE, ); if (!this.hasTrainer()) { @@ -3143,8 +3298,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { ); } - const hasHiddenAbility = !Utils.randSeedInt(hiddenAbilityChance.value); - const randAbilityIndex = Utils.randSeedInt(2); + const hasHiddenAbility = !randSeedInt(hiddenAbilityChance.value); + const randAbilityIndex = randSeedInt(2); const filter = !forStarter ? this.species.getCompatibleFusionSpeciesFilter() @@ -3461,7 +3616,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (stabMovePool.length) { const totalWeight = stabMovePool.reduce((v, m) => v + m[1], 0); - let rand = Utils.randSeedInt(totalWeight); + let rand = randSeedInt(totalWeight); let index = 0; while (rand > stabMovePool[index][1]) { rand -= stabMovePool[index++][1]; @@ -3475,7 +3630,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { ); if (attackMovePool.length) { const totalWeight = attackMovePool.reduce((v, m) => v + m[1], 0); - let rand = Utils.randSeedInt(totalWeight); + let rand = randSeedInt(totalWeight); let index = 0; while (rand > attackMovePool[index][1]) { rand -= attackMovePool[index++][1]; @@ -3527,7 +3682,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { movePool = baseWeights.filter(m => !this.moveset.some(mo => m[0] === mo.moveId)); } const totalWeight = movePool.reduce((v, m) => v + m[1], 0); - let rand = Utils.randSeedInt(totalWeight); + let rand = randSeedInt(totalWeight); let index = 0; while (rand > movePool[index][1]) { rand -= movePool[index++][1]; @@ -3751,8 +3906,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { simulated = true, ignoreHeldItems = false, ): number { - const statStage = new Utils.NumberHolder(this.getStatStage(stat)); - const ignoreStatStage = new Utils.BooleanHolder(false); + const statStage = new NumberHolder(this.getStatStage(stat)); + const ignoreStatStage = new BooleanHolder(false); if (opponent) { if (isCritical) { @@ -3789,7 +3944,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } if (!ignoreStatStage.value) { - const statStageMultiplier = new Utils.NumberHolder( + const statStageMultiplier = new NumberHolder( Math.max(2, 2 + statStage.value) / Math.max(2, 2 - statStage.value), ); if (!ignoreHeldItems) { @@ -3821,13 +3976,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return 1; } - const userAccStage = new Utils.NumberHolder(this.getStatStage(Stat.ACC)); - const targetEvaStage = new Utils.NumberHolder( + const userAccStage = new NumberHolder(this.getStatStage(Stat.ACC)); + const targetEvaStage = new NumberHolder( target.getStatStage(Stat.EVA), ); - const ignoreAccStatStage = new Utils.BooleanHolder(false); - const ignoreEvaStatStage = new Utils.BooleanHolder(false); + const ignoreAccStatStage = new BooleanHolder(false); + const ignoreEvaStatStage = new BooleanHolder(false); applyAbAttrs( IgnoreOpponentStatStagesAbAttr, @@ -3869,7 +4024,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { targetEvaStage.value = Math.min(0, targetEvaStage.value); } - const accuracyMultiplier = new Utils.NumberHolder(1); + const accuracyMultiplier = new NumberHolder(1); if (userAccStage.value !== targetEvaStage.value) { accuracyMultiplier.value = userAccStage.value > targetEvaStage.value @@ -3886,7 +4041,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { sourceMove, ); - const evasionMultiplier = new Utils.NumberHolder(1); + const evasionMultiplier = new NumberHolder(1); applyStatMultiplierAbAttrs( StatMultiplierAbAttr, target, @@ -3941,7 +4096,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * The attacker's offensive stat for the given move's category. * Critical hits cause negative stat stages to be ignored. */ - const sourceAtk = new Utils.NumberHolder( + const sourceAtk = new NumberHolder( source.getEffectiveStat( isPhysical ? Stat.ATK : Stat.SPATK, this, @@ -3959,7 +4114,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * This Pokemon's defensive stat for the given move's category. * Critical hits cause positive stat stages to be ignored. */ - const targetDef = new Utils.NumberHolder( + const targetDef = new NumberHolder( this.getEffectiveStat( isPhysical ? Stat.DEF : Stat.SPDEF, source, @@ -4020,12 +4175,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { isCritical = false, simulated = true, ): DamageCalculationResult { - const damage = new Utils.NumberHolder(0); + const damage = new NumberHolder(0); const defendingSide = this.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - const variableCategory = new Utils.NumberHolder(move.category); + const variableCategory = new NumberHolder(move.category); applyMoveAttrs( VariableMoveCategoryAttr, source, @@ -4039,7 +4194,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const moveType = source.getMoveType(move); /** If `value` is `true`, cancels the move and suppresses "No Effect" messages */ - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); /** * The effectiveness of the move being used. Along with type matchups, this @@ -4059,7 +4214,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const isPhysical = moveCategory === MoveCategory.PHYSICAL; /** Combined damage multiplier from field effects such as weather, terrain, etc. */ - const arenaAttackTypeMultiplier = new Utils.NumberHolder( + const arenaAttackTypeMultiplier = new NumberHolder( globalScene.arena.getAttackTypeMultiplier(moveType, source.isGrounded()), ); applyMoveAttrs( @@ -4082,10 +4237,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } // If the attack deals fixed damage, return a result with that much damage - const fixedDamage = new Utils.NumberHolder(0); + const fixedDamage = new NumberHolder(0); applyMoveAttrs(FixedDamageAttr, source, this, move, fixedDamage); if (fixedDamage.value) { - const multiLensMultiplier = new Utils.NumberHolder(1); + const multiLensMultiplier = new NumberHolder(1); globalScene.applyModifiers( PokemonMultiHitModifier, source.isPlayer(), @@ -4094,7 +4249,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { null, multiLensMultiplier, ); - fixedDamage.value = Utils.toDmgValue( + fixedDamage.value = toDmgValue( fixedDamage.value * multiLensMultiplier.value, ); @@ -4106,7 +4261,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } // If the attack is a one-hit KO move, return a result with damage equal to this Pokemon's HP - const isOneHitKo = new Utils.BooleanHolder(false); + const isOneHitKo = new BooleanHolder(false); applyMoveAttrs(OneHitKOAttr, source, this, move, isOneHitKo); if (isOneHitKo.value) { return { @@ -4138,7 +4293,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const targetMultiplier = numTargets > 1 ? 0.75 : 1; /** Multiplier for moves enhanced by Multi-Lens and/or Parental Bond */ - const multiStrikeEnhancementMultiplier = new Utils.NumberHolder(1); + const multiStrikeEnhancementMultiplier = new NumberHolder(1); globalScene.applyModifiers( PokemonMultiHitModifier, source.isPlayer(), @@ -4160,13 +4315,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } /** Doubles damage if this Pokemon's last move was Glaive Rush */ - const glaiveRushMultiplier = new Utils.NumberHolder(1); + const glaiveRushMultiplier = new NumberHolder(1); if (this.getTag(BattlerTagType.RECEIVE_DOUBLE_DAMAGE)) { glaiveRushMultiplier.value = 2; } /** The damage multiplier when the given move critically hits */ - const criticalMultiplier = new Utils.NumberHolder(isCritical ? 1.5 : 1); + const criticalMultiplier = new NumberHolder(isCritical ? 1.5 : 1); applyAbAttrs(MultCritAbAttr, source, null, simulated, criticalMultiplier); /** @@ -4181,7 +4336,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const sourceTeraType = source.getTeraType(); const matchesSourceType = sourceTypes.includes(moveType); /** A damage multiplier for when the attack is of the attacker's type and/or Tera type. */ - const stabMultiplier = new Utils.NumberHolder(1); + const stabMultiplier = new NumberHolder(1); if (matchesSourceType && moveType !== PokemonType.STELLAR) { stabMultiplier.value += 0.5; } @@ -4222,14 +4377,14 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { stabMultiplier.value = Math.min(stabMultiplier.value, 2.25); /** Halves damage if the attacker is using a physical attack while burned */ - const burnMultiplier = new Utils.NumberHolder(1); + const burnMultiplier = new NumberHolder(1); if ( isPhysical && source.status && source.status.effect === StatusEffect.BURN ) { if (!move.hasAttr(BypassBurnDamageReductionAttr)) { - const burnDamageReductionCancelled = new Utils.BooleanHolder(false); + const burnDamageReductionCancelled = new BooleanHolder(false); if (!ignoreSourceAbility) { applyAbAttrs( BypassBurnDamageReductionAbAttr, @@ -4245,7 +4400,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } /** Reduces damage if this Pokemon has a relevant screen (e.g. Light Screen for special attacks) */ - const screenMultiplier = new Utils.NumberHolder(1); + const screenMultiplier = new NumberHolder(1); // Critical hits should bypass screens if (!isCritical) { @@ -4265,7 +4420,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * AND * The move doubles damage when used against that tag */ - const hitsTagMultiplier = new Utils.NumberHolder(1); + const hitsTagMultiplier = new NumberHolder(1); move .getAttrs(HitsTagAttr) .filter(hta => hta.doubleDamage) @@ -4283,7 +4438,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { ? 0.5 : 1; - damage.value = Utils.toDmgValue( + damage.value = toDmgValue( baseDamage * targetMultiplier * multiStrikeEnhancementMultiplier.value * @@ -4392,10 +4547,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const defendingSide = this.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - const moveCategory = new Utils.NumberHolder(move.category); + const moveCategory = new NumberHolder(move.category); applyMoveAttrs(VariableMoveCategoryAttr, source, this, move, moveCategory); if (moveCategory.value === MoveCategory.STATUS) { - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); const typeMultiplier = this.getMoveEffectiveness( source, move, @@ -4415,7 +4570,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } /** Determines whether the attack critically hits */ let isCritical: boolean; - const critOnly = new Utils.BooleanHolder(false); + const critOnly = new BooleanHolder(false); const critAlways = source.getTag(BattlerTagType.ALWAYS_CRIT); applyMoveAttrs(CritOnlyAttr, source, this, move, critOnly); applyAbAttrs( @@ -4438,7 +4593,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } const noCritTag = globalScene.arena.getTagOnSide(NoCritTag, defendingSide); - const blockCrit = new Utils.BooleanHolder(false); + const blockCrit = new BooleanHolder(false); applyAbAttrs(BlockCritAbAttr, this, null, false, blockCrit); if (noCritTag || blockCrit.value || Overrides.NEVER_CRIT_OVERRIDE) { isCritical = false; @@ -4520,7 +4675,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (damage > 0) { if (source.isPlayer()) { - globalScene.validateAchvs(DamageAchv, new Utils.NumberHolder(damage)); + globalScene.validateAchvs(DamageAchv, new NumberHolder(damage)); if (damage > globalScene.gameData.gameStats.highestDamage) { globalScene.gameData.gameStats.highestDamage = damage; } @@ -4544,7 +4699,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { DamageMoneyRewardModifier, true, source, - new Utils.NumberHolder(damage), + new NumberHolder(damage), ); } } @@ -4609,7 +4764,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (this.isFainted()) { return 0; } - const surviveDamage = new Utils.BooleanHolder(false); + const surviveDamage = new BooleanHolder(false); if (!preventEndure && this.hp - damage <= 0) { if (this.hp >= 1 && this.getTag(BattlerTagType.ENDURING)) { @@ -4744,7 +4899,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const stubTag = new BattlerTag(tagType, 0, 0); - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); applyPreApplyBattlerTagAbAttrs( BattlerTagImmunityAbAttr, this, @@ -4782,7 +4937,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const newTag = getBattlerTag(tagType, turnCount, sourceMove!, sourceId!); // TODO: are the bangs correct? - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); applyPreApplyBattlerTagAbAttrs( BattlerTagImmunityAbAttr, this, @@ -5115,12 +5270,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { let fusionCry = this.getFusionSpeciesForm().cry(soundConfig, true); duration = Math.min(duration, fusionCry.totalDuration * 1000); fusionCry.destroy(); - scene.time.delayedCall(Utils.fixedInt(Math.ceil(duration * 0.4)), () => { + scene.time.delayedCall(fixedInt(Math.ceil(duration * 0.4)), () => { try { SoundFade.fadeOut( scene, cry, - Utils.fixedInt(Math.ceil(duration * 0.2)), + fixedInt(Math.ceil(duration * 0.2)), ); fusionCry = this.getFusionSpeciesForm().cry( Object.assign( @@ -5131,7 +5286,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { SoundFade.fadeIn( scene, fusionCry, - Utils.fixedInt(Math.ceil(duration * 0.2)), + fixedInt(Math.ceil(duration * 0.2)), scene.masterVolume * scene.fieldVolume, 0, ); @@ -5171,7 +5326,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { let faintCryTimer: Phaser.Time.TimerEvent | null = globalScene.time.addEvent({ - delay: Utils.fixedInt(delay), + delay: fixedInt(delay), repeat: -1, callback: () => { frameThreshold = sprite.anims.msPerFrame / rate; @@ -5197,7 +5352,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { }); // Failsafe - globalScene.time.delayedCall(Utils.fixedInt(3000), () => { + globalScene.time.delayedCall(fixedInt(3000), () => { if (!faintCryTimer || !globalScene) { return; } @@ -5256,7 +5411,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { let faintCryTimer: Phaser.Time.TimerEvent | null = globalScene.time.addEvent({ - delay: Utils.fixedInt(delay), + delay: fixedInt(delay), repeat: -1, callback: () => { ++i; @@ -5273,7 +5428,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { SoundFade.fadeOut( globalScene, cry, - Utils.fixedInt(Math.ceil((duration / rate) * 0.2)), + fixedInt(Math.ceil((duration / rate) * 0.2)), ); fusionCry = globalScene.playSound( fusionCryKey, @@ -5285,7 +5440,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { SoundFade.fadeIn( globalScene, fusionCry, - Utils.fixedInt(Math.ceil((duration / rate) * 0.2)), + fixedInt(Math.ceil((duration / rate) * 0.2)), globalScene.masterVolume * globalScene.fieldVolume, 0, ); @@ -5311,7 +5466,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { }); // Failsafe - globalScene.time.delayedCall(Utils.fixedInt(3000), () => { + globalScene.time.delayedCall(fixedInt(3000), () => { if (!faintCryTimer || !globalScene) { return; } @@ -5386,7 +5541,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } // Check if the source Pokemon has an ability that cancels the Poison/Toxic immunity - const cancelImmunity = new Utils.BooleanHolder(false); + const cancelImmunity = new BooleanHolder(false); if (sourcePokemon) { applyAbAttrs( IgnoreTypeStatusEffectImmunityAbAttr, @@ -5442,7 +5597,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { break; } - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); applyPreSetStatusAbAttrs( StatusEffectImmunityAbAttr, this, @@ -5513,10 +5668,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return true; } - let sleepTurnsRemaining: Utils.NumberHolder; + let sleepTurnsRemaining: NumberHolder; if (effect === StatusEffect.SLEEP) { - sleepTurnsRemaining = new Utils.NumberHolder(this.randSeedIntRange(2, 4)); + sleepTurnsRemaining = new NumberHolder(this.randSeedIntRange(2, 4)); this.setFrameRate(4); @@ -5567,7 +5722,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; if (globalScene.arena.getTagOnSide(ArenaTagType.SAFEGUARD, defendingSide)) { - const bypassed = new Utils.BooleanHolder(false); + const bypassed = new BooleanHolder(false); if (attacker) { applyAbAttrs(InfiltratorAbAttr, attacker, null, false, bypassed); } @@ -5580,7 +5735,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.summonDataPrimer = summonDataPrimer; } + // For PreSummonAbAttr to get access to summonData + initSummondata(): void { + this.summonData = this.summonData ?? this.summonDataPrimer ?? new PokemonSummonData() + } + resetSummonData(): void { + const illusion: IllusionData | null = this.summonData?.illusion; if (this.summonData?.speciesForm) { this.summonData.speciesForm = null; this.updateFusionPalette(); @@ -5616,6 +5777,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } this.summonDataPrimer = null; } + this.summonData.illusion = illusion this.updateInfo(); } @@ -5863,9 +6025,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (this.shiny && variantColors && variantColors[this.variant]) { Object.keys(variantColors[this.variant]).forEach(k => { variantColorSet.set( - Utils.rgbaToInt(Array.from(Object.values(Utils.rgbHexToRgba(k)))), + rgbaToInt(Array.from(Object.values(rgbHexToRgba(k)))), Array.from( - Object.values(Utils.rgbHexToRgba(variantColors[this.variant][k])), + Object.values(rgbHexToRgba(variantColors[this.variant][k])), ), ); }); @@ -5876,7 +6038,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const pixel = pixelData[f].slice(i, i + 4); let [r, g, b, a] = pixel; if (variantColors) { - const color = Utils.rgbaToInt([r, g, b, a]); + const color = rgbaToInt([r, g, b, a]); if (variantColorSet.has(color)) { const mappedPixel = variantColorSet.get(color); if (mappedPixel) { @@ -5925,10 +6087,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { ) { for (const k of Object.keys(variantColors[this.fusionVariant])) { variantColorSet.set( - Utils.rgbaToInt(Array.from(Object.values(Utils.rgbHexToRgba(k)))), + rgbaToInt(Array.from(Object.values(rgbHexToRgba(k)))), Array.from( Object.values( - Utils.rgbHexToRgba(variantColors[this.fusionVariant][k]), + rgbHexToRgba(variantColors[this.fusionVariant][k]), ), ), ); @@ -5948,7 +6110,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { pixelData[2 + f][i + 3], ]; if (variantColors) { - const color = Utils.rgbaToInt([r, g, b, a]); + const color = rgbaToInt([r, g, b, a]); if (variantColorSet.has(color)) { const mappedPixel = variantColorSet.get(color); if (mappedPixel) { @@ -6006,7 +6168,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { hsvColors = Array.from(rgbaColors.keys()).reduce( (map: Map, k: number) => { const rgb = rgbaColors.get(k)!.slice(0, 3); - map.set(k, Utils.rgbToHsv(rgb[0], rgb[1], rgb[2])); + map.set(k, rgbToHsv(rgb[0], rgb[1], rgb[2])); return map; }, new Map(), @@ -6086,7 +6248,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { spriteColors.forEach((sc: number[], i: number) => { paletteDeltas.push([]); for (let p = 0; p < palette.length; p++) { - paletteDeltas[i].push(Utils.deltaRgb(sc, palette[p])); + paletteDeltas[i].push(deltaRgb(sc, palette[p])); } }); @@ -6131,8 +6293,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * * This calls either {@linkcode BattleScene.randBattleSeedInt}({@linkcode range}, {@linkcode min}) in `src/battle-scene.ts` * which calls {@linkcode Battle.randSeedInt}({@linkcode range}, {@linkcode min}) in `src/battle.ts` - * which calls {@linkcode Utils.randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts`, - * or it directly calls {@linkcode Utils.randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts` if there is no current battle + * which calls {@linkcode randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts`, + * or it directly calls {@linkcode randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts` if there is no current battle * * @param range How large of a range of random numbers to choose from. If {@linkcode range} <= 1, returns {@linkcode min} * @param min The minimum integer to pick, default `0` @@ -6141,7 +6303,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { randSeedInt(range: number, min = 0): number { return globalScene.currentBattle ? globalScene.randBattleSeedInt(range, min) - : Utils.randSeedInt(range, min); + : randSeedInt(range, min); } /** @@ -6437,7 +6599,7 @@ export class PlayerPokemon extends Pokemon { ? globalScene.gameData.starterData[fusionStarterSpeciesId] : null, ].filter(d => !!d); - const amount = new Utils.NumberHolder(friendship); + const amount = new NumberHolder(friendship); globalScene.applyModifier( PokemonFriendshipBoosterModifier, true, @@ -6452,7 +6614,7 @@ export class PlayerPokemon extends Pokemon { ? 1.5 // Divide candy gain for fusions by 1.5 during events : 2 // 2 for fusions outside events : 1; // 1 for non-fused mons - const starterAmount = new Utils.NumberHolder( + const starterAmount = new NumberHolder( Math.floor( (amount.value * candyFriendshipMultiplier) / fusionReduction, ), @@ -7188,15 +7350,11 @@ export class EnemyPokemon extends Pokemon { ) { targetScore = -20; } else if (move instanceof AttackMove) { - /** - * Attack moves are given extra multipliers to their base benefit score based on - * the move's type effectiveness against the target and whether the move is a STAB move. - */ - const effectiveness = target.getMoveEffectiveness( - this, - move, - !target.battleData?.abilityRevealed, - ); + /** + * Attack moves are given extra multipliers to their base benefit score based on + * the move's type effectiveness against the target and whether the move is a STAB move. + */ + const effectiveness = target.getMoveEffectiveness(this, move, !target.battleData?.abilityRevealed, undefined, undefined, true); if (target.isPlayer() !== this.isPlayer()) { targetScore *= effectiveness; if (this.isOfType(move.type)) { @@ -7415,7 +7573,7 @@ export class EnemyPokemon extends Pokemon { //console.log('damage', damage, 'segment', segmentsBypassed + 1, 'segment size', segmentSize, 'damage needed', Math.round(segmentSize * Math.pow(2, segmentsBypassed + 1))); } - damage = Utils.toDmgValue( + damage = toDmgValue( this.hp - hpThreshold + segmentSize * segmentsBypassed, ); clearedBossSegmentIndex = s - segmentsBypassed; @@ -7493,7 +7651,7 @@ export class EnemyPokemon extends Pokemon { } // Pick a random stat from the leftover stats to increase its stages - const randInt = Utils.randSeedInt(totalWeight); + const randInt = randSeedInt(totalWeight); for (const i in statThresholds) { if (randInt < statThresholds[i]) { boostedStat = leftoverStats[i]; @@ -7564,7 +7722,7 @@ export class EnemyPokemon extends Pokemon { this, ); - if (Utils.isBetween(slotIndex, 0, PLAYER_PARTY_MAX_SIZE - 1)) { + if (isBetween(slotIndex, 0, PLAYER_PARTY_MAX_SIZE - 1)) { party.splice(slotIndex, 0, newPokemon); } else { party.push(newPokemon); @@ -7585,6 +7743,42 @@ export class EnemyPokemon extends Pokemon { } } +/** + * Illusion property + */ +interface IllusionData { + basePokemon: { + /** The actual name of the Pokemon */ + name: string; + /** The actual nickname of the Pokemon */ + nickname: string; + /** Whether the base pokemon is shiny or not */ + shiny: boolean; + /** The shiny variant of the base pokemon */ + variant: Variant; + /** Whether the fusion species of the base pokemon is shiny or not */ + fusionShiny: boolean; + /** The variant of the fusion species of the base pokemon */ + fusionVariant: Variant; + }; + /** The species of the illusion */ + species: Species; + /** The formIndex of the illusion */ + formIndex: number; + /** The gender of the illusion */ + gender: Gender; + /** The pokeball of the illusion */ + pokeball: PokeballType; + /** The fusion species of the illusion if it's a fusion */ + fusionSpecies?: PokemonSpecies; + /** The fusionFormIndex of the illusion */ + fusionFormIndex?: number; + /** The fusionGender of the illusion if it's a fusion */ + fusionGender?: Gender; + /** The level of the illusion (not used currently) */ + level?: number +} + export interface TurnMove { move: Moves; targets: BattlerIndex[]; @@ -7618,9 +7812,12 @@ export class PokemonSummonData { public fusionGender: Gender; public stats: number[] = [0, 0, 0, 0, 0, 0]; public moveset: PokemonMove[]; + public illusionBroken: boolean = false; + // If not initialized this value will not be populated from save data. public types: PokemonType[] = []; public addedType: PokemonType | null = null; + public illusion: IllusionData | null = null; } export class PokemonBattleData { @@ -7631,7 +7828,7 @@ export class PokemonBattleData { public endured = false; public berriesEaten: BerryType[] = []; public abilitiesApplied: Abilities[] = []; - public abilityRevealed = false; + public abilityRevealed: boolean = false; } export class PokemonBattleSummonData { @@ -7806,7 +8003,7 @@ export class PokemonMove { getMovePp(): number { return ( this.maxPpOverride || - this.getMove().pp + this.ppUp * Utils.toDmgValue(this.getMove().pp / 5) + this.getMove().pp + this.ppUp * toDmgValue(this.getMove().pp / 5) ); } diff --git a/src/field/trainer.ts b/src/field/trainer.ts index ccd8c83e684..30cf43b54a1 100644 --- a/src/field/trainer.ts +++ b/src/field/trainer.ts @@ -11,7 +11,7 @@ import { TrainerSlot } from "#enums/trainer-slot"; import { TrainerPoolTier } from "#enums/trainer-pool-tier"; import { TeraAIMode } from "#enums/tera-ai-mode"; import type { EnemyPokemon } from "#app/field/pokemon"; -import * as Utils from "#app/utils"; +import { randSeedWeightedItem, randSeedItem, randSeedInt } from "#app/utils"; import type { PersistentModifier } from "#app/modifier/modifier"; import { ArenaTagSide, ArenaTrapTag } from "#app/data/arena-tag"; import { getIsInitialized, initI18n } from "#app/plugins/i18n"; @@ -58,7 +58,7 @@ export default class Trainer extends Phaser.GameObjects.Container { this.partyTemplateIndex = Math.min( partyTemplateIndex !== undefined ? partyTemplateIndex - : Utils.randSeedWeightedItem(this.config.partyTemplates.map((_, i) => i)), + : randSeedWeightedItem(this.config.partyTemplates.map((_, i) => i)), this.config.partyTemplates.length - 1, ); const classKey = `trainersCommon:${TrainerType[trainerType]}`; @@ -71,9 +71,7 @@ export default class Trainer extends Phaser.GameObjects.Container { ? ".FEMALE" : ".MALE" : ""; - const trainerKey = Utils.randSeedItem( - Object.keys(i18next.t(`${classKey}${genderKey}`, { returnObjects: true })), - ); + const trainerKey = randSeedItem(Object.keys(i18next.t(`${classKey}${genderKey}`, { returnObjects: true }))); this.nameKey = `${classKey}${genderKey}.${trainerKey}`; } this.name = i18next.t(this.nameKey); @@ -87,7 +85,7 @@ export default class Trainer extends Phaser.GameObjects.Container { } } else { const partnerGenderKey = i18next.exists(`${classKey}.FEMALE`) ? ".FEMALE" : ""; - const partnerTrainerKey = Utils.randSeedItem( + const partnerTrainerKey = randSeedItem( Object.keys( i18next.t(`${classKey}${partnerGenderKey}`, { returnObjects: true, @@ -420,7 +418,7 @@ export default class Trainer extends Phaser.GameObjects.Container { // If useNewSpeciesPool is true, we need to generate a new species from the new species pool, otherwise we generate a random species let species = useNewSpeciesPool - ? getPokemonSpecies(newSpeciesPool[Math.floor(Utils.randSeedInt(newSpeciesPool.length))]) + ? getPokemonSpecies(newSpeciesPool[Math.floor(randSeedInt(newSpeciesPool.length))]) : template.isSameSpecies(index) && index > offset ? getPokemonSpecies( battle.enemyParty[offset].species.getTrainerSpeciesForLevel( @@ -461,7 +459,7 @@ export default class Trainer extends Phaser.GameObjects.Container { let baseSpecies: PokemonSpecies; if (this.config.speciesPools) { - const tierValue = Utils.randSeedInt(512); + const tierValue = randSeedInt(512); let tier = tierValue >= 156 ? TrainerPoolTier.COMMON @@ -480,7 +478,7 @@ export default class Trainer extends Phaser.GameObjects.Container { tier--; } const tierPool = this.config.speciesPools[tier]; - baseSpecies = getPokemonSpecies(Utils.randSeedItem(tierPool)); + baseSpecies = getPokemonSpecies(randSeedItem(tierPool)); } else { baseSpecies = globalScene.randomSpecies(battle.waveIndex, level, false, this.config.speciesFilter); } @@ -619,7 +617,7 @@ export default class Trainer extends Phaser.GameObjects.Container { if (maxScorePartyMemberIndexes.length > 1) { let rand: number; globalScene.executeWithSeedOffset( - () => (rand = Utils.randSeedInt(maxScorePartyMemberIndexes.length)), + () => (rand = randSeedInt(maxScorePartyMemberIndexes.length)), globalScene.currentBattle.turn << 2, ); return maxScorePartyMemberIndexes[rand!]; diff --git a/src/game-mode.ts b/src/game-mode.ts index c340768ef77..4779fda50e8 100644 --- a/src/game-mode.ts +++ b/src/game-mode.ts @@ -7,7 +7,7 @@ import type PokemonSpecies from "./data/pokemon-species"; import { allSpecies } from "./data/pokemon-species"; import type { Arena } from "./field/arena"; import Overrides from "#app/overrides"; -import * as Utils from "./utils"; +import { randSeedInt, randSeedItem } from "#app/utils"; import { Biome } from "#enums/biome"; import { Species } from "#enums/species"; import { Challenges } from "./enums/challenges"; @@ -186,7 +186,7 @@ export class GameMode implements GameModeConfig { if (w < waveIndex) { globalScene.executeWithSeedOffset(() => { const waveTrainerChance = arena.getTrainerChance(); - if (!Utils.randSeedInt(waveTrainerChance)) { + if (!randSeedInt(waveTrainerChance)) { allowTrainerBattle = false; } }, w); @@ -196,7 +196,7 @@ export class GameMode implements GameModeConfig { } } } - return Boolean(allowTrainerBattle && trainerChance && !Utils.randSeedInt(trainerChance)); + return Boolean(allowTrainerBattle && trainerChance && !randSeedInt(trainerChance)); } return false; } @@ -222,7 +222,7 @@ export class GameMode implements GameModeConfig { s.speciesId !== Species.ETERNATUS && s.speciesId !== Species.ARCEUS, ); - return Utils.randSeedItem(allFinalBossSpecies); + return randSeedItem(allFinalBossSpecies); } return null; diff --git a/src/inputs-controller.ts b/src/inputs-controller.ts index fb4555084ee..f92ce3957ab 100644 --- a/src/inputs-controller.ts +++ b/src/inputs-controller.ts @@ -1,6 +1,5 @@ import Phaser from "phaser"; -import * as Utils from "./utils"; -import { deepCopy } from "./utils"; +import { deepCopy, getEnumValues } from "#app/utils"; import pad_generic from "./configs/inputs/pad_generic"; import pad_unlicensedSNES from "./configs/inputs/pad_unlicensedSNES"; import pad_xbox360 from "./configs/inputs/pad_xbox360"; @@ -102,7 +101,7 @@ export class InputsController { [Device.KEYBOARD]: "default", }; - for (const b of Utils.getEnumValues(Button)) { + for (const b of getEnumValues(Button)) { this.interactions[b] = { pressTime: false, isPressed: false, diff --git a/src/loading-scene.ts b/src/loading-scene.ts index f99831c53bc..b45cf64ff56 100644 --- a/src/loading-scene.ts +++ b/src/loading-scene.ts @@ -4,7 +4,7 @@ import CacheBustedLoaderPlugin from "#app/plugins/cache-busted-loader-plugin"; import { SceneBase } from "#app/scene-base"; import { WindowVariant, getWindowVariantSuffix } from "#app/ui/ui-theme"; import { isMobile } from "#app/touch-controls"; -import * as Utils from "#app/utils"; +import { localPing, getEnumValues, hasAllLocalizedSprites, getEnumKeys } from "#app/utils"; import { initPokemonPrevolutions, initPokemonStarters } from "#app/data/balance/pokemon-evolutions"; import { initBiomes } from "#app/data/balance/biomes"; import { initEggMoves } from "#app/data/balance/egg-moves"; @@ -34,7 +34,7 @@ export class LoadingScene extends SceneBase { } preload() { - Utils.localPing(); + localPing(); this.load["manifest"] = this.game["manifest"]; this.loadImage("loading_bg", "arenas"); @@ -49,7 +49,7 @@ export class LoadingScene extends SceneBase { this.loadImage("friendship_overlay", "ui"); this.loadImage("cursor", "ui"); this.loadImage("cursor_reverse", "ui"); - for (const wv of Utils.getEnumValues(WindowVariant)) { + for (const wv of getEnumValues(WindowVariant)) { for (let w = 1; w <= 5; w++) { this.loadImage(`window_${w}${getWindowVariantSuffix(wv)}`, "ui/windows"); } @@ -177,7 +177,7 @@ export class LoadingScene extends SceneBase { this.loadImage("default_bg", "arenas"); // Load arena images - Utils.getEnumValues(Biome).map(bt => { + getEnumValues(Biome).map(bt => { const btKey = Biome[bt].toLowerCase(); const isBaseAnimated = btKey === "end"; const baseAKey = `${btKey}_a`; @@ -239,7 +239,7 @@ export class LoadingScene extends SceneBase { // Get current lang and load the types atlas for it. English will only load types while all other languages will load types and types_ const lang = i18next.resolvedLanguage; if (lang !== "en") { - if (Utils.hasAllLocalizedSprites(lang)) { + if (hasAllLocalizedSprites(lang)) { this.loadAtlas(`statuses_${lang}`, ""); this.loadAtlas(`types_${lang}`, ""); } else { @@ -268,7 +268,7 @@ export class LoadingScene extends SceneBase { this.loadAtlas("egg_icons", "egg"); this.loadAtlas("egg_shard", "egg"); this.loadAtlas("egg_lightrays", "egg"); - for (const gt of Utils.getEnumKeys(GachaType)) { + for (const gt of getEnumKeys(GachaType)) { const key = gt.toLowerCase(); this.loadImage(`gacha_${key}`, "egg"); this.loadAtlas(`gacha_underlay_${key}`, "egg"); diff --git a/src/messages.ts b/src/messages.ts index e35b48f7226..c29151a98b3 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -6,9 +6,10 @@ import i18next from "i18next"; /** * Retrieves the Pokemon's name, potentially with an affix indicating its role (wild or foe) in the current battle context, translated * @param pokemon {@linkcode Pokemon} name and battle context will be retrieved from this instance + * @param {boolean} useIllusion - Whether we want the name of the illusion or not. Default value : true * @returns {string} ex: "Wild Gengar", "Ectoplasma sauvage" */ -export function getPokemonNameWithAffix(pokemon: Pokemon | undefined): string { +export function getPokemonNameWithAffix(pokemon: Pokemon | undefined, useIllusion = true): string { if (!pokemon) { return "Missigno"; } @@ -18,19 +19,17 @@ export function getPokemonNameWithAffix(pokemon: Pokemon | undefined): string { return !pokemon.isPlayer() ? pokemon.hasTrainer() ? i18next.t("battle:foePokemonWithAffix", { - pokemonName: pokemon.getNameToRender(), + pokemonName: pokemon.getNameToRender(useIllusion), }) : i18next.t("battle:wildPokemonWithAffix", { - pokemonName: pokemon.getNameToRender(), + pokemonName: pokemon.getNameToRender(useIllusion), }) - : pokemon.getNameToRender(); + : pokemon.getNameToRender(useIllusion); case BattleSpec.FINAL_BOSS: return !pokemon.isPlayer() - ? i18next.t("battle:foePokemonWithAffix", { - pokemonName: pokemon.getNameToRender(), - }) - : pokemon.getNameToRender(); + ? i18next.t("battle:foePokemonWithAffix", { pokemonName: pokemon.getNameToRender(useIllusion) }) + : pokemon.getNameToRender(useIllusion); default: - return pokemon.getNameToRender(); + return pokemon.getNameToRender(useIllusion); } } diff --git a/src/overrides.ts b/src/overrides.ts index 3a9a54e740b..21c72cd7b98 100644 --- a/src/overrides.ts +++ b/src/overrides.ts @@ -2,7 +2,7 @@ import { type PokeballCounts } from "#app/battle-scene"; import { EvolutionItem } from "#app/data/balance/pokemon-evolutions"; import { Gender } from "#app/data/gender"; import { FormChangeItem } from "#app/data/pokemon-forms"; -import { Variant } from "#app/data/variant"; +import { Variant } from "#app/sprites/variant"; import { type ModifierOverride } from "#app/modifier/modifier-type"; import { Unlockables } from "#app/system/unlockables"; import { Abilities } from "#enums/abilities"; diff --git a/src/phases/encounter-phase.ts b/src/phases/encounter-phase.ts index 9e5edf3e1d9..15f3d102e41 100644 --- a/src/phases/encounter-phase.ts +++ b/src/phases/encounter-phase.ts @@ -1,7 +1,7 @@ import { BattlerIndex, BattleType } from "#app/battle"; import { globalScene } from "#app/global-scene"; import { PLAYER_PARTY_MAX_SIZE } from "#app/constants"; -import { applyAbAttrs, SyncEncounterNatureAbAttr } from "#app/data/ability"; +import { applyAbAttrs, SyncEncounterNatureAbAttr, applyPreSummonAbAttrs, PreSummonAbAttr } from "#app/data/ability"; import { initEncounterAnims, loadEncounterAnimAssets } from "#app/data/battle-anims"; import { getCharVariantFromDialogue } from "#app/data/dialogue"; import { getEncounterText } from "#app/data/mystery-encounters/utils/encounter-dialogue-utils"; @@ -259,6 +259,9 @@ export class EncounterPhase extends BattlePhase { } if (e < (battle.double ? 2 : 1)) { if (battle.battleType === BattleType.WILD) { + for (const pokemon of globalScene.getField()) { + applyPreSummonAbAttrs(PreSummonAbAttr, pokemon, []); + } globalScene.field.add(enemyPokemon); battle.seenEnemyPartyMemberIds.add(enemyPokemon.id); const playerPokemon = globalScene.getPlayerPokemon(); @@ -545,7 +548,7 @@ export class EncounterPhase extends BattlePhase { const enemyField = globalScene.getEnemyField(); enemyField.forEach((enemyPokemon, e) => { - if (enemyPokemon.isShiny()) { + if (enemyPokemon.isShiny(true)) { globalScene.unshiftPhase(new ShinySparklePhase(BattlerIndex.ENEMY + e)); } /** This sets Eternatus' held item to be untransferrable, preventing it from being stolen */ diff --git a/src/phases/level-up-phase.ts b/src/phases/level-up-phase.ts index 31c7fabf451..c6ca17d583e 100644 --- a/src/phases/level-up-phase.ts +++ b/src/phases/level-up-phase.ts @@ -71,6 +71,7 @@ export class LevelUpPhase extends PlayerPartyMemberPokemonPhase { if (!this.pokemon.pauseEvolutions) { const evolution = this.pokemon.getEvolution(); if (evolution) { + this.pokemon.breakIllusion() globalScene.unshiftPhase(new EvolutionPhase(this.pokemon, evolution, this.lastLevel)); } } diff --git a/src/phases/move-effect-phase.ts b/src/phases/move-effect-phase.ts index 6c46f7ff8c0..acc7ac0f63a 100644 --- a/src/phases/move-effect-phase.ts +++ b/src/phases/move-effect-phase.ts @@ -297,16 +297,16 @@ export class MoveEffectPhase extends PokemonPhase { ); } - /** Is the target protected by Protect, etc. or a relevant conditional protection effect? */ - const isProtected = - ![MoveTarget.ENEMY_SIDE, MoveTarget.BOTH_SIDES].includes(this.move.getMove().moveTarget) && - (bypassIgnoreProtect.value || - !this.move.getMove().doesFlagEffectApply({ flag: MoveFlags.IGNORE_PROTECT, user, target })) && - (hasConditionalProtectApplied.value || - (!target.findTags(t => t instanceof DamageProtectedTag).length && - target.findTags(t => t instanceof ProtectedTag).find(t => target.lapseTag(t.tagType))) || - (this.move.getMove().category !== MoveCategory.STATUS && - target.findTags(t => t instanceof DamageProtectedTag).find(t => target.lapseTag(t.tagType)))); + /** Is the target protected by Protect, etc. or a relevant conditional protection effect? */ + const isProtected = + ![MoveTarget.ENEMY_SIDE, MoveTarget.BOTH_SIDES].includes(this.move.getMove().moveTarget) && + (bypassIgnoreProtect.value || + !this.move.getMove().doesFlagEffectApply({ flag: MoveFlags.IGNORE_PROTECT, user, target })) && + (hasConditionalProtectApplied.value || + (!target.findTags(t => t instanceof DamageProtectedTag).length && + target.findTags(t => t instanceof ProtectedTag).find(t => target.lapseTag(t.tagType))) || + (this.move.getMove().category !== MoveCategory.STATUS && + target.findTags(t => t instanceof DamageProtectedTag).find(t => target.lapseTag(t.tagType)))); /** Is the target hidden by the effects of its Commander ability? */ const isCommanding = @@ -316,11 +316,11 @@ export class MoveEffectPhase extends PokemonPhase { /** Is the target reflecting status moves from the magic coat move? */ const isReflecting = !!target.getTag(BattlerTagType.MAGIC_COAT); - /** Is the target's magic bounce ability not ignored and able to reflect this move? */ - const canMagicBounce = - !isReflecting && - !move.doesFlagEffectApply({ flag: MoveFlags.IGNORE_ABILITIES, user, target }) && - target.hasAbilityWithAttr(ReflectStatusMoveAbAttr); + /** Is the target's magic bounce ability not ignored and able to reflect this move? */ + const canMagicBounce = + !isReflecting && + !move.doesFlagEffectApply({ flag: MoveFlags.IGNORE_ABILITIES, user, target }) && + target.hasAbilityWithAttr(ReflectStatusMoveAbAttr); const semiInvulnerableTag = target.getTag(SemiInvulnerableTag); @@ -333,21 +333,19 @@ export class MoveEffectPhase extends PokemonPhase { (isReflecting || canMagicBounce) && !semiInvulnerableTag; - // If the move will bounce, then queue the bounce and move on to the next target - if (!target.switchOutStatus && willBounce) { - const newTargets = move.isMultiTarget() - ? getMoveTargets(target, move.id).targets - : [user.getBattlerIndex()]; - if (!isReflecting) { - // TODO: Ability displays should be handled by the ability - queuedPhases.push( - new ShowAbilityPhase( - target.getBattlerIndex(), - target.getPassiveAbility().hasAttr(ReflectStatusMoveAbAttr), - ), - ); - queuedPhases.push(new HideAbilityPhase()); - } + // If the move will bounce, then queue the bounce and move on to the next target + if (!target.switchOutStatus && willBounce) { + const newTargets = move.isMultiTarget() ? getMoveTargets(target, move.id).targets : [user.getBattlerIndex()]; + if (!isReflecting) { + // TODO: Ability displays should be handled by the ability + queuedPhases.push( + new ShowAbilityPhase( + target.getBattlerIndex(), + target.getPassiveAbility().hasAttr(ReflectStatusMoveAbAttr), + ), + ); + queuedPhases.push(new HideAbilityPhase()); + } queuedPhases.push(new MovePhase(target, newTargets, new PokemonMove(move.id, 0, 0, true), true, true, true)); continue; diff --git a/src/phases/revival-blessing-phase.ts b/src/phases/revival-blessing-phase.ts index e650d714abc..f6fe4d9a3ee 100644 --- a/src/phases/revival-blessing-phase.ts +++ b/src/phases/revival-blessing-phase.ts @@ -4,7 +4,7 @@ import type { PartyOption } from "#app/ui/party-ui-handler"; import PartyUiHandler, { PartyUiMode } from "#app/ui/party-ui-handler"; import { Mode } from "#app/ui/ui"; import i18next from "i18next"; -import * as Utils from "#app/utils"; +import { toDmgValue, isNullOrUndefined } from "#app/utils"; import { BattlePhase } from "#app/phases/battle-phase"; import { SwitchSummonPhase } from "#app/phases/switch-summon-phase"; import { ToggleDoublePositionPhase } from "#app/phases/toggle-double-position-phase"; @@ -33,7 +33,7 @@ export class RevivalBlessingPhase extends BattlePhase { pokemon.resetTurnData(); pokemon.resetStatus(); - pokemon.heal(Math.min(Utils.toDmgValue(0.5 * pokemon.getMaxHp()), pokemon.getMaxHp())); + pokemon.heal(Math.min(toDmgValue(0.5 * pokemon.getMaxHp()), pokemon.getMaxHp())); globalScene.queueMessage( i18next.t("moveTriggers:revivalBlessing", { pokemonName: pokemon.name, @@ -46,7 +46,7 @@ export class RevivalBlessingPhase extends BattlePhase { if ( globalScene.currentBattle.double && globalScene.getPlayerParty().length > 1 && - !Utils.isNullOrUndefined(allyPokemon) + !isNullOrUndefined(allyPokemon) ) { if (slotIndex <= 1) { // Revived ally pokemon diff --git a/src/phases/select-biome-phase.ts b/src/phases/select-biome-phase.ts index 2d67cb87405..b27e2d0e7cc 100644 --- a/src/phases/select-biome-phase.ts +++ b/src/phases/select-biome-phase.ts @@ -33,24 +33,12 @@ export class SelectBiomePhase extends BattlePhase { } else if (globalScene.gameMode.hasRandomBiomes) { setNextBiome(this.generateNextBiome()); } else if (Array.isArray(biomeLinks[currentBiome])) { - let biomes: Biome[] = []; - globalScene.executeWithSeedOffset(() => { - biomes = (biomeLinks[currentBiome] as (Biome | [Biome, number])[]) - .filter(b => !Array.isArray(b) || !randSeedInt(b[1])) - .map(b => (!Array.isArray(b) ? b : b[0])); - }, globalScene.currentBattle.waveIndex); + const biomes: Biome[] = (biomeLinks[currentBiome] as (Biome | [Biome, number])[]) + .filter(b => !Array.isArray(b) || !randSeedInt(b[1])) + .map(b => (!Array.isArray(b) ? b : b[0])); + if (biomes.length > 1 && globalScene.findModifier(m => m instanceof MapModifier)) { - let biomeChoices: Biome[] = []; - globalScene.executeWithSeedOffset(() => { - biomeChoices = ( - !Array.isArray(biomeLinks[currentBiome]) - ? [biomeLinks[currentBiome] as Biome] - : (biomeLinks[currentBiome] as (Biome | [Biome, number])[]) - ) - .filter(b => !Array.isArray(b) || !randSeedInt(b[1])) - .map(b => (Array.isArray(b) ? b[0] : b)); - }, globalScene.currentBattle.waveIndex); - const biomeSelectItems = biomeChoices.map(b => { + const biomeSelectItems = biomes.map(b => { const ret: OptionSelectItem = { label: getBiomeName(b), handler: () => { diff --git a/src/phases/select-starter-phase.ts b/src/phases/select-starter-phase.ts index c6ded6be7af..35511531609 100644 --- a/src/phases/select-starter-phase.ts +++ b/src/phases/select-starter-phase.ts @@ -12,7 +12,7 @@ import type { Starter } from "#app/ui/starter-select-ui-handler"; import { Mode } from "#app/ui/ui"; import type { Species } from "#enums/species"; import SoundFade from "phaser3-rex-plugins/plugins/soundfade"; -import * as Utils from "../utils"; +import { isNullOrUndefined } from "#app/utils"; export class SelectStarterPhase extends Phase { start() { @@ -49,7 +49,7 @@ export class SelectStarterPhase extends Phase { let starterFormIndex = Math.min(starterProps.formIndex, Math.max(starter.species.forms.length - 1, 0)); if ( starter.species.speciesId in Overrides.STARTER_FORM_OVERRIDES && - !Utils.isNullOrUndefined(Overrides.STARTER_FORM_OVERRIDES[starter.species.speciesId]) && + !isNullOrUndefined(Overrides.STARTER_FORM_OVERRIDES[starter.species.speciesId]) && starter.species.forms[Overrides.STARTER_FORM_OVERRIDES[starter.species.speciesId]!] ) { starterFormIndex = Overrides.STARTER_FORM_OVERRIDES[starter.species.speciesId]!; @@ -87,7 +87,7 @@ export class SelectStarterPhase extends Phase { starterPokemon.nickname = starter.nickname; } - if (!Utils.isNullOrUndefined(starter.teraType)) { + if (!isNullOrUndefined(starter.teraType)) { starterPokemon.teraType = starter.teraType; } else { starterPokemon.teraType = starterPokemon.species.type1; diff --git a/src/phases/summon-phase.ts b/src/phases/summon-phase.ts index 621c8c8c2a9..7379d509e55 100644 --- a/src/phases/summon-phase.ts +++ b/src/phases/summon-phase.ts @@ -13,6 +13,7 @@ import { PostSummonPhase } from "./post-summon-phase"; import { GameOverPhase } from "./game-over-phase"; import { ShinySparklePhase } from "./shiny-sparkle-phase"; import { MysteryEncounterMode } from "#enums/mystery-encounter-mode"; +import { applyPreSummonAbAttrs, PreSummonAbAttr } from "#app/data/ability"; import { globalScene } from "#app/global-scene"; export class SummonPhase extends PartyMemberPokemonPhase { @@ -27,6 +28,7 @@ export class SummonPhase extends PartyMemberPokemonPhase { start() { super.start(); + applyPreSummonAbAttrs(PreSummonAbAttr, this.getPokemon()); this.preSummon(); } @@ -126,7 +128,7 @@ export class SummonPhase extends PartyMemberPokemonPhase { this.player ? 36 : 248, this.player ? 80 : 44, "pb", - getPokeballAtlasKey(pokemon.pokeball), + getPokeballAtlasKey(pokemon.getPokeball(true)), ); pokeball.setVisible(false); pokeball.setOrigin(0.5, 0.625); @@ -175,7 +177,11 @@ export class SummonPhase extends PartyMemberPokemonPhase { } globalScene.currentBattle.seenEnemyPartyMemberIds.add(pokemon.id); } - addPokeballOpenParticles(pokemon.x, pokemon.y - 16, pokemon.pokeball); + addPokeballOpenParticles( + pokemon.x, + pokemon.y - 16, + pokemon.getPokeball(true), + ); globalScene.updateModifiers(this.player); globalScene.updateFieldScale(); pokemon.showInfo(); @@ -183,7 +189,7 @@ export class SummonPhase extends PartyMemberPokemonPhase { pokemon.setVisible(true); pokemon.getSprite().setVisible(true); pokemon.setScale(0.5); - pokemon.tint(getPokeballTintColor(pokemon.pokeball)); + pokemon.tint(getPokeballTintColor(pokemon.getPokeball(true))); pokemon.untint(250, "Sine.easeIn"); globalScene.updateFieldScale(); globalScene.tweens.add({ @@ -270,7 +276,7 @@ export class SummonPhase extends PartyMemberPokemonPhase { onEnd(): void { const pokemon = this.getPokemon(); - if (pokemon.isShiny()) { + if (pokemon.isShiny(true)) { globalScene.unshiftPhase(new ShinySparklePhase(pokemon.getBattlerIndex())); } diff --git a/src/phases/switch-summon-phase.ts b/src/phases/switch-summon-phase.ts index e0903ada275..d63cdb90f25 100644 --- a/src/phases/switch-summon-phase.ts +++ b/src/phases/switch-summon-phase.ts @@ -1,5 +1,11 @@ import { globalScene } from "#app/global-scene"; -import { applyPreSwitchOutAbAttrs, PostDamageForceSwitchAbAttr, PreSwitchOutAbAttr } from "#app/data/ability"; +import { + applyPreSummonAbAttrs, + applyPreSwitchOutAbAttrs, + PostDamageForceSwitchAbAttr, + PreSummonAbAttr, + PreSwitchOutAbAttr, +} from "#app/data/ability"; import { allMoves, ForceSwitchOutAttr } from "#app/data/moves/move"; import { getPokeballTintColor } from "#app/data/pokeball"; import { SpeciesFormChangeActiveTrigger } from "#app/data/pokemon-forms"; @@ -99,7 +105,7 @@ export class SwitchSummonPhase extends SummonPhase { ); globalScene.playSound("se/pb_rel"); pokemon.hideInfo(); - pokemon.tint(getPokeballTintColor(pokemon.pokeball), 1, 250, "Sine.easeIn"); + pokemon.tint(getPokeballTintColor(pokemon.getPokeball(true)), 1, 250, "Sine.easeIn"); globalScene.tweens.add({ targets: pokemon, duration: 250, @@ -116,6 +122,7 @@ export class SwitchSummonPhase extends SummonPhase { const party = this.player ? this.getParty() : globalScene.getEnemyParty(); const switchedInPokemon = party[this.slotIndex]; this.lastPokemon = this.getPokemon(); + applyPreSummonAbAttrs(PreSummonAbAttr, switchedInPokemon); applyPreSwitchOutAbAttrs(PreSwitchOutAbAttr, this.lastPokemon); if (this.switchType === SwitchType.BATON_PASS && switchedInPokemon) { (this.player ? globalScene.getEnemyField() : globalScene.getPlayerField()).forEach(enemyPokemon => diff --git a/src/pipelines/field-sprite.ts b/src/pipelines/field-sprite.ts index 547281d7dee..a55b6a9adb6 100644 --- a/src/pipelines/field-sprite.ts +++ b/src/pipelines/field-sprite.ts @@ -1,210 +1,8 @@ import { globalScene } from "#app/global-scene"; import { TerrainType, getTerrainColor } from "../data/terrain"; -import * as Utils from "../utils"; - -const spriteFragShader = ` -#ifdef GL_FRAGMENT_PRECISION_HIGH -precision highp float; -#else -precision mediump float; -#endif - -uniform sampler2D uMainSampler[%count%]; - -varying vec2 outTexCoord; -varying float outTexId; -varying float outTintEffect; -varying vec4 outTint; - -uniform float time; -uniform int ignoreTimeTint; -uniform int isOutside; -uniform vec3 dayTint; -uniform vec3 duskTint; -uniform vec3 nightTint; -uniform vec3 terrainColor; -uniform float terrainColorRatio; - -float blendOverlay(float base, float blend) { - return base<0.5?(2.0*base*blend):(1.0-2.0*(1.0-base)*(1.0-blend)); -} - -vec3 blendOverlay(vec3 base, vec3 blend) { - return vec3(blendOverlay(base.r,blend.r),blendOverlay(base.g,blend.g),blendOverlay(base.b,blend.b)); -} - -vec3 blendHardLight(vec3 base, vec3 blend) { - return blendOverlay(blend, base); -} - -float hue2rgb(float f1, float f2, float hue) { - if (hue < 0.0) - hue += 1.0; - else if (hue > 1.0) - hue -= 1.0; - float res; - if ((6.0 * hue) < 1.0) - res = f1 + (f2 - f1) * 6.0 * hue; - else if ((2.0 * hue) < 1.0) - res = f2; - else if ((3.0 * hue) < 2.0) - res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; - else - res = f1; - return res; -} - -vec3 rgb2hsl(vec3 color) { - vec3 hsl; - - float fmin = min(min(color.r, color.g), color.b); - float fmax = max(max(color.r, color.g), color.b); - float delta = fmax - fmin; - - hsl.z = (fmax + fmin) / 2.0; - - if (delta == 0.0) { - hsl.x = 0.0; - hsl.y = 0.0; - } else { - if (hsl.z < 0.5) - hsl.y = delta / (fmax + fmin); - else - hsl.y = delta / (2.0 - fmax - fmin); - - float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta; - float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta; - float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta; - - if (color.r == fmax ) - hsl.x = deltaB - deltaG; - else if (color.g == fmax) - hsl.x = (1.0 / 3.0) + deltaR - deltaB; - else if (color.b == fmax) - hsl.x = (2.0 / 3.0) + deltaG - deltaR; - - if (hsl.x < 0.0) - hsl.x += 1.0; - else if (hsl.x > 1.0) - hsl.x -= 1.0; - } - - return hsl; -} - -vec3 hsl2rgb(vec3 hsl) { - vec3 rgb; - - if (hsl.y == 0.0) - rgb = vec3(hsl.z); - else { - float f2; - - if (hsl.z < 0.5) - f2 = hsl.z * (1.0 + hsl.y); - else - f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z); - - float f1 = 2.0 * hsl.z - f2; - - rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0)); - rgb.g = hue2rgb(f1, f2, hsl.x); - rgb.b = hue2rgb(f1, f2, hsl.x - (1.0/3.0)); - } - - return rgb; -} - -vec3 blendHue(vec3 base, vec3 blend) { - vec3 baseHSL = rgb2hsl(base); - return hsl2rgb(vec3(rgb2hsl(blend).r, baseHSL.g, baseHSL.b)); -} - -void main() { - vec4 texture; - - %forloop% - - vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a); - - // Multiply texture tint - vec4 color = texture * texel; - - if (outTintEffect == 1.0) { - // Solid color + texture alpha - color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a); - } else if (outTintEffect == 2.0) { - // Solid color, no texture - color = texel; - } - - /* Apply day/night tint */ - if (color.a > 0.0 && ignoreTimeTint == 0) { - vec3 dayNightTint; - - if (time < 0.25) { - dayNightTint = dayTint; - } else if (isOutside == 0 && time < 0.5) { - dayNightTint = mix(dayTint, nightTint, (time - 0.25) / 0.25); - } else if (time < 0.375) { - dayNightTint = mix(dayTint, duskTint, (time - 0.25) / 0.125); - } else if (time < 0.5) { - dayNightTint = mix(duskTint, nightTint, (time - 0.375) / 0.125); - } else if (time < 0.75) { - dayNightTint = nightTint; - } else if (isOutside == 0) { - dayNightTint = mix(nightTint, dayTint, (time - 0.75) / 0.25); - } else if (time < 0.875) { - dayNightTint = mix(nightTint, duskTint, (time - 0.75) / 0.125); - } else { - dayNightTint = mix(duskTint, dayTint, (time - 0.875) / 0.125); - } - - color = vec4(blendHardLight(color.rgb, dayNightTint), color.a); - } - - if (terrainColorRatio > 0.0 && (1.0 - terrainColorRatio) < outTexCoord.y) { - if (color.a > 0.0 && (terrainColor.r > 0.0 || terrainColor.g > 0.0 || terrainColor.b > 0.0)) { - color.rgb = mix(color.rgb, blendHue(color.rgb, terrainColor), 1.0); - } - } - - gl_FragColor = color; -} -`; - -const spriteVertShader = ` -precision mediump float; - -uniform mat4 uProjectionMatrix; -uniform int uRoundPixels; -uniform vec2 uResolution; - -attribute vec2 inPosition; -attribute vec2 inTexCoord; -attribute float inTexId; -attribute float inTintEffect; -attribute vec4 inTint; - -varying vec2 outTexCoord; -varying float outTexId; -varying vec2 outPosition; -varying float outTintEffect; -varying vec4 outTint; - -void main() { - gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0); - if (uRoundPixels == 1) - { - gl_Position.xy = floor(((gl_Position.xy + 1.0) * 0.5 * uResolution) + 0.5) / uResolution * 2.0 - 1.0; - } - outTexCoord = inTexCoord; - outTexId = inTexId; - outPosition = inPosition; - outTint = inTint; - outTintEffect = inTintEffect; -} -`; +import { getCurrentTime } from "#app/utils"; +import fieldSpriteFragShader from "./glsl/fieldSpriteFragShader.frag?raw"; +import spriteVertShader from "./glsl/spriteShader.vert?raw"; export default class FieldSpritePipeline extends Phaser.Renderer.WebGL.Pipelines.MultiPipeline { constructor(game: Phaser.Game, config?: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig) { @@ -212,7 +10,7 @@ export default class FieldSpritePipeline extends Phaser.Renderer.WebGL.Pipelines config || { game: game, name: "field-sprite", - fragShader: spriteFragShader, + fragShader: fieldSpriteFragShader, vertShader: spriteVertShader, }, ); @@ -236,7 +34,7 @@ export default class FieldSpritePipeline extends Phaser.Renderer.WebGL.Pipelines const time = globalScene.currentBattle?.waveIndex ? ((globalScene.currentBattle.waveIndex + globalScene.waveCycleOffset) % 40) / 40 // ((new Date().getSeconds() * 1000 + new Date().getMilliseconds()) % 10000) / 10000 - : Utils.getCurrentTime(); + : getCurrentTime(); this.set1f("time", time); this.set1i("ignoreTimeTint", ignoreTimeTint ? 1 : 0); this.set1i("isOutside", globalScene.arena.isOutside() ? 1 : 0); diff --git a/src/pipelines/glsl/fieldSpriteFragShader.frag b/src/pipelines/glsl/fieldSpriteFragShader.frag new file mode 100644 index 00000000000..e79dea86fe9 --- /dev/null +++ b/src/pipelines/glsl/fieldSpriteFragShader.frag @@ -0,0 +1,168 @@ +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif + +uniform sampler2D uMainSampler[%count%]; + +varying vec2 outTexCoord; +varying float outTexId; +varying float outTintEffect; +varying vec4 outTint; + +uniform float time; +uniform int ignoreTimeTint; +uniform int isOutside; +uniform vec3 dayTint; +uniform vec3 duskTint; +uniform vec3 nightTint; +uniform vec3 terrainColor; +uniform float terrainColorRatio; + +float blendOverlay(float base, float blend) { + return base<0.5?(2.0*base*blend):(1.0-2.0*(1.0-base)*(1.0-blend)); +} + +vec3 blendOverlay(vec3 base, vec3 blend) { + return vec3(blendOverlay(base.r,blend.r),blendOverlay(base.g,blend.g),blendOverlay(base.b,blend.b)); +} + +vec3 blendHardLight(vec3 base, vec3 blend) { + return blendOverlay(blend, base); +} + +float hue2rgb(float f1, float f2, float hue) { + if (hue < 0.0) + hue += 1.0; + else if (hue > 1.0) + hue -= 1.0; + float res; + if ((6.0 * hue) < 1.0) + res = f1 + (f2 - f1) * 6.0 * hue; + else if ((2.0 * hue) < 1.0) + res = f2; + else if ((3.0 * hue) < 2.0) + res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; + else + res = f1; + return res; +} + +vec3 rgb2hsl(vec3 color) { + vec3 hsl; + + float fmin = min(min(color.r, color.g), color.b); + float fmax = max(max(color.r, color.g), color.b); + float delta = fmax - fmin; + + hsl.z = (fmax + fmin) / 2.0; + + if (delta == 0.0) { + hsl.x = 0.0; + hsl.y = 0.0; + } else { + if (hsl.z < 0.5) + hsl.y = delta / (fmax + fmin); + else + hsl.y = delta / (2.0 - fmax - fmin); + + float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta; + float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta; + float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta; + + if (color.r == fmax ) + hsl.x = deltaB - deltaG; + else if (color.g == fmax) + hsl.x = (1.0 / 3.0) + deltaR - deltaB; + else if (color.b == fmax) + hsl.x = (2.0 / 3.0) + deltaG - deltaR; + + if (hsl.x < 0.0) + hsl.x += 1.0; + else if (hsl.x > 1.0) + hsl.x -= 1.0; + } + + return hsl; +} + +vec3 hsl2rgb(vec3 hsl) { + vec3 rgb; + + if (hsl.y == 0.0) + rgb = vec3(hsl.z); + else { + float f2; + + if (hsl.z < 0.5) + f2 = hsl.z * (1.0 + hsl.y); + else + f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z); + + float f1 = 2.0 * hsl.z - f2; + + rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0)); + rgb.g = hue2rgb(f1, f2, hsl.x); + rgb.b = hue2rgb(f1, f2, hsl.x - (1.0/3.0)); + } + + return rgb; +} + +vec3 blendHue(vec3 base, vec3 blend) { + vec3 baseHSL = rgb2hsl(base); + return hsl2rgb(vec3(rgb2hsl(blend).r, baseHSL.g, baseHSL.b)); +} + +void main() { + vec4 texture; + + %forloop% + + vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a); + + // Multiply texture tint + vec4 color = texture * texel; + + if (outTintEffect == 1.0) { + // Solid color + texture alpha + color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a); + } else if (outTintEffect == 2.0) { + // Solid color, no texture + color = texel; + } + + /* Apply day/night tint */ + if (color.a > 0.0 && ignoreTimeTint == 0) { + vec3 dayNightTint; + + if (time < 0.25) { + dayNightTint = dayTint; + } else if (isOutside == 0 && time < 0.5) { + dayNightTint = mix(dayTint, nightTint, (time - 0.25) / 0.25); + } else if (time < 0.375) { + dayNightTint = mix(dayTint, duskTint, (time - 0.25) / 0.125); + } else if (time < 0.5) { + dayNightTint = mix(duskTint, nightTint, (time - 0.375) / 0.125); + } else if (time < 0.75) { + dayNightTint = nightTint; + } else if (isOutside == 0) { + dayNightTint = mix(nightTint, dayTint, (time - 0.75) / 0.25); + } else if (time < 0.875) { + dayNightTint = mix(nightTint, duskTint, (time - 0.75) / 0.125); + } else { + dayNightTint = mix(duskTint, dayTint, (time - 0.875) / 0.125); + } + + color = vec4(blendHardLight(color.rgb, dayNightTint), color.a); + } + + if (terrainColorRatio > 0.0 && (1.0 - terrainColorRatio) < outTexCoord.y) { + if (color.a > 0.0 && (terrainColor.r > 0.0 || terrainColor.g > 0.0 || terrainColor.b > 0.0)) { + color.rgb = mix(color.rgb, blendHue(color.rgb, terrainColor), 1.0); + } + } + + gl_FragColor = color; +} \ No newline at end of file diff --git a/src/pipelines/glsl/invert.frag b/src/pipelines/glsl/invert.frag new file mode 100644 index 00000000000..24d9ee83a55 --- /dev/null +++ b/src/pipelines/glsl/invert.frag @@ -0,0 +1,10 @@ +precision mediump float; + +uniform sampler2D uMainSampler; + +varying vec2 outTexCoord; + +void main() +{ + gl_FragColor = 1.0 - texture2D(uMainSampler, outTexCoord); +} \ No newline at end of file diff --git a/src/pipelines/glsl/spriteFragShader.frag b/src/pipelines/glsl/spriteFragShader.frag new file mode 100644 index 00000000000..3765e595b70 --- /dev/null +++ b/src/pipelines/glsl/spriteFragShader.frag @@ -0,0 +1,279 @@ +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif + +uniform sampler2D uMainSampler[%count%]; + +varying vec2 outTexCoord; +varying float outTexId; +varying vec2 outPosition; +varying float outTintEffect; +varying vec4 outTint; + +uniform float time; +uniform int ignoreTimeTint; +uniform int isOutside; +uniform vec3 dayTint; +uniform vec3 duskTint; +uniform vec3 nightTint; +uniform float teraTime; +uniform vec3 teraColor; +uniform int hasShadow; +uniform int yCenter; +uniform float fieldScale; +uniform float vCutoff; +uniform vec2 relPosition; +uniform vec2 texFrameUv; +uniform vec2 size; +uniform vec2 texSize; +uniform float yOffset; +uniform float yShadowOffset; +uniform vec4 tone; +uniform ivec4 baseVariantColors[32]; +uniform vec4 variantColors[32]; +uniform ivec4 spriteColors[32]; +uniform ivec4 fusionSpriteColors[32]; + +const vec3 lumaF = vec3(.299, .587, .114); + +float blendOverlay(float base, float blend) { + return base<0.5?(2.0*base*blend):(1.0-2.0*(1.0-base)*(1.0-blend)); +} + +vec3 blendOverlay(vec3 base, vec3 blend) { + return vec3(blendOverlay(base.r,blend.r),blendOverlay(base.g,blend.g),blendOverlay(base.b,blend.b)); +} + +vec3 blendHardLight(vec3 base, vec3 blend) { + return blendOverlay(blend, base); +} + +float hue2rgb(float f1, float f2, float hue) { + if (hue < 0.0) + hue += 1.0; + else if (hue > 1.0) + hue -= 1.0; + float res; + if ((6.0 * hue) < 1.0) + res = f1 + (f2 - f1) * 6.0 * hue; + else if ((2.0 * hue) < 1.0) + res = f2; + else if ((3.0 * hue) < 2.0) + res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; + else + res = f1; + return res; +} + +vec3 rgb2hsl(vec3 color) { + vec3 hsl; + + float fmin = min(min(color.r, color.g), color.b); + float fmax = max(max(color.r, color.g), color.b); + float delta = fmax - fmin; + + hsl.z = (fmax + fmin) / 2.0; + + if (delta == 0.0) { + hsl.x = 0.0; + hsl.y = 0.0; + } else { + if (hsl.z < 0.5) + hsl.y = delta / (fmax + fmin); + else + hsl.y = delta / (2.0 - fmax - fmin); + + float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta; + float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta; + float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta; + + if (color.r == fmax ) + hsl.x = deltaB - deltaG; + else if (color.g == fmax) + hsl.x = (1.0 / 3.0) + deltaR - deltaB; + else if (color.b == fmax) + hsl.x = (2.0 / 3.0) + deltaG - deltaR; + + if (hsl.x < 0.0) + hsl.x += 1.0; + else if (hsl.x > 1.0) + hsl.x -= 1.0; + } + + return hsl; +} + +vec3 hsl2rgb(vec3 hsl) { + vec3 rgb; + + if (hsl.y == 0.0) + rgb = vec3(hsl.z); + else { + float f2; + + if (hsl.z < 0.5) + f2 = hsl.z * (1.0 + hsl.y); + else + f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z); + + float f1 = 2.0 * hsl.z - f2; + + rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0)); + rgb.g = hue2rgb(f1, f2, hsl.x); + rgb.b= hue2rgb(f1, f2, hsl.x - (1.0/3.0)); + } + + return rgb; +} + +vec3 blendHue(vec3 base, vec3 blend) { + vec3 baseHSL = rgb2hsl(base); + return hsl2rgb(vec3(rgb2hsl(blend).r, baseHSL.g, baseHSL.b)); +} + +vec3 rgb2hsv(vec3 c) { + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + +vec3 hsv2rgb(vec3 c) { + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + +void main() { + vec4 texture = texture2D(uMainSampler[0], outTexCoord); + + ivec4 colorInt = ivec4(texture*255.0); + + for (int i = 0; i < 32; i++) { + if (baseVariantColors[i][3] == 0) + break; + // abs value is broken in this version of gles with highp + ivec3 diffs = ivec3( + (colorInt.r > baseVariantColors[i].r) ? colorInt.r - baseVariantColors[i].r : baseVariantColors[i].r - colorInt.r, + (colorInt.g > baseVariantColors[i].g) ? colorInt.g - baseVariantColors[i].g : baseVariantColors[i].g - colorInt.g, + (colorInt.b > baseVariantColors[i].b) ? colorInt.b - baseVariantColors[i].b : baseVariantColors[i].b - colorInt.b + ); + // Set color threshold to be within 3 points for each channel + bvec3 threshold = lessThan(diffs, ivec3(3)); + + if (texture.a > 0.0 && all(threshold)) { + texture.rgb = variantColors[i].rgb; + break; + } + } + + for (int i = 0; i < 32; i++) { + if (spriteColors[i][3] == 0) + break; + if (texture.a > 0.0 && colorInt.r == spriteColors[i].r && colorInt.g == spriteColors[i].g && colorInt.b == spriteColors[i].b) { + vec3 fusionColor = vec3(float(fusionSpriteColors[i].r) / 255.0, float(fusionSpriteColors[i].g) / 255.0, float(fusionSpriteColors[i].b) / 255.0); + vec3 bg = vec3(spriteColors[i].rgb) / 255.0; + float gray = (bg.r + bg.g + bg.b) / 3.0; + bg = vec3(gray, gray, gray); + vec3 fg = fusionColor; + texture.rgb = mix(1.0 - 2.0 * (1.0 - bg) * (1.0 - fg), 2.0 * bg * fg, step(bg, vec3(0.5))); + break; + } + } + + vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a); + + // Multiply texture tint + vec4 color = texture * texel; + + if (color.a > 0.0 && teraColor.r > 0.0 && teraColor.g > 0.0 && teraColor.b > 0.0) { + vec2 relUv = vec2((outTexCoord.x - texFrameUv.x) / (size.x / texSize.x), (outTexCoord.y - texFrameUv.y) / (size.y / texSize.y)); + vec2 teraTexCoord = vec2(relUv.x * (size.x / 200.0), relUv.y * (size.y / 120.0)); + vec4 teraCol = texture2D(uMainSampler[1], teraTexCoord); + float floorValue = 86.0 / 255.0; + vec3 teraPatternHsv = rgb2hsv(teraCol.rgb); + teraCol.rgb = hsv2rgb(vec3((teraPatternHsv.b - floorValue) * 4.0 + teraTexCoord.x * fieldScale / 2.0 + teraTexCoord.y * fieldScale / 2.0 + teraTime * 255.0, teraPatternHsv.b, teraPatternHsv.b)); + + color.rgb = mix(color.rgb, blendHue(color.rgb, teraColor), 0.625); + teraCol.rgb = mix(teraCol.rgb, teraColor, 0.5); + color.rgb = blendOverlay(color.rgb, teraCol.rgb); + + if (any(lessThan(teraCol.rgb, vec3(1.0)))) { + vec3 teraColHsv = rgb2hsv(teraColor); + color.rgb = mix(color.rgb, teraColor, (1.0 - teraColHsv.g) / 2.0); + } + } + + if (outTintEffect == 1.0) { + // Solid color + texture alpha + color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a); + } else if (outTintEffect == 2.0) { + // Solid color, no texture + color = texel; + } + + /* Apply gray */ + float luma = dot(color.rgb, lumaF); + color.rgb = mix(color.rgb, vec3(luma), tone.w); + + /* Apply tone */ + color.rgb += tone.rgb * (color.a / 255.0); + + /* Apply day/night tint */ + if (color.a > 0.0 && ignoreTimeTint == 0) { + vec3 dayNightTint; + + if (time < 0.25) { + dayNightTint = dayTint; + } else if (isOutside == 0 && time < 0.5) { + dayNightTint = mix(dayTint, nightTint, (time - 0.25) / 0.25); + } else if (time < 0.375) { + dayNightTint = mix(dayTint, duskTint, (time - 0.25) / 0.125); + } else if (time < 0.5) { + dayNightTint = mix(duskTint, nightTint, (time - 0.375) / 0.125); + } else if (time < 0.75) { + dayNightTint = nightTint; + } else if (isOutside == 0) { + dayNightTint = mix(nightTint, dayTint, (time - 0.75) / 0.25); + } else if (time < 0.875) { + dayNightTint = mix(nightTint, duskTint, (time - 0.75) / 0.125); + } else { + dayNightTint = mix(duskTint, dayTint, (time - 0.875) / 0.125); + } + + color.rgb = blendHardLight(color.rgb, dayNightTint); + } + + if (hasShadow == 1) { + float width = size.x - (yOffset / 2.0); + + float spriteX = ((floor(outPosition.x / fieldScale) - relPosition.x) / width) + 0.5; + float spriteY = ((floor(outPosition.y / fieldScale) - relPosition.y - yShadowOffset) / size.y); + + if (yCenter == 1) { + spriteY += 0.5; + } else { + spriteY += 1.0; + } + + bool yOverflow = outTexCoord.y >= vCutoff; + + if ((spriteY >= 0.9 && (color.a == 0.0 || yOverflow))) { + float shadowSpriteY = (spriteY - 0.9) * (1.0 / 0.15); + if (distance(vec2(spriteX, shadowSpriteY), vec2(0.5, 0.5)) < 0.5) { + color = vec4(vec3(0.0, 0.0, 0.0), 0.5); + } else if (yOverflow) { + discard; + } + } else if (yOverflow) { + discard; + } + } + + gl_FragColor = color; +} \ No newline at end of file diff --git a/src/pipelines/glsl/spriteShader.vert b/src/pipelines/glsl/spriteShader.vert new file mode 100644 index 00000000000..33743384b47 --- /dev/null +++ b/src/pipelines/glsl/spriteShader.vert @@ -0,0 +1,32 @@ +precision mediump float; + +uniform mat4 uProjectionMatrix; +uniform int uRoundPixels; +uniform vec2 uResolution; + +attribute vec2 inPosition; +attribute vec2 inTexCoord; +attribute float inTexId; +attribute float inTintEffect; +attribute vec4 inTint; + +varying vec2 outTexCoord; +varying vec2 outtexFrameUv; +varying float outTexId; +varying vec2 outPosition; +varying float outTintEffect; +varying vec4 outTint; + +void main() +{ + gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0); + if (uRoundPixels == 1) + { + gl_Position.xy = floor(((gl_Position.xy + 1.0) * 0.5 * uResolution) + 0.5) / uResolution * 2.0 - 1.0; + } + outTexCoord = inTexCoord; + outTexId = inTexId; + outPosition = inPosition; + outTint = inTint; + outTintEffect = inTintEffect; +} \ No newline at end of file diff --git a/src/pipelines/invert.ts b/src/pipelines/invert.ts index a945d0c95aa..0ebc3ad865f 100644 --- a/src/pipelines/invert.ts +++ b/src/pipelines/invert.ts @@ -1,17 +1,5 @@ import type { Game } from "phaser"; - -const fragShader = ` -precision mediump float; - -uniform sampler2D uMainSampler; - -varying vec2 outTexCoord; - -void main() -{ - gl_FragColor = 1.0 - texture2D(uMainSampler, outTexCoord); -} -`; +import fragShader from "./glsl/invert.frag?raw"; export default class InvertPostFX extends Phaser.Renderer.WebGL.Pipelines.PostFXPipeline { constructor(game: Game) { diff --git a/src/pipelines/sprite.ts b/src/pipelines/sprite.ts index 439e35f711f..d97cae1662b 100644 --- a/src/pipelines/sprite.ts +++ b/src/pipelines/sprite.ts @@ -1,318 +1,12 @@ -import { variantColorCache } from "#app/data/variant"; +import { variantColorCache } from "#app/sprites/variant"; import MysteryEncounterIntroVisuals from "#app/field/mystery-encounter-intro"; import Pokemon from "#app/field/pokemon"; import Trainer from "#app/field/trainer"; import { globalScene } from "#app/global-scene"; -import * as Utils from "#app/utils"; +import { rgbHexToRgba } from "#app/utils"; import FieldSpritePipeline from "./field-sprite"; - -const spriteFragShader = ` -#ifdef GL_FRAGMENT_PRECISION_HIGH -precision highp float; -#else -precision mediump float; -#endif - -uniform sampler2D uMainSampler[%count%]; - -varying vec2 outTexCoord; -varying float outTexId; -varying vec2 outPosition; -varying float outTintEffect; -varying vec4 outTint; - -uniform float time; -uniform int ignoreTimeTint; -uniform int isOutside; -uniform vec3 dayTint; -uniform vec3 duskTint; -uniform vec3 nightTint; -uniform float teraTime; -uniform vec3 teraColor; -uniform int hasShadow; -uniform int yCenter; -uniform float fieldScale; -uniform float vCutoff; -uniform vec2 relPosition; -uniform vec2 texFrameUv; -uniform vec2 size; -uniform vec2 texSize; -uniform float yOffset; -uniform float yShadowOffset; -uniform vec4 tone; -uniform ivec4 baseVariantColors[32]; -uniform vec4 variantColors[32]; -uniform ivec4 spriteColors[32]; -uniform ivec4 fusionSpriteColors[32]; - -const vec3 lumaF = vec3(.299, .587, .114); - -float blendOverlay(float base, float blend) { - return base<0.5?(2.0*base*blend):(1.0-2.0*(1.0-base)*(1.0-blend)); -} - -vec3 blendOverlay(vec3 base, vec3 blend) { - return vec3(blendOverlay(base.r,blend.r),blendOverlay(base.g,blend.g),blendOverlay(base.b,blend.b)); -} - -vec3 blendHardLight(vec3 base, vec3 blend) { - return blendOverlay(blend, base); -} - -float hue2rgb(float f1, float f2, float hue) { - if (hue < 0.0) - hue += 1.0; - else if (hue > 1.0) - hue -= 1.0; - float res; - if ((6.0 * hue) < 1.0) - res = f1 + (f2 - f1) * 6.0 * hue; - else if ((2.0 * hue) < 1.0) - res = f2; - else if ((3.0 * hue) < 2.0) - res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; - else - res = f1; - return res; -} - -vec3 rgb2hsl(vec3 color) { - vec3 hsl; - - float fmin = min(min(color.r, color.g), color.b); - float fmax = max(max(color.r, color.g), color.b); - float delta = fmax - fmin; - - hsl.z = (fmax + fmin) / 2.0; - - if (delta == 0.0) { - hsl.x = 0.0; - hsl.y = 0.0; - } else { - if (hsl.z < 0.5) - hsl.y = delta / (fmax + fmin); - else - hsl.y = delta / (2.0 - fmax - fmin); - - float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta; - float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta; - float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta; - - if (color.r == fmax ) - hsl.x = deltaB - deltaG; - else if (color.g == fmax) - hsl.x = (1.0 / 3.0) + deltaR - deltaB; - else if (color.b == fmax) - hsl.x = (2.0 / 3.0) + deltaG - deltaR; - - if (hsl.x < 0.0) - hsl.x += 1.0; - else if (hsl.x > 1.0) - hsl.x -= 1.0; - } - - return hsl; -} - -vec3 hsl2rgb(vec3 hsl) { - vec3 rgb; - - if (hsl.y == 0.0) - rgb = vec3(hsl.z); - else { - float f2; - - if (hsl.z < 0.5) - f2 = hsl.z * (1.0 + hsl.y); - else - f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z); - - float f1 = 2.0 * hsl.z - f2; - - rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0)); - rgb.g = hue2rgb(f1, f2, hsl.x); - rgb.b= hue2rgb(f1, f2, hsl.x - (1.0/3.0)); - } - - return rgb; -} - -vec3 blendHue(vec3 base, vec3 blend) { - vec3 baseHSL = rgb2hsl(base); - return hsl2rgb(vec3(rgb2hsl(blend).r, baseHSL.g, baseHSL.b)); -} - -vec3 rgb2hsv(vec3 c) { - vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); - vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); - vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); - - float d = q.x - min(q.w, q.y); - float e = 1.0e-10; - return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); -} - -vec3 hsv2rgb(vec3 c) { - vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); - vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); - return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); -} - -void main() { - vec4 texture = texture2D(uMainSampler[0], outTexCoord); - - ivec4 colorInt = ivec4(int(texture.r * 255.0), int(texture.g * 255.0), int(texture.b * 255.0), int(texture.a * 255.0)); - - for (int i = 0; i < 32; i++) { - if (baseVariantColors[i][3] == 0) - break; - if (texture.a > 0.0 && colorInt.r == baseVariantColors[i].r && colorInt.g == baseVariantColors[i].g && colorInt.b == baseVariantColors[i].b) { - texture.rgb = variantColors[i].rgb; - break; - } - } - - for (int i = 0; i < 32; i++) { - if (spriteColors[i][3] == 0) - break; - if (texture.a > 0.0 && colorInt.r == spriteColors[i].r && colorInt.g == spriteColors[i].g && colorInt.b == spriteColors[i].b) { - vec3 fusionColor = vec3(float(fusionSpriteColors[i].r) / 255.0, float(fusionSpriteColors[i].g) / 255.0, float(fusionSpriteColors[i].b) / 255.0); - vec3 bg = vec3(float(spriteColors[i].r) / 255.0, float(spriteColors[i].g) / 255.0, float(spriteColors[i].b) / 255.0); - float gray = (bg.r + bg.g + bg.b) / 3.0; - bg = vec3(gray, gray, gray); - vec3 fg = fusionColor; - texture.rgb = mix(1.0 - 2.0 * (1.0 - bg) * (1.0 - fg), 2.0 * bg * fg, step(bg, vec3(0.5))); - break; - } - } - - vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a); - - // Multiply texture tint - vec4 color = texture * texel; - - if (color.a > 0.0 && teraColor.r > 0.0 && teraColor.g > 0.0 && teraColor.b > 0.0) { - vec2 relUv = vec2((outTexCoord.x - texFrameUv.x) / (size.x / texSize.x), (outTexCoord.y - texFrameUv.y) / (size.y / texSize.y)); - vec2 teraTexCoord = vec2(relUv.x * (size.x / 200.0), relUv.y * (size.y / 120.0)); - vec4 teraCol = texture2D(uMainSampler[1], teraTexCoord); - float floorValue = 86.0 / 255.0; - vec3 teraPatternHsv = rgb2hsv(teraCol.rgb); - teraCol.rgb = hsv2rgb(vec3((teraPatternHsv.b - floorValue) * 4.0 + teraTexCoord.x * fieldScale / 2.0 + teraTexCoord.y * fieldScale / 2.0 + teraTime * 255.0, teraPatternHsv.b, teraPatternHsv.b)); - - color.rgb = mix(color.rgb, blendHue(color.rgb, teraColor), 0.625); - teraCol.rgb = mix(teraCol.rgb, teraColor, 0.5); - color.rgb = blendOverlay(color.rgb, teraCol.rgb); - - if (teraColor.r < 1.0 || teraColor.g < 1.0 || teraColor.b < 1.0) { - vec3 teraColHsv = rgb2hsv(teraColor); - color.rgb = mix(color.rgb, teraColor, (1.0 - teraColHsv.g) / 2.0); - } - } - - if (outTintEffect == 1.0) { - // Solid color + texture alpha - color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a); - } else if (outTintEffect == 2.0) { - // Solid color, no texture - color = texel; - } - - /* Apply gray */ - float luma = dot(color.rgb, lumaF); - color.rgb = mix(color.rgb, vec3(luma), tone.w); - - /* Apply tone */ - color.rgb += tone.rgb * (color.a / 255.0); - - /* Apply day/night tint */ - if (color.a > 0.0 && ignoreTimeTint == 0) { - vec3 dayNightTint; - - if (time < 0.25) { - dayNightTint = dayTint; - } else if (isOutside == 0 && time < 0.5) { - dayNightTint = mix(dayTint, nightTint, (time - 0.25) / 0.25); - } else if (time < 0.375) { - dayNightTint = mix(dayTint, duskTint, (time - 0.25) / 0.125); - } else if (time < 0.5) { - dayNightTint = mix(duskTint, nightTint, (time - 0.375) / 0.125); - } else if (time < 0.75) { - dayNightTint = nightTint; - } else if (isOutside == 0) { - dayNightTint = mix(nightTint, dayTint, (time - 0.75) / 0.25); - } else if (time < 0.875) { - dayNightTint = mix(nightTint, duskTint, (time - 0.75) / 0.125); - } else { - dayNightTint = mix(duskTint, dayTint, (time - 0.875) / 0.125); - } - - color.rgb = blendHardLight(color.rgb, dayNightTint); - } - - if (hasShadow == 1) { - float width = size.x - (yOffset / 2.0); - - float spriteX = ((floor(outPosition.x / fieldScale) - relPosition.x) / width) + 0.5; - float spriteY = ((floor(outPosition.y / fieldScale) - relPosition.y - yShadowOffset) / size.y); - - if (yCenter == 1) { - spriteY += 0.5; - } else { - spriteY += 1.0; - } - - bool yOverflow = outTexCoord.y >= vCutoff; - - if ((spriteY >= 0.9 && (color.a == 0.0 || yOverflow))) { - float shadowSpriteY = (spriteY - 0.9) * (1.0 / 0.15); - if (distance(vec2(spriteX, shadowSpriteY), vec2(0.5, 0.5)) < 0.5) { - color = vec4(vec3(0.0, 0.0, 0.0), 0.5); - } else if (yOverflow) { - discard; - } - } else if (yOverflow) { - discard; - } - } - - gl_FragColor = color; -} -`; - -const spriteVertShader = ` -precision mediump float; - -uniform mat4 uProjectionMatrix; -uniform int uRoundPixels; -uniform vec2 uResolution; - -attribute vec2 inPosition; -attribute vec2 inTexCoord; -attribute float inTexId; -attribute float inTintEffect; -attribute vec4 inTint; - -varying vec2 outTexCoord; -varying vec2 outtexFrameUv; -varying float outTexId; -varying vec2 outPosition; -varying float outTintEffect; -varying vec4 outTint; - -void main() -{ - gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0); - if (uRoundPixels == 1) - { - gl_Position.xy = floor(((gl_Position.xy + 1.0) * 0.5 * uResolution) + 0.5) / uResolution * 2.0 - 1.0; - } - outTexCoord = inTexCoord; - outTexId = inTexId; - outPosition = inPosition; - outTint = inTint; - outTintEffect = inTintEffect; -} -`; +import spriteFragShader from "./glsl/spriteFragShader.frag?raw"; +import spriteVertShader from "./glsl/spriteShader.vert?raw"; export default class SpritePipeline extends FieldSpritePipeline { private _tone: number[]; @@ -450,8 +144,8 @@ export default class SpritePipeline extends FieldSpritePipeline { const baseColors = Object.keys(variantColors[variant]); for (let c = 0; c < 32; c++) { if (c < baseColors.length) { - const baseColor = Array.from(Object.values(Utils.rgbHexToRgba(baseColors[c]))); - const variantColor = Array.from(Object.values(Utils.rgbHexToRgba(variantColors[variant][baseColors[c]]))); + const baseColor = Array.from(Object.values(rgbHexToRgba(baseColors[c]))); + const variantColor = Array.from(Object.values(rgbHexToRgba(variantColors[variant][baseColors[c]]))); flatBaseColors.splice(flatBaseColors.length, 0, ...baseColor); flatVariantColors.splice(flatVariantColors.length, 0, ...variantColor.map(c => c / 255.0)); } else { diff --git a/src/sprites/pokemon-asset-loader.ts b/src/sprites/pokemon-asset-loader.ts new file mode 100644 index 00000000000..4ce88f4f1fb --- /dev/null +++ b/src/sprites/pokemon-asset-loader.ts @@ -0,0 +1,11 @@ +import type { Moves } from "#enums/moves"; +import { initMoveAnim, loadMoveAnimAssets } from "#app/data/battle-anims"; + +/** + * Asynchronously load the animations and assets for the provided moves. + * @param moveIds - An array of move IDs to load assets for. + */ +export async function loadMoveAnimations(moveIds: Moves[]): Promise { + await Promise.allSettled(moveIds.map(m => initMoveAnim(m))); + await loadMoveAnimAssets(moveIds); +} diff --git a/src/sprites/pokemon-sprite.ts b/src/sprites/pokemon-sprite.ts new file mode 100644 index 00000000000..66432f5a4ea --- /dev/null +++ b/src/sprites/pokemon-sprite.ts @@ -0,0 +1,79 @@ +import { globalScene } from "#app/global-scene"; +import { variantColorCache, variantData } from "#app/sprites/variant"; +import { Gender } from "#app/data/gender"; +import { hasExpSprite } from "./sprite-utils"; +import type { Variant, VariantSet } from "#app/sprites/variant"; +import type Pokemon from "#app/field/pokemon"; +import type BattleScene from "#app/battle-scene"; + +// Regex patterns + +/** Regex matching double underscores */ +const DUNDER_REGEX = /\_{2}/g; + +/** + * Calculate the sprite ID from a pokemon form. + */ +export function getSpriteId(pokemon: Pokemon, ignoreOverride?: boolean): string { + return pokemon + .getSpeciesForm(ignoreOverride) + .getSpriteId( + pokemon.getGender(ignoreOverride) === Gender.FEMALE, + pokemon.formIndex, + pokemon.shiny, + pokemon.variant, + ); +} + +export function getBattleSpriteId(pokemon: Pokemon, back?: boolean, ignoreOverride = false): string { + if (back === undefined) { + back = pokemon.isPlayer(); + } + return pokemon + .getSpeciesForm(ignoreOverride) + .getSpriteId( + pokemon.getGender(ignoreOverride) === Gender.FEMALE, + pokemon.formIndex, + pokemon.shiny, + pokemon.variant, + back, + ); +} + +/** Compute the path to the sprite atlas by converting double underscores to path components (/) + */ +export function getSpriteAtlasPath(pokemon: Pokemon, ignoreOverride = false): string { + const spriteId = getSpriteId(pokemon, ignoreOverride).replace(DUNDER_REGEX, "/"); + return `${/_[1-3]$/.test(spriteId) ? "variant/" : ""}${spriteId}`; +} + +/** + * Load the variant assets for the given sprite and store it in {@linkcode variantColorCache}. + * @param spriteKey - The key of the sprite to load + * @param fileRoot - The root path of the sprite file + * @param variant - The variant to load + * @param scene - The scene to load the assets in (defaults to the global scene) + */ +export async function loadPokemonVariantAssets( + spriteKey: string, + fileRoot: string, + variant: Variant, + scene: BattleScene = globalScene, +): Promise { + if (variantColorCache.hasOwnProperty(spriteKey)) { + return; + } + const useExpSprite = scene.experimentalSprites && hasExpSprite(spriteKey); + if (useExpSprite) { + fileRoot = `exp/${fileRoot}`; + } + let variantConfig = variantData; + fileRoot.split("/").map(p => (variantConfig ? (variantConfig = variantConfig[p]) : null)); + const variantSet = variantConfig as VariantSet; + if (!variantConfig || variantSet[variant] !== 1) { + return; + } + variantColorCache[spriteKey] = await scene + .cachedFetch(`./images/pokemon/variant/${fileRoot}.json`) + .then(res => res.json()); +} diff --git a/src/sprites/sprite-keys.ts b/src/sprites/sprite-keys.ts new file mode 100644 index 00000000000..f023df089f6 --- /dev/null +++ b/src/sprites/sprite-keys.ts @@ -0,0 +1 @@ +export const expSpriteKeys: Set = new Set(); diff --git a/src/sprites/sprite-utils.ts b/src/sprites/sprite-utils.ts new file mode 100644 index 00000000000..8a352de3d55 --- /dev/null +++ b/src/sprites/sprite-utils.ts @@ -0,0 +1,28 @@ +import { expSpriteKeys } from "#app/sprites/sprite-keys"; + +const expKeyRegex = /^pkmn__?(back__)?(shiny__)?(female__)?(\d+)(\-.*?)?(?:_[1-3])?$/; + +export function hasExpSprite(key: string): boolean { + const keyMatch = expKeyRegex.exec(key); + if (!keyMatch) { + return false; + } + + let k = keyMatch[4]!; + if (keyMatch[2]) { + k += "s"; + } + if (keyMatch[1]) { + k += "b"; + } + if (keyMatch[3]) { + k += "f"; + } + if (keyMatch[5]) { + k += keyMatch[5]; + } + if (!expSpriteKeys.has(k)) { + return false; + } + return true; +} diff --git a/src/sprites/variant.ts b/src/sprites/variant.ts new file mode 100644 index 00000000000..7552f63b778 --- /dev/null +++ b/src/sprites/variant.ts @@ -0,0 +1,145 @@ +import { VariantTier } from "#app/enums/variant-tier"; +import { hasExpSprite } from "#app/sprites/sprite-utils"; +import { globalScene } from "#app/global-scene"; +import type Pokemon from "#app/field/pokemon"; +import { isNullOrUndefined } from "#app/utils"; + +export type Variant = 0 | 1 | 2; + +export type VariantSet = [Variant, Variant, Variant]; + +export const variantData: any = {}; + +/** Caches variant colors that have been generated */ +export const variantColorCache = {}; + +export function getVariantTint(variant: Variant): number { + switch (variant) { + case 0: + return 0xf8c020; + case 1: + return 0x20f8f0; + case 2: + return 0xe81048; + } +} + +export function getVariantIcon(variant: Variant): number { + switch (variant) { + case 0: + return VariantTier.STANDARD; + case 1: + return VariantTier.RARE; + case 2: + return VariantTier.EPIC; + } +} + +/** Delete all of the keys in variantData */ +export function clearVariantData(): void { + for (const key in variantData) { + delete variantData[key]; + } +} + +/** Update the variant data to use experiment sprite files for variants that have experimental sprites. */ +export async function mergeExperimentalData(mainData: any, expData: any): Promise { + if (!expData) { + return; + } + + for (const key of Object.keys(expData)) { + if (typeof expData[key] === "object" && !Array.isArray(expData[key])) { + // If the value is an object, recursively merge. + if (!mainData[key]) { + mainData[key] = {}; + } + mergeExperimentalData(mainData[key], expData[key]); + } else { + // Otherwise, replace the value + mainData[key] = expData[key]; + } + } +} + +/** + * Populate the variant color cache with the variant colors for this pokemon. + * The global scene must be initialized before this function is called. + */ +export async function populateVariantColors( + pokemon: Pokemon, + isBackSprite = false, + ignoreOverride = true, +): Promise { + const battleSpritePath = pokemon + .getBattleSpriteAtlasPath(isBackSprite, ignoreOverride) + .replace("variant/", "") + .replace(/_[1-3]$/, ""); + let config = variantData; + const useExpSprite = + globalScene.experimentalSprites && hasExpSprite(pokemon.getBattleSpriteKey(isBackSprite, ignoreOverride)); + battleSpritePath.split("/").map(p => (config ? (config = config[p]) : null)); + const variantSet: VariantSet = config as VariantSet; + if (!variantSet || variantSet[pokemon.variant] !== 1) { + return; + } + const cacheKey = pokemon.getBattleSpriteKey(isBackSprite); + if (!variantColorCache.hasOwnProperty(cacheKey)) { + await populateVariantColorCache(cacheKey, useExpSprite, battleSpritePath); + } +} + +/** + * Gracefully handle errors loading a variant sprite. Log if it fails and attempt to fall back on + * non-experimental sprites before giving up. + * + * @param cacheKey - The cache key for the variant color sprite + * @param attemptedSpritePath - The sprite path that failed to load + * @param useExpSprite - Was the attempted sprite experimental + * @param battleSpritePath - The filename of the sprite + * @param optionalParams - Any additional params to log + */ +async function fallbackVariantColor( + cacheKey: string, + attemptedSpritePath: string, + useExpSprite: boolean, + battleSpritePath: string, + ...optionalParams: any[] +): Promise { + console.warn(`Could not load ${attemptedSpritePath}!`, ...optionalParams); + if (useExpSprite) { + await populateVariantColorCache(cacheKey, false, battleSpritePath); + } +} + +/** + * Fetch a variant color sprite from the key and store it in the variant color cache. + * + * @param cacheKey - The cache key for the variant color sprite + * @param useExpSprite - Should the experimental sprite be used + * @param battleSpritePath - The filename of the sprite + */ +export async function populateVariantColorCache( + cacheKey: string, + useExpSprite: boolean, + battleSpritePath: string, +): Promise { + const spritePath = `./images/pokemon/variant/${useExpSprite ? "exp/" : ""}${battleSpritePath}.json`; + return globalScene + .cachedFetch(spritePath) + .then(res => { + // Prevent the JSON from processing if it failed to load + if (!res.ok) { + return fallbackVariantColor(cacheKey, res.url, useExpSprite, battleSpritePath, res.status, res.statusText); + } + return res.json(); + }) + .catch(error => { + return fallbackVariantColor(cacheKey, spritePath, useExpSprite, battleSpritePath, error); + }) + .then(c => { + if (!isNullOrUndefined(c)) { + variantColorCache[cacheKey] = c; + } + }); +} diff --git a/src/system/achv.ts b/src/system/achv.ts index bd8595b2f94..62e69e6fbfe 100644 --- a/src/system/achv.ts +++ b/src/system/achv.ts @@ -2,7 +2,7 @@ import type { Modifier } from "typescript"; import { TurnHeldItemTransferModifier } from "../modifier/modifier"; import { pokemonEvolutions } from "#app/data/balance/pokemon-evolutions"; import i18next from "i18next"; -import * as Utils from "../utils"; +import { NumberHolder } from "#app/utils"; import { PlayerGender } from "#enums/player-gender"; import type { Challenge } from "#app/data/challenge"; import { @@ -138,7 +138,7 @@ export class DamageAchv extends Achv { "", iconImage, score, - (args: any[]) => (args[0] instanceof Utils.NumberHolder ? args[0].value : args[0]) >= this.damageAmount, + (args: any[]) => (args[0] instanceof NumberHolder ? args[0].value : args[0]) >= this.damageAmount, ); this.damageAmount = damageAmount; } @@ -154,7 +154,7 @@ export class HealAchv extends Achv { "", iconImage, score, - (args: any[]) => (args[0] instanceof Utils.NumberHolder ? args[0].value : args[0]) >= this.healAmount, + (args: any[]) => (args[0] instanceof NumberHolder ? args[0].value : args[0]) >= this.healAmount, ); this.healAmount = healAmount; } @@ -170,7 +170,7 @@ export class LevelAchv extends Achv { "", iconImage, score, - (args: any[]) => (args[0] instanceof Utils.NumberHolder ? args[0].value : args[0]) >= this.level, + (args: any[]) => (args[0] instanceof NumberHolder ? args[0].value : args[0]) >= this.level, ); this.level = level; } diff --git a/src/system/game-data.ts b/src/system/game-data.ts index 391ceec503d..53146301666 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -8,7 +8,7 @@ import { pokemonPrevolutions } from "#app/data/balance/pokemon-evolutions"; import type PokemonSpecies from "#app/data/pokemon-species"; import { allSpecies, getPokemonSpecies } from "#app/data/pokemon-species"; import { speciesStarterCosts } from "#app/data/balance/starters"; -import * as Utils from "#app/utils"; +import { randInt, getEnumKeys, isLocal, executeIf, fixedInt, randSeedItem, NumberHolder } from "#app/utils"; import Overrides from "#app/overrides"; import PokemonData from "#app/system/pokemon-data"; import PersistentModifierData from "#app/system/modifier-data"; @@ -32,11 +32,12 @@ import { Tutorial } from "#app/tutorial"; import { speciesEggMoves } from "#app/data/balance/egg-moves"; import { allMoves } from "#app/data/moves/move"; import { TrainerVariant } from "#app/field/trainer"; -import type { Variant } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; import { setSettingGamepad, SettingGamepad, settingGamepadDefaults } from "#app/system/settings/settings-gamepad"; import type { SettingKeyboard } from "#app/system/settings/settings-keyboard"; import { setSettingKeyboard } from "#app/system/settings/settings-keyboard"; import { TagAddedEvent, TerrainChangedEvent, WeatherChangedEvent } from "#app/events/arena"; +// biome-ignore lint/style/noNamespaceImport: Something weird is going on here and I don't want to touch it import * as Modifier from "#app/modifier/modifier"; import { StatusEffect } from "#enums/status-effect"; import ChallengeData from "#app/system/challenge-data"; @@ -360,8 +361,8 @@ export class GameData { this.loadSettings(); this.loadGamepadSettings(); this.loadMappingConfigs(); - this.trainerId = Utils.randInt(65536); - this.secretId = Utils.randInt(65536); + this.trainerId = randInt(65536); + this.secretId = randInt(65536); this.starterData = {}; this.gameStats = new GameStats(); this.runHistory = {}; @@ -589,7 +590,7 @@ export class GameData { } if (systemData.voucherCounts) { - Utils.getEnumKeys(VoucherType).forEach(key => { + getEnumKeys(VoucherType).forEach(key => { const index = VoucherType[key]; this.voucherCounts[index] = systemData.voucherCounts[index] || 0; }); @@ -617,7 +618,7 @@ export class GameData { * At the moment, only retrievable from locale cache */ async getRunHistoryData(): Promise { - if (!Utils.isLocal) { + if (!isLocal) { /** * Networking Code DO NOT DELETE! * Note: Might have to be migrated to `pokerogue-api.ts` @@ -1035,6 +1036,7 @@ export class GameData { } getSession(slotId: number): Promise { + // biome-ignore lint/suspicious/noAsyncPromiseExecutor: return new Promise(async (resolve, reject) => { if (slotId < 0) { return resolve(null); @@ -1075,6 +1077,7 @@ export class GameData { } loadSession(slotId: number, sessionData?: SessionSaveData): Promise { + // biome-ignore lint/suspicious/noAsyncPromiseExecutor: return new Promise(async (resolve, reject) => { try { const initSessionFromData = async (sessionData: SessionSaveData) => { @@ -1406,7 +1409,7 @@ export class GameData { saveAll(skipVerification = false, sync = false, useCachedSession = false, useCachedSystem = false): Promise { return new Promise(resolve => { - Utils.executeIf(!skipVerification, updateUserInfo).then(success => { + executeIf(!skipVerification, updateUserInfo).then(success => { if (success !== null && !success) { return resolve(false); } @@ -1423,12 +1426,11 @@ export class GameData { ), ) // TODO: is this bang correct? : this.getSessionSaveData(); - const maxIntAttrValue = 0x80000000; const systemData = useCachedSystem ? this.parseSystemData(decrypt(localStorage.getItem(`data_${loggedInUser?.username}`)!, bypassLogin)) : this.getSystemSaveData(); // TODO: is this bang correct? - + const request = { system: systemData, session: sessionData, @@ -1445,7 +1447,6 @@ export class GameData { bypassLogin, ), ); - localStorage.setItem( `sessionData${globalScene.sessionSlotId ? globalScene.sessionSlotId : ""}_${loggedInUser?.username}`, encrypt(JSON.stringify(sessionData), bypassLogin), @@ -1586,7 +1587,7 @@ export class GameData { } const displayError = (error: string) => - globalScene.ui.showText(error, null, () => globalScene.ui.showText("", 0), Utils.fixedInt(1500)); + globalScene.ui.showText(error, null, () => globalScene.ui.showText("", 0), fixedInt(1500)); dataName = dataName!; // tell TS compiler that dataName is defined! if (!valid) { @@ -1594,7 +1595,7 @@ export class GameData { `Your ${dataName} data could not be loaded. It may be corrupted.`, null, () => globalScene.ui.showText("", 0), - Utils.fixedInt(1500), + fixedInt(1500), ); } @@ -1687,7 +1688,7 @@ export class GameData { () => { const neutralNatures = [Nature.HARDY, Nature.DOCILE, Nature.SERIOUS, Nature.BASHFUL, Nature.QUIRKY]; for (let s = 0; s < defaultStarterSpecies.length; s++) { - defaultStarterNatures.push(Utils.randSeedItem(neutralNatures)); + defaultStarterNatures.push(randSeedItem(neutralNatures)); } }, 0, @@ -2188,7 +2189,7 @@ export class GameData { value = decrementValue(value); } - const cost = new Utils.NumberHolder(value); + const cost = new NumberHolder(value); applyChallenges(ChallengeType.STARTER_COST, speciesId, cost); return cost.value; @@ -2216,7 +2217,7 @@ export class GameData { entry.hatchedCount = 0; } if (!entry.hasOwnProperty("natureAttr") || (entry.caughtAttr && !entry.natureAttr)) { - entry.natureAttr = this.defaultDexData?.[k].natureAttr || 1 << Utils.randInt(25, 1); + entry.natureAttr = this.defaultDexData?.[k].natureAttr || 1 << randInt(25, 1); } } } diff --git a/src/system/game-speed.ts b/src/system/game-speed.ts index d9c48664f80..3df47fafc6c 100644 --- a/src/system/game-speed.ts +++ b/src/system/game-speed.ts @@ -3,7 +3,7 @@ import type FadeIn from "phaser3-rex-plugins/plugins/audio/fade/FadeIn"; import type FadeOut from "phaser3-rex-plugins/plugins/audio/fade/FadeOut"; import type BattleScene from "#app/battle-scene"; import { globalScene } from "#app/global-scene"; -import * as Utils from "../utils"; +import { FixedInt } from "#app/utils"; type FadeInType = typeof FadeIn; type FadeOutType = typeof FadeOut; @@ -11,9 +11,9 @@ type FadeOutType = typeof FadeOut; export function initGameSpeed() { const thisArg = this as BattleScene; - const transformValue = (value: number | Utils.FixedInt): number => { - if (value instanceof Utils.FixedInt) { - return (value as Utils.FixedInt).value; + const transformValue = (value: number | FixedInt): number => { + if (value instanceof FixedInt) { + return (value as FixedInt).value; } return thisArg.gameSpeed === 1 ? value : Math.ceil((value /= thisArg.gameSpeed)); }; diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index 957d43797a1..97ce494a43a 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -7,7 +7,7 @@ import { getPokemonSpecies, getPokemonSpeciesForm } from "../data/pokemon-specie import { Status } from "../data/status-effect"; import Pokemon, { EnemyPokemon, PokemonMove, PokemonSummonData } from "../field/pokemon"; import { TrainerSlot } from "#enums/trainer-slot"; -import type { Variant } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; import { loadBattlerTag } from "../data/battler-tags"; import type { Biome } from "#enums/biome"; import { Moves } from "#enums/moves"; @@ -79,12 +79,14 @@ export default class PokemonData { this.id = source.id; this.player = sourcePokemon ? sourcePokemon.isPlayer() : source.player; this.species = sourcePokemon ? sourcePokemon.species.speciesId : source.species; - this.nickname = sourcePokemon ? sourcePokemon.nickname : source.nickname; + this.nickname = sourcePokemon + ? (!!sourcePokemon.summonData?.illusion ? sourcePokemon.summonData.illusion.basePokemon.nickname : sourcePokemon.nickname) + : source.nickname; this.formIndex = Math.max(Math.min(source.formIndex, getPokemonSpecies(this.species).forms.length - 1), 0); this.abilityIndex = source.abilityIndex; this.passive = source.passive; - this.shiny = source.shiny; - this.variant = source.variant; + this.shiny = sourcePokemon ? sourcePokemon.isShiny() : source.shiny; + this.variant = sourcePokemon ? sourcePokemon.getVariant() : source.variant; this.pokeball = source.pokeball; this.level = source.level; this.exp = source.exp; @@ -117,8 +119,12 @@ export default class PokemonData { this.fusionSpecies = sourcePokemon ? sourcePokemon.fusionSpecies?.speciesId : source.fusionSpecies; this.fusionFormIndex = source.fusionFormIndex; this.fusionAbilityIndex = source.fusionAbilityIndex; - this.fusionShiny = source.fusionShiny; - this.fusionVariant = source.fusionVariant; + this.fusionShiny = sourcePokemon + ? (!!sourcePokemon.summonData?.illusion ? sourcePokemon.summonData.illusion.basePokemon.fusionShiny : sourcePokemon.fusionShiny) + : source.fusionShiny; + this.fusionVariant = sourcePokemon + ? (!!sourcePokemon.summonData?.illusion ? sourcePokemon.summonData.illusion.basePokemon.fusionVariant : sourcePokemon.fusionVariant) + : source.fusionVariant; this.fusionGender = source.fusionGender; this.fusionLuck = source.fusionLuck !== undefined ? source.fusionLuck : source.fusionShiny ? source.fusionVariant + 1 : 0; @@ -174,6 +180,7 @@ export default class PokemonData { this.summonData.types = source.summonData.types; this.summonData.speciesForm = source.summonData.speciesForm; this.summonDataSpeciesFormIndex = source.summonDataSpeciesFormIndex; + this.summonData.illusionBroken = source.summonData.illusionBroken; if (source.summonData.tags) { this.summonData.tags = source.summonData.tags?.map(t => loadBattlerTag(t)); @@ -219,6 +226,7 @@ export default class PokemonData { if (this.summonData) { // when loading from saved session, recover summonData.speciesFrom and form index species object // used to stay transformed on reload session + if (this.summonData.speciesForm) { this.summonData.speciesForm = getPokemonSpeciesForm( this.summonData.speciesForm.speciesId, diff --git a/src/system/version_migration/version_converter.ts b/src/system/version_migration/version_converter.ts index 4b712609819..1fdb9e93f88 100644 --- a/src/system/version_migration/version_converter.ts +++ b/src/system/version_migration/version_converter.ts @@ -48,12 +48,15 @@ export const settingsMigrators: Readonly = [settingsMigr // import * as vA_B_C from "./versions/vA_B_C"; // --- v1.0.4 (and below) PATCHES --- // +// biome-ignore lint/style/noNamespaceImport: Convenience (TODO: make this a file-wide ignore when Biome supports those) import * as v1_0_4 from "./versions/v1_0_4"; // --- v1.7.0 PATCHES --- // +// biome-ignore lint/style/noNamespaceImport: Convenience import * as v1_7_0 from "./versions/v1_7_0"; // --- v1.8.3 PATCHES --- // +// biome-ignore lint/style/noNamespaceImport: Convenience import * as v1_8_3 from "./versions/v1_8_3"; /** Current game version */ diff --git a/src/ui/abstact-option-select-ui-handler.ts b/src/ui/abstact-option-select-ui-handler.ts index f605f73e171..b360065f61d 100644 --- a/src/ui/abstact-option-select-ui-handler.ts +++ b/src/ui/abstact-option-select-ui-handler.ts @@ -3,7 +3,7 @@ import { TextStyle, addBBCodeTextObject, getTextColor, getTextStyleOptions } fro import { Mode } from "./ui"; import UiHandler from "./ui-handler"; import { addWindow } from "./ui-theme"; -import * as Utils from "../utils"; +import { rgbHexToRgba, fixedInt } from "#app/utils"; import { argbFromRgba } from "@material/material-color-utilities"; import { Button } from "#enums/buttons"; import BBCodeText from "phaser3-rex-plugins/plugins/gameobjects/tagtext/bbcodetext/BBCodeText"; @@ -178,8 +178,8 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { itemOverlayIcon.setPositionRelative(this.optionSelectText, 36 * this.scale, 7 + i * (114 * this.scale - 3)); if (option.itemArgs) { - itemIcon.setTint(argbFromRgba(Utils.rgbHexToRgba(option.itemArgs[0]))); - itemOverlayIcon.setTint(argbFromRgba(Utils.rgbHexToRgba(option.itemArgs[1]))); + itemIcon.setTint(argbFromRgba(rgbHexToRgba(option.itemArgs[0]))); + itemOverlayIcon.setTint(argbFromRgba(rgbHexToRgba(option.itemArgs[1]))); } } } @@ -207,7 +207,7 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { this.blockInput = true; this.optionSelectTextContainer.setAlpha(0.5); this.cursorObj?.setAlpha(0.8); - globalScene.time.delayedCall(Utils.fixedInt(this.config.delay), () => this.unblockInput()); + globalScene.time.delayedCall(fixedInt(this.config.delay), () => this.unblockInput()); } if (this.config?.supportHover) { diff --git a/src/ui/arena-flyout.ts b/src/ui/arena-flyout.ts index 36a44eb5aa0..1eb18a32f98 100644 --- a/src/ui/arena-flyout.ts +++ b/src/ui/arena-flyout.ts @@ -16,7 +16,7 @@ import type { TurnEndEvent } from "../events/battle-scene"; import { BattleSceneEventType } from "../events/battle-scene"; import { ArenaTagType } from "#enums/arena-tag-type"; import TimeOfDayWidget from "./time-of-day-widget"; -import * as Utils from "../utils"; +import { toCamelCaseString, formatText, fixedInt } from "#app/utils"; import type { ParseKeys } from "i18next"; import i18next from "i18next"; @@ -47,10 +47,10 @@ export function getFieldEffectText(arenaTagType: string): string { if (!arenaTagType || arenaTagType === ArenaTagType.NONE) { return arenaTagType; } - const effectName = Utils.toCamelCaseString(arenaTagType); + const effectName = toCamelCaseString(arenaTagType); const i18nKey = `arenaFlyout:${effectName}` as ParseKeys; const resultName = i18next.t(i18nKey); - return !resultName || resultName === i18nKey ? Utils.formatText(arenaTagType) : resultName; + return !resultName || resultName === i18nKey ? formatText(arenaTagType) : resultName; } export class ArenaFlyout extends Phaser.GameObjects.Container { @@ -411,7 +411,7 @@ export class ArenaFlyout extends Phaser.GameObjects.Container { globalScene.tweens.add({ targets: this.flyoutParent, x: visible ? this.anchorX : this.anchorX - this.translationX, - duration: Utils.fixedInt(125), + duration: fixedInt(125), ease: "Sine.easeInOut", alpha: visible ? 1 : 0, onComplete: () => (this.timeOfDayWidget.parentVisible = visible), diff --git a/src/ui/base-stats-overlay.ts b/src/ui/base-stats-overlay.ts index 5a6c67cae7b..d0b0aff3a9d 100644 --- a/src/ui/base-stats-overlay.ts +++ b/src/ui/base-stats-overlay.ts @@ -1,7 +1,7 @@ import type { InfoToggle } from "../battle-scene"; import { TextStyle, addTextObject } from "./text"; import { addWindow } from "./ui-theme"; -import * as Utils from "../utils"; +import { fixedInt } from "#app/utils"; import i18next from "i18next"; import { globalScene } from "#app/global-scene"; @@ -93,7 +93,7 @@ export class BaseStatsOverlay extends Phaser.GameObjects.Container implements In } globalScene.tweens.add({ targets: this.statsLabels, - duration: Utils.fixedInt(125), + duration: fixedInt(125), ease: "Sine.easeInOut", alpha: visible ? 1 : 0, }); diff --git a/src/ui/battle-flyout.ts b/src/ui/battle-flyout.ts index 206546ad9cb..854f4cc4dd9 100644 --- a/src/ui/battle-flyout.ts +++ b/src/ui/battle-flyout.ts @@ -1,6 +1,6 @@ import type { default as Pokemon } from "../field/pokemon"; import { addTextObject, TextStyle } from "./text"; -import * as Utils from "../utils"; +import { fixedInt } from "#app/utils"; import { globalScene } from "#app/global-scene"; import type Move from "#app/data/moves/move"; import type { BerryUsedEvent, MoveUsedEvent } from "../events/battle-scene"; @@ -201,7 +201,7 @@ export default class BattleFlyout extends Phaser.GameObjects.Container { globalScene.tweens.add({ targets: this.flyoutParent, x: visible ? this.anchorX : this.anchorX - this.translationX, - duration: Utils.fixedInt(125), + duration: fixedInt(125), ease: "Sine.easeInOut", alpha: visible ? 1 : 0, }); diff --git a/src/ui/battle-info.ts b/src/ui/battle-info.ts index 355ab9167a1..06c5f7fb3f1 100644 --- a/src/ui/battle-info.ts +++ b/src/ui/battle-info.ts @@ -1,13 +1,13 @@ import type { EnemyPokemon, default as Pokemon } from "../field/pokemon"; import { getLevelTotalExp, getLevelRelExp } from "../data/exp"; -import * as Utils from "../utils"; +import { getLocalizedSpriteKey, fixedInt } from "#app/utils"; import { addTextObject, TextStyle } from "./text"; import { getGenderSymbol, getGenderColor, Gender } from "../data/gender"; import { StatusEffect } from "#enums/status-effect"; import { globalScene } from "#app/global-scene"; import { getTypeRgb } from "#app/data/type"; import { PokemonType } from "#enums/pokemon-type"; -import { getVariantTint } from "#app/data/variant"; +import { getVariantTint } from "#app/sprites/variant"; import { Stat } from "#enums/stat"; import BattleFlyout from "./battle-flyout"; import { WindowVariant, addWindow } from "./ui-theme"; @@ -163,7 +163,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.splicedIcon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 12, 15), Phaser.Geom.Rectangle.Contains); this.add(this.splicedIcon); - this.statusIndicator = globalScene.add.sprite(0, 0, Utils.getLocalizedSpriteKey("statuses")); + this.statusIndicator = globalScene.add.sprite(0, 0, getLocalizedSpriteKey("statuses")); this.statusIndicator.setName("icon_status"); this.statusIndicator.setVisible(false); this.statusIndicator.setOrigin(0, 0); @@ -356,7 +356,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { }); this.teraIcon.on("pointerout", () => globalScene.ui.hideTooltip()); - const isFusion = pokemon.isFusion(); + const isFusion = pokemon.isFusion(true); this.splicedIcon.setPositionRelative( this.nameText, @@ -375,7 +375,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { } const doubleShiny = isFusion && pokemon.shiny && pokemon.fusionShiny; - const baseVariant = !doubleShiny ? pokemon.getVariant() : pokemon.variant; + const baseVariant = !doubleShiny ? pokemon.getVariant(true) : pokemon.variant; this.shinyIcon.setPositionRelative( this.nameText, @@ -536,7 +536,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { toggleStats(visible: boolean): void { globalScene.tweens.add({ targets: this.statsContainer, - duration: Utils.fixedInt(125), + duration: fixedInt(125), ease: "Sine.easeInOut", alpha: visible ? 1 : 0, }); @@ -617,6 +617,11 @@ export default class BattleInfo extends Phaser.GameObjects.Container { return resolve(); } + const gender: Gender = !!pokemon.summonData?.illusion ? pokemon.summonData?.illusion.gender : pokemon.gender; + + this.genderText.setText(getGenderSymbol(gender)); + this.genderText.setColor(getGenderColor(gender)); + const nameUpdated = this.lastName !== pokemon.getNameToRender(); if (nameUpdated) { @@ -638,8 +643,10 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.lastTeraType = teraType; } + const isFusion = pokemon.isFusion(true); + if (nameUpdated || teraTypeUpdated) { - this.splicedIcon.setVisible(!!pokemon.fusionSpecies); + this.splicedIcon.setVisible(isFusion); this.teraIcon.setPositionRelative( this.nameText, @@ -764,7 +771,17 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.lastStats = statsStr; } - this.shinyIcon.setVisible(pokemon.isShiny()); + this.shinyIcon.setVisible(pokemon.isShiny(true)); + + const doubleShiny = isFusion && pokemon.shiny && pokemon.fusionShiny; + const baseVariant = !doubleShiny ? pokemon.getVariant(true) : pokemon.variant; + this.shinyIcon.setTint(getVariantTint(baseVariant)); + + this.fusionShinyIcon.setVisible(doubleShiny); + if (isFusion) { + this.fusionShinyIcon.setTint(getVariantTint(pokemon.fusionVariant)); + } + this.fusionShinyIcon.setPosition(this.shinyIcon.x, this.shinyIcon.y); resolve(); }); @@ -777,10 +794,11 @@ export default class BattleInfo extends Phaser.GameObjects.Container { const nameSizeTest = addTextObject(0, 0, displayName, TextStyle.BATTLE_INFO); nameTextWidth = nameSizeTest.displayWidth; + const gender: Gender = !!pokemon.summonData?.illusion ? pokemon.summonData?.illusion.gender : pokemon.gender; while ( nameTextWidth > (this.player || !this.boss ? 60 : 98) - - ((pokemon.gender !== Gender.GENDERLESS ? 6 : 0) + + ((gender !== Gender.GENDERLESS ? 6 : 0) + (pokemon.fusionSpecies ? 8 : 0) + (pokemon.isShiny() ? 8 : 0) + (Math.min(pokemon.level.toString().length, 3) - 3) * 8) diff --git a/src/ui/bgm-bar.ts b/src/ui/bgm-bar.ts index 45ed766c7fa..d944453ba2c 100644 --- a/src/ui/bgm-bar.ts +++ b/src/ui/bgm-bar.ts @@ -1,6 +1,6 @@ import { addTextObject, TextStyle } from "./text"; import i18next from "i18next"; -import * as Utils from "#app/utils"; +import { formatText } from "#app/utils"; import { globalScene } from "#app/global-scene"; const hiddenX = -150; @@ -100,7 +100,7 @@ export default class BgmBar extends Phaser.GameObjects.Container { getRealBgmName(bgmName: string): string { return i18next.t([`bgmName:${bgmName}`, "bgmName:missing_entries"], { - name: Utils.formatText(bgmName), + name: formatText(bgmName), }); } } diff --git a/src/ui/candy-bar.ts b/src/ui/candy-bar.ts index ba85ed7fef3..0cf3e0c91e9 100644 --- a/src/ui/candy-bar.ts +++ b/src/ui/candy-bar.ts @@ -2,7 +2,7 @@ import { starterColors } from "#app/battle-scene"; import { globalScene } from "#app/global-scene"; import { TextStyle, addTextObject } from "./text"; import { argbFromRgba } from "@material/material-color-utilities"; -import * as Utils from "../utils"; +import { rgbHexToRgba } from "#app/utils"; import type { Species } from "#enums/species"; export default class CandyBar extends Phaser.GameObjects.Container { @@ -60,8 +60,8 @@ export default class CandyBar extends Phaser.GameObjects.Container { const colorScheme = starterColors[starterSpeciesId]; - this.candyIcon.setTint(argbFromRgba(Utils.rgbHexToRgba(colorScheme[0]))); - this.candyOverlayIcon.setTint(argbFromRgba(Utils.rgbHexToRgba(colorScheme[1]))); + this.candyIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[0]))); + this.candyOverlayIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[1]))); this.countText.setText( `${globalScene.gameData.starterData[starterSpeciesId].candyCount + count} (+${count.toString()})`, diff --git a/src/ui/challenges-select-ui-handler.ts b/src/ui/challenges-select-ui-handler.ts index 61989cd594e..caffede2487 100644 --- a/src/ui/challenges-select-ui-handler.ts +++ b/src/ui/challenges-select-ui-handler.ts @@ -5,7 +5,7 @@ import { addWindow } from "./ui-theme"; import { Button } from "#enums/buttons"; import i18next from "i18next"; import type { Challenge } from "#app/data/challenge"; -import * as Utils from "../utils"; +import { getLocalizedSpriteKey } from "#app/utils"; import { Challenges } from "#app/enums/challenges"; import BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext"; import { Color, ShadowColor } from "#app/enums/color"; @@ -193,7 +193,7 @@ export default class GameChallengesUiHandler extends UiHandler { }; } - this.monoTypeValue = globalScene.add.sprite(8, 98, Utils.getLocalizedSpriteKey("types")); + this.monoTypeValue = globalScene.add.sprite(8, 98, getLocalizedSpriteKey("types")); this.monoTypeValue.setName("challenge-value-monotype-sprite"); this.monoTypeValue.setScale(0.86); this.monoTypeValue.setVisible(false); diff --git a/src/ui/char-sprite.ts b/src/ui/char-sprite.ts index 74c021a65b8..f717927c107 100644 --- a/src/ui/char-sprite.ts +++ b/src/ui/char-sprite.ts @@ -1,5 +1,5 @@ import { globalScene } from "#app/global-scene"; -import * as Utils from "../utils"; +import { MissingTextureKey } from "#app/utils"; export default class CharSprite extends Phaser.GameObjects.Container { private sprite: Phaser.GameObjects.Sprite; @@ -57,7 +57,7 @@ export default class CharSprite extends Phaser.GameObjects.Container { }, }); - this.setVisible(globalScene.textures.get(key).key !== Utils.MissingTextureKey); + this.setVisible(globalScene.textures.get(key).key !== MissingTextureKey); this.shown = true; this.key = key; diff --git a/src/ui/daily-run-scoreboard.ts b/src/ui/daily-run-scoreboard.ts index 53c737898e7..896f2171676 100644 --- a/src/ui/daily-run-scoreboard.ts +++ b/src/ui/daily-run-scoreboard.ts @@ -1,6 +1,6 @@ import i18next from "i18next"; import { globalScene } from "#app/global-scene"; -import * as Utils from "../utils"; +import { getEnumKeys, executeIf } from "#app/utils"; import { TextStyle, addTextObject } from "./text"; import { WindowVariant, addWindow } from "./ui-theme"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; @@ -89,7 +89,7 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { this.prevCategoryButton.setInteractive(new Phaser.Geom.Rectangle(0, 0, 6, 10), Phaser.Geom.Rectangle.Contains); this.prevCategoryButton.on("pointerup", () => { - this.update(this.category ? this.category - 1 : Utils.getEnumKeys(ScoreboardCategory).length - 1); + this.update(this.category ? this.category - 1 : getEnumKeys(ScoreboardCategory).length - 1); }); this.nextCategoryButton = globalScene.add.sprite(window.displayWidth - 4, 4, "cursor"); @@ -98,7 +98,7 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { this.nextCategoryButton.setInteractive(new Phaser.Geom.Rectangle(0, 0, 6, 10), Phaser.Geom.Rectangle.Contains); this.nextCategoryButton.on("pointerup", () => { - this.update(this.category < Utils.getEnumKeys(ScoreboardCategory).length - 1 ? this.category + 1 : 0); + this.update(this.category < getEnumKeys(ScoreboardCategory).length - 1 ? this.category + 1 : 0); }); this.prevPageButton = globalScene.add.sprite( @@ -226,7 +226,7 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { this.page = page = 1; } - Utils.executeIf(category !== this.category || this.pageCount === undefined, () => + executeIf(category !== this.category || this.pageCount === undefined, () => pokerogueApi.daily.getRankingsPageCount({ category }).then(count => (this.pageCount = count)), ) .then(() => { diff --git a/src/ui/egg-gacha-ui-handler.ts b/src/ui/egg-gacha-ui-handler.ts index cb6a474f01d..956a308448b 100644 --- a/src/ui/egg-gacha-ui-handler.ts +++ b/src/ui/egg-gacha-ui-handler.ts @@ -1,7 +1,7 @@ import { Mode } from "./ui"; import { TextStyle, addTextObject, getEggTierTextTint, getTextStyleOptions } from "./text"; import MessageUiHandler from "./message-ui-handler"; -import * as Utils from "../utils"; +import { getEnumValues, getEnumKeys, fixedInt, randSeedShuffle } from "#app/utils"; import type { IEggOptions } from "../data/egg"; import { Egg, getLegendaryGachaSpeciesForTimestamp } from "../data/egg"; import { VoucherType, getVoucherTypeIcon } from "../system/voucher"; @@ -83,7 +83,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { }); } - Utils.getEnumValues(GachaType).forEach((gachaType, g) => { + getEnumValues(GachaType).forEach((gachaType, g) => { const gachaTypeKey = GachaType[gachaType].toString().toLowerCase(); const gachaContainer = globalScene.add.container(180 * g, 18); @@ -272,7 +272,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { this.eggGachaContainer.add(this.eggGachaOptionsContainer); - new Array(Utils.getEnumKeys(VoucherType).length).fill(null).map((_, i) => { + new Array(getEnumKeys(VoucherType).length).fill(null).map((_, i) => { const container = globalScene.add.container(globalScene.game.canvas.width / 6 - 56 * i, 0); const bg = addWindow(0, 0, 56, 22); @@ -355,7 +355,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { if (this.transitioning && this.transitionCancelled) { delay = Math.ceil(delay / 5); } - return Utils.fixedInt(delay); + return fixedInt(delay); } pull(pullCount = 0, count = 0, eggs?: Egg[]): void { @@ -476,7 +476,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { eggs.push(egg); } // Shuffle the eggs in case the guaranteed one got added as last egg - eggs = Utils.randSeedShuffle(eggs); + eggs = randSeedShuffle(eggs); (globalScene.currentBattle ? globalScene.gameData.saveAll(true, true, true) @@ -643,7 +643,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { } showError(text: string): void { - this.showText(text, undefined, () => this.showText(this.defaultText), Utils.fixedInt(1500)); + this.showText(text, undefined, () => this.showText(this.defaultText), fixedInt(1500)); } setTransitioning(transitioning: boolean): void { @@ -783,7 +783,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { } break; case Button.RIGHT: - if (this.gachaCursor < Utils.getEnumKeys(GachaType).length - 1) { + if (this.gachaCursor < getEnumKeys(GachaType).length - 1) { success = this.setGachaCursor(this.gachaCursor + 1); } break; diff --git a/src/ui/fight-ui-handler.ts b/src/ui/fight-ui-handler.ts index 9f76e85f228..27985629e3d 100644 --- a/src/ui/fight-ui-handler.ts +++ b/src/ui/fight-ui-handler.ts @@ -6,7 +6,7 @@ import { PokemonType } from "#enums/pokemon-type"; import { Command } from "./command-ui-handler"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; -import * as Utils from "../utils"; +import { getLocalizedSpriteKey, fixedInt, padInt } from "#app/utils"; import { MoveCategory } from "#enums/MoveCategory"; import i18next from "i18next"; import { Button } from "#enums/buttons"; @@ -54,7 +54,7 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { this.typeIcon = globalScene.add.sprite( globalScene.scaledCanvas.width - 57, -36, - Utils.getLocalizedSpriteKey("types"), + getLocalizedSpriteKey("types"), "unknown", ); this.typeIcon.setVisible(false); @@ -199,7 +199,7 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { } globalScene.tweens.add({ targets: [this.movesContainer, this.cursorObj], - duration: Utils.fixedInt(125), + duration: fixedInt(125), ease: "Sine.easeInOut", alpha: visible ? 0 : 1, }); @@ -245,7 +245,7 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { if (hasMove) { const pokemonMove = moveset[cursor]; const moveType = pokemon.getMoveType(pokemonMove.getMove()); - const textureKey = Utils.getLocalizedSpriteKey("types"); + const textureKey = getLocalizedSpriteKey("types"); this.typeIcon.setTexture(textureKey, PokemonType[moveType].toLowerCase()).setScale(0.8); const moveCategory = pokemonMove.getMove().category; @@ -255,8 +255,8 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { const maxPP = pokemonMove.getMovePp(); const pp = maxPP - pokemonMove.ppUsed; - const ppLeftStr = Utils.padInt(pp, 2, " "); - const ppMaxStr = Utils.padInt(maxPP, 2, " "); + const ppLeftStr = padInt(pp, 2, " "); + const ppMaxStr = padInt(maxPP, 2, " "); this.ppText.setText(`${ppLeftStr}/${ppMaxStr}`); this.powerText.setText(`${power >= 0 ? power : "---"}`); this.accuracyText.setText(`${accuracy >= 0 ? accuracy : "---"}`); @@ -306,6 +306,9 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { pokemon, pokemonMove.getMove(), !opponent.battleData?.abilityRevealed, + undefined, + undefined, + true ); if (effectiveness === undefined) { return undefined; @@ -350,7 +353,7 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { const moveColors = opponents .map(opponent => - opponent.getMoveEffectiveness(pokemon, pokemonMove.getMove(), !opponent.battleData.abilityRevealed), + opponent.getMoveEffectiveness(pokemon, pokemonMove.getMove(), !opponent.battleData.abilityRevealed, undefined, undefined, true), ) .sort((a, b) => b - a) .map(effectiveness => getTypeDamageMultiplierColor(effectiveness ?? 0, "offense")); diff --git a/src/ui/form-modal-ui-handler.ts b/src/ui/form-modal-ui-handler.ts index 8784145acd6..e27b2e9ed89 100644 --- a/src/ui/form-modal-ui-handler.ts +++ b/src/ui/form-modal-ui-handler.ts @@ -4,7 +4,7 @@ import type { Mode } from "./ui"; import { TextStyle, addTextInputObject, addTextObject } from "./text"; import { WindowVariant, addWindow } from "./ui-theme"; import type InputText from "phaser3-rex-plugins/plugins/inputtext"; -import * as Utils from "../utils"; +import { fixedInt } from "#app/utils"; import { Button } from "#enums/buttons"; import { globalScene } from "#app/global-scene"; @@ -135,7 +135,7 @@ export abstract class FormModalUiHandler extends ModalUiHandler { this.tween = globalScene.tweens.add({ targets: this.modalContainer, - duration: Utils.fixedInt(1000), + duration: fixedInt(1000), ease: "Sine.easeInOut", y: "-=24", alpha: 1, diff --git a/src/ui/game-stats-ui-handler.ts b/src/ui/game-stats-ui-handler.ts index 7d3decf0c4c..2e2112dfda4 100644 --- a/src/ui/game-stats-ui-handler.ts +++ b/src/ui/game-stats-ui-handler.ts @@ -3,7 +3,7 @@ import { TextStyle, addTextObject } from "#app/ui/text"; import type { Mode } from "#app/ui/ui"; import UiHandler from "#app/ui/ui-handler"; import { addWindow } from "#app/ui/ui-theme"; -import * as Utils from "#app/utils"; +import { getPlayTimeString, formatFancyLargeNumber, toReadableString } from "#app/utils"; import type { GameData } from "#app/system/game-data"; import { DexAttr } from "#app/system/game-data"; import { speciesStarterCosts } from "#app/data/balance/starters"; @@ -25,7 +25,7 @@ interface DisplayStats { const displayStats: DisplayStats = { playTime: { label_key: "playTime", - sourceFunc: gameData => Utils.getPlayTimeString(gameData.gameStats.playTime), + sourceFunc: gameData => getPlayTimeString(gameData.gameStats.playTime), }, battles: { label_key: "totalBattles", @@ -91,7 +91,7 @@ const displayStats: DisplayStats = { }, highestMoney: { label_key: "highestMoney", - sourceFunc: gameData => Utils.formatFancyLargeNumber(gameData.gameStats.highestMoney), + sourceFunc: gameData => formatFancyLargeNumber(gameData.gameStats.highestMoney), }, highestDamage: { label_key: "highestDamage", @@ -435,7 +435,7 @@ export function initStatsKeys() { } if (!(displayStats[key] as DisplayStat).label_key) { const splittableKey = key.replace(/([a-z]{2,})([A-Z]{1}(?:[^A-Z]|$))/g, "$1_$2"); - (displayStats[key] as DisplayStat).label_key = Utils.toReadableString( + (displayStats[key] as DisplayStat).label_key = toReadableString( `${splittableKey[0].toUpperCase()}${splittableKey.slice(1)}`, ); } diff --git a/src/ui/hatched-pokemon-container.ts b/src/ui/hatched-pokemon-container.ts index 0b283c2e063..9d1c13e19d5 100644 --- a/src/ui/hatched-pokemon-container.ts +++ b/src/ui/hatched-pokemon-container.ts @@ -1,6 +1,6 @@ import type { EggHatchData } from "#app/data/egg-hatch-data"; import { Gender } from "#app/data/gender"; -import { getVariantTint } from "#app/data/variant"; +import { getVariantTint } from "#app/sprites/variant"; import { DexAttr } from "#app/system/game-data"; import { globalScene } from "#app/global-scene"; import type PokemonSpecies from "#app/data/pokemon-species"; diff --git a/src/ui/login-form-ui-handler.ts b/src/ui/login-form-ui-handler.ts index 1087ffa3fd1..5c009357443 100644 --- a/src/ui/login-form-ui-handler.ts +++ b/src/ui/login-form-ui-handler.ts @@ -1,7 +1,7 @@ import type { InputFieldConfig } from "./form-modal-ui-handler"; import { FormModalUiHandler } from "./form-modal-ui-handler"; import type { ModalConfig } from "./modal-ui-handler"; -import * as Utils from "../utils"; +import { fixedInt } from "#app/utils"; import { Mode } from "./ui"; import i18next from "i18next"; import { addTextObject, TextStyle } from "./text"; @@ -283,7 +283,7 @@ export default class LoginFormUiHandler extends FormModalUiHandler { this.externalPartyContainer.setAlpha(0); globalScene.tweens.add({ targets: this.externalPartyContainer, - duration: Utils.fixedInt(1000), + duration: fixedInt(1000), ease: "Sine.easeInOut", y: "-=24", alpha: 1, @@ -292,7 +292,7 @@ export default class LoginFormUiHandler extends FormModalUiHandler { this.infoContainer.setAlpha(0); globalScene.tweens.add({ targets: this.infoContainer, - duration: Utils.fixedInt(1000), + duration: fixedInt(1000), ease: "Sine.easeInOut", y: "-=24", alpha: 1, diff --git a/src/ui/menu-ui-handler.ts b/src/ui/menu-ui-handler.ts index b83ae24c9e0..241ddbb91a8 100644 --- a/src/ui/menu-ui-handler.ts +++ b/src/ui/menu-ui-handler.ts @@ -2,7 +2,7 @@ import { bypassLogin } from "#app/battle-scene"; import { globalScene } from "#app/global-scene"; import { TextStyle, addTextObject, getTextStyleOptions } from "./text"; import { Mode } from "./ui"; -import * as Utils from "../utils"; +import { getEnumKeys, isLocal, isBeta, fixedInt, getCookie, sessionIdKey } from "#app/utils"; import { addWindow, WindowVariant } from "./ui-theme"; import MessageUiHandler from "./message-ui-handler"; import type { OptionSelectConfig, OptionSelectItem } from "./abstact-option-select-ui-handler"; @@ -75,7 +75,7 @@ export default class MenuUiHandler extends MessageUiHandler { { condition: bypassLogin, options: [MenuOptions.LOG_OUT] }, ]; - this.menuOptions = Utils.getEnumKeys(MenuOptions) + this.menuOptions = getEnumKeys(MenuOptions) .map(m => Number.parseInt(MenuOptions[m]) as MenuOptions) .filter(m => { return !this.excludedMenus().some(exclusion => exclusion.condition && exclusion.options.includes(m)); @@ -130,7 +130,7 @@ export default class MenuUiHandler extends MessageUiHandler { { condition: bypassLogin, options: [MenuOptions.LOG_OUT] }, ]; - this.menuOptions = Utils.getEnumKeys(MenuOptions) + this.menuOptions = getEnumKeys(MenuOptions) .map(m => Number.parseInt(MenuOptions[m]) as MenuOptions) .filter(m => { return !this.excludedMenus().some(exclusion => exclusion.condition && exclusion.options.includes(m)); @@ -238,7 +238,7 @@ export default class MenuUiHandler extends MessageUiHandler { }); }; - if (Utils.isLocal || Utils.isBeta) { + if (isLocal || isBeta) { manageDataOptions.push({ label: i18next.t("menuUiHandler:importSession"), handler: () => { @@ -292,7 +292,7 @@ export default class MenuUiHandler extends MessageUiHandler { }, keepOpen: true, }); - if (Utils.isLocal || Utils.isBeta) { + if (isLocal || isBeta) { manageDataOptions.push({ label: i18next.t("menuUiHandler:importData"), handler: () => { @@ -328,7 +328,7 @@ export default class MenuUiHandler extends MessageUiHandler { keepOpen: true, }, ); - if (Utils.isLocal || Utils.isBeta) { + if (isLocal || isBeta) { // this should make sure we don't have this option in live manageDataOptions.push({ label: "Test Dialogue", @@ -510,7 +510,7 @@ export default class MenuUiHandler extends MessageUiHandler { this.render(); super.show(args); - this.menuOptions = Utils.getEnumKeys(MenuOptions) + this.menuOptions = getEnumKeys(MenuOptions) .map(m => Number.parseInt(MenuOptions[m]) as MenuOptions) .filter(m => { return !this.excludedMenus().some(exclusion => exclusion.condition && exclusion.options.includes(m)); @@ -574,7 +574,7 @@ export default class MenuUiHandler extends MessageUiHandler { ui.setOverlayMode(Mode.EGG_LIST); success = true; } else { - ui.showText(i18next.t("menuUiHandler:noEggs"), null, () => ui.showText(""), Utils.fixedInt(1500)); + ui.showText(i18next.t("menuUiHandler:noEggs"), null, () => ui.showText(""), fixedInt(1500)); error = true; } break; @@ -607,7 +607,7 @@ export default class MenuUiHandler extends MessageUiHandler { : i18next.t("menuUiHandler:unlinkDiscord"), handler: () => { if (loggedInUser?.discordId === "") { - const token = Utils.getCookie(Utils.sessionIdKey); + const token = getCookie(sessionIdKey); const redirectUri = encodeURIComponent(`${import.meta.env.VITE_SERVER_URL}/auth/discord/callback`); const discordId = import.meta.env.VITE_DISCORD_CLIENT_ID; const discordUrl = `https://discord.com/api/oauth2/authorize?client_id=${discordId}&redirect_uri=${redirectUri}&response_type=code&scope=identify&state=${token}&prompt=none`; @@ -627,7 +627,7 @@ export default class MenuUiHandler extends MessageUiHandler { : i18next.t("menuUiHandler:unlinkGoogle"), handler: () => { if (loggedInUser?.googleId === "") { - const token = Utils.getCookie(Utils.sessionIdKey); + const token = getCookie(sessionIdKey); const redirectUri = encodeURIComponent(`${import.meta.env.VITE_SERVER_URL}/auth/google/callback`); const googleId = import.meta.env.VITE_GOOGLE_CLIENT_ID; const googleUrl = `https://accounts.google.com/o/oauth2/auth?client_id=${googleId}&response_type=code&redirect_uri=${redirectUri}&scope=openid&state=${token}`; diff --git a/src/ui/message-ui-handler.ts b/src/ui/message-ui-handler.ts index e927793e0ab..b57b236531c 100644 --- a/src/ui/message-ui-handler.ts +++ b/src/ui/message-ui-handler.ts @@ -1,6 +1,6 @@ import AwaitableUiHandler from "./awaitable-ui-handler"; import type { Mode } from "./ui"; -import * as Utils from "../utils"; +import { getFrameMs } from "#app/utils"; import { globalScene } from "#app/global-scene"; export default abstract class MessageUiHandler extends AwaitableUiHandler { @@ -183,7 +183,7 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { if (charDelay) { this.textTimer!.paused = true; // TODO: is the bang correct? globalScene.tweens.addCounter({ - duration: Utils.getFrameMs(charDelay), + duration: getFrameMs(charDelay), onComplete: () => { this.textTimer!.paused = false; // TODO: is the bang correct? advance(); @@ -193,7 +193,7 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { this.textTimer!.paused = true; globalScene.time.delayedCall(150, () => { globalScene.ui.fadeOut(750).then(() => { - const delay = Utils.getFrameMs(charFade); + const delay = getFrameMs(charFade); globalScene.time.delayedCall(delay, () => { globalScene.ui.fadeIn(500).then(() => { this.textTimer!.paused = false; diff --git a/src/ui/modifier-select-ui-handler.ts b/src/ui/modifier-select-ui-handler.ts index e5d8f858782..26351d4dbf1 100644 --- a/src/ui/modifier-select-ui-handler.ts +++ b/src/ui/modifier-select-ui-handler.ts @@ -10,11 +10,10 @@ import { handleTutorial, Tutorial } from "../tutorial"; import { Button } from "#enums/buttons"; import MoveInfoOverlay from "./move-info-overlay"; import { allMoves } from "../data/moves/move"; -import * as Utils from "./../utils"; +import { formatMoney, NumberHolder } from "#app/utils"; import Overrides from "#app/overrides"; import i18next from "i18next"; import { ShopCursorTarget } from "#app/enums/shop-cursor-target"; -import { NumberHolder } from "./../utils"; import Phaser from "phaser"; import type { PokeballType } from "#enums/pokeball"; @@ -645,7 +644,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { this.rerollCostText.setVisible(true); const canReroll = globalScene.money >= this.rerollCost; - const formattedMoney = Utils.formatMoney(globalScene.moneyFormat, this.rerollCost); + const formattedMoney = formatMoney(globalScene.moneyFormat, this.rerollCost); this.rerollCostText.setText(i18next.t("modifierSelectUiHandler:rerollCost", { formattedMoney })); this.rerollCostText.setColor(this.getTextColor(canReroll ? TextStyle.MONEY : TextStyle.PARTY_RED)); @@ -933,7 +932,7 @@ class ModifierOption extends Phaser.GameObjects.Container { const cost = Overrides.WAIVE_ROLL_FEE_OVERRIDE ? 0 : this.modifierTypeOption.cost; const textStyle = cost <= globalScene.money ? TextStyle.MONEY : TextStyle.PARTY_RED; - const formattedMoney = Utils.formatMoney(globalScene.moneyFormat, cost); + const formattedMoney = formatMoney(globalScene.moneyFormat, cost); this.itemCostText.setText(i18next.t("modifierSelectUiHandler:itemCost", { formattedMoney })); this.itemCostText.setColor(getTextColor(textStyle, false, globalScene.uiTheme)); diff --git a/src/ui/move-info-overlay.ts b/src/ui/move-info-overlay.ts index 6fc99beb0ae..bd9fdf00c72 100644 --- a/src/ui/move-info-overlay.ts +++ b/src/ui/move-info-overlay.ts @@ -2,7 +2,7 @@ import type { InfoToggle } from "#app/battle-scene"; import { globalScene } from "#app/global-scene"; import { TextStyle, addTextObject } from "./text"; import { addWindow } from "./ui-theme"; -import * as Utils from "../utils"; +import { getLocalizedSpriteKey, fixedInt } from "#app/utils"; import type Move from "../data/moves/move"; import { MoveCategory } from "#enums/MoveCategory"; import { PokemonType } from "#enums/pokemon-type"; @@ -120,7 +120,7 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem valuesBg.setOrigin(0, 0); this.val.add(valuesBg); - this.typ = globalScene.add.sprite(25, EFF_HEIGHT - 35, Utils.getLocalizedSpriteKey("types"), "unknown"); + this.typ = globalScene.add.sprite(25, EFF_HEIGHT - 35, getLocalizedSpriteKey("types"), "unknown"); this.typ.setScale(0.8); this.val.add(this.typ); @@ -175,7 +175,7 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem this.pow.setText(move.power >= 0 ? move.power.toString() : "---"); this.acc.setText(move.accuracy >= 0 ? move.accuracy.toString() : "---"); this.pp.setText(move.pp >= 0 ? move.pp.toString() : "---"); - this.typ.setTexture(Utils.getLocalizedSpriteKey("types"), PokemonType[move.type].toLowerCase()); + this.typ.setTexture(getLocalizedSpriteKey("types"), PokemonType[move.type].toLowerCase()); this.cat.setFrame(MoveCategory[move.category].toLowerCase()); this.desc.setText(move?.effect || ""); @@ -193,10 +193,10 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem // generate scrolling effects this.descScroll = globalScene.tweens.add({ targets: this.desc, - delay: Utils.fixedInt(2000), + delay: fixedInt(2000), loop: -1, - hold: Utils.fixedInt(2000), - duration: Utils.fixedInt((moveDescriptionLineCount - 3) * 2000), + hold: fixedInt(2000), + duration: fixedInt((moveDescriptionLineCount - 3) * 2000), y: `-=${14.83 * (72 / 96) * (moveDescriptionLineCount - 3)}`, }); } @@ -219,7 +219,7 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem } globalScene.tweens.add({ targets: this.desc, - duration: Utils.fixedInt(125), + duration: fixedInt(125), ease: "Sine.easeInOut", alpha: visible ? 1 : 0, }); diff --git a/src/ui/mystery-encounter-ui-handler.ts b/src/ui/mystery-encounter-ui-handler.ts index 87d2e2ba28c..2bf05302c55 100644 --- a/src/ui/mystery-encounter-ui-handler.ts +++ b/src/ui/mystery-encounter-ui-handler.ts @@ -6,8 +6,7 @@ import { addWindow, WindowVariant } from "./ui-theme"; import type { MysteryEncounterPhase } from "../phases/mystery-encounter-phases"; import { PartyUiMode } from "./party-ui-handler"; import type MysteryEncounterOption from "#app/data/mystery-encounters/mystery-encounter-option"; -import * as Utils from "../utils"; -import { isNullOrUndefined } from "../utils"; +import { fixedInt, isNullOrUndefined } from "#app/utils"; import { getPokeballAtlasKey } from "../data/pokeball"; import type { OptionSelectSettings } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { getEncounterText } from "#app/data/mystery-encounters/utils/encounter-dialogue-utils"; @@ -456,10 +455,10 @@ export default class MysteryEncounterUiHandler extends UiHandler { if (optionTextWidth > nonScrollWidth) { this.optionScrollTweens[i] = globalScene.tweens.add({ targets: optionText, - delay: Utils.fixedInt(2000), + delay: fixedInt(2000), loop: -1, - hold: Utils.fixedInt(2000), - duration: Utils.fixedInt(((optionTextWidth - nonScrollWidth) / 15) * 2000), + hold: fixedInt(2000), + duration: fixedInt(((optionTextWidth - nonScrollWidth) / 15) * 2000), x: `-=${optionTextWidth - nonScrollWidth}`, }); } @@ -527,10 +526,10 @@ export default class MysteryEncounterUiHandler extends UiHandler { if (descriptionLineCount > 6) { this.descriptionScrollTween = globalScene.tweens.add({ targets: descriptionTextObject, - delay: Utils.fixedInt(2000), + delay: fixedInt(2000), loop: -1, - hold: Utils.fixedInt(2000), - duration: Utils.fixedInt((descriptionLineCount - 6) * 2000), + hold: fixedInt(2000), + duration: fixedInt((descriptionLineCount - 6) * 2000), y: `-=${10 * (descriptionLineCount - 6)}`, }); } @@ -637,10 +636,10 @@ export default class MysteryEncounterUiHandler extends UiHandler { if (tooltipLineCount > 3) { this.tooltipScrollTween = globalScene.tweens.add({ targets: tooltipTextObject, - delay: Utils.fixedInt(1200), + delay: fixedInt(1200), loop: -1, - hold: Utils.fixedInt(1200), - duration: Utils.fixedInt((tooltipLineCount - 3) * 1200), + hold: fixedInt(1200), + duration: fixedInt((tooltipLineCount - 3) * 1200), y: `-=${11.2 * (tooltipLineCount - 3)}`, }); } diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index caddd64cd28..ba90108c274 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -5,7 +5,7 @@ import { addBBCodeTextObject, addTextObject, getTextColor, TextStyle } from "#ap import { Command } from "#app/ui/command-ui-handler"; import MessageUiHandler from "#app/ui/message-ui-handler"; import { Mode } from "#app/ui/ui"; -import * as Utils from "#app/utils"; +import { BooleanHolder, toReadableString, randInt, getLocalizedSpriteKey } from "#app/utils"; import { PokemonFormChangeItemModifier, PokemonHeldItemModifier, @@ -18,7 +18,7 @@ import PokemonIconAnimHandler, { PokemonIconAnimMode } from "#app/ui/pokemon-ico import { pokemonEvolutions } from "#app/data/balance/pokemon-evolutions"; import { addWindow } from "#app/ui/ui-theme"; import { SpeciesFormChangeItemTrigger, FormChangeItem } from "#app/data/pokemon-forms"; -import { getVariantTint } from "#app/data/variant"; +import { getVariantTint } from "#app/sprites/variant"; import { Button } from "#enums/buttons"; import { applyChallenges, ChallengeType } from "#app/data/challenge"; import MoveInfoOverlay from "#app/ui/move-info-overlay"; @@ -193,18 +193,14 @@ export default class PartyUiHandler extends MessageUiHandler { public static FilterNonFainted = (pokemon: PlayerPokemon) => { if (pokemon.isFainted()) { - return i18next.t("partyUiHandler:noEnergy", { - pokemonName: getPokemonNameWithAffix(pokemon), - }); + return i18next.t("partyUiHandler:noEnergy", { pokemonName: getPokemonNameWithAffix(pokemon, false) }); } return null; }; public static FilterFainted = (pokemon: PlayerPokemon) => { if (!pokemon.isFainted()) { - return i18next.t("partyUiHandler:hasEnergy", { - pokemonName: getPokemonNameWithAffix(pokemon), - }); + return i18next.t("partyUiHandler:hasEnergy", { pokemonName: getPokemonNameWithAffix(pokemon, false) }); } return null; }; @@ -215,12 +211,10 @@ export default class PartyUiHandler extends MessageUiHandler { * @returns */ private FilterChallengeLegal = (pokemon: PlayerPokemon) => { - const challengeAllowed = new Utils.BooleanHolder(true); + const challengeAllowed = new BooleanHolder(true); applyChallenges(ChallengeType.POKEMON_IN_BATTLE, pokemon, challengeAllowed); if (!challengeAllowed.value) { - return i18next.t("partyUiHandler:cantBeUsed", { - pokemonName: getPokemonNameWithAffix(pokemon), - }); + return i18next.t("partyUiHandler:cantBeUsed", { pokemonName: getPokemonNameWithAffix(pokemon, false) }); } return null; }; @@ -232,9 +226,7 @@ export default class PartyUiHandler extends MessageUiHandler { m => m instanceof PokemonHeldItemModifier && m.pokemonId === pokemon.id && m.matchType(modifier), ) as PokemonHeldItemModifier; if (matchingModifier && matchingModifier.stackCount === matchingModifier.getMaxStackCount()) { - return i18next.t("partyUiHandler:tooManyItems", { - pokemonName: getPokemonNameWithAffix(pokemon), - }); + return i18next.t("partyUiHandler:tooManyItems", { pokemonName: getPokemonNameWithAffix(pokemon, false) }); } return null; }; @@ -583,7 +575,7 @@ export default class PartyUiHandler extends MessageUiHandler { this.showText( i18next.t( pokemon.pauseEvolutions ? "partyUiHandler:pausedEvolutions" : "partyUiHandler:unpausedEvolutions", - { pokemonName: getPokemonNameWithAffix(pokemon) }, + { pokemonName: getPokemonNameWithAffix(pokemon, false) }, ), undefined, () => this.showText("", 0), @@ -596,14 +588,14 @@ export default class PartyUiHandler extends MessageUiHandler { this.showText( i18next.t("partyUiHandler:unspliceConfirmation", { fusionName: pokemon.fusionSpecies?.name, - pokemonName: pokemon.name, + pokemonName: pokemon.getName(), }), null, () => { ui.setModeWithoutClear( Mode.CONFIRM, () => { - const fusionName = pokemon.name; + const fusionName = pokemon.getName(); pokemon.unfuse().then(() => { this.clearPartySlots(); this.populatePartySlots(); @@ -611,7 +603,7 @@ export default class PartyUiHandler extends MessageUiHandler { this.showText( i18next.t("partyUiHandler:wasReverted", { fusionName: fusionName, - pokemonName: pokemon.name, + pokemonName: pokemon.getName(false), }), undefined, () => { @@ -637,7 +629,7 @@ export default class PartyUiHandler extends MessageUiHandler { this.blockInput = true; this.showText( i18next.t("partyUiHandler:releaseConfirmation", { - pokemonName: getPokemonNameWithAffix(pokemon), + pokemonName: getPokemonNameWithAffix(pokemon, false), }), null, () => { @@ -1201,7 +1193,7 @@ export default class PartyUiHandler extends MessageUiHandler { if (this.localizedOptions.includes(option)) { optionName = i18next.t(`partyUiHandler:${PartyOption[option]}`); } else { - optionName = Utils.toReadableString(PartyOption[option]); + optionName = toReadableString(PartyOption[option]); } } break; @@ -1285,7 +1277,7 @@ export default class PartyUiHandler extends MessageUiHandler { doRelease(slotIndex: number): void { this.showText( - this.getReleaseMessage(getPokemonNameWithAffix(globalScene.getPlayerParty()[slotIndex])), + this.getReleaseMessage(getPokemonNameWithAffix(globalScene.getPlayerParty()[slotIndex], false)), null, () => { this.clearPartySlots(); @@ -1309,7 +1301,7 @@ export default class PartyUiHandler extends MessageUiHandler { } getReleaseMessage(pokemonName: string): string { - const rand = Utils.randInt(128); + const rand = randInt(128); if (rand < 20) { return i18next.t("partyUiHandler:goodbye", { pokemonName: pokemonName }); } @@ -1495,7 +1487,7 @@ class PartySlot extends Phaser.GameObjects.Container { const slotInfoContainer = globalScene.add.container(0, 0); this.add(slotInfoContainer); - let displayName = this.pokemon.getNameToRender(); + let displayName = this.pokemon.getNameToRender(false); let nameTextWidth: number; const nameSizeTest = addTextObject(0, 0, displayName, TextStyle.PARTY); @@ -1566,7 +1558,7 @@ class PartySlot extends Phaser.GameObjects.Container { } if (this.pokemon.status) { - const statusIndicator = globalScene.add.sprite(0, 0, Utils.getLocalizedSpriteKey("statuses")); + const statusIndicator = globalScene.add.sprite(0, 0, getLocalizedSpriteKey("statuses")); statusIndicator.setFrame(StatusEffect[this.pokemon.status?.effect].toLowerCase()); statusIndicator.setOrigin(0, 0); statusIndicator.setPositionRelative(slotLevelLabel, this.slotIndex >= battlerCount ? 43 : 55, 0); @@ -1575,12 +1567,12 @@ class PartySlot extends Phaser.GameObjects.Container { } if (this.pokemon.isShiny()) { - const doubleShiny = this.pokemon.isFusion() && this.pokemon.shiny && this.pokemon.fusionShiny; + const doubleShiny = this.pokemon.isDoubleShiny(false); const shinyStar = globalScene.add.image(0, 0, `shiny_star_small${doubleShiny ? "_1" : ""}`); shinyStar.setOrigin(0, 0); shinyStar.setPositionRelative(this.slotName, -9, 3); - shinyStar.setTint(getVariantTint(!doubleShiny ? this.pokemon.getVariant() : this.pokemon.variant)); + shinyStar.setTint(getVariantTint(this.pokemon.getBaseVariant(doubleShiny))); slotInfoContainer.add(shinyStar); @@ -1588,7 +1580,9 @@ class PartySlot extends Phaser.GameObjects.Container { const fusionShinyStar = globalScene.add.image(0, 0, "shiny_star_small_2"); fusionShinyStar.setOrigin(0, 0); fusionShinyStar.setPosition(shinyStar.x, shinyStar.y); - fusionShinyStar.setTint(getVariantTint(this.pokemon.fusionVariant)); + fusionShinyStar.setTint( + getVariantTint(this.pokemon.summonData?.illusion?.basePokemon.fusionVariant ?? this.pokemon.fusionVariant), + ); slotInfoContainer.add(fusionShinyStar); } diff --git a/src/ui/pokedex-info-overlay.ts b/src/ui/pokedex-info-overlay.ts index 7dfa3745cb7..43e9bbc1a65 100644 --- a/src/ui/pokedex-info-overlay.ts +++ b/src/ui/pokedex-info-overlay.ts @@ -1,7 +1,7 @@ import type { InfoToggle } from "../battle-scene"; import { TextStyle, addTextObject } from "./text"; import { addWindow } from "./ui-theme"; -import * as Utils from "../utils"; +import { fixedInt } from "#app/utils"; import i18next from "i18next"; import { globalScene } from "#app/global-scene"; @@ -128,10 +128,10 @@ export default class PokedexInfoOverlay extends Phaser.GameObjects.Container imp // generate scrolling effects this.descScroll = globalScene.tweens.add({ targets: this.desc, - delay: Utils.fixedInt(2000), + delay: fixedInt(2000), loop: -1, - hold: Utils.fixedInt(2000), - duration: Utils.fixedInt((lineCount - 3) * 2000), + hold: fixedInt(2000), + duration: fixedInt((lineCount - 3) * 2000), y: `-=${14.83 * (72 / 96) * (lineCount - 3)}`, }); } @@ -154,7 +154,7 @@ export default class PokedexInfoOverlay extends Phaser.GameObjects.Container imp } globalScene.tweens.add({ targets: this.desc, - duration: Utils.fixedInt(125), + duration: fixedInt(125), ease: "Sine.easeInOut", alpha: visible ? 1 : 0, }); diff --git a/src/ui/pokedex-mon-container.ts b/src/ui/pokedex-mon-container.ts index e61da86e95e..410effda40d 100644 --- a/src/ui/pokedex-mon-container.ts +++ b/src/ui/pokedex-mon-container.ts @@ -1,4 +1,4 @@ -import type { Variant } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; import { globalScene } from "#app/global-scene"; import { isNullOrUndefined } from "#app/utils"; import type PokemonSpecies from "../data/pokemon-species"; diff --git a/src/ui/pokedex-page-ui-handler.ts b/src/ui/pokedex-page-ui-handler.ts index 062b4c3797c..407ebfcd843 100644 --- a/src/ui/pokedex-page-ui-handler.ts +++ b/src/ui/pokedex-page-ui-handler.ts @@ -1,7 +1,7 @@ import type { SpeciesFormEvolution } from "#app/data/balance/pokemon-evolutions"; import { pokemonEvolutions, pokemonPrevolutions, pokemonStarters } from "#app/data/balance/pokemon-evolutions"; -import type { Variant } from "#app/data/variant"; -import { getVariantTint, getVariantIcon } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; +import { getVariantTint, getVariantIcon } from "#app/sprites/variant"; import { argbFromRgba } from "@material/material-color-utilities"; import i18next from "i18next"; import { starterColors } from "#app/battle-scene"; @@ -54,7 +54,7 @@ import { toReadableString, } from "#app/utils"; import type { Nature } from "#enums/nature"; -import * as Utils from "../utils"; +import { getEnumKeys } from "#app/utils"; import { speciesTmMoves } from "#app/data/balance/tms"; import type { BiomeTierTod } from "#app/data/balance/biomes"; import { BiomePoolTier, catchableSpecies } from "#app/data/balance/biomes"; @@ -592,7 +592,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.menuContainer.setVisible(false); - this.menuOptions = Utils.getEnumKeys(MenuOptions).map(m => Number.parseInt(MenuOptions[m]) as MenuOptions); + this.menuOptions = getEnumKeys(MenuOptions).map(m => Number.parseInt(MenuOptions[m]) as MenuOptions); this.optionSelectText = addBBCodeTextObject( 0, @@ -696,7 +696,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.starterAttributes = this.initStarterPrefs(); - this.menuOptions = Utils.getEnumKeys(MenuOptions).map(m => Number.parseInt(MenuOptions[m]) as MenuOptions); + this.menuOptions = getEnumKeys(MenuOptions).map(m => Number.parseInt(MenuOptions[m]) as MenuOptions); this.menuContainer.setVisible(true); diff --git a/src/ui/pokedex-ui-handler.ts b/src/ui/pokedex-ui-handler.ts index 680b9d532e3..85279d90b46 100644 --- a/src/ui/pokedex-ui-handler.ts +++ b/src/ui/pokedex-ui-handler.ts @@ -1,5 +1,5 @@ -import type { Variant } from "#app/data/variant"; -import { getVariantTint, getVariantIcon } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; +import { getVariantTint, getVariantIcon } from "#app/sprites/variant"; import { argbFromRgba } from "@material/material-color-utilities"; import i18next from "i18next"; import { starterColors } from "#app/battle-scene"; diff --git a/src/ui/pokemon-hatch-info-container.ts b/src/ui/pokemon-hatch-info-container.ts index 99940b92351..692f0f1d374 100644 --- a/src/ui/pokemon-hatch-info-container.ts +++ b/src/ui/pokemon-hatch-info-container.ts @@ -1,7 +1,7 @@ import PokemonInfoContainer from "#app/ui/pokemon-info-container"; import { Gender } from "#app/data/gender"; import { PokemonType } from "#enums/pokemon-type"; -import * as Utils from "#app/utils"; +import { rgbHexToRgba, padInt } from "#app/utils"; import { TextStyle, addTextObject } from "#app/ui/text"; import { speciesEggMoves } from "#app/data/balance/egg-moves"; import { allMoves } from "#app/data/moves/move"; @@ -154,14 +154,14 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { super.show(pokemon, false, 1, hatchInfo.getDex(), hatchInfo.getStarterEntry(), true); const colorScheme = starterColors[species.speciesId]; - this.pokemonCandyIcon.setTint(argbFromRgba(Utils.rgbHexToRgba(colorScheme[0]))); + this.pokemonCandyIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[0]))); this.pokemonCandyIcon.setVisible(true); - this.pokemonCandyOverlayIcon.setTint(argbFromRgba(Utils.rgbHexToRgba(colorScheme[1]))); + this.pokemonCandyOverlayIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[1]))); this.pokemonCandyOverlayIcon.setVisible(true); this.pokemonCandyCountText.setText(`x${globalScene.gameData.starterData[species.speciesId].candyCount}`); this.pokemonCandyCountText.setVisible(true); - this.pokemonNumberText.setText(Utils.padInt(species.speciesId, 4)); + this.pokemonNumberText.setText(padInt(species.speciesId, 4)); this.pokemonNameText.setText(species.name); const hasEggMoves = species && speciesEggMoves.hasOwnProperty(species.speciesId); diff --git a/src/ui/pokemon-icon-anim-handler.ts b/src/ui/pokemon-icon-anim-handler.ts index c84ee2a0f9a..b6944c0fd84 100644 --- a/src/ui/pokemon-icon-anim-handler.ts +++ b/src/ui/pokemon-icon-anim-handler.ts @@ -1,5 +1,5 @@ import { globalScene } from "#app/global-scene"; -import * as Utils from "../utils"; +import { fixedInt } from "#app/utils"; export enum PokemonIconAnimMode { NONE, @@ -27,7 +27,7 @@ export default class PokemonIconAnimHandler { } }; globalScene.tweens.addCounter({ - duration: Utils.fixedInt(200), + duration: fixedInt(200), from: 0, to: 1, yoyo: true, diff --git a/src/ui/pokemon-info-container.ts b/src/ui/pokemon-info-container.ts index 56201f38748..0ccece46ab9 100644 --- a/src/ui/pokemon-info-container.ts +++ b/src/ui/pokemon-info-container.ts @@ -1,4 +1,4 @@ -import { getVariantTint } from "#app/data/variant"; +import { getVariantTint } from "#app/sprites/variant"; import type BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext"; import { globalScene } from "#app/global-scene"; import { Gender, getGenderColor, getGenderSymbol } from "../data/gender"; @@ -8,7 +8,7 @@ import type Pokemon from "../field/pokemon"; import i18next from "i18next"; import type { DexEntry, StarterDataEntry } from "../system/game-data"; import { DexAttr } from "../system/game-data"; -import * as Utils from "../utils"; +import { fixedInt } from "#app/utils"; import ConfirmUiHandler from "./confirm-ui-handler"; import { StatsContainer } from "./stats-container"; import { TextStyle, addBBCodeTextObject, addTextObject, getTextColor } from "./text"; @@ -393,7 +393,7 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { if (!eggInfo) { globalScene.tweens.add({ targets: this, - duration: Utils.fixedInt(Math.floor(750 / speedMultiplier)), + duration: fixedInt(Math.floor(750 / speedMultiplier)), ease: "Cubic.easeInOut", x: this.initialX - this.infoWindowWidth, onComplete: () => { @@ -403,9 +403,9 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { if (showMoves) { globalScene.tweens.add({ - delay: Utils.fixedInt(Math.floor(325 / speedMultiplier)), + delay: fixedInt(Math.floor(325 / speedMultiplier)), targets: this.pokemonMovesContainer, - duration: Utils.fixedInt(Math.floor(325 / speedMultiplier)), + duration: fixedInt(Math.floor(325 / speedMultiplier)), ease: "Cubic.easeInOut", x: this.movesContainerInitialX - 57, onComplete: () => resolve(), @@ -463,7 +463,7 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { return new Promise(resolve => { globalScene.tweens.add({ targets: this, - duration: Utils.fixedInt(Math.floor(150 / speedMultiplier)), + duration: fixedInt(Math.floor(150 / speedMultiplier)), ease: "Cubic.easeInOut", x: xPosition, onComplete: () => { @@ -482,14 +482,14 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { globalScene.tweens.add({ targets: this.pokemonMovesContainer, - duration: Utils.fixedInt(Math.floor(750 / speedMultiplier)), + duration: fixedInt(Math.floor(750 / speedMultiplier)), ease: "Cubic.easeInOut", x: this.movesContainerInitialX, }); globalScene.tweens.add({ targets: this, - duration: Utils.fixedInt(Math.floor(750 / speedMultiplier)), + duration: fixedInt(Math.floor(750 / speedMultiplier)), ease: "Cubic.easeInOut", x: this.initialX, onComplete: () => { diff --git a/src/ui/rename-form-ui-handler.ts b/src/ui/rename-form-ui-handler.ts index 91c0025d283..7083f83865b 100644 --- a/src/ui/rename-form-ui-handler.ts +++ b/src/ui/rename-form-ui-handler.ts @@ -38,7 +38,7 @@ export default class RenameFormUiHandler extends FormModalUiHandler { if (super.show(args)) { const config = args[0] as ModalConfig; if (args[1] && typeof (args[1] as PlayerPokemon).getNameToRender === "function") { - this.inputs[0].text = (args[1] as PlayerPokemon).getNameToRender(); + this.inputs[0].text = (args[1] as PlayerPokemon).getNameToRender(false); } else { this.inputs[0].text = args[1]; } diff --git a/src/ui/run-history-ui-handler.ts b/src/ui/run-history-ui-handler.ts index 85ea1e93e8d..ffc9d378d18 100644 --- a/src/ui/run-history-ui-handler.ts +++ b/src/ui/run-history-ui-handler.ts @@ -3,7 +3,7 @@ import { GameModes } from "../game-mode"; import { TextStyle, addTextObject } from "./text"; import { Mode } from "./ui"; import { addWindow } from "./ui-theme"; -import * as Utils from "../utils"; +import { fixedInt, formatLargeNumber } from "#app/utils"; import type PokemonData from "../system/pokemon-data"; import MessageUiHandler from "./message-ui-handler"; import i18next from "i18next"; @@ -218,7 +218,7 @@ export default class RunHistoryUiHandler extends MessageUiHandler { globalScene.tweens.add({ targets: this.runsContainer, y: this.runContainerInitialY - 56 * scrollCursor, - duration: Utils.fixedInt(325), + duration: fixedInt(325), ease: "Sine.easeInOut", }); } @@ -314,7 +314,7 @@ class RunEntryContainer extends Phaser.GameObjects.Container { const enemyLevel = addTextObject( 32, 20, - `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, + `${i18next.t("saveSlotSelectUiHandler:lv")}${formatLargeNumber(enemy.level, 1000)}`, TextStyle.PARTY, { fontSize: "54px", color: "#f8f8f8" }, ); @@ -408,7 +408,7 @@ class RunEntryContainer extends Phaser.GameObjects.Container { const text = addTextObject( 32, 20, - `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(pokemon.level, 1000)}`, + `${i18next.t("saveSlotSelectUiHandler:lv")}${formatLargeNumber(pokemon.level, 1000)}`, TextStyle.PARTY, { fontSize: "54px", color: "#f8f8f8" }, ); diff --git a/src/ui/run-info-ui-handler.ts b/src/ui/run-info-ui-handler.ts index 364cb8e4003..47de6a1a64d 100644 --- a/src/ui/run-info-ui-handler.ts +++ b/src/ui/run-info-ui-handler.ts @@ -5,7 +5,7 @@ import { TextStyle, addTextObject, addBBCodeTextObject, getTextColor } from "./t import { Mode } from "./ui"; import { addWindow } from "./ui-theme"; import { getPokeballAtlasKey } from "#app/data/pokeball"; -import * as Utils from "../utils"; +import { formatLargeNumber, getPlayTimeString, formatMoney, formatFancyLargeNumber } from "#app/utils"; import type PokemonData from "../system/pokemon-data"; import i18next from "i18next"; import { Button } from "../enums/buttons"; @@ -18,8 +18,9 @@ import { getTypeRgb } from "#app/data/type"; import { PokemonType } from "#enums/pokemon-type"; import { TypeColor, TypeShadow } from "#app/enums/color"; import { getNatureStatMultiplier, getNatureName } from "../data/nature"; -import { getVariantTint } from "#app/data/variant"; -import * as Modifier from "../modifier/modifier"; +import { getVariantTint } from "#app/sprites/variant"; +// biome-ignore lint/style/noNamespaceImport: See `src/system/game-data.ts` +import * as Modifier from "#app/modifier/modifier"; import type { Species } from "#enums/species"; import { PlayerGender } from "#enums/player-gender"; import { SettingKeyboard } from "#app/system/settings/settings-keyboard"; @@ -411,7 +412,7 @@ export default class RunInfoUiHandler extends UiHandler { const enemyLevel = addTextObject( 36, 26, - `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, + `${i18next.t("saveSlotSelectUiHandler:lv")}${formatLargeNumber(enemy.level, 1000)}`, enemyLevelStyle, { fontSize: "44px", color: "#f8f8f8" }, ); @@ -441,7 +442,7 @@ export default class RunInfoUiHandler extends UiHandler { const enemyLevel = addTextObject( 36, 26, - `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, + `${i18next.t("saveSlotSelectUiHandler:lv")}${formatLargeNumber(enemy.level, 1000)}`, bossStatus ? TextStyle.PARTY_RED : TextStyle.PARTY, { fontSize: "44px", color: "#f8f8f8" }, ); @@ -527,7 +528,7 @@ export default class RunInfoUiHandler extends UiHandler { const enemyLevel = addTextObject( 43 * (e % 3), 27 * (pokemonRowHeight + 1), - `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, + `${i18next.t("saveSlotSelectUiHandler:lv")}${formatLargeNumber(enemy.level, 1000)}`, isBoss ? TextStyle.PARTY_RED : TextStyle.PARTY, { fontSize: "54px" }, ); @@ -606,9 +607,9 @@ export default class RunInfoUiHandler extends UiHandler { fontSize: "50px", lineSpacing: lineSpacing, }); - const runTime = Utils.getPlayTimeString(this.runInfo.playTime); + const runTime = getPlayTimeString(this.runInfo.playTime); runInfoText.appendText(`${i18next.t("runHistory:runLength")}: ${runTime}`, false); - const runMoney = Utils.formatMoney(globalScene.moneyFormat, this.runInfo.money); + const runMoney = formatMoney(globalScene.moneyFormat, this.runInfo.money); const moneyTextColor = getTextColor(TextStyle.MONEY_WINDOW, false, globalScene.uiTheme); runInfoText.appendText( `[color=${moneyTextColor}]${i18next.t("battleScene:moneyOwned", { formattedMoney: runMoney })}[/color]`, @@ -770,7 +771,7 @@ export default class RunInfoUiHandler extends UiHandler { lineSpacing: lineSpacing, }); pokeInfoText.appendText( - `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatFancyLargeNumber(pokemon.level, 1)} - ${pNatureName}`, + `${i18next.t("saveSlotSelectUiHandler:lv")}${formatFancyLargeNumber(pokemon.level, 1)} - ${pNatureName}`, ); pokeInfoText.appendText(pAbilityInfo); pokeInfoText.appendText(pPassiveInfo); @@ -780,7 +781,7 @@ export default class RunInfoUiHandler extends UiHandler { // Colored Arrows (Red/Blue) are placed by stats that are boosted from natures const pokeStatTextContainer = globalScene.add.container(-35, 6); const pStats: string[] = []; - pokemon.stats.forEach(element => pStats.push(Utils.formatFancyLargeNumber(element, 1))); + pokemon.stats.forEach(element => pStats.push(formatFancyLargeNumber(element, 1))); for (let i = 0; i < pStats.length; i++) { const isMult = getNatureStatMultiplier(pNature, i); pStats[i] = isMult < 1 ? pStats[i] + "[color=#40c8f8]↓[/color]" : pStats[i]; diff --git a/src/ui/save-slot-select-ui-handler.ts b/src/ui/save-slot-select-ui-handler.ts index a1e9e5219b4..0c16e41bbef 100644 --- a/src/ui/save-slot-select-ui-handler.ts +++ b/src/ui/save-slot-select-ui-handler.ts @@ -2,10 +2,11 @@ import i18next from "i18next"; import { globalScene } from "#app/global-scene"; import { Button } from "#enums/buttons"; import { GameMode } from "../game-mode"; -import * as Modifier from "../modifier/modifier"; +// biome-ignore lint/style/noNamespaceImport: See `src/system/game-data.ts` +import * as Modifier from "#app/modifier/modifier"; import type { SessionSaveData } from "../system/game-data"; import type PokemonData from "../system/pokemon-data"; -import * as Utils from "../utils"; +import { isNullOrUndefined, fixedInt, getPlayTimeString, formatLargeNumber } from "#app/utils"; import MessageUiHandler from "./message-ui-handler"; import { TextStyle, addTextObject } from "./text"; import { Mode } from "./ui"; @@ -296,7 +297,7 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler { } this.setArrowVisibility(hasData); } - if (!Utils.isNullOrUndefined(prevSlotIndex)) { + if (!isNullOrUndefined(prevSlotIndex)) { this.revertSessionSlot(prevSlotIndex); } @@ -339,7 +340,7 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler { globalScene.tweens.add({ targets: this.sessionSlotsContainer, y: this.sessionSlotsContainerInitialY - 56 * scrollCursor, - duration: Utils.fixedInt(325), + duration: fixedInt(325), ease: "Sine.easeInOut", }); } @@ -407,7 +408,7 @@ class SessionSlot extends Phaser.GameObjects.Container { const timestampLabel = addTextObject(8, 19, new Date(data.timestamp).toLocaleString(), TextStyle.WINDOW); this.add(timestampLabel); - const playTimeLabel = addTextObject(8, 33, Utils.getPlayTimeString(data.playTime), TextStyle.WINDOW); + const playTimeLabel = addTextObject(8, 33, getPlayTimeString(data.playTime), TextStyle.WINDOW); this.add(playTimeLabel); const pokemonIconsContainer = globalScene.add.container(144, 4); @@ -421,7 +422,7 @@ class SessionSlot extends Phaser.GameObjects.Container { const text = addTextObject( 32, 20, - `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(pokemon.level, 1000)}`, + `${i18next.t("saveSlotSelectUiHandler:lv")}${formatLargeNumber(pokemon.level, 1000)}`, TextStyle.PARTY, { fontSize: "54px", color: "#f8f8f8" }, ); diff --git a/src/ui/saving-icon-handler.ts b/src/ui/saving-icon-handler.ts index 4404ea423b1..3db84f128a1 100644 --- a/src/ui/saving-icon-handler.ts +++ b/src/ui/saving-icon-handler.ts @@ -1,5 +1,5 @@ import { globalScene } from "#app/global-scene"; -import * as Utils from "../utils"; +import { fixedInt } from "#app/utils"; export default class SavingIconHandler extends Phaser.GameObjects.Container { private icon: Phaser.GameObjects.Sprite; @@ -36,10 +36,10 @@ export default class SavingIconHandler extends Phaser.GameObjects.Container { globalScene.tweens.add({ targets: this, alpha: 1, - duration: Utils.fixedInt(250), + duration: fixedInt(250), ease: "Sine.easeInOut", onComplete: () => { - globalScene.time.delayedCall(Utils.fixedInt(500), () => { + globalScene.time.delayedCall(fixedInt(500), () => { this.animActive = false; if (!this.shown) { this.hide(); @@ -64,7 +64,7 @@ export default class SavingIconHandler extends Phaser.GameObjects.Container { globalScene.tweens.add({ targets: this, alpha: 0, - duration: Utils.fixedInt(250), + duration: fixedInt(250), ease: "Sine.easeInOut", onComplete: () => { this.animActive = false; diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index 1e84b367791..3e2940f45b9 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -1,8 +1,8 @@ import type { CandyUpgradeNotificationChangedEvent } from "#app/events/battle-scene"; import { BattleSceneEventType } from "#app/events/battle-scene"; import { pokemonPrevolutions } from "#app/data/balance/pokemon-evolutions"; -import type { Variant } from "#app/data/variant"; -import { getVariantTint, getVariantIcon } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; +import { getVariantTint, getVariantIcon } from "#app/sprites/variant"; import { argbFromRgba } from "@material/material-color-utilities"; import i18next from "i18next"; import type BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext"; @@ -43,7 +43,7 @@ import { Egg } from "#app/data/egg"; import Overrides from "#app/overrides"; import { SettingKeyboard } from "#app/system/settings/settings-keyboard"; import { Passive as PassiveAttr } from "#enums/passive"; -import * as Challenge from "#app/data/challenge"; +import { applyChallenges, ChallengeType } from "#app/data/challenge"; import MoveInfoOverlay from "#app/ui/move-info-overlay"; import { getEggTierForSpecies } from "#app/data/egg"; import { Device } from "#enums/devices"; @@ -78,7 +78,6 @@ import { import type { Nature } from "#enums/nature"; import { PLAYER_PARTY_MAX_SIZE } from "#app/constants"; import { achvs } from "#app/system/achv"; -import * as Utils from "../utils"; import type { GameObjects } from "phaser"; import { checkStarterValidForChallenge } from "#app/data/challenge"; @@ -2518,7 +2517,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { case Button.CYCLE_TERA: if (this.canCycleTera) { const speciesForm = getPokemonSpeciesForm(this.lastSpecies.speciesId, starterAttributes.form ?? 0); - if (speciesForm.type1 === this.teraCursor && !Utils.isNullOrUndefined(speciesForm.type2)) { + if (speciesForm.type1 === this.teraCursor && !isNullOrUndefined(speciesForm.type2)) { starterAttributes.tera = speciesForm.type2!; this.setSpeciesDetails(this.lastSpecies, { teraType: speciesForm.type2!, @@ -2960,7 +2959,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { valueLimit.value = 10; } - Challenge.applyChallenges(Challenge.ChallengeType.STARTER_POINTS, valueLimit); + applyChallenges(ChallengeType.STARTER_POINTS, valueLimit); return valueLimit.value; } @@ -3748,7 +3747,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { ); // TODO: is this bang correct? this.abilityCursor = abilityIndex !== undefined ? abilityIndex : (abilityIndex = oldAbilityIndex); this.natureCursor = natureIndex !== undefined ? natureIndex : (natureIndex = oldNatureIndex); - this.teraCursor = !Utils.isNullOrUndefined(teraType) ? teraType : (teraType = species.type1); + this.teraCursor = !isNullOrUndefined(teraType) ? teraType : (teraType = species.type1); const [isInParty, partyIndex]: [boolean, number] = this.isInParty(species); // we use this to firstly check if the pokemon is in the party, and if so, to get the party index in order to update the icon image if (isInParty) { this.updatePartyIcon(species, partyIndex); @@ -3886,7 +3885,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.canCycleTera = !this.statsMode && globalScene.gameData.achvUnlocks.hasOwnProperty(achvs.TERASTALLIZE.id) && - !Utils.isNullOrUndefined(getPokemonSpeciesForm(species.speciesId, formIndex ?? 0).type2); + !isNullOrUndefined(getPokemonSpeciesForm(species.speciesId, formIndex ?? 0).type2); } if (dexEntry.caughtAttr && species.malePercent !== null) { @@ -4483,7 +4482,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.canCycleTera = !this.statsMode && globalScene.gameData.achvUnlocks.hasOwnProperty(achvs.TERASTALLIZE.id) && - !Utils.isNullOrUndefined(getPokemonSpeciesForm(this.lastSpecies.speciesId, formIndex ?? 0).type2); + !isNullOrUndefined(getPokemonSpeciesForm(this.lastSpecies.speciesId, formIndex ?? 0).type2); this.updateInstructions(); } } diff --git a/src/ui/summary-ui-handler.ts b/src/ui/summary-ui-handler.ts index 9b209ded57a..04bcf71d7ae 100644 --- a/src/ui/summary-ui-handler.ts +++ b/src/ui/summary-ui-handler.ts @@ -2,7 +2,16 @@ import { starterColors } from "#app/battle-scene"; import { globalScene } from "#app/global-scene"; import { Mode } from "#app/ui/ui"; import UiHandler from "#app/ui/ui-handler"; -import * as Utils from "#app/utils"; +import { + getLocalizedSpriteKey, + rgbHexToRgba, + padInt, + getEnumValues, + fixedInt, + isNullOrUndefined, + toReadableString, + formatStat, +} from "#app/utils"; import type { PlayerPokemon, PokemonMove } from "#app/field/pokemon"; import { getStarterValueFriendshipCap, speciesStarterCosts } from "#app/data/balance/starters"; import { argbFromRgba } from "@material/material-color-utilities"; @@ -19,8 +28,8 @@ import { StatusEffect } from "#enums/status-effect"; import { getBiomeName } from "#app/data/balance/biomes"; import { getNatureName, getNatureStatMultiplier } from "#app/data/nature"; import { loggedInUser } from "#app/account"; -import type { Variant } from "#app/data/variant"; -import { getVariantTint } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; +import { getVariantTint } from "#app/sprites/variant"; import { Button } from "#enums/buttons"; import type { Ability } from "#app/data/ability"; import i18next from "i18next"; @@ -255,7 +264,7 @@ export default class SummaryUiHandler extends UiHandler { this.statusContainer.add(statusLabel); - this.status = globalScene.add.sprite(91, 4, Utils.getLocalizedSpriteKey("statuses")); + this.status = globalScene.add.sprite(91, 4, getLocalizedSpriteKey("statuses")); this.status.setOrigin(0.5, 0); this.statusContainer.add(this.status); @@ -330,10 +339,10 @@ export default class SummaryUiHandler extends UiHandler { this.shinyOverlay.setVisible(this.pokemon.isShiny()); const colorScheme = starterColors[this.pokemon.species.getRootSpeciesId()]; - this.candyIcon.setTint(argbFromRgba(Utils.rgbHexToRgba(colorScheme[0]))); - this.candyOverlay.setTint(argbFromRgba(Utils.rgbHexToRgba(colorScheme[1]))); + this.candyIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[0]))); + this.candyOverlay.setTint(argbFromRgba(rgbHexToRgba(colorScheme[1]))); - this.numberText.setText(Utils.padInt(this.pokemon.species.speciesId, 4)); + this.numberText.setText(padInt(this.pokemon.species.speciesId, 4)); this.numberText.setColor(this.getTextColor(!this.pokemon.isShiny() ? TextStyle.SUMMARY : TextStyle.SUMMARY_GOLD)); this.numberText.setShadowColor( this.getTextColor(!this.pokemon.isShiny() ? TextStyle.SUMMARY : TextStyle.SUMMARY_GOLD, true), @@ -348,8 +357,14 @@ export default class SummaryUiHandler extends UiHandler { this.pokemonSprite.setPipelineData("isTerastallized", this.pokemon.isTerastallized); this.pokemonSprite.setPipelineData("ignoreTimeTint", true); this.pokemonSprite.setPipelineData("spriteKey", this.pokemon.getSpriteKey()); - this.pokemonSprite.setPipelineData("shiny", this.pokemon.shiny); - this.pokemonSprite.setPipelineData("variant", this.pokemon.variant); + this.pokemonSprite.setPipelineData( + "shiny", + this.pokemon.summonData?.illusion?.basePokemon.shiny ?? this.pokemon.shiny, + ); + this.pokemonSprite.setPipelineData( + "variant", + this.pokemon.summonData?.illusion?.basePokemon.variant ?? this.pokemon.variant, + ); ["spriteColors", "fusionSpriteColors"].map(k => { delete this.pokemonSprite.pipelineData[`${k}Base`]; if (this.pokemon?.summonData?.speciesForm) { @@ -359,7 +374,7 @@ export default class SummaryUiHandler extends UiHandler { }); this.pokemon.cry(); - this.nameText.setText(this.pokemon.getNameToRender()); + this.nameText.setText(this.pokemon.getNameToRender(false)); const isFusion = this.pokemon.isFusion(); @@ -417,8 +432,8 @@ export default class SummaryUiHandler extends UiHandler { this.friendshipShadow.setCrop(0, 0, 16, 16 - 16 * ((this.pokemon?.friendship || 0) / 255)); - const doubleShiny = isFusion && this.pokemon.shiny && this.pokemon.fusionShiny; - const baseVariant = !doubleShiny ? this.pokemon.getVariant() : this.pokemon.variant; + const doubleShiny = this.pokemon.isDoubleShiny(false); + const baseVariant = this.pokemon.getBaseVariant(doubleShiny); this.shinyIcon.setPositionRelative( this.nameText, @@ -426,7 +441,7 @@ export default class SummaryUiHandler extends UiHandler { 3, ); this.shinyIcon.setTexture(`shiny_star${doubleShiny ? "_1" : ""}`); - this.shinyIcon.setVisible(this.pokemon.isShiny()); + this.shinyIcon.setVisible(this.pokemon.isShiny(false)); this.shinyIcon.setTint(getVariantTint(baseVariant)); if (this.shinyIcon.visible) { const shinyDescriptor = @@ -446,7 +461,9 @@ export default class SummaryUiHandler extends UiHandler { this.fusionShinyIcon.setPosition(this.shinyIcon.x, this.shinyIcon.y); this.fusionShinyIcon.setVisible(doubleShiny); if (isFusion) { - this.fusionShinyIcon.setTint(getVariantTint(this.pokemon.fusionVariant)); + this.fusionShinyIcon.setTint( + getVariantTint(this.pokemon.summonData?.illusion?.basePokemon.fusionVariant ?? this.pokemon.fusionVariant), + ); } this.pokeball.setFrame(getPokeballAtlasKey(this.pokemon.pokeball)); @@ -600,7 +617,7 @@ export default class SummaryUiHandler extends UiHandler { } success = true; } else { - const pages = Utils.getEnumValues(Page); + const pages = getEnumValues(Page); switch (button) { case Button.UP: case Button.DOWN: { @@ -675,10 +692,10 @@ export default class SummaryUiHandler extends UiHandler { if (moveDescriptionLineCount > 3) { this.descriptionScrollTween = globalScene.tweens.add({ targets: this.moveDescriptionText, - delay: Utils.fixedInt(2000), + delay: fixedInt(2000), loop: -1, - hold: Utils.fixedInt(2000), - duration: Utils.fixedInt((moveDescriptionLineCount - 3) * 2000), + hold: fixedInt(2000), + duration: fixedInt((moveDescriptionLineCount - 3) * 2000), y: `-=${14.83 * (moveDescriptionLineCount - 3)}`, }); } @@ -697,10 +714,10 @@ export default class SummaryUiHandler extends UiHandler { this.moveCursorObj.setVisible(true); this.moveCursorBlinkTimer = globalScene.time.addEvent({ loop: true, - delay: Utils.fixedInt(600), + delay: fixedInt(600), callback: () => { this.moveCursorObj?.setVisible(false); - globalScene.time.delayedCall(Utils.fixedInt(100), () => { + globalScene.time.delayedCall(fixedInt(100), () => { if (!this.moveCursorObj) { return; } @@ -818,7 +835,7 @@ export default class SummaryUiHandler extends UiHandler { const getTypeIcon = (index: number, type: PokemonType, tera = false) => { const xCoord = typeLabel.width * typeLabel.scale + 9 + 34 * index; const typeIcon = !tera - ? globalScene.add.sprite(xCoord, 42, Utils.getLocalizedSpriteKey("types"), PokemonType[type].toLowerCase()) + ? globalScene.add.sprite(xCoord, 42, getLocalizedSpriteKey("types"), PokemonType[type].toLowerCase()) : globalScene.add.sprite(xCoord, 42, "type_tera"); if (tera) { typeIcon.setScale(0.5); @@ -829,7 +846,7 @@ export default class SummaryUiHandler extends UiHandler { return typeIcon; }; - const types = this.pokemon?.getTypes(false, false, true)!; // TODO: is this bang correct? + const types = this.pokemon?.getTypes(false, false, true, false)!; // TODO: is this bang correct? profileContainer.add(getTypeIcon(0, types[0])); if (types.length > 1) { profileContainer.add(getTypeIcon(1, types[1])); @@ -853,7 +870,7 @@ export default class SummaryUiHandler extends UiHandler { if ( globalScene.gameData.achvUnlocks.hasOwnProperty(achvs.TERASTALLIZE.id) && - !Utils.isNullOrUndefined(this.pokemon) + !isNullOrUndefined(this.pokemon) ) { const teraIcon = globalScene.add.sprite(123, 26, "button_tera"); teraIcon.setName("terrastallize-icon"); @@ -925,10 +942,10 @@ export default class SummaryUiHandler extends UiHandler { abilityInfo.descriptionText.setY(69); this.descriptionScrollTween = globalScene.tweens.add({ targets: abilityInfo.descriptionText, - delay: Utils.fixedInt(2000), + delay: fixedInt(2000), loop: -1, - hold: Utils.fixedInt(2000), - duration: Utils.fixedInt((abilityDescriptionLineCount - 2) * 2000), + hold: fixedInt(2000), + duration: fixedInt((abilityDescriptionLineCount - 2) * 2000), y: `-=${14.83 * (abilityDescriptionLineCount - 2)}`, }); } @@ -939,8 +956,8 @@ export default class SummaryUiHandler extends UiHandler { this.passiveContainer?.descriptionText?.setVisible(false); const closeFragment = getBBCodeFrag("", TextStyle.WINDOW_ALT); - const rawNature = Utils.toReadableString(Nature[this.pokemon?.getNature()!]); // TODO: is this bang correct? - const nature = `${getBBCodeFrag(Utils.toReadableString(getNatureName(this.pokemon?.getNature()!)), TextStyle.SUMMARY_RED)}${closeFragment}`; // TODO: is this bang correct? + const rawNature = toReadableString(Nature[this.pokemon?.getNature()!]); // TODO: is this bang correct? + const nature = `${getBBCodeFrag(toReadableString(getNatureName(this.pokemon?.getNature()!)), TextStyle.SUMMARY_RED)}${closeFragment}`; // TODO: is this bang correct? const memoString = i18next.t("pokemonSummary:memoString", { metFragment: i18next.t( @@ -999,8 +1016,8 @@ export default class SummaryUiHandler extends UiHandler { const statValueText = stat !== Stat.HP - ? Utils.formatStat(this.pokemon?.getStat(stat)!) // TODO: is this bang correct? - : `${Utils.formatStat(this.pokemon?.hp!, true)}/${Utils.formatStat(this.pokemon?.getMaxHp()!, true)}`; // TODO: are those bangs correct? + ? formatStat(this.pokemon?.getStat(stat)!) // TODO: is this bang correct? + : `${formatStat(this.pokemon?.hp!, true)}/${formatStat(this.pokemon?.getMaxHp()!, true)}`; // TODO: are those bangs correct? const ivText = `${this.pokemon?.ivs[stat]}/31`; const statValue = addTextObject(93 + 88 * colIndex, 16 * rowIndex, statValueText, TextStyle.WINDOW_ALT); @@ -1106,7 +1123,7 @@ export default class SummaryUiHandler extends UiHandler { this.extraMoveRowContainer.setVisible(true); if (this.newMove && this.pokemon) { - const spriteKey = Utils.getLocalizedSpriteKey("types"); + const spriteKey = getLocalizedSpriteKey("types"); const moveType = this.pokemon.getMoveType(this.newMove); const newMoveTypeIcon = globalScene.add.sprite(0, 0, spriteKey, PokemonType[moveType].toLowerCase()); newMoveTypeIcon.setOrigin(0, 1); @@ -1116,7 +1133,7 @@ export default class SummaryUiHandler extends UiHandler { ppOverlay.setOrigin(0, 1); this.extraMoveRowContainer.add(ppOverlay); - const pp = Utils.padInt(this.newMove?.pp!, 2, " "); // TODO: is this bang correct? + const pp = padInt(this.newMove?.pp!, 2, " "); // TODO: is this bang correct? const ppText = addTextObject(173, 1, `${pp}/${pp}`, TextStyle.WINDOW); ppText.setOrigin(0, 1); this.extraMoveRowContainer.add(ppText); @@ -1132,7 +1149,7 @@ export default class SummaryUiHandler extends UiHandler { this.moveRowsContainer.add(moveRowContainer); if (move && this.pokemon) { - const spriteKey = Utils.getLocalizedSpriteKey("types"); + const spriteKey = getLocalizedSpriteKey("types"); const moveType = this.pokemon.getMoveType(move.getMove()); const typeIcon = globalScene.add.sprite(0, 0, spriteKey, PokemonType[moveType].toLowerCase()); typeIcon.setOrigin(0, 1); @@ -1153,7 +1170,7 @@ export default class SummaryUiHandler extends UiHandler { if (move) { const maxPP = move.getMovePp(); const pp = maxPP - move.ppUsed; - ppText.setText(`${Utils.padInt(pp, 2, " ")}/${Utils.padInt(maxPP, 2, " ")}`); + ppText.setText(`${padInt(pp, 2, " ")}/${padInt(maxPP, 2, " ")}`); } moveRowContainer.add(ppText); diff --git a/src/ui/target-select-ui-handler.ts b/src/ui/target-select-ui-handler.ts index d2f72ef4a4c..a9f88b337f3 100644 --- a/src/ui/target-select-ui-handler.ts +++ b/src/ui/target-select-ui-handler.ts @@ -1,7 +1,7 @@ import { BattlerIndex } from "../battle"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; -import * as Utils from "../utils"; +import { isNullOrUndefined, fixedInt } from "#app/utils"; import { getMoveTargets } from "../data/moves/move"; import { Button } from "#enums/buttons"; import type { Moves } from "#enums/moves"; @@ -70,7 +70,7 @@ export default class TargetSelectUiHandler extends UiHandler { * @param user the Pokemon using the move */ resetCursor(cursorN: number, user: Pokemon): void { - if (!Utils.isNullOrUndefined(cursorN)) { + if (!isNullOrUndefined(cursorN)) { if ([BattlerIndex.PLAYER, BattlerIndex.PLAYER_2].includes(cursorN) || user.battleSummonData.waveTurnCount === 1) { // Reset cursor on the first turn of a fight or if an ally was targeted last turn cursorN = -1; @@ -89,11 +89,11 @@ export default class TargetSelectUiHandler extends UiHandler { this.targetSelectCallback(button === Button.ACTION ? targetIndexes : []); success = true; if (this.fieldIndex === BattlerIndex.PLAYER) { - if (Utils.isNullOrUndefined(this.cursor0) || this.cursor0 !== this.cursor) { + if (isNullOrUndefined(this.cursor0) || this.cursor0 !== this.cursor) { this.cursor0 = this.cursor; } } else if (this.fieldIndex === BattlerIndex.PLAYER_2) { - if (Utils.isNullOrUndefined(this.cursor1) || this.cursor1 !== this.cursor) { + if (isNullOrUndefined(this.cursor1) || this.cursor1 !== this.cursor) { this.cursor1 = this.cursor; } } @@ -152,7 +152,7 @@ export default class TargetSelectUiHandler extends UiHandler { key: { start: 1, to: 0.25 }, loop: -1, loopDelay: 150, - duration: Utils.fixedInt(450), + duration: fixedInt(450), ease: "Sine.easeInOut", yoyo: true, onUpdate: t => { @@ -178,7 +178,7 @@ export default class TargetSelectUiHandler extends UiHandler { targets: [info], y: { start: info.getBaseY(), to: info.getBaseY() + 1 }, loop: -1, - duration: Utils.fixedInt(250), + duration: fixedInt(250), ease: "Linear", yoyo: true, }), diff --git a/src/ui/time-of-day-widget.ts b/src/ui/time-of-day-widget.ts index bda1f750cb1..5e42e6215f8 100644 --- a/src/ui/time-of-day-widget.ts +++ b/src/ui/time-of-day-widget.ts @@ -1,4 +1,4 @@ -import * as Utils from "../utils"; +import { fixedInt } from "#app/utils"; import { globalScene } from "#app/global-scene"; import { BattleSceneEventType } from "../events/battle-scene"; import { EaseType } from "#enums/ease-type"; @@ -75,14 +75,14 @@ export default class TimeOfDayWidget extends Phaser.GameObjects.Container { const rotate = { targets: [this.timeOfDayIconMgs[0], this.timeOfDayIconMgs[1]], angle: "+=90", - duration: Utils.fixedInt(1500), + duration: fixedInt(1500), ease: "Back.easeOut", paused: !this.parentVisible, }; const fade = { targets: [this.timeOfDayIconBgs[1], this.timeOfDayIconMgs[1], this.timeOfDayIconFgs[1]], alpha: 0, - duration: Utils.fixedInt(500), + duration: fixedInt(500), ease: "Linear", paused: !this.parentVisible, }; @@ -98,14 +98,14 @@ export default class TimeOfDayWidget extends Phaser.GameObjects.Container { const bounce = { targets: [this.timeOfDayIconMgs[0], this.timeOfDayIconMgs[1]], angle: "+=90", - duration: Utils.fixedInt(2000), + duration: fixedInt(2000), ease: "Bounce.easeOut", paused: !this.parentVisible, }; const fade = { targets: [this.timeOfDayIconBgs[1], this.timeOfDayIconMgs[1], this.timeOfDayIconFgs[1]], alpha: 0, - duration: Utils.fixedInt(800), + duration: fixedInt(800), ease: "Linear", paused: !this.parentVisible, }; diff --git a/src/ui/title-ui-handler.ts b/src/ui/title-ui-handler.ts index d87d4e5ca79..405e3cc4a27 100644 --- a/src/ui/title-ui-handler.ts +++ b/src/ui/title-ui-handler.ts @@ -1,6 +1,6 @@ import OptionSelectUiHandler from "./settings/option-select-ui-handler"; import { Mode } from "./ui"; -import * as Utils from "../utils"; +import { fixedInt, randInt, randItem } from "#app/utils"; import { TextStyle, addTextObject } from "./text"; import { getSplashMessages } from "../data/splash-messages"; import i18next from "i18next"; @@ -72,7 +72,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { globalScene.tweens.add({ targets: this.splashMessageText, - duration: Utils.fixedInt(350), + duration: fixedInt(350), scale: originalSplashMessageScale * 1.25, loop: -1, yoyo: true, @@ -104,7 +104,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { /** Used solely to display a random Pokémon name in a splash message. */ randomPokemon(): void { - const rand = Utils.randInt(1025, 1); + const rand = randInt(1025, 1); const pokemon = getPokemonSpecies(rand as Species); if ( this.splashMessage === "splashMessages:underratedPokemon" || @@ -132,7 +132,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { // Moving player count to top of the menu this.playerCountLabel.setY(globalScene.game.canvas.height / 6 - 13 - this.getWindowHeight()); - this.splashMessage = Utils.randItem(getSplashMessages()); + this.splashMessage = randItem(getSplashMessages()); this.splashMessageText.setText( i18next.t(this.splashMessage, { count: TitleUiHandler.BATTLES_WON_FALLBACK, @@ -159,7 +159,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { globalScene.tweens.add({ targets: [this.titleContainer, ui.getMessageHandler().bg], - duration: Utils.fixedInt(325), + duration: fixedInt(325), alpha: (target: any) => (target === this.titleContainer ? 1 : 0), ease: "Sine.easeInOut", }); @@ -180,7 +180,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { globalScene.tweens.add({ targets: [this.titleContainer, ui.getMessageHandler().bg], - duration: Utils.fixedInt(325), + duration: fixedInt(325), alpha: (target: any) => (target === this.titleContainer ? 0 : 1), ease: "Sine.easeInOut", }); diff --git a/src/ui/ui.ts b/src/ui/ui.ts index 6605e5ef730..c7981cd5fba 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -28,7 +28,7 @@ import { addWindow } from "./ui-theme"; import LoginFormUiHandler from "./login-form-ui-handler"; import RegistrationFormUiHandler from "./registration-form-ui-handler"; import LoadingModalUiHandler from "./loading-modal-ui-handler"; -import * as Utils from "../utils"; +import { executeIf } from "#app/utils"; import GameStatsUiHandler from "./game-stats-ui-handler"; import AwaitableUiHandler from "./awaitable-ui-handler"; import SaveSlotSelectUiHandler from "./save-slot-select-ui-handler"; @@ -674,7 +674,7 @@ export default class UI extends Phaser.GameObjects.Container { if (!this?.modeChain?.length) { return resolve(); } - this.revertMode().then(success => Utils.executeIf(success, this.revertModes).then(() => resolve())); + this.revertMode().then(success => executeIf(success, this.revertModes).then(() => resolve())); }); } diff --git a/src/ui/unavailable-modal-ui-handler.ts b/src/ui/unavailable-modal-ui-handler.ts index 3007f7247f1..01ed850f6d0 100644 --- a/src/ui/unavailable-modal-ui-handler.ts +++ b/src/ui/unavailable-modal-ui-handler.ts @@ -3,7 +3,7 @@ import { ModalUiHandler } from "./modal-ui-handler"; import { addTextObject, TextStyle } from "./text"; import type { Mode } from "./ui"; import { updateUserInfo } from "#app/account"; -import * as Utils from "#app/utils"; +import { removeCookie, sessionIdKey } from "#app/utils"; import i18next from "i18next"; import { globalScene } from "#app/global-scene"; @@ -65,7 +65,7 @@ export default class UnavailableModalUiHandler extends ModalUiHandler { globalScene.playSound("se/pb_bounce_1"); this.reconnectCallback(); } else if (response[1] === 401) { - Utils.removeCookie(Utils.sessionIdKey); + removeCookie(sessionIdKey); globalScene.reset(true, true); } else { this.reconnectDuration = Math.min(this.reconnectDuration * 2, this.maxTime); // Set a max delay so it isn't infinite diff --git a/src/utils.ts b/src/utils.ts index 4092b68b405..2f05e2724ff 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -613,3 +613,25 @@ export function animationFileName(move: Moves): string { export function camelCaseToKebabCase(str: string): string { return str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (s, o) => (o ? "-" : "") + s.toLowerCase()); } + +/** + * Merges the two objects, such that for each property in `b` that matches a property in `a`, + * the value in `a` is replaced by the value in `b`. This is done recursively if the property is a non-array object + * + * If the property does not exist in `a` or its `typeof` evaluates differently, the property is skipped. + * If the value of the property is an array, the array is replaced. If it is any other object, the object is merged recursively. + */ +// biome-ignore lint/complexity/noBannedTypes: This function is designed to merge json objects +export function deepMergeObjects(a: Object, b: Object) { + for (const key in b) { + // !(key in a) is redundant here, yet makes it clear that we're explicitly interested in properties that exist in `a` + if (!(key in a) || typeof a[key] !== typeof b[key]) { + continue; + } + if (typeof b[key] === "object" && !Array.isArray(b[key])) { + deepMergeObjects(a[key], b[key]); + } else { + a[key] = b[key]; + } + } +} diff --git a/test/abilities/illusion.test.ts b/test/abilities/illusion.test.ts new file mode 100644 index 00000000000..aa77aa701b2 --- /dev/null +++ b/test/abilities/illusion.test.ts @@ -0,0 +1,144 @@ +import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; +import Phaser from "phaser"; +import GameManager from "#test/testUtils/gameManager"; +import { Species } from "#enums/species"; +import { TurnEndPhase } from "#app/phases/turn-end-phase"; +import { Moves } from "#enums/moves"; +import { Abilities } from "#enums/abilities"; +import { PokeballType } from "#app/enums/pokeball"; +import { Gender } from "#app/data/gender"; + +describe("Abilities - Illusion", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + game.override.battleType("single"); + game.override.enemySpecies(Species.ZORUA); + game.override.enemyAbility(Abilities.ILLUSION); + game.override.enemyMoveset(Moves.TACKLE); + game.override.enemyHeldItems([{ name: "WIDE_LENS", count: 3 }]); + + game.override.moveset([Moves.WORRY_SEED, Moves.SOAK, Moves.TACKLE]); + game.override.startingHeldItems([{ name: "WIDE_LENS", count: 3 }]); + }); + + it("creates illusion at the start", async () => { + await game.classicMode.startBattle([Species.ZOROARK, Species.AXEW]); + const zoroark = game.scene.getPlayerPokemon()!; + const zorua = game.scene.getEnemyPokemon()!; + + expect(!!zoroark.summonData?.illusion).equals(true); + expect(!!zorua.summonData?.illusion).equals(true); + }); + + it("break after receiving damaging move", async () => { + await game.classicMode.startBattle([Species.AXEW]); + game.move.select(Moves.TACKLE); + + await game.phaseInterceptor.to(TurnEndPhase); + + const zorua = game.scene.getEnemyPokemon()!; + + expect(!!zorua.summonData?.illusion).equals(false); + expect(zorua.name).equals("Zorua"); + }); + + it("break after getting ability changed", async () => { + await game.classicMode.startBattle([Species.AXEW]); + game.move.select(Moves.WORRY_SEED); + + await game.phaseInterceptor.to(TurnEndPhase); + + const zorua = game.scene.getEnemyPokemon()!; + + expect(!!zorua.summonData?.illusion).equals(false); + }); + + it("break if the ability is suppressed", async () => { + game.override.enemyAbility(Abilities.NEUTRALIZING_GAS); + await game.classicMode.startBattle([Species.KOFFING]); + + const zorua = game.scene.getEnemyPokemon()!; + + expect(!!zorua.summonData?.illusion).equals(false); + }); + + it("causes enemy AI to consider the illusion's type instead of the actual type when considering move effectiveness", async () => { + game.override.enemyMoveset([Moves.FLAMETHROWER, Moves.PSYCHIC, Moves.TACKLE]); + await game.classicMode.startBattle([Species.ZOROARK, Species.AXEW]); + + const enemy = game.scene.getEnemyPokemon()!; + const zoroark = game.scene.getPlayerPokemon()!; + + const flameThrower = enemy.getMoveset()[0]!.getMove(); + const psychic = enemy.getMoveset()[1]!.getMove(); + const flameThrowerEffectiveness = zoroark.getAttackTypeEffectiveness( + flameThrower.type, + enemy, + undefined, + undefined, + flameThrower, + true, + ); + const psychicEffectiveness = zoroark.getAttackTypeEffectiveness( + psychic.type, + enemy, + undefined, + undefined, + psychic, + true, + ); + expect(psychicEffectiveness).above(flameThrowerEffectiveness); + }); + + it("does not break from indirect damage", async () => { + game.override.enemySpecies(Species.GIGALITH); + game.override.enemyAbility(Abilities.SAND_STREAM); + game.override.enemyMoveset(Moves.WILL_O_WISP); + game.override.moveset([Moves.FLARE_BLITZ]); + + await game.classicMode.startBattle([Species.ZOROARK, Species.AZUMARILL]); + + game.move.select(Moves.FLARE_BLITZ); + + await game.phaseInterceptor.to(TurnEndPhase); + + const zoroark = game.scene.getPlayerPokemon()!; + + expect(!!zoroark.summonData?.illusion).equals(true); + }); + + it("copies the the name, nickname, gender, shininess, and pokeball from the illusion source", async () => { + game.override.enemyMoveset(Moves.SPLASH); + await game.classicMode.startBattle([Species.ABRA, Species.ZOROARK, Species.AXEW]); + const axew = game.scene.getPlayerParty().at(2)!; + axew.shiny = true; + axew.nickname = btoa(unescape(encodeURIComponent("axew nickname"))); + axew.gender = Gender.FEMALE; + axew.pokeball = PokeballType.GREAT_BALL; + + game.doSwitchPokemon(1); + + await game.phaseInterceptor.to(TurnEndPhase); + + const zoroark = game.scene.getPlayerPokemon()!; + + expect(zoroark.name).equals("Axew"); + expect(zoroark.getNameToRender()).equals("axew nickname"); + expect(zoroark.getGender(false, true)).equals(Gender.FEMALE); + expect(zoroark.isShiny(true)).equals(true); + expect(zoroark.getPokeball(true)).equals(PokeballType.GREAT_BALL); + }); +}); diff --git a/test/escape-calculations.test.ts b/test/escape-calculations.test.ts index 0cbf11dd230..b4504c7359c 100644 --- a/test/escape-calculations.test.ts +++ b/test/escape-calculations.test.ts @@ -1,7 +1,7 @@ import { AttemptRunPhase } from "#app/phases/attempt-run-phase"; import type { CommandPhase } from "#app/phases/command-phase"; import { Command } from "#app/ui/command-ui-handler"; -import * as Utils from "#app/utils"; +import { NumberHolder } from "#app/utils"; import { Abilities } from "#enums/abilities"; import { Species } from "#enums/species"; import GameManager from "#test/testUtils/gameManager"; @@ -45,7 +45,7 @@ describe("Escape chance calculations", () => { await game.phaseInterceptor.to(AttemptRunPhase, false); const phase = game.scene.getCurrentPhase() as AttemptRunPhase; - const escapePercentage = new Utils.NumberHolder(0); + const escapePercentage = new NumberHolder(0); // this sets up an object for multiple attempts. The pokemonSpeedRatio is your speed divided by the enemy speed, the escapeAttempts are the number of escape attempts and the expectedEscapeChance is the chance it should be escaping const escapeChances: { @@ -118,7 +118,7 @@ describe("Escape chance calculations", () => { await game.phaseInterceptor.to(AttemptRunPhase, false); const phase = game.scene.getCurrentPhase() as AttemptRunPhase; - const escapePercentage = new Utils.NumberHolder(0); + const escapePercentage = new NumberHolder(0); // this sets up an object for multiple attempts. The pokemonSpeedRatio is your speed divided by the enemy speed, the escapeAttempts are the number of escape attempts and the expectedEscapeChance is the chance it should be escaping const escapeChances: { @@ -197,7 +197,7 @@ describe("Escape chance calculations", () => { await game.phaseInterceptor.to(AttemptRunPhase, false); const phase = game.scene.getCurrentPhase() as AttemptRunPhase; - const escapePercentage = new Utils.NumberHolder(0); + const escapePercentage = new NumberHolder(0); // this sets up an object for multiple attempts. The pokemonSpeedRatio is your speed divided by the enemy speed, the escapeAttempts are the number of escape attempts and the expectedEscapeChance is the chance it should be escaping const escapeChances: { @@ -284,7 +284,7 @@ describe("Escape chance calculations", () => { await game.phaseInterceptor.to(AttemptRunPhase, false); const phase = game.scene.getCurrentPhase() as AttemptRunPhase; - const escapePercentage = new Utils.NumberHolder(0); + const escapePercentage = new NumberHolder(0); // this sets up an object for multiple attempts. The pokemonSpeedRatio is your speed divided by the enemy speed, the escapeAttempts are the number of escape attempts and the expectedEscapeChance is the chance it should be escaping const escapeChances: { diff --git a/test/items/exp_booster.test.ts b/test/items/exp_booster.test.ts index e4491b22637..2b1308f1afb 100644 --- a/test/items/exp_booster.test.ts +++ b/test/items/exp_booster.test.ts @@ -1,6 +1,6 @@ import { Abilities } from "#app/enums/abilities"; import { PokemonExpBoosterModifier } from "#app/modifier/modifier"; -import * as Utils from "#app/utils"; +import { NumberHolder } from "#app/utils"; import GameManager from "#test/testUtils/gameManager"; import Phase from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; @@ -33,7 +33,7 @@ describe("EXP Modifier Items", () => { const partyMember = game.scene.getPlayerPokemon()!; partyMember.exp = 100; - const expHolder = new Utils.NumberHolder(partyMember.exp); + const expHolder = new NumberHolder(partyMember.exp); game.scene.applyModifiers(PokemonExpBoosterModifier, true, partyMember, expHolder); expect(expHolder.value).toBe(440); }, 20000); diff --git a/test/items/leek.test.ts b/test/items/leek.test.ts index ec4d075fe19..afb31a5f9fa 100644 --- a/test/items/leek.test.ts +++ b/test/items/leek.test.ts @@ -1,5 +1,5 @@ import { TurnEndPhase } from "#app/phases/turn-end-phase"; -import * as Utils from "#app/utils"; +import { randInt } from "#app/utils"; import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; import GameManager from "#test/testUtils/gameManager"; @@ -78,7 +78,7 @@ describe("Items - Leek", () => { // Randomly choose from the Farfetch'd line const species = [Species.FARFETCHD, Species.GALAR_FARFETCHD, Species.SIRFETCHD]; - await game.startBattle([species[Utils.randInt(species.length)], Species.PIKACHU]); + await game.startBattle([species[randInt(species.length)], Species.PIKACHU]); const [partyMember, ally] = game.scene.getPlayerParty(); @@ -106,7 +106,7 @@ describe("Items - Leek", () => { // Randomly choose from the Farfetch'd line const species = [Species.FARFETCHD, Species.GALAR_FARFETCHD, Species.SIRFETCHD]; - await game.startBattle([Species.PIKACHU, species[Utils.randInt(species.length)]]); + await game.startBattle([Species.PIKACHU, species[randInt(species.length)]]); const [partyMember, ally] = game.scene.getPlayerParty(); diff --git a/test/items/light_ball.test.ts b/test/items/light_ball.test.ts index e4959002904..1f5227142eb 100644 --- a/test/items/light_ball.test.ts +++ b/test/items/light_ball.test.ts @@ -2,7 +2,7 @@ import { Stat } from "#enums/stat"; import { SpeciesStatBoosterModifier } from "#app/modifier/modifier"; import { modifierTypes } from "#app/modifier/modifier-type"; import i18next from "#app/plugins/i18n"; -import * as Utils from "#app/utils"; +import { NumberHolder } from "#app/utils"; import { Species } from "#enums/species"; import GameManager from "#test/testUtils/gameManager"; import Phase from "phaser"; @@ -90,9 +90,9 @@ describe("Items - Light Ball", () => { const spAtkStat = partyMember.getStat(Stat.SPATK); // Making sure modifier is not applied without holding item - const atkValue = new Utils.NumberHolder(atkStat); + const atkValue = new NumberHolder(atkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); - const spAtkValue = new Utils.NumberHolder(spAtkStat); + const spAtkValue = new NumberHolder(spAtkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); expect(atkValue.value / atkStat).toBe(1); @@ -129,9 +129,9 @@ describe("Items - Light Ball", () => { const spAtkStat = partyMember.getStat(Stat.SPATK); // Making sure modifier is not applied without holding item - const atkValue = new Utils.NumberHolder(atkStat); + const atkValue = new NumberHolder(atkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); - const spAtkValue = new Utils.NumberHolder(spAtkStat); + const spAtkValue = new NumberHolder(spAtkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); expect(atkValue.value / atkStat).toBe(1); @@ -168,9 +168,9 @@ describe("Items - Light Ball", () => { const spAtkStat = partyMember.getStat(Stat.SPATK); // Making sure modifier is not applied without holding item - const atkValue = new Utils.NumberHolder(atkStat); + const atkValue = new NumberHolder(atkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); - const spAtkValue = new Utils.NumberHolder(spAtkStat); + const spAtkValue = new NumberHolder(spAtkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); expect(atkValue.value / atkStat).toBe(1); @@ -197,9 +197,9 @@ describe("Items - Light Ball", () => { const spAtkStat = partyMember.getStat(Stat.SPATK); // Making sure modifier is not applied without holding item - const atkValue = new Utils.NumberHolder(atkStat); + const atkValue = new NumberHolder(atkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); - const spAtkValue = new Utils.NumberHolder(spAtkStat); + const spAtkValue = new NumberHolder(spAtkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); expect(atkValue.value / atkStat).toBe(1); diff --git a/test/items/metal_powder.test.ts b/test/items/metal_powder.test.ts index 460a95d0f06..ed96d3c498b 100644 --- a/test/items/metal_powder.test.ts +++ b/test/items/metal_powder.test.ts @@ -2,7 +2,7 @@ import { Stat } from "#enums/stat"; import { SpeciesStatBoosterModifier } from "#app/modifier/modifier"; import { modifierTypes } from "#app/modifier/modifier-type"; import i18next from "#app/plugins/i18n"; -import * as Utils from "#app/utils"; +import { NumberHolder } from "#app/utils"; import { Species } from "#enums/species"; import GameManager from "#test/testUtils/gameManager"; import Phase from "phaser"; @@ -89,7 +89,7 @@ describe("Items - Metal Powder", () => { const defStat = partyMember.getStat(Stat.DEF); // Making sure modifier is not applied without holding item - const defValue = new Utils.NumberHolder(defStat); + const defValue = new NumberHolder(defStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(1); @@ -122,7 +122,7 @@ describe("Items - Metal Powder", () => { const defStat = partyMember.getStat(Stat.DEF); // Making sure modifier is not applied without holding item - const defValue = new Utils.NumberHolder(defStat); + const defValue = new NumberHolder(defStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(1); @@ -155,7 +155,7 @@ describe("Items - Metal Powder", () => { const defStat = partyMember.getStat(Stat.DEF); // Making sure modifier is not applied without holding item - const defValue = new Utils.NumberHolder(defStat); + const defValue = new NumberHolder(defStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(1); @@ -178,7 +178,7 @@ describe("Items - Metal Powder", () => { const defStat = partyMember.getStat(Stat.DEF); // Making sure modifier is not applied without holding item - const defValue = new Utils.NumberHolder(defStat); + const defValue = new NumberHolder(defStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(1); diff --git a/test/items/quick_powder.test.ts b/test/items/quick_powder.test.ts index 26faf5a0f4f..7115cad8cd1 100644 --- a/test/items/quick_powder.test.ts +++ b/test/items/quick_powder.test.ts @@ -2,7 +2,7 @@ import { Stat } from "#enums/stat"; import { SpeciesStatBoosterModifier } from "#app/modifier/modifier"; import { modifierTypes } from "#app/modifier/modifier-type"; import i18next from "#app/plugins/i18n"; -import * as Utils from "#app/utils"; +import { NumberHolder } from "#app/utils"; import { Species } from "#enums/species"; import GameManager from "#test/testUtils/gameManager"; import Phase from "phaser"; @@ -89,7 +89,7 @@ describe("Items - Quick Powder", () => { const spdStat = partyMember.getStat(Stat.SPD); // Making sure modifier is not applied without holding item - const spdValue = new Utils.NumberHolder(spdStat); + const spdValue = new NumberHolder(spdStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(1); @@ -122,7 +122,7 @@ describe("Items - Quick Powder", () => { const spdStat = partyMember.getStat(Stat.SPD); // Making sure modifier is not applied without holding item - const spdValue = new Utils.NumberHolder(spdStat); + const spdValue = new NumberHolder(spdStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(1); @@ -155,7 +155,7 @@ describe("Items - Quick Powder", () => { const spdStat = partyMember.getStat(Stat.SPD); // Making sure modifier is not applied without holding item - const spdValue = new Utils.NumberHolder(spdStat); + const spdValue = new NumberHolder(spdStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(1); @@ -178,7 +178,7 @@ describe("Items - Quick Powder", () => { const spdStat = partyMember.getStat(Stat.SPD); // Making sure modifier is not applied without holding item - const spdValue = new Utils.NumberHolder(spdStat); + const spdValue = new NumberHolder(spdStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(1); diff --git a/test/items/thick_club.test.ts b/test/items/thick_club.test.ts index 9edbbcdc7d9..69ca316d455 100644 --- a/test/items/thick_club.test.ts +++ b/test/items/thick_club.test.ts @@ -2,7 +2,7 @@ import { Stat } from "#enums/stat"; import { SpeciesStatBoosterModifier } from "#app/modifier/modifier"; import { modifierTypes } from "#app/modifier/modifier-type"; import i18next from "#app/plugins/i18n"; -import * as Utils from "#app/utils"; +import { NumberHolder, randInt } from "#app/utils"; import { Species } from "#enums/species"; import GameManager from "#test/testUtils/gameManager"; import Phase from "phaser"; @@ -89,7 +89,7 @@ describe("Items - Thick Club", () => { const atkStat = partyMember.getStat(Stat.ATK); // Making sure modifier is not applied without holding item - const atkValue = new Utils.NumberHolder(atkStat); + const atkValue = new NumberHolder(atkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); @@ -112,7 +112,7 @@ describe("Items - Thick Club", () => { const atkStat = partyMember.getStat(Stat.ATK); // Making sure modifier is not applied without holding item - const atkValue = new Utils.NumberHolder(atkStat); + const atkValue = new NumberHolder(atkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); @@ -135,7 +135,7 @@ describe("Items - Thick Club", () => { const atkStat = partyMember.getStat(Stat.ATK); // Making sure modifier is not applied without holding item - const atkValue = new Utils.NumberHolder(atkStat); + const atkValue = new NumberHolder(atkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); @@ -153,7 +153,7 @@ describe("Items - Thick Club", () => { it("THICK_CLUB held by fused CUBONE line (base)", async () => { // Randomly choose from the Cubone line const species = [Species.CUBONE, Species.MAROWAK, Species.ALOLA_MAROWAK]; - const randSpecies = Utils.randInt(species.length); + const randSpecies = randInt(species.length); await game.classicMode.startBattle([species[randSpecies], Species.PIKACHU]); @@ -172,7 +172,7 @@ describe("Items - Thick Club", () => { const atkStat = partyMember.getStat(Stat.ATK); // Making sure modifier is not applied without holding item - const atkValue = new Utils.NumberHolder(atkStat); + const atkValue = new NumberHolder(atkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); @@ -190,7 +190,7 @@ describe("Items - Thick Club", () => { it("THICK_CLUB held by fused CUBONE line (part)", async () => { // Randomly choose from the Cubone line const species = [Species.CUBONE, Species.MAROWAK, Species.ALOLA_MAROWAK]; - const randSpecies = Utils.randInt(species.length); + const randSpecies = randInt(species.length); await game.classicMode.startBattle([Species.PIKACHU, species[randSpecies]]); @@ -209,7 +209,7 @@ describe("Items - Thick Club", () => { const atkStat = partyMember.getStat(Stat.ATK); // Making sure modifier is not applied without holding item - const atkValue = new Utils.NumberHolder(atkStat); + const atkValue = new NumberHolder(atkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); @@ -232,7 +232,7 @@ describe("Items - Thick Club", () => { const atkStat = partyMember.getStat(Stat.ATK); // Making sure modifier is not applied without holding item - const atkValue = new Utils.NumberHolder(atkStat); + const atkValue = new NumberHolder(atkStat); game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); diff --git a/test/moves/multi_target.test.ts b/test/moves/multi_target.test.ts index 2b17929a5df..5d33c7860cb 100644 --- a/test/moves/multi_target.test.ts +++ b/test/moves/multi_target.test.ts @@ -1,7 +1,7 @@ import { BattlerIndex } from "#app/battle"; import { Abilities } from "#app/enums/abilities"; import { Species } from "#app/enums/species"; -import * as Utils from "#app/utils"; +import { toDmgValue } from "#app/utils"; import { Moves } from "#enums/moves"; import GameManager from "#test/testUtils/gameManager"; import Phaser from "phaser"; @@ -71,8 +71,8 @@ describe("Multi-target damage reduction", () => { // Single target moves don't get reduced expect(tackle1).toBe(tackle2); // Moves that target all enemies get reduced if there's more than one enemy - expect(gleam1).toBeLessThanOrEqual(Utils.toDmgValue(gleam2 * 0.75) + 1); - expect(gleam1).toBeGreaterThanOrEqual(Utils.toDmgValue(gleam2 * 0.75) - 1); + expect(gleam1).toBeLessThanOrEqual(toDmgValue(gleam2 * 0.75) + 1); + expect(gleam1).toBeGreaterThanOrEqual(toDmgValue(gleam2 * 0.75) - 1); }); it("should reduce earthquake when more than one pokemon other than user is not fainted", async () => { @@ -122,7 +122,7 @@ describe("Multi-target damage reduction", () => { const damageEnemy1Turn3 = enemy1.getMaxHp() - enemy1.hp; // Turn 3: 1 target, should be no damage reduction - expect(damageEnemy1Turn1).toBeLessThanOrEqual(Utils.toDmgValue(damageEnemy1Turn3 * 0.75) + 1); - expect(damageEnemy1Turn1).toBeGreaterThanOrEqual(Utils.toDmgValue(damageEnemy1Turn3 * 0.75) - 1); + expect(damageEnemy1Turn1).toBeLessThanOrEqual(toDmgValue(damageEnemy1Turn3 * 0.75) + 1); + expect(damageEnemy1Turn1).toBeGreaterThanOrEqual(toDmgValue(damageEnemy1Turn3 * 0.75) - 1); }); }); diff --git a/test/mystery-encounter/encounter-test-utils.ts b/test/mystery-encounter/encounter-test-utils.ts index 8c54e0dd606..93629778e0a 100644 --- a/test/mystery-encounter/encounter-test-utils.ts +++ b/test/mystery-encounter/encounter-test-utils.ts @@ -1,3 +1,4 @@ +// biome-ignore lint/style/noNamespaceImport: Necessary for mocks import * as EncounterPhaseUtils from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { Status } from "#app/data/status-effect"; import { CommandPhase } from "#app/phases/command-phase"; diff --git a/test/sprites/pokemonSprite.test.ts b/test/sprites/pokemonSprite.test.ts index 5bd08a58cda..a008b75b42e 100644 --- a/test/sprites/pokemonSprite.test.ts +++ b/test/sprites/pokemonSprite.test.ts @@ -3,8 +3,10 @@ import fs from "fs"; import path from "path"; import { beforeAll, describe, expect, it } from "vitest"; import _masterlist from "../../public/images/pokemon/variant/_masterlist.json"; +import _exp_masterlist from "../../public/images/pokemon/variant/_exp_masterlist.json"; type PokemonVariantMasterlist = typeof _masterlist; +type PokemonExpVariantMasterlist = typeof _exp_masterlist; const deepCopy = (data: any) => { return JSON.parse(JSON.stringify(data)); @@ -12,7 +14,7 @@ const deepCopy = (data: any) => { describe("check if every variant's sprite are correctly set", () => { let masterlist: PokemonVariantMasterlist; - let expVariant: PokemonVariantMasterlist["exp"]; + let expVariant: PokemonExpVariantMasterlist; let femaleVariant: PokemonVariantMasterlist["female"]; let backVariant: PokemonVariantMasterlist["back"]; let rootDir: string; @@ -20,13 +22,12 @@ describe("check if every variant's sprite are correctly set", () => { beforeAll(() => { rootDir = `${getAppRootDir()}${path.sep}public${path.sep}images${path.sep}pokemon${path.sep}variant${path.sep}`; masterlist = deepCopy(_masterlist); - expVariant = masterlist.exp; + expVariant = deepCopy(_exp_masterlist); femaleVariant = masterlist.female; backVariant = masterlist.back; - //@ts-ignore - delete masterlist.exp; //TODO: resolve ts-ignore - //@ts-ignore - delete masterlist.female; //TODO: resolve ts-ignore + + // @ts-ignore + delete masterlist.female; // TODO: resolve ts-ignore //@ts-ignore delete masterlist.back; //TODO: resolve ts-ignore }); diff --git a/test/testUtils/gameWrapper.ts b/test/testUtils/gameWrapper.ts index 64362a7ce00..b25fd934565 100644 --- a/test/testUtils/gameWrapper.ts +++ b/test/testUtils/gameWrapper.ts @@ -2,7 +2,7 @@ import BattleScene, * as battleScene from "#app/battle-scene"; import { MoveAnim } from "#app/data/battle-anims"; import Pokemon from "#app/field/pokemon"; -import * as Utils from "#app/utils"; +import { setCookie, sessionIdKey } from "#app/utils"; import { blobToString } from "#test/testUtils/gameManagerUtils"; import { MockClock } from "#test/testUtils/mocks/mockClock"; import { MockFetch } from "#test/testUtils/mocks/mockFetch"; @@ -31,7 +31,7 @@ window.URL.createObjectURL = (blob: Blob) => { }; navigator.getGamepads = () => []; global.fetch = vi.fn(MockFetch); -Utils.setCookie(Utils.sessionIdKey, "fake_token"); +setCookie(sessionIdKey, "fake_token"); window.matchMedia = () => ({ matches: false, diff --git a/test/testUtils/helpers/overridesHelper.ts b/test/testUtils/helpers/overridesHelper.ts index 9bb0369a31a..0ed1511255b 100644 --- a/test/testUtils/helpers/overridesHelper.ts +++ b/test/testUtils/helpers/overridesHelper.ts @@ -1,4 +1,4 @@ -import type { Variant } from "#app/data/variant"; +import type { Variant } from "#app/sprites/variant"; import { Weather } from "#app/data/weather"; import { Abilities } from "#app/enums/abilities"; import type { ModifierOverride } from "#app/modifier/modifier-type";