Pocketwatch
Overview
The PocketWatch component serves as a flexible spell-casting gatekeeper. It tracks whether an entity is in an inactive state (via the inactive property) and conditionally allows spell casting—either by default (if CanCastFn/DoCastSpell functions are assigned externally) or explicitly denied when inactive.
Dependencies & Tags
- Tags Added/Removed:
"pocketwatch_inactive"(added wheninactive = true, removed on component removal or wheninactive = false) - Component Dependencies: None declared. Requires only that the entity (
inst) supports tag management (AddOrRemoveTag,RemoveTag).
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil (assigned in constructor) | Reference to the owning entity. |
inactive | boolean | true | Controls whether the pocketwatch is active. When true, casting is blocked unless CanCastFn/DoCastSpell explicitly allow it. |
CanCastFn | function | nil | Optional external callback (set externally) that overrides the default cast check. |
DoCastSpell | function | nil | Optional external callback (set externally) containing the actual spell logic. |
Note:
CanCastFnandDoCastSpellare not initialized in the constructor but are expected to be assigned externally (e.g., by the modder or higher-level logic) to enable full spell functionality.
Main Functions
CanCast(doer, target, pos)
- Description: Determines whether the entity is allowed to cast a spell. Returns
trueonly ifinactive = trueand either no customCanCastFnis set, orCanCastFnreturnstrue. - Parameters:
doer: The entity attempting to cast.target: The target entity (if any).pos: The target position (if any).
CastSpell(doer, target, pos)
- Description: Executes the spell logic if
inactive = trueand aDoCastSpellfunction has been assigned. Returnsfalseif conditions aren’t met; otherwise returns the result ofDoCastSpell. - Parameters:
doer: The entity attempting to cast.target: The target entity (if any).pos: The target position (if any).
Events & Listeners
- Listens to the
"inactive"event: Triggers theoninactivehandler to add/remove the"pocketwatch_inactive"tag on the entity when the"inactive"event is pushed.