示例#1
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);
        }
示例#2
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);
        }
示例#3
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();
        }
示例#4
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);
        }
示例#5
0
 public void Remove(Item item)
 {
     if (Items.Contains(item))
     {
         Items.Remove(item);
         print("Removed the item");
     }
     OnInventoryChange?.Invoke();
     Debug.Log("Removed: " + item.Name);
 }
示例#6
0
 public void Add(Item item)
 {
     if (Items.Count >= _amountOfSlots)
     {
         print("Not Enough Room");
         return;
     }
     Items.Add(item);
     OnInventoryChange?.Invoke();
 }
示例#7
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();
        }
    }
    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);
    }
示例#9
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));
        }
    void Awake()
    {
        inventory = new Dictionary <string, int>();
        inventory.Add(healthItem, startingHealthAmount);
        foreach (string s in itemNames)
        {
            inventory.Add(s, 0);
        }
        for (int i = 0; i < itemAmounts.Length; i++)
        {
            inventory[itemNames[i]] = itemAmounts[i];
        }

        OnInventoryChange DeathCheck = () =>
        {
            if (IsDeathCheck())
            {
                onPlayerDeath();
            }
        };

        onInventoryChange += DeathCheck;
    }
示例#11
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();
        }
示例#12
0
 /// <summary>
 /// Removes Listener from Gold-Event
 /// </summary>
 /// <param name="listener">Listener to Remove</param>
 public void RemoveGoldListener(OnInventoryChange listener)
 {
     goldChangeEvent -= listener;
 }
示例#13
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);
 }
示例#14
0
 /// <summary>
 /// Removes Listener from Dust-Event
 /// </summary>
 /// <param name="listener">Listener to Remove</param>
 public void RemoveDustListener(OnInventoryChange listener)
 {
     dustChangeEvent -= listener;
 }
示例#15
0
 private void OnValidate()
 {
     OnInventoryChange?.Invoke();
 }
 public void UpdateItemAmount(Item item)
 {
     OnInventoryChange.Invoke(item.ItemSO.Slot);
 }
 public void RemoveItem(int index, ItemSlot slot)
 {
     GetInventorySlots(slot).RemoveAt(index);
     OnInventoryChange.Invoke(slot);
 }
示例#18
0
 /// <summary>
 /// Adds Listener to Dust-Event
 /// </summary>
 /// <param name="listener">Listener to Add</param>
 public void AddDustListener(OnInventoryChange listener)
 {
     dustChangeEvent += listener;
 }