Skip to content

Commit

Permalink
Merge pull request #2281 from SkyCryptWebsite/fix-farming
Browse files Browse the repository at this point in the history
Fix the farming skill section
  • Loading branch information
Shiiyu authored Sep 28, 2024
2 parents fd9e274 + 63b2ef8 commit 5314570
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 26 deletions.
179 changes: 167 additions & 12 deletions src/constants/weight/farming-weight.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,111 @@
const CROP_TO_PEST = {
CACTUS: "Mite",
CARROT_ITEM: "Cricket",
"INK_SACK:3": "Moth",
MELON: "Earthworm",
MUSHROOM_COLLECTION: "Slug",
NETHER_STALK: "Beetle",
POTATO_ITEM: "Locust",
PUMPKIN: "Rat",
SUGAR_CANE: "Mosquito",
WHEAT: "Fly",
};

const PEST_COLLECTION_BRACKETS = [0, 50, 100, 250, 500, 750, 1000];

const PEST_COLLECTION_ADJUSTMENTS = {
Mite: {
0: 0,
50: 1285.333312988281,
100: 1898.6666259765625,
250: 2512,
500: 3125.333251953125,
750: 3493.333251953125,
1000: 3861.3333740234375,
},
Cricket: {
0: 0,
50: 1430.3999755859375,
100: 2086.399951171875,
250: 2742.4,
500: 3398.39990234375,
750: 3791.99990234375,
1000: 4185.600048828125,
},
Moth: {
0: 0,
50: 1430.3999755859375,
100: 2086.399951171875,
250: 2742.4,
500: 3398.39990234375,
750: 3791.99990234375,
1000: 4185.600048828125,
},
Earthworm: {
0: 0,
50: 2010.6666259765625,
100: 2837.333251953125,
250: 3664,
500: 4490.66650390625,
750: 4986.66650390625,
1000: 5482.666748046875,
},
Slug: {
0: 0,
50: 632.5333312988281,
100: 1053.8666625976562,
250: 1475.2,
500: 1896.5333251953125,
750: 2149.3333251953127,
1000: 2402.133337402344,
},
Beetle: {
0: 0,
50: 1647.9999694824216,
100: 2367.9999389648438,
250: 3088,
500: 3807.9998779296875,
750: 4239.9998779296875,
1000: 4672.000061035156,
},
Locust: {
0: 0,
50: 1647.9999694824216,
100: 2367.9999389648438,
250: 3088,
500: 3807.9998779296875,
750: 4239.9998779296875,
1000: 4672.000061035156,
},
Rat: {
0: 0,
50: 922.6666564941406,
100: 1429.333312988281,
250: 1936,
500: 2442.6666259765625,
750: 2746.6666259765625,
1000: 3050.6666870117188,
},
Mosquito: {
0: 0,
50: 1285.333312988281,
100: 1898.6666259765625,
250: 2512,
500: 3125.333251953125,
750: 3493.333251953125,
1000: 3861.3333740234375,
},
Fly: {
0: 0,
50: 7179.839925842285,
100: 11197.43985168457,
250: 15215.04,
500: 19232.63970336914,
750: 21643.19970336914,
1000: 24053.76014831543,
},
};

