Room save/load code under construction. Realized during implementation that I will need to re-work the environment save code due to how rooms doors are loaded and saved.
This commit is contained in:
parent
706c770dd7
commit
2c39c7538e
9 changed files with 148 additions and 13 deletions
|
@ -40,6 +40,19 @@ namespace MudEngine.DAL
|
|||
return String.Empty;
|
||||
}
|
||||
|
||||
public String[] GetDataCollection(String property)
|
||||
{
|
||||
List<String> data = new List<string>();
|
||||
|
||||
foreach (XElement element in SaveData.Elements())
|
||||
{
|
||||
if (element.Name.LocalName == property)
|
||||
data.Add(element.Value);
|
||||
}
|
||||
|
||||
return data.ToArray();
|
||||
}
|
||||
|
||||
public Boolean Save(String filename)
|
||||
{
|
||||
if (!Directory.Exists(Path.GetDirectoryName(filename)))
|
||||
|
|
|
@ -22,12 +22,12 @@ namespace MudEngine.Game.Characters
|
|||
{
|
||||
return
|
||||
"Strength:" + this.Strength.ToString()
|
||||
+ ".Dexterity:" + this.Dexterity.ToString()
|
||||
+ ".Constitution:" + this.Constitution.ToString()
|
||||
+ ".Intelligence:" + this.Intelligence.ToString()
|
||||
+ ".Wisdom:" + this.Wisdom.ToString()
|
||||
+ ".Charisma:" + this.Charisma.ToString()
|
||||
+ ".Experience:" + this.Experience.ToString();
|
||||
+ ">Dexterity:" + this.Dexterity.ToString()
|
||||
+ ">Constitution:" + this.Constitution.ToString()
|
||||
+ ">Intelligence:" + this.Intelligence.ToString()
|
||||
+ ">Wisdom:" + this.Wisdom.ToString()
|
||||
+ ">Charisma:" + this.Charisma.ToString()
|
||||
+ ">Experience:" + this.Experience.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,28 @@ namespace MudEngine.Game.Environment
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{" + this.GetType().Name + "}: " + this.DepartureRoom.Name + "->" + this.TravelDirection.ToString() + "->" + this.ArrivalRoom.Name;
|
||||
if (this.RequiredKey == null)
|
||||
{
|
||||
return
|
||||
"DepartureRoom-" + this.DepartureRoom.Filename +
|
||||
">DepartureZone-" + this.DepartureRoom.Zone.Filename +
|
||||
">ArrivalRoom-" + this.ArrivalRoom.Filename +
|
||||
">ArrivalZone-" + this.ArrivalRoom.Zone.Filename +
|
||||
">Locked-" + this.Locked.ToString() +
|
||||
">RequiredKey-None" +
|
||||
">LevelRequirement-" + this.LevelRequirement.ToString() +
|
||||
">TravelDirection-" + this.TravelDirection.ToString();
|
||||
}
|
||||
else
|
||||
return
|
||||
"DepartureRoom-" + this.DepartureRoom.Filename +
|
||||
">DepartureZone-" + this.DepartureRoom.Zone.Filename +
|
||||
">ArrivalRoom-" + this.ArrivalRoom.Filename +
|
||||
">ArrivalZone-" + this.ArrivalRoom.Zone.Filename +
|
||||
">Locked-" + this.Locked.ToString() +
|
||||
">RequiredKey-" + this.RequiredKey.Filename +
|
||||
">LevelRequirement-" + this.LevelRequirement.ToString() +
|
||||
">TravelDirection-" + this.TravelDirection.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace MudEngine.Game.Environment
|
|||
|
||||
base.Load(filename);
|
||||
|
||||
String[] zones = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(this.Filename), "Zones"), "*.zone");
|
||||
String[] zones = Directory.GetFiles(Path.Combine(path, "Zones"), "*.zone", SearchOption.AllDirectories);
|
||||
|
||||
foreach (String zone in zones)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
using MudEngine.Core.Interfaces;
|
||||
using MudEngine.Core;
|
||||
|
@ -12,6 +13,15 @@ namespace MudEngine.Game.Environment
|
|||
{
|
||||
public class Room : Environment
|
||||
{
|
||||
public new String Filename
|
||||
{
|
||||
get
|
||||
{
|
||||
String path = Path.Combine(this.Game.SavePaths.GetPath(DAL.DataTypes.Environments), this.Zone.Realm.Name, "Zones", this.Zone.Name, "Rooms", this.Name + "." + this.GetType().Name);
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
public Zone Zone { get; private set; }
|
||||
|
||||
public Boolean Safe { get; set; }
|
||||
|
@ -26,6 +36,79 @@ namespace MudEngine.Game.Environment
|
|||
this.Zone = zone;
|
||||
}
|
||||
|
||||
public override bool Save()
|
||||
{
|
||||
if (!base.Save(true))
|
||||
return false;
|
||||
|
||||
this.SaveData.AddSaveData("Safe", this.Safe.ToString());
|
||||
|
||||
foreach (Doorway door in this._Doors)
|
||||
{
|
||||
this.SaveData.AddSaveData("Doorway", door.ToString());
|
||||
}
|
||||
|
||||
return this.SaveData.Save(this.Filename);
|
||||
}
|
||||
|
||||
public override void Load(string filename)
|
||||
{
|
||||
String path = Path.GetDirectoryName(filename);
|
||||
if (!Directory.Exists(path))
|
||||
return;
|
||||
|
||||
base.Load(filename);
|
||||
|
||||
Logger.WriteLine("Loading " + this.Name + "...");
|
||||
|
||||
try { this.Safe = Convert.ToBoolean(this.SaveData.GetData("Safe")); }
|
||||
catch { this.LoadFailedMessage("Safe"); }
|
||||
|
||||
try
|
||||
{
|
||||
String[] data = this.SaveData.GetDataCollection("Doorway");
|
||||
|
||||
foreach (String entry in data)
|
||||
{
|
||||
String[] values = entry.Split('>');
|
||||
|
||||
Room departure = new Room(this.Game, String.Empty, String.Empty, this.Zone);
|
||||
Room arrival = new Room(this.Game, String.Empty, String.Empty, this.Zone);
|
||||
|
||||
foreach (String value in values)
|
||||
{
|
||||
String[] propertyInfo = value.Split('-');
|
||||
|
||||
switch (propertyInfo[0])
|
||||
{
|
||||
case "DepartureRoom":
|
||||
departure.Load(propertyInfo[1]);
|
||||
break;
|
||||
case "DepartureZone":
|
||||
if (propertyInfo[1] != this.Zone.Filename)
|
||||
departure.Zone.Load(propertyInfo[1]);
|
||||
else
|
||||
departure.Zone = this.Zone;
|
||||
break;
|
||||
case "ArrivalRoom":
|
||||
arrival.Load(propertyInfo[1]);
|
||||
break;
|
||||
case "ArrivalZone":
|
||||
if (propertyInfo[1] != this.Zone.Filename)
|
||||
arrival.Zone.Load(propertyInfo[1]);
|
||||
else
|
||||
arrival.Zone = this.Zone;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
this.LoadFailedMessage("Doorway");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace MudEngine.Game.Environment
|
|||
{
|
||||
get
|
||||
{
|
||||
String path = Path.Combine(Path.GetDirectoryName(this.Realm.Filename), "Zones", this.Name + "." + this.GetType().Name);
|
||||
String path = Path.Combine(Path.GetDirectoryName(this.Realm.Filename), "Zones", this.Name, this.Name + "." + this.GetType().Name);
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,11 @@ namespace MudEngine.Game.Environment
|
|||
this.SaveData.AddSaveData("Safe", this.Safe.ToString());
|
||||
this.SaveData.AddSaveData("CharacterStats", this.StatDrain.ToString());
|
||||
|
||||
foreach (Room room in this._RoomCollection)
|
||||
{
|
||||
room.Save();
|
||||
}
|
||||
|
||||
return this.SaveData.Save(this.Filename);
|
||||
}
|
||||
|
||||
|
@ -62,7 +67,7 @@ namespace MudEngine.Game.Environment
|
|||
try
|
||||
{
|
||||
String data = this.SaveData.GetData("CharacterStats");
|
||||
String[] stats = data.Split('.');
|
||||
String[] stats = data.Split('>');
|
||||
CharacterStats charStats = new CharacterStats();
|
||||
|
||||
foreach (String stat in stats)
|
||||
|
@ -96,6 +101,13 @@ namespace MudEngine.Game.Environment
|
|||
{
|
||||
this.LoadFailedMessage("CharacterStats");
|
||||
}
|
||||
|
||||
String[] rooms = Directory.GetFiles(Path.Combine(path, "Rooms"));
|
||||
foreach (String room in rooms)
|
||||
{
|
||||
Room r = new Room(this.Game, String.Empty, String.Empty, this);
|
||||
r.Load(room);
|
||||
}
|
||||
}
|
||||
|
||||
public Room CreateRoom(String name, String description)
|
||||
|
|
|
@ -25,6 +25,8 @@ namespace MudEngine.GameScripts.Commands
|
|||
|
||||
public bool Execute(string command, StandardCharacter character)
|
||||
{
|
||||
character.SendMessage(character.CurrentRoom.Name);
|
||||
character.SendMessage(character.CurrentRoom.Description);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ namespace MudEngine.GameScripts
|
|||
{
|
||||
this.Server.ServerOwner = "Admin";
|
||||
base.Start(maxPlayers, maxQueueSize);
|
||||
|
||||
|
||||
|
||||
//Quick demonstration on how to create the initial starting room for new players.
|
||||
this.World.CreateRealm("Azeroth", "Starting Realm for beginning players");
|
||||
Zone z = this.World.GetRealm("Azeroth").CreateZone("Bedlam", "Initial Zone for new players.");
|
||||
|
@ -52,6 +53,9 @@ namespace MudEngine.GameScripts
|
|||
this.Enabled = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,9 +55,9 @@
|
|||
<Compile Include="Core\ObjectCollection.cs" />
|
||||
<Compile Include="DAL\DataPaths.cs" />
|
||||
<Compile Include="DAL\XMLData.cs" />
|
||||
<None Include="GameScripts\BaseCommands\Look.cs">
|
||||
<Compile Include="GameScripts\BaseCommands\Look.cs">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</Compile>
|
||||
<None Include="GameScripts\BaseCommands\Login.cs">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue