private void HandleCraftInteraction(string[] commandWords, Person actor) { var craftedItemType = commandWords[2]; string craftedItemName = commandWords[3]; Item theNewCraftedItem = null; var actorInventory = actor.ListInventory(); if (craftedItemType == "weapon") { bool hasWood = PossessTheRequiredItem(actorInventory, ItemType.Wood); bool hasIron = PossessTheRequiredItem(actorInventory, ItemType.Iron); if (hasWood && hasIron) { theNewCraftedItem = new Weapon(craftedItemName); this.AddToPerson(actor, theNewCraftedItem); theNewCraftedItem.UpdateWithInteraction("craft"); } } else if (craftedItemType == "armor") { bool hasIron = PossessTheRequiredItem(actorInventory, ItemType.Iron); if (hasIron) { theNewCraftedItem = new Armor(craftedItemName); this.AddToPerson(actor, theNewCraftedItem); theNewCraftedItem.UpdateWithInteraction("craft"); } } }
private void HandleCraftCommand(string[] commandWords, Person actor) { var inventory = actor.ListInventory(); bool hasIron = false; bool hasWood = false; foreach (var item in inventory) { if (ownerByItem[item] == actor) { if (item.ItemType == ItemType.Iron) { hasIron = true; } if (item.ItemType == ItemType.Wood) { hasWood = true; } } } switch (commandWords[2]) { case "armor": { if (commandWords[2] == "armor" && hasIron) { var armorItem = new Armor(commandWords[3]); this.AddToPerson(actor, armorItem); armorItem.UpdateWithInteraction("crafted"); } break; } case "weapon": { if (hasWood && hasIron) { var weaponItem = new Weapon(commandWords[3]); this.AddToPerson(actor, weaponItem); weaponItem.UpdateWithInteraction("crafted"); } break; } default: break; } }
private void CraftWeapon(string newItemName, Person actor) { var ironItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Iron); var woodItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Wood); if (ironItems != null && woodItems != null && ironItems.Count() > 0 && woodItems.Count() > 0) { var item = new Weapon(newItemName, null); actor.AddToInventory(item); ownerByItem.Add(item, actor); item.UpdateWithInteraction("craft"); } }
private void HandleCraftInteraction(string[] commandWords, Person actor) { string craftItemType = commandWords[2]; string craftItemName = commandWords[3]; if (craftItemType == "armor") { bool hasIron = false; foreach (var item in actor.ListInventory()) { if (item.ItemType == ItemType.Iron) { hasIron = true; break; } } if (hasIron) { var addedItem = new Armor(craftItemName); this.AddToPerson(actor, addedItem); addedItem.UpdateWithInteraction("craft"); } } if (craftItemType == "weapon") { bool hasWood = false; bool hasIron = false; foreach (var item in actor.ListInventory()) { if (item.ItemType == ItemType.Wood) { hasWood = true; } else if (item.ItemType == ItemType.Iron) { hasIron = true; } } if (hasWood && hasIron) { var addedItem = new Weapon(craftItemName); this.AddToPerson(actor, addedItem); addedItem.UpdateWithInteraction("craft"); } } }