muddesigner/MudEngine/GameObjects/Environment/Room.cs
Scionwest_cp de82476525 MudEngine:
- 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.
2010-09-03 19:50:32 -07:00

172 lines
5.8 KiB
C#

//Microsoft .NET Framework
using System;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
//MUD Engine
using MudEngine.FileSystem;
using MudEngine.GameObjects.Items;
using MudEngine.GameManagement;
namespace MudEngine.GameObjects.Environment
{
[XmlInclude(typeof(Door))]
public class Room : BaseObject
{
[Category("Environment Information")]
[Description("Allows for linking of Rooms together via Doorways")]
//[EditorAttribute(typeof(UIDoorwayEditor), typeof(UITypeEditor))]
[RefreshProperties(RefreshProperties.All)]
public List<Door> Doorways { get; internal set; }
[ReadOnly(true)]
[Description("This is the Zone that the Room is currently assigned to.")]
[Category("Environment Information")]
public String Zone
{
get;
set;
}
[ReadOnly(true)]
[Description("This is the Realm that the Room belongs to.")]
[Category("Environment Information")]
public String Realm
{
get;
set;
}
[Category("Environment Information")]
[DefaultValue(false)]
[Description("Determins if the Player can be attacked within this Room or not.")]
public Boolean IsSafe
{
get;
set;
}
/// <summary>
/// Gets or Sets if this is the starting room for the Zone that contains it.
/// </summary>
[Browsable(true)]
[Description("Sets if this is the starting room for the Zone that contains it.")]
public Boolean IsInitialRoom
{
get;
set;
}
/// <summary>
/// Gets the current complete location for this Room, including Realm and Zone paths.
/// This includes the objects Filenames.
/// </summary>
public String RoomLocation
{
get
{
return this.Realm + ">" + Zone + ">" + Filename;
}
}
/// <summary>
/// Gets the current complete location for this Room, including Realm and Zone paths.
/// This includes the objects Filenames without their file extension.
/// </summary>
public String RoomLocationWithoutExtension
{
get
{
return Path.GetFileNameWithoutExtension(Realm) + ">" + Path.GetFileNameWithoutExtension(Zone) + ">" + Path.GetFileNameWithoutExtension(Filename);
}
}
public Room(Game game) :base(game)
{
Doorways = new List<Door>();
IsSafe = false;
}
/// <summary>
/// Saves the Room to file within the Game.DataPath.Environment path.
/// Room is saved within a Realm/Zone/Room directory structure
/// </summary>
/// <param name="path"></param>
public override void Save(String path)
{
base.Save(path);
String filename = Path.Combine(path, Filename);
FileManager.WriteLine(filename, IsInitialRoom.ToString(), "IsInitialRoom");
FileManager.WriteLine(filename, this.IsSafe.ToString(), "IsSafe");
FileManager.WriteLine(filename, this.Realm, "Realm");
FileManager.WriteLine(filename, this.Zone, "Zone");
FileManager.WriteLine(filename, Doorways.Count.ToString(), "DoorwayCount");
foreach (Door d in Doorways)
{
FileManager.WriteLine(filename, d.ArrivalRoom.RoomLocation, "DoorwayArrivalRoom");
FileManager.WriteLine(filename, d.DepartureRoom.RoomLocation, "DoorwayDepartureRoom");
FileManager.WriteLine(filename, d.IsLocked.ToString(), "DoorwayIsLocked");
FileManager.WriteLine(filename, d.LevelRequirement.ToString(), "DoorwayLevelRequirement");
FileManager.WriteLine(filename, d.TravelDirection.ToString(), "DoorwayTravelDirection");
//TODO: Save Doorway Keys
}
}
public override void Load(string filename)
{
base.Load(filename);
this.IsInitialRoom = Convert.ToBoolean(FileManager.GetData(filename, "IsInitialRoom"));
this.IsSafe = Convert.ToBoolean(FileManager.GetData(filename, "IsSafe"));
this.Realm = FileManager.GetData(filename, "Realm");
this.Zone = FileManager.GetData(filename, "Zone");
//SetRoomToDoorNorth
//SetRoomToDoorEast
//etc...
//Restoring Doorways performed by Zone.RestoreLinkedRooms() Called via GameWorld.Load();
}
/// <summary>
/// Checks to see if a doorway in the travelDirection exists.
/// </summary>
/// <param name="travelDirection"></param>
/// <returns></returns>
public Boolean DoorwayExist(AvailableTravelDirections travelDirection)
{
foreach (Door door in Doorways)
{
if (door.TravelDirection == travelDirection)
return true;
}
return false;
}
/// <summary>
/// Gets reference to the Rooms door connected in the supplied travelDirection
/// </summary>
/// <param name="travelDirection"></param>
/// <returns></returns>
public Door GetDoor(AvailableTravelDirections travelDirection)
{
foreach (Door door in this.Doorways)
{
if (door.TravelDirection == travelDirection)
return door;
}
return null;
}
}
}