IEquipmentController - jimdroberts/FishMMO GitHub Wiki

Description

Interface for equipment controllers, managing equip/unequip logic and activation of equipment slots. Extends character behaviour and item container functionality.


API Access

Methods

  • void Activate(int index)

    Activates the item in the specified equipment slot, typically triggering its use effect. Parameters: - int index: The equipment slot index to activate.

  • bool Equip(Item item, int inventoryIndex, IItemContainer container, ItemSlot toSlot)

    Equips the specified item into the given equipment slot, handling swaps and unequips as needed. Parameters: - Item item: The item to equip. - int inventoryIndex: The index in the source inventory. - IItemContainer container: The source item container (e.g., inventory or bank). - ItemSlot toSlot: The equipment slot to equip the item into. Returns: - bool: True if the item was successfully equipped, false otherwise.

  • bool Unequip(IItemContainer container, byte slot, out List modifiedItems)

    Unequips the item from the specified slot and adds it to the given container (e.g., inventory or bank). Parameters: - IItemContainer container: The destination item container. - byte slot: The equipment slot to unequip from. - out List modifiedItems: The list of items modified during the operation. Returns: - bool: True if the item was successfully unequipped and added, false otherwise.


Basic Usage

Setup

  1. Implement the IEquipmentController interface in your equipment controller class.
  2. Ensure your class also implements ICharacterBehaviour and IItemContainer.
  3. Provide logic for activating, equipping, and unequipping items as required.
  4. Integrate with your character and item systems as needed.

Example

// Example 1: Implementing IEquipmentController in a custom class
public class MyEquipmentController : IEquipmentController {
    public void Activate(int index) {
        // Custom activation logic
    }
    public bool Equip(Item item, int inventoryIndex, IItemContainer container, ItemSlot toSlot) {
        // Custom equip logic
        return true;
    }
    public bool Unequip(IItemContainer container, byte slot, out List<Item> modifiedItems) {
        // Custom unequip logic
        modifiedItems = null;
        return true;
    }
}

Best Practices

  • Always validate slot compatibility and item type before equipping or unequipping.
  • Ensure null checks for all parameters to prevent runtime errors.
  • Document custom implementations for clarity and maintainability.
  • Integrate with network or event systems as needed for multiplayer scenarios.
⚠️ **GitHub.com Fallback** ⚠️