Beispiel #1
0
        /// <summary>
        /// Does the inventory contain the required items?
        /// </summary>
        /// <param name="blueprint"></param>
        /// <param name="alsoScanBank"></param>
        /// <param name="craftCount"></param>
        /// <returns></returns>
        public virtual bool CanCraftBlueprint(InventoryCraftingBlueprint blueprint, bool alsoScanBank, int craftCount)
        {
            // Layout can only be triggered if one is visible -> selected. So no need to check it here.


            if (InventoryManager.instance.inventory.gold < blueprint.craftCostPrice * craftCount)
            {
                InventoryManager.instance.lang.userNotEnoughGold.Show(blueprint.itemResult.name, blueprint.itemResult.description, craftCount, blueprint.craftCostPrice * craftCount, InventoryManager.instance.inventory.gold);
                return(false);
            }

            // Can the items be stored in the inventory / designated spot?
            if (currentCategory.forceSaveInCollection != null)
            {
                bool added = currentCategory.forceSaveInCollection.CanAddItem(blueprint.itemResult);
                if (added == false)
                {
                    return(false);
                }
            }
            else
            {
                bool added = InventoryManager.CanAddItem(blueprint.itemResult);
                if (added == false)
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Can this item * amount be added to the inventory, is there room?
        /// </summary>
        /// <param name="item"></param>
        /// <param name="amount"></param>
        /// <returns>True if items can be placed, false is not.</returns>
        protected virtual bool CanAddItemsToInventory(InventoryItemBase item, uint amount)
        {
            uint originalStackSize = item.currentStackSize;

            item.currentStackSize = amount;
            bool can = InventoryManager.CanAddItem(item);

            item.currentStackSize = originalStackSize; // Reset

            return(can);
        }
Beispiel #3
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);
        }
        /// <summary>
        /// Does the inventory contain the required items?
        /// </summary>
        /// <param name="blueprint"></param>
        /// <param name="alsoScanBank"></param>
        /// <param name="craftCount"></param>
        /// <returns></returns>
        public virtual bool CanCraftBlueprint(InventoryCraftingBlueprint blueprint, bool alsoScanBank, int craftCount)
        {
            foreach (var item in blueprint.requiredItems)
            {
                uint count = InventoryManager.GetItemCount(item.item.ID, alsoScanBank);
                if (count < item.amount * craftCount)
                {
                    InventoryManager.instance.lang.craftingDontHaveRequiredItems.Show(item.item.name, item.item.description, blueprint.name);
                    return(false);
                }
            }

            if (InventoryManager.instance.inventory.gold < blueprint.craftCostPrice * craftCount)
            {
                InventoryManager.instance.lang.userNotEnoughGold.Show(blueprint.itemResult.name, blueprint.itemResult.description, craftCount, blueprint.craftCostPrice * craftCount, InventoryManager.instance.inventory.gold);
                return(false);
            }

            // Can the items be stored in the inventory / designated spot?
            if (currentCategory.forceSaveInCollection != null)
            {
                bool added = currentCategory.forceSaveInCollection.CanAddItem(blueprint.itemResult);
                if (added == false)
                {
                    return(false);
                }
            }
            else
            {
                bool added = InventoryManager.CanAddItem(blueprint.itemResult);
                if (added == false)
                {
                    return(false);
                }
            }

            return(true);
        }