From 7e9251891b6e994dd900b100dd5642c12c3a94a8 Mon Sep 17 00:00:00 2001 From: Taken Date: Mon, 8 Sep 2025 00:10:08 +0200 Subject: [PATCH] Updated mw stats --- .../player/[ign]/_stats/megawalls/table.tsx | 30 +++++++++++++++++-- src/lib/hypixel/megawalls/general.ts | 30 +++++++++++++++++++ src/lib/schema/stats.ts | 24 +++++++++++++-- 3 files changed, 79 insertions(+), 5 deletions(-) diff --git a/src/app/(stats)/player/[ign]/_stats/megawalls/table.tsx b/src/app/(stats)/player/[ign]/_stats/megawalls/table.tsx index 6326c61..71a50d3 100644 --- a/src/app/(stats)/player/[ign]/_stats/megawalls/table.tsx +++ b/src/app/(stats)/player/[ign]/_stats/megawalls/table.tsx @@ -1,6 +1,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { formatNumber } from "@/lib/formatters" -import { getMegaWallsModeName, getMegaWallsModeStats } from "@/lib/hypixel/megawalls/general" +import { romanize } from "@/lib/hypixel/general" +import { getAllClassStats, getDifficultyColor, getMegaWallsClass, getMegaWallsModeName, getMegaWallsModeStats } from "@/lib/hypixel/megawalls/general" import { NonNullStats } from "@/lib/schema/player" export function MegaWallsModesTable({ stats }: { stats: NonNullable }) { @@ -20,8 +21,7 @@ export function MegaWallsClassesTable({ stats }: { stats: NonNullable - - + ) } @@ -76,6 +76,30 @@ function MegaWallsTableHeader() { ) } +function MegaWallsClassStats({ stats }: { stats: NonNullable }) { + const classStats = getAllClassStats(stats) + return ( + + {classStats.map((c, i) => { + const { id, val } = c + const klass = getMegaWallsClass(id) + const difColor = getDifficultyColor(klass.difficulty) + return ( + + {klass.name} + {val.map((v, j) => { + if (j === val.length - 2) { + return {v === 0 ? "-" : romanize(v)} + } + return {formatNumber(v)} + })} + + ) + })} + + ) +} + function MegaWallsModeStat( { modeId, stats }: { modeId: Parameters[0], stats: NonNullable } ) { diff --git a/src/lib/hypixel/megawalls/general.ts b/src/lib/hypixel/megawalls/general.ts index 314eb35..31af36a 100644 --- a/src/lib/hypixel/megawalls/general.ts +++ b/src/lib/hypixel/megawalls/general.ts @@ -28,6 +28,36 @@ export function getMegaWallsModeName(modeId: typeof MODES[number]["id"]) { return MODES.find(m => m.id === modeId)!.name } +export function getMegaWallsClass(classId: typeof CLASSES[number]["id"]) { + return CLASSES.find(c => c.id === classId)! +} + +export function getAllClassStats(stats: NonNullable) { + const statsArr: { id: typeof CLASSES[number]["id"], val: number[] }[] = [] + + for (const klass of CLASSES) { + statsArr.push({ id: klass.id, val: megaWalsClassStats(klass.id, stats) }) + } + + return statsArr +} + +export function megaWalsClassStats(classId: typeof CLASSES[number]["id"], stats: NonNullable) { + return [ + stats[`${classId}_kills`], + stats[`${classId}_deaths`], + devide(stats[`${classId}_kills`], stats[`${classId}_deaths`]), + stats[`${classId}_final_kills`], + stats[`${classId}_final_deaths`], + devide(stats[`${classId}_final_kills`], stats[`${classId}_final_deaths`]), + stats[`${classId}_wins`], + stats[`${classId}_losses`], + devide(stats[`${classId}_wins`], stats[`${classId}_deaths`]), + stats.classes === undefined ? 0 : stats.classes[classId].prestige, + stats.classes === undefined ? 0 : stats.classes[classId].enderchest_rows + ] +} + export function getMegaWallsModeStats(modeId: typeof MODES[number]["id"], stats: NonNullable) { return [ stats[`kills_${modeId}`], diff --git a/src/lib/schema/stats.ts b/src/lib/schema/stats.ts index 0702d70..86ae624 100644 --- a/src/lib/schema/stats.ts +++ b/src/lib/schema/stats.ts @@ -586,19 +586,38 @@ function megawallsClassStats() { ] as const const stats = [ + "kills", + "deaths", + "final_kills", + "final_deaths", "wins", "losses" ] as const + const classesOther = [ + "prestige", + "enderchest_rows" + ] as const + const entries = new Map>() + const classes = new Map, enderchest_rows: z.ZodDefault }, z.core.$loose>>() for (const id of ids) { for (const stat of stats) { entries.set(`${id}_${stat}`, z.number().default(0)) } + for (const klass of classesOther) { + classes.set(id, z.looseObject({ prestige: z.number().default(0), enderchest_rows: z.number().default(0) })) + } } - return Object.fromEntries(entries) as Record<`${typeof ids[number]}_${typeof stats[number]}`, z.ZodDefault> + return { + classStats: Object.fromEntries(entries) as Record<`${typeof ids[number]}_${typeof stats[number]}`, z.ZodDefault>, + classOther: Object.fromEntries(classes) as Record< + `${typeof ids[number]}`, + z.ZodObject<{ prestige: z.ZodDefault, enderchest_rows: z.ZodDefault }, z.core.$loose> + > + } } function megawallsModeStats() { @@ -640,6 +659,7 @@ export const megawallsStats = z.looseObject({ coins: z.number().default(0), wither_damage: z.number().default(0), witherDamage: z.number().default(0), - ...megawallsClassStats(), + classes: z.looseObject(megawallsClassStats().classOther).optional(), + ...megawallsClassStats().classStats, ...megawallsModeStats() })