using Microsoft.Extensions.Logging;
namespace NewMoon.Samples.NPC;
///
/// The custom NPC: a npc_bot_newmoon classname that is a factory alias of base_boss. Spawning it yields a real
/// base_boss that carries the new classname, and the registry calls the lifecycle overrides below.
///
///
/// The class only logs. Reading keyvalues, inputs and outputs from a custom entity is not part of the landed API yet, so the
/// spawner supplies health and model, for example ent_create npc_bot_newmoon health 500 model models/bots/headless_hatman.mdl. The registry needs an accessible parameterless constructor.
///
[CustomEntity("npc_bot_newmoon", "base_boss", PrecacheModels = ["models/bots/headless_hatman.mdl"])]
internal sealed class NPCBotNewMoon : FCustomEntity
{
///
/// The logger the callbacks write to; set by at start-up, because the registry creates this
/// object through its parameterless constructor.
///
internal static ILogger? Log { get; set; }
// Captured at spawn so the remove log never depends on the view still resolving while the instance is torn down.
private int _index = -1;
///
protected override void OnSpawn()
{
_index = Entity.Index;
Log?.LogNPCSpawn(_index);
}
///
protected override void OnActivate() => Log?.LogNPCActivate(_index);
///
protected override void OnRemoved() => Log?.LogNPCRemoved(_index);
}