export type EntityId = number;

export type Vec2 = { x: number; y: number };

export type Tile = number;

export type Action =
  | { type: "move"; dx: number; dy: number }
  | { type: "attack"; targetId: EntityId }
  | { type: "wait" };

export type SimEvent =
  | { type: "moved"; actorId: EntityId; from: Vec2; to: Vec2 }
  | { type: "attacked"; attackerId: EntityId; targetId: EntityId }
  | { type: "damaged"; targetId: EntityId; amount: number; hp: number; x: number; y: number }
  | { type: "killed"; targetId: EntityId; killerId: EntityId; x: number; y: number; victimType?: "player" | "rat" | "bat" | "exp_orb" }

  | { type: "waited"; actorId: EntityId }
  | { type: "exp-collected"; actorId: EntityId; amount: number; x: number; y: number }
  | { type: "orb-spawned"; orbId: EntityId; x: number; y: number }
  | { type: "leveled-up"; actorId: EntityId; level: number; x: number; y: number };


export type Stats = {
  maxHp: number;
  hp: number;
  attack: number;
  defense: number;
  level: number;
  exp: number;
  expToNextLevel: number;
};


export type Inventory = {
  gold: number;
  items: string[];
};

export type RunState = {
  stats: Stats;
  inventory: Inventory;
};

export type Actor = {
  id: EntityId;
  isPlayer: boolean;
  type?: "player" | "rat" | "bat" | "exp_orb";
  pos: Vec2;

  speed: number;
  energy: number;

  stats?: Stats;
  inventory?: Inventory;
};

export type World = {
  width: number;
  height: number;
  tiles: Tile[];
  actors: Map<EntityId, Actor>;
  exit: Vec2;
};
