Beispiel #1
0
        /// <summary>
        /// Some item's require multiple slots, for example a 2 handed item forces the left handed item to be empty.
        /// </summary>
        /// <returns>true if items were removed, false if items were not removed.</returns>
        public virtual bool HandleLocks(InventoryEquippableField equipSlot, ItemCollectionBase usedFromCollection)
        {
            var toBeRemoved = new List <uint>(8);

            // Loop through things we want to block
            foreach (var blockType in equipType.blockTypes)
            {
                // Check every slot against this block type
                foreach (var field in InventoryManager.instance.character.equipSlotFields)
                {
                    var item = InventoryManager.instance.character[field.index].item;
                    if (item != null)
                    {
                        var eq = (EquippableInventoryItem)item;

                        if (eq.equipType.ID == blockType && field.index != equipSlot.index)
                        {
                            toBeRemoved.Add(field.index);
                            bool canAdd = InventoryManager.CanAddItem(eq);
                            if (canAdd == false)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            //// There was already an item in this slot, un-equip that one first
            //if (InventoryManager.instance.character[equipSlot.index].item != null)
            //{
            //    // TODO:  FIX THIS .. !
            //    toBeRemoved.Add(equipSlot.index);
            //}

            foreach (uint i in toBeRemoved)
            {
                var  item  = InventoryManager.instance.character[i].item as EquippableInventoryItem;
                bool added = InventoryManager.AddItemAndRemove(item);
                if (added == false)
                {
                    Debug.LogError("Item could not be saved, even after check, please report this bug + stacktrace.");
                    return(false);
                }

                item.NotifyItemUnEquipped();
                //InventoryManager.instance.character.SetItem(i, null);
                //InventoryManager.instance.character[i].Repaint();
            }

            return(true);
        }
        // Items from the bank go straight to the inventory
        public override bool OverrideUseMethod(InventoryItemBase item)
        {
            if (InventorySettingsManager.instance.useContextMenu)
            {
                return(false);
            }

            if (useMoveToInventory)
            {
                InventoryManager.AddItemAndRemove(item);
            }

            return(useMoveToInventory);
        }
Beispiel #3
0
        public override bool OverrideUseMethod(InventoryItemBase item)
        {
            var bag = item as BagInventoryItem;

            if (item.itemCollection == this)
            {
                // Used from inside
                if (bag != null)
                {
                    bool unequip = bag.Unequip();
                    if (unequip)
                    {
                        InventoryManager.AddItemAndRemove(bag);
                    }
                }
            }

            return(true);
        }
Beispiel #4
0
        public virtual bool Equip(InventoryEquippableField equipSlot, ItemCollectionBase equipToCollection)
        {
            bool handled = HandleLocks(equipSlot, itemCollection);

            if (handled == false)
            {
                return(false); // Other items cannot be unequipped
            }
            // There was already an item in this slot, un-equip that one first
            if (equipToCollection[equipSlot.index].item != null)
            {
                var  item      = equipToCollection[equipSlot.index].item as EquippableInventoryItem;
                bool addedItem = InventoryManager.AddItemAndRemove(item);
                if (addedItem == false)
                {
                    return(false); // Can't un-equip item to equip item..
                }
                item.NotifyItemUnEquipped();
            }

            // The values before the collection / slot changed.
            uint prevIndex      = index;
            var  fromCollection = itemCollection;

            // Equip the item -> Will swap as merge is not possible
            bool swapped = itemCollection.SwapOrMerge(index, equipToCollection, equipSlot.index);

            if (swapped)
            {
                NotifyItemUsed(1, false); // NOTE: Collection changed, collection - event no longer valid!
                fromCollection.NotifyItemUsed(ID, prevIndex, 1);

                if (fromCollection[prevIndex].item != null)
                {
                    ((EquippableInventoryItem)fromCollection[prevIndex].item).NotifyItemUnEquipped();
                }

                return(true);
            }

            return(false);
        }
Beispiel #5
0
        public virtual bool Unequip()
        {
            uint prevIndex      = index;
            var  fromCollection = itemCollection;

            bool added = InventoryManager.AddItemAndRemove(this);

            if (added == false)
            {
                return(false);
            }

            //if (fromCollection != null)
            //    fromCollection.NotifyItemUnequipped(this, prevIndex);
            //else
            //    InventoryManager.instance.character.NotifyItemUnequipped(this, prevIndex);

            NotifyItemUsed(1, false); // NOTE: Collection changed, collection - event no longer valid!
            fromCollection.NotifyItemUsed(ID, prevIndex, 1);

            NotifyItemUnEquipped();

            return(true);
        }