UNPKG

fnbr

Version:

A library to interact with Epic Games' Fortnite HTTP and XMPP services

76 lines 2.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const STWItem_1 = tslib_1.__importDefault(require("./STWItem")); const Util_1 = require("../../util/Util"); /** * Represents a Save The World profile's survivor */ class STWSurvivor extends STWItem_1.default { /** * @param client The main client * @param id The item ID * @param data The survivors's data */ constructor(client, id, data) { super(client, id, data); const parsedSurvivor = (0, Util_1.parseSTWSurvivorTemplateId)(data.templateId); this.type = parsedSurvivor.type; this.name = parsedSurvivor.name; this.tier = parsedSurvivor.tier; this.rarity = parsedSurvivor.rarity; this.managerSynergy = data.attributes.managerSynergy; this.gender = data.attributes.gender === '1' ? 'male' : 'female'; this.level = data.attributes.level; this.squad = data.attributes.squad_id ? { id: data.attributes.squad_id, name: data.attributes.squad_id.split('_')[3], type: data.attributes.squad_id.split('_')[2], slotIdx: data.attributes.squad_slot_idx, } : undefined; this.portrait = data.attributes.portrait; this.maxLevelBonus = data.attributes.max_level_bonus; this.personality = data.attributes.personality; this.xp = data.attributes.xp; this.buildingSlotBuildingId = data.attributes.building_slot_used !== -1 ? data.attributes.slotted_building_id : undefined; this.setBonus = data.attributes.set_bonus; this.isSeen = data.attributes.item_seen; this.isFavorite = data.attributes.favorite; } /** * Whether the survivor is a leader */ get isLeader() { return this.type === 'manager'; } /** * The survivor's power level. * Depends on the tier, level, rarity value and whether the survivor is a leader */ get powerLevel() { return (0, Util_1.calcSTWSurvivorPowerLevel)(this.rarity, this.isLeader, this.level, this.tier); } /** * The survivor's lead bonus. * Will return 0 if the survivor is not a leader or not part of a squad */ get leadBonus() { if (!this.managerSynergy || !this.squad) return 0; return (0, Util_1.calcSTWSurvivorLeadBonus)(this.managerSynergy, this.squad.name, this.powerLevel); } /** * Calculates the survivor's bonus. * Depends on the leader's rarity and personality. * Returns 0 if the survivor is a leader */ calcSurvivorBonus(leader) { if (this.isLeader) return 0; if (!leader.isLeader) throw new Error('The leader survivor must be a leader'); return (0, Util_1.calcSTWSurvivorBonus)(leader.personality, leader.rarity, this.personality, this.powerLevel); } } exports.default = STWSurvivor; //# sourceMappingURL=STWSurvivor.js.map