Пример #1
0
        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);
        }