示例#1
0
    /*********************** ADD ITEMS ***********************/
    public virtual bool AddItem(CRItem item)
    {
        #region ERROR_CHECKING
        if (item == null)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to add item: Item is NULL");
            return false;
        }

        if (ContainsItem(item))
        {
            Debug.LogWarning(gameObject.name + ":: Failed to add item: Item already exists in the container");
            return false;
        }

        int src = GetOpenSlot();

        if (src == -1)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to add item: Container is full");
            return false;
        }
        #endregion

        _items[src] = item;
        _count++;

        item.transform.parent = transform;
        item.transform.localPosition = Vector3.zero;

        item.container = this;
        item.index = src;

        return true;
    }
示例#2
0
    /// <summary>
    /// Checks if the item inherits from CREquipableItem
    /// Checks if the slot is open
    /// Checks the armor bitmask
    /// Checks the weapon bitmask
    /// </summary>
    public bool CanEquip(CRItem item)
    {
        if (!(item is CREquipableItem) || !((CREquipableItem)item).equipable)
        {
            if (item.name != "Hand")
                Debug.LogWarning("That item is not equipable!");

            return false;
        }

        if (item is CRArmorItem)
        {
            CRArmorItem armor = (CRArmorItem)item;

            if ((armorBitmask & (int)armor.armorType) == 0 )
            {
                Debug.LogWarning ("Cannot equip that armor type!");
                return false;
            }
        }

        if (item is CRWeaponItem)
        {
            CRWeaponItem weapon = (CRWeaponItem)item;

            if ((weaponBitmask & (int)weapon.weaponType) == 0 )
            {
                Debug.LogWarning ("Cannot equip that weapon type!");
                return false;
            }
        }

        return true;
    }
示例#3
0
    public override bool AddItem(CRItem item)
    {
        if (!CanEquip(item))
        {
            return false;
        }

        if (base.AddItem(item, (int)((CREquipableItem)item).slot))
        {
            ((CREquipableItem)item).OnEquip(this);
            return true;
        }

        return false;
    }
示例#4
0
    public virtual bool AddItem(CRItem item, int src)
    {
        #region ERROR_CHECKING
        if (item == null)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to add item: Item is NULL");
            return false;
        }

        if (ContainsItem(item))
        {
            //todo check if item is stackable
            Debug.LogWarning(gameObject.name + ":: Failed to add item: Item already exists in the container");
            return false;
        }

        if (IsFull())
        {
            Debug.LogWarning(gameObject.name + ":: Failed to add item: Container is full");
            return false;
        }

        //this method checks bounds
        if (IsSlotOccupied(src))
        {
            Debug.LogWarning(gameObject.name + ":: Failed to add item: Slot is occupied");
            return false;
        }
        #endregion

        _items[src] = item;
        _count++;

        item.transform.parent = transform;
        item.transform.localPosition = Vector3.zero;

        item.container = this;
        item.index = src;

        return true;
    }
示例#5
0
    public override bool AddItem(CRItem item, int dst)
    {
        if (!CanEquip(item))
        {
            return false;
        }

        if (!ItemFitsInSlot((CREquipableItem)item, dst))
        {
            return false;
        }

        if (base.AddItem(item, dst))
        {
            ((CREquipableItem)item).OnEquip(this);

            return true;
        }

        return false;
    }
示例#6
0
    /*********************** SWAP ITEMS ***********************/
    public virtual bool SwapItem(CRItem srcItem, CRItem dstItem)
    {
        #region ERROR_CHECKING
        int src = GetIndex(srcItem);

        if (src == -1)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to swap item: Source item not found");
            return false;
        }

        int dst = GetIndex(dstItem);

        if (dst == -1)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to swap item: Destination item not found");
            return false;
        }
        #endregion

        _items[dst] = srcItem;
        _items[src] = dstItem;

        srcItem.index = dst;
        srcItem.container = this;

        dstItem.index = src;
        dstItem.container = this;

        return true;
    }
