From 93a27ca75f9afdf04e82c85e957b806cdc9cb6c0 Mon Sep 17 00:00:00 2001 From: Scionwest_cp Date: Sun, 15 Aug 2010 14:11:21 -0700 Subject: [PATCH] MudEngine: - Fixed the ScriptEngine and CommandEngine not loading Custom game commands from scripts. - BaseCharacter's Create, Initialize, Send and FlushConsole are now overridable via scripts. - Invalid commands are now printed to the player "Invalid Command." MudGame: - Added CommandSay script that adds primitive chatting support. Only players within the same Room can see the messages. - Renamed California script to WorldCalifornia - Renamed MyGame script to EarthGame. - Added Clear command script for and Say command script for showing how to build custom commands for use with the game. The commands can only be added server-side, but used client-side. --- MudEngine/GameManagement/CommandEngine.cs | 2 ++ .../GameObjects/Characters/BaseCharacter.cs | 15 ++++++----- MudEngine/Scripting/ScriptEngine.cs | 3 +++ MudGame/MudGame.csproj | 12 +++++++++ MudGame/Program.cs | 13 ++++++---- .../{bin/Debug => }/Scripts/CommandClear.cs | 0 MudGame/Scripts/CommandSay.cs | 26 +++++++++++++++++++ .../MyGame.cs => Scripts/EarthGame.cs} | 11 ++++---- .../WorldCalifornia.cs} | 4 +-- MudGame/bin/Release/..svnbridge/.svnbridge | 5 ++++ 10 files changed, 72 insertions(+), 19 deletions(-) rename MudGame/{bin/Debug => }/Scripts/CommandClear.cs (100%) create mode 100644 MudGame/Scripts/CommandSay.cs rename MudGame/{bin/Debug/Scripts/MyGame.cs => Scripts/EarthGame.cs} (52%) rename MudGame/{bin/Debug/Scripts/California.cs => Scripts/WorldCalifornia.cs} (94%) diff --git a/MudEngine/GameManagement/CommandEngine.cs b/MudEngine/GameManagement/CommandEngine.cs index 5f92722..fff738a 100644 --- a/MudEngine/GameManagement/CommandEngine.cs +++ b/MudEngine/GameManagement/CommandEngine.cs @@ -83,6 +83,8 @@ namespace MudEngine.GameManagement return; } } + + player.Send("Invalid Command."); } public static void LoadBaseCommands() diff --git a/MudEngine/GameObjects/Characters/BaseCharacter.cs b/MudEngine/GameObjects/Characters/BaseCharacter.cs index 26f211c..c0c6ac5 100644 --- a/MudEngine/GameObjects/Characters/BaseCharacter.cs +++ b/MudEngine/GameObjects/Characters/BaseCharacter.cs @@ -228,7 +228,7 @@ Send("Command: ", false); } - public void Create(string playerName, string password) + public virtual void Create(string playerName, string password) { Name = playerName; Password = password; @@ -244,7 +244,7 @@ return false; } - internal void Initialize() + public virtual void Initialize() { if (ActiveGame.IsMultiplayer) client.Receive(new byte[255]); @@ -286,7 +286,7 @@ /// /// /// - internal void Send(String data, Boolean newLine) + public void Send(String data, Boolean newLine) { try { @@ -309,12 +309,12 @@ /// Sends data to the player. /// /// - internal void Send(String data) + public void Send(String data) { Send(data, true); } - internal void FlushConsole() + public void FlushConsole() { try { @@ -337,7 +337,7 @@ } } - internal void Disconnect() + public void Disconnect() { if (IsActive) { @@ -350,7 +350,8 @@ Log.Write(Name + " disconnected."); } } - internal String ReadInput() + + public String ReadInput() { if (ActiveGame.IsMultiplayer) { diff --git a/MudEngine/Scripting/ScriptEngine.cs b/MudEngine/Scripting/ScriptEngine.cs index 61985d9..35f8ca2 100644 --- a/MudEngine/Scripting/ScriptEngine.cs +++ b/MudEngine/Scripting/ScriptEngine.cs @@ -259,6 +259,9 @@ namespace MudEngine.Scripting GameObjects.Add(obj); } } + + //Lastly, send this assembly off to the CommandEngine so we can load commands from it for use as well. + CommandEngine.LoadCommandLibrary(assembly); } _AssemblyCollection.Clear(); } diff --git a/MudGame/MudGame.csproj b/MudGame/MudGame.csproj index 0fc70d9..50a581a 100644 --- a/MudGame/MudGame.csproj +++ b/MudGame/MudGame.csproj @@ -45,6 +45,18 @@ + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + diff --git a/MudGame/Program.cs b/MudGame/Program.cs index 0b1a731..76f0c2d 100644 --- a/MudGame/Program.cs +++ b/MudGame/Program.cs @@ -19,14 +19,16 @@ namespace MudGame static void Main(String[] args) { - //Re-create the settings file if it is missing + //Re-create the settings file if it is missing. Don't push any log messages until we know that this is + //verbose or not + Log.Write("Loading Settings...", false); if (!File.Exists(SettingsFile)) { - Log.Write("Settings.ini missing!"); + Log.Write("Settings.ini missing!", false); FileManager.WriteLine(SettingsFile, "Scripts", "ScriptPath"); FileManager.WriteLine(SettingsFile, ".cs", "ScriptExtension"); FileManager.WriteLine(SettingsFile, "True", "ServerEnabled"); - Log.Write("Settings.ini re-created with default values"); + Log.Write("Settings.ini re-created with default values", false); } if (FileManager.GetData(SettingsFile, "ServerEnabled").ToLower() == "false") @@ -36,11 +38,12 @@ namespace MudGame else Log.IsVerbose = false; + //Get are cached log messages and go forward from here. + Console.Write(Log.GetMessages()); + Log.FlushMessages(); Log.Write("Launching...", true); ScriptEngine scriptEngine; - - Log.Write("Loading settings...", true); scriptEngine = new ScriptEngine(new Game(), ScriptEngine.ScriptTypes.Both); //scriptEngine.CompileScripts(); diff --git a/MudGame/bin/Debug/Scripts/CommandClear.cs b/MudGame/Scripts/CommandClear.cs similarity index 100% rename from MudGame/bin/Debug/Scripts/CommandClear.cs rename to MudGame/Scripts/CommandClear.cs diff --git a/MudGame/Scripts/CommandSay.cs b/MudGame/Scripts/CommandSay.cs new file mode 100644 index 0000000..904380f --- /dev/null +++ b/MudGame/Scripts/CommandSay.cs @@ -0,0 +1,26 @@ +public class CommandSay : IGameCommand +{ + public Boolean Override { get; set; } + public String Name { get; set; } + + public void Execute(String command, BaseCharacter player) + { + if (command.Length <= 4) //user only sent 'Say' or 'Say ' + { + return; //nothing to say, don't say anything at all. + } + + String message = command.Substring("Say ".Length); + + foreach (BaseCharacter p in player.ActiveGame.PlayerCollection) + { + if ((p.CurrentRoom.Realm == player.CurrentRoom.Realm) && (p.CurrentRoom.Zone == player.CurrentRoom.Zone) && (p.CurrentRoom.Filename == player.CurrentRoom.Filename)) + { + p.Send(player.Name + " says: " + message); + } + } + + player.Send("You say: " + message); + + } +} \ No newline at end of file diff --git a/MudGame/bin/Debug/Scripts/MyGame.cs b/MudGame/Scripts/EarthGame.cs similarity index 52% rename from MudGame/bin/Debug/Scripts/MyGame.cs rename to MudGame/Scripts/EarthGame.cs index a53b232..b0d3387 100644 --- a/MudGame/bin/Debug/Scripts/MyGame.cs +++ b/MudGame/Scripts/EarthGame.cs @@ -1,11 +1,12 @@ -public class MyGame : Game +public class EarthGame : Game { - public California Cali; + public WorldCalifornia Cali; - public MyGame() + public EarthGame() : base() { - GameTitle = "Mud Designer Example Game"; + GameTitle = "Planet Earth MUD"; + Story = "The planet Earth reproduced in a MUD for your playing enjoyment!"; IsMultiplayer = true; CompanyName = "Mud Designer Team"; @@ -13,7 +14,7 @@ public class MyGame : Game Version = "Example Game Version 1.0"; MaximumPlayers = 5000; - Cali = new California(this); + Cali = new WorldCalifornia(this); Cali.Create(); } } \ No newline at end of file diff --git a/MudGame/bin/Debug/Scripts/California.cs b/MudGame/Scripts/WorldCalifornia.cs similarity index 94% rename from MudGame/bin/Debug/Scripts/California.cs rename to MudGame/Scripts/WorldCalifornia.cs index c3f6319..0e47cc6 100644 --- a/MudGame/bin/Debug/Scripts/California.cs +++ b/MudGame/Scripts/WorldCalifornia.cs @@ -1,8 +1,8 @@ -public class California +public class WorldCalifornia { private Game _Game; - public California(Game game) + public WorldCalifornia(Game game) { _Game = game; } diff --git a/MudGame/bin/Release/..svnbridge/.svnbridge b/MudGame/bin/Release/..svnbridge/.svnbridge index 205dcd3..25d09e9 100644 --- a/MudGame/bin/Release/..svnbridge/.svnbridge +++ b/MudGame/bin/Release/..svnbridge/.svnbridge @@ -2,4 +2,9 @@ MudEngine.pdb MudGame.exe MudGame.pdb +svn:ignoreMudEngine.dll +MudEngine.pdb +MudGame.exe +MudGame.pdb +Scripts \ No newline at end of file