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:
64 lines (63 loc) • 3.58 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CharacterDetail = void 0;
const EnkaManagerError_1 = require("../../errors/EnkaManagerError");
const Artifact_1 = require("../../models/Artifact");
const CharacterConstellation_1 = require("../../models/character/CharacterConstellation");
const CharacterCostume_1 = require("../../models/character/CharacterCostume");
const CharacterInfo_1 = require("../../models/character/CharacterInfo");
const CharacterSkill_1 = require("../../models/character/CharacterSkill");
const CharacterStatusManager_1 = require("../../models/character/CharacterStatusManager");
const SetBonus_1 = require("../../models/SetBonus");
const Weapon_1 = require("../../models/weapon/Weapon");
/**
* Class of the character obtained from EnkaNetwork
*/
class CharacterDetail {
/**
* Create a CharacterDetail
* @param data Data from EnkaNetwork
*/
constructor(data) {
var _a, _b;
const characterInfo = new CharacterInfo_1.CharacterInfo(data.avatarId, data.skillDepotId);
this.id = characterInfo.id;
this.defaultCostumeId = characterInfo.defaultCostumeId;
this.depotId = characterInfo.depotId;
this.name = characterInfo.name;
this.element = characterInfo.element;
this.rarity = characterInfo.rarity;
this.bodyType = characterInfo.bodyType;
this.weaponType = characterInfo.weaponType;
this.maxLevel = characterInfo.maxLevel;
this.costume = new CharacterCostume_1.CharacterCostume((_a = data.costumeId) !== null && _a !== void 0 ? _a : characterInfo.defaultCostumeId);
this.level = +(data.propMap[4001].val || 0);
this.levelXp = +(data.propMap[1001].val || 0);
this.promoteLevel = +(data.propMap[1002].val || 0);
this.constellations =
characterInfo.constellationIds.map((id) => {
var _a;
return new CharacterConstellation_1.CharacterConstellation(id, !((_a = data.talentIdList) === null || _a === void 0 ? void 0 : _a.includes(id)));
}) || [];
this.skills = characterInfo.skillOrder.map((id) => {
const proudId = characterInfo.proudMap.get(id);
const extraLevel = proudId && data.proudSkillExtraLevelMap
? data.proudSkillExtraLevelMap[proudId]
: 0;
return new CharacterSkill_1.CharacterSkill(id, data.skillLevelMap[id] || 0, extraLevel);
});
this.combatStatus = new CharacterStatusManager_1.CharacterStatusManager(data.fightPropMap);
const weaponData = data.equipList.find((equip) => 'weapon' in equip);
if (!weaponData)
throw new EnkaManagerError_1.EnkaManagerError('Weapon not found.');
const affixMap = weaponData.weapon.affixMap;
this.weapon = new Weapon_1.Weapon(weaponData.itemId, weaponData.weapon.level, [0, 20, 40, 50, 60, 70, 80, 90][(_b = weaponData.weapon.promoteLevel) !== null && _b !== void 0 ? _b : 0] >=
weaponData.weapon.level, (affixMap ? affixMap[weaponData.itemId + 100000] : 0) + 1);
const artifactDatas = data.equipList.filter((equip) => 'reliquary' in equip);
this.artifacts = artifactDatas.map((data) => new Artifact_1.Artifact(data.itemId, data.reliquary.mainPropId, data.reliquary.level - 1, data.reliquary.appendPropIdList));
this.friendShipLevel = data.fetterInfo.expLevel;
this.setBonus = new SetBonus_1.SetBonus(this.artifacts);
this.data = data;
}
}
exports.CharacterDetail = CharacterDetail;