farming-weight
Version:
Tools for calculating farming weight and fortune in Hypixel Skyblock
197 lines (196 loc) • 6.67 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
exports.FarmingTool = void 0;
const ENCHANTS_1 = require('../constants/enchants');
const REFORGES_1 = require('../constants/reforges');
const TOOLS_1 = require('../constants/tools');
const GEMS_1 = require('../util/gems');
const ITEMSTATS_1 = require('../util/itemstats');
const LORE_1 = require('../util/lore');
class FarmingTool {
get name() {
return this.colorPrefix + (this.reforge?.name ?? '') + ' ' + this.itemname;
}
constructor(item, options) {
this.rebuildTool(item, options);
}
setOptions(options) {
this.options = options;
this.fortune = this.getFortune();
}
rebuildTool(item, options) {
this.options = options;
this.item = item;
const TOOL = TOOLS_1.FARMING_TOOLS[item.skyblockId];
if (!TOOL) {
throw new Error(`Unknown farming tool: ${item.name} (${item.skyblockId})`);
}
this.tool = TOOL;
this.crop = TOOL.crop;
if (item.lore) {
this.rarity = (0, ITEMSTATS_1.getRarityFromLore)(item.lore);
}
this.counter = this.getCounter();
this.cultivating = this.getCultivating() ?? 0;
this.logCounter = 0;
this.collAnalysis = 0;
this.setReforge(item.attributes?.modifier ?? '');
this.farmingForDummies = +(this.item.attributes?.farming_for_dummies_count ?? 0);
this.recombobulated = this.item.attributes?.rarity_upgrades === '1';
this.fortune = this.getFortune();
if (this.reforge?.name && item.name) {
const [PREFIX, NAME] = item.name.split(this.reforge.name);
this.colorPrefix = PREFIX ?? '';
this.itemname = NAME?.trim() ?? '';
} else {
this.colorPrefix = '';
this.itemname = item.name ?? '';
}
}
setReforge(reforgeId) {
this.reforge = REFORGES_1.REFORGES[reforgeId] ?? undefined;
this.reforgeStats = this.reforge?.tiers?.[this.rarity];
}
changeReforgeTo(reforgeId) {
this.setReforge(reforgeId);
this.fortune = this.getFortune();
}
changeFarmedCropsTo(crops) {
if (this.tool.type !== TOOLS_1.FarmingToolType.MathematicalHoe) return;
const DIGITS = Math.floor(crops).toString().length - 4;
if (this.logCounter > 0) {
this.logCounter = DIGITS * 16;
}
if (this.collAnalysis > 0) {
this.collAnalysis = DIGITS * 8;
}
this.fortune = this.getFortune();
}
getFortune() {
this.fortuneBreakdown = {};
let SUM = 0;
// Base fortune
const BASE = this.tool.baseStats?.[REFORGES_1.Stat.FarmingFortune] ?? 0;
if (BASE > 0) {
this.fortuneBreakdown['Tool Bonus'] = BASE;
SUM += BASE;
}
// Tool rarity stats
const BASE_RARITY = this.recombobulated ? (0, ITEMSTATS_1.previousRarity)(this.rarity) : this.rarity;
const RARITY_STATS = this.tool.stats?.[BASE_RARITY]?.[REFORGES_1.Stat.FarmingFortune] ?? 0;
if (RARITY_STATS > 0) {
this.fortuneBreakdown['Tool Stats'] = RARITY_STATS;
SUM += RARITY_STATS;
}
// Reforge stats
const REFORGE = this.reforgeStats?.stats?.[REFORGES_1.Stat.FarmingFortune] ?? 0;
if (REFORGE > 0) {
this.fortuneBreakdown[this.reforge?.name ?? 'Reforge'] = REFORGE;
SUM += REFORGE;
}
// Farming for Dummies
if (this.farmingForDummies > 0) {
this.fortuneBreakdown['Farming for Dummies'] = this.farmingForDummies;
SUM += this.farmingForDummies;
}
// Collection analysis and digit bonuses
if (this.tool.type === TOOLS_1.FarmingToolType.MathematicalHoe) {
this.getFarmingAbilityFortune(this);
if (this.logCounter > 0) {
this.fortuneBreakdown['Logarithmic Counter'] = this.logCounter;
SUM += this.logCounter;
}
if (this.collAnalysis > 0) {
this.fortuneBreakdown['Collection Analysis'] = this.collAnalysis;
SUM += this.collAnalysis;
}
}
// Gems
const PERIDOT = (0, GEMS_1.getPeridotFortune)(this.rarity, this.item);
if (PERIDOT > 0) {
this.fortuneBreakdown['Peridot Gems'] = PERIDOT;
SUM += PERIDOT;
}
// Enchantments
const ENCHANTMENTS = Object.entries(this.item.enchantments ?? {});
for (const [ENCHANT, LEVEL] of ENCHANTMENTS) {
if (!LEVEL) continue;
if (ENCHANT in ENCHANTS_1.TURBO_ENCHANTS) {
const MATCHING_CROP = ENCHANTS_1.TURBO_ENCHANTS[ENCHANT];
if (!MATCHING_CROP || MATCHING_CROP !== this.crop) continue;
const GAIN = ENCHANTS_1.TURBO_ENCHANT_FORTUNE * LEVEL;
this.fortuneBreakdown['Turbo'] = GAIN;
SUM += GAIN;
continue;
}
const ENCHANTMENT = ENCHANTS_1.FARMING_ENCHANTS[ENCHANT];
if (!ENCHANTMENT || !LEVEL) continue;
const FORTUNE = ENCHANTMENT.levels?.[LEVEL]?.[REFORGES_1.Stat.FarmingFortune] ?? 0;
if (FORTUNE > 0) {
this.fortuneBreakdown[ENCHANTMENT.name] = FORTUNE;
SUM += FORTUNE;
}
}
const MILESTONE = this.options?.milestones?.[this.crop] ?? 0;
if (MILESTONE && 'dedication' in (this.item.enchantments ?? {})) {
const LEVEL = this.item.enchantments?.dedication;
const ENCHANTMENT = ENCHANTS_1.FARMING_ENCHANTS.dedication;
if (LEVEL && ENCHANTMENT) {
const MULTIPLIER = ENCHANTMENT.multipliedLevels?.[LEVEL]?.[REFORGES_1.Stat.FarmingFortune] ?? 0;
if (MULTIPLIER > 0 && !isNaN(MILESTONE)) {
this.fortuneBreakdown[ENCHANTMENT.name] = MULTIPLIER * MILESTONE;
SUM += MULTIPLIER * MILESTONE;
}
}
}
this.fortune = SUM;
return SUM;
}
getCounter() {
const COUNTER = +(this.item?.attributes?.mined_crops ?? 0);
return COUNTER && !isNaN(COUNTER) ? COUNTER : undefined;
}
getCultivating() {
const CULTIVATING = +(this.item?.attributes?.farmed_cultivating ?? 0);
return CULTIVATING && !isNaN(CULTIVATING) ? CULTIVATING : undefined;
}
getCultivatingLevel() {
return this.item.enchantments?.cultivating ?? 0;
}
get farmed() {
return this.counter ?? this.cultivating ?? 0;
}
isUsed() {
if (this.farmed > 0) return true;
if (this.getCultivatingLevel() > 0) return true;
return false;
}
isMissingDedication() {
return this.item?.enchantments?.dedication && (this.options?.milestones?.[this.crop] ?? 0) <= 0;
}
getFarmingAbilityFortune(tool) {
const REGEX = /§7You have §6\+(\d+)☘/g;
for (const LINE of tool.item.lore ?? []) {
const FOUND = (0, LORE_1.extractNumberFromLine)(LINE, REGEX) ?? 0;
if (!FOUND) continue;
if (!this.logCounter) {
this.logCounter = FOUND;
} else if (!this.collAnalysis) {
this.collAnalysis = FOUND;
}
}
return this.logCounter + this.collAnalysis;
}
static isValid(item) {
if (item instanceof FarmingTool) return true;
return TOOLS_1.FARMING_TOOLS[item.skyblockId] !== undefined;
}
static fromArray(items, options) {
return items
.filter((item) => FarmingTool.isValid(item))
.map((item) => new FarmingTool(item, options))
.sort((a, b) => b.fortune - a.fortune);
}
}
exports.FarmingTool = FarmingTool;
//# sourceMappingURL=farmingtool.js.map