Item

Item

Base class for all item types.

Items can be picked up, carried, used, thrown, and fired. They do not block movement into a cell. All callbacks are no-ops by default.

Constructor

new Item()

Source:

Methods

getDefiniteNoun(phrase)

Description:
  • Return a phrase with the item name using a definite article (e.g., "the sword").

Source:
Parameters:
Name Type Description
phrase string

template string with {0} placeholder

getIndefiniteNoun(phrase)

Description:
  • Return a phrase with the item name using an indefinite article (e.g., "a sword").

Source:
Parameters:
Name Type Description
phrase string

template string with {0} placeholder

onDeselect()

Description:
  • This item is about to be deselected. Cancel event to prevent deselection.

Source:

onDrop()

Description:
  • This item is about to be dropped. Cancel event to prevent the drop.

Source:

onFire(event) → {Item|null}

Description:
  • The player is firing this item (ranged weapon). Return the ammunition piece to launch, or null if unable to fire. Cancel event to abort firing.

Source:
Parameters:
Name Type Description
event GameEvent
Returns:
Type
Item | null

onHit(event, agentLoc, agent)

Description:
  • This item has struck an agent (thrown or wielded).

Source:
Parameters:
Name Type Description
event GameEvent
agentLoc Cell
agent Agent

onSelect()

Description:
  • This item was selected in the player's inventory.

Source:

onSteppedOn()

Description:
  • An agent has stepped onto the same cell as this item.

Source:

onThrow(event, cell)

Description:
  • The player is about to throw this item. Cancel event to prevent the throw.

Source:
Parameters:
Name Type Description
event GameEvent
cell Cell

player's current cell

onThrowEnd()

Description:
  • This item, having been thrown, has landed at the given cell. Cancel event to make the item disappear instead of landing.

Source:

onUse()

Description:
  • The player used this item without specifying a direction. Cancel event with a message if the item requires a direction.

Source: