From 60f284c9d09f775c36d87079a68a1b0c1cda55b8 Mon Sep 17 00:00:00 2001 From: yuko1101 <68993883+yuko1101@users.noreply.github.com> Date: Thu, 25 May 2023 17:44:10 +0900 Subject: [PATCH] add relics --- .vscode/settings.json | 1 + CHANGELOG.md | 2 + src/index.ts | 7 ++- src/models/User.ts | 9 ++++ src/models/character/Character.ts | 11 +++- src/models/relic/Relic.ts | 70 ++++++++++++++++++++++++++ src/models/relic/RelicMainStatGroup.ts | 4 +- src/models/relic/RelicSubStatGroup.ts | 8 ++- 8 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 src/models/relic/Relic.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 8a95907..fe93a0f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "cSpell.words": [ "autodrain", + "starfaring", "starrail", "Trailblaze", "typedefs" diff --git a/CHANGELOG.md b/CHANGELOG.md index 57c697d..badc0b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # 0.3.0 - Added StarRail#fetchUser. +- Renamed RelicSubStat to RelicSubStatData. +- Renamed RelicMainStat to RelicMainStat. # 0.2.1 - Use adm-zip library instead of unzipper. # 0.2.0 diff --git a/src/index.ts b/src/index.ts index d12d746..6e70b93 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,7 @@ import LightCone from "./models/light_cone/LightCone"; import LightConeData from "./models/light_cone/LightConeData"; import LightConeExpType from "./models/light_cone/LightConeExpType"; import LightConeSuperimposition from "./models/light_cone/LightConeSuperimposition"; +import Relic from "./models/relic/Relic"; import RelicData from "./models/relic/RelicData"; import RelicExpType from "./models/relic/RelicExpType"; import RelicMainStatGroup from "./models/relic/RelicMainStatGroup"; @@ -41,6 +42,7 @@ export { LightConeData, LightConeExpType, LightConeSuperimposition, + Relic, RelicData, RelicExpType, RelicMainStatGroup, @@ -59,10 +61,11 @@ export { ClientOptions } from "./client/StarRail"; export { ImageBaseUrl } from "./models/assets/ImageAssets"; export { AttackType, EffectType } from "./models/character/skill/Skill"; export { LightConeLevel } from "./models/light_cone/LightConeExpType"; +export { RelicSubStat } from "./models/relic/Relic"; export { RelicType } from "./models/relic/RelicData"; export { RelicLevel } from "./models/relic/RelicExpType"; -export { RelicMainStat } from "./models/relic/RelicMainStatGroup"; -export { RelicSubStat } from "./models/relic/RelicSubStatGroup"; +export { RelicMainStatData } from "./models/relic/RelicMainStatGroup"; +export { RelicSubStatData } from "./models/relic/RelicSubStatGroup"; export { CombatTypeId } from "./models/CombatType"; export { PathId } from "./models/Path"; export { StatPropertyType } from "./models/StatProperty"; diff --git a/src/models/User.ts b/src/models/User.ts index 0910329..1e6a847 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -3,6 +3,7 @@ import StarRail from "../client/StarRail"; import CharacterData from "./character/CharacterData"; import ImageAssets from "./assets/ImageAssets"; import AssetsNotFoundError from "../errors/AssetsNotFoundError"; +import Character from "./character/Character"; /** @typedef */ export interface Birthday { @@ -48,6 +49,10 @@ class User { readonly forgottenHall: number; /** */ readonly simulatedUniverse: number; + /** */ + readonly supportCharacter: Character; + /** Characters on the user's display */ + readonly starfaringCompanions: Character[]; readonly _data: JsonObject; @@ -100,6 +105,10 @@ class User { this.forgottenHall = playerSpaceInfo.getAsNumberWithDefault(0, "ChallengeData", "PreMazeGroupIndex"); this.simulatedUniverse = playerSpaceInfo.getAsNumberWithDefault(0, "PassAreaProgress"); + + this.supportCharacter = new Character(playerDetailInfo.getAsJsonObject("AssistAvatar"), this.client); + this.starfaringCompanions = playerDetailInfo.getAsJsonArrayWithDefault([], "DisplayAvatarList").map(c => new Character(c as JsonObject, this.client)); + } } diff --git a/src/models/character/Character.ts b/src/models/character/Character.ts index 3ecf7fb..5561798 100644 --- a/src/models/character/Character.ts +++ b/src/models/character/Character.ts @@ -2,6 +2,7 @@ import { JsonObject, JsonReader } from "config_file.js"; import StarRail from "../../client/StarRail"; import CharacterData from "./CharacterData"; import LightCone from "../light_cone/LightCone"; +import Relic from "../relic/Relic"; /** * @en Character @@ -15,11 +16,15 @@ class Character { /** */ readonly lightCone: LightCone | null; /** */ + readonly relics: Relic[]; + /** */ readonly level: number; /** */ readonly exp: number; /** */ readonly ascension: number; + /** */ + readonly eidolons: number; readonly _data: JsonObject; @@ -36,10 +41,12 @@ class Character { this.characterData = new CharacterData(json.getAsNumber("AvatarID"), this.client); this.lightCone = json.has("EquipmentID", "ID") ? new LightCone(json.getAsJsonObject("EquipmentID"), this.client) : null; + this.relics = json.getAsJsonArrayWithDefault([], "RelicList").map(relic => new Relic(relic as JsonObject, this.client)); this.level = json.getAsNumber("Level"); - this.exp = json.getAsNumber("EXP"); - this.ascension = json.getAsNumber("Promotion"); + this.exp = json.getAsNumberWithDefault(0, "EXP"); + this.ascension = json.getAsNumberWithDefault(0, "Promotion"); + this.eidolons = json.getAsNumberWithDefault(0, "Rank"); } } diff --git a/src/models/relic/Relic.ts b/src/models/relic/Relic.ts new file mode 100644 index 0000000..91d950b --- /dev/null +++ b/src/models/relic/Relic.ts @@ -0,0 +1,70 @@ +import { JsonObject, JsonReader } from "config_file.js"; +import StarRail from "../../client/StarRail"; +import RelicData from "./RelicData"; +import { RelicMainStatData } from "./RelicMainStatGroup"; +import { RelicSubStatData } from "./RelicSubStatGroup"; + +/** @typedef */ +export interface RelicSubStat { + subStatData: RelicSubStatData; + /** The number of times this SubStat has been enhanced */ + count: number; + /** */ + steps: number; + /** Calculated by [baseValue](RelicSubStatData#baseValue) * [count](#count) + [stepValue](RelicSubStatData#stepValue) * [steps](#steps) */ + value: number; +} + +/** + * @en Relic + */ +class Relic { + /** */ + readonly client: StarRail; + + /** */ + readonly relicData: RelicData; + /** */ + readonly level: number; + /** */ + readonly mainStat: RelicMainStatData; + /** */ + readonly subStats: RelicSubStat[]; + + readonly _data: JsonObject; + + /** + * @param data + * @param client + */ + constructor(data: JsonObject, client: StarRail) { + this.client = client; + this._data = data; + + const json = new JsonReader(this._data); + + this.relicData = new RelicData(json.getAsNumber("ID"), this.client); + + this.level = json.getAsNumberWithDefault(0, "Level"); + + const mainAffixId = json.getAsNumber("MainAffixID"); + this.mainStat = this.relicData.mainStatGroup.mainStats.find(mainStat => mainStat.id === mainAffixId) as RelicMainStatData; + + this.subStats = json.get("RelicSubAffix").mapArray((_, subAffix) => { + const subAffixId = subAffix.getAsNumber("SubAffixID"); + const subStatData = this.relicData.subStatGroup.subStats.find(s => s.id === subAffixId) as RelicSubStatData; + const count = subAffix.getAsNumber("Cnt"); + const steps = subAffix.getAsNumberWithDefault(0, "Step"); + + return { + subStatData, + count, + steps, + value: subStatData.baseValue * count + subStatData.stepValue * steps, + }; + }); + + } +} + +export default Relic; \ No newline at end of file diff --git a/src/models/relic/RelicMainStatGroup.ts b/src/models/relic/RelicMainStatGroup.ts index edf4b7d..dd4dd49 100644 --- a/src/models/relic/RelicMainStatGroup.ts +++ b/src/models/relic/RelicMainStatGroup.ts @@ -4,7 +4,7 @@ import AssetsNotFoundError from "../../errors/AssetsNotFoundError"; import StatProperty, { StatPropertyType } from "../StatProperty"; /** @typedef */ -export interface RelicMainStat { +export interface RelicMainStatData { id: number; groupId: number; statProperty: StatProperty; @@ -20,7 +20,7 @@ class RelicMainStatGroup { readonly client: StarRail; /** */ - readonly mainStats: RelicMainStat[]; + readonly mainStats: RelicMainStatData[]; readonly _data: JsonObject; diff --git a/src/models/relic/RelicSubStatGroup.ts b/src/models/relic/RelicSubStatGroup.ts index dd40d5c..280e1b6 100644 --- a/src/models/relic/RelicSubStatGroup.ts +++ b/src/models/relic/RelicSubStatGroup.ts @@ -4,10 +4,12 @@ import AssetsNotFoundError from "../../errors/AssetsNotFoundError"; import StatProperty, { StatPropertyType } from "../StatProperty"; /** @typedef */ -export interface RelicSubStat { +export interface RelicSubStatData { id: number; groupId: number; statProperty: StatProperty; + baseValue: number; + stepValue: number; } /** @@ -20,7 +22,7 @@ class RelicSubStatGroup { readonly client: StarRail; /** */ - readonly subStats: RelicSubStat[]; + readonly subStats: RelicSubStatData[]; readonly _data: JsonObject; @@ -43,6 +45,8 @@ class RelicSubStatGroup { id: v.getAsNumber("AffixID"), groupId: this.id, statProperty: new StatProperty(v.getAsString("Property") as StatPropertyType, this.client), + baseValue: v.getAsNumber("BaseValue", "Value"), + stepValue: v.getAsNumber("StepValue", "Value"), }; }); }