import type { BossId } from "./types";

export const BOSS_DEATH_HOLD_SECONDS = 2.5;
export const BOSS_DEATH_FADE_SECONDS = 0.75;
export const BOSS_DEATH_DESPAWN_SECONDS = BOSS_DEATH_HOLD_SECONDS + BOSS_DEATH_FADE_SECONDS;

const BOSS_DEATH_HOLD_OVERRIDES: Partial<Record<BossId, number>> = {
  // Armature|Fall lasts 5.73 seconds. Hold through final authored pose before fade.
  "gravehorn-triceratops": 5.85,
};

export function bossDeathHoldSeconds(bossId?: BossId) {
  return bossId ? BOSS_DEATH_HOLD_OVERRIDES[bossId] ?? BOSS_DEATH_HOLD_SECONDS : BOSS_DEATH_HOLD_SECONDS;
}

export function bossDeathDespawnSeconds(bossId?: BossId) {
  return bossDeathHoldSeconds(bossId) + BOSS_DEATH_FADE_SECONDS;
}

export function bossDeathOpacity(elapsedSeconds: number, bossId?: BossId) {
  const holdSeconds = bossDeathHoldSeconds(bossId);
  if (elapsedSeconds <= holdSeconds) return 1;
  return Math.max(0, 1 - (elapsedSeconds - holdSeconds) / BOSS_DEATH_FADE_SECONDS);
}
