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.
This commit is contained in:
parent
2152a139b0
commit
e822537128
4 changed files with 28 additions and 6 deletions
|
@ -26,7 +26,7 @@ namespace MudEngine.Commands
|
||||||
if (player.Role == SecurityRoles.Admin)
|
if (player.Role == SecurityRoles.Admin)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < player.ActiveGame.PlayerCollection.Length; i++)
|
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.EndServer();
|
||||||
player.ActiveGame.Server.Initialize(555, ref player.ActiveGame.PlayerCollection);
|
player.ActiveGame.Server.Initialize(555, ref player.ActiveGame.PlayerCollection);
|
||||||
return new CommandResults("Server Restarted.");
|
return new CommandResults("Server Restarted.");
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace MudEngine.FileSystem
|
namespace MudEngine.FileSystem
|
||||||
{
|
{
|
||||||
|
@ -33,10 +34,18 @@ namespace MudEngine.FileSystem
|
||||||
/// <param name="o"></param>
|
/// <param name="o"></param>
|
||||||
public static void Save(string Filename, object o)
|
public static void Save(string Filename, object o)
|
||||||
{
|
{
|
||||||
|
Type t = o.GetType();
|
||||||
|
|
||||||
|
foreach (PropertyInfo info in t.GetProperties())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
/*
|
||||||
if (FileType == OutputFormats.XML)
|
if (FileType == OutputFormats.XML)
|
||||||
{
|
{
|
||||||
XmlSerialization.Save(Filename, o);
|
XmlSerialization.Save(Filename, o);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -64,6 +64,8 @@ namespace MudEngine.GameObjects
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
string extension = "." + this.GetType().Name;
|
string extension = "." + this.GetType().Name;
|
||||||
|
if (extension.StartsWith("Base"))
|
||||||
|
extension = extension.Substring("Base".Length);
|
||||||
if (!value.EndsWith(extension))
|
if (!value.EndsWith(extension))
|
||||||
value += extension;
|
value += extension;
|
||||||
|
|
||||||
|
@ -153,12 +155,14 @@ namespace MudEngine.GameObjects
|
||||||
/// Saves the current object with the supplied filename
|
/// Saves the current object with the supplied filename
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename"></param>
|
/// <param name="filename"></param>
|
||||||
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))
|
if (!Directory.Exists(directory))
|
||||||
Directory.CreateDirectory(directory);
|
Directory.CreateDirectory(directory);
|
||||||
FileManager.Save(filename, this);
|
|
||||||
|
FileManager.Save(Filename, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
|
|
@ -30,20 +30,27 @@ namespace MudEngine.GameObjects.Characters
|
||||||
public Boolean IsControlled { get; set; }
|
public Boolean IsControlled { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets if this user has Admin privileges or not.
|
/// Gets if this user has Admin privileges or not.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SecurityRoles Role { get; private set; }
|
public SecurityRoles Role { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets if this player is active.
|
/// Gets or if this character is active.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Boolean IsActive { get; private set; }
|
public Boolean IsActive { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current inventory of the character
|
||||||
|
/// </summary>
|
||||||
|
public Bag Inventory { get; private set; }
|
||||||
|
|
||||||
public BaseCharacter(Game game) : base(game)
|
public BaseCharacter(Game game) : base(game)
|
||||||
{
|
{
|
||||||
ActiveGame = game;
|
ActiveGame = game;
|
||||||
IsActive = false;
|
IsActive = false;
|
||||||
CurrentRoom = game.InitialRealm.InitialZone.InitialRoom;
|
CurrentRoom = game.InitialRealm.InitialZone.InitialRoom;
|
||||||
|
Inventory = new Bag(game);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -129,6 +136,8 @@ namespace MudEngine.GameObjects.Characters
|
||||||
internal void Clear()
|
internal void Clear()
|
||||||
{
|
{
|
||||||
// TODO: Save();
|
// TODO: Save();
|
||||||
|
Save();
|
||||||
|
|
||||||
IsActive = false;
|
IsActive = false;
|
||||||
client.Close();
|
client.Close();
|
||||||
// TODO: Reset game so it can be used again
|
// TODO: Reset game so it can be used again
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue