Example #1
0
        public static void Drop(IUser player, List<string> commands) {
            //1.get the item name from the command, may have to join all the words after dropping the command
            StringBuilder itemName = new StringBuilder();
            IRoom room = Room.GetRoom(player.Player.Location);

            string full = commands[0];
            commands.RemoveAt(0);
            commands.RemoveAt(0);
            
            foreach (string word in commands) {
                itemName.Append(word + " ");
            }

            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);
                itemName = itemName.Remove(itemName.Length - 2, 2);
            }

            //2.get the item from the DB
            List<IItem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
            IItem item = items[itemPosition - 1];

			//3.have player drop item
			IMessage message = new Message();
			message.InstigatorID = player.UserID.ToString();
			message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;

            if (item != null) {
                player.Player.Inventory.RemoveInventoryItem(item, player.Player.Equipment);
                item.Location = player.Player.Location;
				item.Owner = player.UserID;
                item.Save();

                //4.Inform room and player of action
                message.Room = string.Format("{0} drops {1}", player.Player.FirstName, item.Name);
                room.InformPlayersInRoom(message, new List<ObjectId>() { player.UserID });
                message.Self = string.Format("You drop {0}", item.Name);
            }
            else {
                message.Self = "You are not carrying anything of the sorts.";
            }

			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}
		}
Example #2
0
		//TODO: this needs more work done and also need to figure out a nice way to display it to the user
		private static void DisplayStats(IUser player, List<string> commands) {
            Character.Character character = player.Player as Character.Character;
            if (character != null) {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("You are currently " + character.ActionState.ToString().ToUpper() + " and " + character.StanceState.ToString().ToUpper());
                sb.AppendLine("\nName: " + character.FirstName.CamelCaseWord() + " " + character.LastName.CamelCaseWord());
                sb.AppendLine("Level : " + character.Level); 
                sb.AppendLine("Class: " + character.Class);
                sb.AppendLine("Race: " + character.Race);
                sb.AppendLine("XP: " + (long)character.Experience);
                sb.AppendLine("Next Level XP required: " + (long)character.NextLevelExperience + " (Needed: " + (long)(character.NextLevelExperience - character.Experience) + ")");
                sb.AppendLine("\n[Attributes]");
                foreach (var attrib in player.Player.GetAttributes()) {
                    sb.AppendLine(string.Format("{0,-12}: {1}/{2,-3}    Rank: {3}",attrib.Name.CamelCaseWord(), attrib.Value, attrib.Max, attrib.Rank));
                }

                sb.AppendLine("\n[Sub Attributes]");
                foreach (var attrib in player.Player.GetSubAttributes()) {
                    sb.AppendLine(attrib.Key.CamelCaseWord() + ": \t" + attrib.Value);
                }

                sb.AppendLine("Description/Bio: " + player.Player.Description);
                player.MessageHandler(sb.ToString());
            }
		}
Example #3
0
        private static void Examine(IUser player, List<string> commands) {
            string message = "";
            bool foundIt = false;
            if (commands.Count > 2) {
                //order is room, door, items, player, NPCs

                //rooms should have a list of items that belong to the room (non removable) but which can be interacted with by the player.  For example a loose brick, oven, fridge, closet, etc.
                //in turn these objects can have items that can be removed from the room I.E. food, clothing, weapons, etc.

                IRoom room = Room.GetRoom(player.Player.Location);
                IDoor door = FindDoor(player.Player.Location, commands);

                if (door != null) {
                    message = door.Examine;
                    foundIt = true;
                }


                //TODO: For items and players we need to be able to use the dot operator to discern between multiple of the same name.
                //look for items in room, then inventory, finally equipment.  What about another players equipment?
                //maybe the command could be "examine [itemname] [playername]" or "examine [itemname] equipment/inventory"
                if (!foundIt) {
                   message = FindAnItem(commands, player, room, out foundIt);
                    
                }

                if (!foundIt) {
                    message = FindAPlayer(commands, room, out foundIt);
                    
                }
                if (!foundIt) {
                    message = FindAnNpc(commands, room, out foundIt);
                   

                }
            }

            if (!foundIt) {
                message = "Examine what?";
            }

            player.MessageHandler(message);
        }
Example #4
0
        private static void Inventory(IUser player, List<string> commands){
            List<IItem> inventoryList = player.Player.Inventory.GetInventoryAsItemList();
            StringBuilder sb = new StringBuilder();

            Dictionary<string, int> grouping = new Dictionary<string, int>();

            //let's group repeat items for easier display this may be a candidate for a helper method
            foreach (IItem item in inventoryList) {
                IContainer container = item as IContainer;
                if (!grouping.ContainsKey(item.Name)) {
                    if (!item.ItemType.ContainsKey(ItemsType.CONTAINER)) {
                        grouping.Add(item.Name, 1);
                    }
                    else{
                        grouping.Add(item.Name + " [" + (container.Opened ? "Opened" : "Closed") + "]", 1);
                        container = null;
                    }
                }
                else {
                    if (!item.ItemType.ContainsKey(ItemsType.CONTAINER)) {
                        grouping[item.Name] += 1;
                    }
                    else {
                        grouping[item.Name + " [" + (container.Opened ? "Opened" : "Closed") + "]"] += 1;
                        container = null;
                    }
                }
            }

            if (grouping.Count > 0) {
                sb.AppendLine("You are carrying:");
                foreach (KeyValuePair<string, int> pair in grouping) {
                    sb.AppendLine(pair.Key.CamelCaseString() + (pair.Value > 1 ? "[" + pair.Value + "]" : ""));
                }
                sb.AppendLine("\n\r");
            }
            else{
                sb.AppendLine("\n\r[ EMPTY ]\n\r");
            }
            
            player.MessageHandler(sb.ToString());
        }
Example #5
0
        public static void Unequip(IUser player, List<string> commands) {
            StringBuilder itemName = new StringBuilder();
            int itemPosition = 1;
			IMessage message = new Message();
			message.InstigatorID = player.UserID.ToString();
			message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;

            //they said 'all' so we are going to remove everything
            if (commands.Count > 2 && string.Equals(commands[2].ToLower(), "all", StringComparison.InvariantCultureIgnoreCase)) {
                foreach (KeyValuePair<Wearable, IItem> item in player.Player.Equipment.GetEquipment()) {
                    if (player.Player.Equipment.UnequipItem(item.Value, player.Player)) {
                    }
                }

                message.Room = string.Format("{0} removes all his equipment.", player.Player.FirstName);
            }
            else {
                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);
                    itemName = itemName.Remove(itemName.Length - 2, 2);
                }

                string full = commands[0];
                commands.RemoveAt(0);
                commands.RemoveAt(0);

                foreach (string word in commands) {
                    itemName.Append(word + " ");
                }
				
                List<IItem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
                IItem item = items[itemPosition - 1];

                if (item != null) {
                    player.Player.Equipment.UnequipItem(item, player.Player);
                    message.Room = string.Format("{0} unequips {1}", player.Player.FirstName, item.Name);
                    message.Self = string.Format("You unequip {0}", item.Name);
                }
                else {
                    if (commands.Count == 2) {
                        message.Self = "Unequip what?";
                    }
                    else {
						message.Self = "You don't seem to be equipping that at the moment.";
                    }
                }
            }

			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}
			Room.GetRoom(player.Player.Location).InformPlayersInRoom(message, new List<ObjectId>(){ player.UserID });
        }
