using Microsoft.Extensions.Logging; using NewMoon.TF2Helpers; using NewMoon.TF2Helpers.Entities; using NewMoon.Utility; namespace NewMoon.Samples.CustomNpc; /// /// The custom NPC: a nm_sample_npc 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 (see the README). The registry needs an accessible parameterless constructor. /// [CustomEntity("nm_sample_npc", "base_boss", PrecacheModels = ["models/bots/headless_hatman.mdl"])] internal sealed class SampleNpc : 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); }