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, through the the registry supplies. The spawner supplies health /// and model, for example ent_create npc_bot_newmoon health 500 model models/bots/headless_hatman.mdl. The registry /// constructs the class through dependency injection, so it needs a public constructor; any constructor parameters are resolved /// from the plugin's services. The plugin registers it automatically at start-up. /// [CustomEntity("npc_bot_newmoon", "base_boss", PrecacheModels = ["models/bots/headless_hatman.mdl"])] internal sealed class NPCBotNewMoon : FCustomEntity { // 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; PLogger.LogNPCSpawn(_index); } /// protected override void OnActivate() => PLogger.LogNPCActivate(_index); /// protected override void OnRemoved() => PLogger.LogNPCRemoved(_index); }