Example #6
0
        public bool Loot(IUser looter, List<string> commands, bool bypassCheck = false) {
			bool looted = false;
            if (IsDead()) {
                List<IItem> result = new List<IItem>();
                StringBuilder sb = new StringBuilder();

				if (!bypassCheck) {
					if (CanLoot(looter.UserID)) {
						looter.MessageHandler("You did not deal the killing blow and can not loot this corpse at this time.");
						return false;
					}
				}

                if (commands.Contains("all")) {
                    sb.AppendLine("You loot the following items from " + FirstName + ":");
                    Inventory.GetInventoryAsItemList().ForEach(i => {
                        sb.AppendLine(i.Name);
                        looter.Player.Inventory.AddItemToInventory(i);
                    });
					looted = true;
                }
                else if (commands.Count > 2) { //the big one, should allow to loot individual item from the inventory
                    string itemName = Items.Items.ParseItemName(commands);
                    int index = 1;
                    int position = 1;
                    string[] positionString = commands[0].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
                    if (positionString.Count() > 1) {
                        int.TryParse(positionString[positionString.Count() - 1], out position);
                    }

                    Inventory.GetInventoryAsItemList().ForEach(i => {
                        if (string.Equals(i.Name, itemName, StringComparison.InvariantCultureIgnoreCase) && index == position) {
                            looter.Player.Inventory.AddItemToInventory(i);
                            sb.AppendLine("You loot " + i.Name + " from " + FirstName);
                            index = -1; //we found it and don't need this to match anymore
							looted = true;
                            //no need to break since we are checking on index and I doubt a player will have so many items in their inventory that it will
                            //take a long time to go through each of them
                        }
                        else {
                            index++;
                        }
                    });
                }
                else {
                    sb.AppendLine(FirstName + " is carrying: ");
                    Inventory.GetInventoryAsItemList().ForEach(i => sb.AppendLine(i.Name));
                }
            }
			return looted;
        }
Example #7
0
        private static void Loot(IUser player, List<string> commands) {
            IActor npc = null;
            string[] position = commands[0].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
            if (position.Count() > 1) {
                //ok so the player specified a specific NPC in the room list to loot and not just the first to match
                int pos;
                int.TryParse(position[position.Count() - 1], out pos);
                if (pos != 0) {
                    npc = Character.NPCUtils.GetAnNPCByID(GetObjectInPosition(pos, commands[2], player.Player.Location));
                }
            }
			if (npc == null) {
				var npcList = Character.NPCUtils.GetAnNPCByName(commands[2], player.Player.Location);
				if (npcList.Count > 1) {
					npc = npcList.SingleOrDefault(n => n.Location == player.Player.Location);
				}
				else {
					npc = npcList[0];
				}
			}
            if (npc == null) {
                npc = Character.NPCUtils.GetAnNPCByID(player.Player.CurrentTarget);
            }

            if (npc != null && npc.IsDead()) {
                npc.Loot(player, commands);
            }
            else if (npc != null && !npc.IsDead()) {
                player.MessageHandler("You can't loot what is not dead! Maybe you should try killing it first.");
            }

            //wasn't an npc we specified so it's probably a player
            if (npc == null) {
                IUser lootee = FindTargetByName(commands[commands.Count - 1], player.Player.Location);
                if (lootee != null && lootee.Player.IsDead()) {
                    lootee.Player.Loot(player, commands);
                }
                else if (lootee != null && !lootee.Player.IsDead()) {
                    player.MessageHandler("You can't loot what is not dead! Maybe you should try pickpocketing or killing it first.");
                }
                else {
                    player.MessageHandler("You can't loot what doesn't exist...unless you see dead people, but you don't.");
                }
            }

            return;
        }
Example #8
0
		private static void Sit(IUser player, List<string> commands) {
			IMessage message = new Message();
			message.InstigatorID = player.UserID.ToString();
			message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;

			if (player.Player.StanceState != CharacterStanceState.Sitting && (player.Player.ActionState == CharacterActionState.None
				|| player.Player.ActionState == CharacterActionState.Fighting)) {
				player.Player.SetStanceState(CharacterStanceState.Sitting);
				message.Self = "You sit down.";
				message.Room = String.Format("{0} sits down.", player.Player.FirstName);

			}
			else if (player.Player.ActionState != CharacterActionState.None) {
				message.Self = String.Format("You can't sit down.  You are {0}!", player.Player.ActionState.ToString().ToLower());
			}
			else {
				message.Self = String.Format("You can't sit down.  You are {0}!", player.Player.StanceState.ToString().ToLower());
			}

			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}
			Room.GetRoom(player.Player.Location).InformPlayersInRoom(message, new List<ObjectId>(){ player.UserID });
		}
Example #9
0
		private void MasterLooterLoots(IUser looter, List<string> commands, IActor npc) {
			if (string.Equals(looter.UserID, MasterLooter)) {
				npc.Loot(looter, commands, true);
			}
			else {
				looter.MessageHandler("Only the master looter can loot corpses killed by the group.");
			}
		}
