/// <summary> /// Informs all parties of the outcome of the combat round. /// </summary> /// <param name="player"></param> /// <param name="enemy"></param> /// <param name="room"></param> /// <param name="damage"></param> /// <param name="defense"></param> /// <param name="attack"></param> private static void SendRoundOutcomeMessage(User.User player, User.User enemy, Room room, double damage, double defense, double attack) { //TODO: Get the message based weapon type/special weapon (blunt, blade, axe, pole, etc.) //Get the weapon type and append it to the "Hit" or "Miss" type when getting the message //ex: HitSword, HitClub, MissAxe, MissUnarmed could even get really specific HitRustyShortSword, MissLegendaryDaggerOfBlindness //Make a method to figure out the type by having a lookup table in the DB that points to a weapon type string if (damage < 0) { player.MessageHandler(ParseMessage(GetMessage("Combat", "Hit", MessageType.Self), player, enemy, damage, defense, attack)); enemy.MessageHandler(ParseMessage(GetMessage("Combat", "Hit", MessageType.Target), player, enemy, damage, defense, attack)); string roomMessage = ParseMessage(GetMessage("Combat", "Hit", MessageType.Room), player, enemy, damage, defense, attack); room.InformPlayersInRoom(roomMessage, new List <string>(new string[] { player.UserID, enemy.UserID })); enemy.Player.ApplyEffectOnAttribute("Hitpoints", damage); Character.NPC npc = enemy.Player as Character.NPC; if (npc != null) { npc.IncreaseXPReward(player.UserID, (damage * -1.0)); } } else { player.MessageHandler(ParseMessage(GetMessage("Combat", "Miss", MessageType.Self), player, enemy, damage, defense, attack)); enemy.MessageHandler(ParseMessage(GetMessage("Combat", "Miss", MessageType.Target), player, enemy, damage, defense, attack)); string roomMessage = ParseMessage(GetMessage("Combat", "Miss", MessageType.Room), player, enemy, damage, defense, attack); room.InformPlayersInRoom(roomMessage, new List <string>(new string[] { player.UserID, enemy.UserID })); } }
private static bool BreakDoor(User.User player, List <string> commands) { Door door = FindDoor(player.Player.Location, commands); if (door == null) { return(false); } if (door.Destroyed) { player.MessageHandler(GetMessage("Messages", "AlreadyBroken", MessageType.Self)); return(true); } double attack = CalculateAttack(player, 0); double defense = CalculateDefense(door); double damage = attack - defense; List <string> message = door.ApplyDamage(damage); door.UpdateDoorStatus(); player.MessageHandler(message[0].FontColor(Utils.FontForeColor.RED)); Rooms.Room.GetRoom(player.Player.Location).InformPlayersInRoom(String.Format(message[1], player.Player.FirstName), new List <string>(new string[] { player.UserID })); return(true); }
static public void ParseCommands(User.User player) { List <string> commands = ParseCommandLine(player.InBufferPeek); bool commandFound = false; foreach (Dictionary <string, CommandDelegate> AvailableCommands in CommandsList) { if (AvailableCommands.ContainsKey(commands[1].ToUpper())) { AvailableCommands[commands[1].ToUpper()](player, commands); commandFound = true; break; } } //if all else fails auto-attack if (player.Player.InCombat && player.Player.CurrentTarget != null) { //auto attack! or we could remove this and let a player figure out on their own they're being attacked commands.Clear(); commands.Add("KILL"); commands.Add("target"); commands.Insert(0, commands[0] + " " + commands[1]); } if (!commandFound && CombatCommands.ContainsKey(commands[1].ToUpper())) //check to see if player provided a combat related command { CombatCommands[commands[1].ToUpper()](player, commands); commandFound = true; commands[0] = player.InBuffer; //just removing the command from the queue now commands.Clear(); } if (commands.Count == 0) { return; } //maybe this command shouldn't be a character method call...we'll see if (commands.Count >= 2 && commands[1].ToLower() == "save") { player.Player.Save(); player.MessageHandler("Save succesful!\r\n"); commandFound = true; } if (!commandFound && commands[0].Length > 0) { player.MessageHandler("I don't know what you're trying to do, but that's not going to happen."); } commands[0] = player.InBuffer; //remove command from queue }
private static void OpenDoor(User.User player, Door door) { if (!player.Player.InCombat) { List <string> message = new List <string>(); Room room = Room.GetRoom(player.Player.Location); if (!room.IsDark) { if (door.Openable) { if (!door.Open && !door.Locked && !door.Destroyed) { door.Open = true; door.UpdateDoorStatus(); message.Add(String.Format("You open {0} {1}.", GetArticle(door.Description[0]), door.Description)); message.Add(String.Format("{0} opens {1} {2}.", player.Player.FirstName, GetArticle(door.Description[0]), door.Description)); } else if (door.Open && !door.Destroyed) { message.Add("It's already open."); } else if (door.Locked && !door.Destroyed) { message.Add("You can't open it because it is locked."); } else if (door.Destroyed) { message.Add("It's more than open it's in pieces!"); } } else { message.Add("It can't be opened."); } } else { message.Add("You can't see anything! Let alone what you are trying to open."); } player.MessageHandler(message[0]); if (message.Count > 1) { room.InformPlayersInRoom(message[1], new List <string>(new string[] { player.UserID })); } } else { player.MessageHandler("You are in the middle of combat, there are more pressing matters at hand than opening something."); } }
/// <summary> /// Informs everyone of the state change the player just went through as a result of combat, either killed or knocked out /// </summary> /// <param name="player"></param> /// <param name="enemy"></param> /// private static void SendDeadOrUnconciousMessage(User.User player, User.User enemy, bool dead = false) { player.Player.ClearTarget(); string status = dead == true ? "Killed" : "KnockedUnconcious"; player.MessageHandler(ParseMessage(GetMessage("Combat", status, MessageType.Self), player, enemy)); player.MessageHandler(ParseMessage(GetMessage("Combat", status, MessageType.Target), player, enemy)); Room.GetRoom(player.Player.Location).InformPlayersInRoom(ParseMessage(GetMessage("Combat", status, MessageType.Room), player, enemy), new List <string>(new string[] { player.UserID, enemy.UserID })); if (dead) { SetKiller(enemy, player); } SetCombatTimer(player, enemy); }
private static void Emote(User.User player, List<string> commands) { string temp = ""; if (commands[0].Trim().Length > 6) temp = commands[0].Substring(6).Trim(); else { player.MessageHandler("You go to do something but what?."); return; } if (!player.Player.IsNPC) { player.MessageHandler(player.Player.FirstName + " " + temp + (temp.EndsWith(".") == false ? "." : "")); } Room room = Room.GetRoom(player.Player.Location); room.InformPlayersInRoom((room.IsDark == true ? "Someone" : player.Player.FirstName) + " " + temp + (temp.EndsWith(".") == false ? "." : ""), new List<string>(new string[] { player.UserID })); }
public static void Drink(User.User player, List<string> commands) { Items.Iitem item = GetItem(commands, player.Player.Location.ToString()); if (item == null) { player.MessageHandler("You don't seem to be carrying that to drink it."); return; } if (item.ItemType.ContainsKey(Items.ItemsType.DRINKABLE)) { Consume(player, commands, "drink", item); } else { player.MessageHandler("You can't drink that!"); } }
private static void CloseDoor(User.User player, Door door) { if (!player.Player.InCombat) { Room room = Room.GetRoom(player.Player.Location); List <string> message = new List <string>(); if (!room.IsDark) { if (door.Openable) { if (door.Open && !door.Destroyed) { door.Open = false; door.UpdateDoorStatus(); //I may end up putting these strings in the general collection and then each method just supplies the verb message.Add(String.Format("You close {0} {1}.", GetArticle(door.Description[0]), door.Description)); message.Add(String.Format("{0} closes {1} {2}.", player.Player.FirstName, GetArticle(door.Description[0]), door.Description)); } else if (door.Destroyed) { message.Add("You can't close it because it is in pieces!"); } else { message.Add("It's already closed."); } } else { message.Add("It can't be closed."); } } else { message.Add("You can't see anything! Let alone what you are trying to close."); } player.MessageHandler(message[0]); if (message.Count > 1) { room.InformPlayersInRoom(message[1], new List <string>(new string[] { player.UserID })); } } else { player.MessageHandler("You are in the middle of combat, there are more pressing matters at hand than closing something."); } }
private static void Loot(User.User player, List <string> commands) { Character.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)); } } else { 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) { User.User 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; }
//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(User.User 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 (KeyValuePair<string, Character.Attribute> attrib in player.Player.GetAttributes()) { sb.AppendLine(string.Format("{0,-12}: {1}/{2,-3} Rank: {3}",attrib.Key.CamelCaseWord(), attrib.Value.Value, attrib.Value.Max, attrib.Value.Rank)); } sb.AppendLine("\n[Sub Attributes]"); foreach (KeyValuePair<string, double> attrib in player.Player.GetSubAttributes()) { sb.AppendLine(attrib.Key.CamelCaseWord() + ": \t" + attrib.Value); } sb.AppendLine("Description/Bio: " + player.Player.Description); player.MessageHandler(sb.ToString()); } }
//called from the MOVE command private static void ApplyRoomModifier(User.User player) { StringBuilder sb = new StringBuilder(); //Todo: Check the player bonuses to see if they are immune or have resistance to the modifier foreach (Dictionary <string, string> modifier in Rooms.Room.GetModifierEffects(player.Player.Location)) { player.Player.ApplyEffectOnAttribute("Hitpoints", double.Parse(modifier["Value"])); double positiveValue = double.Parse(modifier["Value"]); if (positiveValue < 0) { positiveValue *= -1; } sb.Append(String.Format(modifier["DescriptionSelf"], positiveValue)); if (!player.Player.IsNPC) { player.MessageHandler("\r" + sb.ToString()); } sb.Clear(); sb.Append(String.Format(modifier["DescriptionOthers"], player.Player.FirstName, player.Player.Gender.ToString() == "Male" ? "he" : "she", positiveValue)); Room.GetRoom(player.Player.Location).InformPlayersInRoom("\r" + sb.ToString(), new List <string>(new string[] { player.UserID })); } }
private static void Break(User.User player, List <string> commands) { string objectName = ""; for (int i = commands.Count - 1; i > 0; i--) //this should keep the words in the order we want { objectName += commands[i]; } bool brokeIt = false; //let's see if it a door we want to break down first if (BreakDoor(player, commands)) { brokeIt = true; } else if (BreakObject(player, objectName)) { brokeIt = true; } if (!brokeIt) { //TODO: add this to the message collection in the DB player.MessageHandler(GetMessage("Messages", "NothingToBreak", MessageType.Self)); } }
private static void DisplayTime(User.User player, List<string> commands) { //full, short or whatever combination we feel like allowing the player to grab BsonDocument time = Calendar.Calendar.GetTime(); string message = ""; if (commands.Count < 3) { commands.Add("FULL"); } //let's add in the "full" for time full string amPm = time["Hour"].AsInt32 > 12 ? "PM" : "AM"; if (!player.HourFormat24) { int hour = time["Hour"].AsInt32 > 12 ? time["Hour"].AsInt32 - 12 : time["Hour"].AsInt32; } switch (commands[2].ToUpper()) { case "SHORT": message = String.Format("\rCurrent Time: {0:D2}:{1:D2}:{2:D2} {3}.\n", time["Hour"].AsInt32, time["Minute"].AsInt32, time["Second"].AsInt32, amPm); break; case "FULL": default: message = String.Format("\rCurrent Time: {0}, {1:D2}:{2:D2}:{3:D2} {4}.\n", time["TimeOfDay"].AsString.CamelCaseWord(), time["Hour"].AsInt32, time["Minute"].AsInt32, time["Second"].AsInt32, amPm); break; } player.MessageHandler(message); }
private static void DisplayTime(User.User player, List <string> commands) { //full, short or whatever combination we feel like allowing the player to grab BsonDocument time = Calendar.Calendar.GetTime(); string message = ""; if (commands.Count < 3) { commands.Add("FULL"); } //let's add in the "full" for time full string amPm = time["Hour"].AsInt32 > 12 ? "PM" : "AM"; if (!player.HourFormat24) { int hour = time["Hour"].AsInt32 > 12 ? time["Hour"].AsInt32 - 12 : time["Hour"].AsInt32; } switch (commands[2].ToUpper()) { case "SHORT": message = String.Format("\rCurrent Time: {0:D2}:{1:D2}:{2:D2} {3}.\n", time["Hour"].AsInt32, time["Minute"].AsInt32, time["Second"].AsInt32, amPm); break; case "FULL": default: message = String.Format("\rCurrent Time: {0}, {1:D2}:{2:D2}:{3:D2} {4}.\n", time["TimeOfDay"].AsString.CamelCaseWord(), time["Hour"].AsInt32, time["Minute"].AsInt32, time["Second"].AsInt32, amPm); break; } player.MessageHandler(message); }
//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(User.User 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 (KeyValuePair <string, Character.Attribute> attrib in player.Player.GetAttributes()) { sb.AppendLine(string.Format("{0,-12}: {1}/{2,-3} Rank: {3}", attrib.Key.CamelCaseWord(), attrib.Value.Value, attrib.Value.Max, attrib.Value.Rank)); } sb.AppendLine("\n[Sub Attributes]"); foreach (KeyValuePair <string, double> attrib in player.Player.GetSubAttributes()) { sb.AppendLine(attrib.Key.CamelCaseWord() + ": \t" + attrib.Value); } sb.AppendLine("Description/Bio: " + player.Player.Description); player.MessageHandler(sb.ToString()); } }
public static void Drink(User.User player, List <string> commands) { Items.Iitem item = GetItem(commands, player.Player.Location.ToString()); if (item == null) { player.MessageHandler("You don't seem to be carrying that to drink it."); return; } if (item.ItemType.ContainsKey(Items.ItemsType.DRINKABLE)) { Consume(player, commands, "drink", item); } else { player.MessageHandler("You can't drink that!"); } }
private static void Inventory(User.User player, List <string> commands) { List <Items.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 (Items.Iitem item in inventoryList) { Items.Icontainer container = item as Items.Icontainer; if (!grouping.ContainsKey(item.Name)) { if (!item.ItemType.ContainsKey(Items.ItemsType.CONTAINER)) { grouping.Add(item.Name, 1); } else { grouping.Add(item.Name + " [" + (container.Opened ? "Opened" : "Closed") + "]", 1); container = null; } } else { if (!item.ItemType.ContainsKey(Items.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()); }
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 Emote(User.User player, List <string> commands) { string temp = ""; if (commands[0].Trim().Length > 6) { temp = commands[0].Substring(6).Trim(); } else { player.MessageHandler("You go to do something but what?."); return; } if (!player.Player.IsNPC) { player.MessageHandler(player.Player.FirstName + " " + temp + (temp.EndsWith(".") == false ? "." : "")); } Room room = Room.GetRoom(player.Player.Location); room.InformPlayersInRoom((room.IsDark == true ? "Someone" : player.Player.FirstName) + " " + temp + (temp.EndsWith(".") == false ? "." : ""), new List <string>(new string[] { player.UserID })); }
private static void Sit(User.User user, List <string> commands) { string message = ""; if (user.Player.StanceState != CharacterEnums.CharacterStanceState.Sitting && (user.Player.ActionState == CharacterEnums.CharacterActionState.None || user.Player.ActionState == CharacterEnums.CharacterActionState.Fighting)) { user.Player.SetStanceState(CharacterEnums.CharacterStanceState.Sitting); user.MessageHandler("You sit down."); Room.GetRoom(user.Player.Location).InformPlayersInRoom(String.Format("{0} sits down.", user.Player.FirstName), new List <string>(new string[] { user.UserID })); } else if (user.Player.ActionState != CharacterEnums.CharacterActionState.None) { message = String.Format("You can't sit down. You are {0}!", user.Player.ActionState.ToString().ToLower()); } else { message = String.Format("You can't sit down. You are {0}!", user.Player.StanceState.ToString().ToLower()); } user.MessageHandler(message); }
public static void Drop(User.User 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(); Room 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 <Items.Iitem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID); Items.Iitem item = items[itemPosition - 1]; //3.have player drop item string msgPlayer = null; if (item != null) { player.Player.Inventory.RemoveInventoryItem(item, player.Player.Equipment); item.Location = player.Player.Location; item.Owner = item.Location.ToString(); item.Save(); //4.Inform room and player of action string msgOthers = string.Format("{0} drops {1}", player.Player.FirstName, item.Name); room.InformPlayersInRoom(msgOthers, new List <string>(new string[] { player.UserID })); msgPlayer = string.Format("You drop {0}", item.Name); } else { msgPlayer = "You are not carrying anything of the sorts."; } player.MessageHandler(msgPlayer); }
/// <summary> /// Send message out if target not found, not in same location or already dead. /// </summary> /// <param name="player"></param> /// <param name="enemy"></param> /// <returns></returns> private static bool SendMessageIfTargetUnavailable(User.User player, User.User enemy) { bool targetFound = true; if (enemy == null) //target not found so no longer in combat //TODO: pull target not found message from DB { player.MessageHandler(ParseMessage(GetMessage("Combat", "TargetNotFound", MessageType.Self), player, enemy)); player.Player.InCombat = false; player.Player.LastTarget = player.Player.CurrentTarget; //set the current target to the last target the player had player.Player.CurrentTarget = null; if (player.Player.IsNPC) { player.Player.Save(); //need to update the npc status in the DB } targetFound = false; } //can't fight when you are not in the same room if (targetFound && enemy.Player.Location != player.Player.Location) { player.MessageHandler(ParseMessage(GetMessage("Combat", "TargetNotInLocation", MessageType.Self), player, enemy)); player.Player.InCombat = false; player.Player.UpdateTarget(null); targetFound = false; } //before we get to fighting let's make sure this target isn't already dead if (targetFound && enemy.Player.IsDead()) { player.MessageHandler(ParseMessage(GetMessage("Combat", "TargetFoundDead", MessageType.Self), player, enemy)); player.Player.InCombat = false; player.Player.UpdateTarget(null); targetFound = false; } return(targetFound); }
private static void Say(User.User player, List <string> commands) { string temp = ""; if (commands[0].Length > 4) { temp = commands[0].Substring(4); } else { if (player.Player.IsNPC) { player.MessageHandler("You decide to stay quiet since you had nothing to say."); return; } } Room room = Room.GetRoom(player.Player.Location); player.MessageHandler("You say \"" + temp + "\""); room.InformPlayersInRoom((room.IsDark == true ? "Someone" : player.Player.FirstName) + " says \"" + temp + "\"", new List <string>(new string[] { player.UserID })); }
//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(User.User player, List <string> commands) { int itemPosition = 1; int containerPosition = 1; string itemName = ""; string containerName = ""; List <string> commandAltered = ParseItemPositions(commands, "from", out itemPosition, out itemName); ParseContainerPosition(commandAltered, commands[3], out containerPosition, out containerName); string location = player.Player.Location; Items.Iitem retrievedItem = null; Items.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); string msg = null; string msgOthers = null; if (retrievedItem != null) { Items.Icontainer container = containerItem as Items.Icontainer; if (containerItem != null) { retrievedItem = container.RetrieveItem(retrievedItem.Id.ToString()); msg = "You take " + retrievedItem.Name.ToLower() + " out of " + containerItem.Name.ToLower() + "."; msgOthers = string.Format("{0} takes {1} out of {2}", player.Player.FirstName, retrievedItem.Name.ToLower(), containerItem.Name.ToLower()); } else { msg = "You get " + retrievedItem.Name.ToLower(); msgOthers = string.Format("{0} grabs {1}.", player.Player.FirstName, retrievedItem.Name.ToLower()); } retrievedItem.Location = null; retrievedItem.Owner = player.UserID; retrievedItem.Save(); player.Player.Inventory.AddItemToInventory(retrievedItem); } else { msg = "You can't seem to find " + itemName.ToString().Trim().ToLower() + " to grab it."; } Room.GetRoom(player.Player.Location).InformPlayersInRoom(msgOthers, new List <string>(new string[] { player.UserID })); player.MessageHandler(msg); }
private static void Who(User.User player, List <string> commands) { StringBuilder sb = new StringBuilder(); sb.AppendLine("PlayerName"); sb.AppendLine("----------"); MySockets.Server.GetCurrentUserList() .Where(u => u.CurrentState == User.User.UserState.TALKING) .OrderBy(u => u.Player.FirstName) .ToList() .ForEach(u => sb.AppendLine(u.Player.FirstName + " " + u.Player.LastName)); player.MessageHandler(sb.ToString()); }
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 static void Examine(User.User 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. Room room = Room.GetRoom(player.Player.Location); Door 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); }
public static void Drop(User.User 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(); Room 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<Items.Iitem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID); Items.Iitem item = items[itemPosition - 1]; //3.have player drop item string msgPlayer = null; if (item != null) { player.Player.Inventory.RemoveInventoryItem(item, player.Player.Equipment); item.Location = player.Player.Location; item.Owner = item.Location.ToString(); item.Save(); //4.Inform room and player of action string msgOthers = string.Format("{0} drops {1}", player.Player.FirstName, item.Name); room.InformPlayersInRoom(msgOthers, new List<string>(new string[] { player.UserID })); msgPlayer = string.Format("You drop {0}", item.Name); } else { msgPlayer = "You are not carrying anything of the sorts."; } player.MessageHandler(msgPlayer); }
public static void ReportBug(User.User player, List<string> commands) { MongoUtils.MongoData.ConnectToDatabase(); MongoDatabase db = MongoUtils.MongoData.GetDatabase("Logs"); MongoCollection col = db.GetCollection("Bugs"); BsonDocument doc = new BsonDocument(); doc.Add("ReportedBy", BsonValue.Create(player.UserID)); doc.Add("DateTime", BsonValue.Create(DateTime.Now.ToUniversalTime())); doc.Add("Resolved", BsonValue.Create(false)); doc.Add("Issue", BsonValue.Create(commands[0].Substring("bug".Length + 1))); col.Save(doc); if (player.Player != null) { //could be an internal bug being reported player.MessageHandler("Your bug has been reported, thank you."); } }
private static void LevelUp(User.User 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 = User.User.UserState.LEVEL_UP; } else { player.MessageHandler("You do not have enough Experience, or points to spend to perform this action."); } }
private static void Look(User.User player, List <string> commands) { List <CharacterEnums.CharacterActionState> NonAllowableStates = new List <CharacterEnums.CharacterActionState> { CharacterEnums.CharacterActionState.Dead, CharacterEnums.CharacterActionState.Rotting, CharacterEnums.CharacterActionState.Sleeping, CharacterEnums.CharacterActionState.Unconcious }; StringBuilder sb = new StringBuilder(); if (!NonAllowableStates.Contains(player.Player.ActionState)) { if (commands.Count > 2 && commands[2] == "in") { LookIn(player, commands); return; } //let's build the description the player will see Room room = Room.GetRoom(player.Player.Location); room.GetRoomExits(); List <Exits> exitList = room.RoomExits; sb.AppendLine(("- " + room.Title + " -\t\t\t").FontStyle(Utils.FontStyles.BOLD)); //TODO: add a "Descriptive" flag, that we will use to determine if we need to display the room description. Should be a player level //config we can probably store them in a dictionary called Settings and make a method that turns them on or off. User would just type //Set Descriptions and the method would toggle the bit and then display back to the user the current setting ON/OFF sb.AppendLine(room.Description); sb.Append(HintCheck(player)); foreach (Exits exit in exitList) { sb.AppendLine(GetExitDescription(exit, room)); } sb.Append(DisplayPlayersInRoom(room, player.UserID)); sb.Append(DisplayItemsInRoom(room)); } else { sb.Append(string.Format("You can't look around when you are {0}!", player.Player.Action)); } player.MessageHandler(sb.ToString()); }
public static void ReportBug(User.User player, List <string> commands) { MongoUtils.MongoData.ConnectToDatabase(); MongoDatabase db = MongoUtils.MongoData.GetDatabase("Logs"); MongoCollection col = db.GetCollection("Bugs"); BsonDocument doc = new BsonDocument(); doc.Add("ReportedBy", BsonValue.Create(player.UserID)); doc.Add("DateTime", BsonValue.Create(DateTime.Now.ToUniversalTime())); doc.Add("Resolved", BsonValue.Create(false)); doc.Add("Issue", BsonValue.Create(commands[0].Substring("bug".Length + 1))); col.Save(doc); if (player.Player != null) //could be an internal bug being reported { player.MessageHandler("Your bug has been reported, thank you."); } }
private static void DisplayDate(User.User player, List <string> commands) { //full, short or whatever combination we feel like allowing the player to grab Dictionary <string, string> dateInfo = Calendar.Calendar.GetDate(); string message = ""; if (commands.Count < 3) { commands.Add("FULL"); } //let's add in the "full" for date full string inth = ""; if (dateInfo["DayInMonth"].Substring(dateInfo["DayInMonth"].Length - 1) == "1") { inth = "st"; } else if (dateInfo["DayInMonth"].Substring(dateInfo["DayInMonth"].Length - 1) == "2") { inth = "nd"; } else if (dateInfo["DayInMonth"].Substring(dateInfo["DayInMonth"].Length - 1) == "3") { inth = "rd"; } else { inth = "th"; } switch (commands[2].ToUpper()) { case "SHORT": message = String.Format("\r{0}, {1}{2} of {3}, {4}.\n", dateInfo["DayInWeek"], dateInfo["DayInMonth"], inth, dateInfo["Month"], dateInfo["Year"]); break; case "FULL": default: message = String.Format("\r{0}, on the {1}{2} day of the month of {3}, {4} the year of the {5}.\n", dateInfo["DayInWeek"], dateInfo["DayInMonth"], inth, dateInfo["Month"], dateInfo["Year"], dateInfo["YearOf"]); break; } player.MessageHandler(message); }
private static void Equipment(User.User player, List <string> commands) { Dictionary <Items.Wearable, Items.Iitem> equipmentList = player.Player.Equipment.GetEquipment(); StringBuilder sb = new StringBuilder(); if (equipmentList.Count > 0) { sb.AppendLine("You are equipping:"); foreach (KeyValuePair <Items.Wearable, Items.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()); }
private static void Help(User.User player, List <string> commands) { StringBuilder sb = new StringBuilder(); MongoCollection helpCollection = MongoUtils.MongoData.GetCollection("Commands", "Help"); if (commands.Count < 3 || commands.Contains("all")) //display just the names { MongoCursor cursor = helpCollection.FindAllAs <BsonDocument>(); foreach (BsonDocument doc in cursor) { sb.AppendLine(doc["_id"].ToString()); } } else //user specified a specific command so we will display the explanation and example { BsonDocument doc = helpCollection.FindOneAs <BsonDocument>(Query.Matches("_id", commands[2].ToUpper())); sb.AppendLine(doc["_id"].ToString()); sb.AppendLine(doc["explanation"].AsString); sb.AppendLine(doc["Example"].AsString); } player.MessageHandler(sb.ToString()); }
private static void DisplayDate(User.User player, List<string> commands) { //full, short or whatever combination we feel like allowing the player to grab Dictionary<string, string> dateInfo = Calendar.Calendar.GetDate(); string message = ""; if (commands.Count < 3) { commands.Add("FULL"); } //let's add in the "full" for date full string inth = ""; if (dateInfo["DayInMonth"].Substring(dateInfo["DayInMonth"].Length - 1) == "1") inth = "st"; else if (dateInfo["DayInMonth"].Substring(dateInfo["DayInMonth"].Length - 1) == "2") inth = "nd"; else if (dateInfo["DayInMonth"].Substring(dateInfo["DayInMonth"].Length - 1) == "3") inth = "rd"; else inth = "th"; switch (commands[2].ToUpper()) { case "SHORT": message = String.Format("\r{0}, {1}{2} of {3}, {4}.\n", dateInfo["DayInWeek"], dateInfo["DayInMonth"], inth, dateInfo["Month"], dateInfo["Year"]); break; case "FULL": default: message = String.Format("\r{0}, on the {1}{2} day of the month of {3}, {4} the year of the {5}.\n", dateInfo["DayInWeek"], dateInfo["DayInMonth"], inth, dateInfo["Month"], dateInfo["Year"], dateInfo["YearOf"]); break; } player.MessageHandler(message); }
//called from the MOVE command private static void ApplyRoomModifier(User.User player) { StringBuilder sb = new StringBuilder(); //Todo: Check the player bonuses to see if they are immune or have resistance to the modifier foreach (Dictionary<string, string> modifier in Rooms.Room.GetModifierEffects(player.Player.Location)) { player.Player.ApplyEffectOnAttribute("Hitpoints", double.Parse(modifier["Value"])); double positiveValue = double.Parse(modifier["Value"]); if (positiveValue < 0) { positiveValue *= -1; } sb.Append(String.Format(modifier["DescriptionSelf"], positiveValue)); if (!player.Player.IsNPC) { player.MessageHandler("\r" + sb.ToString()); } sb.Clear(); sb.Append(String.Format(modifier["DescriptionOthers"], player.Player.FirstName, player.Player.Gender.ToString() == "Male" ? "he" : "she", positiveValue)); Room.GetRoom(player.Player.Location).InformPlayersInRoom("\r" + sb.ToString(), new List<string>(new string[] { player.UserID })); } }
private static void Consume(User.User player, List <string> commands, string action, Items.Iitem item) { string upDown = "gain"; StringBuilder msgPlayer = new StringBuilder(); string msgOtherPlayers = null; Dictionary <string, double> affectAttributes = null; Items.Iedible food = item as Items.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"; } msgPlayer.AppendLine(string.Format("You {0} {1} and {2} {3:F1} points of {4}.", action, item.Name, upDown, Math.Abs(attribute.Value), attribute.Key)); msgOtherPlayers = 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.ConnectToDatabase(); MongoDatabase db = MongoUtils.MongoData.GetDatabase("World"); MongoCollection col = db.GetCollection("Items"); col.Remove(Query.EQ("_id", item.Id)); Room.GetRoom(player.Player.Location).InformPlayersInRoom(msgOtherPlayers, new List <string>(new string[] { player.UserID })); player.MessageHandler(msgPlayer.ToString()); }
private static void Loot(User.User player, List<string> commands) { Character.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)); } } else { 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) { User.User 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; }
public static void Equip(User.User player, List<string> commands) { StringBuilder itemName = new StringBuilder(); int itemPosition = 1; string msgOthers = null; string msgPlayer = null; //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 (Items.Iitem item in player.Player.Inventory.GetAllItemsToWear()) { if (player.Player.Equipment.EquipItem(item, player.Player.Inventory)) { msgPlayer += string.Format("You equip {0}.\n", item.Name); msgOthers = 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<Items.Iitem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID); msgPlayer = null; //players need to specify an indexer or we will just give them the first one we found that matched Items.Iitem item = items[itemPosition - 1]; Items.Iweapon weapon = item as Items.Iweapon; if (item != null && item.IsWearable) { player.Player.Equipment.EquipItem(item, player.Player.Inventory); if (item.ItemType.ContainsKey(Items.ItemsType.CONTAINER)) { Items.Icontainer container = item as Items.Icontainer; container.Wear(); } if (item.ItemType.ContainsKey(Items.ItemsType.CLOTHING)) { Items.Iclothing clothing = item as Items.Iclothing; clothing.Wear(); } msgOthers = string.Format("{0} equips {1}.", player.Player.FirstName, item.Name); msgPlayer = string.Format("You equip {0}.", item.Name); } else if (weapon.IsWieldable) { msgPlayer = "This item can only be wielded not worn."; } else if (!item.IsWearable || !weapon.IsWieldable) { msgPlayer = "That doesn't seem like something you can wear."; } else { msgPlayer = "You don't seem to have that in your inventory to be able to wear."; } } player.MessageHandler(msgPlayer); Room.GetRoom(player.Player.Location).InformPlayersInRoom(msgOthers, new List<string>(new string[] { player.UserID })); }
private static void Equipment(User.User player, List<string> commands) { Dictionary<Items.Wearable, Items.Iitem> equipmentList = player.Player.Equipment.GetEquipment(); StringBuilder sb = new StringBuilder(); if (equipmentList.Count > 0) { sb.AppendLine("You are equipping:"); foreach (KeyValuePair<Items.Wearable, Items.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()); }
private static void CloseContainer(User.User player, List<string> commands) { 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; } string itemNameToGet = Items.Items.ParseItemName(commands); bool itemFound = false; Room room = Room.GetRoom(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); } int index = 1; //Here is the real problem, how do I differentiate between a container in the room and one in the players inventory? //if a backpack is laying on the ground th eplayer should be able to put stuff in it or take from it, same as if it were //in his inventory. I should probably check room containers first then player inventory otherwise the player can //specify "inventory" to just do it in their inventory container. 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); if (string.Equals(inventoryItem.Name, itemNameToGet, StringComparison.InvariantCultureIgnoreCase)) { if (index == itemPosition) { Items.Icontainer container = inventoryItem as Items.Icontainer; player.MessageHandler(container.Close()); room.InformPlayersInRoom(player.Player.FirstName + " closes " + inventoryItem.Name.ToLower(), new List<string>(new string[] { player.UserID })); 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 (string.Equals(inventoryItem.Name, itemNameToGet, StringComparison.InvariantCultureIgnoreCase)) { //if player didn't specify an index number loop through all items until we find the want 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.Close()); itemFound = true; break; } else { index++; } } } } }
private static void CloseDoor(User.User player, Door door) { if (!player.Player.InCombat) { Room room = Room.GetRoom(player.Player.Location); List<string> message = new List<string>(); if (!room.IsDark) { if (door.Openable) { if (door.Open && !door.Destroyed) { door.Open = false; door.UpdateDoorStatus(); //I may end up putting these strings in the general collection and then each method just supplies the verb message.Add(String.Format("You close {0} {1}.", GetArticle(door.Description[0]), door.Description)); message.Add(String.Format("{0} closes {1} {2}.", player.Player.FirstName, GetArticle(door.Description[0]), door.Description)); } else if (door.Destroyed) { message.Add("You can't close it because it is in pieces!"); } else { message.Add("It's already closed."); } } else { message.Add("It can't be closed."); } } else { message.Add("You can't see anything! Let alone what you are trying to close."); } player.MessageHandler(message[0]); if (message.Count > 1) { room.InformPlayersInRoom(message[1], new List<string>(new string[] { player.UserID })); } } else { player.MessageHandler("You are in the middle of combat, there are more pressing matters at hand than closing something."); } }
private static void Stand(User.User user, List<string> commands) { string message = ""; if (user.Player.StanceState != CharacterEnums.CharacterStanceState.Standing && (user.Player.ActionState == CharacterEnums.CharacterActionState.None || user.Player.ActionState == CharacterEnums.CharacterActionState.Fighting)) { user.Player.SetStanceState(CharacterEnums.CharacterStanceState.Standing); user.MessageHandler("You stand up."); Room.GetRoom(user.Player.Location).InformPlayersInRoom(String.Format("{0} stands up.", user.Player.FirstName), new List<string>(new string[] { user.UserID })); } else if (user.Player.ActionState != CharacterEnums.CharacterActionState.None) { message = String.Format("You can't stand up. You are {0}!", user.Player.ActionState.ToString().ToLower()); } else { message = String.Format("You can't stand up. You are {0}!", user.Player.StanceState.ToString().ToLower()); } user.MessageHandler(message); }
private static void Look(User.User player, List<string> commands) { List<CharacterEnums.CharacterActionState> NonAllowableStates = new List<CharacterEnums.CharacterActionState> { CharacterEnums.CharacterActionState.Dead, CharacterEnums.CharacterActionState.Rotting, CharacterEnums.CharacterActionState.Sleeping, CharacterEnums.CharacterActionState.Unconcious }; StringBuilder sb = new StringBuilder(); if (!NonAllowableStates.Contains(player.Player.ActionState)) { if (commands.Count > 2 && commands[2] == "in") { LookIn(player, commands); return; } //let's build the description the player will see Room room = Room.GetRoom(player.Player.Location); room.GetRoomExits(); List<Exits> exitList = room.RoomExits; sb.AppendLine(("- " + room.Title + " -\t\t\t").FontStyle(Utils.FontStyles.BOLD)); //TODO: add a "Descriptive" flag, that we will use to determine if we need to display the room description. Should be a player level //config we can probably store them in a dictionary called Settings and make a method that turns them on or off. User would just type //Set Descriptions and the method would toggle the bit and then display back to the user the current setting ON/OFF sb.AppendLine(room.Description); sb.Append(HintCheck(player)); foreach (Exits exit in exitList) { sb.AppendLine(GetExitDescription(exit, room)); } sb.Append(DisplayPlayersInRoom(room, player.UserID)); sb.Append(DisplayItemsInRoom(room)); } else { sb.Append(string.Format("You can't look around when you are {0}!", player.Player.Action)); } player.MessageHandler(sb.ToString()); }
//a tell is a private message basically, location is not a factor private static void Tell(User.User player, List<string> commands) { List<User.User> toPlayerList = MySockets.Server.GetAUserByFirstName(commands[2]).ToList(); User.User toPlayer = null; string message = ""; if (commands[2].ToUpper() == "SELF") { player.MessageHandler("You go to tell yourself something when you realize you already know it."); return; } if (toPlayerList.Count < 1) { message = "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 = "There is no one named " + commands[2].CamelCaseWord() + " to tell something."; } else { 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) { message = commands[0].Substring(startAt); player.MessageHandler("You tell " + toPlayer.Player.FirstName + " \"" + message + "\""); toPlayer.MessageHandler(player.Player.FirstName + " tells you \"" + message + "\""); } else { player.MessageHandler("You have nothing to tell them."); } } }
private static void Say(User.User player, List<string> commands) { string temp =""; if (commands[0].Length > 4) temp = commands[0].Substring(4); else{ if (player.Player.IsNPC) { player.MessageHandler("You decide to stay quiet since you had nothing to say."); return; } } Room room = Room.GetRoom(player.Player.Location); player.MessageHandler("You say \"" + temp + "\""); room.InformPlayersInRoom((room.IsDark == true ? "Someone" : player.Player.FirstName) + " says \"" + temp + "\"", new List<string>(new string[] { player.UserID })); }
private static void LevelUp(User.User 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 = User.User.UserState.LEVEL_UP; } else { player.MessageHandler("You do not have enough Experience, or points to spend to perform this action."); } }
private static void Inventory(User.User player, List<string> commands) { List<Items.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 (Items.Iitem item in inventoryList) { Items.Icontainer container = item as Items.Icontainer; if (!grouping.ContainsKey(item.Name)) { if (!item.ItemType.ContainsKey(Items.ItemsType.CONTAINER)) { grouping.Add(item.Name, 1); } else{ grouping.Add(item.Name + " [" + (container.Opened ? "Opened" : "Closed") + "]", 1); container = null; } } else { if (!item.ItemType.ContainsKey(Items.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()); }
private static void Help(User.User player, List<string> commands) { StringBuilder sb = new StringBuilder(); MongoCollection helpCollection = MongoUtils.MongoData.GetCollection("Commands", "Help"); if (commands.Count < 3 || commands.Contains("all")) { //display just the names MongoCursor cursor = helpCollection.FindAllAs<BsonDocument>(); foreach (BsonDocument doc in cursor) { sb.AppendLine(doc["_id"].ToString()); } } else { //user specified a specific command so we will display the explanation and example BsonDocument doc = helpCollection.FindOneAs<BsonDocument>(Query.Matches("_id", commands[2].ToUpper())); sb.AppendLine(doc["_id"].ToString()); sb.AppendLine(doc["explanation"].AsString); sb.AppendLine(doc["Example"].AsString); } player.MessageHandler(sb.ToString()); }
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 })); } }
//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(User.User player, List<string> commands) { List<User.User> toPlayerList = new List<User.User>(); Room room = Room.GetRoom(player.Player.Location); if (commands.Count > 2){ if (commands[2].ToUpper() == "SELF") { player.MessageHandler("You turn your head towards your own shoulder and whisper quietly to yourself."); room.InformPlayersInRoom((room.IsDark == true ? "Someone" : player.Player.FirstName) + " whispers into " + player.Player.Gender == "MALE" ? "his" : "her" + " own shoulder.", new List<string>(new string[] { player.UserID })); ; return; } toPlayerList = MySockets.Server.GetAUserByFirstName(commands[2]).Where(p => p.Player.Location == player.Player.Location).ToList(); } User.User toPlayer = null; string message = ""; 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 = "You try and whisper to " + commands[2].CamelCaseWord() + " but they're not around."; } else { 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) { message = commands[0].Substring(startAt); player.MessageHandler("You whisper to " + toPlayer.Player.FirstName + " \"" + message + "\""); toPlayer.MessageHandler((room.IsDark == true ? "Someone" : player.Player.FirstName) + " whispers to you \"" + message + "\""); //this is where we would display what was whispered to players with high perception? room.InformPlayersInRoom((room.IsDark == true ? "Someone" : player.Player.FirstName) + " whispers something to " + toPlayer.Player.FirstName, new List<string>(new string[] { player.UserID, toPlayer.UserID })); } } }
private static void Consume(User.User player, List<string> commands, string action, Items.Iitem item) { string upDown = "gain"; StringBuilder msgPlayer = new StringBuilder(); string msgOtherPlayers = null; Dictionary<string, double> affectAttributes = null; Items.Iedible food = item as Items.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"; } msgPlayer.AppendLine(string.Format("You {0} {1} and {2} {3:F1} points of {4}.", action, item.Name, upDown, Math.Abs(attribute.Value), attribute.Key)); msgOtherPlayers = 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.ConnectToDatabase(); MongoDatabase db = MongoUtils.MongoData.GetDatabase("World"); MongoCollection col = db.GetCollection("Items"); col.Remove(Query.EQ("_id", item.Id)); Room.GetRoom(player.Player.Location).InformPlayersInRoom(msgOtherPlayers, new List<string>(new string[] { player.UserID })); player.MessageHandler(msgPlayer.ToString()); }
private static void Who(User.User player, List<string> commands) { StringBuilder sb = new StringBuilder(); sb.AppendLine("PlayerName"); sb.AppendLine("----------"); MySockets.Server.GetCurrentUserList() .Where(u => u.CurrentState == User.User.UserState.TALKING) .OrderBy(u => u.Player.FirstName) .ToList() .ForEach(u => sb.AppendLine(u.Player.FirstName + " " + u.Player.LastName)); player.MessageHandler(sb.ToString()); }
public static void Move(User.User player, List<string> commands) { if (!player.Player.InCombat) { bool foundExit = false; string direction = commands[1].ToLower(); MongoUtils.MongoData.ConnectToDatabase(); MongoDatabase worldDB = MongoUtils.MongoData.GetDatabase("Commands"); MongoCollection roomCollection = worldDB.GetCollection("General"); //this is where general command messages are stored Room room = Room.GetRoom(player.Player.Location); room.GetRoomExits(); if (direction == "north" || direction == "n") direction = "North"; else if (direction == "south" || direction == "s") direction = "South"; else if (direction == "west" || direction == "w") direction = "West"; else if (direction == "east" || direction == "e") direction = "East"; else if (direction == "up" || direction == "u") direction = "Up"; else if (direction == "down" || direction == "d") direction = "Down"; foreach (Exits exit in room.RoomExits) { if (exit.availableExits.ContainsKey(direction.CamelCaseWord())) { //is there a door blocking the exit? bool blocked = false; if (exit.doors.Count > 0 && !exit.doors[exit.Direction.CamelCaseWord()].Open && !exit.doors[exit.Direction.CamelCaseWord()].Destroyed) { blocked = true; } if (!blocked) { player.Player.LastLocation = player.Player.Location; player.Player.Location = exit.availableExits[direction.CamelCaseWord()].Id; player.Player.Save(); IMongoQuery query = Query.EQ("_id", "Leaves"); BsonDocument leave = roomCollection.FindOneAs<BsonDocument>(query); //semantics if (direction.ToLower() == "up") { direction = "above"; } else if (direction.ToLower() == "down") { direction = "below"; } string who = player.Player.FirstName; if (room.IsDark) { who = "Someone"; direction = "somewhere"; } string temp = null; //if the player was just hiding and moves he shows himself if (player.Player.ActionState == CharacterEnums.CharacterActionState.Hiding) { PerformSkill(player, new List<string>(new string[] { "Hide", "Hide" })); } //when sneaking the skill displays the leave/arrive message if (player.Player.ActionState != CharacterEnums.CharacterActionState.Sneaking) { temp = String.Format(leave["ShowOthers"].AsString, who, direction); Room.GetRoom(player.Player.LastLocation).InformPlayersInRoom(temp, new List<string>(new string[] { player.UserID })); } //now we reverse the direction if (direction == "north") direction = "south"; else if (direction == "south") direction = "north"; else if (direction == "west") direction = "east"; else if (direction == "above") direction = "below"; else if (direction == "below") direction = "above"; else direction = "west"; query = Query.EQ("_id", "Arrives"); BsonDocument message = roomCollection.FindOneAs<BsonDocument>(query); room = Room.GetRoom(player.Player.Location); //need to get the new room player moved into if (room.IsDark) { who = "Someone"; direction = "somewhere"; } else { who = player.Player.FirstName; } if (!player.Player.IsNPC) { Look(player, commands); } ApplyRoomModifier(player); if (player.Player.ActionState != CharacterEnums.CharacterActionState.Sneaking) { temp = String.Format(message["ShowOthers"].AsString, who, direction); room.InformPlayersInRoom(temp, new List<string>(new string[] { player.UserID })); } foundExit = true; break; } else {//uh-oh there's a door and it's closed foundExit = true; //we did find an exit it just happens to be blocked by a door if (!player.Player.IsNPC) { string temp = ""; IMongoQuery query = Query.EQ("_id", "NoExit"); BsonDocument message = roomCollection.FindOneAs<BsonDocument>(query); temp = message["ShowSelf"].AsString; query = Query.EQ("_id", "Blocked"); message = roomCollection.FindOneAs<BsonDocument>(query); temp += " " + message["ShowSelf"]; query = Query.EQ("_id", "ClosedDoor"); message = roomCollection.FindOneAs<BsonDocument>(query); temp = temp.Remove(temp.Length - 1); //get rid of previous line period temp += " because " + String.Format(message["ShowSelf"].AsString.ToLower(), exit.doors[exit.Direction.CamelCaseWord()].Description.ToLower()); player.MessageHandler(temp); } break; } } else { continue; } } if (!foundExit) { IMongoQuery query = Query.EQ("_id", "NoExit"); BsonDocument message = roomCollection.FindOneAs<BsonDocument>(query); if (!player.Player.IsNPC) { player.MessageHandler(message["ShowSelf"].AsString + "\r\n"); } } } else { string msgPlayer = null; if (player.Player.InCombat) { msgPlayer = "You can't do that while you are in combat!"; } player.MessageHandler(msgPlayer); } }
private static void UnlockDoor(User.User player, Door door) { if (!player.Player.InCombat) { List<string> message = new List<string>(); Room room = Room.GetRoom(player.Player.Location); bool hasKey = false; if (!room.IsDark) { if (door.Lockable) { if (door.RequiresKey) { //let's see if the player has the key in his inventory or a skeleton key (opens any door) List<Items.Iitem> inventory = player.Player.Inventory.GetInventoryAsItemList(); List<Items.Iitem> keyList = inventory.Where(i => i.ItemType.ContainsKey(Items.ItemsType.KEY)).ToList(); Items.Ikey key = null; foreach (Items.Iitem keys in keyList) { key = keys as Items.Ikey; if (key.DoorID == door.Id || key.SkeletonKey) { hasKey = true; break; } } } if (!door.Open && !door.Destroyed && ((door.RequiresKey && hasKey) || !door.RequiresKey)) { door.Locked = false; door.UpdateDoorStatus(); //I may end up putting these strings in the general collection and then each method just supplies the verb message.Add(String.Format("You unlock {0} {1}.", GetArticle(door.Description[0]), door.Description)); message.Add(String.Format("{0} unlocks {1} {2}.", player.Player.FirstName, GetArticle(door.Description[0]), door.Description)); } else if (door.Destroyed) { message.Add("Why would you want to unlock something that is in pieces?"); } else if (!hasKey) { message.Add("You don't have the key to unlock this door."); } else { message.Add("It can't be unlocked, the door is open."); } } else { message.Add("It can't be unlocked."); } } else { message.Add("You can't see anything! Let alone what you are trying to unlock."); } player.MessageHandler(message[0]); if (message.Count > 1) { room.InformPlayersInRoom(message[1], new List<string>(new string[] { player.UserID })); } } else { player.MessageHandler("You are in the middle of combat there are more pressing matters at hand than unlocking something."); } }
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++; } } } } }
private static void OpenContainer(User.User player, List<string> commands) { //this is a quick work around for knowing which container to open without implementing the dot operator //I need to come back and make it work like with NPCS once I've tested everything works correctly 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; } string itemNameToGet = Items.Items.ParseItemName(commands); bool itemFound = false; 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); } int index = 1; Room room = Room.GetRoom(location); 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); if (string.Equals(inventoryItem.Name, itemNameToGet, StringComparison.InvariantCultureIgnoreCase)) { if (index == itemPosition) { Items.Icontainer container = inventoryItem as Items.Icontainer; player.MessageHandler(container.Open()); itemFound = true; break; } else { index++; } } } } 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 (string.Equals(inventoryItem.Name, itemNameToGet, StringComparison.InvariantCultureIgnoreCase)) { //if player didn't specify an index number loop through all items until we find the want 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.Open()); room.InformPlayersInRoom(player.Player.FirstName + " opens " + inventoryItem.Name.ToLower(), new List<string>(new string[] { player.UserID })); itemFound = true; break; } else { index++; } } } } if (!itemFound) { player.MessageHandler("Open what?"); } }
private static void Examine(User.User 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. Room room = Room.GetRoom(player.Player.Location); Door 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); }
private static void OpenDoor(User.User player, Door door) { if (!player.Player.InCombat) { List<string> message = new List<string>(); Room room = Room.GetRoom(player.Player.Location); if (!room.IsDark) { if (door.Openable) { if (!door.Open && !door.Locked && !door.Destroyed) { door.Open = true; door.UpdateDoorStatus(); message.Add(String.Format("You open {0} {1}.", GetArticle(door.Description[0]), door.Description)); message.Add(String.Format("{0} opens {1} {2}.", player.Player.FirstName, GetArticle(door.Description[0]), door.Description)); } else if (door.Open && !door.Destroyed) { message.Add("It's already open."); } else if (door.Locked && !door.Destroyed) { message.Add("You can't open it because it is locked."); } else if (door.Destroyed) { message.Add("It's more than open it's in pieces!"); } } else { message.Add("It can't be opened."); } } else { message.Add("You can't see anything! Let alone what you are trying to open."); } player.MessageHandler(message[0]); if (message.Count > 1) { room.InformPlayersInRoom(message[1], new List<string>(new string[] { player.UserID })); } } else { player.MessageHandler("You are in the middle of combat, there are more pressing matters at hand than opening something."); } }