muddesigner/MudEngine/GameObjects/Environment/Realm.cs
Scionwest_cp 5aa5504171 MudEngine:
- Added FileManager.GetDataCollection() Method for getting a collection of values that match the supplied parameter. This is used by environments for restoring saved object collections
 - World Restoration is now fully implemented.
 - Removed un-needed Log messages
 - Added a pushMessage parameter to Log.Write() allowing messages to be sent directly to the console instead of stacking them in a cache. All log messages now push the message by default.
2010-08-15 11:15:35 -07:00

125 lines
3.9 KiB
C#

//Microsoft .NET Framework
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;
//MUD Engine
using MudEngine.FileSystem;
using MudEngine.GameObjects;
namespace MudEngine.GameObjects.Environment
{
public class Realm : BaseObject
{
[Category("Environment Information")]
[Description("A collection of Zones that are contained within this Realm. Players can traverse the world be traveling through Rooms that are contained within Zones. Note that it is not required to place a Zone into a Realm.")]
//[EditorAttribute(typeof(UIRealmEditor), typeof(System.Drawing.Design.UITypeEditor))]
public List<Zone> ZoneCollection { get; private set; }
/// <summary>
/// Gets or Sets if this Realm is the starting realm for the game.
/// </summary>
public Boolean IsInitialRealm { get; set; }
/// <summary>
/// The Initial Starting Zone for this Realm.
/// </summary>
public Zone InitialZone { get; private set; }
public Realm(GameManagement.Game game) : base(game)
{
ZoneCollection = new List<Zone>();
InitialZone = new Zone(game);
}
public override void Load(string filename)
{
base.Load(filename);
IsInitialRealm = Convert.ToBoolean(FileManager.GetData(filename, "IsInitialRealm"));
String zoneFile = FileManager.GetData(filename, "InitialZone");
String realmPath = filename.Substring(0, filename.Length - Path.GetFileName(filename).Length);
String zonePath = Path.Combine(realmPath, "Zones", Path.GetFileNameWithoutExtension(zoneFile));
//Load all zones
foreach (String zone in FileManager.GetCollectionData(filename, "ZoneCollection"))
{
Zone z = new Zone(ActiveGame);
z.Load(Path.Combine(zonePath, zone));
}
//Set the initial zone.
foreach (Zone z in ZoneCollection)
{
if (z.IsInitialZone)
{
InitialZone = z;
break;
}
}
}
public override void Save(String path)
{
path = Path.Combine(path, Path.GetFileNameWithoutExtension(Filename));
base.Save(path);
String filename = Path.Combine(path, Filename);
FileManager.WriteLine(filename, this.IsInitialRealm.ToString(), "IsInitialRealm");
FileManager.WriteLine(filename, this.InitialZone.Filename, "InitialZone");
String zonePath = Path.Combine(path, "Zones");
foreach (Zone z in ZoneCollection)
{
FileManager.WriteLine(filename, z.Filename, "ZoneCollection");
z.Save(zonePath);
}
}
public List<Zone> GetZoneByFilename(String filename)
{
List<Zone> zones = new List<Zone>();
foreach (Zone zone in ZoneCollection)
{
if (zone.Filename == filename)
{
zones.Add(zone);
}
}
return zones;
}
public void AddZone(Zone zone)
{
if (zone.IsInitialZone)
{
foreach (Zone z in ZoneCollection)
{
if (z.IsInitialZone)
{
z.IsInitialZone = false;
break;
}
}
}
if (zone.IsInitialZone)
InitialZone = zone;
//TODO: Check fo duplicates
ZoneCollection.Add(zone);
zone.Realm = Filename;
}
}
}