Пример #1
0
        /// <summary>
        /// Tries to initialize the room instance for a given room. The room is destroyed on errors.
        /// </summary>
        /// <param name="ID">The database ID of the room to construct an instance of.</param>
        public roomInstance(int ID)
        {
            this.roomID      = ID;
            this.Information = Engine.Game.Rooms.getRoomInformation(ID);
            if (this.Information == null) // Invalid room
            {
                Engine.Game.Rooms.destroyRoomInstance(ID);
                return;
            }

            this.loadItems();
            this.generateFloorMap();
            this.gridUnit = new bool[this.gridState.GetUpperBound(0) + 1, this.gridState.GetUpperBound(1) + 1];

            if (this.Information.isUserFlat)
            {
                foreach (Items.floorItem lItem in this.floorItems)
                {
                    if (lItem.Definition.Behaviour.canStandOnTop && lItem.Definition.Sprite == "nest")
                    {
                        this.loadRoomPet(lItem.ID, 0, 0);
                    }
                }
            }

            this.loadRoomBot(roomID, 0, 0);

            this.roomWorker = new Thread(workerLoop);
            this.roomWorker.Start();
            Logging.Log("Initialized room instance for room " + this.roomID + ".", Logging.logType.roomInstanceEvent);
        }
Пример #2
0
        /// <summary>
        /// Tries to initialize the room instance for a given room. The room is destroyed on errors.
        /// </summary>
        /// <param name="ID">The database ID of the room to construct an instance of.</param>
        public roomInstance(int ID)
        {
            this.roomID = ID;
            this.Information = ObjectTree.Game.Rooms.getRoomInformation(ID);
            if (this.Information == null) // Invalid room
            {
                ObjectTree.Game.Rooms.destroyRoomInstance(ID);
                return;
            }

            this.loadItems();
            this.generateFloorMap();
            this.gridUnit = new bool[this.gridState.GetUpperBound(0) + 1, this.gridState.GetUpperBound(1) + 1];

            if (this.Information.isUserFlat)
            {
                foreach (Items.floorItem lItem in this.floorItems)
                {
                    if (lItem.Definition.Behaviour.canStandOnTop && lItem.Definition.Sprite == "nest")
                        this.loadRoomPet(lItem.ID, 0, 0);
                }
            }

            this.roomWorker = new Thread(workerLoop);
            this.roomWorker.Start();
            Logging.Log("Initialized room instance for room " + this.roomID + ".", Logging.logType.roomInstanceEvent);
        }
Пример #3
0
        /// <summary>
        /// Removes all users from the room and nullifies all objects.
        /// </summary>
        public void Destroy()
        {
            this.roomWorker.Abort();
            this.roomWorker = null;

            if (this.userAmount > 0) // Users in room
            {
                // Broadcoast 'kick' message
                serverMessage Notify = new serverMessage(18); // "@R"
                sendMessage(Notify);
                Notify = null;

                Type pCommonReactor = typeof(roomReactor);// new roomReactor().GetType();
                Type pFlatReactor   = typeof(flatReactor);

                lock (this.roomUsers)
                {
                    foreach (roomUser lRoomUser in this.roomUsers.Values)
                    {
                        if (this.Information.isUserFlat)
                        {
                            lRoomUser.Session.gameConnection.reactorHandler.unRegister(pFlatReactor);
                        }
                        else
                        {
                            lRoomUser.Session.gameConnection.reactorHandler.unRegister(pCommonReactor);
                        }

                        lRoomUser.Session.roomID       = 0;
                        lRoomUser.Session.roomInstance = null;
                    }
                }
                this.roomUsers.Clear();
            }
            this.updateUserAmount();
            this.roomUsers = null;

            this.roomUnitIdentifiers.Clear(); this.roomUnitIdentifiers = null;
            this.enteringSessions.Clear(); this.enteringSessions       = null;

            this.saveItems();
            this.unloadItems();

            this.Information = null;
            this.gridState   = null;
            this.gridHeight  = null;
            this.gridUnit    = null;
        }
Пример #4
0
        /// <summary>
        /// Removes all users from the room and nullifies all objects.
        /// </summary>
        public void Destroy()
        {
            this.roomWorker.Abort();
            this.roomWorker = null;

            if (this.userAmount > 0) // Users in room
            {
                // Broadcoast 'kick' message
                serverMessage Notify = new serverMessage(18); // "@R"
                sendMessage(Notify);
                Notify = null;

                Type pCommonReactor = new roomReactor().GetType();
                Type pFlatReactor = new flatReactor().GetType();

                lock (this.roomUsers)
                {
                    foreach (roomUser lRoomUser in this.roomUsers.Values)
                    {
                        if (this.Information.isUserFlat)
                            lRoomUser.Session.gameConnection.reactorHandler.unRegister(pFlatReactor);
                        else
                            lRoomUser.Session.gameConnection.reactorHandler.unRegister(pCommonReactor);

                        lRoomUser.Session.roomID = 0;
                        lRoomUser.Session.roomInstance = null;
                    }
                }
                this.roomUsers.Clear();
            }
            this.updateUserAmount();
            this.roomUsers = null;

            this.roomUnitIdentifiers.Clear(); this.roomUnitIdentifiers = null;
            this.enteringSessions.Clear(); this.enteringSessions = null;

            this.saveItems();
            this.unloadItems();

            this.Information = null;
            this.gridState = null;
            this.gridHeight = null;
            this.gridUnit = null;
        }