using UnityEngine;
namespace MazeGen
{
///
/// One participant in a battle - either an agent or a monster instance - behind a single
/// interface so doesn't need to branch on which it is.
///
/// Wraps the *live* , not a copy: resolving a fight mutates real
/// agent and monster health, which is exactly what "only the result of the fight has changed
/// for that room" means. is snapshotted before resolution purely so
/// the arena playback can animate health draining down from where it actually started.
///
public class Combatant
{
public const int TeamAgents = 0;
public const int TeamMonsters = 1;
/// Index of this combatant within its own battle. Combat events refer to these.
public readonly int Id;
public readonly int Team;
public readonly string Name;
public readonly Color Color;
/// Set for agent combatants, null for monsters.
public readonly MazeAgent Agent;
/// Set for monster combatants, null for agents.
public readonly MonsterEncounter.MonsterInstance Monster;
public readonly CharacterSheet Sheet;
/// Health at the moment the battle was resolved, for playback purposes.
public readonly float StartHealth;
public bool IsAgent => Agent != null;
public bool IsAlive => Sheet.Stats.IsAlive;
///
/// Base max health, not GetEffectiveMaxHealth(): CharacterStats.CurrentHealth is clamped
/// to the base value, so using the effective one here would give health bars that can
/// never fill up whenever equipment grants a health bonus.
///
public float MaxHealth => Mathf.Max(1f, Sheet.Stats.MaxHealth);
private Combatant(int id, int team, string name, Color color, MazeAgent agent, MonsterEncounter.MonsterInstance monster, CharacterSheet sheet)
{
Id = id;
Team = team;
Name = name;
Color = color;
Agent = agent;
Monster = monster;
Sheet = sheet;
StartHealth = sheet.Stats.CurrentHealth;
}
public static Combatant ForAgent(int id, MazeAgent agent, Color color)
=> new Combatant(id, TeamAgents, agent.CharacterSheet.Name, color, agent, null, agent.CharacterSheet);
public static Combatant ForMonster(int id, MonsterEncounter.MonsterInstance monster)
=> new Combatant(id, TeamMonsters, monster.Template.MonsterName, monster.Template.Color, null, monster, monster.CharacterSheet);
}
}