MudEngine:
- Game World Auto-save property now fully implemented. However, the Game world saving mechanics are not fully implemented. As additional components are implemented, they will be auto-saved if the property is set to true. - Game.AutoSaveInterval property added for setting how often the Game will save all objects in the world (incase run-time changes to environments/objects were made, they must be saved). - Player walk command now supports Game.AutoSave. Every-time the player changes location they will be saved. - ScriptEngine now supports Initializing both Assembly and Source based scripts at the same time via the new ScriptTypes.Both element. - ScriptEngine now auto-loads previously saved settings from Settings.ini - Game.ObjectIdentifierCollection renamed to Game.WorldObjects. Type collection changed from that of Int32 to BaseObject. - Game.update now contains the code needed to update the World Time and Auto-Save the world if needed. - Game.AddObject method added for adding World Objects to the Game.WorldObjects collection
This commit is contained in:
parent
d212f5b854
commit
7a4c9211d4
9 changed files with 105 additions and 61 deletions
|
@ -35,6 +35,9 @@ namespace MudEngine.Commands
|
||||||
|
|
||||||
player.CommandSystem.ExecuteCommand("Look", player);
|
player.CommandSystem.ExecuteCommand("Look", player);
|
||||||
|
|
||||||
|
if (player.ActiveGame.AutoSave)
|
||||||
|
player.Save(player.Filename);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace MudEngine.GameManagement
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a copy of all identifiers being used in the game.
|
/// Gets a copy of all identifiers being used in the game.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal List<Int32> ObjectIdentifierCollection { get; private set; }
|
internal List<BaseObject> WorldObjects { get; private set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Game Information
|
#region Game Information
|
||||||
|
@ -125,10 +125,16 @@ namespace MudEngine.GameManagement
|
||||||
[Category("Project Settings")]
|
[Category("Project Settings")]
|
||||||
[Description("Enable or Disable Auto-saving of players when the player travels")]
|
[Description("Enable or Disable Auto-saving of players when the player travels")]
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets if the game autosaves when the player changes locations.
|
/// Gets or Sets if the Game world is automatically saved at a specified interval.
|
||||||
|
/// Players will be saved every-time they change location.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AutoSave { get; set; }
|
public bool AutoSave { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets the interval in which the Game will automatically save every game object.
|
||||||
|
/// </summary>
|
||||||
|
public Int32 AutoSaveInterval { get; set; }
|
||||||
|
|
||||||
[Category("Project Settings")]
|
[Category("Project Settings")]
|
||||||
[Description("Hide Room names from being outputted to the console.")]
|
[Description("Hide Room names from being outputted to the console.")]
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -185,6 +191,7 @@ namespace MudEngine.GameManagement
|
||||||
CurrencyList = new List<Currency>();
|
CurrencyList = new List<Currency>();
|
||||||
scriptEngine = new Scripting.ScriptEngine(this);
|
scriptEngine = new Scripting.ScriptEngine(this);
|
||||||
RealmCollection = new List<Realm>();
|
RealmCollection = new List<Realm>();
|
||||||
|
WorldObjects = new List<BaseObject>();
|
||||||
WorldTime = new GameTime(this);
|
WorldTime = new GameTime(this);
|
||||||
|
|
||||||
//Prepare the Save Paths for all of our Game objects.
|
//Prepare the Save Paths for all of our Game objects.
|
||||||
|
@ -238,12 +245,8 @@ namespace MudEngine.GameManagement
|
||||||
if (!Directory.Exists(DataPaths.Players))
|
if (!Directory.Exists(DataPaths.Players))
|
||||||
Directory.CreateDirectory(DataPaths.Players);
|
Directory.CreateDirectory(DataPaths.Players);
|
||||||
|
|
||||||
//First, compile and execute all of the script files.
|
//Load both pre-compiled and file based scripts
|
||||||
scriptEngine.ScriptType = ScriptEngine.ScriptTypes.SourceFiles;
|
scriptEngine.ScriptType = ScriptEngine.ScriptTypes.Both;
|
||||||
scriptEngine.Initialize();
|
|
||||||
|
|
||||||
//Next, load any pre-compiled libraries.
|
|
||||||
scriptEngine.ScriptType = ScriptEngine.ScriptTypes.Assembly;
|
|
||||||
scriptEngine.Initialize();
|
scriptEngine.Initialize();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -326,7 +329,38 @@ namespace MudEngine.GameManagement
|
||||||
|
|
||||||
public virtual void Update()
|
public virtual void Update()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
DateTime serverTime = new DateTime();
|
||||||
|
DateTime systemTime = DateTime.Now;
|
||||||
|
|
||||||
|
int lastSaveGap = 0;
|
||||||
|
|
||||||
WorldTime.Update();
|
WorldTime.Update();
|
||||||
|
|
||||||
|
if (lastSaveGap == AutoSaveInterval)
|
||||||
|
{
|
||||||
|
if (AutoSave)
|
||||||
|
Save();
|
||||||
|
lastSaveGap = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//ServerTime holds the last minute prior to our current minute.
|
||||||
|
if (serverTime.Minute != DateTime.Now.Minute)
|
||||||
|
{
|
||||||
|
serverTime = DateTime.Now;
|
||||||
|
lastSaveGap++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsMultiplayer)
|
||||||
|
{
|
||||||
|
Console.Write(Log.GetMessages());
|
||||||
|
Log.FlushMessages();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlayerCollection[0].ExecuteCommand(Console.ReadLine());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Save()
|
public virtual void Save()
|
||||||
|
@ -414,6 +448,23 @@ namespace MudEngine.GameManagement
|
||||||
RealmCollection.Add(realm);
|
RealmCollection.Add(realm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddObject(BaseObject obj)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void RemoveObject(BaseObject obj)
|
||||||
|
{
|
||||||
|
foreach (BaseObject o in WorldObjects)
|
||||||
|
{
|
||||||
|
if (o == obj)
|
||||||
|
{
|
||||||
|
WorldObjects.Remove(o);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a Realm currently stored in the Games collection of Realms.
|
/// Gets a Realm currently stored in the Games collection of Realms.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -432,7 +483,7 @@ namespace MudEngine.GameManagement
|
||||||
return realms;
|
return realms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Realm GetRealmByID(Guid id)
|
public Realm GetRealmByID(Int32 id)
|
||||||
{
|
{
|
||||||
foreach (Realm r in RealmCollection)
|
foreach (Realm r in RealmCollection)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace MudEngine.GameObjects
|
||||||
[RefreshProperties(RefreshProperties.All)]
|
[RefreshProperties(RefreshProperties.All)]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public Guid ID { get; internal set; }
|
public Int32 ID { get; internal set; }
|
||||||
|
|
||||||
[Category("Object Setup")]
|
[Category("Object Setup")]
|
||||||
[Description("A brief description of this object. The description is displayed to users when they use a command for investigating an object")]
|
[Description("A brief description of this object. The description is displayed to users when they use a command for investigating an object")]
|
||||||
|
@ -39,10 +39,8 @@ namespace MudEngine.GameObjects
|
||||||
{
|
{
|
||||||
//Returns the name of the object + the objects Type as it's extension.
|
//Returns the name of the object + the objects Type as it's extension.
|
||||||
//Filenames are generated by the class itself, users can not assign it.
|
//Filenames are generated by the class itself, users can not assign it.
|
||||||
get
|
get;
|
||||||
{
|
set;
|
||||||
return this.ID + "." + GetType().Name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Category("Environment Information")]
|
[Category("Environment Information")]
|
||||||
|
@ -76,12 +74,22 @@ namespace MudEngine.GameObjects
|
||||||
this.Smell = "You don't smell anything unsual.";
|
this.Smell = "You don't smell anything unsual.";
|
||||||
this.Name = DefaultName();
|
this.Name = DefaultName();
|
||||||
|
|
||||||
|
this.Filename = DefaultName() + "." + this.GetType().Name;
|
||||||
|
|
||||||
//This must be called on instancing of the object.
|
//This must be called on instancing of the object.
|
||||||
//It is unique and will be used for saving the object.
|
//It is unique and will be used for saving the object.
|
||||||
//Allows for multiple objects with the same Name property
|
//Allows for multiple objects with the same Name property
|
||||||
//but different Identifiers. Letting there be multiple versions
|
//but different Identifiers. Letting there be multiple versions
|
||||||
//of the same object.
|
//of the same object.
|
||||||
this.ID = Guid.NewGuid();
|
|
||||||
|
ActiveGame.AddObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
~BaseObject()
|
||||||
|
{
|
||||||
|
//We must free up this ID so that it can be used by other objects being instanced.
|
||||||
|
ActiveGame.RemoveObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ShouldSerializeName()
|
private bool ShouldSerializeName()
|
||||||
|
|
|
@ -89,7 +89,7 @@ namespace MudEngine.GameObjects.Characters
|
||||||
}
|
}
|
||||||
|
|
||||||
//Restore the users current Room.
|
//Restore the users current Room.
|
||||||
Realm realm = ActiveGame.GetRealmByID(Guid.Parse(FileManager.GetData(filename, "CurrentRealm")));
|
Realm realm = ActiveGame.GetRealmByID(Convert.ToInt32(FileManager.GetData(filename, "CurrentRealm")));
|
||||||
|
|
||||||
if (realm == null)
|
if (realm == null)
|
||||||
{
|
{
|
||||||
|
@ -97,7 +97,7 @@ namespace MudEngine.GameObjects.Characters
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Zone zone = realm.GetZoneByID(Guid.Parse(FileManager.GetData(filename, "CurrentZone")));
|
Zone zone = realm.GetZoneByID(Convert.ToInt32(FileManager.GetData(filename, "CurrentZone")));
|
||||||
|
|
||||||
if (zone == null)
|
if (zone == null)
|
||||||
{
|
{
|
||||||
|
@ -105,7 +105,7 @@ namespace MudEngine.GameObjects.Characters
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentRoom = zone.GetRoomByID(Guid.Parse(FileManager.GetData(filename, "CurrentRoom")));
|
CurrentRoom = zone.GetRoomByID(Convert.ToInt32(FileManager.GetData(filename, "CurrentRoom")));
|
||||||
if (CurrentRoom == null)
|
if (CurrentRoom == null)
|
||||||
{
|
{
|
||||||
CurrentRoom = new Room(ActiveGame);
|
CurrentRoom = new Room(ActiveGame);
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace MudEngine.GameObjects.Environment
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="zoneName"></param>
|
/// <param name="zoneName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Zone GetZoneByID(Guid id)
|
public Zone GetZoneByID(Int32 id)
|
||||||
{
|
{
|
||||||
foreach (Zone zone in ZoneCollection)
|
foreach (Zone zone in ZoneCollection)
|
||||||
{
|
{
|
||||||
|
|
|
@ -88,7 +88,7 @@ namespace MudEngine.GameObjects.Environment
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="RoomName"></param>
|
/// <param name="RoomName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Room GetRoomByID(Guid id)
|
public Room GetRoomByID(Int32 id)
|
||||||
{
|
{
|
||||||
foreach (Room room in RoomCollection)
|
foreach (Room room in RoomCollection)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,8 @@ namespace MudEngine.Scripting
|
||||||
public enum ScriptTypes
|
public enum ScriptTypes
|
||||||
{
|
{
|
||||||
Assembly,
|
Assembly,
|
||||||
SourceFiles
|
SourceFiles,
|
||||||
|
Both
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -83,6 +84,7 @@ namespace MudEngine.Scripting
|
||||||
private Assembly _ScriptAssembly;
|
private Assembly _ScriptAssembly;
|
||||||
private List<Assembly> _AssemblyCollection;
|
private List<Assembly> _AssemblyCollection;
|
||||||
private string[] _ErrorMessages;
|
private string[] _ErrorMessages;
|
||||||
|
private string _SettingsFile;
|
||||||
Game _Game;
|
Game _Game;
|
||||||
|
|
||||||
public ScriptEngine(Game game) : this(game, ScriptTypes.Assembly)
|
public ScriptEngine(Game game) : this(game, ScriptTypes.Assembly)
|
||||||
|
@ -98,11 +100,17 @@ namespace MudEngine.Scripting
|
||||||
public ScriptEngine(Game game, ScriptTypes scriptTypes)
|
public ScriptEngine(Game game, ScriptTypes scriptTypes)
|
||||||
{
|
{
|
||||||
//Initialize our engine fields
|
//Initialize our engine fields
|
||||||
ScriptType = scriptTypes;
|
_SettingsFile = "Settings.ini";
|
||||||
|
|
||||||
|
ScriptExtension = FileManager.GetData(_SettingsFile, "ScriptExtension");
|
||||||
|
if (String.IsNullOrEmpty(ScriptExtension))
|
||||||
ScriptExtension = ".cs";
|
ScriptExtension = ".cs";
|
||||||
|
|
||||||
//Get our current install path
|
//Get our current install path
|
||||||
|
ScriptPath = FileManager.GetData(_SettingsFile, "ScriptPath");
|
||||||
|
if (String.IsNullOrEmpty(ScriptPath))
|
||||||
ScriptPath = "Scripts";
|
ScriptPath = "Scripts";
|
||||||
|
|
||||||
InstallPath = Environment.CurrentDirectory;
|
InstallPath = Environment.CurrentDirectory;
|
||||||
GameObjects = new List<GameObject>();
|
GameObjects = new List<GameObject>();
|
||||||
_AssemblyCollection = new List<Assembly>();
|
_AssemblyCollection = new List<Assembly>();
|
||||||
|
@ -210,13 +218,15 @@ namespace MudEngine.Scripting
|
||||||
/// <param name="scriptAssembly"></param>
|
/// <param name="scriptAssembly"></param>
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
if (ScriptType == ScriptTypes.Assembly)
|
if ((ScriptType == ScriptTypes.Assembly) || (ScriptType == ScriptTypes.Both))
|
||||||
{
|
{
|
||||||
Log.Write("Loading Assembly based scripts...");
|
Log.Write("Loading Assembly based Scripts...");
|
||||||
InitializeAssembly();
|
InitializeAssembly();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if ((ScriptType == ScriptTypes.SourceFiles) || (ScriptType == ScriptTypes.Both))
|
||||||
{
|
{
|
||||||
|
Log.Write("Loading Source File based Scripts...");
|
||||||
InitializeSourceFiles();
|
InitializeSourceFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,7 @@ namespace MudGame
|
||||||
Log.IsVerbose = false;
|
Log.IsVerbose = false;
|
||||||
|
|
||||||
Log.Write("Loading settings...");
|
Log.Write("Loading settings...");
|
||||||
scriptEngine = new ScriptEngine(new Game(), ScriptEngine.ScriptTypes.SourceFiles);
|
scriptEngine = new ScriptEngine(new Game(), ScriptEngine.ScriptTypes.Both);
|
||||||
scriptEngine.ScriptPath = FileManager.GetData(SettingsFile, "ScriptPath");
|
|
||||||
scriptEngine.ScriptExtension = FileManager.GetData(SettingsFile, "ScriptExtension");
|
|
||||||
|
|
||||||
//scriptEngine.CompileScripts();
|
//scriptEngine.CompileScripts();
|
||||||
Log.Write("Initializing Script Engine for Script Compilation...");
|
Log.Write("Initializing Script Engine for Script Compilation...");
|
||||||
|
@ -66,7 +64,6 @@ namespace MudGame
|
||||||
game = (Game)obj.Instance;
|
game = (Game)obj.Instance;
|
||||||
scriptEngine = new ScriptEngine(game, ScriptEngine.ScriptTypes.Assembly);
|
scriptEngine = new ScriptEngine(game, ScriptEngine.ScriptTypes.Assembly);
|
||||||
}
|
}
|
||||||
scriptEngine.ScriptPath = FileManager.GetDataPath(SaveDataTypes.Root);
|
|
||||||
//Force TCP
|
//Force TCP
|
||||||
game.ServerType = ProtocolType.Tcp;
|
game.ServerType = ProtocolType.Tcp;
|
||||||
|
|
||||||
|
@ -111,38 +108,8 @@ namespace MudGame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DateTime serverTime = new DateTime();
|
|
||||||
DateTime systemTime = DateTime.Now;
|
|
||||||
|
|
||||||
int lastSaveGap = 0;
|
|
||||||
|
|
||||||
while (game.IsRunning)
|
while (game.IsRunning)
|
||||||
{
|
{
|
||||||
if (lastSaveGap == 30)
|
|
||||||
{
|
|
||||||
if (game.AutoSave)
|
|
||||||
game.Save();
|
|
||||||
lastSaveGap = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//ServerTime holds the last minute prior to our current minute.
|
|
||||||
if (serverTime.Minute != DateTime.Now.Minute)
|
|
||||||
{
|
|
||||||
serverTime = DateTime.Now;
|
|
||||||
lastSaveGap++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (game.IsMultiplayer)
|
|
||||||
{
|
|
||||||
Console.Write(Log.GetMessages());
|
|
||||||
Log.FlushMessages();
|
|
||||||
System.Threading.Thread.Sleep(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
game.PlayerCollection[0].ExecuteCommand(Console.ReadLine());
|
|
||||||
}
|
|
||||||
game.Update();
|
game.Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
5
MudGame/bin/Release/..svnbridge/.svnbridge
Normal file
5
MudGame/bin/Release/..svnbridge/.svnbridge
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?><ItemProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Properties><Property><Name>svn:ignore</Name><Value>MudEngine.dll
|
||||||
|
MudEngine.pdb
|
||||||
|
MudGame.exe
|
||||||
|
MudGame.pdb
|
||||||
|
</Value></Property></Properties></ItemProperties>
|
Loading…
Add table
Add a link
Reference in a new issue