UNPKG

enka-network-api

Version:

Enka-network API wrapper for Genshin Impact.

88 lines (87 loc) 6.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CharacterStats = void 0; const constants_1 = require("../../utils/constants"); const StatProperty_1 = require("../StatProperty"); class CharacterStats { constructor(data, enka, element) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; this._data = data; this.enka = enka; 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.matchedElementDamage = (element === null || element === void 0 ? void 0 : element.id) === "Fire" ? this.pyroDamage : (element === null || element === void 0 ? void 0 : element.id) === "Electric" ? this.electroDamage : (element === null || element === void 0 ? void 0 : element.id) === "Water" ? this.hydroDamage : (element === null || element === void 0 ? void 0 : element.id) === "Grass" ? this.dendroDamage : (element === null || element === void 0 ? void 0 : element.id) === "Wind" ? this.anemoDamage : (element === null || element === void 0 ? void 0 : element.id) === "Rock" ? this.geoDamage : (element === null || element === void 0 ? void 0 : element.id) === "Ice" ? this.cryoDamage : null; const sortedDamageBonus = [this.pyroDamage, this.electroDamage, this.hydroDamage, this.dendroDamage, this.anemoDamage, this.geoDamage, this.cryoDamage, this.physicalDamage].sort((a, b) => b.value - a.value); const highestDamageBonusList = sortedDamageBonus.filter(d => d.value === sortedDamageBonus[0].value); if (highestDamageBonusList.length > 1) highestDamageBonusList.sort((a, b) => { var _a, _b; return ((_a = this.matchedElementDamage) === null || _a === void 0 ? void 0 : _a.fightProp) === a.fightProp ? -1 : ((_b = this.matchedElementDamage) === null || _b === void 0 ? void 0 : _b.fightProp) === b.fightProp ? 1 : 0; }); this.highestDamageBonus = highestDamageBonusList; this.pyroEnergyCost = ((_a = data[70]) !== null && _a !== void 0 ? _a : 0); this.electroEnergyCost = ((_b = data[71]) !== null && _b !== void 0 ? _b : 0); this.hydroEnergyCost = ((_c = data[72]) !== null && _c !== void 0 ? _c : 0); this.dendroEnergyCost = ((_d = data[73]) !== null && _d !== void 0 ? _d : 0); this.anemoEnergyCost = ((_e = data[74]) !== null && _e !== void 0 ? _e : 0); this.cryoEnergyCost = ((_f = data[75]) !== null && _f !== void 0 ? _f : 0); this.geoEnergyCost = ((_g = data[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 = data[1000]) !== null && _h !== void 0 ? _h : 0); this.currentElectroEnergy = ((_j = data[1001]) !== null && _j !== void 0 ? _j : 0); this.currentHydroEnergy = ((_k = data[1002]) !== null && _k !== void 0 ? _k : 0); this.currentDendroEnergy = ((_l = data[1003]) !== null && _l !== void 0 ? _l : 0); this.currentAnemoEnergy = ((_m = data[1004]) !== null && _m !== void 0 ? _m : 0); this.currentCryoEnergy = ((_o = data[1005]) !== null && _o !== void 0 ? _o : 0); this.currentGeoEnergy = ((_p = data[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); } getStatProperty(id, defaultValue = 0) { var _a; return new StatProperty_1.StatProperty(constants_1.fightProps[id], ((_a = this._data[id]) !== null && _a !== void 0 ? _a : defaultValue), this.enka); } } exports.CharacterStats = CharacterStats;