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:

134 lines (133 loc) 6.64 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.Monster = void 0; const Client_1 = require("../client/Client"); const OutOfRangeError_1 = require("../errors/OutOfRangeError"); const ImageAssets_1 = require("../models/assets/ImageAssets"); const StatProperty_1 = require("../models/StatProperty"); const types_1 = require("../types"); const statusBonusMonsterAtMultiPlay = { FIGHT_PROP_BASE_HP: [1.0, 1.5, 2.0, 2.5], FIGHT_PROP_BASE_ATTACK: [1.0, 1.1, 1.25, 1.4], FIGHT_PROP_BASE_DEFENSE: [1.0, 1.0, 1.0, 1.0], }; /** * Class of Monster */ class Monster { /** * Create a Monster * @param monsterId monster ID * @param level monsterLevel (1-100). Default: 1 * @param playerCount Number of players (1-4). Default: 1 */ constructor(monsterId, level = 1, playerCount = 1) { var _b, _c, _d, _e, _f, _g, _h, _j; /** * Monster Preview name */ this.describeName = ''; /** * Monster description */ this.description = ''; /** * Monster stats */ this.stats = []; this.id = monsterId; this.level = level; if (this.level < 1 || this.level > 100) throw new OutOfRangeError_1.OutOfRangeError('level', this.level, 1, 200); if (playerCount < 1 || playerCount > 4) throw new OutOfRangeError_1.OutOfRangeError('playerCount', playerCount, 1, 4); const monsterJson = Client_1.Client._getJsonFromCachedExcelBinOutput('MonsterExcelConfigData', this.id); this.internalName = monsterJson.monsterName; this.name = Client_1.Client._cachedTextMap.get(String(monsterJson.nameTextMapHash)) || ''; const describeId = +String(this.id).slice(1, 6); if (Object.keys(Client_1.Client._getCachedExcelBinOutputByName('MonsterDescribeExcelConfigData')).includes(String(describeId))) { const monsterDescribeJson = Client_1.Client._getJsonFromCachedExcelBinOutput('MonsterDescribeExcelConfigData', describeId); this.describeName = Client_1.Client._cachedTextMap.get(String(monsterDescribeJson.nameTextMapHash)) || ''; this.icon = new ImageAssets_1.ImageAssets(monsterDescribeJson.icon); } if (monsterJson.describeId && Object.keys(Client_1.Client._getCachedExcelBinOutputByName('AnimalCodexExcelConfigData')).includes(String(monsterJson.describeId))) { const animalCodexJson = Client_1.Client._getJsonFromCachedExcelBinOutput('AnimalCodexExcelConfigData', monsterJson.describeId); this.description = Client_1.Client._cachedTextMap.get(String(animalCodexJson.descTextMapHash)) || ''; this.codexType = (_b = animalCodexJson.subType) !== null && _b !== void 0 ? _b : 'CODEX_SUBTYPE_ELEMENT_LIFE'; } const propGrowCurves = monsterJson.propGrowCurves; const hpBase = this.getStatValueByJson(propGrowCurves[0], monsterJson.hpBase, playerCount); const attackBase = this.getStatValueByJson(propGrowCurves[1], monsterJson.attackBase, playerCount); const defenseBase = this.getStatValueByJson(propGrowCurves[2], monsterJson.defenseBase, playerCount); this.stats = [ new StatProperty_1.StatProperty(types_1.FightProps[1], hpBase), new StatProperty_1.StatProperty(types_1.FightProps[4], attackBase), new StatProperty_1.StatProperty(types_1.FightProps[7], defenseBase), new StatProperty_1.StatProperty(types_1.FightProps[29], ((_c = monsterJson.physicalSubHurt) !== null && _c !== void 0 ? _c : 0)), new StatProperty_1.StatProperty(types_1.FightProps[51], ((_d = monsterJson.elecSubHurt) !== null && _d !== void 0 ? _d : 0)), new StatProperty_1.StatProperty(types_1.FightProps[52], ((_e = monsterJson.waterSubHurt) !== null && _e !== void 0 ? _e : 0)), new StatProperty_1.StatProperty(types_1.FightProps[53], ((_f = monsterJson.grassSubHurt) !== null && _f !== void 0 ? _f : 0)), new StatProperty_1.StatProperty(types_1.FightProps[54], ((_g = monsterJson.windSubHurt) !== null && _g !== void 0 ? _g : 0)), new StatProperty_1.StatProperty(types_1.FightProps[55], ((_h = monsterJson.rockSubHurt) !== null && _h !== void 0 ? _h : 0)), new StatProperty_1.StatProperty(types_1.FightProps[56], ((_j = monsterJson.iceSubHurt) !== null && _j !== void 0 ? _j : 0)), ]; } /** * Get all monster IDs * @returns All monster IDs */ static get allMonsterIds() { return Object.keys(Client_1.Client._getCachedExcelBinOutputByName('MonsterExcelConfigData')).map((id) => Number(id)); } /** * find monster ID by describe ID * @param describeId Describe ID * @returns monster ID */ static findMonsterIdByDescribeId(describeId) { const convertId = describeId.toString().padStart(5, '0'); //Since some monsterId cannot be obtained by this method, the describeId is converted. const exceptionIds = { 21104: 22110403, 30604: 23060201, 90903: 29090304, 62081: 26208103, }; return Object.keys(exceptionIds).includes(String(describeId)) ? exceptionIds[+describeId] : Number(`2${convertId}01`); } /** * Get monster's stat value by stat type * @param propGrowCurve monsterExcelConfigData.propGrowCurves * @param initValue Initial value * @param playerCount Number of players * @returns Stat value */ getStatValueByJson(propGrowCurve, initValue = 0, playerCount = 1) { if (!propGrowCurve) return initValue; const bonusValue = propGrowCurve.type === undefined || propGrowCurve.type === 'FIGHT_PROP_NONE' ? 1.0 : statusBonusMonsterAtMultiPlay[propGrowCurve.type][playerCount - 1]; if (propGrowCurve.growCurve === undefined || propGrowCurve.growCurve === 'GROW_CURVE_NONE' || propGrowCurve.growCurve === 'GROW_CURVE_DEFENDING' //Skip GROW_CURVE_DEFENDING as it does not exist in the 4.0 data ) return initValue * bonusValue; const curveValue = Client_1.Client._getJsonFromCachedExcelBinOutput('MonsterCurveExcelConfigData', propGrowCurve.growCurve)[this.level]; return initValue * curveValue * bonusValue; } } exports.Monster = Monster; _a = Monster; (() => { Client_1.Client._addExcelBinOutputKeyFromClassPrototype(_a.prototype); })();