Engine:
- Changed the IGameCommand Interface constructor for the Execute method. - Updated all of the game commands to make use of the new Execute Method Constructor requirements set by the updated interface. - Look command now returns a description of the players current Room. - Walk command now supports moving players from one Room to another. Use 'Walk Direction' where Direction equals the direction you want to travel (Example: 'Walk North") - TravelDirections.GetTravelDirectionValue now checks the supplied direction value in a case-insensitive manor. - Add a new CommandEngine that handles the commands inputed from the user. - Modified CommandResult to return an array of objects rather than a single object. Runtime: - Now scans the supplied collection of objects returned to the runtime after executing a game command, and adjusts the runtime components as needed, including printing information to the console. - Now displays various warnings during startup to let the user know if certain content hasn't been set within the ProjectInformation yet. - Now executes the 'Look' command on startup to display the users current location. - Fully supports the 'Look' and 'Walk' commands.
This commit is contained in:
parent
efc49e35ce
commit
79f6d36083
10 changed files with 334 additions and 24 deletions
122
Mud Designer/MudEngine/GameCommands/CommandEngine.cs
Normal file
122
Mud Designer/MudEngine/GameCommands/CommandEngine.cs
Normal file
|
@ -0,0 +1,122 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using MudDesigner.MudEngine.Interfaces;
|
||||
using MudDesigner.MudEngine.Characters;
|
||||
using MudDesigner.MudEngine.GameManagement;
|
||||
using MudDesigner.MudEngine.GameObjects.Environment;
|
||||
|
||||
namespace MudDesigner.MudEngine.GameCommands
|
||||
{
|
||||
public class CommandEngine
|
||||
{
|
||||
#region ====== Public Enumerators, Structures & Properties ======
|
||||
/// <summary>
|
||||
/// Gets or Sets a Dictionary list of available commands to use.
|
||||
/// </summary>
|
||||
static internal Dictionary<string, IGameCommand> Commands { get; set; }
|
||||
|
||||
public List<string> GetCommands
|
||||
{
|
||||
get
|
||||
{
|
||||
List<string> temp = new List<string>();
|
||||
foreach (string name in Commands.Keys)
|
||||
{
|
||||
temp.Add(name);
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ====== Public Methods ======
|
||||
public bool GetCommand(string Name)
|
||||
{
|
||||
if (Commands.ContainsKey(Name.ToLower()))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Executes the specified command name if it exists in the Commands Dictionary.
|
||||
/// </summary>
|
||||
/// <param name="Name"></param>
|
||||
/// <param name="Parameter"></param>
|
||||
/// <returns></returns>
|
||||
public static CommandResults ExecuteCommand(string Name, BaseCharacter player, ProjectInformation project, Room room, string command)
|
||||
{
|
||||
Name = Name.Insert(0, "Command");
|
||||
foreach (string key in Commands.Keys)
|
||||
{
|
||||
if (Name.ToLower().Contains(key.ToLower()))
|
||||
{
|
||||
return Commands[key.ToLower()].Execute(player, project, room, command);
|
||||
}
|
||||
}
|
||||
|
||||
return new CommandResults();
|
||||
}
|
||||
/// <summary>
|
||||
/// Dynamically loads the specified library into memory and stores all of the
|
||||
/// classess inheriting from MudCreator.InputCommands.ICommand into the CommandEngines
|
||||
/// commands dictionary for use with the project
|
||||
/// </summary>
|
||||
/// <param name="CommandLibrary"></param>
|
||||
public static void LoadAllCommands()
|
||||
{
|
||||
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
|
||||
Commands = new Dictionary<string, IGameCommand>();
|
||||
foreach (Type t in assembly.GetTypes())
|
||||
{
|
||||
if (t.GetInterface(typeof(IGameCommand).FullName) != null)
|
||||
{
|
||||
//Use activator to create an instance
|
||||
IGameCommand command = (IGameCommand)Activator.CreateInstance(t);
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
if (command.Name == null)
|
||||
command.Name = t.Name.ToLower();
|
||||
else //Make sure the command is always in lower case.
|
||||
command.Name = command.Name.ToLower();
|
||||
|
||||
//Add the command to the commands list if it does not already exist
|
||||
if (Commands.ContainsKey(command.Name))
|
||||
{
|
||||
//Command exists, check if the command is set to override existing commands or not
|
||||
if (command.Override)
|
||||
{
|
||||
Commands[command.Name] = command;
|
||||
}
|
||||
}
|
||||
//Command does not exist, add it to the commands list
|
||||
else
|
||||
Commands.Add(command.Name, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetCommand(object Parameter)
|
||||
{
|
||||
List<object> objectList = (List<object>)Parameter;
|
||||
|
||||
foreach (object obj in objectList)
|
||||
{
|
||||
if (obj is string)
|
||||
return (string)obj;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue