Beispiel #1
0
        /// <summary>
        /// Destroys the Room and
        /// </summary>
        public override void Destroy()
        {
            Doorways.Clear();
            Doorways = null;

            List <IPlayer> playerCollection = new List <IPlayer>();

            foreach (IMob mob in Occupants)
            {
                if (mob is IPlayer)
                {
                    playerCollection.Add((IPlayer)mob);
                }
            }
            this.BroadcastMessage("Room is being destroyed!  You will be teleported to a new location.",
                                  playerCollection.ToList());

            // Trace back up through the environment path to get the World
            IWorld world = Zone.Realm.World;

            //Get the initial Room location, and split it up into an array so we can parse it
            string[] roomPath = EngineSettings.Default.InitialRoom.Split('>');

            // Make sure we have three entries, Realm, Zone and Room
            if (roomPath.Length != 3)
            {
                return;
            }

            // Get the Realm
            IRealm realm = world.GetRealm(roomPath[0]);

            if (realm == null)
            {
                return;
            }

            // Get our Zone
            IZone zone = realm.GetZone(roomPath[1]);

            if (zone == null)
            {
                return;
            }

            // Get the initial Room
            IRoom room = zone.GetRoom(roomPath[2]);

            if (room == null)
            {
                return;
            }

            // Loop through each player in this Room and move them to the initial Room.
            foreach (IPlayer player in Occupants)
            {
                player.Move(room);
                player.SendMessage("You have been moved to " + room.Name);
            }
        }
Beispiel #2
0
        private void roomsBtnDeleteRoom_Click(object sender, EventArgs e)
        {
            //Make sure all of the required UI elements are selected
            if (roomsLstExistingRooms.SelectedIndex == -1)
            {
                MessageBox.Show("You must select a Room first.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (roomsComRealms.SelectedIndex == -1 || roomsComZones.SelectedIndex == -1)
            {
                MessageBox.Show("You must select both a Realm and a Zone first.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //Grab a reference to the Realm.
            IRealm realm = Editor.Game.World.GetRealm(roomsComRealms.SelectedItem.ToString());

            if (realm == null)
            {
                MessageBox.Show("Failed to locate the selected Realm within the system for an unknown reason!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //Get a reference to the zone the selected Room belongs to.
            IZone zone = realm.GetZone(roomsComZones.SelectedItem.ToString());

            if (zone == null)
            {
                MessageBox.Show("Failed to locate the selected Zone within the system for an unknown reason!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //Get a reference to the room that the user wants to delete.
            IRoom room = zone.GetRoom(roomsLstExistingRooms.SelectedItem.ToString());

            if (room == null)
            {
                MessageBox.Show("Failed to locate the selected Room within the system for an unknown reason!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //Remove the room from our list collection
            if (Editor.CurrentRoom.ToString() == string.Format("{0}>{1}>{2}", roomsComRealms.SelectedItem.ToString(), roomsComZones.SelectedItem.ToString(), room.Name))
            {
                Editor.CurrentRoom = null;
            }

            roomsLstExistingRooms.Items.Remove(room.Name);
            //Remove the room from the Zone
            zone.RemoveRoom(room);
            //Null the reference.
            room = null;
            RefreshRoomLabels(Editor.CurrentRealm, Editor.CurrentZone, Editor.CurrentRoom);
        }
        private void btnSetLoginRoom_Click(object sender, EventArgs e)
        {
            frmLoginRoom form = new frmLoginRoom();

            form.ShowDialog();

            while (form.Visible)
            {
                Application.DoEvents();
            }

            form = null;

            //Reset the login room text
            bool good = false;

            if (EngineSettings.Default.InitialRoom != null)
            {
                string[] env = EngineSettings.Default.InitialRoom.Split('>');

                if (env.Length == 3)
                {
                    IRealm realm = Editor.Game.World.GetRealm(env[0]);
                    if (realm != null)
                    {
                        IZone zone = realm.GetZone(env[1]);
                        if (zone != null)
                        {
                            IRoom room = zone.GetRoom(env[2]);
                            if (room != null)
                            {
                                lblLoginRoom.Text = string.Format("Login Room: {0}>{1}>{2}", realm.Name, zone.Name, room.Name);
                                good = true;
                            }
                        }
                    }
                }
            }

            if (!good)
            {
                lblLoginRoom.Text = "Login Room: None set.";
            }
        }
        private void frmEngineSettings_Load(object sender, EventArgs e)
        {
            //Load all of the scripts that have settings associated with them, store them and
            //present them to the GUI.
            ProcessScripts();

            bool good = false;

            if (EngineSettings.Default.InitialRoom != null)
            {
                string[] env = EngineSettings.Default.InitialRoom.Split('>');

                if (env.Length == 3)
                {
                    IRealm realm = Editor.Game.World.GetRealm(env[0]);
                    if (realm != null)
                    {
                        IZone zone = realm.GetZone(env[1]);
                        if (zone != null)
                        {
                            IRoom room = zone.GetRoom(env[2]);
                            if (room != null)
                            {
                                lblLoginRoom.Text = string.Format("Login Room: {0}>{1}>{2}", realm.Name, zone.Name, room.Name);
                                good = true;
                            }
                        }
                    }
                }
            }

            if (!good)
            {
                lblLoginRoom.Text = "Login Room: None set.";
            }
        }
Beispiel #5
0
        public ICommand GetCommand()
        {
            var File = new FileIO();

            if (connectedPlayer.Location == null)
            {
                string   startRoom = EngineSettings.Default.InitialRoom;
                string[] locations = startRoom.Split('>');

                if (locations.Length < 3)
                {
                    Log.Error("The Server does not have a starting room set!");
                    connectedPlayer.SendMessage(
                        "The server does not have a starting room set! Please contact the server administrator.");
                    return(new NoOpCommand());
                }

                IWorld world = director.Server.Game.World;

                if (world == null)
                {
                    Log.Fatal("Failed to get a instance of the game world!");
                    return(new NoOpCommand()); //If this is null, then we should end up in a infinite console spam
                }

                IRealm realm = world.GetRealm(locations[0]);
                if (realm == null)
                {
                    Log.Fatal(string.Format("Failed to load Realm {0}", locations[0]));
                    return(new NoOpCommand());
                }

                IZone zone = realm.GetZone(locations[1]);
                if (zone == null)
                {
                    Log.Fatal(string.Format("Failed to load Zone {0}", locations[1]));
                    return(new NoOpCommand());
                }

                IRoom room = zone.GetRoom(locations[2]);
                if (room == null)
                {
                    Log.Fatal(string.Format("Failed to load Room {0}", locations[2]));
                    return(new NoOpCommand());
                }

                connectedPlayer.Move(room);

                File.Save(connectedPlayer, Path.Combine(EngineSettings.Default.PlayerSavePath, string.Format("{0}.char", connectedPlayer.Username)));
            }
            else if (connectedPlayer.Director.Server.Game.World.RoomExists(connectedPlayer.Location.ToString()))
            {
                File.Save(connectedPlayer, Path.Combine(EngineSettings.Default.PlayerSavePath, string.Format("{0}.char", connectedPlayer.Username)));
            }
            else
            {
                //Set as null and re-run through this state again.
                connectedPlayer.Location = null;
                return(new NoOpCommand()); //Dont allow it to finish the setup
            }

            return(SetupDefaultState());
        }
        private bool GetUserPassword()
        {
            //Recieve the user input
            var input = connectedPlayer.ReceiveInput();

            //Make sure the text entered is valid and not null, blank etc.
            if (!ValidateInput(input))
            {
                connectedPlayer.SendMessage("Your password is invalid!");
                return(false);
            }

            var file = new FileIO();

            IPlayer loadedplayer = (IPlayer)file.Load(
                Path.Combine(
                    EngineSettings.Default.PlayerSavePath,
                    string.Format("{0}.char", connectedPlayer.Username)),
                connectedPlayer.GetType());

            if (loadedplayer != null && loadedplayer.CheckPassword(input))
            {
                /*Make sure we are disconnecting the user if they are connected already.
                 * foreach (var connectedUser in director.ConnectedPlayers.Keys)
                 * {
                 *  if (connectedUser.Name == loadedplayer.Name && connectedUser != loadedplayer)
                 *      connectedUser.Disconnect();
                 * }
                 */

                connectedPlayer.SendMessage("Success!!");

                //Can use inherited built-in CopyState method instead
                //connectedPlayer.LoadPlayer(loadedplayer);

                //Use IGameObject.CopyState to use a uniform method across the engine
                //A little slower than the LoadPlayer method, but it can be revised to be quicker.
                //Notes on revising the method are under GameObject.cs
                IGameObject tmp = (IGameObject)loadedplayer;
                connectedPlayer.CopyState(ref tmp); //Copies loadedPlayer state to connectedPlayer.

                //Make sure the player is properly added to the world.
                IWorld world = connectedPlayer.Director.Server.Game.World;
                IRealm realm = world.GetRealm(connectedPlayer.Location.Zone.Realm.Name);

                if (realm == null)
                {
                    return(false);
                }

                IZone zone = realm.GetZone(connectedPlayer.Location.Zone.Name);
                if (zone == null)
                {
                    return(false);
                }

                IRoom room = zone.GetRoom(connectedPlayer.Location.Name);
                if (room == null)
                {
                    return(false);
                }

                connectedPlayer.Move(room);

                Log.Info(string.Format("{0} has just logged in.", connectedPlayer.Name));
                connectedPlayer.SwitchState(new LoginCompleted());

                return(true);
            }
            else
            {
                Log.Info(string.Format("{0} has failed logged in at IP Address: {1}.", connectedPlayer.Name,
                                       connectedPlayer.Connection.RemoteEndPoint));

                return(false);
            }
        }
Beispiel #7
0
        private void roomsBtnLoadRoom_Click(object sender, EventArgs e)
        {
            //Can't load a room if nothing is selected
            if (roomsLstExistingRooms.SelectedIndex == -1)
            {
                MessageBox.Show("You must select a Room from within the Available Rooms list.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //If a Realm or Zone isn't selected, abort.
            if (roomsComRealms.SelectedIndex == -1 || roomsComZones.SelectedIndex == -1)
            {
                MessageBox.Show("You must select a Realm and a Zone from the Existing Realm and Existing Zone drop down menus.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //Our instance variables
            IRealm realm = null;
            IZone  zone  = null;
            IRoom  room  = null;

            //Get a reference to the currently selected Realm.
            realm = Editor.Game.World.GetRealm(roomsComRealms.SelectedItem.ToString());
            if (realm == null)
            {
                MessageBox.Show(roomsComRealms.SelectedItem.ToString() + " was not found within the games World collection!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //If the Realm exists, we need to get a reference to the currently selected Zone too.
            else
            {
                zone = realm.GetZone(roomsComZones.SelectedItem.ToString());
            }

            if (zone == null)
            {
                MessageBox.Show(roomsComZones.SelectedItem.ToString() + " was not found within the " + realm.Name + " zone collection!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //If the Zone exists, we need to get a reference to the currently selected Room
            else
            {
                room = zone.GetRoom(roomsLstExistingRooms.SelectedItem.ToString());
            }

            //Check if the Room is null
            if (room == null)
            {
                MessageBox.Show("The selected Room '" + roomsLstExistingRooms.SelectedItem.ToString() + "' was not located within the " + zone.Name + " room collection!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //Room isn't null, set the static Editor types Current properties.
            //Lets us modify them with-out having to call a Get() method again.
            else
            {
                Editor.CurrentRealm = realm;
                Editor.CurrentZone  = zone;
                Editor.CurrentRoom  = room;
            }

            //Refresh our UI
            RefreshDoorwayList();
            RefreshRoomLabels(realm, zone, room);

            //Select the Room object in the property grid for editing.
            roomsPropertiesRoom.SelectedObject = room;
        }
Beispiel #8
0
        public Engine.Commands.ICommand GetCommand()
        {
            switch (currentCreationState)
            {
            case CreationState.CharacterCreation:
                connectedPlayer.SwitchState(new CreateNewCharacter(director));
                break;

            case CreationState.GenderSelect:
                connectedPlayer.SwitchState(new GenderSelect(director));
                break;

            case CreationState.Completed:
                //Broacast we are now done creating the character
                connectedPlayer.SendMessage("You have completed the character creation process! Enjoy your stay in our world!");
                connectedPlayer.SendMessage(string.Empty);    //blank line.

                //Trace back up through the environment path to get the World
                IWorld world = director.Server.Game.World;

                //Get the initial Room location, and split it up into an array so we can parse it
                string[] roomPath = EngineSettings.Default.InitialRoom.Split('>');

                //Make sure we have three entries, Realm, Zone and Room
                if (roomPath.Length != 3)
                {
                    return(new NoOpCommand());
                }

                //Get the Realm
                IRealm realm = world.GetRealm(roomPath[0]);
                if (realm == null)
                {
                    return(new NoOpCommand());
                }

                //Get our Zone
                IZone zone = realm.GetZone(roomPath[1]);
                if (zone == null)
                {
                    return(new NoOpCommand());
                }

                //Get the initial Room
                IRoom room = zone.GetRoom(roomPath[2]);
                if (room == null)
                {
                    return(new NoOpCommand());
                }


                connectedPlayer.Move(room);

                //Make sure we have a valid save path
                var filePath = Path.Combine(Directory.GetCurrentDirectory(), EngineSettings.Default.PlayerSavePath, connectedPlayer.Username + ".char");
                var path     = Path.GetDirectoryName(filePath);

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                //Save the player using our serialization class
                FileIO fileSave = new FileIO();
                fileSave.Save(connectedPlayer, filePath);

                connectedPlayer.SwitchState(new EnteringCommandState());
                Log.Info(string.Format("{0} has just logged in.", connectedPlayer.Name));
                return(new LookCommand());
            }

            return(new NoOpCommand());
        }