farming-weight
Version:
Tools for calculating farming weight and fortune in Hypixel Skyblock
88 lines • 3.37 kB
JavaScript
import { Stat } from '../constants/stats.js';
import { FARMING_ACCESSORIES_INFO } from '../items/accessories.js';
import { statsToEffects } from '../items/sources/effects-util.js';
import { gemEffects } from '../items/sources/gems.js';
import { getSourceProgress } from '../upgrades/getsourceprogress.js';
import { ACCESSORY_FORTUNE_SOURCES } from '../upgrades/sources/accessorysources.js';
import { getGemStat, getPeridotFortune } from '../util/gems.js';
import { UpgradeableBase } from './upgradeablebase.js';
export class FarmingAccessory extends UpgradeableBase {
constructor(item, options) {
super({ item, options, items: FARMING_ACCESSORIES_INFO });
this.getFortune();
}
getProgress(stats, zeroed = false) {
return getSourceProgress(this, ACCESSORY_FORTUNE_SOURCES, zeroed, stats);
}
setOptions(options) {
this.options = options;
this.getFortune();
}
getStat(stat) {
let sum = 0;
// Base fortune
sum += this.info.baseStats?.[stat] ?? 0;
sum += this.getCalculatedStats()[stat] ?? 0;
// Gems
const gemStat = getGemStat(this.item, stat, this.rarity);
if (gemStat > 0) {
sum += +(gemStat / 2).toFixed(2);
}
return sum;
}
/**
* Returns the declarative `Effect[]` representation of every contribution
* this accessory makes. Base stats, computed stats, and (halved) gem
* stats.
*/
getEffects(_env) {
const sourceName = this.info.name;
const effects = [];
effects.push(...statsToEffects(this.info.baseStats, sourceName));
effects.push(...statsToEffects(this.getCalculatedStats(), sourceName));
effects.push(...gemEffects(this.item, this.rarity, `${sourceName} (Gems)`, 0.5));
return effects;
}
getFortune() {
this.fortuneBreakdown = {};
let sum = 0;
// Base fortune
const base = (this.info.baseStats?.[Stat.FarmingFortune] ?? 0) + (this.getCalculatedStats()[Stat.FarmingFortune] ?? 0);
if (base > 0) {
this.fortuneBreakdown['Base Stats'] = base;
sum += base;
}
// Gems
let peridot = getPeridotFortune(this.rarity, this.item);
if (peridot > 0) {
peridot = +(peridot / 2).toFixed(2); // Only half the stats are applied on accessories
this.fortuneBreakdown['Peridot Gems'] = peridot;
sum += peridot;
}
this.fortune = sum;
return sum;
}
static isValid(item) {
return FARMING_ACCESSORIES_INFO[item.skyblockId] !== undefined;
}
static fromArray(items, options) {
return items
.filter((item) => FarmingAccessory.isValid(item))
.map((item) => new FarmingAccessory(item, options))
.sort((a, b) => b.fortune - a.fortune);
}
static fakeItem(info, options) {
const fake = {
name: info.name,
skyblockId: info.skyblockId,
uuid: crypto.randomUUID(),
lore: ['This is a fake item used for upgrade calculations!'],
attributes: {},
enchantments: {},
};
if (!FarmingAccessory.isValid(fake))
return undefined;
return new FarmingAccessory(fake, options);
}
}
//# sourceMappingURL=farmingaccessory.js.map