Cursable
Overview
The Cursable component allows an entity to be affected by various curses, typically originating from cursed items. It manages the application, removal, and current stack count of curses on the entity, and triggers specific curse-related behaviors, such as those associated with "MONKEY" curses, by interacting with the curse_monkey_util module. It also includes logic for handling cursed items within the entity's inventory and ensuring proper item management when curses are applied or removed.
Dependencies & Tags
This component relies on the following other components and utility modules:
healthcomponent (checked for entity's life status)inventorycomponent (heavily used for item management, finding, consuming, and dropping items)debuffablecomponent (checked for "spawnprotectionbuff" debuff)curseditemcomponent (present on items that apply curses)stackablecomponent (present on items that can be stacked, used to determine curse quantity)inventoryitemcomponent (present on items handled by inventory)curse_monkey_utilmodule (for specific "MONKEY" curse effects)
Tags involved in its logic:
applied_curse(added to items upon applying a curse)ghost(checked on the owning entity)monkey_token(searched for on items when removing "MONKEY" curses)nosteal(checked on items when determining inventory space or items to drop)INLIMBO(checked on items duringForceOntoOwnerto determine position)
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | N/A | A reference to the entity this component is attached to. |
curses | table | {} | A table mapping curse names (string) to their current stack count (number) on the entity. |
Main Functions
ApplyCurse(item, curse)
- Description: Applies a curse to the entity. If an
itemis provided, the curse type and stack size are extracted from the item'scurseditemandstackablecomponents, and the item is tagged withapplied_curse. The curse count for the specified type is incremented. Special handling exists for "MONKEY" curses, invokingcurse_monkey.docurse. - Parameters:
item: (Entity, optional) The cursed item initiating the curse. If provided, itscurseditemcomponent determines the curse type.curse: (string, optional) The name of the curse to apply. This parameter is used ifitemis not provided.
RemoveCurse(curse, numofitems, dropitems)
- Description: Removes a specified quantity of a curse from the entity. For "MONKEY" curses, it attempts to find and remove
monkey_tokenitems from the entity's inventory, optionally dropping them into the world. The curse count for the specified type is decremented, and special handling exists for "MONKEY" curses, invokingcurse_monkey.uncurse. - Parameters:
curse: (string) The name of the curse to remove (e.g., "MONKEY").numofitems: (number) The number of curse stacks or contributing items to remove.dropitems: (boolean) Iftrue, and the curse is "MONKEY", any removedmonkey_tokenitems will be spawned into the world.
IsCursable(item)
- Description: Checks if the entity can currently receive a cursed item or curse. It verifies the entity is not a ghost, doesn't have "spawnprotectionbuff", and has available inventory space (either an empty slot or a stackable slot for the given
item). - Parameters:
item: (Entity) The item that is attempting to be cursed onto the entity.
- Returns:
booleantrueif the entity can receive the curse/item;falseif it cannot (e.g., has spawn protection);nilif the entity is a "ghost".
ForceOntoOwner(item)
- Description: Forces a given item into the entity's inventory, ensuring there is space by first attempting to stack the item, and if inventory is full and stacking is not possible, dropping another non-
nostealitem from the inventory. - Parameters:
item: (Entity) The item to be placed into the entity's inventory.
Died()
- Description: This function is intended to be called when the entity dies. It iterates through all cursed items in the entity's inventory and removes their corresponding curses, dropping the items into the world.
- Parameters: None.
OnSave()
- Description: A placeholder function for saving the component's state. Currently, it returns an empty table, indicating that no component-specific data (like active curses) is saved. The commented-out code suggests
self.cursescould be saved in the future. - Parameters: None.
- Returns:
tableAn empty table.
OnLoad(data)
- Description: A placeholder function for loading the component's state. It currently does nothing. The commented-out code suggests it could load saved curses and re-apply them.
- Parameters:
data: (table) The saved data for this component.