Example #10
0
		private static void Give(IUser player, List<string> commands) {
			//get the item name from the command, may have to join all the words after dropping the command
			StringBuilder itemName = new StringBuilder();
			IRoom room = Room.GetRoom(player.Player.Location);

			string[] full = commands[0].Replace("give","").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
			
			foreach (string word in full) {
				if (word.ToLower() != "to") {
					itemName.Append(word + " ");
				}
				else {
					break; //we got to the end of the item name
				}
			}

			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);
				itemName = itemName.Remove(itemName.Length - 2, 2);
			}

			//get the item from the DB
			List<IItem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
			if (items.Count == 0) {
				player.MessageHandler("You can't seem to find an item by that name.");
				return;
			}
			IItem item = items[itemPosition - 1];


			string toPlayerName = commands[0].ToLower().Replace("give", "").Replace(itemName.ToString(), "").Replace("to", "").Trim();

			bool HasDotOperator = false;
			int playerPosition = 0;
			position = toPlayerName.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 playerPosition);
				HasDotOperator = true;
			}

			IUser toPlayer = null;
			List<IUser> toPlayerList = new List<IUser>();
			//we need some special logic here, first we'll try by first name only and see if we get a hit.  If there's more than one person named the same
			//then we'll see if the last name was included in the commands. And try again.  If not we'll check for the dot operator and all if else fails tell them
			//to be a bit more specific about who they are trying to directly speak to.
			string[] nameBreakDown = toPlayerName.ToLower().Split(' ');
			foreach (var id in room.GetObjectsInRoom(RoomObjects.Players, 100)) {
				toPlayerList.Add(Server.GetAUser(id));
			}

			if (toPlayerList.Where(p => p.Player.FirstName.ToLower() == nameBreakDown[0]).Count() > 1) { //let's narrow it down by including a last name (if provided)
				toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == (nameBreakDown[0] ?? "")).Where(p => String.Compare(p.Player.LastName.ToLower(), nameBreakDown[1] ?? "", true) == 0).SingleOrDefault();

				if (toPlayer == null) { //no match on full name, let's try with the dot operator if they provided one
					if (HasDotOperator && (playerPosition < toPlayerList.Count && playerPosition >= 0)) {
						toPlayer = toPlayerList[playerPosition];
					}
					else {
						toPlayer = toPlayerList[0];
					}
				}
			}
			else { //we found an exact match
				toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == (nameBreakDown[0] ?? "")).SingleOrDefault();

				if (toPlayer != null && toPlayer.UserID == player.UserID) {
					toPlayer = null; //It's the player saying something!
				}
			}

			if (toPlayer == null) { //we are looking for an npc at this point
				toPlayerList.Clear();
				foreach (var id in room.GetObjectsInRoom(RoomObjects.Npcs, 100)) {
					toPlayerList.Add(Character.NPCUtils.GetUserAsNPCFromList(new List<ObjectId>() { id }));
				}
				if (toPlayerList.Where(p => p.Player.FirstName.ToLower() == nameBreakDown[0]).Count() > 1) { //let's narrow it down by including a last name (if provided)
					toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == (nameBreakDown[0] ?? "")).Where(p => String.Compare(p.Player.LastName, nameBreakDown[1] ?? "", true) == 0).SingleOrDefault();

					if (toPlayer == null) { //no match on full name, let's try with the dot operator if they provided one
						if (HasDotOperator && (playerPosition < toPlayerList.Count && playerPosition >= 0)) {
							toPlayer = toPlayerList[playerPosition];
						}
						else {
							toPlayer = toPlayerList[0];
						}
					}
				}
				else { //we found an exact match
					toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == (nameBreakDown[0] ?? "")).SingleOrDefault();

					if (commands.Count == 2 || toPlayer != null && toPlayer.UserID == player.UserID) {
						toPlayer = null;
						player.MessageHandler("Really? Giving to yourself?.");
					}
					else if (toPlayer == null) {
						player.MessageHandler("You can't give things to someone who is not here.");
					}
				}
			}

			//have player give item
			IMessage message = new Message();

			if (item != null && toPlayer != null) {
				message.InstigatorID = player.Player.Id.ToString();
				message.InstigatorType = player.Player.IsNPC ? ObjectType.Npc : ObjectType.Player;
				message.TargetID = toPlayer.Player.Id.ToString();
				message.TargetType = toPlayer.Player.IsNPC ? ObjectType.Npc : ObjectType.Player;

				player.Player.Inventory.RemoveInventoryItem(item, player.Player.Equipment);
				player.Player.Save();

                item.Location = "";
				item.Owner = toPlayer.UserID;
				item.Save();

				toPlayer.Player.Inventory.AddItemToInventory(item);
				toPlayer.Player.Save();
				
				//Inform room and player of action
				message.Room = string.Format("{0} gives {1} to {2}", player.Player.FirstName, item.Name, toPlayer.Player.FirstName);
				message.Self = string.Format("You give {0} to {1}", item.Name, toPlayer.Player.FirstName);
				message.Target = string.Format("{0} gives you {1}", player.Player.FirstName, item.Name);

				if (toPlayer.Player.IsNPC) {
					toPlayer.MessageHandler(message);
				}
				else {
					toPlayer.MessageHandler(message.Target);
				}
			}

			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}

			room.InformPlayersInRoom(message, new List<ObjectId>() { player.UserID });
		}
Example #11
0
        private static void DeActivate(IUser player, List<string> commands) {
            //used for turning off a lightSource that can be lit.
            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);

            IMessage message = new Message();
            IRoom room = Room.GetRoom(player.Player.Location);

            lightItem = FindLightInEquipment(commands, player, room);

            if (lightItem != null) {
                if (lightItem.isLit) {
                    message = lightItem.Extinguish();
                    message.Room = string.Format(message.Room, player.Player.FirstName);
                    
                }
                else {
                    message.Self = "It's already off!";
                }
            }
            else {
                message.Self = "You don't see anything to " + command + ".";
            }

			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}
			room.InformPlayersInRoom(message, new List<ObjectId>() { player.UserID });
        }
Example #12
0
 public static void Drink(IUser player, List<string> commands) {
     IItem item = GetItem(commands, player.Player.Location);
     if (item == null) {
         player.MessageHandler("You don't seem to be carrying that to drink it.");
         return;
     }
     if (item.ItemType.ContainsKey(ItemsType.DRINKABLE)) {
         Consume(player, commands, "drink", item);
     }
     else {
         player.MessageHandler("You can't drink that!");
     }
     
 }
Example #13
0
        //container commands
        public async static void Put(IUser player, List<string> commands) {
            //this command is used only for putting an Item in the root inventory of a player into a bag.  
            //If an item needs to go from a bag to the root inventory level player should use the GET command instead.

            int itemPosition = 1;
            int containerPosition = 1;
            string itemName = "";
            string containerName = "";

           //this allows players to use either IN or INTO
            int commandIndex = 0;
            foreach (string word in commands) {
                if (string.Equals(word, "in", StringComparison.InvariantCultureIgnoreCase)) {
                    commands[commandIndex] = "into";
                    break;
                }
                commandIndex++;
            }

            var location = "";
            if (string.Equals(commands[commands.Count - 1], "inventory", StringComparison.InvariantCultureIgnoreCase)) {
                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;
            }

            List<string> commandAltered = ParseItemPositions(commands, "into", out itemPosition, out itemName);
            ParseContainerPosition(commandAltered, "", out containerPosition, out containerName);

            IItem retrievedItem = null;
            IItem containerItem = null;

            //using a recursive method we will dig down into each sub container looking for the appropriate container
            if (location.Equals(ObjectId.Empty)) {
                TraverseItems(player, containerName.ToString().Trim(), itemName.ToString().Trim(), containerPosition, itemPosition, out retrievedItem, out containerItem);

                //player is an idiot and probably wanted to put it in his inventory but didn't specify it so let's check there as well
                if (containerItem == null) {
                    foreach (IItem tempContainer in player.Player.Inventory.GetInventoryAsItemList()) {
                        containerItem = KeepOpening(containerName.CamelCaseString(), tempContainer, containerPosition);
                        if (string.Equals(containerItem.Name, containerName.CamelCaseString(), StringComparison.InvariantCultureIgnoreCase)) {
                            break;
                        }
                    }
                }
            }
            else{ //player specified it is in his inventory 
                foreach (var id in player.Player.Inventory.GetInventoryList()) {
                   IItem tempContainer = await Items.Items.GetByID(ObjectId.Parse(id));
                    containerItem = KeepOpening(containerName.CamelCaseString(), tempContainer, containerPosition);
                    if (string.Equals(containerItem.Name, containerName.CamelCaseString(), StringComparison.InvariantCultureIgnoreCase)) {
                        break;
                    }
                }
            }

            bool stored = false;

            retrievedItem = player.Player.Inventory.GetInventoryAsItemList().Where(i => i.Name == itemName).SingleOrDefault();

            if (containerItem != null  && retrievedItem != null) {
                retrievedItem.Location = containerItem.Location;
                retrievedItem.Owner = containerItem.Id;
                retrievedItem.Save();
                IContainer container = containerItem as IContainer;
                stored = container.StoreItem(retrievedItem.Id);
            }
            

            string msg = null;

            if (!stored) {
                msg = "Could not put " + itemName.ToString().Trim().ToLower() + " inside the " + containerName.ToString().Trim().ToLower() + ".";
            }
            else {
                msg = "You place " + itemName.ToString().Trim().ToLower() + " inside the " + containerName.ToString().Trim().ToLower() + ".";
            }

            player.MessageHandler(msg);
        }
Example #14
0
		//a tell is a private message basically, location is not a factor
		private static void Tell(IUser player, List<string> commands) {
			IMessage message = new Message();
			message.InstigatorID = player.Player.Id.ToString();
			message.InstigatorType = player.Player.IsNPC ? ObjectType.Npc : ObjectType.Player;

			List<IUser> toPlayerList = Server.GetAUserByFirstName(commands[2]).ToList();
			IUser toPlayer = null;
			
			if (commands[2].ToUpper() == "SELF") {
				message.Self = "You go to tell yourself something when you realize you already know it.";
				return;
			}

			if (toPlayerList.Count < 1) {
				message.Self = "There is no one named " + commands[2].CamelCaseWord() + " to tell something.";
			}
			else if (toPlayerList.Count > 1) { //let's narrow it down by including a last name (if provided)
				toPlayer = toPlayerList.Where(p => String.Compare(p.Player.LastName, commands[3], true) == 0).SingleOrDefault();
			}
			else {
				toPlayer = toPlayerList[0];
				if (toPlayer.UserID == player.UserID) {
					player.MessageHandler("You tell yourself something important.");
					return;
				}
			}

		   bool fullName = true;
			if (toPlayer == null) {
				message.Self = "There is no one named " + commands[2].CamelCaseWord() + " to tell something.";
			}
			else {
				message.TargetID = toPlayer.Player.Id.ToString();
				message.InstigatorType = toPlayer.Player.IsNPC ? ObjectType.Npc : ObjectType.Player;

				int startAt = commands[0].ToLower().IndexOf(toPlayer.Player.FirstName.ToLower() + " " + toPlayer.Player.LastName.ToLower());
				if (startAt == -1 || startAt > 11) {
					startAt = commands[0].ToLower().IndexOf(toPlayer.Player.FirstName.ToLower());
					fullName = false;
				}

				if (startAt > 11) startAt = 11 + toPlayer.Player.FirstName.Length + 1;
				else startAt += toPlayer.Player.FirstName.Length + 1;
				if (fullName) startAt += toPlayer.Player.LastName.Length + 1;

				if (commands[0].Length > startAt) {
					string temp = commands[0].Substring(startAt);
					message.Self = "You tell " + toPlayer.Player.FirstName + " \"" + temp + "\"";
					message.Target = player.Player.FirstName + " tells you \"" + temp + "\"";
                }
				else {
					message.Self = "You have nothing to tell them.";
				}
			}

			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}
			if (toPlayer.Player.IsNPC) {
				toPlayer.MessageHandler(message);
			}
			else {
				toPlayer.MessageHandler(message.Target);
			}
		}
Example #15
0
        public static void Equip(IUser player, List<string> commands) {
            StringBuilder itemName = new StringBuilder();
            int itemPosition = 1;
			IMessage message = new Message();
			message.InstigatorID = player.UserID.ToString();
			message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;

            //we need to make a list of items to wear from the players inventory and sort them based on stats
            if (commands.Count > 2 && string.Equals(commands[2].ToLower(), "all", StringComparison.InvariantCultureIgnoreCase)) {
                foreach (IItem item in player.Player.Inventory.GetAllItemsToWear()) {
                    if (player.Player.Equipment.EquipItem(item, player.Player.Inventory)) {
                        message.Self += string.Format("You equip {0}.\n", item.Name);
                        message.Room += string.Format("{0} equips {1}.\n", player.Player.FirstName, item.Name);
                    }
                }
            }
            else {
                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);
                    itemName = itemName.Remove(itemName.Length - 2, 2);
                }

                string full = commands[0];
                commands.RemoveRange(0, 2);

                foreach (string word in commands) {
                    itemName.Append(word + " ");
                }

                List<IItem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
                
                //players need to specify an indexer or we will just give them the first one we found that matched
                IItem item = items[itemPosition - 1];

                IWeapon weapon = item as IWeapon;

                if (item != null && item.IsWearable) {
                    player.Player.Equipment.EquipItem(item, player.Player.Inventory);
                    if (item.ItemType.ContainsKey(ItemsType.CONTAINER)) {
                        IContainer container = item as IContainer;
                        container.Wear();
                    }
                    if (item.ItemType.ContainsKey(ItemsType.CLOTHING)) {
                        IClothing clothing = item as IClothing;
                        clothing.Wear();
                    }

                    message.Room = string.Format("{0} equips {1}.", player.Player.FirstName, item.Name);
                    message.Self = string.Format("You equip {0}.", item.Name);
                }
                else if (weapon.IsWieldable) {
                    message.Self = "This item can only be wielded not worn.";
                }
                else if (!item.IsWearable || !weapon.IsWieldable) {
                    message.Self = "That doesn't seem like something you can wear.";
                }
                else {
                    message.Self = "You don't seem to have that in your inventory to be able to wear.";
                }
            }

			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}
			Room.GetRoom(player.Player.Location).InformPlayersInRoom(message, new List<ObjectId>(){ player.UserID });
        }
