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:
parent
bbd411fdd1
commit
93a27ca75f
10 changed files with 72 additions and 19 deletions
|
@ -83,6 +83,8 @@ namespace MudEngine.GameManagement
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
player.Send("Invalid Command.");
|
||||
}
|
||||
|
||||
public static void LoadBaseCommands()
|
||||
|
|
|
@ -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 @@
|
|||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="newLine"></param>
|
||||
internal void Send(String data, Boolean newLine)
|
||||
public void Send(String data, Boolean newLine)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -309,12 +309,12 @@
|
|||
/// Sends data to the player.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -45,6 +45,18 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Program.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>
|
||||
<ProjectReference Include="..\MudEngine\MudEngine.csproj">
|
||||
|
|
|
@ -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();
|
||||
|
|
26
MudGame/Scripts/CommandSay.cs
Normal file
26
MudGame/Scripts/CommandSay.cs
Normal 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);
|
||||
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
public class California
|
||||
public class WorldCalifornia
|
||||
{
|
||||
private Game _Game;
|
||||
|
||||
public California(Game game)
|
||||
public WorldCalifornia(Game game)
|
||||
{
|
||||
_Game = game;
|
||||
}
|
|
@ -2,4 +2,9 @@
|
|||
MudEngine.pdb
|
||||
MudGame.exe
|
||||
MudGame.pdb
|
||||
</Value></Property><Property><Name>svn:ignore</Name><Value>MudEngine.dll
|
||||
MudEngine.pdb
|
||||
MudGame.exe
|
||||
MudGame.pdb
|
||||
Scripts
|
||||
</Value></Property></Properties></ItemProperties>
|
Loading…
Add table
Add a link
Reference in a new issue