private void OnSorted()
        {
            var items = new InventoryItemBase[fromCollection.items.Length];
            for (int i = 0; i < items.Length; i++)
                toArr[i] = items[i];

        }
예제 #2
0
        protected void LootWindowOnRemovedItem(InventoryItemBase item, uint itemID, uint slot, uint amount)
        {
            items[slot] = null;

            if (OnLootedItem != null)
                OnLootedItem(item, itemID, slot, amount);
        }
        public CollectionToArraySyncer(ItemCollectionBase fromCollection, InventoryItemBase[] toArr)
        {
            this.fromCollection = fromCollection;
            this.toArr = toArr;

            RegisterEvents();
        }
        public override bool MoveItem(InventoryItemBase item, uint fromSlot, ItemCollectionBase toCollection, uint toSlot, bool clearOld, bool doRepaint = true)
        {
            if (item == null)
                return true;

            // No moving inside own collection
            if (this == toCollection)
                return false;

            var bag = (BagInventoryItem)item;
            if (toCollection[toSlot].item == null)
            {
                bool set = toCollection.SetItem(toSlot, item);
                if (set && InventoryManager.instance.inventory.CanRemoveSlots(bag.extendInventoryBySlots) == false)
                {
                    toCollection.SetItem(toSlot, null); // And reset
                    return false;
                }
            }

            bool moved = base.MoveItem(item, fromSlot, toCollection, toSlot, clearOld, doRepaint);
            if (moved == false)
                return false;

            if (toCollection != this)
            {
                bool unequip = bag.Unequip();
                if (unequip)
                {
                    SetItem(fromSlot, null);
                }
            }

            return true;
        }
예제 #5
0
        public override bool MoveItem(InventoryItemBase item, uint fromSlot, ItemCollectionBase toCollection, uint toSlot, bool clearOld, bool doRepaint = true)
        {
            if (item == null)
                return true;

            if (this != toCollection)
            {
                // Moving to another collection       
                var bag = item as BagInventoryItem;
                if (bag == null)
                    return false;

                if (toCollection[toSlot].item != null)
                    return false; // Slot is not empty, swap should have been called?

                toCollection.SetItem(toSlot, item); // Temp set it
                bool canMove = extendingCollection.CanRemoveSlots(bag.extendInventoryBySlots); // Check if allowed
                toCollection.SetItem(toSlot, null); // Remove

                if (canMove == false)
                    return false;
            }
            
            return base.MoveItem(item, fromSlot, toCollection, toSlot, clearOld, doRepaint);
        }
        public bool IsItemAbidingFilters(InventoryItemBase item)
        {
            switch (matchType)
            {
                case FiltersMatchType.MatchAll:

                    if (filters.Any(filter => filter.IsItemAbidingFilter(item) == false))
                    {
                        return false;
                    }

                    return true;

                case FiltersMatchType.MatchAny:

                    if (filters.Any(filter => filter.IsItemAbidingFilter(item)))
                    {
                        return true;
                    }

                    return false;

                default:
                    Debug.LogWarning("Type " + matchType + " not found");
                    break;
            }

            return false;
        }
        private bool CustomCollectionConditions(InventoryItemBase item)
        {
            // Only allow items that are less than 20 gold in the collections.
            if (item.buyPrice.amount < 20)
                return true; // The item can be added to the collection.

            return false; // The item cannot be  added to the collection.
        }
 public override void OnReset()
 {
     title = "";
     message = "";
     color = Color.black;
     duration = NoticeDuration.Medium;
     item = null;
 }
        //public AnimationClip successAnimation;
        //public AnimationClip failedAnimation;
        //public AnimationClip canceledAnimation;


        #region Notifies

        public virtual void NotifyCraftSuccess(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, InventoryItemBase result)
        {
            InventoryManager.instance.lang.craftedItem.Show(blueprint.itemResult.name, blueprint.itemResult.description);

            if (successCraftItem != null)
                InventoryUtility.AudioPlayOneShot(successCraftItem);

            if (OnCraftSuccess != null)
                OnCraftSuccess(category, blueprint, result);
        }
예제 #10
0
        // 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;
        }
