Ejemplo n.º 1
0
    //add item to our inventory
    public bool Add(Item item)
    {
        //add only not default items
        if (!item.isDefaultItem)
        {
            //just add item if we have room in our inventory
            //otherwise, send a message to UI
            if (items.Count < inventorySpace)
            {
                //add item to item list
                items.Add(item);

                //call callback
                if (onInventoryChangeCallback != null)
                {
                    onInventoryChangeCallback.Invoke();
                }

                //item added successfuly
                return(true);
            }
            else
            {
                //send message to client log
                MessageWorld.instance.SendMessageWorld("Inventory is Full!");

                Debug.Log("Inventory is Full.");
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 2
0
 public void Add(Item newItem)
 {
     if (items.Count < space)
     {
         items.Add(newItem);
         if (onChange != null)
         {
             onChange.Invoke();
         }
     }
     else
     {
         Debug.Log("Lista completa");
     }
 }
Ejemplo n.º 3
0
        public bool RemovePackage(int width, int height)
        {
            var widthNode = new Node <WidthData>(new WidthData(width));

            if (tree.TryGetNode(ref widthNode))
            {
                var heightNode = new Node <HeightData>(new HeightData(height));
                if (widthNode.Data.HeightTree.TryGetNode(ref heightNode))
                {
                    widthNode.Data.HeightTree.RemoveNode(heightNode.Data);
                    heightNode.Data.Count = 0;

                    if (widthNode.Data.HeightTree.Count == 0)
                    {
                        tree.RemoveNode(data: widthNode.Data);
                    }

                    var pkg = new Package()
                    {
                        Count  = 0,
                        Width  = width,
                        Height = height
                    };

                    OnInventoryChange?.Invoke(this, new InventoryChangeEventArgs(pkg));
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        private void OnExpired(object sender, JobDoneArgs e)
        {
            _jobRunner.Stop();
            var dq         = e.DataQueue;
            var parentTree = dq.ParentTree;

            parentTree.RemoveNode(dq.Data);
            var hCount = parentTree.Count;
            var width  = dq.BaseNode.Data.Width;
            var height = dq.Data.Height;

            if (hCount == 0)
            {
                RemovePackage(width);
            }
            var pkg = new Package()
            {
                Count  = 0,
                Width  = width,
                Height = height
            };

            OnInventoryChange?.Invoke(this, new InventoryChangeEventArgs(pkg));
            _jobRunner.Start();
        }
Ejemplo n.º 5
0
        public bool Use(Item item)
        {
            if (item == null)
            {
                return(false);
            }

            Loot loot;

            if ((loot = item as Loot) != null && loot.use(this))
            {
                loot.count--;
                if (loot.count <= 0)
                {
                    RemoveFromInventory(item);
                }
                OnInventoryChange?.Invoke();
                return(true);
            }

            Weapon weapon;

            if ((weapon = item as Weapon) != null)
            {
                return(Equip(weapon));
            }

            return(false);
        }
Ejemplo n.º 6
0
        public bool IssuePackage(int width, int height, int quantity = 1)
        {
            var widthNode = new Node <WidthData>(new WidthData(width));

            if (tree.TryGetNode(ref widthNode))
            {
                var heightNode = new Node <HeightData>(new HeightData(height));
                int hCount     = heightNode.Data.Count;
                if (widthNode.Data.HeightTree.TryGetNode(ref heightNode, true))
                {
                    --hCount;
                    if (hCount == 0)
                    {
                        RemovePackage(width, height);
                        _storeQueue.Remove(heightNode.Data.QueueNode);
                    }
                    else if (hCount <= MinimumPackageQuantity)
                    {
                        Publish(MessageType.PackageQuanityLow, new Package(width, height));
                    }

                    var pkg = new Package()
                    {
                        Count  = hCount,
                        Width  = width,
                        Height = height
                    };

                    OnInventoryChange?.Invoke(this, new InventoryChangeEventArgs(pkg));
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 7
0
    public void AddItemToInventory(GameObject item)
    {
        if (inventory.Count >= maxInventorySlots)
        {
            Debug.Log("Inventory is full");
        }
        else
        {
            inventory.Add(item);

            if (onInventoryChangeCallback != null)
            {
                onInventoryChangeCallback.Invoke();
            }

            DisplayLootMessage(item);
        }
    }
Ejemplo n.º 8
0
 public void Remove(Item item)
 {
     if (Items.Contains(item))
     {
         Items.Remove(item);
         print("Removed the item");
     }
     OnInventoryChange?.Invoke();
     Debug.Log("Removed: " + item.Name);
 }
Ejemplo n.º 9
0
 public void Add(Item item)
 {
     if (Items.Count >= _amountOfSlots)
     {
         print("Not Enough Room");
         return;
     }
     Items.Add(item);
     OnInventoryChange?.Invoke();
 }
Ejemplo n.º 10
0
    public bool StoreItem(Item item)
    {
        if (currentNumberOfItems < maxNumberOfSlots)
        {
            int nextEmptySlot = Array.IndexOf(items, null);
            items[nextEmptySlot] = item.itemData;
            Destroy(item.gameObject);
            currentNumberOfItems++;

            if (inventoryChangeCallback != null)
            {
                inventoryChangeCallback.Invoke();
            }

            item.itemData.isStored = true;

            return(true);
        }
        return(false);
    }
Ejemplo n.º 11
0
    public bool Add(Item item) // called by ItemPickup.DoOnInteract()
    {
        if ((_items.ContainsKey(item.ItemName) && _items[item.ItemName].Count == 99) || (!_items.ContainsKey(item.ItemName) && _items.Count == MaxSize))
        {
            Debug.Log("Add()" + item.name + " false");
            return(false);
        }

        if (!_items.ContainsKey(item.ItemName) && _items.Count < MaxSize)
        {
            _items.Add(item.ItemName, new List <Item>());
        }


        _items[item.ItemName].Add(item);

        OnInventoryChangeCallback.Invoke();

        Debug.Log("Add()" + item.name + " true");
        return(true);
    }
Ejemplo n.º 12
0
    public bool AddToInventory(Item item)
    {
        float weight = 0f;

        for (int i = 0; i < items.Count; i++)
        {
            weight += items[i].weight;
        }
        if ((weight += item.weight) > strength)
        {
            Debug.Log("To Heavy");
            return(false);
        }
        else
        {
            items.Add(item);
            if (onInventoryChangeCallBack != null)
            {
                onInventoryChangeCallBack.Invoke();
            }
            return(true);
        }
    }
Ejemplo n.º 13
0
    //Internal method. This is called from various places if something in the inventory changes.
    private void inventoryChanged(bool fireUserEvents = true)
    {
        //Execute all requested callbacks (e.g. from the UI script to actualize the list), if not null;
        if (OnInventoryChangeAction != null)
        {
            OnInventoryChangeAction.Invoke();
        }

        if (fireUserEvents == true)
        {
            //Execute User Events
            OnInventoryChange.Invoke();
        }
    }
Ejemplo n.º 14
0
    public void AddItem(ItemSO itemSO)
    {
        List <Item> items = GetInventorySlots(itemSO.Slot);
        Item        item  = items.Find(x => x.ItemSO == itemSO);

        if (item == null)
        {
            item = new Item(itemSO);
            items.Add(item);
        }
        else
        {
            item.AddAmount();
        }

        OnInventoryChange.Invoke(itemSO.Slot);
    }
Ejemplo n.º 15
0
        public void AddPackage(int width, int height, int quantity = 1)
        {
            var widthNode  = new Node <WidthData>(new WidthData(width));
            var heightNode = new Node <HeightData>(new HeightData(height));
            var hData      = heightNode.Data;

            if (tree.TryGetNode(ref widthNode))
            {
                if (widthNode.Data.HeightTree.TryGetNode(node: ref heightNode))
                {
                    hData = heightNode.Data;
                    _storeQueue.Enqueue(_storeQueue.Dequeue().Data);
                }
                else
                {
                    _storeQueue.Enqueue(hData);
                    widthNode.Data.HeightTree.Insert(data: hData);
                }
            }
            else
            {
                hData.Base = widthNode;
                _storeQueue.Enqueue(hData);
                widthNode.Data.HeightTree.Insert(hData);
                tree.Insert(widthNode.Data);
            }

            var pkg = new Package()
            {
                Count  = heightNode.Data.Count,
                Width  = width,
                Height = height
            };

            hData.Count = GetRightAmountAndPublishMessage(currentPackageCount: hData.Count,
                                                          amountToAdd: quantity,
                                                          package: pkg);

            pkg.Count = hData.Count;

            OnInventoryChange?.Invoke(this, new InventoryChangeEventArgs(pkg));
        }
Ejemplo n.º 16
0
        public override void SetInventorySlot(int index, Item item)
        {
            base.SetInventorySlot(index, item);

            int itemCount = 0;

            for (int i = 0; i < MaxInventorySize; i++)
            {
                if (GetInventorySlot(i) != null)
                {
                    itemCount++;
                }
            }
            weight = WeightClass.LIGHT;
            for (int i = 0; i < (int)WeightClass.COUNT; i++)
            {
                if (itemCount >= data.weightClassItemCount[i])
                {
                    weight = (WeightClass)i;
                }
            }

            OnInventoryChange?.Invoke();
        }
Ejemplo n.º 17
0
 public void RemoveItem(int index, ItemSlot slot)
 {
     GetInventorySlots(slot).RemoveAt(index);
     OnInventoryChange.Invoke(slot);
 }
Ejemplo n.º 18
0
 public void UpdateItemAmount(Item item)
 {
     OnInventoryChange.Invoke(item.ItemSO.Slot);
 }
Ejemplo n.º 19
0
 private void OnValidate()
 {
     OnInventoryChange?.Invoke();
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Adds Listener to Gold-Event
 /// </summary>
 /// <param name="listener">Listener to Add</param>
 public void AddGoldListener(OnInventoryChange listener)
 {
     goldChangeEvent += listener;
     // Set Initial Value
     listener.Invoke(Gold, 0);
 }
Ejemplo n.º 21
0
        IEnumerator DoLateInit()
        {
            yield return(new WaitForSeconds(.05f));

            onInventoryChange?.Invoke();
        }