From d6671a67458f8cdf7869595309b7e29705e6d05a Mon Sep 17 00:00:00 2001 From: DuckySoLucky Date: Sun, 14 Jul 2024 12:18:51 +0200 Subject: [PATCH] refactor(stats/dungeons): add Blood Mob Kills, SPR & move stats in dungeosn floor --- src/lib/constants/NotEnoughUpdates-REPO | 2 +- src/lib/stats/bestiary.ts | 20 ++++++++- src/lib/stats/dungeons.ts | 54 +++++++++++++++-------- src/types/processed/profile/dungeons.d.ts | 40 ++++++++++------- 4 files changed, 80 insertions(+), 36 deletions(-) diff --git a/src/lib/constants/NotEnoughUpdates-REPO b/src/lib/constants/NotEnoughUpdates-REPO index 7e67c37c..9ab22630 160000 --- a/src/lib/constants/NotEnoughUpdates-REPO +++ b/src/lib/constants/NotEnoughUpdates-REPO @@ -1 +1 @@ -Subproject commit 7e67c37ce92cf8a7be4cf09ce594fda148dbffc9 +Subproject commit 9ab226302fe724f91ad60eeafe915f47f5e60264 diff --git a/src/lib/stats/bestiary.ts b/src/lib/stats/bestiary.ts index a53e4143..e8189d4e 100644 --- a/src/lib/stats/bestiary.ts +++ b/src/lib/stats/bestiary.ts @@ -1,5 +1,5 @@ -import type { Member } from "$types/global"; import * as constants from "$constants/constants"; +import type { Member } from "$types/global"; import type { BestiaryStats } from "$types/processed/profile/bestiary"; function getBestiaryMobs( @@ -35,6 +35,24 @@ function getBestiaryMobs( return output; } +export function getBestiaryFamily(userProfile: Member, mobName: string) { + const bestiary = userProfile.bestiary.kills || {}; + const family = Object.values(constants.BESTIARY) + .flatMap((category) => category.mobs) + .find((mob) => mob.name === mobName); + + if (family === undefined) { + return null; + } + + const output = getBestiaryMobs(bestiary, [family]); + if (!output.length) { + return null; + } + + return output[0]; +} + export function getBestiary(userProfile: Member) { const bestiary = userProfile.bestiary.kills || {}; diff --git a/src/lib/stats/dungeons.ts b/src/lib/stats/dungeons.ts index 420ad46f..a0d4c5c7 100644 --- a/src/lib/stats/dungeons.ts +++ b/src/lib/stats/dungeons.ts @@ -1,6 +1,7 @@ import * as constants from "$constants/constants"; import * as helper from "$lib/helper"; import type { BestRun, Catacombs, Member, Skill } from "$types/global"; +import { getBestiaryFamily } from "./bestiary"; import { getLevelByXp } from "./leveling/leveling"; function getDungeonClasses(userProfile: Member) { @@ -85,6 +86,22 @@ function getBestRun(catacombs: Catacombs, floorId: number) { }; } +function getSecrets(catacombs: Member["dungeons"]) { + const secretsFound = catacombs.secrets ?? 0; + const totalRuns = + Object.keys(catacombs?.dungeon_types?.catacombs?.tier_completions || {}) + .filter((key) => key !== "total") + .reduce((a, b) => a + (catacombs?.dungeon_types?.catacombs?.tier_completions[b] || 0), 0) + + Object.keys(catacombs?.dungeon_types?.master_catacombs?.tier_completions || {}) + .filter((key) => key !== "total") + .reduce((a, b) => a + (catacombs?.dungeon_types?.master_catacombs?.tier_completions[b] || 0), 0); + + return { + found: secretsFound, + secretsPerRun: secretsFound / totalRuns + }; +} + function formatCatacombsData(catacombs: Catacombs) { const type = catacombs.experience ? "catacombs" : "master_catacombs"; @@ -94,22 +111,20 @@ function formatCatacombsData(catacombs: Catacombs) { output.push({ name: floor.name, texture: floor.texture, - - times_played: catacombs.times_played?.[floor.id] ?? 0, - tier_completions: catacombs.tier_completions?.[floor.id] ?? 0, - milestone_completions: catacombs.milestone_completions?.[floor.id] ?? 0, - best_score: catacombs.best_score?.[floor.id] ?? 0, - - mobs_killed: catacombs.mobs_killed?.[floor.id] ?? 0, - watcher_kills: catacombs.watcher_kills?.[floor.id] ?? 0, - most_mobs_killed: catacombs.most_mobs_killed?.[floor.id] ?? 0, - - fastest_time: catacombs.fastest_time?.[floor.id] ?? 0, - fastest_time_s: catacombs.fastest_time?.[floor.id] ?? 0, - fastest_time_s_plus: catacombs.fastest_time_s_plus?.[floor.id] ?? 0, - - most_healing: catacombs.most_healing?.[floor.id] ?? 0, - most_damage: getMostDamage(catacombs, floor.id), + stats: { + times_played: catacombs.times_played?.[floor.id] ?? 0, + tier_completions: catacombs.tier_completions?.[floor.id] ?? 0, + milestone_completions: catacombs.milestone_completions?.[floor.id] ?? 0, + best_score: catacombs.best_score?.[floor.id] ?? 0, + mobs_killed: catacombs.mobs_killed?.[floor.id] ?? 0, + watcher_kills: catacombs.watcher_kills?.[floor.id] ?? 0, + most_mobs_killed: catacombs.most_mobs_killed?.[floor.id] ?? 0, + fastest_time: catacombs.fastest_time?.[floor.id] ?? 0, + fastest_time_s: catacombs.fastest_time?.[floor.id] ?? 0, + fastest_time_s_plus: catacombs.fastest_time_s_plus?.[floor.id] ?? 0, + most_healing: catacombs.most_healing?.[floor.id] ?? 0, + most_damage: getMostDamage(catacombs, floor.id), + }, best_run: getBestRun(catacombs, floor.id) }); } @@ -133,8 +148,11 @@ export function getDungeons(userProfile: Member) { classAverageWithProgress: Object.values(dungeonClasses).reduce((a, b) => a + b.levelWithProgress, 0) / Object.keys(dungeonClasses).length, totalClassExp: Object.values(userProfile.dungeons.player_classes).reduce((a, b) => a + b.experience, 0) }, - secrets: { - found: userProfile.dungeons.secrets + stats: { + secrets: getSecrets(userProfile.dungeons), + highestFloorBeatenNormal: userProfile.dungeons.dungeon_types.catacombs.highest_tier_completed ?? 0, + highestFloorBeatenMaster: userProfile.dungeons.dungeon_types.master_catacombs.highest_tier_completed ?? 0, + bloodMobKills: getBestiaryFamily(userProfile, "Undead")?.kills ?? 0 }, catacombs: formatCatacombsData(userProfile.dungeons.dungeon_types.catacombs), master_catacombs: formatCatacombsData(userProfile.dungeons.dungeon_types.master_catacombs) diff --git a/src/types/processed/profile/dungeons.d.ts b/src/types/processed/profile/dungeons.d.ts index 82b51260..dc71ef88 100644 --- a/src/types/processed/profile/dungeons.d.ts +++ b/src/types/processed/profile/dungeons.d.ts @@ -9,8 +9,14 @@ export type DungeonsStats = { classAverageWithProgress: number; totalClassExp: number; }; - secrets: { - found: number; + stats: { + secrets: { + found: number; + secretsPerRun: number; + }; + highestFloorBeatenNormal: number; + highestFloorBeatenMaster: number; + bloodMobKills: number; }; catacombs: CatacombsData[]; master_catacombs: CatacombsData[]; @@ -19,20 +25,22 @@ export type DungeonsStats = { export type CatacombsData = { name: string; texture: string; - times_played: number; - tier_completions: number; - milestone_completions: number; - best_score: number; - mobs_killed: number; - watcher_kills: number; - most_mobs_killed: number; - fastest_time: number; - fastest_time_s: number; - fastest_time_s_plus: number; - most_healing: number; - most_damage: { - damage: number; - type: string; + stats: { + times_played: number; + tier_completions: number; + milestone_completions: number; + best_score: number; + mobs_killed: number; + watcher_kills: number; + most_mobs_killed: number; + fastest_time: number; + fastest_time_s: number; + fastest_time_s_plus: number; + most_healing: number; + most_damage: { + damage: number; + type: string; + }; }; best_run: { grade: string;