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:

98 lines (97 loc) 5.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CharacterStatusManager = void 0; const StatProperty_1 = require("../../models/StatProperty"); const types_1 = require("../../types"); /** * Class of Character's Combat Properties */ class CharacterStatusManager { /** * Create a CharacterStatusManager * @param fightPropData FightPropMap from EnkaNetwork and other sources */ constructor(fightPropData) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; this.statProperties = []; this.fightPropData = fightPropData; this.healthBase = this.getStatProperty(1); this.healthFlat = this.getStatProperty(2); this.healthPercent = this.getStatProperty(3); this.attackBase = this.getStatProperty(4); this.attackFlat = this.getStatProperty(5); this.attackPercent = this.getStatProperty(6); this.defenseBase = this.getStatProperty(7); this.defenseFlat = this.getStatProperty(8); this.defensePercent = this.getStatProperty(9); this.speedBase = this.getStatProperty(10); this.speedPercent = this.getStatProperty(11); this.critRate = this.getStatProperty(20); this.critDamage = this.getStatProperty(22); this.chargeEfficiency = this.getStatProperty(23); this.healAdd = this.getStatProperty(26); this.healedAdd = this.getStatProperty(27); this.elementMastery = this.getStatProperty(28); this.physicalRes = this.getStatProperty(29); this.physicalDamage = this.getStatProperty(30); this.pyroDamage = this.getStatProperty(40); this.electroDamage = this.getStatProperty(41); this.hydroDamage = this.getStatProperty(42); this.dendroDamage = this.getStatProperty(43); this.anemoDamage = this.getStatProperty(44); this.geoDamage = this.getStatProperty(45); this.cryoDamage = this.getStatProperty(46); this.pyroRes = this.getStatProperty(50); this.electroRes = this.getStatProperty(51); this.hydroRes = this.getStatProperty(52); this.dendroRes = this.getStatProperty(53); this.anemoRes = this.getStatProperty(54); this.geoRes = this.getStatProperty(55); this.cryoRes = this.getStatProperty(56); this.sortedDamageBonus = [ this.pyroDamage, this.electroDamage, this.hydroDamage, this.dendroDamage, this.anemoDamage, this.geoDamage, this.cryoDamage, this.physicalDamage, ].sort((a, b) => b.value - a.value); this.pyroEnergyCost = (_a = this.fightPropData[70]) !== null && _a !== void 0 ? _a : 0; this.electroEnergyCost = (_b = this.fightPropData[71]) !== null && _b !== void 0 ? _b : 0; this.hydroEnergyCost = (_c = this.fightPropData[72]) !== null && _c !== void 0 ? _c : 0; this.dendroEnergyCost = (_d = this.fightPropData[73]) !== null && _d !== void 0 ? _d : 0; this.anemoEnergyCost = (_e = this.fightPropData[74]) !== null && _e !== void 0 ? _e : 0; this.cryoEnergyCost = (_f = this.fightPropData[75]) !== null && _f !== void 0 ? _f : 0; this.geoEnergyCost = (_g = this.fightPropData[76]) !== null && _g !== void 0 ? _g : 0; this.energyCost = Math.max(this.pyroEnergyCost, this.electroEnergyCost, this.hydroEnergyCost, this.dendroEnergyCost, this.anemoEnergyCost, this.cryoEnergyCost, this.geoEnergyCost); this.cooldownReduction = this.getStatProperty(80); this.shieldStrength = this.getStatProperty(81); this.currentPyroEnergy = (_h = this.fightPropData[1000]) !== null && _h !== void 0 ? _h : 0; this.currentElectroEnergy = (_j = this.fightPropData[1001]) !== null && _j !== void 0 ? _j : 0; this.currentHydroEnergy = (_k = this.fightPropData[1002]) !== null && _k !== void 0 ? _k : 0; this.currentDendroEnergy = (_l = this.fightPropData[1003]) !== null && _l !== void 0 ? _l : 0; this.currentAnemoEnergy = (_m = this.fightPropData[1004]) !== null && _m !== void 0 ? _m : 0; this.currentCryoEnergy = (_o = this.fightPropData[1005]) !== null && _o !== void 0 ? _o : 0; this.currentGeoEnergy = (_p = this.fightPropData[1006]) !== null && _p !== void 0 ? _p : 0; this.currentEnergy = Math.max(this.currentPyroEnergy, this.currentElectroEnergy, this.currentHydroEnergy, this.currentDendroEnergy, this.currentAnemoEnergy, this.currentCryoEnergy, this.currentGeoEnergy); this.currentHealth = this.getStatProperty(1010); this.maxHealth = this.getStatProperty(2000); this.attack = this.getStatProperty(2001); this.defense = this.getStatProperty(2002); this.speed = this.getStatProperty(2003); this.statProperties = Object.values(this).filter((value) => value instanceof StatProperty_1.StatProperty); } /** * Get StatProperty from fightPropData * @param id FightProp ID * @param defaultValue Default value if fightPropData[ID] is undefined * @returns StatProperty */ getStatProperty(id, defaultValue = 0) { var _a; return new StatProperty_1.StatProperty(types_1.FightProps[id], (_a = this.fightPropData[id]) !== null && _a !== void 0 ? _a : defaultValue); } } exports.CharacterStatusManager = CharacterStatusManager;