Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 5314570

Browse files
authored
Merge pull request #2281 from SkyCryptWebsite/fix-farming
Fix the farming skill section
2 parents fd9e274 + 63b2ef8 commit 5314570

4 files changed

Lines changed: 182 additions & 26 deletions

File tree

src/constants/weight/farming-weight.js

Lines changed: 167 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,111 @@
1+
const CROP_TO_PEST = {
2+
CACTUS: "Mite",
3+
CARROT_ITEM: "Cricket",
4+
"INK_SACK:3": "Moth",
5+
MELON: "Earthworm",
6+
MUSHROOM_COLLECTION: "Slug",
7+
NETHER_STALK: "Beetle",
8+
POTATO_ITEM: "Locust",
9+
PUMPKIN: "Rat",
10+
SUGAR_CANE: "Mosquito",
11+
WHEAT: "Fly",
12+
};
13+
14+
const PEST_COLLECTION_BRACKETS = [0, 50, 100, 250, 500, 750, 1000];
15+
16+
const PEST_COLLECTION_ADJUSTMENTS = {
17+
Mite: {
18+
0: 0,
19+
50: 1285.333312988281,
20+
100: 1898.6666259765625,
21+
250: 2512,
22+
500: 3125.333251953125,
23+
750: 3493.333251953125,
24+
1000: 3861.3333740234375,
25+
},
26+
Cricket: {
27+
0: 0,
28+
50: 1430.3999755859375,
29+
100: 2086.399951171875,
30+
250: 2742.4,
31+
500: 3398.39990234375,
32+
750: 3791.99990234375,
33+
1000: 4185.600048828125,
34+
},
35+
Moth: {
36+
0: 0,
37+
50: 1430.3999755859375,
38+
100: 2086.399951171875,
39+
250: 2742.4,
40+
500: 3398.39990234375,
41+
750: 3791.99990234375,
42+
1000: 4185.600048828125,
43+
},
44+
Earthworm: {
45+
0: 0,
46+
50: 2010.6666259765625,
47+
100: 2837.333251953125,
48+
250: 3664,
49+
500: 4490.66650390625,
50+
750: 4986.66650390625,
51+
1000: 5482.666748046875,
52+
},
53+
Slug: {
54+
0: 0,
55+
50: 632.5333312988281,
56+
100: 1053.8666625976562,
57+
250: 1475.2,
58+
500: 1896.5333251953125,
59+
750: 2149.3333251953127,
60+
1000: 2402.133337402344,
61+
},
62+
Beetle: {
63+
0: 0,
64+
50: 1647.9999694824216,
65+
100: 2367.9999389648438,
66+
250: 3088,
67+
500: 3807.9998779296875,
68+
750: 4239.9998779296875,
69+
1000: 4672.000061035156,
70+
},
71+
Locust: {
72+
0: 0,
73+
50: 1647.9999694824216,
74+
100: 2367.9999389648438,
75+
250: 3088,
76+
500: 3807.9998779296875,
77+
750: 4239.9998779296875,
78+
1000: 4672.000061035156,
79+
},
80+
Rat: {
81+
0: 0,
82+
50: 922.6666564941406,
83+
100: 1429.333312988281,
84+
250: 1936,
85+
500: 2442.6666259765625,
86+
750: 2746.6666259765625,
87+
1000: 3050.6666870117188,
88+
},
89+
Mosquito: {
90+
0: 0,
91+
50: 1285.333312988281,
92+
100: 1898.6666259765625,
93+
250: 2512,
94+
500: 3125.333251953125,
95+
750: 3493.333251953125,
96+
1000: 3861.3333740234375,
97+
},
98+
Fly: {
99+
0: 0,
100+
50: 7179.839925842285,
101+
100: 11197.43985168457,
102+
250: 15215.04,
103+
500: 19232.63970336914,
104+
750: 21643.19970336914,
105+
1000: 24053.76014831543,
106+
},
107+
};
108+
1109
const crops = {
2110
CACTUS: {
3111
name: "Cactus",
@@ -15,6 +123,10 @@ const crops = {
15123
name: "Melon",
16124
weight: 485_308.47,
17125
},
126+
MUSHROOM_COLLECTION: {
127+
name: "Mushroom",
128+
weight: 90_178.06,
129+
},
18130
NETHER_STALK: {
19131
name: "Nether Wart",
20132
weight: 250_000,
@@ -36,6 +148,36 @@ const crops = {
36148
weight: 100_000,
37149
},
38150
};
151+
function calculatePestCrops(pest) {
152+
let kills = pest?.kills ?? 0;
153+
let pestCount = 0;
154+
let pestCropCount = 0;
155+
for (let i = 0; i < PEST_COLLECTION_BRACKETS.length; i++) {
156+
const bracket = PEST_COLLECTION_BRACKETS[i];
157+
158+
if (kills <= 0) break;
159+
160+
const bracketCrops = PEST_COLLECTION_ADJUSTMENTS[pest.name][bracket];
161+
162+
if (i === PEST_COLLECTION_BRACKETS.length - 1) {
163+
pestCropCount += Math.ceil(bracketCrops * kills);
164+
break;
165+
}
166+
167+
const nextBracket = PEST_COLLECTION_BRACKETS.at(i + 1);
168+
169+
pestCount = Math.min(nextBracket - pestCount, kills);
170+
171+
if (bracketCrops === 0) {
172+
kills -= pestCount;
173+
continue;
174+
}
175+
176+
kills -= pestCount;
177+
pestCropCount += Math.ceil(bracketCrops * pestCount);
178+
}
179+
return pestCropCount;
180+
}
39181

40182
export function calculateFarmingWeight(userProfile) {
41183
const output = {
@@ -50,12 +192,16 @@ export function calculateFarmingWeight(userProfile) {
50192
};
51193

52194
const farmingCollection = userProfile?.collections?.farming?.collections;
195+
const pests = userProfile?.bestiary?.categories?.garden?.mobs;
53196
if (farmingCollection !== undefined) {
54197
let weight = 0;
55198
for (const [name, crop] of Object.entries(crops)) {
56199
const { amount = 0 } = farmingCollection.find((a) => a.id === name);
57200

58-
const calculated = amount / crop.weight;
201+
const pest = pests.find((a) => a.name === CROP_TO_PEST[name]);
202+
const pestCrops = calculatePestCrops(pest);
203+
204+
const calculated = Math.max(amount - pestCrops, 0) / crop.weight;
59205

60206
output.crops[name] = {
61207
name: crop.name,
@@ -71,18 +217,16 @@ export function calculateFarmingWeight(userProfile) {
71217

72218
const mushroomCollection = farmingCollection.find((a) => a.id === "MUSHROOM_COLLECTION")?.amount ?? 0;
73219

74-
const total = output.weight + mushroomCollection / mushroomScaling;
220+
const total = output.weight;
75221
const doubleBreakRatio = total <= 0 ? 0 : (output.crops.CACTUS.weight + output.crops.SUGAR_CANE.weight) / total;
76222
const normalRatio = total <= 0 ? 0 : (total - output.crops.CACTUS.weight - output.crops.SUGAR_CANE.weight) / total;
77223

78224
const mushroomWeight =
79225
doubleBreakRatio * (mushroomCollection / (2 * mushroomScaling)) +
80226
normalRatio * (mushroomCollection / mushroomScaling);
81227

82-
output.crops.MUSHROOM = {
83-
name: "Mushroom",
84-
weight: mushroomWeight,
85-
};
228+
output.weight -= output.crops.MUSHROOM_COLLECTION.weight;
229+
output.crops.MUSHROOM_COLLECTION.weight = mushroomWeight;
86230
output.weight += mushroomWeight;
87231
}
88232

@@ -113,14 +257,25 @@ export function calculateFarmingWeight(userProfile) {
113257

114258
bonus += doubleDrops * 2;
115259

116-
const goldMedals = userProfile.farming?.total_badges?.gold ?? 0;
117-
const goldMedalBonus = Math.min(Math.floor(goldMedals / 50) * 25, 500);
118-
output.bonuses.gold_medals = {
119-
medals: goldMedals,
120-
weight: goldMedalBonus,
260+
const maxMedals = 1000;
261+
const medals = userProfile.farming?.total_badges;
262+
const diamondMedals = medals?.diamond ?? 0;
263+
const platinumMedals = Math.min(medals?.platinum ?? 0, maxMedals - diamondMedals);
264+
const goldMedals = Math.min(medals?.gold ?? 0, maxMedals - diamondMedals - platinumMedals);
265+
266+
const diamondMedalBonus = diamondMedals * 0.75;
267+
const platinumMedalBonus = platinumMedals * 0.5;
268+
const goldMedalBonus = goldMedals * 0.25;
269+
270+
const contestMedals = goldMedals + platinumMedals + diamondMedals;
271+
const contestMedalBonus = goldMedalBonus + platinumMedalBonus + diamondMedalBonus;
272+
273+
output.bonuses.contest_medals = {
274+
medals: contestMedals,
275+
weight: contestMedalBonus,
121276
};
122277

123-
bonus += goldMedalBonus;
278+
bonus += contestMedalBonus;
124279
}
125280

126281
if (userProfile.minions !== undefined) {

src/lib.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export async function getStats(
188188
bingo: { fn: stats.getBingoData, args: { bingoProfile } },
189189
user_data: { fn: stats.getUserData, args: { userProfile } },
190190
currencies: { fn: stats.getCurrenciesData, args: { userProfile, profile } },
191-
weight: { fn: stats.getWeight, args: { output }, promise: true },
191+
weight: { fn: stats.getWeight, args: { output }, promise: true, awaitPromises: true },
192192
accessories: { fn: stats.getMissingAccessories, args: { output, packs }, promise: true, awaitPromises: true },
193193
temp_stats: { fn: stats.getTempStats, args: { userProfile } },
194194
rift: { fn: stats.getRift, args: { userProfile } },

src/stats/farming.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export function getFarming(userProfile) {
9191
crop: crop,
9292
collected: data.collected,
9393
claimed: data.claimed_rewards || false,
94-
medal: null,
94+
medal: data.claimed_medal || null,
9595
};
9696

9797
const placing = {};
@@ -102,18 +102,18 @@ export function getFarming(userProfile) {
102102
const participants = data.claimed_participants;
103103

104104
// Use the claimed medal if it exists and is valid
105-
if (contest.claimed_medal) {
106-
contest.medal = contest.claimed_medal;
107-
} else if (placing.position <= Math.floor(participants * 0.02)) {
108-
contest.medal = "diamond";
109-
} else if (placing.position <= Math.floor(participants * 0.05)) {
110-
contest.medal = "platinum";
111-
} else if (placing.position <= Math.floor(participants * 0.1)) {
112-
contest.medal = "gold";
113-
} else if (placing.position <= Math.floor(participants * 0.3)) {
114-
contest.medal = "silver";
115-
} else if (placing.position <= Math.floor(participants * 0.6)) {
116-
contest.medal = "bronze";
105+
if (!contest.medal) {
106+
if (placing.position <= Math.floor(participants * 0.02)) {
107+
contest.medal = "diamond";
108+
} else if (placing.position <= Math.floor(participants * 0.05)) {
109+
contest.medal = "platinum";
110+
} else if (placing.position <= Math.floor(participants * 0.1)) {
111+
contest.medal = "gold";
112+
} else if (placing.position <= Math.floor(participants * 0.3)) {
113+
contest.medal = "silver";
114+
} else if (placing.position <= Math.floor(participants * 0.6)) {
115+
contest.medal = "bronze";
116+
}
117117
}
118118

119119
// Count the medal if it exists

views/stats.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ const metaDescription = getMetaDescription()
652652
<%- include('./sections/stats/minions.ejs', { skillItems }); %>
653653
<% } %>
654654
655+
<!-- Bestiary-->
655656
<% if (calculated.bestiary !== undefined) {%>
656657
<%- include('./sections/stats/bestiary.ejs', {}); %>
657658
<% } %>

0 commit comments

Comments
 (0)