Ejemplo n.º 1
0
 /// <summary>
 /// Updates the status of a virtualRoomUser object in room. If the user is walking, then the user isn't refreshed immediately but processed at the next cycle of the status thread, to prevent double status strings in @b.
 /// </summary>
 /// <param name="roomUser">The virtualRoomUser object to update.</param>
 internal void Refresh(virtualRoomUser roomUser)
 {
     if (roomUser.goalX == -1)
         _statusUpdates.Append(roomUser.statusString + Convert.ToChar(13));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Sends a 'say' chat message from a virtualRoomUser to the room. Users and bots in a range of 5 squares will receive the message and bob their heads. Roombots will check the message and optionally interact to it.
 /// </summary>
 /// <param name="sourceUser">The virtualRoomUser object that sent the message.</param>
 /// <param name="Message">The message that was sent.</param>
 internal void sendSaying(virtualRoomUser sourceUser, string Message)
 {
     checkEmotion(sourceUser, Message);
     if (sourceUser.isTyping)
     {
         sendData("Ei" + Encoding.encodeVL64(sourceUser.roomUID) + "H");
         sourceUser.isTyping = false;
     }
     sourceUser.statusManager.handleStatus("talk", "", Message.Length * 190);
     string Filtered = "@X" + Encoding.encodeVL64(sourceUser.roomUID) + stringManager.filterSwearwords(Message) + Convert.ToChar(2);
     string Data = "@X" + Encoding.encodeVL64(sourceUser.roomUID) + Message + Convert.ToChar(2);
     Hashtable users = new Hashtable();
     users = (Hashtable)this._Users.Clone();
     {
         foreach (virtualRoomUser roomUser in users.Values)
         {
             _statusUpdates.Append(roomUser.statusString + Convert.ToChar(13));
             roomUser.User.sendData(Data);
         }
     }
     lock (_Bots)
     {
         foreach (virtualBot roomBot in _Bots.Values)
         {
             if (Math.Abs(roomBot.X - sourceUser.X) < 6 && Math.Abs(roomBot.Y - sourceUser.Y) < 6)
             {
                 if (new Random(DateTime.Now.Millisecond).Next(0, 11) == 0)
                     sendSaying(roomBot, roomBot.noShoutingMessage);
             }
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Filter the emotions in a chat message, and displays it at the face of the virtual user
        /// </summary>
        /// <param name="sourceUser">The virtualRoomUser object of the sender.</param>
        /// <param name="Message">The message being sent.</param>
        internal void checkEmotion(virtualRoomUser sourceUser, string Message)
        {
            // Define all gestures
            string[] GestureList = { "sml", "agr", "sad", "srp" };
            string[] Gestures_sml = { ":)", ":D" };
            string[] Gestures_agr = { ">:(", ":@", ":/" };
            string[] Gestures_sad = { ":(", ":'(" };
            string[] Gestures_srp = { ":o", ":O", ":0" };
            string[][] Gestures = { Gestures_sml, Gestures_agr, Gestures_sad, Gestures_srp };

            // Look for them
            for (int i = 0; i < Gestures.Length; i++)
            {
                string[] currentGestures = Gestures[i];
                string[] splitMessage = Message.Split(currentGestures, StringSplitOptions.None);

                if (splitMessage.Length > 1) // Result?
                {
                    string Gesture = GestureList[i];
                    sourceUser.statusManager.handleStatus("gest", Gesture, 6000);
                    return;
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Moves a virtual room user one step to a certain coord [the coord has to be one step removed from the room user's current coords], with pauses and handling for seats and rugs.
 /// </summary>
 /// <param name="roomUser">The virtual room user to move.</param>
 /// <param name="toX">The X of the destination coord.</param>
 /// <param name="toY">The Y of the destination coord.</param>
 internal void moveUser(virtualRoomUser roomUser, int toX, int toY, bool secondRefresh)
 {
     new userMover(MOVEUSER).BeginInvoke(roomUser, toX, toY, secondRefresh, null, null);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Sends a 'whisper' chat message, which is only visible for sender and receiver, from a certain user to a certain user in the virtual room.
        /// </summary>
        /// <param name="sourceUser">The virtualRoomUser object of the sender.</param>
        /// <param name="Receiver">The username of the receiver.</param>
        /// <param name="Message">The message being sent.</param>
        internal void sendWhisper(virtualRoomUser sourceUser, string Receiver, string Message)
        {
            checkEmotion(sourceUser, Message);
            if (sourceUser.isTyping)
            {
                sendData("Ei" + Encoding.encodeVL64(sourceUser.roomUID) + "H");
                sourceUser.isTyping = false;
            }

            string Filtered = "@Y" + Encoding.encodeVL64(sourceUser.roomUID) + stringManager.filterSwearwords(Message) + Convert.ToChar(2);
            string Data = "@Y" + Encoding.encodeVL64(sourceUser.roomUID) + Message + Convert.ToChar(2);
            Hashtable users = new Hashtable();
            users = (Hashtable)this._Users.Clone();
            {
                foreach (virtualRoomUser roomUser in _Users.Values)
                {
                        sourceUser.User.sendData(Data);
                        roomUser.User.sendData(Data);
                        return;
                    }
                }
        }
Ejemplo n.º 6
0
        private void MOVEUSER(virtualRoomUser roomUser, int toX, int toY, bool secondRefresh)
        {
            try
            {
                sqUNIT[roomUser.X, roomUser.Y] = false;
                sqUNIT[toX, toY] = true;
                roomUser.Z1 = Pathfinding.Rotation.Calculate(roomUser.X, roomUser.Y, toX, toY);
                roomUser.Z2 = roomUser.Z1;
                roomUser.statusManager.removeStatus("sit");
                double nextHeight = 0;
                if (sqSTATE[toX, toY] == squareState.Rug)
                    nextHeight = sqITEMHEIGHT[toX, toY];
                else
                    nextHeight = (double)sqFLOORHEIGHT[toX, toY];
                roomUser.statusManager.addStatus("mv", toX + "," + toY + "," + nextHeight.ToString().Replace(',', '.'));
                sendData("@b" + roomUser.statusString);

                Thread.Sleep(310);
                roomUser.X = toX;
                roomUser.Y = toY;
                roomUser.H = nextHeight;

                roomUser.statusManager.removeStatus("mv");
                if (secondRefresh)
                {
                    if (sqSTATE[toX, toY] == squareState.Seat) // The next steps are on a seat, seat the user, prepare the sit status for next cycle of thread
                    {
                        roomUser.statusManager.removeStatus("dance"); // Remove dance status
                        roomUser.Z1 = sqITEMROT[toX, toY];
                        roomUser.Z2 = roomUser.Z1;
                        roomUser.statusManager.addStatus("sit", sqITEMHEIGHT[toX, toY].ToString().Replace(',', '.'));
                        roomUser.statusManager.removeStatus("mv");
                    }
                    sendData("@b" + roomUser.statusString);
                }
            }
            catch { }
        }
        /// <summary>
        /// Safely shuts this virtualBot down and tidies up all resources.
        /// </summary>
        internal void Kill()
        {
            try { aiHandler.Abort(); }
            catch { }

            aiHandler = null;
            Room = null;
            Statuses = null;
            Coords = null;
            Sayings = null;
            Shouts = null;
            chatTriggers = null;
            Customer = null;
            customerTrigger = null;
        }
        /// <summary>
        /// Invoked by a virtualRoomUser. There is checked if this bot reacts on a certain chat message, if so, then replies/orders etc are processed.
        /// </summary>
        /// <param name="roomUser">The virtualRoomUser object that interacts with this bot by saying a message.</param>
        /// <param name="Message">The message that the virtualRoomUser said to this bot.</param>
        internal void Interact(virtualRoomUser roomUser, string Message)
        {
            Message = Message.ToLower();
            string[] messageWords = Message.Split(' ');
            if (chatTriggers != null)
            {
                foreach (chatTrigger Trigger in chatTriggers)
                {
                    for (int i = 0; i < messageWords.Length; i++)
                    {
                        if (Trigger.containsWord(messageWords[i]))
                        {
                            if (Trigger.serveItem != "") // Serve an item, walk up to the customer and hand over the beverage
                            {
                                if (Customer != null) // The bot is currently serving a different room user, ignore this trigger
                                    return;

                                Coord Closest = getClosestWalkCoordTo(roomUser.X, roomUser.Y);
                                if (Closest.X == -1) // Can't serve this user (no square close enough)
                                    return;

                                Room.sendSaying(this, Trigger.Reply);
                                removeStatus("dance");
                                addStatus("carryd", Trigger.serveItem); // Make the bot starting to carry the order to deliver it
                                goalX = Closest.X;
                                goalY = Closest.Y;
                                this.Customer = roomUser;
                                this.customerTrigger = Trigger;
                            }
                            else
                            {
                                this.Z1 = Rotation.Calculate(X,Y,roomUser.X,roomUser.Y);
                                this.Z2 = this.Z1;
                                Room.sendSaying(this, Trigger.Reply);
                            }
                            return; // One trigger per time
                        }
                    }
                }
            }
        }
        /// <summary>
        /// If the bot currently is processing an order, then it'll hand over the order and prepare for a new one.
        /// </summary>
        internal void checkOrders()
        {
            if (Customer != null)
            {
                {
                    goalX = -1;
                    Rotate(Customer.X, Customer.Y);
                    removeStatus("carryd");
                    Room.sendSaying(this, customerTrigger.serveReply);

                    if (Customer.statusManager.containsStatus("sit") == false)
                    {
                        Customer.Z1 = Rotation.Calculate(Customer.X, Customer.Y, X, Y);
                        Customer.Z2 = Customer.Z1;
                    }
                    Customer.statusManager.carryItem(customerTrigger.serveItem);
                }

                {
                    Customer = null;
                    customerTrigger = null;
                }
            }
        }
        /// <summary>
        /// Sends a 'whisper' chat message, which is only visible for sender and receiver, from a certain user to a certain user in the virtual room.
        /// </summary>
        /// <param name="sourceUser">The virtualRoomUser object of the sender.</param>
        /// <param name="Receiver">The username of the receiver.</param>
        /// <param name="Message">The message being sent.</param>
        internal void sendWhisper(virtualRoomUser sourceUser, string Receiver, string Message)
        {
            if (sourceUser.isTyping)
            {
                sendData("Ei" + Encoding.encodeVL64(sourceUser.roomUID) + "H");
                sourceUser.isTyping = false;
            }

            string Data = "@Y" + Encoding.encodeVL64(sourceUser.roomUID) + Message + Convert.ToChar(2);
            foreach (virtualRoomUser roomUser in _Users.Values)
            {
                if (roomUser.User._Username == Receiver)
                {
                    sourceUser.User.sendData(Data);
                    roomUser.User.sendData(Data);
                    return;
                }
            }
        }
        /// <summary>
        /// Sends a 'shout' chat message from a virtualRoomUser to the room. All users will receive the message and bob their heads. Roombots have a 1/10 chance to react with the 'please don't shout message' set for them.
        /// </summary>
        /// <param name="sourceUser">The virtualRoomUser object that sent the message.</param>
        /// <param name="Message">The message that was sent.</param>
        internal void sendShout(virtualRoomUser sourceUser, string Message)
        {
            if (sourceUser.isTyping)
            {
                sendData("Ei" + Encoding.encodeVL64(sourceUser.roomUID) + "H");
                sourceUser.isTyping = false;
            }
            //sourceUser.statusManager.handleStatus("talk", "", Message.Length * 190);

            string Data = "@Z" + Encoding.encodeVL64(sourceUser.roomUID) + Message + Convert.ToChar(2);
            foreach (virtualRoomUser roomUser in _Users.Values)
            {
                //if (roomUser.roomUID != sourceUser.roomUID && roomUser.goalX == -1)
                //{
                    //byte newHeadRotation = Pathfinding.Rotation.headRotation(roomUser.Z2, roomUser.X, roomUser.Y, sourceUser.X, sourceUser.Y);
                    //if (newHeadRotation < 10 && newHeadRotation != roomUser.Z1) // Rotation changed
                    //{
                    //    roomUser.Z1 = newHeadRotation;
                        _statusUpdates.Append(roomUser.statusString + Convert.ToChar(13));
                    //}
                //}
                roomUser.User.sendData(Data);
            }

            foreach (virtualBot roomBot in _Bots.Values)
            {
                if (Math.Abs(roomBot.X - sourceUser.X) < 6 && Math.Abs(roomBot.Y - sourceUser.Y) < 6)
                {
                    if (new Random(DateTime.Now.Millisecond).Next(0, 11) == 0)
                        sendSaying(roomBot, roomBot.noShoutingMessage);
                }
            }
        }