muddesigner/Mud Designer/MudEngine/GameObjects/Environment/Room.cs
Scionwest_cp f79a5d482b Engine:
- Removed the ManagedScripting Engine from the project. Scripting will be implemented at a later time using a custom build engine.
 - Room.Load was re-wrote to allow for loading a supplied room name (not a full filename). The Room will load the supplied Roomname by checking within it's current Zone. Rooms within different Zones can be loaded by supplying a Zone name as one of the optional parameters. Same goes for loading Rooms within a different Realm
 - All classes using the original Room.Load code have been tweaked to use the new code. Cuts the needed code used by each individual class by 80%.
 - Room.InstallPath Property added for returning the full filename and location of the Room where it's currently installed.

Designer:
 - Room Designer now supports deleting Rooms.
 - Doorway Editor no longer fails when attempting to change doorway Traveling Directions.

Runtime:
 - No longer prints blank lines if the object does not contain any text to print.
 - Added a 2nd Print method with a boolean argument for printing blank lines by force if needed.

Note: Room Deleting and Room.Load code was only tested using Rooms within Root Zones. Rooms contained within a Zone owned by a Realm was not tested.
2010-02-06 20:56:15 -08:00

187 lines
6 KiB
C#

using System;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Drawing.Design;
using System.IO;
using MudDesigner.MudEngine.FileSystem;
using MudDesigner.MudEngine.UITypeEditors;
namespace MudDesigner.MudEngine.GameObjects.Environment
{
[XmlInclude(typeof(Door))]
public class Room : BaseObject
{
[Category("Environment Information")]
[Description("Shows what rooms are currently created and linked to within this Room.")]
[ReadOnly(true)]
public string InstalledDoorways
{
get
{
string installed = "";
if (this.Doorways.Count != 0)
{
foreach (Door d in Doorways)
{
installed += d.TravelDirection.ToString() + ",";
}
if (Doorways.Count >= 2)
{
installed = installed.Substring(0, installed.Length - 1);
}
return installed;
}
else
return "None Installed.";
}
}
[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;
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 bool IsSafe
{
get;
set;
}
[Browsable(false)]
public string InstallPath
{
get
{
string zonePath = "";
if (this.Realm == null || this.Realm == "No Realm Associated.")
{
zonePath = FileManager.GetDataPath(SaveDataTypes.Zones);
zonePath = Path.Combine(zonePath, this.Zone);
}
else
zonePath = FileManager.GetDataPath(this.Realm, this.Zone);
string roomPath = Path.Combine(zonePath, "Rooms");
string filename = Path.Combine(roomPath, this.Filename);
return filename;
}
}
public Room()
{
Doorways = new List<Door>();
IsSafe = false;
}
public bool DoorwayExist(string travelDirection)
{
foreach (Door door in Doorways)
{
if (door.TravelDirection.ToString().ToLower() == travelDirection.ToLower())
return true;
}
return false;
}
public Door GetDoor(AvailableTravelDirections travelDirection)
{
foreach (Door door in this.Doorways)
{
if (door.TravelDirection == travelDirection)
return door;
}
return null;
}
/// <summary>
/// Load a Room that exists within the same Zone as the current Room
/// </summary>
/// <param name="roomName"></param>
/// <returns></returns>
public override object Load(string roomName)
{
//Correct the roomname incase it doesnt contain a file extension
if (!roomName.ToLower().EndsWith(".room"))
roomName += ".room";
//If the current room does not belong within a Realm, then load it from the
//Zones root directory
if (this.Realm != null || this.Realm != "No Realm Associated.")
{
return this.Load(roomName, this.Zone);
}
//This Zone is contained within a Realm so we have to load it from within the
//Realm and not from within the Zones root directory
else
return this.Load(roomName, this.Zone, this.Realm);
}
public object Load(string roomName, string zoneName)
{
string filename = "";
if (!roomName.ToLower().EndsWith(".room"))
roomName += ".room";
if (this.Realm != null && this.Realm != "No Realm Associated.")
{
return this.Load(roomName, zoneName, this.Realm);
}
else
filename = FileManager.GetDataPath(SaveDataTypes.Zones);
filename = Path.Combine(filename, zoneName);
filename = Path.Combine(filename, "Rooms");
filename = Path.Combine(filename, roomName);
return base.Load(filename);
}
public object Load(string roomName, string zoneName, string realmName)
{
if (!roomName.ToLower().EndsWith(".room"))
roomName += ".room";
string filename = FileManager.GetDataPath(realmName, zoneName);
filename = Path.Combine(filename, "Rooms");
filename = Path.Combine(filename, roomName);
if (realmName == null || realmName == "No Realm Associated.")
return this.Load(roomName, zoneName);
return base.Load(filename);
}
}
}