Example #16
0
		//a whisper is a private message but with a chance that other players may hear what was said, other player has to be in the same room
		//TODO: need to add the ability for others to listen in on the whisper if they have the skill
		private static void Whisper(IUser player, List<string> commands){
			IMessage message = new Message();
			message.InstigatorID = player.Player.Id.ToString();
			message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;

			List<IUser> toPlayerList = new List<IUser>();
            IRoom room = Room.GetRoom(player.Player.Location);
			if (commands.Count > 2){
				if (commands[2].ToUpper() == "SELF") {
					message.Self = "You turn your head towards your own shoulder and whisper quietly to yourself.";
					message.Room = (room.IsDark == true ? "Someone" : player.Player.FirstName) + " whispers into " + player.Player.Gender == "MALE" ? "his" : "her" + " own shoulder.";
				}

				toPlayerList = Server.GetAUserByFirstName(commands[2]).Where(p => p.Player.Location == player.Player.Location).ToList();
			}	

			IUser toPlayer = null;

			if (toPlayerList.Count < 1) {
				player.MessageHandler("You whisper to no one. Creepy.");
				return;
			}
			else if (toPlayerList.Count > 1) { //let's narrow it down by including a last name (if provided)
				toPlayer = toPlayerList.Where(p => String.Compare(p.Player.LastName, commands[3], true) == 0).SingleOrDefault();
			}
			else {
				if (toPlayerList.Count == 1) {
					toPlayer = toPlayerList[0];
				}
				if (commands.Count == 2 || toPlayer.UserID == player.UserID) {
						player.MessageHandler("You realize you have nothing to whisper about.");
						return;
					}
			}

			bool fullName = true;
			if (toPlayer == null) {
				message.Self = "You try and whisper to " + commands[2].CamelCaseWord() + " but they're not around.";
			}
			else {
				message.TargetID = toPlayer.Player.Id.ToString();
				message.TargetType = player.Player.IsNPC ? ObjectType.Npc : ObjectType.Player;

				int startAt = commands[0].ToLower().IndexOf(toPlayer.Player.FirstName.ToLower() + " " + toPlayer.Player.LastName.ToLower());
				if (startAt == -1 || startAt > 11) {
					startAt = commands[0].ToLower().IndexOf(toPlayer.Player.FirstName.ToLower());
					fullName = false;
				}

				if (startAt > 11) startAt = 11 + toPlayer.Player.FirstName.Length + 1;
				else startAt += toPlayer.Player.FirstName.Length + 1;
				if (fullName) startAt += toPlayer.Player.LastName.Length + 1;

				if (commands[0].Length > startAt) {
					string whisper = commands[0].Substring(startAt);
					message.Self = "You whisper to " + toPlayer.Player.FirstName + " \"" + whisper + "\"";
					message.Target = (room.IsDark == true ? "Someone" : player.Player.FirstName) + " whispers to you \"" + whisper + "\"";
					//this is where we would display what was whispered to players with high perception?
					message.Room = (room.IsDark == true ? "Someone" : player.Player.FirstName) + " whispers something to " + toPlayer.Player.FirstName;
				}
			}

			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}
			room.InformPlayersInRoom(message, new List<ObjectId>(){ player.UserID, !toPlayer.Equals(ObjectId.Empty) ? toPlayer.UserID : ObjectId.Empty});
			
		}
Example #17
0
		private static void SayTo(IUser player, List<string> commands) {
			IMessage message = new Message();
			
			string temp = "";
			if (commands[0].Length > 5)
				temp = commands[0].Substring(6);
			else {
				if (!player.Player.IsNPC) {
					player.MessageHandler("You decide to stay quiet since you had nothing to say.");
					return;
				}
			}

			//let's check for dot operator
			bool HasDotOperator = false;
			int playerPosition = 0;
			string[] position = commands[2].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 playerPosition);
				HasDotOperator = true;
			}
			IRoom room = Room.GetRoom(player.Player.Location);
			IUser toPlayer = null;
			List<IUser> toPlayerList = new List<IUser>();
			//we need some special logic here, first we'll try by first name only and see if we get a hit.  If there's more than one person named the same
			//then we'll see if the last name was included in the commands. And try again.  If not we'll check for the dot operator and all if else fails tell them
			//to be a bit more specific about who they are trying to directly speak to.
			string[] nameBreakDown = commands[0].ToLower().Split(' ');
			foreach (var id in room.GetObjectsInRoom(RoomObjects.Players, 100)) {
				toPlayerList.Add(Server.GetAUser(id));
			}
			
			if (toPlayerList.Where(p => p.Player.FirstName.ToLower() == nameBreakDown[1]).Count() > 1) { //let's narrow it down by including a last name (if provided)
				toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == nameBreakDown[1]).Where(p => String.Compare(p.Player.LastName, nameBreakDown[2], true) == 0).SingleOrDefault();

				if (toPlayer == null) { //no match on full name, let's try with the dot operator if they provided one
					if (HasDotOperator && (playerPosition < toPlayerList.Count && playerPosition >= 0)) {
						toPlayer = toPlayerList[playerPosition];
					}
					else {
						toPlayer = toPlayerList[0];
					}
				}
			}
			else { //we found an exact match
				toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == nameBreakDown[1]).SingleOrDefault();
				
				if (toPlayer != null && toPlayer.UserID == player.UserID) {
					toPlayer = null; //It's the player saying something!
				}
			}

			if (toPlayer == null) { //we are looking for an npc at this point
				toPlayerList.Clear();
				foreach (var id in room.GetObjectsInRoom(RoomObjects.Npcs, 100)) {
					toPlayerList.Add(Character.NPCUtils.GetUserAsNPCFromList(new List<ObjectId>() { id }));
				}
				if (toPlayerList.Where(p => p.Player.FirstName.ToLower() == nameBreakDown[1]).Count() > 1) { //let's narrow it down by including a last name (if provided)
					toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == nameBreakDown[1]).Where(p => String.Compare(p.Player.LastName, nameBreakDown[2], true) == 0).SingleOrDefault();

					if (toPlayer == null) { //no match on full name, let's try with the dot operator if they provided one
						if (HasDotOperator && (playerPosition < toPlayerList.Count && playerPosition >= 0)) {
							toPlayer = toPlayerList[playerPosition];
						}
						else {
							toPlayer = toPlayerList[0];
						}
					}
				}
				else { //we found an exact match
					toPlayer = toPlayerList.Where(p => p.Player.FirstName.ToLower() == nameBreakDown[1]).SingleOrDefault();
					
					if (commands.Count == 2 || toPlayer != null && toPlayer.UserID == player.UserID) {
						toPlayer = null;
						player.MessageHandler("You realize you have nothing to say that you don't already know.");
					}
					else if (toPlayer == null) {
						player.MessageHandler("That person is not here.  You can't speak directly to them.");
					}
				}
			}

			if (toPlayer != null) {
				if (temp.ToLower().StartsWith(toPlayer.Player.FirstName.ToLower())) {
					temp = temp.Substring(toPlayer.Player.FirstName.Length);
				}
				if (temp.ToLower().StartsWith(toPlayer.Player.LastName.ToLower())) {
					temp = temp.Substring(toPlayer.Player.LastName.Length);
				}
				temp = temp.Trim();
				message.Self = "You say to " + (room.IsDark == true ? "Someone" : toPlayer.Player.FirstName) + " \"" + temp + "\"";
				message.Target = (room.IsDark == true ? "Someone" : player.Player.FirstName) + " says to you \"" + temp + "\"";
				message.Room = (room.IsDark == true ? "Someone" : player.Player.FirstName) + " says to " + (room.IsDark == true ? "Someone" : toPlayer.Player.FirstName) + " \"" + temp + "\"";

				message.InstigatorID = player.Player.Id.ToString();
				message.InstigatorType = player.Player.IsNPC ? ObjectType.Npc : ObjectType.Player;
				message.TargetID = toPlayer.UserID.ToString();
				message.TargetType = player.Player.IsNPC ? ObjectType.Npc : ObjectType.Player;

				if (player.Player.IsNPC) {
					player.MessageHandler(message);
				}
				else {
					player.MessageHandler(message.Self);
				}

				if (toPlayer.Player.IsNPC) {
					toPlayer.MessageHandler(message);
				}
				else {
					toPlayer.MessageHandler(message.Target);
				}

				room.InformPlayersInRoom(message, new List<ObjectId>() { player.UserID, toPlayer.UserID });
			}
		}
