IInventoryController - jimdroberts/FishMMO GitHub Wiki

Description

Interface for inventory controllers, managing activation and slot swapping logic for a character's inventory. Extends character behaviour and item container functionality.


API Access

Methods

  • void Activate(int index)

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

  • bool CanSwapItemSlots(int from, int to, InventoryType fromInventory)

    Determines if two item slots can be swapped, preventing invalid swaps (e.g., same slot). Parameters: - int from: The source slot index. - int to: The destination slot index. - InventoryType fromInventory: The inventory type of the source slot. Returns: - bool: True if the slots can be swapped, false otherwise.


Basic Usage

Setup

  1. Implement the IInventoryController interface in your inventory controller class.
  2. Ensure your class also implements ICharacterBehaviour and IItemContainer.
  3. Provide logic for activating items and swapping slots as required.
  4. Integrate with your character and item systems as needed.

Example

// Example 1: Implementing IInventoryController in a custom class
public class MyInventoryController : IInventoryController {
    public void Activate(int index) {
        // Custom activation logic
    }
    public bool CanSwapItemSlots(int from, int to, InventoryType fromInventory) {
        // Custom slot swap logic
        return from != to;
    }
}

Best Practices

  • Always validate slot indices and inventory types before swapping.
  • 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** ⚠️