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:
Scionwest_cp 2010-08-12 17:05:07 -07:00
parent d212f5b854
commit 7a4c9211d4
9 changed files with 105 additions and 61 deletions

View file

@ -35,6 +35,9 @@ namespace MudEngine.Commands
player.CommandSystem.ExecuteCommand("Look", player);
if (player.ActiveGame.AutoSave)
player.Save(player.Filename);
return null;
}
}

View file

@ -72,7 +72,7 @@ namespace MudEngine.GameManagement
/// <summary>
/// Gets a copy of all identifiers being used in the game.
/// </summary>
internal List<Int32> ObjectIdentifierCollection { get; private set; }
internal List<BaseObject> WorldObjects { get; private set; }
#endregion
#region Game Information
@ -125,10 +125,16 @@ namespace MudEngine.GameManagement
[Category("Project Settings")]
[Description("Enable or Disable Auto-saving of players when the player travels")]
/// <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>
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")]
[Description("Hide Room names from being outputted to the console.")]
/// <summary>
@ -185,6 +191,7 @@ namespace MudEngine.GameManagement
CurrencyList = new List<Currency>();
scriptEngine = new Scripting.ScriptEngine(this);
RealmCollection = new List<Realm>();
WorldObjects = new List<BaseObject>();
WorldTime = new GameTime(this);
//Prepare the Save Paths for all of our Game objects.
@ -238,12 +245,8 @@ namespace MudEngine.GameManagement
if (!Directory.Exists(DataPaths.Players))
Directory.CreateDirectory(DataPaths.Players);
//First, compile and execute all of the script files.
scriptEngine.ScriptType = ScriptEngine.ScriptTypes.SourceFiles;
scriptEngine.Initialize();
//Next, load any pre-compiled libraries.
scriptEngine.ScriptType = ScriptEngine.ScriptTypes.Assembly;
//Load both pre-compiled and file based scripts
scriptEngine.ScriptType = ScriptEngine.ScriptTypes.Both;
scriptEngine.Initialize();
/*
@ -326,7 +329,38 @@ namespace MudEngine.GameManagement
public virtual void Update()
{
DateTime serverTime = new DateTime();
DateTime systemTime = DateTime.Now;
int lastSaveGap = 0;
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()
@ -414,6 +448,23 @@ namespace MudEngine.GameManagement
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>
/// Gets a Realm currently stored in the Games collection of Realms.
/// </summary>
@ -432,7 +483,7 @@ namespace MudEngine.GameManagement
return realms;
}
public Realm GetRealmByID(Guid id)
public Realm GetRealmByID(Int32 id)
{
foreach (Realm r in RealmCollection)
{

View file

@ -21,7 +21,7 @@ namespace MudEngine.GameObjects
[RefreshProperties(RefreshProperties.All)]
public string Name { get; set; }
public Guid ID { get; internal set; }
public Int32 ID { get; internal set; }
[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")]
@ -39,10 +39,8 @@ namespace MudEngine.GameObjects
{
//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.
get
{
return this.ID + "." + GetType().Name;
}
get;
set;
}
[Category("Environment Information")]
@ -76,12 +74,22 @@ namespace MudEngine.GameObjects
this.Smell = "You don't smell anything unsual.";
this.Name = DefaultName();
this.Filename = DefaultName() + "." + this.GetType().Name;
//This must be called on instancing of the object.
//It is unique and will be used for saving the object.
//Allows for multiple objects with the same Name property
//but different Identifiers. Letting there be multiple versions
//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()

View file

@ -89,7 +89,7 @@ namespace MudEngine.GameObjects.Characters
}
//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)
{
@ -97,7 +97,7 @@ namespace MudEngine.GameObjects.Characters
return;
}
Zone zone = realm.GetZoneByID(Guid.Parse(FileManager.GetData(filename, "CurrentZone")));
Zone zone = realm.GetZoneByID(Convert.ToInt32(FileManager.GetData(filename, "CurrentZone")));
if (zone == null)
{
@ -105,7 +105,7 @@ namespace MudEngine.GameObjects.Characters
return;
}
CurrentRoom = zone.GetRoomByID(Guid.Parse(FileManager.GetData(filename, "CurrentRoom")));
CurrentRoom = zone.GetRoomByID(Convert.ToInt32(FileManager.GetData(filename, "CurrentRoom")));
if (CurrentRoom == null)
{
CurrentRoom = new Room(ActiveGame);

View file

@ -40,7 +40,7 @@ namespace MudEngine.GameObjects.Environment
/// </summary>
/// <param name="zoneName"></param>
/// <returns></returns>
public Zone GetZoneByID(Guid id)
public Zone GetZoneByID(Int32 id)
{
foreach (Zone zone in ZoneCollection)
{

View file

@ -88,7 +88,7 @@ namespace MudEngine.GameObjects.Environment
/// </summary>
/// <param name="RoomName"></param>
/// <returns></returns>
public Room GetRoomByID(Guid id)
public Room GetRoomByID(Int32 id)
{
foreach (Room room in RoomCollection)
{

View file

@ -23,7 +23,8 @@ namespace MudEngine.Scripting
public enum ScriptTypes
{
Assembly,
SourceFiles
SourceFiles,
Both
}
/// <summary>
@ -83,6 +84,7 @@ namespace MudEngine.Scripting
private Assembly _ScriptAssembly;
private List<Assembly> _AssemblyCollection;
private string[] _ErrorMessages;
private string _SettingsFile;
Game _Game;
public ScriptEngine(Game game) : this(game, ScriptTypes.Assembly)
@ -98,11 +100,17 @@ namespace MudEngine.Scripting
public ScriptEngine(Game game, ScriptTypes scriptTypes)
{
//Initialize our engine fields
ScriptType = scriptTypes;
_SettingsFile = "Settings.ini";
ScriptExtension = FileManager.GetData(_SettingsFile, "ScriptExtension");
if (String.IsNullOrEmpty(ScriptExtension))
ScriptExtension = ".cs";
//Get our current install path
ScriptPath = FileManager.GetData(_SettingsFile, "ScriptPath");
if (String.IsNullOrEmpty(ScriptPath))
ScriptPath = "Scripts";
InstallPath = Environment.CurrentDirectory;
GameObjects = new List<GameObject>();
_AssemblyCollection = new List<Assembly>();
@ -210,13 +218,15 @@ namespace MudEngine.Scripting
/// <param name="scriptAssembly"></param>
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();
}
else
if ((ScriptType == ScriptTypes.SourceFiles) || (ScriptType == ScriptTypes.Both))
{
Log.Write("Loading Source File based Scripts...");
InitializeSourceFiles();
}

View file

@ -41,9 +41,7 @@ namespace MudGame
Log.IsVerbose = false;
Log.Write("Loading settings...");
scriptEngine = new ScriptEngine(new Game(), ScriptEngine.ScriptTypes.SourceFiles);
scriptEngine.ScriptPath = FileManager.GetData(SettingsFile, "ScriptPath");
scriptEngine.ScriptExtension = FileManager.GetData(SettingsFile, "ScriptExtension");
scriptEngine = new ScriptEngine(new Game(), ScriptEngine.ScriptTypes.Both);
//scriptEngine.CompileScripts();
Log.Write("Initializing Script Engine for Script Compilation...");
@ -66,7 +64,6 @@ namespace MudGame
game = (Game)obj.Instance;
scriptEngine = new ScriptEngine(game, ScriptEngine.ScriptTypes.Assembly);
}
scriptEngine.ScriptPath = FileManager.GetDataPath(SaveDataTypes.Root);
//Force 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)
{
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();
}
}

View 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>