From 73ff6e40befe457338873c51cafec0607f01c68c Mon Sep 17 00:00:00 2001 From: yuko1101 <68993883+yuko1101@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:19:06 +0900 Subject: [PATCH] added Character#costume --- CHANGELOG.md | 2 ++ src/client/CachedAssetsManager.ts | 8 ++++++++ src/index.ts | 1 + src/models/character/Character.ts | 4 ++++ src/models/character/Costume.ts | 29 +++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+) create mode 100644 src/models/character/Costume.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 85c8074..49d5c45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +# 1.7.5 +- Added Character#costume. # 1.7.4 - Fixed a parsing error with servant skills in HSR v3.0. - Added Skill#isServant. diff --git a/src/client/CachedAssetsManager.ts b/src/client/CachedAssetsManager.ts index 229c01f..fcc6ae8 100644 --- a/src/client/CachedAssetsManager.ts +++ b/src/client/CachedAssetsManager.ts @@ -22,6 +22,7 @@ export const excelKeyMap = { "AvatarSkillTreeConfig": ["PointID", "Level"], // Character Skill Trees "AvatarRankConfig": ["RankID"], // Character Eidolons "AvatarPromotionConfig": ["AvatarID", ["Promotion", 0]], // Character Promotions and Character Basic Stats. + "AvatarSkin": ["ID"], // Costumes "EquipmentConfig": ["EquipmentID"], // Light Cones "ItemConfigEquipment": ["ID"], // Light Cones as Items @@ -492,6 +493,13 @@ export class CachedAssetsManager { ); }); + Object.values(data["AvatarSkin"]).forEach(s => { + const json = new JsonReader(s); + push( + json.getAsNumber("AvatarSkinName", "Hash"), + ); + }); + Object.values(data["EquipmentConfig"]).forEach(l => { const json = new JsonReader(l); push( diff --git a/src/index.ts b/src/index.ts index c9ac62c..b70384e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ export * from "./models/character/skill/SkillTreeNode"; export * from "./models/character/Character"; export * from "./models/character/CharacterData"; export * from "./models/character/CharacterStats"; +export * from "./models/character/Costume"; export * from "./models/character/Eidolon"; export * from "./models/enka/StarRailCharacterBuild"; export * from "./models/light_cone/LightCone"; diff --git a/src/models/character/Character.ts b/src/models/character/Character.ts index 1831a29..deb457f 100644 --- a/src/models/character/Character.ts +++ b/src/models/character/Character.ts @@ -9,6 +9,7 @@ import { CharacterStats } from "./CharacterStats"; import { LeveledSkill } from "./skill/Skill"; import { SkillLevel } from "./skill/SkillLevel"; import { nonNullable } from "../../utils/ts_utils"; +import { Costume } from "./Costume"; export class Character { readonly client: StarRail; @@ -20,6 +21,7 @@ export class Character { readonly exp: number; readonly ascension: number; readonly eidolons: number; + readonly costume: Costume | null; readonly skillTreeNodes: LeveledSkillTreeNode[]; readonly skills: LeveledSkill[]; readonly basicStats: StatPropertyValue[]; @@ -43,6 +45,8 @@ export class Character { this.ascension = json.getAsNumberWithDefault(0, "promotion"); this.eidolons = json.getAsNumberWithDefault(0, "rank"); + this.costume = json.has("dressedSkinId") ? new Costume(json.getAsNumber("dressedSkinId"), this.client) : null; + const unlockedEidolons = this.characterData.eidolons.slice(0, this.eidolons); this.skillTreeNodes = json.get("skillTreeList").mapArray((_, skill) => { diff --git a/src/models/character/Costume.ts b/src/models/character/Costume.ts new file mode 100644 index 0000000..48c891c --- /dev/null +++ b/src/models/character/Costume.ts @@ -0,0 +1,29 @@ +import { JsonObject, JsonReader } from "config_file.js"; +import { StarRail } from "../../client/StarRail"; +import { AssetsNotFoundError } from "../../errors/AssetsNotFoundError"; +import { TextAssets } from "../assets/TextAssets"; + +export class Costume { + readonly id: number; + readonly client: StarRail; + + readonly name: TextAssets; + readonly characterId: number; + + readonly _data: JsonObject; + + constructor(id: number, client: StarRail) { + this.id = id; + this.client = client; + + const _data = client.cachedAssetsManager.getExcelData("AvatarSkin", this.id); + if (!_data) throw new AssetsNotFoundError("Costume", this.id); + this._data = _data; + + const json = new JsonReader(this._data); + + this.name = new TextAssets(json.getAsNumber("AvatarSkinName", "Hash"), this.client); + this.characterId = json.getAsNumber("AvatarID"); + + } +} \ No newline at end of file