import { CLASSES, DIFFICULTIES, MODES } from "@/data/hypixel/megawalls" import { NonNullStats } from "@/lib/schema/player" import { devide } from "../general" export function getMegawallsMostPlayed(stats: NonNullable) { let mostPlayedClass: typeof CLASSES[number] | null = null let maxPlays = 0 for (const classObj of CLASSES) { const wins = stats[`${classObj.id}_wins`] || 0 const losses = stats[`${classObj.id}_losses`] || 0 const totalPlays = wins + losses if (totalPlays > maxPlays) { maxPlays = totalPlays mostPlayedClass = classObj } } return mostPlayedClass } export function getMegaWallsDifficultyColor(val: 1 | 2 | 3 | 4) { return DIFFICULTIES[val] } 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 getMegaWallsMostPlayedClass(stats: NonNullable) { let mostPlayedClass: typeof CLASSES[number] | null = null let maxPlays = 0 for (const classObj of CLASSES) { const wins = stats[`${classObj.id}_wins`] || 0 const losses = stats[`${classObj.id}_losses`] || 0 const totalPlays = wins + losses if (totalPlays > maxPlays) { maxPlays = totalPlays mostPlayedClass = classObj } } return mostPlayedClass } export function getMegawallsAllClassStats(stats: NonNullable) { const statsArr: { id: typeof CLASSES[number]["id"], val: number[] }[] = [] for (const klass of CLASSES) { statsArr.push({ id: klass.id, val: getMegaWallsClassStats(klass.id, stats) }) } return statsArr } export function getMegaWallsClassStats(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?.[classId]?.prestige || 0, stats.classes?.[classId]?.enderchest_rows || 0 ] } export function getMegaWallsMostPlayedMode(stats: NonNullable) { const modes = [ { id: "standard" as const, games: (stats.wins_standard || 0) + (stats.losses_standard || 0) }, { id: "face_off" as const, games: (stats.wins_face_off || 0) + (stats.losses_face_off || 0) }, { id: "gvg" as const, games: (stats.wins_gvg || 0) + (stats.losses_gvg || 0) } ] if (modes.map(m => m.games).reduce((a, b) => a + b) === 0) return null const mostPlayed = modes.reduce((max, current) => current.games > max.games ? current : max) return mostPlayed.id } export function getMegaWallsModeStats(modeId: typeof MODES[number]["id"], stats: NonNullable) { return [ stats[`kills_${modeId}`], stats[`deaths_${modeId}`], devide(stats[`kills_${modeId}`], stats[`deaths_${modeId}`]), stats[`wins_${modeId}`], stats[`losses_${modeId}`], devide(stats[`wins_${modeId}`], stats[`losses_${modeId}`]) ] }