muddesigner/MudEngine/GameObjects/Environment/Realm.cs
Scionwest_cp b3238d0227 MudEngine:
- Improvements to the EditRealm command. Bug fixes and tweaks
 - EditRealm command now updates All Zones and Rooms within other Realms when its Realm.name is changed instead of only child Zones/Rooms.
 - Realms, Zones and Rooms will now append a file extension if no file extension is supplied during GetRealm(), GetZone() and GetRoom() method invokes.
 - Realm.InitialZone is no longer read-only
 - Zone.InitialRoom is no longer read-only.
 - Added EditZone command. Allows for editing pre-existing Zones. Zones can be created via the Create command.
 - Added EditRoom command. Allows for editing pre-existing Rooms. Rooms can be created via the Create command.

MudGame:
 - Re-organized the Scripts directory. All Admin commands are now placed within a 'AdminCommands' folder while the player based commands are in a 'PlayerCommands' folder. All remaining scripts reside within the Scripts root folder.
2010-09-05 16:28:35 -07:00

131 lines
4.4 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; 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"));
//Load all zones
foreach (String zone in FileManager.GetCollectionData(filename, "ZoneCollection"))
{
Zone z = new Zone(ActiveGame);
String path = Path.Combine(ActiveGame.DataPaths.Environment, Path.GetFileNameWithoutExtension(this.Filename), "Zones", Path.GetFileNameWithoutExtension(zone));
z.Load(Path.Combine(path, zone));
//Check if this is the initial Zone.
if (z.IsInitialZone)
InitialZone = z;
ZoneCollection.Add(z);
}
}
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");
if (this.InitialZone.Name != "New Zone")
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> GetZone(String filename)
{
List<Zone> zones = new List<Zone>();
if (!filename.ToLower().EndsWith(".zone"))
filename += ".zone";
foreach (Zone zone in ZoneCollection)
{
if (zone.Filename.ToLower() == filename.ToLower())
{
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;
//Set the Zones default senses to that of the Realm provided the Zone does
//not already have a sense description assigned to it.
if ((!String.IsNullOrEmpty(this.Feel)) && (String.IsNullOrEmpty(zone.Feel)))
zone.Feel = this.Feel;
if ((!String.IsNullOrEmpty(this.Listen)) && (String.IsNullOrEmpty(zone.Listen)))
zone.Listen = this.Listen;
if ((!String.IsNullOrEmpty(this.Smell)) && (String.IsNullOrEmpty(zone.Smell)))
zone.Smell = this.Smell;
}
}
}