Item - jimdroberts/FishMMO GitHub Wiki
Represents an item instance in the game, including stackable, equippable, and generated properties. Handles initialization, attribute management, and tooltip generation.
-
public ItemGenerator Generator
The item generator responsible for random attributes and generation logic.
-
public ItemEquippable Equippable
The equippable component for this item, if applicable.
-
public ItemStackable Stackable
The stackable component for this item, if applicable.
-
public event Action OnDestroy
Event triggered when the item is destroyed.
-
public BaseItemTemplate Template { get; private set; }
The item template defining base properties and attributes.
-
public long ID { get; set; }
The unique ID for this item instance.
-
public int Slot { get; set; }
The slot index this item is currently assigned to.
-
public bool IsGenerated { get; }
Returns true if the item has a generator (is randomly generated).
-
public bool IsEquippable { get; }
Returns true if the item is equippable.
-
public bool IsStackable { get; }
Returns true if the item is stackable.
-
public Item(BaseItemTemplate template, uint amount)
Constructs an item from a template and amount, initializing stackable logic if needed. Parameters: - BaseItemTemplate template: The item template. - uint amount: The stack amount.*
-
public Item(long id, int seed, BaseItemTemplate template, uint amount)
Constructs an item from an ID, seed, template, and amount, initializing all components. Parameters: - long id: The item ID. - int seed: The random seed for generation. - BaseItemTemplate template: The item template. - uint amount: The stack amount.*
-
public Item(long id, int seed, int templateID, uint amount)
Constructs an item from an ID, seed, template ID, and amount, initializing all components. Parameters: - long id: The item ID. - int seed: The random seed for generation. - int templateID: The template ID. - uint amount: The stack amount.*
-
public void Initialize(long id, uint amount, int seed)
Initializes the item, setting up stackable, equippable, and generator components as needed. Handles seed logic for random generation and event wiring for attribute changes. Parameters: - long id: The item ID. - uint amount: The stack amount. - int seed: The random seed for generation.*
-
public void Destroy()
Destroys the item, cleaning up generator, equippable, and stackable components and detaching events.
-
public bool IsMatch(Item other)
Determines if this item matches another item, comparing template ID and generation seed. Used for stacking and item comparison logic. Parameters: - Item other: The other item to compare.* Returns: - bool: True if the items match, false otherwise.*
-
public string Tooltip()
Returns the formatted tooltip string for this item, including ID, slot, template tooltip, and generator info. Returns: - string: The formatted tooltip string.*
-
public void ItemGenerator_OnSetAttribute(ItemAttribute attribute, int oldValue, int newValue)
Event handler called when an item's attribute is set by the generator. Updates character attributes or resources accordingly. Parameters: - ItemAttribute attribute: The item attribute being changed. - int oldValue: The previous value of the attribute. - int newValue: The new value of the attribute.*
-
public void ItemEquippable_OnEquip(ICharacter character)
Event handler called when the item is equipped by a character. Applies generated attributes. Parameters: - ICharacter character: The character equipping the item.*
-
public void ItemEquippable_OnUnequip(ICharacter character)
Event handler called when the item is unequipped by a character. Removes generated attributes. Parameters: - ICharacter character: The character unequipping the item.*
- Create an Item instance using a BaseItemTemplate and specify the stack amount if needed.
- Use the Initialize method to set up stackable, equippable, and generator components as required.
- Use the Tooltip method to display item information in the UI.
- Handle OnDestroy events for cleanup when the item is removed.
// Example 1: Creating a new item instance
BaseItemTemplate template = ...;
Item item = new Item(template, 5); // Create a stack of 5 items
// Example 2: Initializing an item with a generator and equippable logic
item.Initialize(12345, 1, 6789); // id, amount, seed
// Example 3: Displaying item tooltip
string tooltip = item.Tooltip();
- Always initialize items with the correct template and amount for proper behavior.
- Use IsMatch for safe stacking and comparison logic.
- Clean up event handlers and components in Destroy to prevent memory leaks.
- Use Tooltip for consistent and informative UI display.
- Document custom item logic and event handling for maintainability.