private static Items.Iitem KeepOpening(string itemName, Items.Iitem item, int itemPosition = 1, int itemIndex = 1) { Items.Icontainer container = item as Items.Icontainer; if (item.ItemType.ContainsKey(Items.ItemsType.CONTAINER) && container.Contents.Count > 0) { foreach (string innerID in container.GetContents()) { Items.Iitem innerItem = Items.Items.GetByID(innerID); if (innerItem != null && KeepOpening(itemName, innerItem, itemPosition, itemIndex).Name.Contains(itemName)) { if (itemIndex == itemPosition) { return(innerItem); } else { itemIndex++; } } } } return(item); }
private static Items.Iiluminate FindLightInEquipment(List <string> commands, User.User player, Rooms.Room room) { Items.Iitem lightItem = null; if (commands.Count > 0) { string itemName = GetItemName(commands, "").ToString(); //let's see if player has a lightsource equipped foreach (Items.Iitem item in player.Player.Equipment.GetEquipment().Values) { if (item.WornOn == Items.Wearable.WIELD_LEFT || item.WornOn == Items.Wearable.WIELD_RIGHT) { Items.Iiluminate temp = item as Items.Iiluminate; if (temp != null && temp.isLightable) { lightItem = item; break; } } } } else //let's be smart and figure out what lightSource he wants activated, first come first serve otherwise { foreach (Items.Iitem item in player.Player.Equipment.GetEquipment().Values) { Items.Iiluminate lightsource = item as Items.Iiluminate; if (lightsource != null && lightsource.isLightable) { lightItem = item; break; } } if (lightItem == null) //not in players equipment let's check the room { foreach (string itemId in room.GetObjectsInRoom(Room.RoomObjects.Items)) { lightItem = Items.Items.GetByID(itemId); Items.Iiluminate lightsource = lightItem as Items.Iiluminate; if (lightsource != null && lightsource.isLightable) { break; } //if it's a container and it's open see if it has a lightsource inside if (lightItem.ItemType.ContainsKey(Items.ItemsType.CONTAINER)) { Items.Icontainer containerItem = lightItem as Items.Icontainer; if (containerItem.Opened) { foreach (string id in containerItem.GetContents()) { lightItem = Items.Items.GetByID(itemId); lightsource = lightItem as Items.Iiluminate; if (lightsource != null && lightsource.isLightable) { break; } } } } } } } return(lightItem as Items.Iiluminate); }
private static void TraverseItems(User.User player, string containerName, string itemName, int containerPosition, int itemPosition, out Items.Iitem retrievedItem, out Items.Iitem retrievedContainer) { int containerIndex = 1; int itemIndex = 1; retrievedItem = null; retrievedContainer = null; Room room = Room.GetRoom(player.Player.Location); if (!string.IsNullOrEmpty(containerName.CamelCaseString())) { foreach (string itemID in room.GetObjectsInRoom(Room.RoomObjects.Items)) { Items.Iitem inventoryItem = Items.Items.GetByID(itemID); inventoryItem = KeepOpening(containerName.CamelCaseString(), inventoryItem, containerPosition, containerIndex); if (inventoryItem.Name.Contains(containerName.CamelCaseString())) { retrievedContainer = inventoryItem; break; } } } //if we retrieved a specific indexed container search within it for the item if (retrievedContainer != null) { Items.Icontainer container = null; container = retrievedContainer as Items.Icontainer; foreach (string itemID in container.GetContents()) { Items.Iitem inventoryItem = Items.Items.GetByID(itemID); inventoryItem = KeepOpening(itemName.CamelCaseString(), inventoryItem, itemPosition, itemIndex); if (inventoryItem.Name.Contains(itemName.CamelCaseString())) { retrievedItem = inventoryItem; break; } } } else if (string.IsNullOrEmpty(containerName)) //we are grabbing a container or an item without a specific index { foreach (string itemID in room.GetObjectsInRoom(Room.RoomObjects.Items)) { Items.Iitem inventoryItem = Items.Items.GetByID(itemID); inventoryItem = KeepOpening(itemName.CamelCaseString(), inventoryItem, itemPosition, itemIndex); if (inventoryItem.Name.Contains(itemName.CamelCaseString())) { retrievedItem = inventoryItem; break; } } } else { foreach (string itemID in room.GetObjectsInRoom(Room.RoomObjects.Items)) { Items.Iitem inventoryItem = Items.Items.GetByID(itemID); if (inventoryItem.Name.Contains(itemName.CamelCaseString())) { retrievedItem = inventoryItem; break; } } } }