示例#7
0
 public override bool SwapItem(CRItem src, CRItem dst)
 {
     Debug.LogWarning("Equipment SwapItem(...) not yet implemented");
     return false;
 }
示例#8
0
    public override bool RemoveItem(CRItem item)
    {
        if (base.RemoveItem(item))
        {
            ((CREquipableItem)item).OnUnequip(this);
            return true;
        }

        return false;
    }
示例#9
0
 public override bool MoveItem(CRItem item, int dst)
 {
     Debug.LogWarning("Equipment MoveItem(...) not yet implemented");
     return false;
 }
示例#10
0
    private void loadWeapon(ref CRArm arm, CRItem item)
    {
        // todo make sure this weapon is really a weapon and not just some equippable item

        CRWeaponItem weapon = null;

        if (null != item && typeof(CRWeaponItem) == item.GetType())
            weapon = (CRWeaponItem)item;

        if (null == arm)
        {
            arm = new CRArm(weapon);
        }
        else if (arm.weapon != weapon)
        {
            arm.setWeapon(weapon);
        }

        arm.updateSpeed(1.0f + _controller.offence.haste(_controller.creature.level) * 0.01f);
    }
示例#11
0
 public GUIItemSlot(Rect _rect, CRItem _item, int _index)
 {
     m_Rect  = _rect;
     m_Item  = _item;
     m_Index = _index;
 }
示例#12
0
    public int GetIndex(CRItem item)
    {
        if (item == null)
            return -1;

        for (int i=0; i<_size; i++)
        {
            if (_items[i] == item)
                return i;
        }
        return -1;
    }
示例#13
0
    /*********************** DEFAULTS ***********************/
    public virtual bool SetDefault(CRItem item, int src)
    {
        #region ERROR_CHECKING
        if (item == null)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to set default item: Item is NULL");
            return false;
        }
        #endregion

        _defaults.Add(src, item);

        return true;
    }
示例#14
0
    public void Resize(int size)
    {
        CRItem[] buffer = new CRItem[size];

        _count = 0;

        for (int i=_size; i<_size; i++)
        {
            if (i >= size)
            {
                if (null != _items[i])
                {
                    Debug.LogWarning(gameObject.name + ":: Inventory is shrinking: '" +_items[i].itemName + "' is being destroyed");
                }
            }
            else
            {
                if (null != _items[i])
                {
                    _count++;
                    buffer[i] = _items[i];
                }
            }
        }

        _items = buffer;
        _size = size;
    }
示例#15
0
    /*********************** REMOVE ITEMS ***********************/
    public virtual bool RemoveItem(CRItem item)
    {
        #region ERROR_CHECKING
        int src = GetIndex(item);

        if (src == -1)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to remove item: Item not found");
            return false;
        }
        #endregion

        _items[src].container = null;
        _items[src].index = -1;

        _items[src] = null;
        _count--;

        return true;
    }
示例#16
0
    /*********************** MOVE ITEMS ***********************/
    public virtual bool MoveItem(CRItem item, 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 SwapItem(...) instead");
            return false;
        }

        int src = GetIndex(item);
        if (src == -1)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to move item: Item not found");
            return false;
        }

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

        _items[src] = null;
        _items[dst] = item;

        item.container = this;
        item.index = dst;

        return true;
    }
示例#17
0
    public virtual bool MoveItemFromContainer(CRItemContainer srcContainer, CRItem item, 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;
        }

        int src = srcContainer.GetIndex(item);
        if (src == -1)
        {
            Debug.LogWarning(gameObject.name + ":: Failed to move item: Source item not found");
            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);

            item.container = this;
            item.index = dst;

            return true;
        }
        else
        {
            return false;
        }
    }
示例#18
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;
        }
    }
示例#19
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;
    }
示例#20
0
    public bool ContainsItem(CRItem item)
    {
        if (item == null)
            return false;

        for (int i=0; i<_size; i++)
        {
            if (_items[i] == item)
                return true;
        }
        return false;
    }