UNPKG

farming-weight

Version:

Tools for calculating farming weight and fortune in Hypixel Skyblock

223 lines (222 loc) 7.75 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports.FarmingPlayer = exports.createFarmingPlayer = void 0; const CROPS_1 = require('../constants/crops'); const PERSONALBESTS_1 = require('../constants/personalbests'); const PESTS_1 = require('../util/pests'); const SPECIFIC_1 = require('../constants/specific'); const NAMES_1 = require('../util/names'); const FARMINGACCESSORY_1 = require('./farmingaccessory'); const FARMINGARMOR_1 = require('./farmingarmor'); const FARMINGPET_1 = require('./farmingpet'); const FARMINGTOOL_1 = require('./farmingtool'); const FARMINGEQUIPMENT_1 = require('./farmingequipment'); function createFarmingPlayer(options) { return new FarmingPlayer(options); } exports.createFarmingPlayer = createFarmingPlayer; class FarmingPlayer { constructor(options) { this.options = options; options.tools ??= []; if (options.tools[0] instanceof FARMINGTOOL_1.FarmingTool) { this.tools = options.tools; for (const TOOL of this.tools) TOOL.setOptions(options); } else { this.tools = FARMINGTOOL_1.FarmingTool.fromArray(options.tools, options); } this.selectedTool = this.options.selectedTool ?? this.tools[0]; options.pets ??= []; if (options.pets[0] instanceof FARMINGPET_1.FarmingPet) { this.pets = options.pets.sort((a, b) => b.fortune - a.fortune); for (const PET of this.pets) PET.setOptions(options); } else { this.pets = FARMINGPET_1.FarmingPet.fromArray(options.pets, options); } this.selectedPet = this.options.selectedPet; options.armor ??= []; if (options.armor instanceof FARMINGARMOR_1.ArmorSet) { this.armorSet = options.armor; this.armor = this.armorSet.pieces; for (const A of this.armor) A.setOptions(options); this.armorSet.getFortuneBreakdown(true); } else if (options.armor[0] instanceof FARMINGARMOR_1.FarmingArmor) { this.armor = options.armor.sort((a, b) => b.fortune - a.fortune); for (const A of this.armor) A.setOptions(options); this.armorSet = new FARMINGARMOR_1.ArmorSet(this.armor); } else { this.armor = FARMINGARMOR_1.FarmingArmor.fromArray(options.armor, options); this.armorSet = new FARMINGARMOR_1.ArmorSet(this.armor); } options.equipment ??= []; if (options.equipment[0] instanceof FARMINGEQUIPMENT_1.FarmingEquipment) { this.equipment = options.equipment.sort((a, b) => b.fortune - a.fortune); for (const E of this.equipment) E.setOptions(options); } else { this.equipment = FARMINGEQUIPMENT_1.FarmingEquipment.fromArray(options.equipment, options); } options.accessories ??= []; if (options.accessories[0] instanceof FARMINGACCESSORY_1.FarmingAccessory) { this.accessories = options.accessories.sort((a, b) => b.fortune - a.fortune); } else { this.accessories = FARMINGACCESSORY_1.FarmingAccessory.fromArray(options.accessories); } this.fortune = this.getGeneralFortune(); } changeArmor(armor) { this.armorSet = new FARMINGARMOR_1.ArmorSet(armor.sort((a, b) => b.fortune - a.fortune)); } selectTool(tool) { this.selectedTool = tool; this.fortune = this.getGeneralFortune(); } selectPet(pet) { this.selectedPet = pet; this.fortune = this.getGeneralFortune(); } setStrength(strength) { this.options.strength = strength; for (const PET of this.pets) { PET.fortune = PET.getFortune(); } this.fortune = this.getGeneralFortune(); } getGeneralFortune() { let SUM = 0; const BREAKDOWN = {}; // Plots const PLOTS = SPECIFIC_1.FORTUNE_PER_PLOT * (this.options.plotsUnlocked ?? 0); if (PLOTS > 0) { BREAKDOWN['Unlocked Plots'] = PLOTS; SUM += PLOTS; } // Farming Level const LEVEL = SPECIFIC_1.FORTUNE_PER_FARMING_LEVEL * (this.options.farmingLevel ?? 0); if (LEVEL > 0) { BREAKDOWN['Farming Level'] = LEVEL; SUM += LEVEL; } // Bestiary if (this.options.bestiaryKills) { const BESTIARY = (0, PESTS_1.fortuneFromPestBestiary)(this.options.bestiaryKills); if (BESTIARY > 0) { BREAKDOWN['Pest Bestiary'] = BESTIARY; SUM += BESTIARY; } } // Armor Set const ARMOR_SET = this.armorSet.fortune; if (ARMOR_SET > 0) { BREAKDOWN['Armor Set'] = ARMOR_SET; SUM += ARMOR_SET; } // Lotus Gear const EQUIPMENT = this.equipment.reduce((a, b) => a + b.fortune, 0); if (EQUIPMENT > 0) { BREAKDOWN['Equipment'] = EQUIPMENT; SUM += EQUIPMENT; } // Anita Bonus const ANITA_BONUS = (this.options.anitaBonus ?? 0) * SPECIFIC_1.FORTUNE_PER_ANITA_BONUS; if (ANITA_BONUS > 0) { BREAKDOWN['Anita Bonus Drops'] = ANITA_BONUS; SUM += ANITA_BONUS; } // Community Center const COMMUNITY_CENTER = (this.options.communityCenter ?? 0) * SPECIFIC_1.FORTUNE_PER_COMMUNITY_CENTER; if (COMMUNITY_CENTER > 0) { BREAKDOWN['Community Center'] = COMMUNITY_CENTER; SUM += COMMUNITY_CENTER; } // Selected Pet const PET = this.selectedPet; if (PET && PET.fortune > 0) { BREAKDOWN[PET.info.name ?? 'Selected Pet'] = PET.fortune; SUM += PET.fortune; } // Accessories, only count highest fortune from each family const FAMILIES = new Map(); for (const ACCESSORY of this.accessories.filter((a) => a.fortune > 0).sort((a, b) => b.fortune - a.fortune)) { if (ACCESSORY.info.family) { if (!FAMILIES.has(ACCESSORY.info.family)) { FAMILIES.set(ACCESSORY.info.family, ACCESSORY); } else { continue; } } BREAKDOWN[ACCESSORY.item.name ?? ACCESSORY.item.skyblockId ?? 'Accessory [Error]'] = ACCESSORY.fortune; SUM += ACCESSORY.fortune; } // Refined Truffles const TRUFFLES = Math.min(5, this.options.refinedTruffles ?? 0); if (TRUFFLES > 0) { BREAKDOWN['Refined Truffles'] = TRUFFLES; SUM += TRUFFLES; } // Extra Fortune for (const EXTRA of this.options.extraFortune ?? []) { if (EXTRA.crop) continue; BREAKDOWN[EXTRA.name ?? 'Extra Fortune'] = EXTRA.fortune; SUM += EXTRA.fortune; } this.breakdown = BREAKDOWN; return SUM; } getCropFortune(crop, tool = this.selectedTool) { if (tool) { this.selectTool(tool); } let SUM = 0; const BREAKDOWN = {}; // Crop upgrades const UPGRADE = SPECIFIC_1.FORTUNE_PER_CROP_UPGRADE * (this.options.cropUpgrades?.[crop] ?? 0); if (UPGRADE > 0) { BREAKDOWN['Crop Upgrade'] = UPGRADE; SUM += UPGRADE; } // Personal bests const PERSONAL_BEST = this.options.personalBests?.[(0, NAMES_1.getItemIdFromCrop)(crop)] ?? this.options.personalBests?.[(0, NAMES_1.getCropDisplayName)(crop).replace(/ /g, '')]; if (PERSONAL_BEST) { const FORTUNE = (0, PERSONALBESTS_1.fortuneFromPersonalBestContest)(crop, PERSONAL_BEST); if (FORTUNE > 0) { BREAKDOWN['Personal Best'] = FORTUNE; SUM += FORTUNE; } } // Tool const TOOL_FORTUNE = this.selectedTool?.fortune ?? 0; if (TOOL_FORTUNE > 0) { BREAKDOWN['Selected Tool'] = TOOL_FORTUNE; SUM += TOOL_FORTUNE; } // Accessories //* There's only one accessory family for farming right now const ACCESSORY = this.accessories.find((a) => a.info.crops && a.info.crops.includes(crop)); if (ACCESSORY && ACCESSORY.fortune > 0) { BREAKDOWN[ACCESSORY.item.name ?? 'Accessories'] = ACCESSORY.fortune ?? 0; SUM += ACCESSORY.fortune ?? 0; } // Exportable Crops if (this.options.exportableCrops?.[crop]) { const EXPORTABLE = this.options.exportableCrops[crop]; if (EXPORTABLE) { BREAKDOWN['Exportable Crop'] = CROPS_1.EXPORTABLE_CROP_FORTUNE; SUM += CROPS_1.EXPORTABLE_CROP_FORTUNE; } } // Extra Fortune for (const EXTRA of this.options.extraFortune ?? []) { if (EXTRA.crop !== crop) continue; BREAKDOWN[EXTRA.name ?? 'Extra Fortune'] = EXTRA.fortune; SUM += EXTRA.fortune; } return { fortune: SUM, breakdown: BREAKDOWN, }; } } exports.FarmingPlayer = FarmingPlayer; //# sourceMappingURL=player.js.map