Table of Contents

Class ItemContainer

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Abstract base class for item containers, providing slot and item management for inventories, equipment, banks, etc. Implements IItemContainer and extends CharacterBehaviour for character association.

public abstract class ItemContainer : CharacterBehaviour, ICharacterBehaviour, IItemContainer
Inheritance
Object
Component
Behaviour
MonoBehaviour
NetworkBehaviour
ItemContainer
Implements
Derived
Inherited Members
NetworkBehaviour.IsSpawned
NetworkBehaviour.ComponentIndex
NetworkBehaviour.NetworkObject
NetworkBehaviour.MAXIMUM_NETWORKBEHAVIOURS
NetworkBehaviour.UNSET_NETWORKBEHAVIOUR_ID
NetworkBehaviour.ToString()
NetworkBehaviour.Reset()
NetworkBehaviour.OnValidate()
NetworkBehaviour.IsBehaviourReconciling
NetworkBehaviour.ClearReplicateCache()
NetworkBehaviour.CreateReconcile()
NetworkBehaviour.Reconcile_Reader<T>(PooledReader, ref T)
NetworkBehaviour.OnStartServerCalled
NetworkBehaviour.OnStartClientCalled
NetworkBehaviour.WritePayload(NetworkConnection, Writer)
NetworkBehaviour.ReadPayload(NetworkConnection, Reader)
NetworkBehaviour.OnStartNetwork()
NetworkBehaviour.OnStopNetwork()
NetworkBehaviour.OnStartServer()
NetworkBehaviour.OnStopServer()
NetworkBehaviour.OnOwnershipServer(NetworkConnection)
NetworkBehaviour.OnSpawnServer(NetworkConnection)
NetworkBehaviour.OnDespawnServer(NetworkConnection)
NetworkBehaviour.OnStartClient()
NetworkBehaviour.OnStopClient()
NetworkBehaviour.OnOwnershipClient(NetworkConnection)
NetworkBehaviour.ClearBuffedRpcs()
NetworkBehaviour.ExcludeOwnerFromUnbufferedObserversRpcs
NetworkBehaviour.IsClientOnly
NetworkBehaviour.IsServerOnly
NetworkBehaviour.IsHost
NetworkBehaviour.IsClient
NetworkBehaviour.IsServer
NetworkBehaviour.IsDeinitializing
NetworkBehaviour.NetworkManager
NetworkBehaviour.ServerManager
NetworkBehaviour.ClientManager
NetworkBehaviour.ObserverManager
NetworkBehaviour.TransportManager
NetworkBehaviour.TimeManager
NetworkBehaviour.SceneManager
NetworkBehaviour.PredictionManager
NetworkBehaviour.RollbackManager
NetworkBehaviour.NetworkObserver
NetworkBehaviour.IsClientInitialized
NetworkBehaviour.IsClientStarted
NetworkBehaviour.IsClientOnlyInitialized
NetworkBehaviour.IsClientOnlyStarted
NetworkBehaviour.IsServerInitialized
NetworkBehaviour.IsServerStarted
NetworkBehaviour.IsServerOnlyInitialized
NetworkBehaviour.IsServerOnlyStarted
NetworkBehaviour.IsHostInitialized
NetworkBehaviour.IsHostStarted
NetworkBehaviour.IsOffline
NetworkBehaviour.IsNetworked
NetworkBehaviour.GetIsNetworked()
NetworkBehaviour.IsManagerReconciling
NetworkBehaviour.Observers
NetworkBehaviour.IsOwner
NetworkBehaviour.IsController
NetworkBehaviour.HasAuthority
NetworkBehaviour.Owner
NetworkBehaviour.OwnerId
NetworkBehaviour.ObjectId
NetworkBehaviour.LocalConnection
NetworkBehaviour.OwnerMatches(NetworkConnection)
NetworkBehaviour.Despawn(GameObject, DespawnType?)
NetworkBehaviour.Despawn(NetworkObject, DespawnType?)
NetworkBehaviour.Despawn(DespawnType?)
NetworkBehaviour.Spawn(GameObject, NetworkConnection, Scene)
NetworkBehaviour.Spawn(NetworkObject, NetworkConnection, Scene)
NetworkBehaviour.RemoveOwnership()
NetworkBehaviour.GiveOwnership(NetworkConnection)
NetworkBehaviour.GetInstance<T>()
NetworkBehaviour.TryRegisterInstance<T>(T)
NetworkBehaviour.UnregisterInstance<T>()
NetworkBehaviour.CanLog(LoggingType)
MonoBehaviour.IsInvoking()
MonoBehaviour.CancelInvoke()
MonoBehaviour.StopCoroutine(Coroutine)
MonoBehaviour.StopAllCoroutines()
MonoBehaviour.destroyCancellationToken
MonoBehaviour.useGUILayout
MonoBehaviour.didStart
MonoBehaviour.didAwake
MonoBehaviour.runInEditMode
Behaviour.enabled
Behaviour.isActiveAndEnabled
Component.GetComponent<T>()
Component.TryGetComponent<T>(out T)
Component.GetComponentInChildren<T>()
Component.GetComponentsInChildren<T>()
Component.GetComponentInParent<T>()
Component.GetComponentsInParent<T>()
Component.GetComponents<T>()
Component.GetComponentIndex()
Component.CompareTag(TagHandle)
Component.transform
Component.transformHandle
Component.gameObject
Component.tag
Object.GetEntityId()
Object.GetInstanceID()
Object.GetHashCode()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion, Transform)
Object.Instantiate(Object)
Object.Instantiate(Object, Scene)
Object.Instantiate<T>(T, InstantiateParameters)
Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.Instantiate(Object, Transform)
Object.Instantiate<T>(T)
Object.Instantiate<T>(T, Vector3, Quaternion)
Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
Object.Instantiate<T>(T, Transform)
Object.Destroy(Object)
Object.DestroyImmediate(Object)
Object.DontDestroyOnLoad(Object)
Object.DestroyObject(Object)
Object.FindObjectsOfType<T>()
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindObjectOfType<T>()
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Object.FindObjectsByType<T>()
Object.FindObjectsByType<T>(FindObjectsInactive)
Object.name
Object.hideFlags

