Example #1
0
    public void takeItems(CRItemContainer container)
    {
        CRItem[] items = container.GetAllItems();

        foreach (CRItem item in items)
        {
            if (null != item)
            {
                if (!_controller.creature.equipment.MoveItemFromContainer(container, item))
                {
                    if (!_controller.creature.inventory.MoveItemFromContainer(container, item))
                        break;
                    else
                    {
                        NetworkChat.instance.send(_controller.GetComponent<NetworkPlayerInit>().owner, "YOU recieve loot " + item.name + ".", 0);
                    }
                }
                else
                {
                    NetworkChat.instance.send(_controller.GetComponent<NetworkPlayerInit>().owner, "YOU recieve loot " + item.name + ".", 0);
                }

            }
        }
    }
 void Awake()
 {
     _container = GetComponent<CRItemContainer>();
 }
Example #3
0
 void Awake()
 {
     cgui = CGUI.Instance;
     cgui.RegisterContainer(this);
     m_Container = GetComponent<CRItemContainer>();
 }
Example #4
0
    void SearchForContainer()
    {
        CRItemContainer parentContainer = CRUtility.GetComponentInParent<CRItemContainer>(transform);

        if (null != parentContainer)
        {
            if (container != parentContainer)
            {
                if (parentContainer.AddItem(this))
                {
                    container = parentContainer;
                }
                else
                {
                    container = null;
                }
            }
        }
        else
        {
            if (null != container)
            {
                container.RemoveItem(this);
            }
        }
    }
Example #5
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 #6
0
    /*********************** SWAP ITEMS FROM CONTAINER ***********************/
    public virtual bool SwapItemFromContainer(CRItemContainer srcContainer, CRItem srcItem, int dst)
    {
        #region ERROR CHECKING
        //slot is occupied, swap should be used instead
        if (!IsSlotOccupied(dst))
        {
            Debug.LogWarning(gameObject.name + ":: Failed to swap item: Destination slot is empty, use MoveItemFromContainer(...) instead");
            return false;
        }

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

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

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

        CRItem dstItem = GetItem(dst);

        if (dstItem == null)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to swap item: Destination item is null");
            return false;
        }

        int src = srcContainer.GetIndex(srcItem);
        #endregion

        //try to remove the dst item from its slot
        if (!RemoveItem(dst))
        {
            return false;
        }

        //try to remove the src item from its slot
        if (!srcContainer.RemoveItem(src))
        {
            //failed
            //put the dst item back in its correct slot
            AddItem(dstItem,dst);
            return false;
        }

        //put the item removed from the src container into this container
        if (!AddItem(srcItem, dst))
        {
            //failed
            //put the dst item back in its correct slot
            AddItem(dstItem, dst);
            //put the src item back in its correct slot
            srcContainer.AddItem(srcItem, src);
            return false;
        }

        //put the item removed from this container into the src container
        if (!srcContainer.AddItem(dstItem, src))
        {
            //failed
            //remove the item added to this container
            RemoveItem(srcItem);
            //put the dst item back in its correct slot
            AddItem(dstItem, dst);
            //put the src item back in its correct slot
            srcContainer.AddItem(srcItem, src);
            return false;
        }

        return true;
    }
Example #7
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;
        }
    }
Example #8
0
    /*********************** MOVE ITEMS FROM CONTAINER ***********************/
    public virtual bool MoveItemFromContainer(CRItemContainer srcContainer, CRItem item)
    {
        #region ERROR_CHECKING
        int src = srcContainer.GetIndex(item);
        if (src == -1)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to move item: Source item not found");
            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))
        {
            srcContainer.RemoveItem(src);

            item.container = this;

            return true;
        }
        else
        {
            return false;
        }
    }