PendingFight.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System.Collections.Generic;
  2. namespace MazeGen
  3. {
  4. public enum FightState
  5. {
  6. /// <summary>Declared, but not started yet - the join window is counting down.</summary>
  7. Mustering,
  8. /// <summary>Outcome is decided; if it's being watched, playback is still running.</summary>
  9. Resolving,
  10. Resolved,
  11. /// <summary>Never happened (every participant left/died, or the monsters were already dead).</summary>
  12. Cancelled
  13. }
  14. /// <summary>Whether a fight's outcome is just logged, or played out on the arena grid.</summary>
  15. public enum CombatViewMode
  16. {
  17. Simulate,
  18. Watch
  19. }
  20. /// <summary>
  21. /// A fight that has been declared in a room but hasn't started yet. The join window is the
  22. /// whole point of this type existing: an agent that picks a fight doesn't fight immediately,
  23. /// it commits and then waits, and during that wait other agents can walk in and pile on
  24. /// (improving the odds) or try to sneak past.
  25. /// </summary>
  26. public class PendingFight
  27. {
  28. public readonly int Id;
  29. public readonly Room Room;
  30. public readonly MonsterEncounter Encounter;
  31. /// <summary>Agents committed to this fight, in join order. The first is whoever started it.</summary>
  32. public readonly List<MazeAgent> Agents = new List<MazeAgent>();
  33. /// <summary>Seconds of join window left. Ticks on SimulationClock time, so pausing freezes it.</summary>
  34. public float JoinTimeRemaining;
  35. public FightState State = FightState.Mustering;
  36. /// <summary>Why this fight started, for the log/HUD.</summary>
  37. public string Trigger;
  38. /// <summary>Null until resolution.</summary>
  39. public BattleResult Result;
  40. /// <summary>How this fight was (or will be) resolved.</summary>
  41. public CombatViewMode ResolvedAs;
  42. /// <summary>
  43. /// The observer's choice of Watch/Log for when the join window naturally expires. Setting
  44. /// this (via CombatDirector.PreferWatch/PreferSimulate) is only a preference, not a trigger -
  45. /// the join window always has to run out on its own first; see CombatDirector.Update.
  46. /// Null means "use the director's default timeout resolution".
  47. /// </summary>
  48. public CombatViewMode? PreferredResolution;
  49. public PendingFight(int id, Room room, MonsterEncounter encounter)
  50. {
  51. Id = id;
  52. Room = room;
  53. Encounter = encounter;
  54. }
  55. public bool Contains(MazeAgent agent) => agent != null && Agents.Contains(agent);
  56. public string Describe() => $"Fight #{Id} in room {Room.Id}: {Agents.Count} agent(s) vs {Encounter.AliveMonsterCount} monster(s)";
  57. }
  58. }