private void HandleGatherInteraction(string[] commandWords, Person actor) { if (actor.Location.LocationType == LocationType.Forest && this.HasItemInInventory(actor, ItemType.Weapon)) { var wood = new Wood(commandWords[2]); this.AddToPerson(actor, wood); wood.UpdateWithInteraction("gather"); } else if (actor.Location.LocationType == LocationType.Mine && this.HasItemInInventory(actor, ItemType.Armor)) { var iron = new Iron(commandWords[2]); this.AddToPerson(actor, iron); iron.UpdateWithInteraction("gather"); } }
protected void HandleGatherInteraction(string[] commandWords, Person actor) { if (actor.Location.LocationType != LocationType.Town) { if (actor.Location.LocationType == LocationType.Forest && actor.ListInventory().Any(item => item.ItemType == ItemType.Weapon)) { Item item = new Wood(commandWords[2], actor.Location); this.AddToPerson(actor, item); item.UpdateWithInteraction("gather"); strayItemsByLocation[actor.Location].Clear(); } else if (actor.Location.LocationType == LocationType.Mine && actor.ListInventory().Any(item => item.ItemType == ItemType.Armor)) { Item item = new Iron(commandWords[2], actor.Location); this.AddToPerson(actor, item); item.UpdateWithInteraction("gather"); strayItemsByLocation[actor.Location].Clear(); } } }
protected void HandleCraftInterraction(string[] commandWords, Person actor) { if (actor.ListInventory().Count != 0) { // How Do I check if inventory contains both Weapon and wood with one LINQ Query? //actor.ListInventory().Any(item => item.ItemType == ItemType.Iron && //item.ItemType == ItemType.Wood)) if (commandWords[2] == "weapon" && actor.ListInventory().Any(item => item.ItemType == ItemType.Iron) && actor.ListInventory().Any(item => item.ItemType == ItemType.Wood)) { Item item = new Iron(commandWords[3], actor.Location); this.AddToPerson(actor, item); item.UpdateWithInteraction("crafted"); } else if (commandWords[2] == "armor" && actor.ListInventory().Any(item => item.ItemType == ItemType.Iron)) { Item item = new Armor(commandWords[3], actor.Location); this.AddToPerson(actor, item); item.UpdateWithInteraction("crafted"); } } }
private void HandleGatherInteraction(string[] commandWords, Person actor) { string gatherItemName = commandWords[2]; Item newItem = null; if (actor.Location.LocationType == LocationType.Forest) { bool hasWeapon = false; foreach (var item in actor.ListInventory()) { if (item.ItemType == ItemType.Weapon) { hasWeapon = true; break; } } if (hasWeapon) { newItem = new Wood(gatherItemName); this.AddToPerson(actor, newItem); newItem.UpdateWithInteraction("gather"); } } else if (actor.Location.LocationType == LocationType.Mine) { bool hasArmor = false; foreach (var item in actor.ListInventory()) { if (item.ItemType == ItemType.Armor) { hasArmor = true; break; } } if (hasArmor) { newItem = new Iron(gatherItemName); this.AddToPerson(actor, newItem); newItem.UpdateWithInteraction("gather"); } } }