- Added FileManager.GetDataSpan() method. This allows developers to start at a line and collect the next 'x' number of lines after that starting line. Example: GetDataSpan("MyFile.txt", 5, "DoorwayArrivalRoom", true); This seeks MyFile.txt until it finds "DoorwayArrivalRoom" and then it stores that line and the next 4 lines for a total of 5 lines and returns the collection. The last argument 'true' means that the method will scan the rest of the file after the initial 5 lines and add any other lines that match the "DoorwayArrivalRoom" string as well. - Deleted CommandResults class as it's no longer used by the script engine. - Singleplayer and Multiplayer save data paths are now the same paths by default. - Game.Update() method now checks for auto-saving (instead of MudGame performing this check) - Saving and restoring of Realms, Zones, Rooms and Doorways now fully implemented. - GameTime now supports auto-saving - GameWorld.Update() now calls BaseCharacter.Update() and is ready for future update code. - GameWorld.AddObject and GameWorld.RemoveObject() have been removed. - GameWorld.AddRealm() re-added for adding Realms pre-populated with zones/rooms. Note that Zones and Rooms can be added to a Realm even after it has been added to the GameWorld.RealmCollection - BaseObject now contains a OnStart() event method. - BaseObject.Save() now saves BaseObject.DetailedDescription collection content. - Updated BaseCharacter to retrieve Environments by Filename rather than Object name. - BaseStats.Experience property added. - Door.RoomTravelType enum added for determining if the room is Arrival or Departure - Door.SetRoom() method added for restoring a Rooms Doorway link during world restoration. - Renamed Room.InstallPath to Room.RoomLocation. Contains a MyRealm.Realm>MyZone.Zone>MyRoom.Room path - Added Room.RoomLocationWithoutExtension property for returning the Rooms location without file extensions. Ex: MyRealm>MyZone>MyRoom - Room now saves Doorways. - The GameWorld now restores the link between Rooms once all Environment objects have been instanced and restored from their saved state. MudGame: - Minor clean-up with MudGame loop and shutdown. - Updated scripts to reflect changes made to the engine.
121 lines
3.8 KiB
C#
121 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"));
|
|
|
|
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));
|
|
|
|
//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");
|
|
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 == 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;
|
|
}
|
|
}
|
|
}
|