Table of Contents

Class AggressionState

Namespace
FishMMO.Server.Implementation.World.SceneServer.AI
Assembly
FishMMO.Server.dll

Manages the aggression (threat) system for a single NPC. Owns the AggressionController instance, subscribes to global damage/heal/kill events, and tracks the per-NPC target re-evaluation timer.

Extracted from AIController to keep the controller focused on navigation and state management. One instance per NPC — plain C# class.

Event-driven combat entry: every hit this NPC takes is reported through OnHitRecorded, and the brain decides from its own state whether that hit starts a fight (OnThreatReceived(ICharacter)). It used to fire only when the table went from empty to non-empty, and nothing but a kill ever emptied it: a fight that ended any other way — the target out of reach, zoned, leashed away — left entries behind, so every later hit from beyond the detection radius was recorded and ignored, and each one refreshed the entry that kept it from ever going stale. Deciding per hit from the brain's state has no edge to consume.

Replay safety: Event handlers are guarded to ignore damage/heal/kill events fired during prediction replay. Global combat events are not replay-suppressed by the damage controller, so we suppress them here.

public class AggressionState
Inheritance
AggressionState
Inherited Members

Constructors

AggressionState(ICharacter)

Creates a new aggression state with a threat table at the default weights, and subscribes to global damage/heal/kill events. Call Configure(float, float, float, float, float, float) to give it an archetype's numbers.

public AggressionState(ICharacter character)

Parameters

character ICharacter

The NPC this threat table belongs to.

Fields

OnHitRecorded

Invoked with the attacker after every hit this NPC's table records.

public Action<ICharacter> OnHitRecorded

Field Value

Action<ICharacter>

Remarks

Every hit, not the first: whether a hit starts a fight is a question about the NPC's state (already fighting, leashing home, immortal, a passive pet), which only the brain can answer. See the class remarks for what the old empty-to-non-empty edge got wrong.

TargetReevaluationTimer

Per-NPC timer for mid-combat target re-evaluation. Decremented by the attacking state; reset when re-evaluation fires.

public float TargetReevaluationTimer

Field Value

float

Properties

Character

The NPC this table belongs to.

public ICharacter Character { get; }

Property Value

ICharacter

Controller

The aggression controller that tracks per-character threat scores and handles target selection.

public AggressionController Controller { get; }

Property Value

AggressionController

HasAggression

True when this NPC is tracking anyone at all.

public bool HasAggression { get; }

Property Value

bool

Remarks

Read by AggressionDispatcher to skip uninvolved NPCs without entering a handler. An out-of-combat NPC is the common case, so this needs to stay a field read.

Methods

Clear()

Clears all aggression data.

public void Clear()

Configure(float, float, float, float, float, float)

Sets the threat table's weights. Existing entries keep their points; only how future events are scored and how fast entries decay changes.

public void Configure(float damageWeight, float healingWeight, float hitBonus, float decayRate, float staleTimeout, float varietyChance)

Parameters

damageWeight float

Threat per 1 point of damage taken.

healingWeight float

Threat per 1 point of healing witnessed on a combat participant.

hitBonus float

Flat threat added per hit, regardless of damage.

decayRate float

Threat lost per second while no new events arrive.

staleTimeout float

Seconds before a drained threat entry is forgotten.

varietyChance float

Chance target selection picks the second-highest threat.

Remarks

Separate from the constructor so a controller whose archetype changes after it has been initialised — a spawner override on a recycled instance — can retune the table it already has instead of rebuilding it and losing its dispatcher registration.

ConfigureDefaults()

Returns the threat table to AggressionController's own default weights. Used for an NPC with no archetype.

public void ConfigureDefaults()

Destroy()

Unsubscribes from global events and clears the threat table.

public void Destroy()

HandleDamaged(ICharacter, int)

Records damage this NPC took. Called by AggressionDispatcher, which has already established that this NPC is the defender.

public void HandleDamaged(ICharacter attacker, int amount)

Parameters

attacker ICharacter

The character that dealt the damage.

amount int

Damage dealt.

HandleHealed(ICharacter, ICharacter, int)

Records threat for a heal this NPC witnessed on one of its enemies.

public void HandleHealed(ICharacter healer, ICharacter healed, int amount)

Parameters

healer ICharacter

The healing character.

healed ICharacter

The healed character.

amount int

Amount healed.

HandleKilled(ICharacter)

Forgets a character that has died.

public void HandleKilled(ICharacter victim)

Parameters

victim ICharacter

The character that died.

RecordResourceSpent(long, int)

Records resource expenditure threat against a specific character. Called externally (e.g., from AbilityController when a caster spends mana).

public void RecordResourceSpent(long characterId, int amount)

Parameters

characterId long
amount int

Tick(float)

Decays threat entries. Call once per tick or frame.

public void Tick(float deltaTime)

Parameters

deltaTime float