muddesigner/MudEngine/GameObjects/Environment/Realm.cs
Scionwest_cp de38cbf272 MudEngine:
- Fixed FileManager.GetDataSpan Index out of bounds exception.
 - Game.Save no long invokes the BaseCharacter.ExecuteCommand("Save"); rather it now just directly invokes BaseCharacter.Save(). This fixes the client typing bug where a new command line was printed to the screen everytime the game world saved.
 - GameWorld now supports storing and saving dynamically created Realms.
 - Renamed BaseCharacter.GetRoomByFilename() to just GetRoom() as all Get() named Methods require a filename.
 - Optimized the loading and saving of Realms, Zones and Rooms some.
 - Room now Loads and Saves the RoomLocation property instead of the Room's Zone and Realm properties individually.
 - GameWorld.GetRealm(), Realm.GetZone() and Zone.GetRoom() now perform case-insensitive checking when scanning for content.

MudGame:
 - Re-wrote the 'Create' command script from the ground up. 50% less code and much better approach to creating content. Now to create content you will use the same formatting as the Room.RoomLocation property.
        Example: Creating a Realm is done with 'Create MyRealm'
        Example: Creating a Zone is done with 'Create MyRealm>MyZone'
        Example: Creating a Room is done with 'Create MyRealm>MyZone>MyRoom'
   If the Realm or Zone does not exist when creating a Room or Zone, then the parent will be created automatically for you.
 - Fixed a bug in the WorldCalifornia script were it was saving the Hallway Room with a Zone file extension, preventing it from working correctly during restoration.
2010-09-04 00:10:04 -07:00

119 lines
3.8 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"));
//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>();
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;
}
}
}