Files
TheriapolisV3/Theriapolis.Core/Rules/Combat/NpcInstantiator.cs
T
Christopher Wiebe b451f83174 Initial commit: Theriapolis baseline at port/godot branch point
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>
2026-04-30 20:40:51 -07:00

37 lines
1.4 KiB
C#

using Theriapolis.Core.Data;
using Theriapolis.Core.Tactical;
namespace Theriapolis.Core.Rules.Combat;
/// <summary>
/// Maps a <see cref="TacticalSpawn"/> + chunk's <see cref="TacticalChunk.DangerZone"/>
/// to the actual <see cref="NpcTemplateDef"/> that should spawn there.
/// Lookup table lives in <c>npc_templates.json</c>'s
/// <c>spawn_kind_to_template_by_zone</c> map (loaded into
/// <see cref="NpcTemplateContent.SpawnKindToTemplateByZone"/>).
///
/// Returns null when no template is configured for the spawn kind/zone (the
/// caller should skip that spawn — chunk is silently denser, that's OK).
/// </summary>
public static class NpcInstantiator
{
public static NpcTemplateDef? PickTemplate(
SpawnKind kind,
int dangerZone,
NpcTemplateContent content)
{
if (kind == SpawnKind.None) return null;
string kindKey = kind.ToString();
if (!content.SpawnKindToTemplateByZone.TryGetValue(kindKey, out var byZone))
return null;
if (byZone.Length == 0) return null;
// Clamp the zone index to the table's length.
int zoneIdx = System.Math.Clamp(dangerZone, 0, byZone.Length - 1);
string templateId = byZone[zoneIdx];
foreach (var t in content.Templates)
if (string.Equals(t.Id, templateId, System.StringComparison.OrdinalIgnoreCase))
return t;
return null;
}
}