muddesigner/MudEngine/GameObjects/BaseObject.cs
Scionwest_cp 9585cede63 MudEngine:
- Added BaseCharacter.FlushConsole() method. Sends a hex sequence to the clients telnet terminal that clears the screen. If IsMultiplayer=false then it just clears the C# Console.
 - Added a 'Clear' command for users to use. It invokes the new FlushConsole command.
 - Removed the need for a full file path and filename when calling an objects save method. Now it just needs the path.
 - Adjusted the Exit command, Login command and Save command to reflect the objects save parameter changes.
 - Removed the Unique ID from objects. 
 - All objects now reference each other via their filenames rather than their object names. Allows for 3 objects with the name Bedroom to exist, but with different filenames such as Bedroom1, Bedroom2 etc.
 - Zone now has a GetRoomByName method that replace the removed GetRoomByID method. Returns a List<> collection of Rooms found with a matching filename.
 - BaseCharacter updated to work with the new Zone.GetRoomByName method.
 - Realm.GetZoneByID renamed to GetZoneByName()
2010-08-13 21:35:46 -07:00

181 lines
5.6 KiB
C#

//Microsoft .NET Framework
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using System.IO;
//MUD Engine
using MudEngine.FileSystem;
using MudEngine.GameManagement;
namespace MudEngine.GameObjects
{
public class BaseObject
{
[Category("Object Setup")]
[Description("The Display Name assigned to this object.")]
//Required to refresh Filename property in the editors propertygrid
[RefreshProperties(RefreshProperties.All)]
public string Name
{
get
{
return _Name;
}
set
{
_Name = value;
if (this.GetType().Name.StartsWith("Base"))
Filename = value + "." + this.GetType().Name.Substring("Base".Length);
else
Filename = value + "." + this.GetType().Name;
}
}
private string _Name;
[Category("Object Setup")]
[Description("A brief description of this object. The description is displayed to users when they use a command for investigating an object")]
public string Description { get; set; }
/// <summary>
/// A detailed description that treats each entry as a seperete line when outputted to the player
/// </summary>
public List<string> DetailedDescription { get; set; }
[Category("Object Setup")]
[ReadOnly(true)]
[Description("The filename of the current object. This is assigned by the engine and not editable.")]
public string Filename
{
//Returns the name of the object + the objects Type as it's extension.
//Filenames are generated by the class itself, users can not assign it.
get;
set;
}
[Category("Environment Information")]
[Description("If a user asks to use his/her senses to investigate an area, this is one of the results that will be displayed. Senses can be used to assist blind characters.")]
[DefaultValue("You don't smell anything unsual.")]
public string Smell { get; set; }
[Category("Environment Information")]
[Description("If a user asks to use his/her senses to investigate an area, this is one of the results that will be displayed. Senses can be used to assist blind characters.")]
[DefaultValue("You hear nothing of interest.")]
public string Listen { get; set; }
[Category("Environment Information")]
[Description("If a user asks to use his/her senses to investigate an area, this is one of the results that will be displayed. Senses can be used to assist blind characters.")]
[DefaultValue("You feel nothing.")]
public string Feel { get; set; }
public Game ActiveGame { get; set; }
/// <summary>
/// Initializes the base object
/// </summary>
public BaseObject(Game game)
{
Name = "New " + this.GetType().Name;
ActiveGame = game;
DetailedDescription = new List<string>();
this.Feel = "You feel nothing.";
this.Listen = "You hear nothing of interest.";
this.Smell = "You don't smell anything unsual.";
this.Name = DefaultName();
this.Filename = DefaultName() + "." + this.GetType().Name;
}
~BaseObject()
{
}
private bool ShouldSerializeName()
{
return this.Name != DefaultName();
}
private void ResetName()
{
this.Name = DefaultName();
}
private string DefaultName()
{
return "New " + this.GetType().Name;
}
#region Public Methods
public override string ToString()
{
return this.Name;
}
public virtual void OnEnter()
{
}
public virtual void OnExit()
{
}
public virtual void OnCreate()
{
}
public virtual void OnDestroy()
{
}
public virtual void OnEquip()
{
}
public virtual void OnUnequip()
{
}
public virtual void OnMount()
{
}
public virtual void OnDismount()
{
}
public virtual void Save(string path)
{
if (String.IsNullOrEmpty(path))
return;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
path = Path.Combine(path, Filename);
if (File.Exists(path))
File.Delete(path);
FileManager.WriteLine(path, this.Name, "Name");
FileManager.WriteLine(path, this.Description, "Description");
FileManager.WriteLine(path, this.Feel, "Feel");
FileManager.WriteLine(path, this.Listen, "Listen");
FileManager.WriteLine(path, this.Smell, "Smell");
}
public virtual void Load(string filename)
{
this.Name = FileManager.GetData(filename, "Name");
this.Description = FileManager.GetData(filename, "Description");
this.Feel = FileManager.GetData(filename, "Feel");
this.Listen = FileManager.GetData(filename, "Listen");
this.Smell = FileManager.GetData(filename, "Smell");
}
#endregion
}
}