From e822537128b0da3651c1566f4253a3953d83a9a0 Mon Sep 17 00:00:00 2001 From: Scionwest_cp Date: Fri, 30 Jul 2010 15:50:53 -0700 Subject: [PATCH] MudEngine: - BaseObject save code re-wrote - Added Inventory property to BaseCharacter - BaseCharacter Save() now called when players are being disconnected. - Adjusted how objects Filenames are generated. --- MudEngine/Commands/CommandRestart.cs | 2 +- MudEngine/FileSystem/FileManager.cs | 9 +++++++++ MudEngine/GameObjects/BaseObject.cs | 10 +++++++--- MudEngine/GameObjects/Characters/BaseCharacter.cs | 13 +++++++++++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/MudEngine/Commands/CommandRestart.cs b/MudEngine/Commands/CommandRestart.cs index 39d8db7..fa79536 100644 --- a/MudEngine/Commands/CommandRestart.cs +++ b/MudEngine/Commands/CommandRestart.cs @@ -26,7 +26,7 @@ namespace MudEngine.Commands if (player.Role == SecurityRoles.Admin) { for (int i = 0; i < player.ActiveGame.PlayerCollection.Length; i++) - player.ActiveGame.PlayerCollection[i].Save(player.ActiveGame.PlayerCollection[i].Name + ".dat"); + player.ActiveGame.PlayerCollection[i].Save(); player.ActiveGame.Server.EndServer(); player.ActiveGame.Server.Initialize(555, ref player.ActiveGame.PlayerCollection); return new CommandResults("Server Restarted."); diff --git a/MudEngine/FileSystem/FileManager.cs b/MudEngine/FileSystem/FileManager.cs index de7ab6b..8520920 100644 --- a/MudEngine/FileSystem/FileManager.cs +++ b/MudEngine/FileSystem/FileManager.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; +using System.Reflection; namespace MudEngine.FileSystem { @@ -33,10 +34,18 @@ namespace MudEngine.FileSystem /// public static void Save(string Filename, object o) { + Type t = o.GetType(); + + foreach (PropertyInfo info in t.GetProperties()) + { + + } + /* if (FileType == OutputFormats.XML) { XmlSerialization.Save(Filename, o); } + */ } /// diff --git a/MudEngine/GameObjects/BaseObject.cs b/MudEngine/GameObjects/BaseObject.cs index b8fa009..a0233c8 100644 --- a/MudEngine/GameObjects/BaseObject.cs +++ b/MudEngine/GameObjects/BaseObject.cs @@ -64,6 +64,8 @@ namespace MudEngine.GameObjects set { string extension = "." + this.GetType().Name; + if (extension.StartsWith("Base")) + extension = extension.Substring("Base".Length); if (!value.EndsWith(extension)) value += extension; @@ -153,12 +155,14 @@ namespace MudEngine.GameObjects /// Saves the current object with the supplied filename /// /// - public void Save(string filename) + public void Save() { - string directory = Path.GetDirectoryName(filename); + string directory = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Root), "Saved", "Players"); + if (!Directory.Exists(directory)) Directory.CreateDirectory(directory); - FileManager.Save(filename, this); + + FileManager.Save(Filename, this); } public override string ToString() diff --git a/MudEngine/GameObjects/Characters/BaseCharacter.cs b/MudEngine/GameObjects/Characters/BaseCharacter.cs index a732b0c..b56938d 100644 --- a/MudEngine/GameObjects/Characters/BaseCharacter.cs +++ b/MudEngine/GameObjects/Characters/BaseCharacter.cs @@ -30,20 +30,27 @@ namespace MudEngine.GameObjects.Characters public Boolean IsControlled { get; set; } /// - /// Gets or Sets if this user has Admin privileges or not. + /// Gets if this user has Admin privileges or not. /// public SecurityRoles Role { get; private set; } /// - /// Gets or Sets if this player is active. + /// Gets or if this character is active. /// public Boolean IsActive { get; private set; } + /// + /// Gets the current inventory of the character + /// + public Bag Inventory { get; private set; } + public BaseCharacter(Game game) : base(game) { ActiveGame = game; IsActive = false; CurrentRoom = game.InitialRealm.InitialZone.InitialRoom; + Inventory = new Bag(game); + } /// @@ -129,6 +136,8 @@ namespace MudEngine.GameObjects.Characters internal void Clear() { // TODO: Save(); + Save(); + IsActive = false; client.Close(); // TODO: Reset game so it can be used again