farming-weight
Version:
Tools for calculating farming weight and fortune in Hypixel Skyblock
113 lines (112 loc) • 3.4 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
exports.LotusGear = exports.FarmingEquipment = 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 FarmingEquipment {
item;
info;
get slot() {
return this.info.slot;
}
constructor(item, options) {
this.options = options;
this.item = item;
const INFO = LOTUS_1.EQUIPMENT_INFO[item.skyblockId];
if (!INFO) {
throw new Error(`Unknown equipment: ${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;
}
// Green Thumb Visitors
const VISITORS = this.getFortuneFromVisitors(BASE, REFORGE);
if (VISITORS > 0) {
this.fortuneBreakdown['Green Thumb'] = VISITORS;
SUM += VISITORS;
}
// Lotus Piece bonus
if (this.info.family === 'LOTUS') {
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.EQUIPMENT_INFO[item.skyblockId] !== undefined;
}
static fromArray(items, options) {
const GEAR = items
.filter((item) => FarmingEquipment.isValid(item))
.map((item) => new FarmingEquipment(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.FarmingEquipment = FarmingEquipment;
// For backwards compatibility
// eslint-disable-next-line @typescript-eslint/naming-convention
exports.LotusGear = FarmingEquipment;
//# sourceMappingURL=farmingequipment.js.map