Example #18
0
 private static void LevelUp(IUser player, List<string> commands) {
     Character.Character temp = player.Player as Character.Character;
     //if we leveled up we should have gotten points to spend assigned before we eve get here
     if (temp != null && (temp.PointsToSpend > 0 || temp.IsLevelUp)) {
         if (temp.Experience >= temp.NextLevelExperience || temp.Leveled) {
             player.Player.Level += 1;
             temp.Leveled = false;
         }
         player.CurrentState = UserState.LEVEL_UP;
     }
     else {
         player.MessageHandler("You do not have enough Experience, or points to spend to perform this action.");
     }
 }
Example #19
0
		private static void Say(IUser player, List<string> commands) {
			IMessage message = new Message();
						
			string temp ="";
            if (commands[0].Length > 4)	temp = commands[0].Substring(4).Trim();
            else{
                if (!player.Player.IsNPC) {
                    player.MessageHandler("You decide to stay quiet since you had nothing to say.");
                    return;
                }
            }
            IRoom room = Room.GetRoom(player.Player.Location);

			message.Self = "You say \"" + temp + "\"";
			message.Room = (room.IsDark == true ? "Someone" : player.Player.FirstName) + " says \"" + temp + "\"";
			message.InstigatorID = player.Player.Id.ToString();
			message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;

			if (player.Player.IsNPC) {
				message.InstigatorType = ObjectType.Npc;
				player.MessageHandler(message);

			}
			else {
				player.MessageHandler(message.Self);
			}

			room.InformPlayersInRoom(message, new List<ObjectId>(){ player.UserID }); 
		}
Example #20
0
		private static void Emote(IUser player, List<string> commands) {
			IMessage message = new Message();
						
			string temp = "";
			if (commands[0].Trim().Length > 6) {
				temp = commands[0].Substring(6).Trim();
			}
			else {
				message.Self = "You go to do something but what?.";
			}

            if (!player.Player.IsNPC && !string.IsNullOrEmpty(temp)) {
                message.Self = player.Player.FirstName + " " + temp + (temp.EndsWith(".") == false ? "." : "");
            }

            IRoom room = Room.GetRoom(player.Player.Location);
			message.Room = (room.IsDark == true ? "Someone" : player.Player.FirstName) + " " + temp + (temp.EndsWith(".") == false ? "." : "");
			message.InstigatorID = player.Player.Id.ToString();
			message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;
			player.MessageHandler(message.Self);
            room.InformPlayersInRoom(message, new List<ObjectId>(){ player.UserID });
		}
Example #21
0
        public static void Wield(IUser player, List<string> commands) {
            StringBuilder itemName = new StringBuilder();
            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);
                itemName = itemName.Remove(itemName.Length - 2, 2);
            }

            string full = commands[0];
            commands.RemoveRange(0, 2);
                        
            foreach (string word in commands) {
                itemName.Append(word + " ");
            }

			IMessage message = new Message();
			message.InstigatorID = player.UserID.ToString();
			message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;

            List<IItem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
            IItem item = items[itemPosition - 1];
            
            IWeapon weapon = (IWeapon)item;
            
            if (weapon != null && weapon.IsWieldable && player.Player.Equipment.GetWieldedWeapons().Count < 2) {
                if (string.IsNullOrEmpty(player.Player.MainHand)) { //no mainhand assigned yet
                    player.Player.MainHand = Wearable.WIELD_RIGHT.ToString(); //we will default to the right hand
                }
                
                player.Player.Equipment.Wield(item, player.Player.Inventory);
                item.Save();
                //TODO: check weapon for any wield perks/curses

                message.Room = string.Format("{0} wields {1}", player.Player.FirstName, item.Name);
                message.Self = string.Format("You wield {0}", item.Name);
            }
            else if (player.Player.Equipment.GetWieldedWeapons().Count == 2) {
                message.Self =  "You are already wielding two weapons...and you don't seem to have a third hand.";
            }
            else if (item.IsWearable) {
				message.Self = "This item can only be wielded not worn.";
            }
            else if (!item.IsWearable) {
				message.Self = "That not something you can wear or would want to wear.";
            }
            else {
				message.Self = "You don't seem to have that in your inventory to be able to wear.";
            }

			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}

			Room.GetRoom(player.Player.Location).InformPlayersInRoom(message, new List<ObjectId>() { player.UserID });
		}
