//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 ZoneCollection { get; private set; } /// /// Gets or Sets if this Realm is the starting realm for the game. /// public Boolean IsInitialRealm { get; set; } /// /// The Initial Starting Zone for this Realm. /// public Zone InitialZone { get; set; } protected override string SavePath { get { return Path.Combine(ActiveGame.DataPaths.Environment, Path.GetFileNameWithoutExtension(this.Filename)); } } public Realm(GameManagement.Game game) : base(game) { ZoneCollection = new List(); 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.Combine(ActiveGame.DataPaths.Environment, Path.GetFileNameWithoutExtension(Filename)); base.Save(); 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(); } } public List GetZone(String filename) { List zones = new List(); 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; } } }