UNPKG

farming-weight

Version:

Tools for calculating farming weight and fortune in Hypixel Skyblock

60 lines 2.16 kB
import { GEMSTONES } from '../../constants/gems.js'; import { statsToEffects } from '../sources/effects-util.js'; export class GemstoneSource { id; name; info; constructor(id, info) { this.id = id; this.name = `${titleCase(id)} Gemstone`; this.info = info; } getStat(hostRarity, gemRarity) { if (!gemRarity) return 0; return this.info.stats[gemRarity]?.[hostRarity] ?? 0; } getEffects(hostRarity, gemRarity, sourceName, multiplier = 1) { const value = this.getStat(hostRarity, gemRarity) * multiplier; if (!value) return []; const rounded = +value.toFixed(2); return statsToEffects({ [this.info.stat]: rounded }, sourceName ?? this.name); } getDeltaEffects(hostRarity, currentGem, nextGem, sourceName, multiplier = 1) { const before = this.getStat(hostRarity, currentGem) * multiplier; const after = this.getStat(hostRarity, nextGem) * multiplier; const delta = +(after - before).toFixed(2); if (!delta) return []; return statsToEffects({ [this.info.stat]: delta }, sourceName ?? this.name); } } export function createGemstoneSources() { return Object.fromEntries(Object.entries(GEMSTONES).map(([id, info]) => [id, new GemstoneSource(id, info)])); } function titleCase(id) { return id .toLowerCase() .split('_') .map((part) => part.charAt(0).toUpperCase() + part.slice(1)) .join(' '); } export function getGemstoneIdFromSlot(slot) { const [gemstoneId] = slot.split('_'); return gemstoneId; } export function getGemstoneSourceFromSlot(slot) { const gemstoneId = getGemstoneIdFromSlot(slot); if (!gemstoneId) return undefined; return GEMSTONE_SOURCES[gemstoneId]; } export const GEMSTONE_SOURCES = createGemstoneSources(); export function getGemstoneStatFromSlot(slot, gemRarity, hostRarity, stat) { const source = getGemstoneSourceFromSlot(slot); if (!source || source.info.stat !== stat) return 0; return source.getStat(hostRarity, gemRarity); } //# sourceMappingURL=base.js.map