예제 #1
0
파일: Dices.cs 프로젝트: habb0/Woodpecker
        public void interactWithDice(int itemID, uint sessionID, bool spinDice)
        {
            floorItem pItem = this.getFloorItem(itemID);
            if (pItem != null && pItem.Definition.Behaviour.isDice) // Valid item
            {
                roomUser pUser = this.getRoomUser(sessionID);
                if (pUser == null || !tilesTouch(pItem.X, pItem.Y, pUser.X, pUser.Y))
                    return; // Invalid position of room user and dice item
                pUser = null;

                serverMessage Message = new serverMessage(90); // "AZ"
                Message.Append(itemID);
                itemID *= 38;

                int randomNumber = 0;
                if (spinDice) // New spin
                {
                    this.sendMessage(Message); // Start spin animation for clients

                    // Generate random number
                    randomNumber = new Random(DateTime.Now.Millisecond).Next(1, 7); // 1-6
                    itemID += randomNumber;
                }

                Message.Append(" " + itemID.ToString()); // Append 'new' item ID
                if (spinDice) // New spin, send delayed message
                    this.sendMessage(Message.ToString(), 1000);
                else // Send message immediately
                    this.sendMessage(Message);

                pItem.customData = randomNumber.ToString(); // Set custom data
                pItem.requiresUpdate = true; // Request update of dice customdata
            }
        }
예제 #2
0
        public void broadcastMessage(serverMessage Message)
        {
            string sMessage = Message.ToString();

            lock (_userSessions)
            {
                foreach (Session lSession in _userSessions.Values)
                {
                    lSession.gameConnection.sendMessage(sMessage);
                }
            }
        }
예제 #3
0
        public void sendTalk(int sourceID, byte sourceX, byte sourceY, string Text)
        {
            string sFullMessage = "";

            serverMessage Message = new serverMessage(24); // "@X"

            Message.appendWired(sourceID);
            Message.appendClosedValue(Text);
            sFullMessage = Message.ToString();
            Message      = null;

            lock (roomUsers)
            {
                foreach (roomUser lRoomUser in roomUsers.Values)
                {
                    int distX = Math.Abs(sourceX - lRoomUser.X) - 1;
                    int distY = Math.Abs(sourceY - lRoomUser.Y) - 1;

                    if (distX < 9 && distY < 9)       // User can hear
                    {
                        if (distX <= 6 && distY <= 6) // User can hear full message
                        {
                            lRoomUser.Session.gameConnection.sendMessage(sFullMessage);
                        }
                        else // User can hear garbled message
                        {
                            Message = new serverMessage(24); // "@X"
                            Message.appendWired(sourceID);

                            int garbleIntensity = distX;
                            if (distY < distX)
                            {
                                garbleIntensity = distY;
                            }
                            garbleIntensity -= 4;

                            string garbledText = Text;
                            stringFunctions.garbleText(ref garbledText, garbleIntensity);

                            Message.appendClosedValue(garbledText);
                            lRoomUser.Session.gameConnection.sendMessage(Message);
                            Message = null;
                        }
                    }
                }
            }
        }
예제 #4
0
파일: Dices.cs 프로젝트: habb0/Woodpecker
        public void interactWithDice(int itemID, uint sessionID, bool spinDice)
        {
            floorItem pItem = this.getFloorItem(itemID);

            if (pItem != null && pItem.Definition.Behaviour.isDice) // Valid item
            {
                roomUser pUser = this.getRoomUser(sessionID);
                if (pUser == null || !tilesTouch(pItem.X, pItem.Y, pUser.X, pUser.Y))
                {
                    return; // Invalid position of room user and dice item
                }
                pUser = null;

                serverMessage Message = new serverMessage(90); // "AZ"
                Message.Append(itemID);
                itemID *= 38;

                int randomNumber = 0;
                if (spinDice)                  // New spin
                {
                    this.sendMessage(Message); // Start spin animation for clients

                    // Generate random number
                    randomNumber = new Random(DateTime.Now.Millisecond).Next(1, 7); // 1-6
                    itemID      += randomNumber;
                }

                Message.Append(" " + itemID.ToString()); // Append 'new' item ID
                if (spinDice)                            // New spin, send delayed message
                {
                    this.sendMessage(Message.ToString(), 1000);
                }
                else // Send message immediately
                {
                    this.sendMessage(Message);
                }

                pItem.customData     = randomNumber.ToString(); // Set custom data
                pItem.requiresUpdate = true;                    // Request update of dice customdata
            }
        }
