DataPath class is now completed and includes a new SetExtension() method for setting game object file extensions. Scripting support fully implemented. StandardGame now contains a Initialize() method for compiling scripts and searching for sub-classes of StandardGame Server app will now use a Scripted game class instead of the default StandardGame if one is present. StandardGame.Start() is now virtual so child classes can override it. Sample Game script created to show how to create a custom game script, including how to setup the game and create Rooms pragamatically. ScriptFactory has a new method for searching all scripts and scripts that inherit from a specified class. Renamed all of the Command scripts. They no longer start with 'Command'. Example: "CommandSay" has now become "Say". There is no need to preceed the command name with the word "Command" anymore.
189 lines
6.6 KiB
C#
189 lines
6.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Reflection;
|
|
using System.IO;
|
|
|
|
namespace MudEngine.DAL
|
|
{
|
|
public enum DataTypes
|
|
{
|
|
Root,
|
|
Players,
|
|
Environments,
|
|
Characters,
|
|
Equipment,
|
|
Scripts,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Contains the paths for the engines file storage.
|
|
/// </summary>
|
|
public class DataPaths
|
|
{
|
|
public DataPaths()
|
|
{
|
|
String path = Assembly.GetExecutingAssembly().Location;
|
|
String assemblyFile = Path.GetFileName(path);
|
|
this._InstallRoot = path.Substring(0, path.Length - assemblyFile.Length);
|
|
|
|
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Characters"), DataTypes.Characters);
|
|
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Environments"), DataTypes.Environments);
|
|
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Equipment"), DataTypes.Equipment);
|
|
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Players"), DataTypes.Players);
|
|
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "GameScripts"), DataTypes.Scripts);
|
|
|
|
this.SetExtension(DataTypes.Characters, ".character");
|
|
this.SetExtension(DataTypes.Environments, ".environment");
|
|
this.SetExtension(DataTypes.Equipment, ".equipment");
|
|
this.SetExtension(DataTypes.Players, ".player");
|
|
this.SetExtension(DataTypes.Scripts, ".cs");
|
|
}
|
|
|
|
public void SetAbsolutePath(String path, DataTypes objectType)
|
|
{
|
|
if (!path.EndsWith(@"\"))
|
|
path = path.Insert(path.Length, @"\");
|
|
|
|
switch (objectType)
|
|
{
|
|
case DataTypes.Characters:
|
|
this._Characters = path;
|
|
break;
|
|
case DataTypes.Environments:
|
|
this._Environments = path;
|
|
break;
|
|
case DataTypes.Equipment:
|
|
this._Equipment = path;
|
|
break;
|
|
case DataTypes.Players:
|
|
this._Players = path;
|
|
break;
|
|
case DataTypes.Scripts:
|
|
this._Scripts = path;
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void SetRelativePath(String path, DataTypes objectType)
|
|
{
|
|
}
|
|
|
|
public String GetPath(DataTypes objectType)
|
|
{
|
|
switch (objectType)
|
|
{
|
|
case DataTypes.Root:
|
|
return this._InstallRoot;
|
|
case DataTypes.Characters:
|
|
return this._Characters;
|
|
case DataTypes.Environments:
|
|
return this._Environments;
|
|
case DataTypes.Equipment:
|
|
return this._Equipment;
|
|
case DataTypes.Players:
|
|
return this._Players;
|
|
case DataTypes.Scripts:
|
|
return this._Scripts;
|
|
}
|
|
|
|
return String.Empty;
|
|
}
|
|
|
|
public String GetFilePath(DataTypes objectType, String filename)
|
|
{
|
|
String result = String.Empty;
|
|
|
|
switch (objectType)
|
|
{
|
|
case DataTypes.Root:
|
|
result = Path.Combine(this._InstallRoot, filename + this.GetExtension(DataTypes.Root));
|
|
break;
|
|
case DataTypes.Characters:
|
|
result = Path.Combine(this._Characters, filename + this.GetExtension(DataTypes.Characters));
|
|
break;
|
|
case DataTypes.Environments:
|
|
result = Path.Combine(this._Environments, filename + this.GetExtension(DataTypes.Environments));
|
|
break;
|
|
case DataTypes.Equipment:
|
|
result = Path.Combine(this._Equipment, filename + this.GetExtension(DataTypes.Equipment));
|
|
break;
|
|
case DataTypes.Players:
|
|
result = Path.Combine(this._Players, filename + this.GetExtension(DataTypes.Players));
|
|
break;
|
|
case DataTypes.Scripts:
|
|
result = Path.Combine(this._Scripts, filename + this.GetExtension(DataTypes.Scripts));
|
|
break;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public String GetExtension(DataTypes objectType)
|
|
{
|
|
String result = String.Empty;
|
|
|
|
switch (objectType)
|
|
{
|
|
case DataTypes.Root:
|
|
result = ".dat";
|
|
break;
|
|
case DataTypes.Characters:
|
|
result = this._CharacterExt;
|
|
break;
|
|
case DataTypes.Environments:
|
|
result = this._EnvironmentExt;
|
|
break;
|
|
case DataTypes.Equipment:
|
|
result = this._EquipmentExt;
|
|
break;
|
|
case DataTypes.Scripts:
|
|
result = this._ScriptExt;
|
|
break;
|
|
case DataTypes.Players:
|
|
result = this._PlayersExt;
|
|
break;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public void SetExtension(DataTypes objectType, String extension)
|
|
{
|
|
if (!extension.StartsWith("."))
|
|
extension = extension.Insert(0, ".");
|
|
|
|
switch (objectType)
|
|
{
|
|
case DataTypes.Characters:
|
|
this._CharacterExt = extension;
|
|
break;
|
|
case DataTypes.Environments:
|
|
this._EnvironmentExt = extension;
|
|
break;
|
|
case DataTypes.Equipment:
|
|
this._EquipmentExt = extension;
|
|
break;
|
|
case DataTypes.Players:
|
|
this._PlayersExt = extension;
|
|
break;
|
|
case DataTypes.Scripts:
|
|
this._ScriptExt = extension;
|
|
break;
|
|
}
|
|
}
|
|
|
|
private String _InstallRoot;
|
|
private String _Players;
|
|
private String _PlayersExt;
|
|
private String _Environments;
|
|
private String _EnvironmentExt;
|
|
private String _Characters;
|
|
private String _CharacterExt;
|
|
private String _Equipment;
|
|
private String _EquipmentExt;
|
|
private String _Scripts;
|
|
private String _ScriptExt;
|
|
}
|
|
}
|