Example #22
0
		private static void Who(IUser player, List<string> commands) {
			StringBuilder sb = new StringBuilder();
			sb.AppendLine("PlayerName");
			sb.AppendLine("----------");
			Server.GetCurrentUserList()
				.Where(u => u.CurrentState == UserState.TALKING)
				.OrderBy(u => u.Player.FirstName)
				.ToList()
				.ForEach(u => sb.AppendLine(u.Player.FirstName + " " + u.Player.LastName));
			
			player.MessageHandler(sb.ToString());
		}
Example #23
0
        private static void Consume(IUser player, List<string> commands, string action, IItem item){
            string upDown = "gain";
			IMessage message = new Message();
                                   
            Dictionary<string, double> affectAttributes = null;
            
            IEdible food = item as IEdible;
            affectAttributes = food.Consume();
            
            foreach (KeyValuePair<string, double> attribute in affectAttributes) {
                player.Player.ApplyEffectOnAttribute(attribute.Key.CamelCaseWord(), attribute.Value);
                if (attribute.Value < 0) {
                    upDown = "lost";
                }

                message.Self += string.Format("You {0} {1} and {2} {3:F1} points of {4}.\n", action, item.Name, upDown, Math.Abs(attribute.Value), attribute.Key);
                message.Room = string.Format("{0} {1}s {2}", player.Player.FirstName.CamelCaseWord(), action, item.Name);
            }

            //now remove it from the players inventory
            player.Player.Inventory.RemoveInventoryItem(item, player.Player.Equipment);

            //item has been consumed so get rid of it from the DB
            MongoUtils.MongoData.GetCollection<Items.Items>("World", "Items").DeleteOneAsync<Items.Items>(i => i.Id == item.Id);

            Room.GetRoom(player.Player.Location).InformPlayersInRoom(message, new List<ObjectId> { player.UserID });
			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}
		}
Example #24
0
		private static void Help(IUser player, List<string> commands) {
			StringBuilder sb = new StringBuilder();

            if (commands.Count < 3 || commands.Contains("all")) { //display just the names
                var cursor = MongoUtils.MongoData.RetrieveObjects<BsonDocument>("Commands", "Help", null);
                foreach (BsonDocument doc in cursor) {
                    sb.AppendLine(doc["_id"].ToString());
                }
            }
            else { //user specified a specific command so we will display the explanation and example
                var doc = MongoUtils.MongoData.RetrieveObject<BsonDocument>("Commands", "Help", b => b["_id"] == commands[2].ToUpper());
                sb.AppendLine(doc["_id"].ToString());
                sb.AppendLine(doc["explanation"].AsString);
                sb.AppendLine(doc["Example"].AsString);
            }
            
			player.MessageHandler(sb.ToString());
		}
Example #25
0
        //TODO: had a bug where I removed item form a container, shut down the game and then both container and player still had the same item (the player even had it duped)
        //needless to say this is bad and fail.
        public static void Get(IUser player, List<string> commands) {
            int itemPosition = 1;
            int containerPosition = 1;
            string itemName = "";
            string containerName = "";

            List<string> commandAltered = ParseItemPositions(commands, "from", out itemPosition, out itemName);
			if (commands.Count >= 3) {
				ParseContainerPosition(commandAltered, commands[3], out containerPosition, out containerName);
			}
          
            var location = player.Player.Location;
           
            IItem retrievedItem = null;
            IItem containerItem = null;
            
            //using a recursive method we will dig down into each sub container and look for the appropriate item/container
            TraverseItems(player, containerName.ToString().Trim(), itemName.ToString().Trim(), containerPosition, itemPosition, out retrievedItem, out containerItem);

			IMessage message = new Message();

            if (retrievedItem != null) {
                IContainer container = containerItem as IContainer;
                if (containerItem != null) {
                    retrievedItem = container.RetrieveItem(retrievedItem.Id);
                    message.Self = "You take " + retrievedItem.Name.ToLower() + " out of " + containerItem.Name.ToLower() + ".";

                    message.Room = string.Format("{0} takes {1} out of {2}", player.Player.FirstName, retrievedItem.Name.ToLower(), containerItem.Name.ToLower());
                    
                }
                else {
					message.Self = "You get " + retrievedItem.Name.ToLower();
					message.Room = string.Format("{0} grabs {1}.", player.Player.FirstName, retrievedItem.Name.ToLower());
                }

                retrievedItem.Location = "";
                retrievedItem.Owner = player.UserID;
                retrievedItem.Save();
                player.Player.Inventory.AddItemToInventory(retrievedItem);
            }
            else {
				message.Self = "You can't seem to find " + itemName.ToString().Trim().ToLower() + " to grab it.";
            }

            Room.GetRoom(player.Player.Location).InformPlayersInRoom(message, new List<ObjectId>(){ player.UserID });
			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}

		}
Example #26
0
        public static async void ReportBug(IUser player, List<string> commands) {
            MongoUtils.MongoData.ConnectToDatabase();
            var bugCollection = MongoUtils.MongoData.GetCollection<BsonDocument>("Logs", "Bugs");

            BsonDocument doc = new BsonDocument{
                { "ReportedBy", BsonValue.Create(player.UserID) },
                { "DateTime", BsonValue.Create(DateTime.Now.ToUniversalTime()) },
                { "Resolved", BsonValue.Create(false) },
                { "Issue", BsonValue.Create(commands[0].Substring("bug".Length + 1)) }
            };

            await bugCollection.InsertOneAsync(doc);

            if (player.Player != null) { //could be an internal bug being reported
                player.MessageHandler("Your bug has been reported, thank you.");
            }
        }
Example #27
0
        private static void Activate(IUser player, List<string> commands) {
            //used for lighting up a lightSource that can be lit.
            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);
            IMessage message = new Message();
			IRoom room = Room.GetRoom(player.Player.Location);

            
            lightItem = FindLightInEquipment(commands, player, room);
            

            if (lightItem != null) {

                if (lightItem.isLit == false) {
                    message = lightItem.Ignite();
                    message.Room = ParseMessage(message.Room, player, null);
                }
                else {
                    message.Self = "It's already on!";
                }
            }
            else {
                message.Self ="You don't see anything to " + command + ".";
            }

			if (player.Player.IsNPC) {
				player.MessageHandler(message);
			}
			else {
				player.MessageHandler(message.Self);
			}
			room.InformPlayersInRoom(message, new List<ObjectId>() { player.UserID });
            
        }
