Files
healer-man/src/game/timedEffectDisplay.ts
T
2026-08-14 15:56:39 -04:00

24 lines
1017 B
TypeScript

import type { TimedCombatEffect } from "./combatStore";
/** The final periodic tick is the moment the displayed aura expires. */
export function timedEffectExpiresAt(effect: TimedCombatEffect): number {
return effect.nextTickAt + Math.max(0, effect.remainingTicks - 1) * effect.intervalMs;
}
export function timedEffectRemainingMs(effect: TimedCombatEffect, now: number): number {
return Math.max(0, timedEffectExpiresAt(effect) - now);
}
/** Compact MMO-style countdown: whole seconds, then tenths for the last 10 seconds. */
export function formatTimedEffectTimer(remainingMs: number): string {
const safeRemaining = Math.max(0, Number.isFinite(remainingMs) ? remainingMs : 0);
const seconds = safeRemaining / 1_000;
if (seconds >= 60) {
const roundedSeconds = Math.ceil(seconds);
const minutes = Math.floor(roundedSeconds / 60);
return `${minutes}:${String(roundedSeconds % 60).padStart(2, "0")}`;
}
if (seconds >= 10) return String(Math.ceil(seconds));
return seconds.toFixed(1);
}