UNPKG

enka-network-api

Version:

Enka-network API wrapper for Genshin Impact.

72 lines (71 loc) 5.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Character = void 0; const Artifact_1 = require("../artifact/Artifact"); const CharacterData_1 = require("./CharacterData"); const Weapon_1 = require("../weapon/Weapon"); const CharacterStats_1 = require("./CharacterStats"); const SkillLevel_1 = require("./talents/SkillLevel"); const UpgradableSkill_1 = require("./talents/UpgradableSkill"); const NormalAttack_1 = require("./talents/NormalAttack"); const ElementalSkill_1 = require("./talents/ElementalSkill"); const ElementalBurst_1 = require("./talents/ElementalBurst"); const config_file_js_1 = require("config_file.js"); const ts_utils_1 = require("../../utils/ts_utils"); const IGOODResolvable_1 = require("../good/IGOODResolvable"); const ExcelTransformer_1 = require("../../client/ExcelTransformer"); class Character { constructor(data, enka) { var _a; this.enka = enka; this._data = data; const json = new config_file_js_1.JsonReader(config_file_js_1.defaultJsonOptions, this._data); this.characterData = CharacterData_1.CharacterData.getById(json.getAsNumber("avatarId"), enka, json.getAsNumberWithDefault(undefined, "skillDepotId")); this.costume = (json.has("costumeId") ? this.characterData.costumes.find(c => c.id === json.getAsNumber("costumeId")) : this.characterData.costumes.find(c => c.isDefault)); this.artifacts = json.get("equipList").filterArray((_, item) => item.has("reliquary")).map(([, artifact]) => new Artifact_1.Artifact(artifact.getAsJsonObject(), enka)); this.artifacts.forEach(a => a.location = (0, IGOODResolvable_1.convertToGOODKey)(this.characterData.name.get("en"))); this.weapon = new Weapon_1.Weapon((_a = json.get("equipList").findArray((_, item) => item.has("weapon"))) === null || _a === void 0 ? void 0 : _a[1].getAsJsonObject(), enka); this.weapon.location = (0, IGOODResolvable_1.convertToGOODKey)(this.characterData.name.get("en")); this.stats = new CharacterStats_1.CharacterStats(json.getAsJsonObject("fightPropMap"), enka, this.characterData.element); const propMap = json.get("propMap"); this.level = Number(propMap.getAsStringWithDefault(0, "4001", "val")); this.xp = Number(propMap.getAsStringWithDefault(0, "1001", "val")); this.ascension = Number(propMap.getAsStringWithDefault(0, "1002", "val")); this.maxLevel = (this.ascension + 1) * 20 - (this.ascension > 1 ? (this.ascension - 1) * 10 : 0); this.stamina = Number(propMap.getAsStringWithDefault(10000, "10010", "val")) / 100; this.friendship = json.getAsNumberWithDefault(1, "fetterInfo", "expLevel"); this.unlockedConstellations = this.characterData.constellations.filter(c => (json.has("talentIdList") ? json.get("talentIdList").mapArray((_, p) => p.getAsNumber()) : []).includes(c.id)); this.skillLevels = json.get("skillLevelMap").mapObject((key, value) => { const skill = this.characterData.skills.find(s => s.id.toString() === key); if (!skill || !(skill instanceof UpgradableSkill_1.UpgradableSkill)) return null; const base = value.getAsNumber(); const proudSkillExtraLevelMap = json.get("proudSkillExtraLevelMap"); const proudSkillGroupId = new config_file_js_1.JsonReader(ExcelTransformer_1.excelJsonOptions, skill._data).getAsNumber("proudSkillGroupId").toString(); const extra = proudSkillExtraLevelMap.getAsNumberWithDefault(0, proudSkillGroupId); return { skill, level: new SkillLevel_1.SkillLevel(base, extra), }; }).filter(ts_utils_1.nonNullable).sort((a, b) => { const getScore = (skill) => (skill instanceof NormalAttack_1.NormalAttack) ? 0 : (skill instanceof ElementalSkill_1.ElementalSkill) ? 1 : (skill instanceof ElementalBurst_1.ElementalBurst) ? 2 : 3; return getScore(a.skill) - getScore(b.skill); }); this.unlockedPassiveTalents = this.characterData.passiveTalents.filter(p => (json.has("inherentProudSkillList") ? json.get("inherentProudSkillList").mapArray((_, e) => e.getAsNumber()) : []).includes(p.id)); } toGOOD() { var _a, _b, _c, _d, _e, _f; return { key: (0, IGOODResolvable_1.convertToGOODKey)(this.characterData.name.get("en")), level: this.level, constellation: this.unlockedConstellations.length, ascension: this.ascension, talent: { auto: (_b = (_a = this.skillLevels.find(s => s.skill instanceof NormalAttack_1.NormalAttack)) === null || _a === void 0 ? void 0 : _a.level.base) !== null && _b !== void 0 ? _b : 1, skill: (_d = (_c = this.skillLevels.find(s => s.skill instanceof ElementalSkill_1.ElementalSkill)) === null || _c === void 0 ? void 0 : _c.level.base) !== null && _d !== void 0 ? _d : 1, burst: (_f = (_e = this.skillLevels.find(s => s.skill instanceof ElementalBurst_1.ElementalBurst)) === null || _e === void 0 ? void 0 : _e.level.base) !== null && _f !== void 0 ? _f : 1, }, }; } } exports.Character = Character;