Stormwatcher
Overview
This component monitors environmental storm activity (sandstorms and moonstorms) affecting the associated entity. It maintains the current storm type and intensity level, updates derived state (e.g., stormlevel, currentstorm), and coordinates updates via scheduled polling and event-driven callbacks. It also ensures UI reflection by syncing the storm level and type to the player_classified.stormlevel and player_classified.stormtype components when present.
Dependencies & Tags
inst:AddComponent("locomotor")— used to remove speed multipliers when exiting a storm (accessed viaself.inst.components.locomotor).inst:AddComponent("sandstormwatcher")— invoked when sandstorm level updates (self.inst.components.sandstormwatcher:UpdateSandstormLevel()).inst:AddComponent("moonstormwatcher")— invoked when moonstorm level updates (self.inst.components.moonstormwatcher:UpdateMoonstormLevel()).- World Dependencies:
TheWorld.components.sandstorms— to check active sandstorms and query storm level/zone presence.TheWorld.net.components.moonstorms— to check active moonstorms and query storm level/zone presence.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
stormlevel | number | 0 | Current normalized storm intensity (0 to 1, quantized to 1/7 increments). |
delay | number or nil | nil | Interpolation delay timer for periodic storm level updates. |
currentstorm | string (STORM_TYPES.*) | STORM_TYPES.NONE | The dominant storm type affecting the entity. |
currentstorms | table | {} | Map of storm types to boolean flags indicating active presence (e.g., {[STORM_TYPES.SANDSTORM] = true}). |
laststorm | string (STORM_TYPES.*) | (not initialized) | Tracks the previous storm type for cleanup purposes. |
Main Functions
GetStormLevel(stormtype)
- Description: Returns the current storm intensity level. If a specific
stormtypeis provided, returns the level only if that storm is active; otherwise, returns0. - Parameters:
stormtype(string, optional) — ASTORM_TYPES.*constant (e.g.,STORM_TYPES.SANDSTORM). If omitted or matchesself.currentstorm, returns the globalself.stormlevel.
GetCurrentStorm(inst)
- Description: Determines the dominant storm type affecting the entity by checking both sandstorm and moonstorm subsystems. Asserts the entity cannot be in two storms simultaneously.
- Parameters:
inst(Entity) — The entity instance (typicallyself.inst).
CheckStorms(data)
- Description: Compares the currently tracked storm type with the result of
GetCurrentStorm(). If different, updatescurrentstorm, triggers storm level recalculation, or clearsstormlevelto0if no storm is active. - Parameters:
data(table, optional) — Storm change event data (unused directly in this function but retained for API consistency).
UpdateStorms(data)
- Description: Updates internal tracking of active storms (via
currentstormstable) based on event data. Enables or disables periodic updates and listens forchangeareaevents depending on whether any storms are active. - Parameters:
data(table, optional) — Must containdata.stormtypeanddata.setting(boolean). Updates thecurrentstormsmap accordingly.
UpdateStormLevel()
- Description: Recalculates and sets the current storm level based on the active storm subsystem. Applies movement speed modifiers when entering a storm and removes them on exit. Delegates to
sandstormwatcherormoonstormwatchercomponents for UI updates. - Parameters: None.
OnUpdate(dt)
- Description: Acts as a polling loop for gradual storm level transitions. Decrements the internal
delaytimer; when elapsed, triggersUpdateStormLevel()and resets the delay based on current storm intensity. - Parameters:
dt(number) — Time since last update (delta time).
Events & Listeners
- Listens to:
"ms_stormchanged"(onTheWorld) — Triggersself:UpdateStorms(data)."changearea"(onself.inst) — TriggersOnChangeArea, which callsself:UpdateStormLevel()and adjusts update delay.
- Triggers:
self.inst:StartUpdatingComponent(self)— Enables periodic updates when any storm is active.self.inst:StopUpdatingComponent(self)— Disables periodic updates when no storms are active.self.inst:ListenForEvent("changearea", OnChangeArea)— Registerschangeareahandler during active storm conditions.self.inst:RemoveEventCallback("changearea", OnChangeArea)— Removeschangeareahandler when storm ends.