Example #28
0
        private static void Equipment(IUser player, List<string> commands) {
            Dictionary<Wearable, IItem> equipmentList = player.Player.Equipment.GetEquipment();
            StringBuilder sb = new StringBuilder();

            if (equipmentList.Count > 0) {
                sb.AppendLine("You are equipping:");
                foreach (KeyValuePair<Wearable, IItem> pair in equipmentList) {
                    sb.AppendLine("[" + pair.Key.ToString().Replace("_", " ").CamelCaseWord() + "] " + pair.Value.Name);
                }
                sb.AppendLine("\n\r");
            }
            else {
                sb.AppendLine("\n\r[ EMPTY ]\n\r");
            }

            player.MessageHandler(sb.ToString());
        }
Example #29
0
		//The group commands will basically follow this following format: 
		//group create The Ragtag Squad
		//group invite willy wonka
		//group disband
		//this will further parse the command line and call the appropriate group commands
		public static void Group(IUser player, List<string> commands) {
			bool inGroup = !string.IsNullOrEmpty(player.GroupName);
			string name = RemoveWords(commands[0]);
			IUser user = null;
			if (commands.Count > 2) {
				switch (commands[2]) {
					case "create":
						Groups.Groups.GetInstance().CreateGroup(player.UserID, name);
						break;
					case "disband":
						Groups.Groups.GetInstance().DisbandGroup(player.UserID, player.GroupName);
						break;
					case "accept":
						Groups.Groups.GetInstance().AcceptDenyJoinRequest(player.UserID, name, true);
						break;
					case "deny":
						Groups.Groups.GetInstance().AcceptDenyJoinRequest(player.UserID, name, false);
						break;
					case "promote":
						user = Server.GetAUserByFullName(name); 
						if (user == null){
							user = Server.GetAUserByFirstName(name).FirstOrDefault(); 
						}

						if (user != null) {
							Groups.Groups.GetInstance().PromoteToLeader(player.UserID, player.GroupName, user.UserID);
						}
						else {
							player.MessageHandler("No player by that name was found.  If you only used a first name try including the last name as well.");
						}
						break;
					case "join":
						Groups.Groups.GetInstance().Join(player.UserID, name);
						break;
					case "invite":
						Groups.Groups.GetInstance().InviteToGroup(player.UserID, name, player.GroupName);
						break;
					case "decline":
						Groups.Groups.GetInstance().DeclineInvite(player.UserID, name);
						break;
					case "uninvite":
						Groups.Groups.GetInstance().Uninvite(player.UserID, name, player.GroupName);
						break;
					case "kick":
					case "remove":
						Groups.Groups.GetInstance().RemovePlayerFromGroup(player.UserID, name, player.GroupName);
						break;
					case "list":
						if (string.IsNullOrEmpty(name) || name.ToLower() == "all") {
							player.MessageHandler(Groups.Groups.GetInstance().GetGroupNameOnlyList());
						}
						else {
							player.MessageHandler(Groups.Groups.GetInstance().GetAllGroupInfo(name));
						}
						break;
					case "request":
						Groups.Groups.GetInstance().RequestGroupJoin(player.UserID, name);
						break;
					case "master":
						user = Server.GetAUserByFullName(name);
						if (user == null) {
							user = Server.GetAUserByFirstName(name).FirstOrDefault();
						}
						if (user == null) {
							player.MessageHandler("No player by that name was found.  If you only used a first name try including the last name as well.");
						}
						else {
							Groups.Groups.GetInstance().AssignMasterLooter(player.UserID, name, player.GroupName);
						}
						break;
					case "lootrule":
						Groups.GroupLootRule newRule = Groups.GroupLootRule.Leader_only;
						switch (commands[3]) {
							case "master":
								newRule = Groups.GroupLootRule.Master_Looter;
								break;
							case "leader":
								newRule = Groups.GroupLootRule.Leader_only;
								break;
							case "chance":
								newRule = Groups.GroupLootRule.Chance_Loot;
								break;
							case "first":
								newRule = Groups.GroupLootRule.First_to_loot;
								break;
							case "next":
								newRule = Groups.GroupLootRule.Next_player_loots;
								break;
						}
						Groups.Groups.GetInstance().ChangeLootingRule(player.UserID, player.GroupName, newRule);
						break;
					case "joinrule":
						Groups.GroupJoinRule joinRule = Groups.GroupJoinRule.Friends_only;
						if (commands.Count > 3) {
							switch (commands[3]) {
								case "friends":
									joinRule = Groups.GroupJoinRule.Friends_only;
									break;
								case "open":
									joinRule = Groups.GroupJoinRule.Open;
									break;
								case "request":
									joinRule = Groups.GroupJoinRule.Request;
									break;
							}
							Groups.Groups.GetInstance().ChangeJoiningRule(player.UserID, player.GroupName, joinRule);
						}
						else {
							player.MessageHandler("What rule do you want to change to?");
						}
						break;
					case "visibility":
						Groups.GroupVisibilityRule visibilityRule = Groups.GroupVisibilityRule.Private;
						switch (commands[3]) {
							case "private":
								visibilityRule = Groups.GroupVisibilityRule.Private;
								break;
							case "public":
								visibilityRule = Groups.GroupVisibilityRule.Public;
								break;
						}
						Groups.Groups.GetInstance().ChangeVisibilityRule(player.UserID, player.GroupName, visibilityRule);
						break;
					case "say":
						Groups.Groups.GetInstance().Say(name, player.GroupName, player.UserID);
						break;
				}
			}
			else {
				player.MessageHandler("Anything in particular you want to do with a group?");
			}
		}
Example #30
0
        //called from the MOVE command
        private static void ApplyRoomModifier(IUser player) {
            StringBuilder sb = new StringBuilder();
            IMessage message = new Message();
            message.InstigatorID = player.UserID.ToString();
            message.InstigatorType = player.Player.IsNPC == false ? ObjectType.Player : ObjectType.Npc;
            //Todo:  Check the player bonuses to see if they are immune or have resistance to the modifier
            foreach (var modifier in Room.GetModifierEffects(player.Player.Location)) {
                player.Player.ApplyEffectOnAttribute("Hitpoints", (double)modifier["Value"]);

                double positiveValue = (double)modifier["Value"];
                if (positiveValue < 0) {
                    positiveValue *= -1;
                }

                sb.Append(String.Format((string)modifier["DescriptionSelf"], positiveValue));
                if (!player.Player.IsNPC) {
                    message.Self = "\r" + sb.ToString();
                }
                sb.Clear();
                sb.Append(String.Format((string)modifier["DescriptionOthers"], player.Player.FirstName,
                           player.Player.Gender.ToString() == "Male" ? "he" : "she", positiveValue));

                message.Room = "\r" + sb.ToString();
                Room.GetRoom(player.Player.Location).InformPlayersInRoom(message, new List<ObjectId>() { player.UserID });
                if (player.Player.IsNPC) {
                    player.MessageHandler(message);
                } else {
                    player.MessageHandler(message.Self);
                }
            }
        }