UNPKG

farming-weight

Version:

Tools for calculating farming weight and fortune in Hypixel Skyblock

96 lines 4.18 kB
import { BESTIARY_PEST_BRACKETS, DEFAULT_GARDEN_BESTIARY_PEST_BRACKET, FORTUNE_PER_PEST_BRACKET, GARDEN_BESTIARY_BRACKETS, GARDEN_BESTIARY_NAMES, PEST_BESTIARY_IDS, PEST_COLLECTION_ADJUSTMENTS, PEST_COLLECTION_BRACKETS, PEST_EXCHANGE_RATES, PEST_TO_CROP, } from '../constants/pests.js'; export function fortuneFromPests(pests) { return PEST_EXCHANGE_RATES[pests] ?? 0; } export function unlockedPestBestiaryTiers(bestiaryKills, onlyPests = true) { let reachedBrackets = 0; const brackets = BESTIARY_PEST_BRACKETS; for (const [bestiaryId, pestId] of Object.entries(PEST_BESTIARY_IDS)) { if (onlyPests && !pestId) continue; const kills = bestiaryKills[bestiaryId]; if (!kills) continue; const bracket = Object.entries((pestId ? brackets[pestId] : GARDEN_BESTIARY_BRACKETS[bestiaryId]) ?? DEFAULT_GARDEN_BESTIARY_PEST_BRACKET).sort((a, b) => b[1] - a[1]); // Find the highest reached bracket for this pest const unlocked = bracket.find((b) => +kills >= b[1]); reachedBrackets += unlocked ? +unlocked[0] : 0; } return reachedBrackets; } export function fortuneFromPestBestiary(bestiaryKills) { return unlockedPestBestiaryTiers(bestiaryKills, false) * FORTUNE_PER_PEST_BRACKET; } export function getGardenBestiaryProgress(bestiaryKills) { const progress = {}; const brackets = BESTIARY_PEST_BRACKETS; for (const [bestiaryId, pestId] of Object.entries(PEST_BESTIARY_IDS)) { const kills = bestiaryKills[bestiaryId] || 0; const pestName = GARDEN_BESTIARY_NAMES[bestiaryId] || 'Unknown Pest'; const bracket = (pestId ? brackets[pestId] : GARDEN_BESTIARY_BRACKETS[bestiaryId]) ?? DEFAULT_GARDEN_BESTIARY_PEST_BRACKET; const sortedBrackets = Object.entries(bracket).sort((a, b) => +a[1] - +b[1]); let bracketsUnlocked = 0; let nextBracketKills = null; for (const [bracketLevel, bracketKills] of sortedBrackets) { if (kills >= bracketKills) { bracketsUnlocked = +bracketLevel; } else { nextBracketKills = bracketKills; break; } } progress[bestiaryId] = { kills, nextBracketKills, bracketsUnlocked, name: pestName, }; } return progress; } export function uncountedCropsFromPests(pestKills) { const crops = {}; const brackets = PEST_COLLECTION_BRACKETS; for (const [bestiaryKey, pestId] of Object.entries(PEST_BESTIARY_IDS)) { let kills = pestKills[bestiaryKey]; if (!kills || !pestId) continue; const crop = PEST_TO_CROP[pestId]; if (!crop) continue; let pestsToCount = 0; let totalDrops = 0; for (let i = 0; i < brackets.length; i++) { const bracket = brackets[i]; // Exit if there are no more pests to calculate if (kills <= 0) break; const bracketCrops = PEST_COLLECTION_ADJUSTMENTS[pestId][bracket] ?? 0; // Use the last bracket for all remaining pests if (i === brackets.length - 1) { totalDrops += Math.ceil(bracketCrops * kills); continue; } // Get the next bracket to find the maximum pests in the current bracket const nextBracket = brackets.at(i + 1); if (nextBracket === undefined) break; if (!Number.isInteger(nextBracket)) continue; // Calculate the pests to count in the current bracket pestsToCount = Math.min(nextBracket - pestsToCount, kills); if (bracketCrops === 0) { // If the value is 0, we don't need to calculate the drops kills -= pestsToCount; continue; } // Calculate the drops for the current bracket kills -= pestsToCount; totalDrops += Math.ceil(bracketCrops * pestsToCount); } crops[crop] = totalDrops; } return crops; } //# sourceMappingURL=pests.js.map