Table of Contents

Class AggressionState

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.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: When the threat table transitions from empty to non-empty (first damage received), the OnCombatInitiated callback is invoked for immediate combat entry without waiting for the next physics sweep.

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, float, float, float, float, float, float)

Creates a new aggression state, initialises the threat table, and subscribes to global damage/heal/kill events.

public AggressionState(ICharacter character, float damageWeight, float healingWeight, float hitBonus, float decayRate, float staleTimeout, float varietyChance)

Parameters

character ICharacter
damageWeight float
healingWeight float
hitBonus float
decayRate float
staleTimeout float
varietyChance float

Fields

OnCombatInitiated

Callback invoked when the threat table transitions from empty to non-empty.

public Action<ICharacter> OnCombatInitiated

Field Value

Action<ICharacter>

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

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()

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