muddesigner/MudEngine/GameObjects/Environment/Room.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

179 lines
6.1 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.RoomLocationWithoutExtension, "RoomLocation");
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"));
String[] env = FileManager.GetData(filename, "RoomLocation").Split('>');
if (env.Length != 3)
{
Log.Write("ERROR: Room " + filename + " does not contain a proper location path in Room.RoomLocation. Path is " + FileManager.GetData(filename, "RoomLocation"));
return;
}
this.Realm = env[0] + ".Realm";
this.Zone = env[1] + ".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;
}
}
}