diff --git a/package.json b/package.json index 047714ba..1a7d052e 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "packageManager": "pnpm@9.7.1", "author": "Kathund", "dependencies": { + "farming-weight": "^0.4.12", "axios": "^1.7.5", "node-cache": "^5.1.2", "prismarine-nbt": "^2.5.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 32f1a5eb..03effb33 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ importers: axios: specifier: ^1.7.5 version: 1.7.5 + farming-weight: + specifier: ^0.4.12 + version: 0.4.12 node-cache: specifier: ^5.1.2 version: 5.1.2 @@ -689,6 +692,9 @@ packages: resolution: {integrity: sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==} engines: {node: '>=16.17'} + farming-weight@0.4.12: + resolution: {integrity: sha512-RIPSSmAkeD/PLU3mQHYkIXkmW6bvpXG6YZ2swlV2wWBQSY2UnzWSECZ1KYYd5YlJiNLtFMGwT7BhjBbHvnZr+A==} + fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -1924,6 +1930,8 @@ snapshots: signal-exit: 4.1.0 strip-final-newline: 3.0.0 + farming-weight@0.4.12: {} + fast-deep-equal@3.1.3: {} fast-glob@3.3.2: diff --git a/src/API/getSkyblockMember.test.ts b/src/API/getSkyblockMember.test.ts index d2e9f40c..7be8aed4 100644 --- a/src/API/getSkyblockMember.test.ts +++ b/src/API/getSkyblockMember.test.ts @@ -121,7 +121,7 @@ test('getSkyblockMember', async () => { expectTypeOf(member.dungeons).toEqualTypeOf(); expect(member.collections).toBeDefined(); - expectTypeOf(member.collections).toEqualTypeOf(); + expectTypeOf(member.collections).toEqualTypeOf>(); expect(member.purse).toBeDefined(); expectTypeOf(member.purse).toEqualTypeOf(); @@ -294,6 +294,11 @@ test('getSkyblockMember', async () => { expectTypeOf(member.getNetworth).toEqualTypeOf<() => Promise>(); expectTypeOf(member.getNetworth()).toEqualTypeOf>(); + expect(member.getFarmingWeight()).toBeDefined(); + expectTypeOf(member.getFarmingWeight).toEqualTypeOf<() => number>(); + expectTypeOf(member.getFarmingWeight()).toEqualTypeOf(); + expect(member.getFarmingWeight()).greaterThanOrEqual(0); + expect(member.toString()).toBeDefined(); expect(member.toString()).toBe(member.uuid); expectTypeOf(member.toString()).toEqualTypeOf(); diff --git a/src/structures/SkyBlock/SkyblockMember.ts b/src/structures/SkyBlock/SkyblockMember.ts index 93d64655..7bf398cf 100644 --- a/src/structures/SkyBlock/SkyblockMember.ts +++ b/src/structures/SkyBlock/SkyblockMember.ts @@ -25,6 +25,7 @@ import Constants from '../../utils/Constants'; import SkyblockGarden from './SkyblockGarden'; import SkyblockMuseum from './SkyblockMuseum'; import SkyblockPet from './SkyblockPet'; +import { createFarmingWeightCalculator } from 'farming-weight'; export interface SkyblockMemberEquipment { gauntlet: SkyblockInventoryItem | null; @@ -61,7 +62,7 @@ class SkyblockMember { bestiary: number; slayer: SkyblockMemberSlayer | null; dungeons: SkyblockMemberDungeons | null; - collections: object; + collections: Record; purse: number; stats: SkyblockMemberStats | null; pets: SkyblockPet[]; @@ -75,6 +76,7 @@ class SkyblockMember { getEquipment: () => Promise; getPersonalVault: () => Promise; getNetworth: () => Promise; + getFarmingWeight: () => number; constructor(data: Record) { this.uuid = data.uuid; this.gameMode = data.gameMode; @@ -229,6 +231,21 @@ class SkyblockMember { return null; } }; + this.getFarmingWeight = () => { + try { + return createFarmingWeightCalculator({ + collection: this.collections, + farmingXp: this.skills.farming.xp, + levelCapUpgrade: this.jacob.perks.farmingLevelCap, + anitaBonusFarmingFortuneLevel: this.jacob.perks.doubleDrops, + minions: data.m.player_data.crafted_generators, + contests: Object.values(this.jacob.contests), + pests: data.m.bestiary.kills + }).getWeightInfo().totalWeight; + } catch { + return 0; + } + }; } toString(): string {