Properties

Items

Gets the list of items contained in this container.

public List<Item> Items { get; }

Property Value

List<Item>

Methods

AddSlots(List<Item>, int)

Adds slots to the container, optionally initializing with a list of items.

public void AddSlots(List<Item> items, int amount)

Parameters

items List<Item>

The initial items to add (can be null).

amount int

The number of slots to add.

CanAddItem(Item)

Determines if the specified item can be added to the container, considering stack sizes and slot availability.

public bool CanAddItem(Item item)

Parameters

item Item

The item to check.

Returns

bool

True if the item can be added, false otherwise.

CanManipulate()

Determines if the container can be manipulated (e.g., items moved or swapped). Checks if the character is alive and the items list is not empty.

public virtual bool CanManipulate()

Returns

bool

True if manipulation is allowed, false otherwise.

Clear()

Clears all items from the container, destroying each item and setting slots to null.

public void Clear()

ContainsItem(BaseItemTemplate)

Checks if the container contains an item with the specified template.

public bool ContainsItem(BaseItemTemplate itemTemplate)

Parameters

itemTemplate BaseItemTemplate

The item template to search for.

Returns

bool

True if the item is found, false otherwise.

FilledSlots()

Gets the number of filled slots in the container.

public int FilledSlots()

Returns

int

The number of filled slots.

FreeSlots()

Gets the number of free slots in the container.

public int FreeSlots()

Returns

int

The number of free slots.

GetItemCount(BaseItemTemplate)

Gets the count of items matching the specified template, including stack sizes.

public int GetItemCount(BaseItemTemplate itemTemplate)

Parameters

itemTemplate BaseItemTemplate

The item template to count.

Returns

int

The number of items matching the template.

HasFreeSlot()

Checks if the container has at least one free slot.

public bool HasFreeSlot()

Returns

bool

