Example #1
0
    public virtual bool SwapItemFromContainer(CRItemContainer srcContainer, int src, int dst)
    {
        #region ERROR_CHECKING
        if (src >= srcContainer.size || src < 0)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to swap item: Source item is null");
            return false;
        }
        CRItem srcItem = srcContainer.GetItem(src);
        #endregion

        return SwapItemFromContainer(srcContainer, srcItem, dst);
    }
Example #2
0
    public virtual bool MoveItemFromContainer(CRItemContainer srcContainer, int src, int dst)
    {
        #region ERROR_CHECKING
        //slot is occupied, swap should be used instead
        if (IsSlotOccupied(dst))
        {
            Debug.LogWarning(gameObject.name + ":: Failed to move item: Destination slot is occupied, use SwapItemFromContainer(...) instead");
            return false;
        }

        CRItem item = srcContainer.GetItem(src);

        if (item == null)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to move item: Source slot is empty");
            return false;
        }

        if (dst >= _size || dst < 0)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to move item: Destination index is out of bounds");
            return false;
        }

        if (ContainsItem(item))
        {
            Debug.LogWarning(gameObject.name + ":: Failed to move item: Destination container already contains that item");
            return false;
        }
        #endregion

        if (AddItem(item, dst))
        {
            srcContainer.RemoveItem(src);
            return true;
        }
        else
        {
            return false;
        }
    }