From 365a7a44e5782083b24e9cebcff188bb13bcf488 Mon Sep 17 00:00:00 2001 From: DuckySoLucky Date: Wed, 17 Jan 2024 23:07:08 +0100 Subject: [PATCH] fix: unqiue accessories count & dupes --- src/lib.js | 2 +- src/stats/missing.js | 28 +++++++++++++++------- views/sections/stats/items/accessories.ejs | 21 +++++++++------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/lib.js b/src/lib.js index 67e797f188..f0c26bad10 100644 --- a/src/lib.js +++ b/src/lib.js @@ -214,7 +214,7 @@ export async function getStats( user_data: { fn: stats.getUserData, args: { userProfile } }, currencies: { fn: stats.getCurrenciesData, args: { userProfile, profile } }, weight: { fn: stats.getWeight, args: { output }, promise: true }, - accessories: { fn: stats.getMissingAccessories, args: { output, items, packs } }, + accessories: { fn: stats.getMissingAccessories, args: { output, items, packs }, promise: true }, temp_stats: { fn: stats.getTempStats, args: { userProfile } }, rift: { fn: stats.getRift, args: { userProfile } }, networth: { fn: getPreDecodedNetworth, args: { userProfile, networthItems, bank, networthOptions }, promise: true }, diff --git a/src/stats/missing.js b/src/stats/missing.js index 38f128b64f..3eef7fe0b1 100644 --- a/src/stats/missing.js +++ b/src/stats/missing.js @@ -141,28 +141,40 @@ export async function getMissingAccessories(calculated, items, packs) { } const accessories = items.accessories.accessories; + const activeAccessories = accessories.filter((a) => a.isInactive === false); output.unique = accessories.filter((a) => a.isUnique === true).length; output.total = constants.UNIQUE_ACCESSORIES_COUNT; - output.recombobulated = accessories.filter((a) => a?.extra?.recombobulated === true).length; + output.recombobulated = activeAccessories.filter((a) => a?.extra?.recombobulated === true).length; output.total_recombobulated = constants.RECOMBABLE_ACCESSORIES_COUNT; - const activeAccessories = accessories.filter((a) => a.isUnique === true && a.isInactive === false); + const hegemonyArtifact = accessoryIds.find((a) => a.id === "HEGEMONY_ARTIFACT"); + const abiphoneContacts = calculated.crimson_isle?.abiphone?.active; + const riftPrism = accessoryIds.find((a) => a.id === "RIFT_PRISM"); + if (riftPrism) { + output.unique += 1; + } output.magical_power = { accessories: activeAccessories.reduce((a, b) => a + helper.getMagicalPower(b.rarity, helper.getId(b)), 0), - abiphone: calculated.crimson_isle?.abiphone?.active ? Math.floor(calculated.crimson_isle.abiphone.active / 2) : 0, - rift_prism: accessoryIds.find((a) => a.id === "RIFT_PRISM") ? 11 : 0, + abiphone: abiphoneContacts ? Math.floor(abiphoneContacts / 2) : 0, + rift_prism: riftPrism ? 11 : 0, + hegemony: hegemonyArtifact ? helper.getMagicalPower(hegemonyArtifact.rarity, hegemonyArtifact.id) : 0, }; - output.magical_power.total = Object.values(output.magical_power).reduce((a, b) => a + b, 0); + output.magical_power.total = Object.keys(output.magical_power) + .filter((a) => a !== "hegemony") + .reduce((a, b) => a + output.magical_power[b], 0); output.magical_power.rarities = {}; for (const rarity in constants.MAGICAL_POWER) { - output.magical_power.rarities[rarity] = activeAccessories - .filter((a) => a.rarity === rarity) - .reduce((a, b) => a + helper.getMagicalPower(rarity, helper.getId(b)), 0); + const accessories = activeAccessories.filter((a) => a.rarity === rarity); + + output.magical_power.rarities[rarity] = { + amount: accessories.length, + magical_power: accessories.reduce((a, b) => a + helper.getMagicalPower(rarity, helper.getId(b)), 0), + }; } return output; diff --git a/views/sections/stats/items/accessories.ejs b/views/sections/stats/items/accessories.ejs index 449371710a..367b1780a4 100644 --- a/views/sections/stats/items/accessories.ejs +++ b/views/sections/stats/items/accessories.ejs @@ -98,14 +98,14 @@ function itemIcon(item, classes) { %> );' class='grey-text'>Abicase = +<%= calculated.accessories.magical_power.abiphone %> MP
@@ -114,6 +114,11 @@ function itemIcon(item, classes) { %> <% if (calculated.accessories.magical_power.rift_prism) { %> Rift Prism: = +<%= calculated.accessories.magical_power.rift_prism %> MP
<% } %> + + <% const hegemonyArtifact = items.accessories.accessory_ids.find((a) => a.id === "HEGEMONY_ARTIFACT"); %> + <% if (calculated.accessories.magical_power.hegemony) { %> + Hegemony Artifact: = +<%= calculated.accessories.magical_power.hegemony %> MP
+ <% } %>
Total: <%= calculated.accessories.magical_power.total.toLocaleString() %> Magical Power ">