Skip to content

Commit

Permalink
add relics
Browse files Browse the repository at this point in the history
  • Loading branch information
yuko1101 committed May 25, 2023
1 parent c324c0c commit 60f284c
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 8 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cSpell.words": [
"autodrain",
"starfaring",
"starrail",
"Trailblaze",
"typedefs"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -41,6 +42,7 @@ export {
LightConeData,
LightConeExpType,
LightConeSuperimposition,
Relic,
RelicData,
RelicExpType,
RelicMainStatGroup,
Expand All @@ -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";
Expand Down
9 changes: 9 additions & 0 deletions src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));

}
}

Expand Down
11 changes: 9 additions & 2 deletions src/models/character/Character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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");
}
}

Expand Down
70 changes: 70 additions & 0 deletions src/models/relic/Relic.ts
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions src/models/relic/RelicMainStatGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +20,7 @@ class RelicMainStatGroup {
readonly client: StarRail;

/** */
readonly mainStats: RelicMainStat[];
readonly mainStats: RelicMainStatData[];

readonly _data: JsonObject<JsonObject>;

Expand Down
8 changes: 6 additions & 2 deletions src/models/relic/RelicSubStatGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -20,7 +22,7 @@ class RelicSubStatGroup {
readonly client: StarRail;

/** */
readonly subStats: RelicSubStat[];
readonly subStats: RelicSubStatData[];

readonly _data: JsonObject<JsonObject>;

Expand All @@ -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"),
};
});
}
Expand Down

1 comment on commit 60f284c

@vercel
Copy link

@vercel vercel bot commented on 60f284c May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

starrail – ./

starrail-git-main-yuko1101.vercel.app
starrail-yuko1101.vercel.app
starrail.vercel.app

Please sign in to comment.