True if a free slot exists, false otherwise.

IsSlotEmpty(int)

Checks if the specified slot is empty (contains no item).

public bool IsSlotEmpty(int slot)

Parameters

slot int

The slot index to check.

Returns

bool

True if the slot is empty, false otherwise.

IsSlotLocked(int)

Returns true if the specified slot is currently locked. Locked slots cannot be swapped, removed, or transferred until unlocked.

public bool IsSlotLocked(int slot)

Parameters

slot int

The slot index to check.

Returns

bool

True if the slot is locked, false otherwise.

IsValidSlot(int)

Checks if the item slot exists (is within valid range).

public bool IsValidSlot(int slot)

Parameters

slot int

The slot index to check.

Returns

bool

True if the slot is valid, false otherwise.

LockSlot(int)

Locks the specified slot, preventing it from being swapped, removed, or transferred.

public void LockSlot(int slot)

Parameters

slot int

The slot index to lock.

OnDestroying()

Called when the container is being destroyed. Clears event handlers and locks.

public override void OnDestroying()

RemoveItem(int)

Removes an item from the specified slot and returns it. Returns null if the slot was empty. Fails if the slot is locked.

public Item RemoveItem(int slot)

Parameters

slot int

The slot index to remove the item from.

Returns

Item

The item that was removed, or null if no item was present.

SetItemSlot(Item, int)

Sets the item in the specified slot. Previous item will be lost if not referenced elsewhere.

public bool SetItemSlot(Item item, int slot)

Parameters

item Item

The item to set.

slot int

The slot index to set the item in.

Returns

bool

True if the item was successfully set, false otherwise.

Remarks

Refuses a locked slot. This is the write primitive every other mutation funnels through, and it was the one that did not check the lock — so a cross-container move could overwrite a slot whose item was mid-consumption, and the activation would then complete against an item that had already gone somewhere else. RemoveItem and SwapItemSlots check the lock themselves before calling in here, so this guard is redundant for them by design.

Callers MUST check the return value. It is a genuine refusal, not a formality.

SwapItemSlots(int, int)

Swaps items between two slots.

public bool SwapItemSlots(int from, int to)

Parameters

from int

The source slot index.

to int

The destination slot index.

Returns

bool

True if the swap was successful, false otherwise.

SwapItemSlots(int, int, out Item, out Item)

Swaps items between two slots and returns the items that were swapped. Fails if either slot is locked.

public bool SwapItemSlots(int from, int to, out Item fromItem, out Item toItem)

Parameters

from int

The source slot index.

to int

The destination slot index.

fromItem Item

The item originally in the source slot.

toItem Item

The item originally in the destination slot.

Returns

bool

True if the swap was successful, false otherwise.

TryAddItem(Item, out List<Item>)

Attempts to add an item to the container. Returns true if the entire stack size of the item has been successfully added. All modified items are returned. Handles stacking logic and slot assignment.

public bool TryAddItem(Item item, out List<Item> modifiedItems)

Parameters

item Item

The item to add.

modifiedItems List<Item>

The list of items modified during the operation.

Returns

bool

True if the item was successfully added, false otherwise.

TryGetItem(int, out Item)

Attempts to get the item in the specified slot. Returns false if the item doesn't exist.

public bool TryGetItem(int slot, out Item item)

Parameters

slot int

The slot index to retrieve.

item Item

The item found in the slot, or null if not found.

Returns

bool

True if an item was found, false otherwise.

UnlockSlot(int)

Unlocks the specified slot, allowing normal manipulation again.

public void UnlockSlot(int slot)

Parameters

slot int

The slot index to unlock.

Events

OnSlotLockChanged

Event triggered when a slot's lock state changes. Parameters: container, slot index, isLocked.

public event Action<IItemContainer, int, bool> OnSlotLockChanged

Event Type

Action<IItemContainer, int, bool>

OnSlotUpdated

Event triggered when an item slot is updated (item added, removed, or changed).

public event Action<IItemContainer, Item, int> OnSlotUpdated

Event Type

Action<IItemContainer, Item, int>