Files
Firefly_Sranalysis/src/hooks/useDamagePerCycle.ts
T
Kain344 cf9553d343
Gitea Auto Deploy / Deploy-Container (push) Successful in 3m21s
Refactor TypeScript files for improved readability and consistency
- Cleaned up imports and formatting in localeStore.ts and socketSettingStore.ts.
- Standardized interface definitions and formatting in attack.ts, avatar.ts, battle.ts, enemy.ts, entity.ts, error.ts, index.ts, lineup.ts, mics.ts, skill.ts, srtools.ts, team.ts, turn.ts, version.ts, and waveAndCycle.ts.
- Ensured consistent use of semicolons and spacing across all modified files.
- Updated tsconfig.json for consistency in formatting.
2026-08-27 18:23:17 +07:00

69 lines
2.3 KiB
TypeScript

import useBattleDataStore from "@/stores/battleDataStore";
import { useTranslations } from "next-intl";
import { useMemo } from "react";
type Mode = 0 | 1 | 2;
export function useDamagePerCycleForOne(avatarId: number, mode: Mode) {
const { skillHistory, turnHistory } = useBattleDataStore.getState();
const transI18n = useTranslations("DataAnalysisPage");
return useMemo(() => {
const damageMap = new Map<string, number>();
skillHistory
.filter(s => s.avatarId === avatarId)
.forEach(s => {
const turn = turnHistory[s.turnBattleId];
if (!turn) return;
let key = '';
if (mode === 0) {
key = `${transI18n('cycle')} ${turn.cycleIndex} - ${transI18n('wave')} ${turn.waveIndex}`;
} else if (mode === 1) {
key = `${transI18n('cycle')} ${turn.cycleIndex}`;
} else if (mode === 2) {
key = `${transI18n('wave')} ${turn.waveIndex}`;
}
damageMap.set(key, (damageMap.get(key) || 0) + s.totalDamage);
});
const result = Array.from(damageMap.entries())
.map(([x, y]) => ({ x, y }))
.sort((a, b) => a.x.localeCompare(b.x, undefined, { numeric: true }));
return result;
}, [avatarId, mode, skillHistory, turnHistory, transI18n]);
}
export function useDamagePerCycleForAll(mode: Mode) {
const { skillHistory, turnHistory } = useBattleDataStore.getState();
const transI18n = useTranslations("DataAnalysisPage");
return useMemo(() => {
const damageMap = new Map<string, number>();
skillHistory.forEach(s => {
const turn = turnHistory[s.turnBattleId];
if (!turn) return;
let key = '';
if (mode === 0) {
key = `${transI18n('cycle')} ${turn.cycleIndex} - ${transI18n('wave')} ${turn.waveIndex}`;
} else if (mode === 1) {
key = `${transI18n('cycle')} ${turn.cycleIndex}`;
} else if (mode === 2) {
key = `${transI18n('wave')} ${turn.waveIndex}`;
}
damageMap.set(key, (damageMap.get(key) || 0) + s.totalDamage);
});
const result = Array.from(damageMap.entries())
.map(([x, y]) => ({ x, y }))
.sort((a, b) => a.x.localeCompare(b.x, undefined, { numeric: true }));
return result;
}, [mode, skillHistory, turnHistory, transI18n]);
}