b451f83174
Captures the pre-Godot-port state of the codebase. This is the rollback anchor for the Godot port (M0 of theriapolis-rpg-implementation-plan-godot-port.md). All Phase 0 through Phase 6.5 work is included; Phase 7 is in flight. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
using Theriapolis.Core.Rules.Combat;
|
|
|
|
namespace Theriapolis.Core.Entities.Ai;
|
|
|
|
/// <summary>
|
|
/// One NPC behavior — what does this NPC do on its turn? Behaviors are
|
|
/// dispatched by id (the template's <c>behavior</c> field) via
|
|
/// <see cref="BehaviorRegistry"/>. Each behavior must produce its turn's
|
|
/// actions within bounded time — no recursion, no while-true loops; if no
|
|
/// valid action is available, end the turn.
|
|
/// </summary>
|
|
public interface INpcBehavior
|
|
{
|
|
/// <summary>
|
|
/// Take one turn for <paramref name="self"/>. Behaviors call into
|
|
/// <see cref="Resolver"/> to mutate the encounter, then return — the
|
|
/// caller (typically <see cref="Encounter"/>'s turn pump) calls
|
|
/// <see cref="Encounter.EndTurn"/> after this returns.
|
|
/// </summary>
|
|
void TakeTurn(Combatant self, AiContext ctx);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Maps behavior ids (the strings in <c>npc_templates.json</c>'s
|
|
/// <c>behavior</c> field) to their <see cref="INpcBehavior"/>
|
|
/// implementation. Phase 5 M5 ships three: <c>brigand</c>,
|
|
/// <c>wild_animal</c>, <c>poi_guard</c>. Unknown ids fall back to
|
|
/// <c>brigand</c> with a debug log.
|
|
/// </summary>
|
|
public static class BehaviorRegistry
|
|
{
|
|
private static readonly System.Collections.Generic.Dictionary<string, INpcBehavior> _impls
|
|
= new(System.StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["brigand"] = new BrigandBehavior(),
|
|
["wild_animal"] = new WildAnimalBehavior(),
|
|
["poi_guard"] = new PoiGuardBehavior(),
|
|
["patrol"] = new BrigandBehavior(), // patrol shares brigand combat behavior
|
|
};
|
|
|
|
public static INpcBehavior For(string id)
|
|
{
|
|
return _impls.TryGetValue(id, out var b) ? b : _impls["brigand"];
|
|
}
|
|
}
|