Skip to content

ThreatTableComponent ​

Inherits: Resource

ThreatTableComponent manages the aggression (threat) system for NPC entities. It tracks and calculates aggression levels towards players, influencing target selection and combat behavior. Key features:

Description ​

  • Maintains a threat table storing aggression values for each player
  • Provides methods for adding, decaying, and resetting threat
  • Handles target selection based on highest threat
  • Manages combat state transitions based on threat levels
  • Responds to entity death or freeing events

Variables ​

Entityentity
Dictionarythreat_table{}
Dictionaryconnected_entities{}
Array[Entity]forced_targets[]

Methods ​

voidthreat_table_component_setup( system_hub: GameHost.SystemHub, parent_entity: Entity )
voidreceive_threat_from_player( player: Entity, threat_amount: int )
voidforce_target( source: Entity )
voidrelease_forced_target( source: Entity )
floatget_threat( source: Entity )
voidset_threat( source: Entity, value: float )
floatget_highest_threat()
Entityselect_target_player()
voiddecay_threat( decay_factor: float = 0.95 )
voidreset_target_threat( player: Entity )
boolall_threat_null()
Entityget_highest_threat_target()
voidclear_threat()

Variable descriptions ​

Entity entity ​

The entity (NPC) that owns this threat table

Dictionary threat_table = ​

Dictionary to store player threat amounts

Dictionary connected_entities = ​

Dictionary to track which entities we're connected to

Array[Entity] forced_targets = [] ​

Entities that forced this NPC to target them (a taunt), the latest last: while there is one, it is the target whatever the threat says

Method descriptions ​

void threat_table_component_setup( system_hub: GameHost.SystemHub, parent_entity: Entity ) ​

Initializes the ThreatTableComponent

void receive_threat_from_player( player: Entity, threat_amount: int ) ​

Adds threat for a player and updates the entity's target

void force_target( source: Entity ) ​

Makes the NPC attack this source (a taunt).

void release_forced_target( source: Entity ) ​

Lets the NPC choose its target again.

float get_threat( source: Entity ) ​

The threat an entity has on this NPC (0 = none)

void set_threat( source: Entity, value: float ) ​

Sets the threat of an entity outright (0 or less removes it)

float get_highest_threat() ​

The highest threat any entity has on this NPC

Entity select_target_player() ​

Selects the player with the highest threat as the target

void decay_threat( decay_factor: float = 0.95 ) ​

Reduces threat for all players over time

void reset_target_threat( player: Entity ) ​

Resets the threat for a specific player

bool all_threat_null() ​

Checks if all threat values are null (no targets)

Entity get_highest_threat_target() ​

Returns the player with the highest threat

void clear_threat() ​

Clears all threat values