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); } }
public void AddItem(NetworkItem item) { foreach (NetworkItem contentsItem in contents) { if (contentsItem.name == item.name) { contentsItem.amount += item.amount; return; } } contents.Add(item); }
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; } } } }
// 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); }
NetworkItem CreateItem(string name, int amount) { NetworkItem newItem = new NetworkItem(name, amount); return(newItem); }