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:

146 lines (145 loc) 6.37 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.Artifact = 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"); /** * Class of artifact */ class Artifact { /** * Create a Artifact * @param artifactId Artifact ID * @param mainPropId Main stat ID from ReliquaryMainPropExcelConfigData.json. Default: 10001 * @param level Artifact level (0-20). Default: 0 * @param appendPropIds Artifact sub stat IDs */ constructor(artifactId, mainPropId = 10001, level = 0, appendPropIds = []) { /** * Artifact set description (index:1 = 1pc, 2 = 2pc , 4 = 4pc) */ this.setDescriptions = {}; this.id = artifactId; this.level = level; const artifactJson = Client_1.Client._getJsonFromCachedExcelBinOutput('ReliquaryExcelConfigData', this.id); this.type = artifactJson.equipType; this.name = Client_1.Client._cachedTextMap.get(String(artifactJson.nameTextMapHash)) || ''; this.description = Client_1.Client._cachedTextMap.get(String(artifactJson.descTextMapHash)) || ''; this.rarity = artifactJson.rankLevel; this.setId = artifactJson.setId; const maxLevel = _a.maxLevelMap[this.rarity]; if (this.level < 0 || this.level > maxLevel) throw new OutOfRangeError_1.OutOfRangeError('level', this.level, 0, maxLevel); if (this.setId) { const setJson = Client_1.Client._getJsonFromCachedExcelBinOutput('ReliquarySetExcelConfigData', this.setId); const equipAffixId = setJson.equipAffixId * 10 + 0; const equipAffixJson = Client_1.Client._getJsonFromCachedExcelBinOutput('EquipAffixExcelConfigData', equipAffixId); this.setName = Client_1.Client._cachedTextMap.get(String(equipAffixJson.nameTextMapHash)); if (_a.oneSetBonusIds.includes(this.setId)) { this.setDescriptions[1] = equipAffixJson ? Client_1.Client._cachedTextMap.get(String(equipAffixJson.descTextMapHash)) : undefined; } else { const equipAffixJsonBy2pc = Client_1.Client._getJsonFromCachedExcelBinOutput('EquipAffixExcelConfigData', equipAffixId); this.setDescriptions[2] = equipAffixJsonBy2pc ? Client_1.Client._cachedTextMap.get(String(equipAffixJsonBy2pc.descTextMapHash)) : undefined; const equipAffixJsonBy4pc = Client_1.Client._getJsonFromCachedExcelBinOutput('EquipAffixExcelConfigData', equipAffixId + 1); this.setDescriptions[4] = equipAffixJsonBy4pc ? Client_1.Client._cachedTextMap.get(String(equipAffixJsonBy4pc.descTextMapHash)) : undefined; } } const artifactMainJson = Client_1.Client._getJsonFromCachedExcelBinOutput('ReliquaryMainPropExcelConfigData', mainPropId); const mainValue = Client_1.Client._getJsonFromCachedExcelBinOutput('ReliquaryLevelExcelConfigData', artifactMainJson.propType)[this.rarity][this.level]; this.mainStat = new StatProperty_1.StatProperty(artifactMainJson.propType, mainValue); this.subStats = this.getSubStatProperties(appendPropIds); this.appendProps = appendPropIds.map((propId) => { const artifactAffixJson = Client_1.Client._getJsonFromCachedExcelBinOutput('ReliquaryAffixExcelConfigData', propId); return { id: propId, type: artifactAffixJson.propType, value: artifactAffixJson.propValue, }; }); this.icon = new ImageAssets_1.ImageAssets(artifactJson.icon); } /** * Get all artifact IDs * @returns All artifact IDs */ static get allArtifactIds() { const artifactDatas = Object.values(Client_1.Client._getCachedExcelBinOutputByName('ReliquaryExcelConfigData')); const filteredArtifactDatas = artifactDatas.filter((data) => !this.blackSetIds.includes(data.setId) && !this.blackArtifactIds.includes(data.id)); return filteredArtifactDatas.map((data) => data.id); } /** * Get max level by artifact ID * @param artifactId Artifact ID * @returns Max level */ static getMaxLevelByArtifactId(artifactId) { const artifactJson = Client_1.Client._getJsonFromCachedExcelBinOutput('ReliquaryExcelConfigData', artifactId); return _a.maxLevelMap[artifactJson.rankLevel]; } /** * Get sub stat properties from appendProp IDs * @param appendPropIds Artifact sub stat IDs * @returns Sub stat properties */ getSubStatProperties(appendPropIds) { const result = {}; appendPropIds.forEach((propId) => { const artifactAffixJson = Client_1.Client._getJsonFromCachedExcelBinOutput('ReliquaryAffixExcelConfigData', propId); const propType = artifactAffixJson.propType; const propValue = result[propType]; if (propValue) result[propType] = propValue + artifactAffixJson.propValue; else result[propType] = artifactAffixJson.propValue; }); return Object.keys(result).map((key) => { return new StatProperty_1.StatProperty(key, result[key]); }); } } exports.Artifact = Artifact; _a = Artifact; /** * Max level map of artifacts by rarity */ Artifact.maxLevelMap = { 1: 5, 2: 5, 3: 12, 4: 16, 5: 20, }; /** * IDs of set bonuses that can be activated with one artifact */ Artifact.oneSetBonusIds = [ 15009, 15010, 15011, 15012, 15013, ]; /** * IDs of set bonuses that cannot be obtained */ Artifact.blackSetIds = [15000, 15004, 15012]; /** * IDs of artifacts that cannot be obtained */ Artifact.blackArtifactIds = [ 23300, 23301, 23302, 23303, 23304, 23305, 23306, 23307, 23308, 23309, 23310, 23311, 23312, 23313, 23314, 23315, 23316, 23317, 23318, 23329, 23330, 23334, 23335, 23336, 23337, 23338, 23339, 23340, ]; (() => { Client_1.Client._addExcelBinOutputKeyFromClassPrototype(_a.prototype); })();