| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using UnityEngine;
- namespace MazeGen
- {
- /// <summary>
- /// One participant in a battle - either an agent or a monster instance - behind a single
- /// interface so <see cref="CombatResolver"/> doesn't need to branch on which it is.
- ///
- /// Wraps the *live* <see cref="CharacterSheet"/>, 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. <see cref="StartHealth"/> is snapshotted before resolution purely so
- /// the arena playback can animate health draining down from where it actually started.
- /// </summary>
- public class Combatant
- {
- public const int TeamAgents = 0;
- public const int TeamMonsters = 1;
- /// <summary>Index of this combatant within its own battle. Combat events refer to these.</summary>
- public readonly int Id;
- public readonly int Team;
- public readonly string Name;
- public readonly Color Color;
- /// <summary>Set for agent combatants, null for monsters.</summary>
- public readonly MazeAgent Agent;
- /// <summary>Set for monster combatants, null for agents.</summary>
- public readonly MonsterEncounter.MonsterInstance Monster;
- public readonly CharacterSheet Sheet;
- /// <summary>Health at the moment the battle was resolved, for playback purposes.</summary>
- public readonly float StartHealth;
- public bool IsAgent => Agent != null;
- public bool IsAlive => Sheet.Stats.IsAlive;
- /// <summary>
- /// 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.
- /// </summary>
- 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);
- }
- }
|