dd-timer/src/domain/services/XpCalculator.ts
POL Mickaël 3e485fd09b chore: normalise fins de ligne CRLF → LF dans tout le repo
Applique .gitattributes sur tous les fichiers existants.
Élimine les différences fantômes entre WSL et Windows.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 08:55:10 +02:00

33 lines
1.1 KiB
TypeScript
Executable File

import { timeToGain } from '@domain/services/GaugeCalculator';
import { xpForLevel } from '@domain/value-objects/XpTable';
import type { GaugeType } from '@domain/value-objects/GaugeType';
export interface XpEtaInput {
currentLevel: number;
target: number | null;
gaugeLevels: Readonly<Record<string, number>>;
activeGauges: readonly string[];
}
export interface XpEtaResult {
done: boolean;
seconds: number;
needsGauge?: GaugeType;
}
export class XpCalculator {
computeEta(input: XpEtaInput): XpEtaResult {
const { currentLevel, target, gaugeLevels, activeGauges } = input;
if (target === null || target === undefined) return { done: false, seconds: 0 };
if (currentLevel >= target) return { done: true, seconds: 0 };
if (!activeGauges.includes('mangeoire')) return { done: false, seconds: Infinity, needsGauge: 'mangeoire' };
const gl = gaugeLevels['mangeoire'] ?? 0;
const xpNeeded = Math.max(0, xpForLevel(target) - xpForLevel(currentLevel));
if (xpNeeded <= 0) return { done: true, seconds: 0 };
const sec = timeToGain(gl, xpNeeded);
return { done: false, seconds: sec };
}
}