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.
This commit is contained in:
Scionwest_cp 2010-08-15 14:11:21 -07:00
parent bbd411fdd1
commit 93a27ca75f
10 changed files with 72 additions and 19 deletions

View file

@ -83,6 +83,8 @@ namespace MudEngine.GameManagement
return; return;
} }
} }
player.Send("Invalid Command.");
} }
public static void LoadBaseCommands() public static void LoadBaseCommands()

View file

@ -228,7 +228,7 @@
Send("Command: ", false); Send("Command: ", false);
} }
public void Create(string playerName, string password) public virtual void Create(string playerName, string password)
{ {
Name = playerName; Name = playerName;
Password = password; Password = password;
@ -244,7 +244,7 @@
return false; return false;
} }
internal void Initialize() public virtual void Initialize()
{ {
if (ActiveGame.IsMultiplayer) if (ActiveGame.IsMultiplayer)
client.Receive(new byte[255]); client.Receive(new byte[255]);
@ -286,7 +286,7 @@
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
/// <param name="newLine"></param> /// <param name="newLine"></param>
internal void Send(String data, Boolean newLine) public void Send(String data, Boolean newLine)
{ {
try try
{ {
@ -309,12 +309,12 @@
/// Sends data to the player. /// Sends data to the player.
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
internal void Send(String data) public void Send(String data)
{ {
Send(data, true); Send(data, true);
} }
internal void FlushConsole() public void FlushConsole()
{ {
try try
{ {
@ -337,7 +337,7 @@
} }
} }
internal void Disconnect() public void Disconnect()
{ {
if (IsActive) if (IsActive)
{ {
@ -350,7 +350,8 @@
Log.Write(Name + " disconnected."); Log.Write(Name + " disconnected.");
} }
} }
internal String ReadInput()
public String ReadInput()
{ {
if (ActiveGame.IsMultiplayer) if (ActiveGame.IsMultiplayer)
{ {

View file

@ -259,6 +259,9 @@ namespace MudEngine.Scripting
GameObjects.Add(obj); 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(); _AssemblyCollection.Clear();
} }

View file

@ -45,6 +45,18 @@
<ItemGroup> <ItemGroup>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<None Include="Scripts\CommandSay.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Scripts\WorldCalifornia.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Scripts\CommandClear.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Scripts\EarthGame.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\MudEngine\MudEngine.csproj"> <ProjectReference Include="..\MudEngine\MudEngine.csproj">

View file

@ -19,14 +19,16 @@ namespace MudGame
static void Main(String[] args) 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)) if (!File.Exists(SettingsFile))
{ {
Log.Write("Settings.ini missing!"); Log.Write("Settings.ini missing!", false);
FileManager.WriteLine(SettingsFile, "Scripts", "ScriptPath"); FileManager.WriteLine(SettingsFile, "Scripts", "ScriptPath");
FileManager.WriteLine(SettingsFile, ".cs", "ScriptExtension"); FileManager.WriteLine(SettingsFile, ".cs", "ScriptExtension");
FileManager.WriteLine(SettingsFile, "True", "ServerEnabled"); 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") if (FileManager.GetData(SettingsFile, "ServerEnabled").ToLower() == "false")
@ -36,11 +38,12 @@ namespace MudGame
else else
Log.IsVerbose = false; Log.IsVerbose = false;
//Get are cached log messages and go forward from here.
Console.Write(Log.GetMessages());
Log.FlushMessages();
Log.Write("Launching...", true); Log.Write("Launching...", true);
ScriptEngine scriptEngine; ScriptEngine scriptEngine;
Log.Write("Loading settings...", true);
scriptEngine = new ScriptEngine(new Game(), ScriptEngine.ScriptTypes.Both); scriptEngine = new ScriptEngine(new Game(), ScriptEngine.ScriptTypes.Both);
//scriptEngine.CompileScripts(); //scriptEngine.CompileScripts();

View file

@ -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);
}
}

View file

@ -1,11 +1,12 @@
public class MyGame : Game public class EarthGame : Game
{ {
public California Cali; public WorldCalifornia Cali;
public MyGame() public EarthGame()
: base() : base()
{ {
GameTitle = "Mud Designer Example Game"; GameTitle = "Planet Earth MUD";
Story = "The planet Earth reproduced in a MUD for your playing enjoyment!";
IsMultiplayer = true; IsMultiplayer = true;
CompanyName = "Mud Designer Team"; CompanyName = "Mud Designer Team";
@ -13,7 +14,7 @@ public class MyGame : Game
Version = "Example Game Version 1.0"; Version = "Example Game Version 1.0";
MaximumPlayers = 5000; MaximumPlayers = 5000;
Cali = new California(this); Cali = new WorldCalifornia(this);
Cali.Create(); Cali.Create();
} }
} }

View file

@ -1,8 +1,8 @@
public class California public class WorldCalifornia
{ {
private Game _Game; private Game _Game;
public California(Game game) public WorldCalifornia(Game game)
{ {
_Game = game; _Game = game;
} }

View file

@ -2,4 +2,9 @@
MudEngine.pdb MudEngine.pdb
MudGame.exe MudGame.exe
MudGame.pdb MudGame.pdb
</Value></Property><Property><Name>svn:ignore</Name><Value>MudEngine.dll
MudEngine.pdb
MudGame.exe
MudGame.pdb
Scripts
</Value></Property></Properties></ItemProperties> </Value></Property></Properties></ItemProperties>