Added first stat on bedwars

This commit is contained in:
2025-08-17 19:42:58 +02:00
parent c79d06f272
commit e3a4a65e2d
12 changed files with 531 additions and 27 deletions

View File

@@ -0,0 +1,55 @@
/*
* Functions for BedWars exp and level conversions.
*/
const EASY_LEVELS = 4
const EASY_LEVELS_XP = 7000
const XP_PER_PRESTIGE = 96 * 5000 + EASY_LEVELS_XP
const LEVELS_PER_PRESTIGE = 100
const HIGHEST_PRESTIGE = 10
export function getBWLevel(level: number) {
if (level > HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE) {
return level - HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE
}
return level % LEVELS_PER_PRESTIGE
}
export function getBWExpForLevel(level: number) {
if (level === 0) return 0
const respectedLevel = getBWLevel(level)
if (respectedLevel > EASY_LEVELS) {
return 5000
}
switch (respectedLevel) {
case 1:
return 500
case 2:
return 1000
case 3:
return 2000
case 4:
return 3500
default:
return 5000
}
}
export function getBWLevelForExp(exp: number) {
const prestiges = Math.floor(exp / XP_PER_PRESTIGE)
let level = prestiges * LEVELS_PER_PRESTIGE
let expWithoutPrestiges = exp - (prestiges * XP_PER_PRESTIGE)
let expForEasyLevel
for (let i = 1; i <= EASY_LEVELS; i += 1) {
expForEasyLevel = getBWExpForLevel(i)
if (expWithoutPrestiges < expForEasyLevel) {
break
}
level += 1
expWithoutPrestiges -= expForEasyLevel
}
return level + Math.floor(expWithoutPrestiges / 5000)
}

View File

@@ -3,28 +3,28 @@ import { Player } from "@/lib/schema/player"
export function getCoinMultiplier(level: number) {
if (level > MULTIPLIER[MULTIPLIER.length - 1].level) {
return MULTIPLIER[MULTIPLIER.length - 1].value;
return MULTIPLIER[MULTIPLIER.length - 1].value
}
for (let i = MULTIPLIER.length - 1; i >= 0; i--) {
if (level >= MULTIPLIER[i].level) {
return MULTIPLIER[i].value;
return MULTIPLIER[i].value
}
}
return MULTIPLIER[0].value
}
export function getTotalCoins(stats: Player["player"]["stats"]) {
return Object.values(stats).reduce((total, stat) => total + (stat.coins || 0), 0);
export function getTotalCoins(stats: Record<string, Record<"coins", number | undefined>>) {
return Object.values(stats).reduce((total, stat) => total + (stat.coins || 0), 0)
}
export function getTotalQuests(quests: Player["player"]["quests"]) {
return Object.values(quests).reduce((total, quest) => total + (quest.completions?.length || 0), 0);
return Object.values(quests).reduce((total, quest) => total + (quest.completions?.length || 0), 0)
}
export function getTotalChallenges(challenges: Player["player"]["challenges"]["all_time"]) {
return Object.values(challenges).reduce((total, challenge) => total + challenge, 0);
return Object.values(challenges).reduce((total, challenge) => total + challenge, 0)
}
export function rewardClaimed(claimedAt?: number) {
@@ -38,4 +38,5 @@ export function rewardClaimed(claimedAt?: number) {
} else {
return false
}
}
}

View File

@@ -0,0 +1,23 @@
import { getColorFromCode } from "@/data/colors"
import { PRESTIGES } from "@/data/hypixel/bedwars"
import { floorLevel } from "./hypixel/formatters"
export function bedwarsLevelColors(level: number) {
if (level < 0) return getColorFromCode()
const floored = floorLevel(level, 100)
if (floored < 1000) {
return getColorFromCode(PRESTIGES.find(v => v.level === floored)!.colormap)
}
if (floored > 5000) {
return PRESTIGES[PRESTIGES.length - 1].colormap.split("").map(v => {
return getColorFromCode(v)
})
}
return PRESTIGES.find(v => v.level === floored)!.colormap.split("").map(v => {
return getColorFromCode(v)
})
}

View File

@@ -1,7 +1,7 @@
import z from "zod"
export const playerSchema = z.object({
player: z.object({
export const playerSchema = z.looseObject({
player: z.looseObject({
displayname: z.string(),
uuid: z.string(),
newPackageRank: z.literal("VIP").or(z.literal("VIP_PLUS").or(z.literal("MVP")).or(z.literal("MVP_PLUS"))).optional(),
@@ -11,37 +11,36 @@ export const playerSchema = z.object({
networkExp: z.number(),
karma: z.number(),
achievementPoints: z.number().optional(),
stats: z.record(
z.string(),
z.object({
coins: z.number().optional()
})
),
stats: z.looseObject({
Bedwars: z.looseObject({
Experience: z.number()
}).optional()
}),
quests: z.record(
z.string(),
z.object({
z.looseObject({
completions: z.array(
z.object({
z.looseObject({
time: z.number()
}).optional()
).optional()
})
),
challenges: z.object({
challenges: z.looseObject({
all_time: z.record(z.string(), z.number())
}),
lastClaimedReward: z.number().optional(),
rewardHighScore: z.number().optional(),
rewardStreak: z.number().optional(),
totalRewards: z.number().optional(),
giftingMeta: z.object({
giftingMeta: z.looseObject({
giftsGiven: z.number().optional(),
ranksGiven: z.number().optional()
}).optional(),
firstLogin: z.number().optional(),
lastLogin: z.number().optional(),
socialMedia: z.object({
links: z.object({
socialMedia: z.looseObject({
links: z.looseObject({
DISCORD: z.string().optional(),
TWITCH: z.string().optional(),
HYPIXEL: z.string().optional(),
@@ -53,4 +52,3 @@ export const playerSchema = z.object({
})
export type Player = z.infer<typeof playerSchema>