UNPKG

farming-weight

Version:

Tools for calculating farming weight and fortune in Hypixel Skyblock

108 lines (107 loc) 3.13 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports.LotusGear = void 0; const LOTUS_1 = require('../constants/lotus'); const REFORGES_1 = require('../constants/reforges'); const ITEMSTATS_1 = require('../util/itemstats'); const LORE_1 = require('../util/lore'); class LotusGear { item; info; get slot() { return this.info.slot; } constructor(item, options) { this.options = options; this.item = item; const INFO = LOTUS_1.LOTUS_GEAR_INFO[item.skyblockId]; if (!INFO) { throw new Error(`Unknown lotus gear: ${item.name} (${item.skyblockId})`); } this.info = INFO; if (item.lore) { this.rarity = (0, ITEMSTATS_1.getRarityFromLore)(item.lore); } this.reforge = REFORGES_1.REFORGES[item.attributes?.modifier ?? ''] ?? undefined; this.reforgeStats = this.reforge?.tiers?.[this.rarity]; this.recombobulated = this.item.attributes?.rarity_upgrades === '1'; this.getFortune(); } setOptions(options) { this.options = options; this.getFortune(); } getFortune() { this.fortuneBreakdown = {}; let SUM = 0; // Base fortune const BASE = this.info.stats?.[REFORGES_1.Stat.FarmingFortune] ?? 0; if (BASE > 0) { this.fortuneBreakdown['Base Stats'] = BASE; SUM += BASE; } // Reforge const REFORGE = this.reforgeStats?.stats?.[REFORGES_1.Stat.FarmingFortune] ?? 0; if (REFORGE > 0) { this.fortuneBreakdown['Reforge'] = REFORGE; SUM += REFORGE; } // Visitors const VISITORS = this.getFortuneFromVisitors(BASE, REFORGE); if (VISITORS > 0) { this.fortuneBreakdown['Green Thumb'] = VISITORS; SUM += VISITORS; } // Piece bonus const PIECE_BONUS = this.getPieceBonus(); if (PIECE_BONUS > 0) { this.fortuneBreakdown['Salesperson'] = PIECE_BONUS; SUM += PIECE_BONUS; } this.fortune = SUM; return SUM; } getFortuneFromVisitors(base, reforge) { if (!this.item.enchantments?.green_thumb) return 0; const REGEX = /§7Farming Fortune: §a\+(\d+.?\d+)/g; let FOUND = 0; for (const LINE of this.item.lore ?? []) { const NUMBER = (0, LORE_1.extractNumberFromLine)(LINE, REGEX) ?? 0; if (!NUMBER) continue; FOUND = +NUMBER; break; } if (FOUND === 0) return 0; return Math.max(0, FOUND - base - reforge); } getPieceBonus() { const REGEX = /§7Piece Bonus: §6\+(\d+)☘/g; let FOUND = 0; for (const LINE of (this.item.lore ?? []).reverse()) { const NUMBER = (0, LORE_1.extractNumberFromLine)(LINE, REGEX) ?? 0; if (!NUMBER) continue; FOUND = NUMBER; break; } return FOUND; } static isValid(item) { return LOTUS_1.LOTUS_GEAR_INFO[item.skyblockId] !== undefined; } static fromArray(items, options) { const GEAR = items .filter((item) => LotusGear.isValid(item)) .map((item) => new LotusGear(item, options)) .sort((a, b) => b.fortune - a.fortune); // Get only the best piece of each slot const BEST = {}; for (const PIECE of GEAR) { if (!BEST[PIECE.slot] || PIECE.fortune > (BEST[PIECE.slot]?.fortune ?? 0)) { BEST[PIECE.slot] = PIECE; } } return Object.values(BEST); } } exports.LotusGear = LotusGear; //# sourceMappingURL=lotusgear.js.map