Пример #1
0
 // Through this method, whenever an item properties change the container invokes the OnInvenotryChange event for its clients
 private void HookUpItemEventsToContainer(BasicItem item)
 {
     // Remove previous listeners if they exists
     item.OnNameChange.RemoveAllListeners();
     item.OnGraphicChange.RemoveAllListeners();
     item.OnNameChange.AddListener(delegate { OnInventoryChange.Invoke(); });
     item.OnGraphicChange.AddListener(delegate { OnInventoryChange.Invoke(); });
 }
Пример #2
0
        // Returns the item of a given slot index, or null if such item doesn't exist
        public BasicItem GetItemOfSlotIndex(int slotIndex)
        {
            BasicItem item = null;

            if (items.TryGetValue(slotIndex, out item))
            {
                return(item);
            }
            return(item);
        }
Пример #3
0
        // Clears the slot and its entry in the dictionary
        public void ClearItemOfSlot(int slotIndex)
        {
            BasicItem item = null;

            if (items.TryGetValue(slotIndex, out item))
            {
                items.Remove(slotIndex);
                item = null;
                OnInventoryChange.Invoke();
            }
        }
Пример #4
0
        //Finds the first item of a given name, or returns null if there is no such item
        public BasicItem FindFirstItemOfName(string itemName)
        {
            BasicItem item = new BasicItem();

            foreach (KeyValuePair <int, BasicItem> entry in items)
            {
                if (entry.Value.Name == itemName)
                {
                    item = entry.Value;
                    return(item);
                }
            }
            return(item);
        }
Пример #5
0
        // Adds an item as a single stack, and returns true if it was successful
        public bool AddItemAsASingleStack(BasicItem item)
        {
            int iEmptySlot = FindEmptySlot();

            if (iEmptySlot == -1)
            {
                return(false);                  // if there are no free slots, do nothing
            }
            else
            {
                HookUpItemEventsToContainer(item);
                items.Add(iEmptySlot, item);
                OnInventoryChange.Invoke();
                return(true);
            }
        }