import { BOSSES_PER_ACT } from "./types";

export type RpgEncounterKind = "hallway-challenge" | "boss-room";

export interface RpgEncounterDifficulty {
  readonly healthMultiplier: number;
  readonly damageMultiplier: number;
}

/**
 * Party rotations are calibrated around two simultaneous bosses. A solo RPG
 * boss therefore carries the full shared health budget, while incoming
 * damage stays below a full 2x multiplier so one unavoidable hit cannot stand
 * in for two independently targeted mechanics.
 */
export const RPG_SOLO_BOSS_HEALTH_MULTIPLIER = 2;
export const RPG_SOLO_BOSS_DAMAGE_MULTIPLIER = 1.5;

const RPG_BOSS_HEALTH_GROWTH_PER_ROOM = 0.14;
const RPG_BOSS_DAMAGE_GROWTH_PER_ACT = 0.08;
const RPG_CHALLENGE_BASE_HEALTH_MULTIPLIER = 0.82;
const RPG_CHALLENGE_HEALTH_GROWTH_PER_ACT = 0.08;

/** Central mode-specific tuning hook used only when an RPG encounter begins. */
export function rpgEncounterDifficulty(
  kind: RpgEncounterKind,
  requestedBossIndex: number,
): RpgEncounterDifficulty {
  const bossIndex = Math.max(0, Math.floor(requestedBossIndex));
  const act = Math.floor(bossIndex / BOSSES_PER_ACT);

  if (kind === "hallway-challenge") {
    return {
      healthMultiplier: RPG_CHALLENGE_BASE_HEALTH_MULTIPLIER + act * RPG_CHALLENGE_HEALTH_GROWTH_PER_ACT,
      damageMultiplier: 1,
    };
  }

  return {
    healthMultiplier: RPG_SOLO_BOSS_HEALTH_MULTIPLIER * (1 + bossIndex * RPG_BOSS_HEALTH_GROWTH_PER_ROOM),
    damageMultiplier: RPG_SOLO_BOSS_DAMAGE_MULTIPLIER * (1 + act * RPG_BOSS_DAMAGE_GROWTH_PER_ACT),
  };
}
