private static void LookIn(User.User player, List <string> commands) { commands.RemoveAt(2); //remove "in" string itemNameToGet = Items.Items.ParseItemName(commands); bool itemFound = false; Room room = Room.GetRoom(player.Player.Location); string location; if (string.Equals(commands[commands.Count - 1], "inventory", StringComparison.InvariantCultureIgnoreCase)) { location = null; commands.RemoveAt(commands.Count - 1); //get rid of "inventory" se we can parse an index specifier if there is one } else { location = player.Player.Location; } int itemPosition = 1; string[] position = commands[commands.Count - 1].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item if (position.Count() > 1) { int.TryParse(position[position.Count() - 1], out itemPosition); itemNameToGet = itemNameToGet.Remove(itemNameToGet.Length - 2, 2); } int index = 1; if (!string.IsNullOrEmpty(location)) //player didn't specify it was in his inventory check room first { foreach (string itemID in room.GetObjectsInRoom(Room.RoomObjects.Items)) { Items.Iitem inventoryItem = Items.Items.GetByID(itemID); inventoryItem = KeepOpening(itemNameToGet, inventoryItem, itemPosition, index); if (inventoryItem.Name.Contains(itemNameToGet)) { Items.Icontainer container = inventoryItem as Items.Icontainer; player.MessageHandler(container.LookIn()); itemFound = true; break; } } } if (!itemFound) //so we didn't find one in the room that matches { var playerInventory = player.Player.Inventory.GetInventoryAsItemList(); foreach (Items.Iitem inventoryItem in playerInventory) { if (inventoryItem.Name.Contains(itemNameToGet)) { //if player didn't specify an index number loop through all items until we find the first one we want otherwise we will // keep going through each item that matches until we hit the index number if (index == itemPosition) { Items.Icontainer container = inventoryItem as Items.Icontainer; player.MessageHandler(container.LookIn()); itemFound = true; break; } else { index++; } } } } }