"use client" import { useEffect, useMemo } from "react"; import SelectCustomText from "../select/customSelectText"; import { calcMonsterStats, getLocaleName, replaceByParam } from "@/helper"; import useLocaleStore from "@/stores/localeStore"; import useUserDataStore from "@/stores/userDataStore";; import Image from "next/image"; import { useTranslations } from "next-intl"; import { MonsterStore } from "@/types"; import useDetailDataStore from "@/stores/detailDataStore"; export default function PeakBar() { const { locale } = useLocaleStore() const { peak_config, setPeakConfig } = useUserDataStore() const { mapMonster, mapPeak, damageType, eliteConfig, hardLevelConfig } = useDetailDataStore() const transI18n = useTranslations("DataPage") const listFloor = useMemo(() => { const peak = mapPeak?.[peak_config?.event_id?.toString()] if (!peak) return [] return [...peak.PreLevel, peak.BossLevel].filter(it => it != null) }, [peak_config, mapPeak]) const eventSelected = useMemo(() => { return mapPeak?.[peak_config?.event_id?.toString()] }, [peak_config, mapPeak]) const bossConfig = useMemo(() => { return mapPeak?.[peak_config?.event_id?.toString()]?.BossConfig; }, [peak_config, mapPeak]) const challengeSelected = useMemo(() => { const challenge = structuredClone(listFloor?.find((peak) => peak?.ID === peak_config.challenge_id)) if ( challenge && challenge.ID === mapPeak?.[peak_config?.event_id?.toString()]?.BossLevel?.ID && bossConfig && peak_config?.boss_mode === "Hard" ) { return bossConfig } return challenge }, [peak_config, listFloor, mapPeak, bossConfig]) useEffect(() => { if (!challengeSelected) return if (peak_config.event_id !== 0 && peak_config.challenge_id !== 0 && challengeSelected) { const newBattleConfig = structuredClone(peak_config) newBattleConfig.cycle_count = 6 newBattleConfig.blessings = [] for (const value of challengeSelected.MazeBuff) { newBattleConfig.blessings.push({ id: value.ID, level: 1 }) } if (peak_config.buff_id !== 0) { newBattleConfig.blessings.push({ id: peak_config.buff_id, level: 1 }) } newBattleConfig.monsters = [] newBattleConfig.stage_id = challengeSelected.EventList[0].ID for (const wave of challengeSelected.EventList[0].MonsterList) { if (!wave) continue const newWave: MonsterStore[] = [] for (const value of Object.values(wave)) { if (!value) continue newWave.push({ monster_id: value, level: challengeSelected.EventList[0].Level, amount: 1, }) } newBattleConfig.monsters.push(newWave) } setPeakConfig(newBattleConfig) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [ peak_config.event_id, peak_config.challenge_id, peak_config.buff_id, peak_config.boss_mode, mapPeak, ]) if (!mapPeak) return null return (
{/* Title Card */}
b.ID - a.ID).map((peak) => ({ id: peak.ID.toString(), name: `${getLocaleName(locale, peak.Name)} (${peak.ID})`, }))} excludeSet={[]} selectedCustomSet={peak_config.event_id.toString()} placeholder={transI18n("selectPEAKEvent")} setSelectedCustomSet={(id) => setPeakConfig({ ...peak_config, event_id: Number(id), challenge_id: 0, buff_id: 0 })} />
{/* Settings */}
{eventSelected && eventSelected.BossLevel?.ID === peak_config.challenge_id && (
)}
StageId: {peak_config?.stage_id}
{ eventSelected && eventSelected.BossLevel?.ID === peak_config.challenge_id && bossConfig && (
({ id: buff.ID.toString(), name: getLocaleName(locale, buff?.Name || ""), description: replaceByParam(getLocaleName(locale, buff?.Desc || ""), buff?.Param || []), })) } excludeSet={[]} selectedCustomSet={peak_config?.buff_id?.toString()} placeholder={transI18n("selectBuff")} setSelectedCustomSet={(id) => setPeakConfig({ ...peak_config, buff_id: Number(id) })} />
) } {/* Turbulence Buff */}

{transI18n("turbulenceBuff")}

{challengeSelected && challengeSelected?.MazeBuff?.length > 0 ? ( challengeSelected.MazeBuff.map((subOption, index) => (
)) ) : (
{transI18n("noTurbulenceBuff")}
)}
{/* Enemy Waves */} {(peak_config?.challenge_id ?? 0) !== 0 && (

{getLocaleName(locale, challengeSelected?.Name)}

{challengeSelected && Object.values(challengeSelected?.EventList?.[0]?.Infinite || []).map((waveValue, waveIndex) => (

{transI18n("wave")} {waveIndex + 1}

{Array.from(new Set(waveValue.MonsterList)).map((monsterId, enemyIndex) => { const monsterStats = calcMonsterStats( mapMonster?.[monsterId.toString()], waveValue.EliteGroup, challengeSelected?.EventList?.[0]?.HardLevelGroup, challengeSelected?.EventList?.[0]?.Level, hardLevelConfig, eliteConfig ); return (
Lv. {challengeSelected?.EventList[0].Level}
{mapMonster?.[monsterId.toString()]?.Image?.IconPath && (
Enemy Icon
)}
HP {monsterStats.hp.toLocaleString(undefined, { maximumFractionDigits: 0 })}
Speed {monsterStats.spd.toLocaleString(undefined, { maximumFractionDigits: 0 })}
Toughness {monsterStats.stance.toLocaleString(undefined, { maximumFractionDigits: 0 })}
Weakness
{mapMonster?.[monsterId.toString()]?.StanceWeakList?.map((icon, iconIndex) => ( {icon} ))}
) })}
))}
)}
) }