const crops = {
CACTUS: {
name: "Cactus",
Expand All @@ -15,6 +123,10 @@ const crops = {
name: "Melon",
weight: 485_308.47,
},
MUSHROOM_COLLECTION: {
name: "Mushroom",
weight: 90_178.06,
},
NETHER_STALK: {
name: "Nether Wart",
weight: 250_000,
Expand All @@ -36,6 +148,36 @@ const crops = {
weight: 100_000,
},
};
function calculatePestCrops(pest) {
let kills = pest?.kills ?? 0;
let pestCount = 0;
let pestCropCount = 0;
for (let i = 0; i < PEST_COLLECTION_BRACKETS.length; i++) {
const bracket = PEST_COLLECTION_BRACKETS[i];

if (kills <= 0) break;

const bracketCrops = PEST_COLLECTION_ADJUSTMENTS[pest.name][bracket];

if (i === PEST_COLLECTION_BRACKETS.length - 1) {
pestCropCount += Math.ceil(bracketCrops * kills);
break;
}

const nextBracket = PEST_COLLECTION_BRACKETS.at(i + 1);

pestCount = Math.min(nextBracket - pestCount, kills);

if (bracketCrops === 0) {
kills -= pestCount;
continue;
}

kills -= pestCount;
pestCropCount += Math.ceil(bracketCrops * pestCount);
}
return pestCropCount;
}

export function calculateFarmingWeight(userProfile) {
const output = {
Expand All @@ -50,12 +192,16 @@ export function calculateFarmingWeight(userProfile) {
};

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

const calculated = amount / crop.weight;
const pest = pests.find((a) => a.name === CROP_TO_PEST[name]);
const pestCrops = calculatePestCrops(pest);

const calculated = Math.max(amount - pestCrops, 0) / crop.weight;

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

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

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

const mushroomWeight =
doubleBreakRatio * (mushroomCollection / (2 * mushroomScaling)) +
normalRatio * (mushroomCollection / mushroomScaling);

output.crops.MUSHROOM = {
name: "Mushroom",
weight: mushroomWeight,
};
output.weight -= output.crops.MUSHROOM_COLLECTION.weight;
output.crops.MUSHROOM_COLLECTION.weight = mushroomWeight;
output.weight += mushroomWeight;
}

Expand Down Expand Up @@ -113,14 +257,25 @@ export function calculateFarmingWeight(userProfile) {

bonus += doubleDrops * 2;

const goldMedals = userProfile.farming?.total_badges?.gold ?? 0;
const goldMedalBonus = Math.min(Math.floor(goldMedals / 50) * 25, 500);
output.bonuses.gold_medals = {
medals: goldMedals,
weight: goldMedalBonus,
const maxMedals = 1000;
const medals = userProfile.farming?.total_badges;
const diamondMedals = medals?.diamond ?? 0;
const platinumMedals = Math.min(medals?.platinum ?? 0, maxMedals - diamondMedals);
const goldMedals = Math.min(medals?.gold ?? 0, maxMedals - diamondMedals - platinumMedals);

const diamondMedalBonus = diamondMedals * 0.75;
const platinumMedalBonus = platinumMedals * 0.5;
const goldMedalBonus = goldMedals * 0.25;

const contestMedals = goldMedals + platinumMedals + diamondMedals;
const contestMedalBonus = goldMedalBonus + platinumMedalBonus + diamondMedalBonus;

output.bonuses.contest_medals = {
medals: contestMedals,
weight: contestMedalBonus,
};

bonus += goldMedalBonus;
bonus += contestMedalBonus;
}

if (userProfile.minions !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export async function getStats(
bingo: { fn: stats.getBingoData, args: { bingoProfile } },
user_data: { fn: stats.getUserData, args: { userProfile } },
currencies: { fn: stats.getCurrenciesData, args: { userProfile, profile } },
weight: { fn: stats.getWeight, args: { output }, promise: true },
weight: { fn: stats.getWeight, args: { output }, promise: true, awaitPromises: true },
accessories: { fn: stats.getMissingAccessories, args: { output, packs }, promise: true, awaitPromises: true },
temp_stats: { fn: stats.getTempStats, args: { userProfile } },
rift: { fn: stats.getRift, args: { userProfile } },
Expand Down
26 changes: 13 additions & 13 deletions src/stats/farming.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function getFarming(userProfile) {
crop: crop,
collected: data.collected,
claimed: data.claimed_rewards || false,
medal: null,
medal: data.claimed_medal || null,
};

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

// Use the claimed medal if it exists and is valid
if (contest.claimed_medal) {
contest.medal = contest.claimed_medal;
} else if (placing.position <= Math.floor(participants * 0.02)) {
contest.medal = "diamond";
} else if (placing.position <= Math.floor(participants * 0.05)) {
contest.medal = "platinum";
} else if (placing.position <= Math.floor(participants * 0.1)) {
contest.medal = "gold";
} else if (placing.position <= Math.floor(participants * 0.3)) {
contest.medal = "silver";
} else if (placing.position <= Math.floor(participants * 0.6)) {
contest.medal = "bronze";
if (!contest.medal) {
if (placing.position <= Math.floor(participants * 0.02)) {
contest.medal = "diamond";
} else if (placing.position <= Math.floor(participants * 0.05)) {
contest.medal = "platinum";
} else if (placing.position <= Math.floor(participants * 0.1)) {
contest.medal = "gold";
} else if (placing.position <= Math.floor(participants * 0.3)) {
contest.medal = "silver";
} else if (placing.position <= Math.floor(participants * 0.6)) {
contest.medal = "bronze";
}
}

// Count the medal if it exists
Expand Down
1 change: 1 addition & 0 deletions views/stats.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ const metaDescription = getMetaDescription()
<%- include('./sections/stats/minions.ejs', { skillItems }); %>
<% } %>
<!-- Bestiary-->
<% if (calculated.bestiary !== undefined) {%>
<%- include('./sections/stats/bestiary.ejs', {}); %>
<% } %>
Expand Down

0 comments on commit 5314570

Please sign in to comment.