MudEngine:
- Fixed command engine stalling when waiting for one users command to finish before starting another users command. - Commands are loaded into static List collections, but the Execute command itself is now no longer static. - Player.CommandSystem property added so each player has their own commandengine to process their input.
This commit is contained in:
parent
b3a672503f
commit
7c6ca6a2b9
5 changed files with 49 additions and 36 deletions
|
@ -53,9 +53,6 @@ namespace MudEngine.Commands
|
||||||
}
|
}
|
||||||
|
|
||||||
player.Send("Welcome " + player.Name + "!");
|
player.Send("Welcome " + player.Name + "!");
|
||||||
|
|
||||||
//string playerName = player.Receive();
|
|
||||||
//TODO: Read user input...
|
|
||||||
return new CommandResults();
|
return new CommandResults();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace MudEngine.Commands
|
||||||
//Move the player into their new room
|
//Move the player into their new room
|
||||||
player.Move(door.TravelDirection);
|
player.Move(door.TravelDirection);
|
||||||
|
|
||||||
CommandResults cmd = CommandEngine.ExecuteCommand("Look", player);
|
CommandResults cmd = player.CommandSystem.ExecuteCommand("Look", player);
|
||||||
string lookValue = "";
|
string lookValue = "";
|
||||||
|
|
||||||
if (cmd.Result.Length != 0)
|
if (cmd.Result.Length != 0)
|
||||||
|
|
|
@ -14,19 +14,28 @@ using MudEngine.GameManagement;
|
||||||
|
|
||||||
namespace MudEngine.GameManagement
|
namespace MudEngine.GameManagement
|
||||||
{
|
{
|
||||||
public static class CommandEngine
|
public class CommandEngine
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets a Dictionary list of available commands to use.
|
/// Gets or Sets a Dictionary list of available commands to use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static internal Dictionary<string, IGameCommand> Commands { get { return _Commands; } set { _Commands = value; } }
|
public static Dictionary<string, IGameCommand> CommandCollection { get; set; }
|
||||||
static Dictionary<string, IGameCommand> _Commands = new Dictionary<string, IGameCommand>();
|
|
||||||
|
internal Dictionary<string, IGameCommand> _Commands { get; set; }
|
||||||
|
|
||||||
|
public CommandEngine()
|
||||||
|
{
|
||||||
|
if ((CommandCollection == null) || (CommandCollection.Count == 0))
|
||||||
|
CommandEngine.LoadBaseCommands();
|
||||||
|
|
||||||
|
_Commands = CommandCollection;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<string> GetCommands()
|
public static List<string> GetCommands()
|
||||||
{
|
{
|
||||||
List<string> temp = new List<string>();
|
List<string> temp = new List<string>();
|
||||||
|
|
||||||
foreach (string name in Commands.Keys)
|
foreach (string name in CommandEngine.CommandCollection.Keys)
|
||||||
{
|
{
|
||||||
temp.Add(name);
|
temp.Add(name);
|
||||||
}
|
}
|
||||||
|
@ -34,9 +43,22 @@ namespace MudEngine.GameManagement
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool GetCommand(string Name)
|
public static string GetCommand(object Parameter)
|
||||||
{
|
{
|
||||||
if (Commands.ContainsKey(Name.ToLower()))
|
List<object> objectList = (List<object>)Parameter;
|
||||||
|
|
||||||
|
foreach (object obj in objectList)
|
||||||
|
{
|
||||||
|
if (obj is string)
|
||||||
|
return (string)obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsValidCommand(string Name)
|
||||||
|
{
|
||||||
|
if (CommandEngine.CommandCollection.ContainsKey(Name.ToLower()))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
@ -47,17 +69,18 @@ namespace MudEngine.GameManagement
|
||||||
/// <param name="Name"></param>
|
/// <param name="Name"></param>
|
||||||
/// <param name="Parameter"></param>
|
/// <param name="Parameter"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static CommandResults ExecuteCommand(string command, BaseCharacter player)
|
public CommandResults ExecuteCommand(string command, BaseCharacter player)
|
||||||
{
|
{
|
||||||
string commandKey = command.Insert(0, "Command");
|
string commandKey = command.Insert(0, "Command");
|
||||||
if (Game.IsDebug)
|
if (Game.IsDebug)
|
||||||
Log.Write("Executing command: " + command);
|
Log.Write("Executing command: " + command);
|
||||||
|
|
||||||
foreach (string key in Commands.Keys)
|
foreach (string key in player.CommandSystem._Commands.Keys)
|
||||||
{
|
{
|
||||||
if (commandKey.ToLower().Contains(key.ToLower()))
|
if (commandKey.ToLower().Contains(key.ToLower()))
|
||||||
{
|
{
|
||||||
return Commands[key.ToLower()].Execute(command, player);
|
return player.CommandSystem._Commands[key.ToLower()].Execute(command, player);
|
||||||
|
//return player.Commands.ExecuteCommand[key.ToLower()]Execute(command, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +89,7 @@ namespace MudEngine.GameManagement
|
||||||
|
|
||||||
public static void LoadBaseCommands()
|
public static void LoadBaseCommands()
|
||||||
{
|
{
|
||||||
LoadCommandLibrary(Assembly.GetExecutingAssembly());
|
LoadCommandLibrary(Assembly.GetExecutingAssembly(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -109,7 +132,7 @@ namespace MudEngine.GameManagement
|
||||||
Log.Write("Loading commands within " + Path.GetFileName(commandLibrary.Location));
|
Log.Write("Loading commands within " + Path.GetFileName(commandLibrary.Location));
|
||||||
|
|
||||||
if (purgeOldCommands)
|
if (purgeOldCommands)
|
||||||
ClearCommands();
|
CommandEngine.ClearCommands();
|
||||||
|
|
||||||
foreach (Type t in commandLibrary.GetTypes())
|
foreach (Type t in commandLibrary.GetTypes())
|
||||||
{
|
{
|
||||||
|
@ -126,17 +149,17 @@ namespace MudEngine.GameManagement
|
||||||
command.Name = command.Name.ToLower();
|
command.Name = command.Name.ToLower();
|
||||||
|
|
||||||
//Add the command to the commands list if it does not already exist
|
//Add the command to the commands list if it does not already exist
|
||||||
if (Commands.ContainsKey(command.Name))
|
if (CommandEngine.CommandCollection.ContainsKey(command.Name))
|
||||||
{
|
{
|
||||||
//Command exists, check if the command is set to override existing commands or not
|
//Command exists, check if the command is set to override existing commands or not
|
||||||
if (command.Override)
|
if (command.Override)
|
||||||
{
|
{
|
||||||
Commands[command.Name] = command;
|
CommandEngine.CommandCollection[command.Name] = command;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Command does not exist, add it to the commands list
|
//Command does not exist, add it to the commands list
|
||||||
else
|
else
|
||||||
Commands.Add(command.Name, command);
|
CommandEngine.CommandCollection.Add(command.Name, command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,20 +167,7 @@ namespace MudEngine.GameManagement
|
||||||
|
|
||||||
public static void ClearCommands()
|
public static void ClearCommands()
|
||||||
{
|
{
|
||||||
_Commands = new Dictionary<string, IGameCommand>();
|
CommandEngine.CommandCollection = new Dictionary<string, IGameCommand>();
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,12 +45,18 @@ namespace MudEngine.GameObjects.Characters
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Bag Inventory { get; private set; }
|
public Bag Inventory { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a working copy of the CommandEngine used by the player.
|
||||||
|
/// </summary>
|
||||||
|
public CommandEngine CommandSystem { get; internal set; }
|
||||||
|
|
||||||
public BaseCharacter(Game game) : base(game)
|
public BaseCharacter(Game game) : base(game)
|
||||||
{
|
{
|
||||||
ActiveGame = game;
|
ActiveGame = game;
|
||||||
IsActive = false;
|
IsActive = false;
|
||||||
CurrentRoom = game.InitialRealm.InitialZone.InitialRoom;
|
CurrentRoom = game.InitialRealm.InitialZone.InitialRoom;
|
||||||
Inventory = new Bag(game);
|
Inventory = new Bag(game);
|
||||||
|
CommandSystem = new CommandEngine();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +129,7 @@ namespace MudEngine.GameObjects.Characters
|
||||||
{
|
{
|
||||||
//TODO: Character class can handle a lot of the command management here, checking various things prior to sending
|
//TODO: Character class can handle a lot of the command management here, checking various things prior to sending
|
||||||
//the command off to the command engine for execution.
|
//the command off to the command engine for execution.
|
||||||
CommandResults result = CommandEngine.ExecuteCommand(command, this);
|
CommandResults result = CommandSystem.ExecuteCommand(command, this);
|
||||||
|
|
||||||
if (result.Result != null)
|
if (result.Result != null)
|
||||||
{
|
{
|
||||||
|
@ -191,7 +197,7 @@ namespace MudEngine.GameObjects.Characters
|
||||||
{
|
{
|
||||||
if (IsActive)
|
if (IsActive)
|
||||||
{
|
{
|
||||||
string filePath = Path.Combine(ActiveGame.DataPaths.Players, Filename);
|
string filePath ="" /*= Path.Combine(ActiveGame.DataPaths.Players, Filename)*/;
|
||||||
this.Save(filePath);
|
this.Save(filePath);
|
||||||
|
|
||||||
IsActive = false;
|
IsActive = false;
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace MudEngine.Networking
|
||||||
}
|
}
|
||||||
} while (sub < 0);
|
} while (sub < 0);
|
||||||
players[sub].client = server.Accept();
|
players[sub].client = server.Accept();
|
||||||
players[sub].Initialize();
|
//players[sub].Initialize();
|
||||||
clientThreads[sub] = new Thread(ReceiveThread);
|
clientThreads[sub] = new Thread(ReceiveThread);
|
||||||
clientThreads[sub].Start((object)sub);
|
clientThreads[sub].Start((object)sub);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ namespace MudEngine.Networking
|
||||||
private void ReceiveThread(object obj)
|
private void ReceiveThread(object obj)
|
||||||
{
|
{
|
||||||
int sub = (int)obj;
|
int sub = (int)obj;
|
||||||
//players[sub].Initialize();
|
players[sub].Initialize();
|
||||||
while (stage == 2 && players[sub].IsActive)
|
while (stage == 2 && players[sub].IsActive)
|
||||||
{
|
{
|
||||||
players[sub].Receive(players[sub].ReadInput());
|
players[sub].Receive(players[sub].ReadInput());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue