Пример #1
0
        /// <summary>
        /// Sets up all of the game objects for use, loads any saved states, restores the world and links itself to the server.
        /// </summary>
        /// <param name="startedServer">A reference to a IServer Type that has had its Start() method called.</param>
        /// <param name="world">A instance of a IWorld Type.  This should be a non-restored World as the game will invoke the IWorld.Load method itself.</param>
        /// <returns></returns>
        public virtual bool Initialize(IServer startedServer)
        {
            // See if we need to update the settings.
            string version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;

            // If the versions do not equal each other, update the stored settings to match this version of the engine.
            if (version != EngineSettings.Default.Version)
            {
                EngineSettings.Default.Upgrade();
                EngineSettings.Default.Save();
            }

            Name = "AllocateThis! Mud Game";

            if (startedServer != null)
            {
                Server = startedServer;
            }
            else
            {
                Server = new Server();
            }

            // Add the engine assembly to the Script Factory
            ScriptFactory.AddAssembly(Assembly.GetExecutingAssembly());

            // Add any additional assemblies that might have been compiled elsewhere (downloadable assemblies)
            if (MudDesigner.Engine.Properties.EngineSettings.Default.ScriptLibrary.Count != 0)
            {
                foreach (string assembly in MudDesigner.Engine.Properties.EngineSettings.Default.ScriptLibrary)
                {
                    // Make sure the assembly actually exists first.
                    if (File.Exists(assembly))
                    {
                        ScriptFactory.AddAssembly(System.Environment.CurrentDirectory + "\\" + assembly);
                    }
                }
            }

            // Get a reference to a new instance of a IWorld Type.
            IWorld world = (IWorld)ScriptFactory.GetScript(MudDesigner.Engine.Properties.EngineSettings.Default.WorldScript, null);

            // If it's not null, we apply it to the Game.World property.
            if (world != null)
            {
                World = world;
            }
            return(true);
        }
Пример #2
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            Log.Info("Mud Designer Toolkit Editor starting.");
            Log.Info("Loading script references.");


            //Loop through each reference mentioned in the engines properties and add them.
            //This provides support for 3rd party pre-compiled *mods* scripts
            foreach (var path in from string reference in EngineSettings.Default.ScriptLibrary select Path.Combine(System.Environment.CurrentDirectory, reference))
            {
                CompileEngine.AddAssemblyReference(path);
                Log.Info(string.Format("Adding assembly reference {0}", path));
            }

            //Compile the scripts.
            bool result = CompileEngine.Compile(EngineSettings.Default.ScriptsPath);

            if (!result)
            {
                this.mainTxtServerInfo.Text = CompileEngine.Errors;
            }

            //Add the compiled script assembly to the script factory.
            ScriptFactory.AddAssembly(CompileEngine.CompiledAssembly);

            //Add the third party references.
            foreach (string reference in EngineSettings.Default.ScriptLibrary)
            {
                ScriptFactory.AddAssembly(reference);
            }

            if (File.Exists("MudDesigner.Scripts.dll"))
            {
                string path = Path.Combine(System.Environment.CurrentDirectory, "MudDesigner.Scripts.dll");
                ScriptFactory.AddAssembly(Assembly.LoadFile(path));
            }

            //Get a reference to a scripted instance of IGame.
            var game = (IGame)ScriptFactory.GetScript(EngineSettings.Default.GameScript, null);

            //In the event that the scripted Game class specified as the default is missing,
            //just search the engine for another one.
            if (game == null)
            {
                game = (IGame)ScriptFactory.FindInheritedScript("MudDesigner.Engine.Core.Game", null);

                if (game == null) //still could not find anything
                {
                    MessageBox.Show("Critical error: Could not locate a Game script to use. This can cause instability in the editor.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Log.Error(string.Format("{0}", CompileEngine.Errors));
                    //Logger.WriteLine(CompileEngine.Errors, Logger.Importance.Critical);

                    menuWorld.Enabled = false;
                    menuGame.Enabled  = false;
                    menuSave.Enabled  = false;

                    return;
                }
            }
            IServer server = new Server(4000);

            //Initialize the Game. Null reference to a server is passed because we don't need a server.
            game.Initialize(server);

            //Load the save game file.
            game.RestoreWorld();

            //Store a reference to the current game to the static Editor Type
            Editor.Game = game;

            //Update the GUI
            mainPropertyGame.SelectedObject   = Editor.Game;
            mainPropertyServer.SelectedObject = Editor.Game.Server;
            RefreshUI();
        }