private CommandResponse DropItem(string itemLabel, Inventory locationItems, Player player) { if (itemLabel != "gold" && player.Inventory.ItemList.ContainsKey(itemLabel) == false) return new CommandResponse("There is no such item"); else { return AddItemToLocation(itemLabel, locationItems, player); } }
private CommandResponse TakeItem(string itemLabel, Inventory locationItems, Player player) { if (itemLabel!="gold" && locationItems.ItemList.ContainsKey(itemLabel)==false) return new CommandResponse("There is no such item"); if (player.Inventory.GetWeightLimit() - player.Inventory.GetWeight() < GetItemWeight(itemLabel, player)) return new CommandResponse("The item's too heavy"); else { return AddItemToInventory(itemLabel, locationItems, player); } }
private CommandResponse SellItem(string itemLabel, Inventory locationItems, Player player) { if (!(player.Inventory.ItemList.ContainsKey(itemLabel))) return new CommandResponse("There is no such item"); else { Item item = player.Inventory.GetItem(itemLabel); player.Inventory.RemoveItem(item); locationItems.AddItem(item); player.Inventory.GetGold().Total += item.Value; return new CommandResponse("You've sold the item: " + itemLabel); } }
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); } }
public Location() { this.exitCollection = new ExitCollection(); this.items = new Inventory(); this.characterList = new NonPlayerCharacterCollection(); }