IInventoryController - jimdroberts/FishMMO GitHub Wiki
Interface for inventory controllers, managing activation and slot swapping logic for a character's inventory. Extends character behaviour and item container functionality.
-
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.
- Implement the IInventoryController interface in your inventory controller class.
- Ensure your class also implements ICharacterBehaviour and IItemContainer.
- Provide logic for activating items and swapping slots as required.
- Integrate with your character and item systems as needed.
// 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;
}
}
- 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.