MudEngine:
- BaseObject Saving and Loading fully implemented. - BaseCharacter Saving and Loading fully implemented. - Game.cs now contains SaveDataPaths property for allowing users to define where their data will be saved. -
This commit is contained in:
parent
7f39821216
commit
4be5a831b1
8 changed files with 137 additions and 125 deletions
|
@ -3,6 +3,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
//MUD Engine
|
||||
using MudEngine.FileSystem;
|
||||
|
@ -53,6 +54,44 @@ namespace MudEngine.GameObjects.Characters
|
|||
|
||||
}
|
||||
|
||||
public override void Load(string filename)
|
||||
{
|
||||
base.Load(filename);
|
||||
|
||||
this.IsControlled = Convert.ToBoolean(FileManager.GetData(filename, "IsControlled"));
|
||||
|
||||
//Need to re-assign the enumerator value that was previously assigned to the Role property
|
||||
Array values = Enum.GetValues(typeof(SecurityRoles));
|
||||
foreach (int value in values)
|
||||
{
|
||||
//Since enum values are not strings, we can't simply just assign the string to the enum
|
||||
string displayName = Enum.GetName(typeof(SecurityRoles), value);
|
||||
|
||||
//If the value = the string saved, then perform the needed conversion to get our data back
|
||||
if (displayName.ToLower() == FileManager.GetData(filename, "Role").ToLower())
|
||||
{
|
||||
Role = (SecurityRoles)Enum.Parse(typeof(SecurityRoles), displayName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Restore the users current Room.
|
||||
Realm realm = ActiveGame.GetRealm(FileManager.GetData(filename, "CurrentRealm"));
|
||||
Zone zone = realm.GetZone(FileManager.GetData(filename, "CurrentZone"));
|
||||
CurrentRoom = zone.GetRoom(FileManager.GetData(filename, "CurrentRoom"));
|
||||
}
|
||||
|
||||
public override void Save(string filename)
|
||||
{
|
||||
base.Save(filename);
|
||||
|
||||
FileManager.WriteLine(filename, this.IsControlled.ToString(), "IsControlled");
|
||||
FileManager.WriteLine(filename, this.Role.ToString(), "Role");
|
||||
FileManager.WriteLine(filename, this.CurrentRoom.Name, "CurrentRoom");
|
||||
FileManager.WriteLine(filename, this.CurrentRoom.Zone, "CurrentZone");
|
||||
FileManager.WriteLine(filename, this.CurrentRoom.Realm, "CurrentRealm");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the player from one Room to another if the supplied direction contains a doorway.
|
||||
/// Returns false if no doorway is available.
|
||||
|
@ -135,8 +174,8 @@ namespace MudEngine.GameObjects.Characters
|
|||
}
|
||||
internal void Disconnect()
|
||||
{
|
||||
// TODO: Save();
|
||||
Save();
|
||||
string filePath = Path.Combine(ActiveGame.DataPaths.Players, Filename);
|
||||
this.Save(filePath);
|
||||
|
||||
IsActive = false;
|
||||
client.Close();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue