muddesigner/Mud Designer/MudEngine/GameObjects/Environment/Zone.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

140 lines
4.3 KiB
C#

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Drawing.Design;
using MudDesigner.MudEngine.FileSystem;
using MudDesigner.MudEngine.GameObjects;
using MudDesigner.MudEngine.UITypeEditors;
namespace MudDesigner.MudEngine.GameObjects.Environment
{
[XmlInclude(typeof(Room))]
public class Zone : BaseObject
{
[Category("Environment Information")]
[DefaultValue(0)]
[Description("The amount to drain each stat by if StatDrain is enabled.")]
public int StatDrainAmount
{
get;
set;
}
[Category("Environment Information")]
[Description("Enable or Disable the ability for draining stats while traversing.")]
[DefaultValue(false)]
public bool StatDrain
{
get;
set;
}
[ReadOnly(true)]
[Category("Environment Information")]
[Description("The Realm that this Zone is assigned to. It is not required to be contained within a Realm.")]
public string Realm
{
get;
set;
}
[Category("Environment Information")]
[Description("Determins if the Player can be attacked within this Room or not.")]
[DefaultValue(false)]
public bool IsSafe
{
get;
set;
}
[Category("Environment Information")]
[EditorAttribute(typeof(UIRoomEditor), typeof(UITypeEditor))]
[Description("Collection of Rooms that have been created. Editing the Rooms Collection lets you manage the Zones rooms.")]
public List<Room> Rooms { get; set; }
[Category("Environment Information")]
public string EntranceRoom { get; set; }
public Zone()
{
Rooms = new List<Room>();
IsSafe = false;
Realm = "No Realm Associated.";
}
/// <summary>
///
/// </summary>
/// <param name="RoomName"></param>
/// <returns></returns>
public Room GetRoomByName(string name)
{
var filterQuery =
from room in Rooms
where room.Name == name
select room;
foreach (var room in filterQuery)
return room;
return null;
}
/// <summary>
///
/// </summary>
/// <param name="RoomName"></param>
/// <returns></returns>
public Room GetRoomByFilename(string filename)
{
var filterQuery =
from room in Rooms
where room.Filename == filename
select room;
foreach (var room in filterQuery)
return room;
return null;
}
/// <summary>
/// Clears out the Zones room collection and re-builds it.
/// This is a time consuming process if there are a large amount of
/// of rooms, use sparingly.
/// </summary>
public void RebuildRoomCollection()
{
Rooms = new List<Room>();
//Create our collection of Rooms.
string realmPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), this.Realm);
string zonePath = Path.Combine(realmPath, this.Name);
//incase the zone hasn't been saved yet.
if (!Directory.Exists(zonePath))
return;
//Zone exists, so it's already been saved.
string[] rooms = Directory.GetFiles(zonePath, "*.room");
//Clear the existing collection of Rooms
this.Rooms.Clear();
//Build a new one based off of the files
foreach (string file in rooms)
{
Room r = new Room();
r = (Room)r.Load(Path.GetFileNameWithoutExtension(file));
//r = (Room)FileManager.Load(file, r);
this.Rooms.Add(r);
}
//Save the re-built Room collection
this.Save(Path.Combine(zonePath, this.Filename));
}
}
}