Luckitem
Overview
This component manages the luck contribution of an inventory item to its owner entity. It calculates effective luck based on the item's base luck, equipped status, and stack size, then applies it to the owner via the luckuser component when the item is equipped or held as part of the inventory source. It also ensures proper cleanup when the item is unequipped, removed, or ownership changes.
Dependencies & Tags
- Components relied on:
inventoryitem,equippable,luckuser - Tags added: None identified
- Inheritance helpers: Uses
MakeComponentAnInventoryItemSource(self)andRemoveComponentInventoryItemSource(self)for inventory source integration.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil (assigned in constructor) | Reference to the entity this component is attached to. |
luck | number or function | 0 | Base luck value provided by the item when not equipped. |
equippedluck | number or function | 0 | Luck value provided by the item when equipped (overrides luck when equipped). |
Main Functions
UpdateOwnerLuck_Internal(owner)
- Description: Calculates the current effective luck from the item and updates the owner's
luckusercomponent. Uses equipped luck if the item is equipped, otherwise base luck. Multiplies by stack size. If no owner is provided, it determines the grand owner via theinventoryitemcomponent. - Parameters:
owner(optionalEntity): The entity receiving the luck. If omitted, determined automatically.
RemoveOwnerLuck_Internal(owner)
- Description: Removes the item’s luck contribution from the owner’s
luckusercomponent. If no owner is provided, it determines the grand owner via theinventoryitemcomponent. - Parameters:
owner(optionalEntity): The entity from which to remove the luck source. If omitted, determined automatically.
SetLuck(luck)
- Description: Sets the base luck value for the item (used when unequipped).
- Parameters:
luck(numberorfunction): The luck value or a function returning the value.
GetLuck()
- Description: Returns the current base luck value, resolving it through
FunctionOrValueto support dynamic values based on item owner context. - Parameters: None.
SetEquippedLuck(luck)
- Description: Sets the luck value applied when the item is equipped.
- Parameters:
luck(numberorfunction): The equipped luck value or a function returning the value.
GetEquippedLuck()
- Description: Returns the current equipped luck value, resolving it through
FunctionOrValueto support dynamic values based on item owner context. - Parameters: None.
GetDebugString()
- Description: Returns a formatted debug string showing the calculated luck percentages for both base and equipped states (multiplied by 100 for readability).
- Parameters: None.
Events & Listeners
- Listens for
"equipped"→ callsUpdateOwnerLuck_Internal() - Listens for
"unequipped"→ callsRemoveOwnerLuck_Internal() - Listens for
"stacksizechange"→ callsUpdateOwnerLuck_Internal() - Listens for
"updateownerluck"→ callsUpdateOwnerLuck_Internal() - Implements
OnItemSourceRemoved(owner)callback → callsRemoveOwnerLuck_Internal(owner) - Implements
OnItemSourceNewOwner(owner)callback → callsUpdateOwnerLuck_Internal(owner)