private CommandResponse AddItemToLocation(String itemLabel, Inventory locationItems, Player player) { if (itemLabel == "gold") { int amount = player.Inventory.GetGold().Total; player.CurrentLocation.Items.AddMoney(amount); player.Inventory.RemoveMoney(amount); return new CommandResponse("You dropped " + amount + " gold"); } Item item = locationItems.GetItem(itemLabel); player.Inventory.AddItem(item); locationItems.RemoveItem(item); return new CommandResponse("You dropped the item: " + itemLabel); }
private CommandResponse BuyItem(string itemLabel, Inventory locationItems, Player player) { if (! (locationItems.ItemList.ContainsKey(itemLabel))) return new CommandResponse("There is no such item"); else if (player.Inventory.GetWeightLimit() - player.Inventory.GetWeight() < locationItems.GetItem(itemLabel).Weight) return new CommandResponse("The item's too heavy"); else if (player.Inventory.GetGold().Total < locationItems.GetItem(itemLabel).Value) return new CommandResponse("You have no enough gold"); else { Item item = locationItems.GetItem(itemLabel); player.Inventory.AddItem(item); locationItems.RemoveItem(item); player.Inventory.GetGold().Total -= item.Value; return new CommandResponse("You've bought the item: " + itemLabel); } }