private static void DeActivate(User.User player, List <string> commands) { //used for turning off a lightSource that can be lit. Items.Iiluminate lightItem = null; //just making the command be display friendly for the messages string command = null; switch (commands[1]) { case "TURNOFF": command = "turn off"; break; case "SWITCHOFF": command = "switch off"; break; default: command = commands[1]; break; } commands.RemoveRange(0, 2); List <string> message = new List <string>(); Room room = Room.GetRoom(player.Player.Location); lightItem = FindLightInEquipment(commands, player, room); if (lightItem != null) { if (lightItem.isLit) { message = lightItem.Extinguish(); if (message.Count > 1) { message[1] = string.Format(message[1], player.Player.FirstName); } } else { message.Add("It's already off!"); } } else { message.Add("You don't see anything to " + command + "."); } player.MessageHandler(message[0]); if (message.Count > 1) { room.InformPlayersInRoom(message[1], new List <string>(new string[] { player.UserID })); } }
private static void Activate(User.User player, List <string> commands) { //used for lighting up a lightSource that can be lit. Items.Iiluminate lightItem = null; string command = null; switch (commands[1]) { case "TURNON": command = "turn on"; break; case "SWITHCON": command = "switch on"; break; default: command = commands[1]; break; } commands.RemoveRange(0, 2); List <string> message = new List <string>();; Room room = Room.GetRoom(player.Player.Location); lightItem = FindLightInEquipment(commands, player, room); if (lightItem != null) { if (lightItem.isLit == false) { message = lightItem.Ignite(); message[1] = ParseMessage(message[1], player, null); } else { message.Add("It's already on!"); } } else { message.Add("You don't see anything to " + command + "."); } player.MessageHandler(message[0]); if (message.Count > 1) { room.InformPlayersInRoom(message[1], new List <string>(new string[] { player.UserID })); } }
private bool LightSourcePresent() { //foreach player/npc/item in room check to see if it is lightsource and on bool lightSource = false; //check th eplayers and see if anyones equipment is a lightsource foreach (string id in players) { User.User temp = MySockets.Server.GetAUser(id); Dictionary <Items.Wearable, Items.Iitem> equipped = temp.Player.Equipment.GetEquipment(); foreach (Items.Iitem item in equipped.Values) { Items.Iiluminate light = item as Items.Iiluminate; if (light != null && light.isLit) { lightSource = true; break; } } if (lightSource) { break; } } //check the NPCS and do the same as we did with the players if (!lightSource) { foreach (string id in npcs) { Character.Iactor actor = Character.NPCUtils.GetAnNPCByID(id); Dictionary <Items.Wearable, Items.Iitem> equipped = actor.Equipment.GetEquipment(); foreach (Items.Iitem item in equipped.Values) { Items.Iiluminate light = item as Items.Iiluminate; if (light != null && light.isLit) { lightSource = true; break; } } if (lightSource) { break; } } } //finally check for items in the room (just ones laying in the room, if a container is open check in container) if (!lightSource) { foreach (string id in items) { Items.Iitem item = Items.Items.GetByID(id); Items.Icontainer container = item as Items.Icontainer; Items.Iiluminate light = item as Items.Iiluminate; //even if container check this first. Container may have light enchanment. if (light != null && light.isLit) { lightSource = true; break; } if (container != null && (container.Contents != null && container.Contents.Count > 0) && container.Opened) //let's look in the container only if it's open { foreach (string innerId in container.Contents) { Items.Iitem innerItem = Items.Items.GetByID(id); light = innerItem as Items.Iiluminate; if (light != null && light.isLit) { lightSource = true; break; } } } if (lightSource) { break; } } } return(lightSource); }
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); }