| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System.Linq;
- namespace MazeGen
- {
- /// <summary>
- /// Decides to use a health potion if the agent's health is low.
- /// Only executes when outside of combat and health is below 50%.
- /// </summary>
- public class UseHealthPotionDecision : AgentDecision
- {
- private const float LowHealthThreshold = 0.5f;
- public override string DecisionName => "Use Health Potion";
- public override bool CanExecute(MazeAgent agent)
- {
- if (agent == null || agent.IsEngaged) return false; // Can't use potions while fighting
- CharacterSheet sheet = agent.CharacterSheet;
- float healthPercent = sheet.Stats.MaxHealth > 0 ? sheet.Stats.CurrentHealth / sheet.Stats.MaxHealth : 1f;
- if (healthPercent >= LowHealthThreshold) return false; // Health is fine
- // Check if we have a potion available (peek without consuming)
- return sheet.Inventory.Any(i => i is Consumable c && c.HealthBonus > 0);
- }
- public override bool Execute(MazeAgent agent)
- {
- CharacterSheet sheet = agent.CharacterSheet;
- Consumable potion = sheet.GetHealthPotionFromInventory();
- if (potion != null && potion.HealthBonus > 0)
- {
- sheet.Stats.Heal(potion.HealthBonus);
- return true;
- }
- return false;
- }
- public override void Think(MazeAgent agent)
- {
- CharacterSheet sheet = agent.CharacterSheet;
- // The potion was consumed in Execute, so we narrate the result
- agent.Thoughts.Add(ThoughtKind.Peek,
- $"Used health potion, recovered HP (now {sheet.Stats.CurrentHealth:0.#}/{sheet.Stats.MaxHealth:0.#})");
- }
- }
- }
|