Exemple #1
0
        void TransferItemBetweenContainers(NetworkItem item, NetworkItemContainer fromContainer, NetworkItemContainer toContainer)
        {
            // Does from container have enough item?
            if (fromContainer.CheckHasItem(item))
            {
                // Then remove item from donor container
                fromContainer.DeleteItem(item);

                // And add to receiver container
                toContainer.AddItem(item);
            }
        }
Exemple #2
0
        public void AddItem(NetworkItem item)
        {
            foreach (NetworkItem contentsItem in contents)
            {
                if (contentsItem.name == item.name)
                {
                    contentsItem.amount += item.amount;
                    return;
                }
            }

            contents.Add(item);
        }
Exemple #3
0
 public void DeleteItem(NetworkItem item)
 {
     foreach (NetworkItem contentsItem in contents)
     {
         if (contentsItem.name == item.name)
         {
             if (contentsItem.amount - item.amount >= 0)
             {
                 contentsItem.amount -= item.amount;
                 return;
             }
         }
     }
 }
Exemple #4
0
        // Check if container has amount of an item
        public bool CheckHasItem(NetworkItem item)
        {
            foreach (NetworkItem contentsItem in contents)
            {
                if (contentsItem.name == item.name)
                {
                    if (contentsItem.amount >= item.amount)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(false);
        }
Exemple #5
0
        NetworkItem CreateItem(string name, int amount)
        {
            NetworkItem newItem = new NetworkItem(name, amount);

            return(newItem);
        }