Exemplo n.º 1
0
        /// <summary>
        /// Calling this will remove any bonuses or penalties whose time has expired.
        /// </summary>
        /// <returns></returns>
        public IMessage Cleanup() {
            List<string> messages = new List<string>();
            var bonusCollection = MongoUtils.MongoData.GetCollection<BsonDocument>("Messages", "Bonuses");
            BsonDocument found = null;
            BsonArray array = null;
            IMongoQuery query = null;
            IMessage message = new Message();
            foreach (var item in Bonuses) {
                if (item.Value.Time != DateTime.MaxValue && DateTime.Now >= item.Value.Time) {
                    query = Query.EQ("_id", item.Key);
                    found = MongoUtils.MongoData.RetrieveObject<BsonDocument>(bonusCollection, b => b["_id"] == item.Key);
                    //let's add the messages that removing the bonus/penalty could have
                    array = found["Messages"][0]["Self"].AsBsonArray;
                    int choice = Extensions.RandomNumber.GetRandomNumber().NextNumber(0, array.Count());

                    message.Self = array[choice].AsString;

                    array = found["Messages"][0]["Target"].AsBsonArray;
                    if (array.Count >= choice - 1) {
                        message.Target = array[choice].AsString;
                    }

                    array = found["Messages"][0]["Others"].AsBsonArray;
                    if (array.Count == choice - 1) {
                        message.Room = array[choice].AsString;
                    }

                    //remove the bonus/penalty
                    Remove(item.Key);
                }
            }

            return message;
        }
		public static bool Call(this Dictionary<GameMessageType, Func<Message, bool>> dict, Message msg)
		{
			Func<Message, bool> func;
			if (dict.TryGetValue((GameMessageType)msg.Type, out func))
			{
				return func(msg);
			}
			return false;
		}
Exemplo n.º 3
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);
			}
		}
Exemplo n.º 4
0
        public IMessage Ignite() {
            IMessage msg = new Message();
            if (!isLit) {
                //TODO: get these messages from the DB based on fuel source or type
                msg.Self = "You turn on " + Name + " and can now see in the dark.";
                msg.Room = "{attacker} turns on " + Name + ".";
                isLit = true;
                this.Save();
                OnIgnited(new ItemEventArgs(ItemEvent.IGNITE, this.Id));
            }
            else {
                msg.Self = "It is already on!";
            }

            return msg;
        }
Exemplo n.º 5
0
        public IMessage Extinguish() {
			IMessage msg = new Message();
            if (isLit) {
                //TODO: get these messages from the DB based on fuel source or type
                msg.Self = "You turn off " + Name + " and can no longer see in the dark.";
                msg.Room = "{0} turns off " + Name + ".";
                isLit = false;
                Save();
                OnExtinguished(new ItemEventArgs(ItemEvent.EXTINGUISH, this.Id));
            }
            else {
                msg.Self = "It is already off!";
            }

            return msg;
        }
Exemplo n.º 6
0
        public async virtual void HandleEvent(object o, EventArgs e) {
            IMessage message = new Message();
            var typeEventCaller = ((TriggerEventArgs)e).IdType;
            var callerID = ((TriggerEventArgs)e).Id;
            object caller = null;

            switch (typeEventCaller) {
                case TriggerEventArgs.IDType.Npc:
                    caller = Character.NPCUtils.GetUserAsNPCFromList(new List<ObjectId>() { callerID });
                    break;
                case TriggerEventArgs.IDType.Room:
                    caller = Room.GetRoom(callerID.ToString());
                    break;
                default:
                    break;
            }

            if (MessageOverrideAsString.Count > 0) {
                script.AddVariable(MessageOverrideAsString, "messageOverrides");
            }

            script.AddVariable(message, "Message");

            if (caller is IRoom) {
                script.AddVariable((IRoom)caller, "room");
                script.AddVariable("room", "callerType");
            } else if (caller is User) {
                script.AddVariable((User)caller, "npc");
                script.AddVariable("npc", "callerType");
            }

            if (((TriggerEventArgs)e).InstigatorType == TriggerEventArgs.IDType.Player) {
                script.AddVariable(Server.GetAUser(((TriggerEventArgs)e).InstigatorID), "player");
            } else if (((TriggerEventArgs)e).InstigatorType == TriggerEventArgs.IDType.Npc) {
                script.AddVariable(Character.NPCUtils.GetUserAsNPCFromList(new List<ObjectId>() { ((TriggerEventArgs)e).InstigatorID }), "player");
            }

            await Task.Run(() => script.RunScript());
        }
Exemplo n.º 7
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);
			}
		}
Exemplo n.º 8
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 });
        }
Exemplo n.º 9
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 });
		}
Exemplo n.º 10
0
        public void WhenCallingGetNextAndThereIsCorruptedMessageShouldPostIt()
        {
            Message message = new Message(new Uri("http://google2.com"), "{\"body\":\"{\\\"key11\\\":\"}");
            message.Id = 2;
            AddHeaders(message);

            var messages = GetTestMessages();
            Repository.Setup(r => r.Get()).Returns(messages[0]);
            Repository.Setup(r => r.GetNextMessageAfter(1))
                .Returns(message);
            Repository.Setup(r => r.GetNextMessageAfter(2))
                .Returns(messages[2]);
            Repository.Setup(r => r.GetNextMessageAfter(3))
                .Returns((IMessage)null);

            var actual = Provider.GetNext();

            Assert.NotNull(actual);

            Assert.Equal("http://post.com/api/batch", actual.Url.AbsoluteUri);
            Assert.Equal(
                "{\"events\":[" +
                    "{\"url\":\"http://google.com/\", \"reynaId\":1, \"payload\":{\"key01\":\"value01\",\"key02\":11}}, " +
                    "{\"url\":\"http://google2.com/\", \"reynaId\":2, \"payload\":{\"body\":\"{\\\"key11\\\":\"}}, " +
                    "{\"url\":\"http://google3.com/\", \"reynaId\":3, \"payload\":{\"key21\":\"value21\",\"key22\":22}}" +
                    "]}",
                    actual.Body);

            AssertHeaders(actual);
            Assert.Equal(3, actual.Id);
        }
Exemplo n.º 11
0
 public DataReceivedEventArgs(IReadOnlyList<byte> dataReceived)
 {
     DataReceived = new Message(dataReceived);
 }
Exemplo n.º 12
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 });
            
        }
Exemplo n.º 13
0
        public void WhenCallingCloseAndSuccessfullySentBatchShouldRecord()
        {
            var message = new Message(new Uri("http://google.com"), "{\"key01\":\"value01\",\"key02\":11}");
            message.Id = 1;

            Provider.Delete(message);
            Provider.Close();

            PeriodicBackoutCheck.Verify(p => p.Record("BatchProvider"), Times.Once());
        }
		private bool HandlePlayerChangedState(IClient client, Message msg)
		{
			(client.UserData as IPlayerData).ReadyToPlay = !(client.UserData as IPlayerData).ReadyToPlay;
			var pcs = new Messages.PlayerChangedState((client.UserData as IPlayerData).UserId);
			this.Server.Clients.SendToAllNoLock(pcs.ToMessage(), c => c != client);
			this.ReorderPlayersList(client);
			return true;
		}
Exemplo n.º 15
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);
                }
            }
        }
Exemplo n.º 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});
			
		}
Exemplo n.º 17
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);
			}
		}
Exemplo n.º 18
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 });
			}
		}
Exemplo n.º 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 }); 
		}
Exemplo n.º 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 });
		}
Exemplo n.º 21
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);
			}

		}
		private bool HandleUnitQueueAction(IClient client, Message msg)
		{
			if (!this.InGame)
				return false;

			var uqa = new Messages.UnitQueueAction(msg);
			if (uqa.Created)
			{
				var token = ((client.UserData as IPlayerData).Player.Type == PlayerType.First ?
					this.GameState.Controller.Player1Queue :
					this.GameState.Controller.Player2Queue).Request(uqa.UnitId);
				client.Send(new Messages.UnitQueued(uqa.UnitId, token != null).ToMessage());
			}
			else
			{
				//TODO: dodać usuwanie z listy
			}
			return true;
		}