예제 #5
0
 /// <summary>
 /// Sends a single message in a serverMessage object to the client via an asynchronous System.Net.Sockets.Socket.BeginSend action.
 /// </summary>
 /// <param name="Message">The serverMessage object of the message.</param>
 public void sendAsyncMessage(serverMessage Message)
 {
     Logging.Log("Session " + this.Session.ID + ">> " + Message, Logging.logType.serverMessageEvent);
     this.sendMessage(Message.ToString());
 }
예제 #6
0
 /// <summary>
 /// Sends a serverMessage object to all active room users in the room, after a given delay in milliseconds.
 /// </summary>
 /// <param name="Message">The serverMessage object to send.</param>
 /// <param name="delayMilliseconds">The amount of milliseconds to sleep before sending the message.</param>
 public void sendMessage(serverMessage Message, int delayMilliseconds)
 {
     this.sendMessage(Message.ToString(), delayMilliseconds);
 }
예제 #7
0
 /// <summary>
 /// Sends a serverMessage object to all active room users in the room.
 /// </summary>
 /// <param name="Message">The serverMessage object to send.</param>
 public void sendMessage(serverMessage Message)
 {
     this.sendMessage(Message.ToString());
 }
예제 #8
0
파일: Rollers.cs 프로젝트: habb0/Woodpecker
        private void runRollers()
        {
            if (mRollerTimer > DateTime.Now.TimeOfDay.TotalSeconds && mRollerDay == DateTime.Today.DayOfYear)
            {
                return;
            }

            StringBuilder Updates          = new StringBuilder();
            List <int>    movedRoomUnitIDs = new List <int>();
            List <int>    movedItemIDs     = new List <int>();

            try
            {
                foreach (floorItem lRoller in this.floorItems)
                {
                    if (!lRoller.Definition.Behaviour.isRoller)
                    {
                        continue; // Not a roller item
                    }
                    #region General
                    // Workout direction for roller
                    byte nextX = lRoller.X;
                    byte nextY = lRoller.Y;
                    if (lRoller.Rotation == 0)
                    {
                        nextY--;
                    }
                    else if (lRoller.Rotation == 2)
                    {
                        nextX++;
                    }
                    else if (lRoller.Rotation == 4)
                    {
                        nextY++;
                    }
                    else if (lRoller.Rotation == 6)
                    {
                        nextX--;
                    }

                    if (!tileExists(nextX, nextY) || tileBlockedByRoomUnit(nextX, nextY))
                    {
                        continue; // Can't roll off room map / on room unit
                    }
                    #endregion

                    #region Get objects on current tile and verify
                    roomUnit         pUnit  = this.getRoomUnitOnTile(lRoller.X, lRoller.Y); // Get room unit on this roller
                    List <floorItem> pItems = new List <floorItem>();
                    foreach (floorItem lItem in this.getFloorItems(lRoller.X, lRoller.Y))
                    {
                        if (!lItem.Definition.Behaviour.isRoller && !movedItemIDs.Contains(lItem.ID))
                        {
                            pItems.Add(lItem);
                        }
                    }

                    if (pUnit != null && (pUnit.Moves || movedRoomUnitIDs.Contains(pUnit.ID)))
                    {
                        pUnit = null; // Invalid room unit
                    }

                    if (pUnit == null && pItems.Count == 0)
                    {
                        continue; // No items on roller and no room unit aswell
                    }
                    #endregion

                    // Get items on next tile and perform some checks
                    bool nextTileIsRoller = false;
                    bool canMoveItems     = (this.gridState[nextX, nextY] == roomTileState.Free);
                    bool canMoveUnit      = canMoveItems;

                    bool nextTileUnitInteractiveStance = false;

                    foreach (floorItem lItem in this.getFloorItems(nextX, nextY))
                    {
                        if (lItem.Definition.Behaviour.isRoller)
                        {
                            nextTileIsRoller = true;
                            continue;
                        }

                        if (lItem.Definition.Behaviour.isSolid)
                        {
                            canMoveItems = false;
                            canMoveUnit  = false;

                            if (lItem.Definition.Behaviour.isDoor)
                            {
                                if (lItem.customData == "O") // Door is open
                                {
                                    canMoveUnit = true;      // Can move unit in door
                                }
                            }
                        }
                        else if (pUnit != null && lItem.Definition.isInteractiveStance)
                        {
                            nextTileUnitInteractiveStance = true;
                            if (!nextTileIsRoller)
                            {
                                canMoveUnit = true;
                            }
                        }
                    }

                    if (!canMoveItems)    // Can't move items
                    {
                        if (!canMoveUnit) // Can't move unit aswell
                        {
                            continue;     // Can't run this roller
                        }
                        pItems.Clear();   // Clear items to move
                    }

                    #region Generate notification and move objects
                    serverMessage eventNotification = new serverMessage(230); // "Cf"
                    eventNotification.appendWired(lRoller.X);
                    eventNotification.appendWired(lRoller.Y);
                    eventNotification.appendWired(nextX);
                    eventNotification.appendWired(nextY);

                    eventNotification.appendWired(pItems.Count);
                    foreach (floorItem lItem in pItems)
                    {
                        float nextZ = lItem.Z;
                        if (!nextTileIsRoller)
                        {
                            nextZ -= lRoller.Definition.topHeight;
                        }

                        eventNotification.appendWired(lItem.ID);
                        eventNotification.appendClosedValue(stringFunctions.formatFloatForClient(lItem.Z));
                        eventNotification.appendClosedValue(stringFunctions.formatFloatForClient(nextZ));

                        lItem.X = nextX;
                        lItem.Y = nextY;
                        lItem.Z = nextZ;
                        lItem.requiresUpdate = true;

                        movedItemIDs.Add(lItem.ID);
                        generateFloorMap();
                    }

                    eventNotification.appendWired(lRoller.ID);

                    if (pUnit != null) // Room unit lifting with roller
                    {
                        float nextZ = pUnit.Z;
                        if (!nextTileIsRoller)
                        {
                            nextZ -= lRoller.Definition.topHeight;
                        }

                        pUnit.X = nextX;
                        pUnit.Y = nextY;
                        pUnit.Z = nextZ;
                        pUnit.requiresUpdate = true;

                        if (!nextTileIsRoller || nextTileUnitInteractiveStance)
                        {
                            this.setRoomUnitTileState(pUnit);
                        }

                        this.gridUnit[lRoller.X, lRoller.Y] = false;
                        this.gridUnit[pUnit.X, pUnit.Y]     = true;

                        eventNotification.appendWired(2);
                        eventNotification.appendWired(pUnit.ID);
                        eventNotification.appendClosedValue(stringFunctions.formatFloatForClient(pUnit.Z));
                        eventNotification.appendClosedValue(stringFunctions.formatFloatForClient(nextZ));

                        movedRoomUnitIDs.Add(pUnit.ID);
                    }
                    #endregion

                    Updates.Append(eventNotification.ToString());
                }

                if (Updates.Length > 0)
                {
                    this.sendMessage(Updates.ToString());
                }

                this.mRollerTimer = DateTime.Now.TimeOfDay.TotalSeconds + rollerDelaySeconds;
                this.mRollerDay   = DateTime.Today.DayOfYear;
            }
            catch (Exception ex)
            {
                Core.Logging.Log("Rollers in room instance of room " + this.roomID + " crashed, exception: " + ex.Message);
                this.hasRollers = false;
            }
        }