Moonstormstaticcapturable
Overview
This component provides the core logic for marking an entity as a static capturable target within the Moonstorm system. It tracks which objects are currently "targeting" it (via moonstormstaticcatcher components), manages transitions between targeted and untargeted states, and notifies registered callbacks or events when capture-related milestones occur (targeting, untargeting, or successful capture).
Dependencies & Tags
- Adds/Removes the
"moonstormstaticcapturable"tag on entity enablement and removal (viaAddOrRemoveTag/RemoveTag) - Assumes coexistence with
moonstormstaticcatchercomponents that call itsOnTargeted,OnUntargeted, andOnCaughtmethods
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
enabled | boolean | true | Controls whether the entity currently registers as a capturable target (affects tag presence) |
targeters | table | {} | Map of targeting objects (keys are entity instances), used to track active targets |
ontargetedfn | function? | nil | Optional callback invoked when the first targeter is added |
onuntargetedfn | function? | nil | Optional callback invoked when the last targeter is removed |
oncaughtfn | function? | nil | Optional callback invoked on successful capture ((inst, targeter, doer)) |
Main Functions
SetEnabled(enabled)
- Description: Enables or disables the capturable behavior by adding or removing the
"moonstormstaticcapturable"tag from the entity. - Parameters:
enabled(boolean): Whether the capturable state should be active.
IsEnabled()
- Description: Returns the current enabled state.
- Parameters: None
SetOnTargetedFn(fn)
- Description: Registers a callback to execute when the entity transitions to a targeted state (i.e., when the first targeter is added).
- Parameters:
fn(function): A callback accepting the entity instance as its sole argument.
SetOnUntargetedFn(fn)
- Description: Registers a callback to execute when the entity transitions to an untargeted state (i.e., when the last targeter is removed).
- Parameters:
fn(function): A callback accepting the entity instance as its sole argument.
SetOnCaughtFn(fn)
- Description: Registers a callback to execute when the entity is successfully captured.
- Parameters:
fn(function): A callback accepting(inst, targeter_obj, doer_obj)arguments.
IsTargeted()
- Description: Returns
trueif at least one object is currently targeting this entity. - Parameters: None
OnTargeted(obj)
- Description: Records a new targeter (
obj), triggers the"moonstormstaticcapturable_targeted"event andontargetedfnif this was the first targeter. - Parameters:
obj(Entity): The object (typically amoonstormstaticcatcher) initiating targeting.
OnUntargeted(obj)
- Description: Removes a targeter (
obj), triggers the"moonstormstaticcapturable_untargeted"event andonuntargetedfnif this was the last targeter. - Parameters:
obj(Entity): The object ceasing to target this entity.
OnCaught(obj, doer)
- Description: Handles successful capture: invokes
oncaughtfnand pushes a"moonstormstatic_caught"event on thedoer. - Parameters:
obj(Entity): The targeter that performed the capture.
doer(Entity?): The entity responsible for executing the capture (e.g., a player or AI).
Events & Listeners
- Listens for
"onremove"on targeters: Cleans up internal tracking when a targeter entity is removed from the world. - Pushes events:
"moonstormstaticcapturable_targeted": Emitted when the first targeter is added (only once per targeting session)."moonstormstaticcapturable_untargeted": Emitted when the last targeter is removed (only once per untargeting session)."moonstormstatic_caught": Pushed on thedoerwhen capture completes.