Skip to main content

Magiciantool

Overview

The Magiciantool component tracks ownership and usage of a magical tool by a Magician character. It maintains a reference to the current user, applies/removes the "magiciantool" tag, and supports optional callback functions triggered when usage starts or stops.

Dependencies & Tags

  • Adds the "magiciantool" tag to the entity during construction.
  • Removes the "magiciantool" tag on entity/component removal.
  • Interacts with the "magician" component (if present on the user) during usage lifecycle events.
  • No direct AddComponent calls beyond tagging.

Properties

PropertyTypeDefault ValueDescription
instEntityReference to the entity this component is attached to.
userEntity?nilReference to the entity currently using the tool (typically a Magician).
onstartusingfnfunction?nilOptional callback invoked when usage starts; signature: fn(tool_entity, user_entity).
onstopusingfnfunction?nilOptional callback invoked when usage stops; signature: fn(tool_entity, user_entity).

Main Functions

SetOnStartUsingFn(fn)

  • Description: Registers a custom callback to execute when the tool begins being used.
  • Parameters:
    • fn (function): A function that accepts two arguments: the tool entity and the user entity.

SetOnStopUsingFn(fn)

  • Description: Registers a custom callback to execute when the tool stops being used.
  • Parameters:
    • fn (function): A function that accepts two arguments: the tool entity and the user entity.

OnStartUsing(doer)

  • Description: Records the user as the active tool user and invokes the onstartusingfn callback, if set. No-op if already in use.
  • Parameters:
    • doer (Entity): The entity (typically a Magician) initiating tool usage.

OnStopUsing(doer)

  • Description: Clears the active user (if matches doer) and invokes the onstopusingfn callback, if set.
  • Parameters:
    • doer (Entity): The entity (typically a Magician) ending tool usage.

StopUsing()

  • Description: Handles forced cessation of tool usage. If the tool is in use by a Magician, it delegates to the Magician’s StopUsing() method; otherwise, triggers internal cleanup via OnStopUsing.
  • Parameters: None.

Events & Listeners

None identified.