- FileManager.GetData() method now checks to ensure that the supplied filename exists prior to attempting to reading data. - Adjusted Game.AutoSaveInterval to 60 minutes instead of 1 minute. - Placed all of the File reading code within Game.Load() into a Try/Catch to prevent exceptions if there was an error restoring the game from saved state. - GameWorld.Load() now places saved Realms that were created at runtime into the Games Realm Collection. This allows for hard-coded and dynamically created Realms to co-exist. - BaseObject.Filename now appends a file extension to the filename if a filename is set but the user forgets to add the file extension. This affects all classes inheriting from BaseObject - BaseCharacter updated to invoke commands by instancing a copy of the command and executing it, instead of injecting commands from the player. - Added EditRealm command. Allows for editing existing Realms properties. Currently has editing of Simple Descriptions, Detailed Descriptions, name and filename fully implemented. Example: EditRealm MyRealmName MudGame: - Removed Cali.Create() call. The MudGame no longer creates a hard-coded world. I want to get away from hard-coded environments all together. They should be built dynamically by admins.
230 lines
7.4 KiB
C#
230 lines
7.4 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;
|
|
using System.Reflection;
|
|
|
|
//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
|
|
{
|
|
return _Filename;
|
|
}
|
|
set
|
|
{
|
|
if (this.GetType().Name.StartsWith("Base"))
|
|
{
|
|
if (value.EndsWith("." + this.GetType().Name.Substring("Base".Length)))
|
|
{
|
|
_Filename = value;
|
|
}
|
|
else
|
|
_Filename = value + "." + this.GetType().Name.Substring("Base".Length);
|
|
}
|
|
else
|
|
{
|
|
if (value.EndsWith("." + this.GetType().Name))
|
|
{
|
|
_Filename = value;
|
|
}
|
|
else
|
|
_Filename =value + "." + this.GetType().Name;
|
|
}
|
|
}
|
|
}
|
|
String _Filename;
|
|
|
|
[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 Boolean 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 Start()
|
|
{
|
|
}
|
|
|
|
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);
|
|
|
|
String filename = Path.Combine(path, Filename);
|
|
|
|
if (File.Exists(filename))
|
|
File.Delete(filename);
|
|
|
|
FileManager.WriteLine(filename, this.Name, "Name");
|
|
FileManager.WriteLine(filename, this.Description, "Description");
|
|
FileManager.WriteLine(filename, this.Feel, "Feel");
|
|
FileManager.WriteLine(filename, this.Listen, "Listen");
|
|
FileManager.WriteLine(filename, this.Smell, "Smell");
|
|
|
|
foreach (String line in DetailedDescription)
|
|
FileManager.WriteLine(filename, line, "DetailedDescription");
|
|
}
|
|
|
|
public virtual void Load(String filename)
|
|
{
|
|
if (String.IsNullOrEmpty(filename))
|
|
return;
|
|
|
|
if (!File.Exists(filename))
|
|
{
|
|
Log.Write("Error: Attempted to load file " + filename);
|
|
return;
|
|
}
|
|
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");
|
|
|
|
List<String> data = FileManager.GetCollectionData(filename, "DetailedDescription");
|
|
|
|
foreach (String line in data)
|
|
DetailedDescription.Add(line);
|
|
|
|
//Set the Filename property based off the physical filename, as setting this.Name sets a default filename
|
|
//which might not match that of the actual physical filename on the harddrive.
|
|
this.Filename = Path.GetFileName(filename);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|