Class AggressionDispatcher
Routes combat events to the one NPC that cares about them, instead of broadcasting every event to every NPC in the scene.
public static class AggressionDispatcher
- Inheritance
-
AggressionDispatcher
- Inherited Members
Remarks
The problem this replaces. Each AggressionState used to subscribe individually to the global damage, heal and kill events. That meant a single sword swing invoked one delegate per NPC in the scene — a thousand NPCs, a thousand calls, of which exactly one was for the NPC actually being hit and 999 returned immediately from a reference comparison. At a busy raid boss with a few hundred hits per second the wasted work is measured in hundreds of thousands of calls per second, all to deliver a handful of events.
What it does instead. One subscription for the whole process. Damage is the hot path and is dispatched by dictionary lookup on the defender — O(1) regardless of how many NPCs exist. Heal and kill still have to consider several NPCs (a heal matters to anyone tracking either party), but they walk a plain list and skip anyone whose threat table is empty with a field read, which is what almost every NPC in a scene is at any moment.
Server-side only. Registration happens when an NPC's aggression state is built and is released when it is destroyed.
Properties
RegisteredCount
Number of NPCs currently registered. Diagnostics.
public static int RegisteredCount { get; }
Property Value
Methods
Clear()
Drops all registrations. Call on server shutdown.
public static void Clear()
Register(ICharacter, AggressionState)
Registers an NPC's threat state to receive combat events.
public static void Register(ICharacter character, AggressionState state)
Parameters
characterICharacterThe NPC that owns the state.
stateAggressionStateThe threat state.
Unregister(ICharacter)
Stops routing events to an NPC's threat state.
public static void Unregister(ICharacter character)
Parameters
characterICharacterThe NPC that owns the state.