UNPKG

fnbr

Version:

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

283 lines 10.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); /* eslint-disable class-methods-use-this */ /* eslint-disable no-restricted-syntax */ const PowerLevelCurves_1 = tslib_1.__importDefault(require("../../../resources/PowerLevelCurves")); const Util_1 = require("../../util/Util"); const STWHero_1 = tslib_1.__importDefault(require("./STWHero")); const STWHeroLoadout_1 = tslib_1.__importDefault(require("./STWHeroLoadout")); const STWItem_1 = tslib_1.__importDefault(require("./STWItem")); const STWLocker_1 = tslib_1.__importDefault(require("./STWLocker")); const STWMeleeWeaponSchematic_1 = tslib_1.__importDefault(require("./STWMeleeWeaponSchematic")); const STWRangedWeaponSchematic_1 = tslib_1.__importDefault(require("./STWRangedWeaponSchematic")); const STWResource_1 = tslib_1.__importDefault(require("./STWResource")); const STWSchematic_1 = tslib_1.__importDefault(require("./STWSchematic")); const STWStats_1 = tslib_1.__importDefault(require("./STWStats")); const STWSurvivor_1 = tslib_1.__importDefault(require("./STWSurvivor")); const STWTeamPerk_1 = tslib_1.__importDefault(require("./STWTeamPerk")); const STWTrapSchematic_1 = tslib_1.__importDefault(require("./STWTrapSchematic")); const STWWeaponSchematic_1 = tslib_1.__importDefault(require("./STWWeaponSchematic")); const User_1 = tslib_1.__importDefault(require("../user/User")); /** * Represents a Save The World profile */ class STWProfile extends User_1.default { /** * @param client The main client * @param data The profile data * @param userData The user data */ constructor(client, data, userData) { super(client, userData); // eslint-disable-next-line no-underscore-dangle this.profileId = data._id; this.createdAt = new Date(data.created); this.updatedAt = new Date(data.updated); this.revision = data.rvn; this.wipeNumber = data.wipeNumber; this.version = data.version; this.commandRevision = data.commandRevision; this.items = []; for (const [itemId, item] of Object.entries(data.items)) { const itemType = item.templateId.split(':')[0]; switch (itemType) { case 'Worker': this.items.push(new STWSurvivor_1.default(this.client, itemId, item)); break; case 'CosmeticLocker': this.items.push(new STWLocker_1.default(this.client, itemId, item)); break; case 'AccountResource': this.items.push(new STWResource_1.default(this.client, itemId, item)); break; case 'Hero': this.items.push(new STWHero_1.default(this.client, itemId, item)); break; case 'CampaignHeroLoadout': this.items.push(new STWHeroLoadout_1.default(this.client, itemId, item)); break; case 'Schematic': switch ((0, Util_1.parseSTWSchematicTemplateId)(item.templateId).type) { case 'melee': this.items.push(new STWMeleeWeaponSchematic_1.default(this.client, itemId, item)); break; case 'ranged': this.items.push(new STWRangedWeaponSchematic_1.default(this.client, itemId, item)); break; case 'trap': this.items.push(new STWTrapSchematic_1.default(this.client, itemId, item)); break; default: this.items.push(new STWSchematic_1.default(this.client, itemId, item)); break; } break; case 'TeamPerk': this.items.push(new STWTeamPerk_1.default(this.client, itemId, item)); break; default: this.items.push(new STWItem_1.default(this.client, itemId, item)); } } this.stats = new STWStats_1.default(this.client, data.stats.attributes); } /** * Returns the profile's survivors */ get survivors() { return this.items.filter((i) => i instanceof STWSurvivor_1.default); } /** * The profile's survivor squads */ get survivorSquads() { const survivorSquads = { trainingteam: [], fireteamalpha: [], closeassaultsquad: [], thethinktank: [], emtsquad: [], corpsofengineering: [], scoutingparty: [], gadgeteers: [], }; for (const survivor of this.survivors.filter((s) => !!s.squad)) { survivorSquads[survivor.squad.name].push(survivor); } return survivorSquads; } /** * The profile's locker */ get locker() { return this.items.find((i) => i instanceof STWLocker_1.default); } /** * The profile's resources */ get resources() { return this.items.filter((i) => i instanceof STWResource_1.default); } /** * The profile's heroes */ get heroes() { return this.items.filter((i) => i instanceof STWHero_1.default); } /** * The profile's hero loadouts */ get heroLoadouts() { return this.items.filter((i) => i instanceof STWHeroLoadout_1.default) .sort((a, b) => a.loadoutIndex - b.loadoutIndex); } /** * The profile's schematics */ get schematics() { return this.items.filter((i) => i instanceof STWSchematic_1.default); } /** * The profile's weapon schematics */ get weaponSchematics() { return this.items.filter((i) => i instanceof STWWeaponSchematic_1.default); } /** * The profile's trap schematics */ get trapSchematics() { return this.items.filter((i) => i instanceof STWTrapSchematic_1.default); } /** * The profile's team perks */ get teamPerks() { return this.items.filter((i) => i instanceof STWTeamPerk_1.default); } /** * The profile's power level */ get powerLevel() { const totalFORTStats = Object.values(this.FORTStats).reduce((prev, cur) => prev + cur); return PowerLevelCurves_1.default.homebaseRating.eval(totalFORTStats * 4); } /** * The profile's ventures power level */ get venturesPowerLevel() { const totalFORTStats = Object.values(this.venturesFORTStats).reduce((prev, cur) => prev + cur); return PowerLevelCurves_1.default.homebaseRating.eval(totalFORTStats * 4); } /** * The profile's FORT stats */ get FORTStats() { const FORTStats = { fortitude: 0, offense: 0, resistance: 0, tech: 0, }; for (const FORTStat of [this.survivorFORTStats, this.researchFORTStats]) { Object.keys(FORTStat).forEach((k) => { FORTStats[k] += FORTStat[k]; }); } return FORTStats; } /** * The profile's survivor squads' FORT stats */ get survivorFORTStats() { const survivorFORTStats = { fortitude: 0, offense: 0, resistance: 0, tech: 0, }; for (const survivorSquad of Object.values(this.survivorSquads)) { const leadSurvivor = survivorSquad.find((s) => s.squad.slotIdx === 0); for (const survivor of survivorSquad) { let totalBonus = survivor.powerLevel; if (survivor.squad.slotIdx === 0) totalBonus += survivor.leadBonus; else if (leadSurvivor) totalBonus += survivor.calcSurvivorBonus(leadSurvivor); switch (survivor.squad.type) { case 'medicine': survivorFORTStats.fortitude += totalBonus; break; case 'arms': survivorFORTStats.offense += totalBonus; break; case 'synthesis': survivorFORTStats.tech += totalBonus; break; case 'scavenging': survivorFORTStats.resistance += totalBonus; break; } } } return survivorFORTStats; } /** * The profile's research FORT stats */ get researchFORTStats() { const survivorFORTStats = { fortitude: 0, offense: 0, resistance: 0, tech: 0, }; for (const value of this.items) { if (value.templateId.startsWith('Stat:') && !value.templateId.includes('phoenix')) { if (value.templateId.includes('fortitude')) survivorFORTStats.fortitude += value.quantity; else if (value.templateId.includes('resistance')) survivorFORTStats.resistance += value.quantity; else if (value.templateId.includes('technology')) survivorFORTStats.tech += value.quantity; else if (value.templateId.includes('offense')) survivorFORTStats.offense += value.quantity; } } return survivorFORTStats; } /** * The profile's ventures FORT stats */ get venturesFORTStats() { const venturesFORTStats = { fortitude: 0, offense: 0, resistance: 0, tech: 0, }; for (const value of this.items) { if (value.templateId.startsWith('Stat:') && value.templateId.includes('phoenix')) { if (value.templateId.includes('fortitude')) venturesFORTStats.fortitude += value.quantity; else if (value.templateId.includes('resistance')) venturesFORTStats.resistance += value.quantity; else if (value.templateId.includes('technology')) venturesFORTStats.tech += value.quantity; else if (value.templateId.includes('offense')) venturesFORTStats.offense += value.quantity; } } return venturesFORTStats; } /** * Whether the profile is a founder * (Whether it can receive vbucks rewards) */ get isFounder() { return this.items.some((i) => i.templateId === 'Token:receivemtxcurrency'); } } exports.default = STWProfile; //# sourceMappingURL=STWProfile.js.map