farming-weight
Version:
Tools for calculating farming weight and fortune in Hypixel Skyblock
193 lines (192 loc) • 6.61 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
exports.createFarmingWeightCalculator = void 0;
const CROPS_1 = require('../constants/crops');
const WEIGHT_1 = require('../constants/weight');
const JACOB_1 = require('../util/jacob');
const PESTS_1 = require('../util/pests');
function createFarmingWeightCalculator(info) {
return new FarmingWeight(info);
}
exports.createFarmingWeightCalculator = createFarmingWeightCalculator;
const CROPS = [
CROPS_1.Crop.Cactus,
CROPS_1.Crop.Carrot,
CROPS_1.Crop.CocoaBeans,
CROPS_1.Crop.Melon,
CROPS_1.Crop.Mushroom,
CROPS_1.Crop.NetherWart,
CROPS_1.Crop.Potato,
CROPS_1.Crop.Pumpkin,
CROPS_1.Crop.SugarCane,
CROPS_1.Crop.Wheat,
];
class FarmingWeight {
info;
constructor(info) {
this.info = info;
this.collection = {};
this.levelCapUpgrade = info?.levelCapUpgrade ?? 0;
this.anitaBonusFarmingFortuneLevel = info?.anitaBonusFarmingFortuneLevel ?? 0;
this.farmingXp = info?.farmingXp ?? 0;
this.earnedMedals = { diamond: 0, platinum: 0, gold: 0 };
this.tier12MinionCount = 0;
this.bonusSources = {};
this.uncountedCrops = {};
this.setContests(info?.contests ?? []);
this.calcUncountedCrops(info?.pests ?? {});
this.setCropsFromCollections(info?.collection ?? {});
this.addMinions(info?.minions ?? []);
}
/**
* Expectes a dictionary of collections and amounts with the default Hypixel SkyBlock IDs
* @param {Record<string, number>} collections
* @returns {FarmingWeight}
*/
setCropsFromCollections(collections) {
for (const CROP of CROPS) {
this.collection[CROP] = collections[CROP] ?? 0;
}
this.getCropWeights();
return this;
}
setCrop = (crop, collection) => {
this.collection[crop] = collection;
this.getCropWeights();
return this;
};
setLevelCap = (levelCap) => {
this.levelCapUpgrade = levelCap;
return this;
};
setFarmingXp = (farmingXp) => {
this.farmingXp = farmingXp;
return this;
};
setAnitaBonusLevel = (anitaBonusFarmingFortuneLevel) => {
this.anitaBonusFarmingFortuneLevel = anitaBonusFarmingFortuneLevel;
return this;
};
addMinions = (minions) => {
for (const MINION of minions) {
if (!MINION.endsWith('_12')) continue;
if (!WEIGHT_1.TIER_12_MINIONS.includes(MINION)) continue;
this.tier12MinionCount++;
}
return this;
};
setEarnedMedals = ({ diamond, platinum, gold }) => {
this.earnedMedals = {
diamond: diamond ?? this.earnedMedals.diamond,
platinum: platinum ?? this.earnedMedals.platinum,
gold: gold ?? this.earnedMedals.gold,
};
return this;
};
setTier12MinionCount = (count) => {
this.tier12MinionCount = count;
return this;
};
setContests = (contests) => {
if (!contests?.length) return this;
for (const CONTEST of contests) {
const MEDAL = (0, JACOB_1.calculateJacobContestMedal)(CONTEST);
if (!MEDAL) continue;
if (MEDAL === 'diamond') {
this.earnedMedals.diamond++;
} else if (MEDAL === 'platinum') {
this.earnedMedals.platinum++;
} else if (MEDAL === 'gold') {
this.earnedMedals.gold++;
}
}
this.getBonusWeights();
return this;
};
getWeightInfo = () => {
const BONUS = this.getBonusWeights();
const crops = this.getCropWeights();
const BONUS_TOTAL = Object.values(BONUS).reduce((a, b) => a + b, 0);
const CROP_TOTAL = Object.values(crops).reduce((a, b) => a + b, 0);
return {
totalWeight: BONUS_TOTAL + CROP_TOTAL,
bonusWeight: BONUS_TOTAL,
cropWeight: CROP_TOTAL,
bonusSources: BONUS,
uncountedCrops: this.uncountedCrops,
};
};
getBonusWeights = () => {
this.bonusSources = {};
if (this.farmingXp >= 111_672_425 && this.levelCapUpgrade >= 10) {
// Farming 60 bonus
this.bonusSources['Farming 60'] = WEIGHT_1.BONUS_WEIGHT.Farming60Bonus;
} else if (this.farmingXp >= 55_172_425) {
// Farming 50 bonus
this.bonusSources['Farming 50'] = WEIGHT_1.BONUS_WEIGHT.Farming50Bonus;
}
// Tier 12 minion bonus
if (this.tier12MinionCount > 0) {
this.bonusSources['Tier 12 Minions'] = this.tier12MinionCount * WEIGHT_1.BONUS_WEIGHT.MinionRewardWeight;
}
// Anita bonus
if (this.anitaBonusFarmingFortuneLevel > 0) {
this.bonusSources['Anita Bonus'] =
this.anitaBonusFarmingFortuneLevel * WEIGHT_1.BONUS_WEIGHT.AnitaBuffBonusMultiplier;
}
const MAX_MEDALS = WEIGHT_1.BONUS_WEIGHT.MaxMedalsCounted;
if (this.earnedMedals.diamond >= MAX_MEDALS) {
this.bonusSources['Contest Medals'] =
WEIGHT_1.BONUS_WEIGHT.WeightPerDiamondMedal * WEIGHT_1.BONUS_WEIGHT.MaxMedalsCounted;
} else {
const DIAMOND = this.earnedMedals.diamond;
const PLATINUM = Math.min(MAX_MEDALS - DIAMOND, this.earnedMedals.platinum);
const GOLD = Math.min(MAX_MEDALS - DIAMOND - PLATINUM, this.earnedMedals.gold);
const MEDALS =
DIAMOND * WEIGHT_1.BONUS_WEIGHT.WeightPerDiamondMedal +
PLATINUM * WEIGHT_1.BONUS_WEIGHT.WeightPerPlatinumMedal +
GOLD * WEIGHT_1.BONUS_WEIGHT.WeightPerGoldMedal;
this.bonusSources['Contest Medals'] = MEDALS;
}
return this.bonusSources;
};
getCropWeights = () => {
const CROP_WEIGHT = {};
let TOTAL_WEIGHT = 0;
let DOUBLE_BREAK_WEIGHT = 0;
for (const CROP of CROPS) {
let COLLECTED = this.collection[CROP] ?? 0;
// Subtract uncounted crops
if (this.uncountedCrops[CROP]) {
COLLECTED = Math.max(0, COLLECTED - (this.uncountedCrops[CROP] ?? 0));
}
const WEIGHT = COLLECTED / WEIGHT_1.CROP_WEIGHT[CROP];
TOTAL_WEIGHT += WEIGHT;
if (CROP === CROPS_1.Crop.Cactus || CROP === CROPS_1.Crop.SugarCane) {
DOUBLE_BREAK_WEIGHT += WEIGHT;
}
CROP_WEIGHT[CROP] = WEIGHT;
}
// Mushroom is a special case, it needs to be calculated dynamically based on the
// ratio between the farmed crops that give two mushrooms per break with cow pet
// and the farmed crops that give one mushroom per break with cow pet
const MUSHROOM_COLLECTION = this.collection[CROPS_1.Crop.Mushroom] ?? 0;
const MUSHROOM_WEIGHT_NUMBER = WEIGHT_1.CROP_WEIGHT[CROPS_1.Crop.Mushroom];
const DOUBLE_BREAK_RATIO = DOUBLE_BREAK_WEIGHT / TOTAL_WEIGHT;
const NORMAL_CROP_RATIO = (TOTAL_WEIGHT - DOUBLE_BREAK_WEIGHT) / TOTAL_WEIGHT;
const MUSHROOM_WEIGHT =
DOUBLE_BREAK_RATIO * (MUSHROOM_COLLECTION / (MUSHROOM_WEIGHT_NUMBER * 2)) +
NORMAL_CROP_RATIO * (MUSHROOM_COLLECTION / MUSHROOM_WEIGHT_NUMBER);
CROP_WEIGHT[CROPS_1.Crop.Mushroom] = MUSHROOM_WEIGHT;
return CROP_WEIGHT;
};
calcUncountedCrops = (bestiary) => {
this.uncountedCrops = (0, PESTS_1.uncountedCropsFromPests)(bestiary);
this.getCropWeights();
return this;
};
getCropWeight = (crop) => {
WEIGHT_1.CROP_WEIGHT[crop];
};
}
//# sourceMappingURL=weightcalc.js.map