diff --git a/src/app/(stats)/player/[ign]/_stats/blitz/blitz.tsx b/src/app/(stats)/player/[ign]/_stats/blitz/blitz.tsx new file mode 100644 index 0000000..5e9b317 --- /dev/null +++ b/src/app/(stats)/player/[ign]/_stats/blitz/blitz.tsx @@ -0,0 +1,46 @@ +import { Separator } from "@/components/ui/separator" +import { formatNumber } from "@/lib/formatters" +import { getBlitzMostPlayedKit } from "@/lib/hypixel/blitz/general" +import { devide } from "@/lib/hypixel/general" +import { NonNullStats } from "@/lib/schema/player" +import { cn } from "@/lib/utils" +import GeneralStats from "../GeneralStats" + +export default function BlitzStats({ stats }: { stats: NonNullStats["Blitz"] }) { + if (!stats) return null + + const kd = formatNumber(devide(stats.kills, stats.deaths)) + const wins = stats.wins_solo_normal + stats.wins_team_normal + const mostPlayedKit = getBlitzMostPlayedKit(stats) + + return ( + Main

, + stat: ( +

+ {mostPlayedKit !== null ? mostPlayedKit.name : "Unknown"} +

+ ) + }, + { + title:

Kills

, + stat:

{formatNumber(stats.kills)}

+ }, + { + title:

KD

, + stat:

{kd}

+ }, + { + title:

Wins

, + stat:

{wins}

+ } + ]} + > + +
+ ) +} diff --git a/src/app/(stats)/player/[ign]/page.tsx b/src/app/(stats)/player/[ign]/page.tsx index 15e7f2d..0498823 100644 --- a/src/app/(stats)/player/[ign]/page.tsx +++ b/src/app/(stats)/player/[ign]/page.tsx @@ -12,6 +12,7 @@ import { Suspense } from "react" import { PlayerPageLoadText } from "./_client" import Sidebar from "./_components/Sidebar" import BedwarsStats from "./_stats/bedwars/bedwars" +import BlitzStats from "./_stats/blitz/blitz" import BuildBattleStats from "./_stats/build-battle/build-battle" import CopsAndCrimsStats from "./_stats/copsandcrims/copsandcrims" import DuelsStats from "./_stats/duels/duels" @@ -127,6 +128,7 @@ async function SuspendedPage({ params }: Pick, "param + ) : diff --git a/src/data/hypixel/blitz.ts b/src/data/hypixel/blitz.ts new file mode 100644 index 0000000..b3f8cd4 --- /dev/null +++ b/src/data/hypixel/blitz.ts @@ -0,0 +1,46 @@ +export const KITS = [ + { id: "arachnologist", name: "Arachnologist" }, + { id: "archer", name: "Archer" }, + { id: "armorer", name: "Armorer" }, + { id: "astronaut", name: "Astronaut" }, + { id: "baker", name: "Baker" }, + { id: "blaze", name: "Blaze" }, + { id: "creepertamer", name: "Creepertamer" }, + { id: "diver", name: "Diver" }, + { id: "donkeytamer", name: "Donkeytamer" }, + { id: "farmer", name: "Farmer" }, + { id: "florist", name: "Florist" }, + { id: "golem", name: "Golem" }, + { id: "guardian", name: "Guardian" }, + { id: "horsetamer", name: "Horsetamer" }, + { id: "hunter", name: "Hunter" }, + { id: "hype train", name: "Hype Train" }, + { id: "jockey", name: "Jockey" }, + { id: "knight", name: "Knight" }, + { id: "meatmaster", name: "Meatmaster" }, + { id: "necromancer", name: "Necromancer" }, + { id: "paladin", name: "Paladin" }, + { id: "phoenix", name: "Phoenix" }, + { id: "pigman", name: "Pigman" }, + { id: "ranger", name: "Ranger" }, + { id: "reaper", name: "Reaper" }, + { id: "reddragon", name: "Red Dragon" }, + { id: "rogue", name: "Rogue" }, + { id: "scout", name: "Scout" }, + { id: "shadow knight", name: "Shadow Knight" }, + { id: "slimeyslime", name: "Slimey Slime" }, + { id: "snowman", name: "Snowman" }, + { id: "speleologist", name: "Speleologist" }, + { id: "tim", name: "Tim" }, + { id: "toxicologist", name: "Toxicologist" }, + { id: "troll", name: "Troll" }, + { id: "viking", name: "Viking" }, + { id: "warlock", name: "Warlock" }, + { id: "warrior", name: "Warrior" }, + { id: "wolftamer", name: "Wolftamer" } +] as const +export const MODES = [ + { id: "solo_normal", name: "Solo Normal" }, + { id: "teams_normal", name: "Teams Normal" } +] as const +export const KITEXP = [0, 100, 250, 500, 1000, 1500, 2000, 2500, 5000, 10000] as const diff --git a/src/lib/hypixel/blitz/general.ts b/src/lib/hypixel/blitz/general.ts new file mode 100644 index 0000000..780343a --- /dev/null +++ b/src/lib/hypixel/blitz/general.ts @@ -0,0 +1,17 @@ +import { KITS } from "@/data/hypixel/blitz" +import { NonNullStats } from "@/lib/schema/player" + +export function getBlitzMostPlayedKit(stats: NonNullable) { + let mostPlayedKit: typeof KITS[number] | null = null + let maxTimePlayed = 0 + + for (const kit of KITS) { + const timePlayed = stats[`time_played_${kit.id}`] + if (timePlayed > maxTimePlayed) { + maxTimePlayed = timePlayed + mostPlayedKit = kit + } + } + + return mostPlayedKit +} diff --git a/src/lib/schema/player.ts b/src/lib/schema/player.ts index ddb51cf..8c93088 100644 --- a/src/lib/schema/player.ts +++ b/src/lib/schema/player.ts @@ -1,6 +1,7 @@ import z from "zod" import { bedwarsStatsSchema, + blitzStatsSchema, buildBattleStatsSchema, copsAndCrimsStatsSchema, duelsStatsSchema, @@ -36,11 +37,13 @@ export const playerSchema = z.looseObject({ TNTGames: tntGamesStatsSchema.optional(), Walls3: megawallsStats.optional(), MCGO: copsAndCrimsStatsSchema.optional(), - WoolGames: woolGamesStatsSchema.optional() - }).transform(({ Walls3, MCGO, ...rest }) => { + WoolGames: woolGamesStatsSchema.optional(), + HungerGames: blitzStatsSchema.optional() + }).transform(({ Walls3, MCGO, HungerGames, ...rest }) => { return { MegaWalls: Walls3, CopsAndCrims: MCGO, + Blitz: HungerGames, ...rest } }).optional(), diff --git a/src/lib/schema/stats.ts b/src/lib/schema/stats.ts index da2ab13..b043bde 100644 --- a/src/lib/schema/stats.ts +++ b/src/lib/schema/stats.ts @@ -789,3 +789,69 @@ export const woolGamesStatsSchema = z.object({ }).optional() }).optional() }) + +function blitzKitPlayedStats() { + const ids = [ + "arachnologist", + "archer", + "armorer", + "astronaut", + "baker", + "blaze", + "creepertamer", + "diver", + "donkeytamer", + "farmer", + "florist", + "golem", + "guardian", + "horsetamer", + "hunter", + "hype train", + "jockey", + "knight", + "meatmaster", + "necromancer", + "paladin", + "phoenix", + "pigman", + "ranger", + "reaper", + "reddragon", + "rogue", + "scout", + "shadow knight", + "slimeyslime", + "snowman", + "speleologist", + "tim", + "toxicologist", + "troll", + "viking", + "warlock", + "warrior", + "wolftamer" + ] as const + + const stats = [ + "time_played" + ] as const + + const entries = new Map>() + + for (const id of ids) { + for (const stat of stats) { + entries.set(`${stat}_${id}`, z.number().default(0)) + } + } + + return Object.fromEntries(entries) as Record<`${typeof stats[number]}_${typeof ids[number]}`, z.ZodDefault> +} + +export const blitzStatsSchema = z.object({ + kills: z.number().default(0), + deaths: z.number().default(0), + wins_solo_normal: z.number().default(0), + wins_team_normal: z.number().default(0), + ...blitzKitPlayedStats() +})