Skip to content

Commit

Permalink
Make LeveledSkill extend Skill (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuko1101 committed Jun 19, 2023
1 parent 2be7ce6 commit 00c25c5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 61 deletions.
60 changes: 9 additions & 51 deletions src/models/character/skill/LeveledSkill.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { JsonObject, JsonReader } from "config_file.js";
import StarRail from "../../../client/StarRail";
import TextAssets from "../../assets/TextAssets";
import { AttackType, EffectType } from "./Skill";
import CombatType, { CombatTypeId } from "../../CombatType";
import ImageAssets from "../../assets/ImageAssets";
import Skill from "./Skill";

/**
* @en LeveledSkill
* @extends {Skill}
*/
class LeveledSkill {
/** */
readonly client: StarRail;

/** */
readonly id: number;
class LeveledSkill extends Skill {
/** */
readonly level: number;
/** */
Expand All @@ -23,58 +17,22 @@ class LeveledSkill {

readonly _data: JsonObject;

// The following properties are the same as for Skill

/** */
readonly name: TextAssets;
/** */
readonly tag: TextAssets;
/** */
readonly skillTypeDescription: TextAssets;
/** */
readonly attackType: AttackType | null;
/** */
readonly combatType: CombatType | null;
/** */
readonly effectType: EffectType;
/** */
readonly maxLevel: number;
/** */
readonly skillIcon: ImageAssets;
/** Available only when [attackType](#attackType) is "Ultra" */
readonly ultraSkillIcon: ImageAssets;

/**
* @param data
* @param client
*/
constructor(data: JsonObject, client: StarRail) {
this._data = data;
this.client = client;

const json = new JsonReader(this._data);
const json = new JsonReader(data);
const id = json.getAsNumber("SkillID");
const level = json.getAsNumber("Level");
super(id, client, level - 1);

this.id = json.getAsNumber("SkillID");
this._data = data;

this.level = json.getAsNumber("Level");
this.level = level;

this.description = new TextAssets(json.getAsNumber("SkillDesc", "Hash"), this.client);
this.simpleDescription = new TextAssets(json.getAsNumber("SimpleSkillDesc", "Hash"), this.client);

// The following properties are the same as for Skill
this.name = new TextAssets(json.getAsNumber("SkillName", "Hash"), this.client);
this.tag = new TextAssets(json.getAsNumber("SkillTag", "Hash"), this.client);
this.skillTypeDescription = new TextAssets(json.getAsNumber("SkillTypeDesc", "Hash"), this.client);

this.attackType = json.getAsStringWithDefault(null, "AttackType") as AttackType | null;
const combatTypeId = json.getAsStringWithDefault(undefined, "StanceDamageType") as CombatTypeId | undefined;
this.combatType = combatTypeId ? new CombatType(combatTypeId, this.client) : null;
this.effectType = json.getAsString("SkillEffect") as EffectType;

this.maxLevel = json.getAsNumber("MaxLevel");

this.skillIcon = new ImageAssets(json.getAsString("SkillIcon"), this.client);
this.ultraSkillIcon = new ImageAssets(json.getAsString("UltraSkillIcon"), this.client);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/models/character/skill/LeveledSkillTreeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class LeveledSkillTreeNode extends SkillTreeNode {
constructor(data: JsonObject, client: StarRail) {
const json = new JsonReader(data);
const id = json.getAsNumber("PointID");
super(id, client);
const level = json.getAsNumber("Level");
super(id, client, level - 1);

this._data = data;

this.level = json.getAsNumber("Level");
this.level = level;
this.characterId = json.getAsNumber("AvatarID");

this.stats = json.get("StatusAddList").mapArray((_, s) => new StatPropertyValue(s.getAsString("PropertyType") as StatPropertyType, s.getAsNumber("Value", "Value"), this.client));
Expand Down
11 changes: 6 additions & 5 deletions src/models/character/skill/Skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,22 @@ class Skill {
/** Available only when [attackType](#attackType) is "Ultra" */
readonly ultraSkillIcon: ImageAssets;

readonly _data: JsonObject[];
readonly _skillsData: JsonObject[];

/**
* @param id
* @param client
* @param skillIndexToUse
*/
constructor(id: number, client: StarRail) {
constructor(id: number, client: StarRail, skillIndexToUse = 0) {
this.id = id;
this.client = client;

const _data: JsonObject | undefined = client.cachedAssetsManager.getStarRailCacheData("AvatarSkillConfig")[this.id];
if (!_data) throw new AssetsNotFoundError("Skill", this.id);
this._data = Object.values(_data) as JsonObject[];
this._skillsData = Object.values(_data) as JsonObject[];

const json = new JsonReader(this._data[0]);
const json = new JsonReader(this._skillsData[skillIndexToUse]);

this.name = new TextAssets(json.getAsNumber("SkillName", "Hash"), this.client);
this.tag = new TextAssets(json.getAsNumber("SkillTag", "Hash"), this.client);
Expand All @@ -76,7 +77,7 @@ class Skill {
* @param level
*/
getSkillByLevel(level: number): LeveledSkill {
return new LeveledSkill(this._data[level - 1], this.client);
return new LeveledSkill(this._skillsData[level - 1], this.client);
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/models/character/skill/SkillTreeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import Skill from "./Skill";
import TextAssets from "../../assets/TextAssets";
import { getStableHash } from "../../../utils/hash_utils";
import ImageAssets from "../../assets/ImageAssets";
import type LeveledSkillTreeNode from "./LeveledSkillTreeNode";

// avoid circular references
import type LeveledSkillTreeNode from "./LeveledSkillTreeNode";
let LeveledSkillTreeNodeClass: typeof LeveledSkillTreeNode;
import("./LeveledSkillTreeNode").then(c => LeveledSkillTreeNodeClass = c.default);

Expand Down Expand Up @@ -37,16 +38,17 @@ class SkillTreeNode {
/**
* @param id
* @param client
* @param nodeIndexToUse
*/
constructor(id: number, client: StarRail) {
constructor(id: number, client: StarRail, nodeIndexToUse = 0) {
this.id = id;
this.client = client;

const _data: JsonObject | undefined = client.cachedAssetsManager.getStarRailCacheData("AvatarSkillTreeConfig")[this.id];
if (!_data) throw new AssetsNotFoundError("SkillTreeNode", this.id);
this._nodesData = Object.values(_data) as JsonObject[];

const json = new JsonReader(this._nodesData[0]);
const json = new JsonReader(this._nodesData[nodeIndexToUse]);

this.maxLevel = json.getAsNumber("MaxLevel");
this.isUnlockedByDefault = json.getAsBooleanWithDefault(false, "DefaultUnlock");
Expand Down

1 comment on commit 00c25c5

@vercel
Copy link

@vercel vercel bot commented on 00c25c5 Jun 19, 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.vercel.app
starrail-yuko1101.vercel.app

Please sign in to comment.