예제 #11
0
        public override bool OverrideUseMethod(InventoryItemBase item)
        {
            var bag = item as BagInventoryItem;
            if (bag != null && item.itemCollection == this)
            {
                if (bag.CanUnEquip())
                {
                    InventoryManager.AddItemAndRemove(bag);
                }
            }

            return true;
        }
        public virtual void AddMenuOption(string name, InventoryItemBase item, UseItemCallback callback)
        {
            var obj = pool.Get();
            obj.transform.SetParent(container);

            obj.item = item;
            obj.text.text = name;

            obj.button.onClick.AddListener(() =>
            {
                callback(obj.item);
                window.Hide();
            });

            menuOptions.Add(new InventoryContextMenuOption(name, callback, obj));
        }
        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;
        }
        private void ShowItem(InventoryItemBase item, uint amount)
        {
            if (item != null)
            {
                var inst = pool.Get();

                inst.transform.SetParent(transform);
                inst.transform.localPosition = Vector3.zero;
                inst.transform.SetSiblingIndex(0);

                inst.icon.sprite = item.icon;
                inst.amountText.text = amount.ToString();
                
                // No repaint, manually handling items

                inst.GetComponent<Animator>().Play(slideAnimation.name);
                StartCoroutine(DestroyItem(inst));
            }
        }
        public virtual void Load()
        {
            if (collection.useReferences)
            {
                //var r = saverLoader.LoadItems(collection, null, (bytes) =>
                //{
                //    var b = serializer.DeserializeItemReferences(bytes);
                //    var itemsArray = new InventoryItemBase[b.Count];
                //    for (int i = 0; i < itemsArray.Length; i++)
                //    {
                //        itemsArray[i] = b[i].itemID
                //    }
                //    collection.SetItems(b.ToArray());

                //    Debug.Log("Saved " + r.Count + " references"); 
                //});
            }
            else
            {
                saverLoader.LoadItems(collection, null, (bytes) =>
                {
                    var b = serializer.DeserializeItems(bytes);
                    var itemsArray = new InventoryItemBase[b.Count];
                    for (int i = 0; i < itemsArray.Length; i++)
                    {
                        if (b[i].itemID != -1)
                        {
                            itemsArray[i] = Instantiate<InventoryItemBase>(ItemManager.instance.items[b[i].itemID]);
                            itemsArray[i].currentStackSize = b[i].amount;
                        }
                        else
                            itemsArray[i] = null;
                    }
                    collection.SetItems(itemsArray, true);

                    Debug.Log("Loaded " + itemsArray.Length + " items"); 
                });
            }
        }
        /// <summary>
        /// Sell an item to this vendor.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="amount"></param>
        public virtual void SellItemToVendor(InventoryItemBase item)
        {
            uint max = InventoryManager.GetItemCount(item.ID, false);

            if (CanSellItemToVendor(item, max) == false)
            {
                InventoryManager.instance.lang.vendorCannotSellItem.Show(item.name, item.description, max);
                return;
            }

            InventorySettingsManager.instance.buySellDialog.ShowDialog("Sell " + name, "Are you sure you want to sell " + name, "Sell", "Cancel", 1, (int)max, item, ItemBuySellDialogAction.Selling, this, (amount) =>
            {
                // Sell items
                SellItemToVendorNow(item, (uint)amount);

            }, (amount) =>
            {
                // Canceled

            });
        }
 public virtual float GetSellPrice(InventoryItemBase item, uint amount)
 {
     return (float)System.Math.Round(item.sellPrice * sellPriceFactor, vendorUI.roundPriceToDecimals) * amount;
 }
        public virtual bool CanSellItemToVendor(InventoryItemBase item, uint amount)
        {
            if (canSellToVendor == false)
                return false;

            if (item.isSellable == false)
                return false;

            return true;
        }
        public virtual bool CanBuyItemFromVendor(InventoryItemBase item, uint amount, bool isBuyBack = false)
        {
            float totalCost = GetBuyPrice(item, amount);
            if (isBuyBack)
                totalCost = GetBuyBackPrice(item, amount);

            string totalCostString = InventorySettingsManager.instance.currencyFormatter.Format(totalCost);
            if (InventoryManager.instance.inventory.gold < totalCost)
            {
                InventoryManager.instance.lang.userNotEnoughGold.Show(item.name, item.description, amount, totalCostString, InventoryManager.instance.inventory.gold);
                return false; // Not enough gold for this many
            }

            if (CanAddItemsToInventory(item, amount) == false)
            {
                InventoryManager.instance.lang.collectionFull.Show(item.name, item.description, vendorUI.collectionName);
                return false;
            }

            return true;
        }
        /// <summary>
        /// Buy an item from this vendor, this does not display a dialog, but moves the item directly to the inventory.
        /// Note that this does not show any UI or warnings and immediately handles the action.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="amount"></param>
        public virtual bool BuyItemFromVendorNow(InventoryItemBase item, uint amount, bool isBuyBack = false)
        {
            if (CanBuyItemFromVendor(item, amount, isBuyBack) == false)
                return false;

            var c1 = GameObject.Instantiate<InventoryItemBase>(item);
            c1.currentStackSize = amount;
            InventoryManager.AddItem(c1); // Will handle unstacking if the stack size goes out of bounds.

            if(isBuyBack)
            {
                InventoryManager.instance.inventory.gold -= GetBuyBackPrice(item, amount);

                if (buyBackIsShared)
                {
                    buyBackDict[vendorCategory][(int)item.index].currentStackSize -= amount;
                    if (buyBackDict[vendorCategory][(int)item.index].currentStackSize < 1)
                    {
                        Destroy(buyBackDict[vendorCategory][(int)item.index].gameObject);
                        buyBackDict[vendorCategory].RemoveAt((int)item.index);
                    }
                }
                else
                {
                    buyBackList[(int)item.index].currentStackSize -= amount;
                    if (buyBackList[(int)item.index].currentStackSize < 1)
                    {
                        Destroy(buyBackList[(int)item.index].gameObject);
                        buyBackList.RemoveAt((int)item.index);
                    }
                }

                vendorUI.NotifyItemBoughtBackFromVendor(item, amount);
            }
            else
            {
                InventoryManager.instance.inventory.gold -= GetBuyPrice(item, amount);

                if(removeItemAfterPurchase)
                {
                    item.itemCollection.SetItem(item.index, null);
                    item.itemCollection.NotifyItemRemoved(item.ID, item.index, item.currentStackSize);
                    item.itemCollection[item.index].Repaint();
                    //Destroy(item.gameObject);
                }
            }

            vendorUI.NotifyItemBoughtFromVendor(item, amount);

            return true;
        }
        public virtual void BuyItemFromVendor(InventoryItemBase item, bool isBuyBack = false)
        {
            ItemBuySellDialogAction action = ItemBuySellDialogAction.Buying;
            uint maxAmount = maxBuyItemCount;
            if (isBuyBack)
            {
                action = ItemBuySellDialogAction.BuyingBack;
                maxAmount = item.currentStackSize;
            }

            InventorySettingsManager.instance.buySellDialog.ShowDialog("Buy item " + item.name, "How many items do you want to buy?", "Buy", "Cancel", 1, (int)maxAmount, item, action, this, (amount) =>
            {
                // Clicked yes!
                BuyItemFromVendorNow(item, (uint)amount, isBuyBack);

            }, (amount) =>
            {
                // Clicked cancel...

            });
        }
 public override void OnReset()
 {
     item = null;
     amount = 1;
     collection = null;
 }
 private void OnUsedItemPly(InventoryItemBase item, uint itemID, uint slot, uint amount)
 {
     if (eventHandler != null)
         eventHandler.CollectionOnUsedItem(item, itemID, slot, amount);
 }
 private void OnAddedItemCollectionFullPly(InventoryItemBase item, bool cameFromCollection)
 {
     if (eventHandler != null)
         eventHandler.CollectionOnAddedItemCollectionFull(item, cameFromCollection);
 }
 private void OnUsedReferencePly(InventoryItemBase actualItem, uint itemID, uint referenceSlot, uint amountUsed)
 {
     if (eventHandler != null)
         eventHandler.CollectionOnUsedReference(actualItem, itemID, referenceSlot, amountUsed);
 }
 private void OnDroppedItemPly(InventoryItemBase item, uint slot, GameObject droppedObj)
 {
     if (eventHandler != null)
         eventHandler.CollectionOnDroppedItem(item, slot, droppedObj);
 }
 private void OnRemovedReferencePly(InventoryItemBase item, uint slot)
 {
     if (eventHandler != null)
         eventHandler.CollectionOnRemovedReference(item, slot);
 }
 public override bool CanSetItem(uint slot, InventoryItemBase item)
 {
     return(item == null);
 }
        /// <summary>
        /// Sell item now to this vendor. The vendor doesn't sell the object, the user sells to this vendor.
        /// Note that this does not show any UI or warnings and immediately handles the action.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public virtual bool SellItemToVendorNow(InventoryItemBase item, uint amount)
        {
            if (CanSellItemToVendor(item, amount) == false)
                return false;

            if (enableBuyBack)
            {
                var copy = GameObject.Instantiate<InventoryItemBase>(item);
                copy.currentStackSize = (uint)amount;
                copy.transform.SetParent(buyBackParent.transform);

                if (buyBackIsShared)
                {
                    if (buyBackDict.ContainsKey(vendorCategory) == false)
                        buyBackDict.Add(vendorCategory, new List<InventoryItemBase>());

                    buyBackDict[vendorCategory].Add(copy);
                    if (buyBackDict[vendorCategory].Count > maxBuyBackItemSlotsCount)
                    {
                        Destroy(buyBackDict[vendorCategory][0].gameObject);
                        buyBackDict[vendorCategory].RemoveAt(0);
                    }
                }
                else
                {
                    // Not shared drop in object array
                    buyBackList.Add(copy);
                    if (buyBackList.Count > maxBuyBackItemSlotsCount)
                    {
                        Destroy(buyBackList[0].gameObject);
                        buyBackList.RemoveAt(0);
                    }
                }
            }

            InventoryManager.instance.inventory.gold += GetSellPrice(item, (uint)amount);
            InventoryManager.RemoveItem(item.ID, amount, false);

            vendorUI.NotifyItemSoldToVendor(item, amount);
            return true;
        }
 public void SetItems(InventoryItemBase[] toSet, float chance = 1.0f)
 {
     items = new InventoryItemGeneratorItem[toSet.Length];
     for (int i = 0; i < items.Length; i++)
     {
         items[i] = new InventoryItemGeneratorItem(toSet[i], chance);
     }
 }
        /// <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;
        }
 public static bool CanAddItem(InventoryItemBase item)
 {
     return(CanAddItemCount(item) >= item.currentStackSize);
 }