Exemplo n.º 23
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 });
		}
Exemplo n.º 24
0
 public void WhenCallingPutShouldCallVolatileStore()
 {
     IMessage message = new Message(new Uri("http://testuri.com"), "body");
     service.Put(message);
     volatileStore.Verify(s => s.Add(message), Times.Exactly(1));
 }
Exemplo n.º 25
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 });
        }
		private bool HandlePlayerChangedNick(IClient client, Message msg)
		{
			var pcn = new Messages.PlayerChangedNick(msg);
			pcn.UserId = (client.UserData as IPlayerData).UserId;
			(client.UserData as IPlayerData).Nick = pcn.NewNick;
			this.Server.Clients.SendToAllNoLock(pcn.ToMessage(), c => c != client);
			return true;
		}
Exemplo n.º 27
0
        public void WhenCallingDeleteShouldDeleteFromRepository()
        {
            var message = new Message(new Uri("http://google.com"), "{\"key01\":\"value01\",\"key02\":11}");
            message.Id = 100;

            Provider.Delete(message);

            Repository.Verify(p => p.DeleteMessagesFrom(message), Times.Once());
        }
Exemplo n.º 28
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 });
        }
Exemplo n.º 29
0
        private List<IMessage> GetTestMessages()
        {
            var message1 = new Message(new Uri("http://google.com"), "{\"key01\":\"value01\",\"key02\":11}");
            var message2 = new Message(new Uri("http://google2.com"), "{\"key11\":\"value11\",\"key12\":12}");
            var message3 = new Message(new Uri("http://google3.com"), "{\"key21\":\"value21\",\"key22\":22}");

            message1.Id = 1;
            message2.Id = 2;
            message3.Id = 3;

            AddHeaders(message1);
            AddHeaders(message2);
            AddHeaders(message3);

            List<IMessage> messages = new List<IMessage>(3);
            messages.Add(message1);
            messages.Add(message2);
            messages.Add(message3);

            return messages;
        }
Exemplo n.º 30
0
        public void Drain() {
			IMessage msg = new Message();
			msg.InstigatorID = Id.ToString();
			msg.InstigatorType = ObjectType.Item;

            currentCharge -= chargeDecayRate;
            IUser temp = Sockets.Server.GetAUser(this.Owner);
            if ((Math.Round(currentCharge/maxCharge,2) * 100) == chargeLowWarning){
                //TODO: these message should be grabbed from the DB and should reflect the type of light it is
                if (temp != null) {
					msg.Self = "The light from your " + this.Name.ToLower() + " flickers.";
					msg.Room = "The light from " + temp.Player.FirstName + "'s " + this.Name.ToLower() + " flickers.";
				}
				
                chargeLowWarning = chargeLowWarning / 2;
            }

            if (Math.Round(currentCharge,2) <= 0) {
                currentCharge = 0.0;
                chargeLowWarning = 10;
                isLit = false;
                //TODO: these message should be grabbed from the DB and should reflect the type of light it is
                if (temp != null) {
					msg.Self = "The light from your " + this.Name.ToLower() + " goes out.";
					msg.Room = "The light from " + temp.Player.FirstName + "'s " + this.Name.ToLower() + " goes out.";
				}
            }

			if (temp.Player.IsNPC) {
				temp.MessageHandler(msg);
			}
			else{
				temp.MessageHandler(msg.Self);
			}

			Room.GetRoom(temp.Player.Location).InformPlayersInRoom(msg, new List<ObjectId>() { temp.UserID });
			
            OnDrained(new ItemEventArgs(ItemEvent.DRAIN, this.Id));
            temp.Player.Inventory.GetInventoryAsItemList(); //this will force an update on the inventory items 
            temp.Player.Equipment.GetEquipment(); //this will force an update on the equipment
            this.Save();
        }