UNPKG

genshin-manager

Version:

<div align="center"> <p> <a href="https://www.npmjs.com/package/genshin-manager"><img src="https://img.shields.io/npm/v/genshin-manager.svg?maxAge=3600" alt="npm version" /></a> <a href="https://www.npmjs.com/package/genshin-manager"><img src="https:

88 lines (87 loc) 4.34 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.CharacterBaseStats = void 0; const Client_1 = require("../../client/Client"); const OutOfRangeError_1 = require("../../errors/OutOfRangeError"); const CharacterAscension_1 = require("../../models/character/CharacterAscension"); const StatProperty_1 = require("../../models/StatProperty"); const calculatePromoteLevel_1 = require("../../utils/calculatePromoteLevel"); /** * Class of character's base stats */ class CharacterBaseStats { /** * Create a character's base stats * @param characterId Character ID * @param level Character level (1-90). Default: 1 * @param isAscended Character is ascended (true or false). Default: false */ constructor(characterId, level = 1, isAscended = false) { this.id = characterId; this.level = level; if (this.level < 1 || this.level > 90) throw new OutOfRangeError_1.OutOfRangeError('level', this.level, 1, 90); this.isAscended = isAscended; const avatarJson = Client_1.Client._getJsonFromCachedExcelBinOutput('AvatarExcelConfigData', this.id); const avatarPromotesJson = Client_1.Client._getJsonFromCachedExcelBinOutput('AvatarPromoteExcelConfigData', avatarJson.avatarPromoteId); this.promoteLevel = (0, calculatePromoteLevel_1.calculatePromoteLevel)(avatarPromotesJson, this.level, this.isAscended); const ascension = new CharacterAscension_1.CharacterAscension(this.id, this.promoteLevel); const propGrowCurves = avatarJson.propGrowCurves; this.stats = this.calculateStatus(avatarJson, propGrowCurves, ascension); } /** * Calculate character's status * @param avatarJson Avatar json * @param propGrowCurves Prop grow curves * @param ascension Character ascension * @returns Character's status */ calculateStatus(avatarJson, propGrowCurves, ascension) { const initValueObj = { FIGHT_PROP_BASE_HP: avatarJson.hpBase, FIGHT_PROP_BASE_ATTACK: avatarJson.attackBase, FIGHT_PROP_BASE_DEFENSE: avatarJson.defenseBase, FIGHT_PROP_CRITICAL: avatarJson.critical, FIGHT_PROP_CRITICAL_HURT: avatarJson.criticalHurt, }; const status = Object.entries(initValueObj).map(([key, value]) => { var _b, _c, _d, _e; const statProperty = new StatProperty_1.StatProperty(key, value); const propGrowCurve = propGrowCurves.find((propGrowCurve) => propGrowCurve.type === statProperty.type); if (propGrowCurve) { return this.getStatPropertyByJson(propGrowCurve, statProperty.value, (_c = (_b = ascension.addProps.find((addProp) => addProp.type === statProperty.type)) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 0); } else { if (statProperty.type === 'FIGHT_PROP_CRITICAL_HURT' || statProperty.type === 'FIGHT_PROP_CRITICAL') { return new StatProperty_1.StatProperty(statProperty.type, statProperty.value + ((_e = (_d = ascension.addProps.find((addProp) => addProp.type === statProperty.type)) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : 0)); } return statProperty; } }); ascension.addProps.forEach((addProp) => { if (!status.some((statProperty) => statProperty.type === addProp.type)) status.push(addProp); }); return status; } /** * Get stat value by json * @param propGrowCurve Json object * @param initValue Initial value * @param addValue Add value * @returns Stat value */ getStatPropertyByJson(propGrowCurve, initValue, addValue = 0) { const curveValue = Client_1.Client._getJsonFromCachedExcelBinOutput('AvatarCurveExcelConfigData', propGrowCurve.growCurve)[this.level]; const statValue = initValue * curveValue + addValue; return new StatProperty_1.StatProperty(propGrowCurve.type, statValue); } } exports.CharacterBaseStats = CharacterBaseStats; _a = CharacterBaseStats; (() => { Client_1.Client._addExcelBinOutputKeyFromClassPrototype(_a.prototype); })();