UNPKG

farming-weight

Version:

Tools for calculating farming weight and fortune in Hypixel Skyblock

177 lines 6.43 kB
import { Stat } from '../constants/stats.js'; export function getSourceProgress(upgradeable, sources, zeroed = false, stats) { const result = []; // Ensure the item fortune is up to date if ('getFortune' in upgradeable && typeof upgradeable.getFortune === 'function') { upgradeable.getFortune(); } for (const source of sources) { if (!source.exists(upgradeable)) continue; const alwaysInclude = source.alwaysInclude === true; const max = source.max(upgradeable); const current = zeroed ? 0 : source.current(upgradeable); const progress = { name: source.name, current: current, max, ratio: Math.min(isNaN(current / max) ? 0 : current / max, 1), }; if (alwaysInclude) progress.alwaysInclude = true; // Per-stat progress (optional; only when explicitly requested) if (stats && stats.length > 0) { const perStat = {}; for (const stat of stats) { const maxForStat = source.maxStat ? source.maxStat(upgradeable, stat) : stat === Stat.FarmingFortune ? max : 0; const currentForStat = zeroed ? 0 : source.currentStat ? source.currentStat(upgradeable, stat) : stat === Stat.FarmingFortune ? current : 0; if (maxForStat !== 0 || currentForStat !== 0) { perStat[stat] = { current: currentForStat, max: maxForStat, ratio: Math.min(isNaN(currentForStat / maxForStat) ? 0 : currentForStat / maxForStat, 1), }; } } if (Object.keys(perStat).length > 0) { progress.stats = perStat; } } if (source.effects) { const effects = source.effects(upgradeable, stats); if (effects.length > 0) { progress.effects = effects; } } if (source.progress) { const p = source.progress(upgradeable, stats); if (p) { progress.progress = p; } } if (source.active) { progress.active = source.active(upgradeable); // If we also have stat-aware active, attach values for requested stats if (source.activeStat && stats && stats.length > 0) { const activeStats = {}; for (const stat of stats) { const a = source.activeStat(upgradeable, stat); if (a.value !== undefined) activeStats[stat] = a.value; } if (Object.keys(activeStats).length > 0) { progress.active.stats = activeStats; } } } if (source.info) { const { item, info, maxInfo, nextInfo } = source.info(upgradeable); if (item) progress.item = item; if (info) progress.info = info; if (maxInfo) progress.maxInfo = maxInfo; if (nextInfo) progress.nextInfo = nextInfo; } if (source.wiki) { const wiki = source.wiki(upgradeable); if (wiki) progress.wiki = wiki; } if (source.api === false) { progress.api = false; } if (source.upgrades) { const upgrades = source.upgrades(upgradeable, stats); for (const upgrade of upgrades) { upgrade.max = upgrade.max ?? max; upgrade.wiki = upgrade.wiki ?? progress.wiki; } if (upgrades.length > 0) { progress.upgrades = upgrades; } } // Keep legacy progress output clean: skip sources that contribute nothing // (but preserve stat-aware or upgrade-bearing sources). if (progress.max === 0 && progress.current === 0 && !progress.alwaysInclude && !progress.stats && !progress.effects && !progress.upgrades && !progress.progress) { continue; } result.push(progress); } return result; } export function getUpgradeSourceProgress(input, sources) { const result = []; // Use optional input initialization if (input && typeof input === 'object' && 'init' in input && typeof input.init === 'function') { input.init(); } for (const source of sources) { if (!source.exists(input)) continue; source.current(input); // Call to make sure any side effects are applied const max = source.max(input); const progress = source.progress(input); if (source.key) { if (typeof source.key === 'function') { progress.key = source.key(input); } else { progress.key = source.key; } } if (source.active) { progress.active = source.active(input); } if (source.info) { const { item, info, maxInfo, nextInfo } = source.info(input); if (item) progress.item = item; if (info) progress.info = info; if (maxInfo) progress.maxInfo = maxInfo; if (nextInfo) progress.nextInfo = nextInfo; } if (source.wiki) { const wiki = source.wiki(input); if (wiki) progress.wiki = wiki; } if (source.api === false) { progress.api = false; } if (source.upgrades) { const upgrades = source.upgrades(input); for (const upgrade of upgrades) { upgrade.max = upgrade.max ?? max; upgrade.wiki = upgrade.wiki ?? progress.wiki; } if (upgrades.length > 0) { progress.upgrades = upgrades; } } result.push(progress); } return result; } //# sourceMappingURL=getsourceprogress.js.map