MudEngine:
BaseGame.IsRunning property added. MudGame: Removed all of the old scripts. They will be re-wrote. MudGame will become a template project. Including a template Game that inherits from BaseGame, along with template characters and items. MudGame.cs added. Initial Game class. It does not support environment loading at this time. Program.cs re-wrote to run the game in a while() loop checking MudGame.IsRunning propery and calling the MudGame.Update() method each iteration. Deleted the Settings.ini file. I want to use something different.
This commit is contained in:
parent
a365256d53
commit
68d49a4160
23 changed files with 131 additions and 1753 deletions
|
@ -24,16 +24,39 @@ namespace MudEngine.Core
|
|||
[Description("Enables or Disables the Auto Save feature.")]
|
||||
public bool EnableAutoSave { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets if the game is currently running or not.
|
||||
/// </summary>
|
||||
public bool IsRunning { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the auto-save interval for the game during runtime
|
||||
/// </summary>
|
||||
public int AutoSaveInterval { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the minimum size a users account password must be
|
||||
/// </summary>
|
||||
public int PasswordMinimumSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the maximum number of players allowed to connect to the server at once.
|
||||
/// </summary>
|
||||
public int MaximumPlayers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the collection of players currently connected to the server
|
||||
/// </summary>
|
||||
public Dictionary<TcpClient, ICharacter> ConnectedPlayers { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the current version of the game.
|
||||
/// </summary>
|
||||
public string Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the environment that will be used when a new user account is created.
|
||||
/// </summary>
|
||||
public IEnvironment InitialEnvironment { get; set; }
|
||||
|
||||
public BaseGame()
|
||||
|
|
100
MudGame/MudGame.cs
Normal file
100
MudGame/MudGame.cs
Normal file
|
@ -0,0 +1,100 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
using MudEngine.Core;
|
||||
using MudEngine.Runtime;
|
||||
using MudEngine.Communication;
|
||||
|
||||
namespace MudGame
|
||||
{
|
||||
public class MudGame : BaseGame
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a reference to the game scripting system
|
||||
/// </summary>
|
||||
protected ScriptSystem ScriptSystem { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the games command execution system
|
||||
/// </summary>
|
||||
protected CommandSystem CommandSystem { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the games networking server.
|
||||
/// </summary>
|
||||
public Server Server { get; private set; }
|
||||
|
||||
public MudGame()
|
||||
: base()
|
||||
{
|
||||
ScriptSystem = new ScriptSystem(".mud");
|
||||
CommandSystem = new CommandSystem();
|
||||
Server = new Server(this);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
//Setup the example game.
|
||||
this.Name = "Mud Example Game";
|
||||
this.Description = "An simple Mud Game class that manages the basics";
|
||||
this.AutoSaveInterval = 5;
|
||||
this.EnableAutoSave = true;
|
||||
this.PasswordMinimumSize = 8;
|
||||
this.Version = "Alpha 2.0";
|
||||
|
||||
//Add the engine.dll.
|
||||
this.ScriptSystem.AddAssemblyReference(Assembly.GetExecutingAssembly().GetName().Name + ".dll");
|
||||
|
||||
//If a scripts directory exists, compile them.
|
||||
if (Directory.Exists("Scripts"))
|
||||
{
|
||||
this.ScriptSystem.Compile("Scripts");
|
||||
if (this.ScriptSystem.HasErrors)
|
||||
//TODO: Output script system compile errors
|
||||
return; //temp. Shouldn't return.
|
||||
}
|
||||
|
||||
//Scripts are compiled, now load all of the commands, if any script commands exist.
|
||||
CommandSystem.LoadCommandLibrary(ScriptSystem.CompiledAssembly);
|
||||
|
||||
//TODO: Iitialize the game world.
|
||||
|
||||
//TODO: Load previously saved state.
|
||||
|
||||
//TODO: Enable server.
|
||||
this.EnableServer = true; //Starts the server.
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
if (this.EnableServer)
|
||||
this.EnableServer = false;
|
||||
|
||||
this.Save();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void OnConnect(System.Net.Sockets.TcpClient client)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void OnDisconnect(System.Net.Sockets.TcpClient client)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int GetAvailableID()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,65 +47,9 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MudGame.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<None Include="Scripts\PlayerCommands\CommandLogin.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\AdminCommands\CommandRestart.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\AdminCommands\CommandSaveWorld.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\AdminCommands\CommandTeleport.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\AdminCommands\CommandList.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\AdminCommands\CommandCreateRoom.cs">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\PlayerCommands\CommandExit.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\PlayerCommands\CommandGetTime.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\AdminCommands\CommandLinkRoom.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\PlayerCommands\CommandLook.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\PlayerCommands\CommandSave.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\PlayerCommands\CommandWalk.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\PlayerCommands\CommandHelp.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\AdminCommands\CommandCreate.cs">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\PlayerCommands\CommandSay.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\WorldCalifornia.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\PlayerCommands\CommandClear.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Scripts\EarthGame.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Settings.ini">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MudEngine\MudEngine.csproj">
|
||||
|
|
|
@ -11,7 +11,13 @@ namespace MudGame
|
|||
{
|
||||
static void Main(String[] args)
|
||||
{
|
||||
MudGame game = new MudGame();
|
||||
game.Initialize();
|
||||
|
||||
while (game.IsRunning)
|
||||
{
|
||||
game.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,222 +0,0 @@
|
|||
/// <summary>
|
||||
/// The Create command is used to dynamically create content within the game world.
|
||||
/// Content is created at run-time while the server/game is running and players are connected.
|
||||
/// Newly created content will be available for players to use/traverse immediately after creation is completed.
|
||||
/// Rooms that are created may be linked together using the LinkRoom command.
|
||||
/// </summary>
|
||||
public class CommandCreate : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public CommandCreate()
|
||||
{
|
||||
Help.Add("Provides Admins the ability to create content dynamically within the game world.");
|
||||
Help.Add("Content is created at run-time while the server/game is running and players are connected.");
|
||||
Help.Add("Newly created content will be available for players to use/traverse immediately after creation is completed.");
|
||||
Help.Add("Rooms that are created may be linked together using the LinkRoom command.");
|
||||
Help.Add("You may create Realms by simply supplying a Realm name. If you wish to create a Zone, you must specify the Realm name followed by a '>' then the Zone name.");
|
||||
Help.Add("Example: 'Create MyRealm>MyZone'");
|
||||
Help.Add("The same concept is applied for creating Rooms.");
|
||||
Help.Add("Example: 'Create MyRealm>MyZone>MyRoom'");
|
||||
Help.Add("Creating just a single Realm is used by supplying only the Realm name.");
|
||||
Help.Add("Example: 'Create MyRealm'");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will execute the command allowing Admins to generate environment objects dynamically on-the-fly.
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="player"></param>
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
//Check if the player has the proper security role in order to create content for the game world.
|
||||
if ((player.Role != SecurityRoles.Admin) && (player.Role != SecurityRoles.GM))
|
||||
{
|
||||
Log.Write("Player " + player.Name + " attempted to invoke the Create command without having the correct security role assigned!");
|
||||
return;
|
||||
}
|
||||
|
||||
//Split the supplied String up. It wil give us an array of strings with the supplied
|
||||
//object names if the admin has specified environment objects for creation.
|
||||
String[] env = command.Substring("Create ".Length).Split('>');
|
||||
|
||||
//No objects specified, so the admin didn't use the command correctly.
|
||||
if (env.Length == 0)
|
||||
{
|
||||
player.Send("Invalid use of the 'Create' command. Please try 'Help Create' for help using the command.");
|
||||
return;
|
||||
}
|
||||
//Only 1 object name supplied, so we assume the admin wants a Realm created with the supplied name.
|
||||
else if (env.Length == 1)
|
||||
{
|
||||
//Check if the supplied name is a valid Realm name, and if the Realm can be created.
|
||||
//If it's valid, the Realm is instanced and stored in our private Field 'realm'
|
||||
Boolean validRealm = ValidateRealm(env[0], player);
|
||||
|
||||
if (validRealm)
|
||||
{
|
||||
player.ActiveGame.World.AddRealm(realm);
|
||||
Log.Write(player.Name + " created a Realm called " + realm.Filename);
|
||||
player.Send(env[0] + " created.");
|
||||
}
|
||||
//Add the 'realm' Field that was instanced via ValidateRealm
|
||||
else
|
||||
{
|
||||
Log.Write("Failed to validate realm during dynamic Creation.");
|
||||
player.Send("Failed to create Realm! Please ensure a duplicate file name does not exist!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
//Recieved two names, so we assume the admin wants a Zone created.
|
||||
//If the Realm that is supplied for this Zone does not create, we will create it.
|
||||
else if (env.Length == 2)
|
||||
{
|
||||
//Check if the Realm name supplied already exists. If it does, this will return false (Invalid name due to already existing)
|
||||
//If it returns true, then the Realm is valid, meaning non already exists, so we will create it.
|
||||
Boolean validRealm = ValidateRealm(env[0], player);
|
||||
|
||||
//Add the Realm to the game world since this Zone is being created in a non-existant Realm.
|
||||
if (validRealm)
|
||||
{
|
||||
player.ActiveGame.World.AddRealm(realm);
|
||||
player.Send(env[0] + " created.");
|
||||
Log.Write(player.Name + " created a Realm called " + realm.Filename);
|
||||
}
|
||||
|
||||
//Check if this Zone is a valid Zone. if it returns true, then the 'zone' field will reference the new Zone
|
||||
Boolean validZone = ValidateZone(env[0], env[1], player);
|
||||
|
||||
if (validZone)
|
||||
{
|
||||
realm.AddZone(zone);
|
||||
player.Send(env[1] + " created.");
|
||||
Log.Write(player.Name + " created a Zone called " + zone.Filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Write("Failed to validate Zone during dynamic creation.");
|
||||
player.Send("Failed to create Zone! Please ensure a duplicate filename does not exist!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (env.Length == 3)
|
||||
{
|
||||
//Check if the Realm name supplied already exists. If it does, this will return false (Invalid name due to already existing)
|
||||
//If it returns true, then the Realm is valid, meaning non already exists, so we will create it.
|
||||
Boolean validRealm = ValidateRealm(env[0], player);
|
||||
|
||||
//Add the Realm to the game world since this Zone is being created in a non-existant Realm.
|
||||
if (validRealm)
|
||||
{
|
||||
player.ActiveGame.World.AddRealm(realm);
|
||||
player.Send(env[0] + " created.");
|
||||
Log.Write(player.Name + " created a Realm called " + realm.Filename);
|
||||
}
|
||||
|
||||
Boolean validZone = ValidateZone(env[0], env[1], player);
|
||||
|
||||
if (validZone)
|
||||
{
|
||||
realm.AddZone(zone);
|
||||
player.Send(env[1] + " created.");
|
||||
Log.Write(player.Name + " created a Zone called " + zone.Filename);
|
||||
}
|
||||
|
||||
Boolean validRoom = ValidateRoom(env[0], env[1], env[2], player);
|
||||
|
||||
if (validRoom)
|
||||
{
|
||||
zone.AddRoom(room);
|
||||
player.Send(env[2] + " created.");
|
||||
Log.Write(player.Name + " created a Room called " + room.Filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Write("Failed to validate Room during dynamic creation.");
|
||||
player.Send("Failed to create Room! Please ensure a duplicate filename does not exist!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates if the supplied Realm filename exists in the game world or not.
|
||||
/// Returns True if it does not exist; False if it does exist (As if it exists it's not a valid name to use during creation).
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="player"></param>
|
||||
/// <returns></returns>
|
||||
private Boolean ValidateRealm(String name, BaseCharacter player)
|
||||
{
|
||||
if (player.ActiveGame.World.GetRealm(name + ".Realm") != null)
|
||||
{
|
||||
realm = player.ActiveGame.World.GetRealm(name + ".Realm");
|
||||
return false;
|
||||
}
|
||||
|
||||
realm = new Realm(player.ActiveGame);
|
||||
realm.Name = name;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates if the supplied Zone filename exists in the game world or not.
|
||||
/// Returns True if it does not exist; False if it does exist (As if it exists it's not a valid name to use during creation).
|
||||
/// If the Zones owning Realm does not exist, it returns false and fails.
|
||||
/// </summary>
|
||||
/// <param name="realmName"></param>
|
||||
/// <param name="zoneName"></param>
|
||||
/// <param name="player"></param>
|
||||
/// <returns></returns>
|
||||
private Boolean ValidateZone(String realmName, String zoneName, BaseCharacter player)
|
||||
{
|
||||
if (realm == null)
|
||||
{
|
||||
player.Send("Unable to validate Zone due to invalid Realm.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (realm.GetZone(zoneName + ".Zone").Count != 0)
|
||||
{
|
||||
zone = realm.GetZone(zoneName + ".Zone")[0];
|
||||
return false;
|
||||
}
|
||||
|
||||
zone = new Zone(player.ActiveGame);
|
||||
zone.Name = zoneName;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates if the supplied Room filename exists in the game world or not.
|
||||
/// Returns True if it does not exist; False if it does exist (As if it exists it's not a valid name to use during creation).
|
||||
/// If the Rooms owning Zone or Realm does not exist, it returns false and fails.
|
||||
/// </summary>
|
||||
/// <param name="realmName"></param>
|
||||
/// <param name="zoneName"></param>
|
||||
/// <param name="roomName"></param>
|
||||
/// <param name="player"></param>
|
||||
/// <returns></returns>
|
||||
private Boolean ValidateRoom(String realmName, String zoneName, String roomName, BaseCharacter player)
|
||||
{
|
||||
if ((realm == null) || (zone == null))
|
||||
{
|
||||
player.Send("Unable to validate Room due to invalid Realm or Zone.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone.GetRoom(roomName + ".Room").Count != 0)
|
||||
{
|
||||
room = zone.GetRoom(roomName + ".Room")[0];
|
||||
return false;
|
||||
}
|
||||
|
||||
room = new Room(player.ActiveGame);
|
||||
room.Name = roomName;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/// <summary>
|
||||
/// This command creates a Room within the players current Realm>Zone.
|
||||
/// Admins using this command will not need to supply a fully qualified path like the 'Create' command requires.
|
||||
/// However, they are restricted to creating Rooms only within their current Realm>Zone.
|
||||
/// </summary>
|
||||
public class CommandCreateRoom : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public CommandCreateRoom()
|
||||
{
|
||||
Help.Add("Creates a Room within the Admin's current Realm>Zone");
|
||||
}
|
||||
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
if ((player.Role == SecurityRoles.Admin) || (player.Role == SecurityRoles.GM))
|
||||
{
|
||||
String roomname = command.Substring("Createroom".Length).Trim();
|
||||
|
||||
if (String.IsNullOrEmpty(roomname))
|
||||
{
|
||||
player.Send("You must supply a Room name! Refer to 'Help CreateRoom' for usage examples.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ((String.IsNullOrEmpty(player.CurrentRoom.Realm)) || (String.IsNullOrEmpty(player.CurrentRoom.Zone)))
|
||||
{
|
||||
player.Send("You are not currently within a pre-existing Zone.");
|
||||
player.Send("Use the Teleport command to teleport yourself into a valid Zone before using the CreateRoom command.");
|
||||
return;
|
||||
}
|
||||
|
||||
Room r = new Room(player.ActiveGame);
|
||||
r.Realm = player.CurrentRoom.Realm;
|
||||
r.Zone = player.CurrentRoom.Zone;
|
||||
r.Name = roomname;
|
||||
player.ActiveGame.World.GetRealm(r.Realm).GetZone(r.Zone)[0].AddRoom(r);
|
||||
|
||||
player.Send(r.Name + " created within " + r.Realm + ">" + r.Zone + ".");
|
||||
Log.Write(player.Name + " created a new Room in " + r.RoomLocation);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,398 +0,0 @@
|
|||
/// <summary>
|
||||
/// The LinkRoom command is used to Link two previously created Rooms together.
|
||||
/// Rooms linked together can be traversed by players.
|
||||
/// This command is used to link Rooms dynamically during run-time by Admins, allowing environments to be created
|
||||
/// and traversed on-the-fly without the need to modify scripts and re-start the server.
|
||||
/// </summary>
|
||||
public class CommandLinkRoom : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public CommandLinkRoom()
|
||||
{
|
||||
Help.Add("Use this to link two previously created Rooms together.");
|
||||
//Incase Admins try to use the command, they will know that it's broken.
|
||||
//Don't convert this class into a Script until it is fully completed.
|
||||
Help.Add("NOTE: This command is not fully implemented. You may link two Rooms together provided they exist within the same Zone.");
|
||||
Help.Add("You may experience some Rooms not being traversable even after linking.");
|
||||
Help.Add("This command is a work-in-progress and will contain bugs.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the command.
|
||||
/// This method is called from the Command Engine, it is not recommended that you call this method directly.
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="player"></param>
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
//Check if the Player has the correct privileges to Link Rooms together.
|
||||
//If they are not a Admin or GM then the command will bail.
|
||||
//This creates the illusion that this command possibly doesn't exist.
|
||||
if ((player.Role != SecurityRoles.Admin) && (player.Role != SecurityRoles.GM))
|
||||
{
|
||||
player.Send("Invalid Command.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Build the Menu system that will be displayed to Admins.
|
||||
player.Send("Room linkage tool");
|
||||
player.Send("Please select an option.");
|
||||
player.Send("1: Link Room");
|
||||
player.Send("2: Exit");
|
||||
|
||||
//Read the input from the Admin.
|
||||
String input = player.ReadInput();
|
||||
Int32 value = 0;
|
||||
|
||||
//Attempt to convert their input from a String into a numerical value.
|
||||
//If they entered a non-numerical value, then the method will exit
|
||||
try
|
||||
{
|
||||
value = Convert.ToInt32(input);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
player.Send("Invalid selection. Please use numeric values.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Ask what Room the Admin wants to use as the Departing Room.
|
||||
//Departing Rooms will be where the travel direction originates from.
|
||||
//meaning if the Admin selects West as the traveling direction, then traveling West will exit the
|
||||
//Departing Room and enter the Arrival Room.
|
||||
player.Send("");
|
||||
player.Send("Please select which Realm your departing Room resides within:");
|
||||
player.Send("");
|
||||
|
||||
//Instance a new Realm that we can use to reference an existing Realm so that we can find the
|
||||
//Rooms within it that the Admin is looking for.
|
||||
Boolean isValidRealm = false;
|
||||
Realm realm = new Realm(player.ActiveGame);
|
||||
|
||||
//Create a Loop incase the Admin enters an invalid Realm, we can just loop
|
||||
//back and re-ask the Admin the enter a valid Realm name.
|
||||
while (!isValidRealm)
|
||||
{
|
||||
//Now that we are in the loop, set the isValidRealm to true, as we will assume that
|
||||
//the user will enter a valid Realm name on the first shot. If we can't find a matching
|
||||
//Realm, then this will get set to false once iterating through Realms is completed.
|
||||
isValidRealm = true;
|
||||
|
||||
//Print each Realm out to the Admin so they may see a complete list to choose from.
|
||||
//This is the Realm that their first Room will reside within.
|
||||
//TODO: Currently only linking Rooms within the same Realm/Zone is supported. Need to fix that.
|
||||
foreach (Realm r in player.ActiveGame.World.RealmCollection)
|
||||
player.Send(r.Filename + " | ", false);
|
||||
|
||||
//As for the Admins selection, we will place the Admins input on the same line
|
||||
//as the last message sent to the Admin by setting the newLine parameter to false.
|
||||
player.Send("");
|
||||
player.Send("Selection: ", false);
|
||||
|
||||
//Get the Admins input that should specify what Realm they are wanting.
|
||||
input = player.ReadInput();
|
||||
|
||||
//Check if the Admin entered 'Cancel'. If so, then cancel the Link process.
|
||||
if (input.ToLower() == "cancel")
|
||||
{
|
||||
player.Send("Room Linking aborted.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Query the Active Games world collection, finding Realms that match the filename entered by the Admin
|
||||
var realmQuery =
|
||||
from r in player.ActiveGame.World.RealmCollection
|
||||
where r.Filename.ToLower() == input.ToLower()
|
||||
select r;
|
||||
|
||||
//Check if the query contains a Realm.
|
||||
if (realmQuery.FirstOrDefault() != null)
|
||||
{
|
||||
//The query does in-fact contain a valid Realm. Assign it to our realm field for use later.
|
||||
realm = realmQuery.FirstOrDefault();
|
||||
//We can set this to true, allowing us to exit out of the loop.
|
||||
isValidRealm = true;
|
||||
}
|
||||
//If the query does not contain a Realm, then we ensure that the loop will continue by forcing
|
||||
//isValidRealm back to false.
|
||||
else
|
||||
{
|
||||
isValidRealm = false;
|
||||
//Let the Admin know that they entered an invalid Realm name and that they need to try again.
|
||||
player.Send("That Realm does not exist! Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
//Let the Admin know that they need to now select which Zone the Room they are wanting to link resides within.
|
||||
player.Send("");
|
||||
player.Send("Please select which Zone your departing Room resides within:");
|
||||
player.Send("");
|
||||
|
||||
//Instance a new Zone that we can use to reference an existing Zone so that we can find the
|
||||
//Rooms within it that the Admin is looking for.
|
||||
Boolean isValidZone = false;
|
||||
Zone zone = new Zone(player.ActiveGame);
|
||||
|
||||
//Create a Loop incase the Admin enters an invalid Zone, we can just loop
|
||||
//back and re-ask the Admin the enter a valid Zone name.
|
||||
while (!isValidZone)
|
||||
{
|
||||
//Now that we are in the loop, set the isValidZone to true, as we will assume that
|
||||
//the user will enter a valid Zone name on the first shot. If we can't find a matching
|
||||
//Zone, then this will get set to false once iterating through Zone is completed.
|
||||
isValidZone = true;
|
||||
|
||||
//Print each Zone out to the Admin so they may see a complete list to choose from.
|
||||
//This is the Zone that their first Room will reside within.
|
||||
//TODO: Currently only linking Rooms within the same Realm/Zone is supported. Need to fix that.
|
||||
foreach (Zone z in realm.ZoneCollection)
|
||||
{
|
||||
player.Send(z.Filename + " | ", false);
|
||||
}
|
||||
|
||||
//As for the Admins selection, we will place the Admins input on the same line
|
||||
//as the last message sent to the Admin by setting the newLine parameter to false.
|
||||
player.Send("");
|
||||
player.Send("Selection: ", false);
|
||||
|
||||
//Get the Admins input that should specify what Zone they are wanting.
|
||||
input = player.ReadInput();
|
||||
|
||||
//Check if the Admin entered 'Cancel'. If so, then cancel the Link process.
|
||||
if (input.ToLower() == "cancel")
|
||||
{
|
||||
player.Send("Room Linking aborted.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Query the stored Realm's Zone collection, finding Zones that match the filename entered by the Admin
|
||||
var zoneQuery =
|
||||
from z in realm.ZoneCollection
|
||||
where z.Filename.ToLower() == input.ToLower()
|
||||
select z;
|
||||
|
||||
//Check if the query contains a Zone.
|
||||
if (zoneQuery.FirstOrDefault() != null)
|
||||
{
|
||||
//The query does in-fact contain a valid Zone. Assign it to our zone field for use later.
|
||||
zone = zoneQuery.FirstOrDefault();
|
||||
//We can set this to true, allowing us to exit out of the loop.
|
||||
isValidZone = true;
|
||||
}
|
||||
//If the query does not contain a Zone, then we ensure that the loop will continue by forcing
|
||||
//isValidZone back to false.
|
||||
else
|
||||
{
|
||||
isValidZone = false;
|
||||
//Let the Admin know that they entered an invalid Zone name and that they need to try again.
|
||||
player.Send("That Zone does not exist! Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
//Let the Admin know that they need to now select Room they are wanting to link as the departure Room
|
||||
player.Send("");
|
||||
player.Send("Please select which Room that you wish to be the departing Room:");
|
||||
player.Send("");
|
||||
|
||||
//Instance a new Room that we can store a reference to a existing Room.
|
||||
//We will use this reference to link the departure and arrival Rooms together.
|
||||
Boolean isValidRoom = false;
|
||||
Room departingRoom = new Room(player.ActiveGame);
|
||||
|
||||
//Create a Loop incase the Admin enters an invalid Room, we can just loop
|
||||
//back and re-ask the Admin the enter a valid Room name.
|
||||
while (!isValidRoom)
|
||||
{
|
||||
//Now that we are in the loop, set the isValidRoom to true, as we will assume that
|
||||
//the user will enter a valid Room name on the first shot. If we can't find a matching
|
||||
//Room, then this will get set to false once iterating through Room is completed.
|
||||
isValidRoom = true;
|
||||
|
||||
//Print each Room out to the Admin so they may see a complete list to choose from.
|
||||
//This will be their departing Room.
|
||||
//TODO: Currently only linking Rooms within the same Realm/Zone is supported. Need to fix that.
|
||||
foreach (Room r in zone.RoomCollection)
|
||||
{
|
||||
player.Send(r.Filename + " | ", false);
|
||||
}
|
||||
|
||||
//As for the Admins selection, we will place the Admins input on the same line
|
||||
//as the last message sent to the Admin by setting the newLine parameter to false.
|
||||
player.Send("");
|
||||
player.Send("Selection: ", false);
|
||||
|
||||
//Get the Admins input that should specify what Room they are wanting.
|
||||
input = player.ReadInput();
|
||||
|
||||
//Check if the Admin entered 'Cancel'. If so, then cancel the Link process.
|
||||
if (input.ToLower() == "cancel")
|
||||
{
|
||||
player.Send("Room Linking aborted.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Query the referenced zone's Room collection, finding Rooms that match the filename entered by the Admin
|
||||
var roomQuery =
|
||||
from r in zone.RoomCollection
|
||||
where r.Filename.ToLower() == input.ToLower()
|
||||
select r;
|
||||
|
||||
//Check if the query contains a Room.
|
||||
if (roomQuery.FirstOrDefault() != null)
|
||||
{
|
||||
//The query does in-fact contain a valid Room. Assign it to our departingRoom field for use later.
|
||||
departingRoom = roomQuery.FirstOrDefault();
|
||||
//We can set this to true, allowing us to exit out of the loop.
|
||||
isValidRoom = true;
|
||||
}
|
||||
//If the query does not contain a Room, then we ensure that the loop will continue by forcing
|
||||
//isValidRoom back to false.
|
||||
else
|
||||
{
|
||||
isValidRoom = false;
|
||||
//Let the Admin know that they entered an invalid Room name and that they need to try again.
|
||||
player.Send("That Room does not exist! Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
//Let the Admin know that they need to now select Room they are wanting to link as the Arrival Room
|
||||
player.Send("");
|
||||
player.Send("Please select which Room that you wish to be the Arrival Room:");
|
||||
player.Send("");
|
||||
|
||||
//Instance a new Room that we can store a reference to a existing Room.
|
||||
//We will use this reference to link the departure and arrival Rooms together.
|
||||
isValidRoom = false;
|
||||
Room arrivalRoom = new Room(player.ActiveGame);
|
||||
|
||||
//Create a Loop incase the Admin enters an invalid Room, we can just loop
|
||||
//back and re-ask the Admin the enter a valid Room name.
|
||||
while (!isValidRoom)
|
||||
{
|
||||
//Now that we are in the loop, set the isValidRoom to true, as we will assume that
|
||||
//the user will enter a valid Room name on the first shot. If we can't find a matching
|
||||
//Room, then this will get set to false once iterating through Room is completed.
|
||||
isValidRoom = true;
|
||||
|
||||
//Print each Room out to the Admin so they may see a complete list to choose from.
|
||||
//This will be their departing Room.
|
||||
//TODO: Currently only linking Rooms within the same Realm/Zone is supported. Need to fix that.
|
||||
foreach (Room r in zone.RoomCollection)
|
||||
{
|
||||
player.Send(r.Filename + " | ", false);
|
||||
}
|
||||
|
||||
//As for the Admins selection, we will place the Admins input on the same line
|
||||
//as the last message sent to the Admin by setting the newLine parameter to false.
|
||||
player.Send("");
|
||||
player.Send("Selection: ", false);
|
||||
|
||||
//Get the Admins input that should specify what Room they are wanting.
|
||||
input = player.ReadInput();
|
||||
|
||||
//Check if the Admin entered 'Cancel'. If so, then cancel the Link process.
|
||||
if (input.ToLower() == "cancel")
|
||||
{
|
||||
player.Send("Room Linking aborted.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Query the referenced zone's Room collection, finding Rooms that match the filename entered by the Admin
|
||||
var roomQuery =
|
||||
from r in zone.RoomCollection
|
||||
where r.Filename.ToLower() == input.ToLower()
|
||||
select r;
|
||||
|
||||
//Check if the query contains a Room.
|
||||
if (roomQuery.FirstOrDefault() != null)
|
||||
{
|
||||
//The query does in-fact contain a valid Room. Assign it to our departingRoom field for use later.
|
||||
departingRoom = roomQuery.FirstOrDefault();
|
||||
//We can set this to true, allowing us to exit out of the loop.
|
||||
isValidRoom = true;
|
||||
}
|
||||
//If the query does not contain a Room, then we ensure that the loop will continue by forcing
|
||||
//isValidRoom back to false.
|
||||
else
|
||||
{
|
||||
isValidRoom = false;
|
||||
//Let the Admin know that they entered an invalid Room name and that they need to try again.
|
||||
player.Send("That Room does not exist! Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
//Let the Admin select the direction of travel required for a player to traverse from the
|
||||
//departing Room into the arriving Room.
|
||||
player.Send("Please select which direction you would like to travel while departing the departure Room.");
|
||||
|
||||
//Store a array of existing values within the AvailableTravelDirection enum.
|
||||
//These values are the legal travel directions that are supported by the game.
|
||||
Array values = Enum.GetValues(typeof(AvailableTravelDirections));
|
||||
|
||||
//Create a reference to the AvailableTravelDirections enum that we can use to assign a travel
|
||||
//when we pass the Room linking off to the Rooms owning Zone.
|
||||
AvailableTravelDirections direction = new AvailableTravelDirections();
|
||||
Boolean isValidDirection = false;
|
||||
|
||||
//Perform the direction corrections within a while loop, incase the Admin enteres
|
||||
//a invalid traveling direction and we need to re-acquire input from the Admin.
|
||||
while (!isValidDirection)
|
||||
{
|
||||
//Loop through the array, printing each travel direction we found in the enum array collection
|
||||
//to the screen for the user to see and select from.
|
||||
foreach (Int32 v in values)
|
||||
{
|
||||
//Since enum values are not strings, we can't simply assign a String value to the enum.
|
||||
//The enum needs to be queried to retrieve a value that matches that of 'v' and convert it to a String
|
||||
String displayName = Enum.GetName(typeof(AvailableTravelDirections), v);
|
||||
|
||||
//Print this current iterations value to the screen for the player.
|
||||
player.Send(displayName + " | ");
|
||||
}
|
||||
|
||||
//As for the Admins selection, we will place the Admins input on the same line
|
||||
//as the last message sent to the Admin by setting the newLine parameter to false.
|
||||
player.Send("Enter Selection: ", false);
|
||||
input = player.ReadInput();
|
||||
|
||||
//Loop through each value found in our original array or values acquired from the AvailableTravelDirections enum.
|
||||
foreach (Int32 v in values)
|
||||
{
|
||||
//Since enum values are not strings, we can't simply assign a String value to the enum.
|
||||
//The enum needs to be queried to retrieve a value that matches that of 'v' and convert it to a String
|
||||
String displayName = Enum.GetName(typeof(AvailableTravelDirections), v);
|
||||
|
||||
//Check if the Admins selected travel direction matches that of the current travel direction value found
|
||||
//within our array of values harvested from the AvailableTravelDirections enum
|
||||
if (displayName.ToLower() == input.ToLower())
|
||||
{
|
||||
//The two match up. Now you have to convert the String version of the travel direction, back into
|
||||
//an enum equivilant for use by the Rooms owning Zone during linking.
|
||||
direction = (AvailableTravelDirections)Enum.Parse(typeof(AvailableTravelDirections), displayName);
|
||||
|
||||
//We found a legal Travel Direction. Setting this to true will exit the while loop.
|
||||
isValidDirection = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
isValidDirection = false;
|
||||
}
|
||||
|
||||
//Check if we haven't found a valid direction yet. This will print to the Admin that the entered
|
||||
//direction was invalid, and then loop back to the top of the current loop.
|
||||
if (!isValidDirection)
|
||||
{
|
||||
player.Send("Invalid direction supplied!");
|
||||
}
|
||||
//The direction supplied by the Admin matched up and was concidered legal, so we shoud
|
||||
//have a converted AvailableTravelDirection now with the value matching that of the Admins.
|
||||
//Link the two rooms together, with the travel direction of the Admins choice.
|
||||
else
|
||||
{
|
||||
zone.LinkRooms(direction, arrivalRoom, departingRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,187 +0,0 @@
|
|||
/// <summary>
|
||||
/// The List command is used to list filenames of a specified object type.
|
||||
/// </summary>
|
||||
public class CommandList : BaseCommand
|
||||
{
|
||||
public CommandList()
|
||||
{
|
||||
Help.Add("Using the List command, you can view a generated list of filenames that pertain to a supplied object type.");
|
||||
Help.Add("Usage: List 'ItemType'");
|
||||
Help.Add("Usage: List 'ItemName>ItemType'");
|
||||
Help.Add("");
|
||||
Help.Add("Supported Listable ItemTypes are as follows:");
|
||||
Help.Add("Players");
|
||||
Help.Add("Realms");
|
||||
Help.Add("Zones");
|
||||
Help.Add("RealmName>Rooms");
|
||||
Help.Add("RealmName>Zones");
|
||||
Help.Add("RealmName>ZoneName>Rooms");
|
||||
}
|
||||
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
command = command.Substring("List".Length).Trim();
|
||||
String[] data = command.ToLower().Split('>');
|
||||
|
||||
//Admin || GM only item listings.
|
||||
if ((player.Role == SecurityRoles.Admin) || (player.Role == SecurityRoles.GM))
|
||||
{
|
||||
//Player must be a admin or GM to view all the objects on the server like this.
|
||||
if ((data.Length == 0) || (String.IsNullOrEmpty(data[0])))
|
||||
{
|
||||
player.Send("Invalid command usage. Enter 'help List' for usage examples.");
|
||||
return;
|
||||
}
|
||||
else if (data.Length == 1)
|
||||
{
|
||||
switch (data[0])
|
||||
{
|
||||
case "realms":
|
||||
if (player.ActiveGame.World.RealmCollection.Count == 0)
|
||||
player.Send("There are currently no loaded Realm files.");
|
||||
else
|
||||
{
|
||||
player.Send("Currently loaded Realm files:");
|
||||
foreach (Realm r in player.ActiveGame.World.RealmCollection)
|
||||
player.Send(r.Filename + " | ", false);
|
||||
}
|
||||
break;
|
||||
case "players":
|
||||
if (System.IO.Directory.GetFiles(player.ActiveGame.DataPaths.Players, "*.character").Length == 0)
|
||||
player.Send("There are currently no characters created on this server.");
|
||||
else
|
||||
{
|
||||
player.Send("Players with created characters:");
|
||||
BaseCharacter p = new BaseCharacter(player.ActiveGame);
|
||||
foreach (String file in System.IO.Directory.GetFiles(player.ActiveGame.DataPaths.Players, "*.character"))
|
||||
{
|
||||
p.Load(file);
|
||||
player.Send(p.Name + " | ", false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "zones":
|
||||
if (player.ActiveGame.World.RealmCollection.Count == 0)
|
||||
{
|
||||
player.Send("There are currently no Zones created on this server.");
|
||||
}
|
||||
else
|
||||
{
|
||||
List<String> names = new List<String>();
|
||||
foreach (Realm r in player.ActiveGame.World.RealmCollection)
|
||||
{
|
||||
foreach (Zone z in r.ZoneCollection)
|
||||
{
|
||||
names.Add(System.IO.Path.GetFileNameWithoutExtension(r.Filename) + ">" + System.IO.Path.GetFileNameWithoutExtension(z.Filename));
|
||||
}
|
||||
}
|
||||
|
||||
if (names.Count == 0)
|
||||
{
|
||||
player.Send("There are currently no Zones created on this server.");
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Send("Currently loaded Zones. This spans across every Realm in the world.");
|
||||
foreach (String name in names)
|
||||
{
|
||||
player.Send(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "commands":
|
||||
player.Send("The following commands are available for use:");
|
||||
|
||||
foreach (String cmd in CommandEngine.GetCommands())
|
||||
{
|
||||
IGameCommand gc = CommandEngine.GetCommand(cmd);
|
||||
player.Send(gc.Name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
player.Send("Invalid token supplied. Enter 'Help List' for usage examples.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (data.Length == 2)
|
||||
{
|
||||
if (data[1] == "zones")
|
||||
{
|
||||
if (player.ActiveGame.World.GetRealm(data[0] + ".realm") == null)
|
||||
{
|
||||
player.Send("Invalid Realm, unable to list Zones.");
|
||||
return;
|
||||
}
|
||||
player.Send("Displaying Currently loaded Zones within Realm " + data[0]);
|
||||
foreach (Zone z in player.ActiveGame.World.GetRealm(data[0] + ".realm").ZoneCollection)
|
||||
player.Send(z.Filename + " | ", false);
|
||||
}
|
||||
else if (data[1] == "rooms")
|
||||
{
|
||||
if (player.ActiveGame.World.GetRealm(data[0] + ".realm") == null)
|
||||
{
|
||||
player.Send("Invalid Realm, unable to list Rooms.");
|
||||
return;
|
||||
}
|
||||
|
||||
player.Send("Displaying currently loaded Rooms within Realm " + data[0] + ". These Rooms span multiple Zones.");
|
||||
foreach (Zone z in player.ActiveGame.World.GetRealm(data[0] + ".realm").ZoneCollection)
|
||||
{
|
||||
foreach (Room r in z.RoomCollection)
|
||||
{
|
||||
player.Send(System.IO.Path.GetFileNameWithoutExtension(z.Filename) + ">" + System.IO.Path.GetFileNameWithoutExtension(r.Filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (data.Length == 3)
|
||||
{
|
||||
if (data[2] == "rooms")
|
||||
{
|
||||
if (player.ActiveGame.World.GetRealm(data[0] + ".realm") == null)
|
||||
{
|
||||
player.Send("Invalid Realm, unable to list Rooms.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.ActiveGame.World.GetRealm(data[0] + ".realm").GetZone(data[1] + ".zone")[0] == null)
|
||||
{
|
||||
player.Send("Invalid Zone, unable to list Rooms.");
|
||||
return;
|
||||
}
|
||||
|
||||
player.Send("Displaying Currently loaded Rooms within " + data[0] + ">" + data[1]);
|
||||
foreach (Room r in player.ActiveGame.World.GetRealm(data[0] + ".realm").GetZone(data[1] + ".zone")[0].RoomCollection)
|
||||
player.Send(r.Filename + " | ", false);
|
||||
}
|
||||
}
|
||||
} //End Admin || GM only item listings.
|
||||
//Begin normal player item listings
|
||||
else
|
||||
{
|
||||
//Player must be a admin or GM to view all the objects on the server like this.
|
||||
if ((data.Length == 0) || (String.IsNullOrEmpty(data[0])))
|
||||
{
|
||||
player.Send("Invalid command usage. Enter 'help List' for usage examples.");
|
||||
return;
|
||||
}
|
||||
else if (data.Length == 1)
|
||||
{
|
||||
if (data[0] == "commands")
|
||||
{
|
||||
player.Send("The following commands are available for use:");
|
||||
|
||||
foreach (String cmd in CommandEngine.GetCommands())
|
||||
{
|
||||
IGameCommand gc = CommandEngine.GetCommand(cmd);
|
||||
if ((gc.Name == "CommandCreate") || (gc.Name == "CommandCreateRoom") || (gc.Name == "CommandLinkRoom") || (gc.Name == "CommandRestart") || (gc.Name == "CommandSaveWorld"))
|
||||
continue;
|
||||
|
||||
player.Send(gc.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
public class CommandRestart : BaseCommand
|
||||
{
|
||||
public CommandRestart()
|
||||
{
|
||||
Help.Add("Restarts the game server.");
|
||||
}
|
||||
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
if (player.Role == SecurityRoles.Admin)
|
||||
{
|
||||
String path = player.ActiveGame.DataPaths.Players;
|
||||
|
||||
for (Int32 i = 0; i < player.ActiveGame.GetPlayerCollection().Length; i++)
|
||||
{
|
||||
String filename = Path.Combine(path, player.ActiveGame.GetPlayerCollection()[i].Filename);
|
||||
player.ActiveGame.GetPlayerCollection()[i].Save();
|
||||
}
|
||||
|
||||
//player.ActiveGame.Server.EndServer(); //-Handled in Game.Shutdown() below.
|
||||
player.ActiveGame.Shutdown();
|
||||
player.ActiveGame.Start();
|
||||
/* Game.Start() calls this, do we need a reference to the GetPlayerCollection()?
|
||||
* They should be unloaded anyway and re-loaded during game.start to force a clean restart of all objects.
|
||||
player.ActiveGame.Server.Initialize(555, ref player.ActiveGame.GetPlayerCollection());
|
||||
*/
|
||||
|
||||
Log.Write("Server Restart Completed.");
|
||||
//This is never printed as CommandResults is no longer outputted to the player console, player.Send is used
|
||||
player.Send("Server Restarted.");
|
||||
return;
|
||||
}
|
||||
|
||||
player.Send("Access Denied.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
public class CommandSaveWorld : BaseCommand
|
||||
{
|
||||
public CommandSaveWorld()
|
||||
{
|
||||
Help.Add("Saves the game world.");
|
||||
}
|
||||
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
if ((player.Role == SecurityRoles.Admin) || (player.Role == SecurityRoles.GM))
|
||||
{
|
||||
player.ActiveGame.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/// <summary>
|
||||
/// The List command is used to list filenames of a specified object type.
|
||||
/// </summary>
|
||||
public class CommandTeleport : BaseCommand
|
||||
{
|
||||
public CommandTeleport()
|
||||
{
|
||||
Help.Add("The Teleport command will teleport a player to a specified Room, regardless of where they are at.");
|
||||
Help.Add("Usage: Teleport playername FullyQualifiedRoomPath");
|
||||
Help.Add("Example: Teleport Billy MyRealm>MyZone>MyRoom");
|
||||
}
|
||||
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
command = command.Substring("teleport".Length).Trim();
|
||||
String[] data = command.ToLower().Split(' ');
|
||||
|
||||
//Admin || GM only item listings.
|
||||
if ((player.Role == SecurityRoles.Admin) || (player.Role == SecurityRoles.GM))
|
||||
{
|
||||
if (data.Length == 0)
|
||||
{
|
||||
player.Send("Invalid operation. You must supply a username along with a fully qualified path name for the user to be teleported to.");
|
||||
return;
|
||||
}
|
||||
else if (data.Length == 1)
|
||||
{
|
||||
player.Send("Invalid operation. You must supply a fully qualified path name for the user to be teleported.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (BaseCharacter p in player.ActiveGame.GetPlayerCollection())
|
||||
{
|
||||
if (p.Name.ToLower() == data[0].ToLower())
|
||||
{
|
||||
String[] values = data[1].Split('>');
|
||||
|
||||
if (values.Length != 3)
|
||||
{
|
||||
player.Send("Invalid Operation. You must supply a fully qualified path name for the user to be teleported.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Realm r = player.ActiveGame.World.GetRealm(values[0]);
|
||||
if (r == null)
|
||||
{
|
||||
player.Send("Invalid Operation. Supplied Realm does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
Zone z = r.GetZone(values[1])[0];
|
||||
if (z == null)
|
||||
{
|
||||
player.Send("Invalid operation. Supplied Zone does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
Room rm = z.GetRoom(values[2])[0];
|
||||
if (rm == null)
|
||||
{
|
||||
player.Send("Invalid operation. Supplied Room does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
p.CurrentRoom = rm;
|
||||
|
||||
//Tell the teleported player that they have been moved.
|
||||
p.Send("You have been teleported by some higher power.");
|
||||
IGameCommand gc = CommandEngine.GetCommand("CommandLook");
|
||||
gc.Execute("Look", p);
|
||||
|
||||
player.Send("Teleporting completed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/// <summary>
|
||||
/// The EarthGame script extends from the Mud Designer Game Engine internal Game class.
|
||||
/// In order for the script to be used as the new default Game class within the engine, it MUST
|
||||
/// inherit from Game by using a colon followed by Game after the script name.
|
||||
///
|
||||
/// Ex: EarthGame : Game
|
||||
///
|
||||
/// This allows developers to extend on or modify how the Game will act during runtime.
|
||||
/// </summary>
|
||||
public class EarthGame : Game
|
||||
{
|
||||
//Our custom California Realm script.
|
||||
public WorldCalifornia Cali;
|
||||
|
||||
/// <summary>
|
||||
/// The Constructor for the Game.
|
||||
/// If you wish to have the internal engine Game class execute it's constructor code before your code
|
||||
/// is called, you must call the base class by using a colon followed by base() on the same line as your constructor.
|
||||
///
|
||||
/// Ex: EarthGame() : base()
|
||||
///
|
||||
/// This will ensure that all of the engine properties are setup correctly, incase you miss anything.
|
||||
/// Any code placed within your constructor is executed after the internal Game class constructor is executed,
|
||||
/// allowing you to override of the engines properties and set things up how your game needs things set.
|
||||
/// </summary>
|
||||
public EarthGame() : base()
|
||||
{
|
||||
//The following are Properties this script inherits from the internal Game class.
|
||||
GameTitle = "Planet Earth MUD";
|
||||
Story = "The planet Earth reproduced in a MUD for your playing enjoyment!";
|
||||
IsMultiplayer = true;
|
||||
|
||||
CompanyName = "Mud Designer Team";
|
||||
Website = "Visit Http://MudDesigner.Codeplex.com for the latest News, Documentation and Releases.";
|
||||
Version = "Example Game Version 1.0";
|
||||
|
||||
//Maximum number of players allowed to play on the server at any given time.
|
||||
MaximumPlayers = 1000;
|
||||
|
||||
//Create a new instance of our California realm script, we must pass a reference to our EarthGame
|
||||
//to the script so that it may add the Realm to our Game world. That is done by using the 'this' keyword.
|
||||
//Cali = new WorldCalifornia(this);
|
||||
|
||||
//Calling the create method within the california script.
|
||||
//Cali.Create();
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/// <summary>
|
||||
/// The Clear command is used to clear the players terminal screen of all text.
|
||||
/// </summary>
|
||||
public class CommandClear : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public CommandClear()
|
||||
{
|
||||
Help.Add("The Clear command is used to clear the screen of all text.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
//Call the flush method to clear the players console screen of all text.
|
||||
player.FlushConsole();
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/// <summary>
|
||||
/// The Exit command is used to exit the MUD game.
|
||||
/// Using this command while connected to a MUD server will perform a disconnect from the server.
|
||||
/// Using the command while running the game in offline mode will simply shut down the game.
|
||||
/// </summary>
|
||||
public class CommandExit : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public CommandExit()
|
||||
{
|
||||
Help.Add("Exits the game.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the command.
|
||||
/// This method is called from the Command Engine, it is not recommended that you call this method directly.
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="player"></param>
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
//Check if the game is multiplayer.
|
||||
//Multiplayer games require disconnecting from the server and letting other players in the same Room know
|
||||
//that this player has left.
|
||||
if (player.ActiveGame.IsMultiplayer)
|
||||
{
|
||||
//Query the Active Games Player collection so that we can build a collection of Players that need to be
|
||||
//informed of the Player disconnecting from the Server.
|
||||
var playerQuery =
|
||||
from p in player.ActiveGame.GetPlayerCollection()
|
||||
where !p.Name.StartsWith("New") && p.Name != player.Name && p.CurrentWorldLocation == player.CurrentWorldLocation
|
||||
select p;
|
||||
|
||||
//Inform each player found in our LINQ query that the player has disconnected from the Server.
|
||||
foreach (BaseCharacter p in playerQuery)
|
||||
p.Send(player.Name + " has left."); ;
|
||||
|
||||
//TODO: If a player is in a Group then s/he needs to be removed upon disconnecting.
|
||||
player.Disconnect();
|
||||
}
|
||||
else
|
||||
{
|
||||
//Call the game's shutdown method which will save all objects and exit the game gracefully.
|
||||
player.ActiveGame.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/// <summary>
|
||||
/// The GetTime command is used to print the current in-game time to the player.
|
||||
/// This command will print the day, month and year along with hour, minute and seconds.
|
||||
/// </summary>
|
||||
public class CommandGetTime : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public CommandGetTime()
|
||||
{
|
||||
Help.Add("Gives you the current time and date in the game world.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the Command.
|
||||
/// This method is called from the Command Engine, it is not recommended that you call this method directly.
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="player"></param>
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
//Send the returned String containing the World Time to the player.
|
||||
player.Send(player.ActiveGame.WorldTime.GetCurrentWorldTime());
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/// <summary>
|
||||
/// Help command provides information on all the existing game commands, including script based commands.
|
||||
/// </summary>
|
||||
public class CommandHelp : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public CommandHelp()
|
||||
{
|
||||
Help.Add("Provides help on various topics.");
|
||||
Help.Add("You may ask for help on any game command.");
|
||||
Help.Add("Usage: Help");
|
||||
Help.Add("Usage: Help 'command' where command = a game command");
|
||||
Help.Add("Example: Help Look");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
//Check if we have a topic that the player wants help with. If there is nothing after the Help word
|
||||
//in the command, then the user didn't supply us with a topic.
|
||||
String topic = command.Substring("Help".Length);
|
||||
|
||||
//if the user did not supply us with a topic, we will print every command currently loaded in the engine
|
||||
//and tell the user how they can access help information regarding that command.
|
||||
//TODO: Help command should have self contained help topics.
|
||||
if (topic.Length == 0)
|
||||
{
|
||||
player.Send("Available commands: ", false);
|
||||
|
||||
//Print each command found within the command engine.
|
||||
foreach (String cmd in CommandEngine.GetCommands())
|
||||
{
|
||||
//We will get a reference to the current command in the iteration
|
||||
IGameCommand g = CommandEngine.GetCommand(cmd);
|
||||
//Print the name of the command to the user, place a comma after the command
|
||||
//so that the next command can be placed afterwards.
|
||||
player.Send(CommandEngine.GetCommandName(g) + ", ", false);
|
||||
}
|
||||
|
||||
//Let the player know how to use the help command to access help regarding any of the aformentioned commands.
|
||||
player.Send("");
|
||||
player.Send("Usage: Help 'Command'");
|
||||
return;
|
||||
}
|
||||
//The player supplied a topic, lets trip out all the white spaces from it caused by the Substring method
|
||||
else
|
||||
topic = topic.Trim();
|
||||
|
||||
//Get a reference to the command the player wants help with. We must insert the 'Command' String into the topic,
|
||||
//as all Commands start with the word Command, however the player never sees the word Command. It's internal only.
|
||||
IGameCommand gc = CommandEngine.GetCommand("Command" + topic);
|
||||
|
||||
//Iterate through each entry in the commands help collection and print it to the player.
|
||||
foreach (String help in gc.Help)
|
||||
player.Send(help);
|
||||
}
|
||||
}
|
|
@ -1,170 +0,0 @@
|
|||
/// <summary>
|
||||
/// The Login command is used internally by the game engine.
|
||||
/// This command will not be available as a Script due to the engine requiring that it exists.
|
||||
/// Any changes needing to be made to this command to customize it in some manor will need to be done
|
||||
/// by modifying the source.
|
||||
/// TODO: Update the engine to dynamically look for a Login script rather than relying on CommandLogin.
|
||||
/// </summary>
|
||||
public class CommandLogin : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Class constructor
|
||||
/// </summary>
|
||||
public CommandLogin()
|
||||
{
|
||||
Help.Add("Logs the player into their respective account.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
//Print the basic Active Game's information to the connecting player.
|
||||
player.Send(player.ActiveGame.GameTitle);
|
||||
player.Send(player.ActiveGame.Version);
|
||||
player.Send(player.ActiveGame.Story);
|
||||
player.Send("");
|
||||
|
||||
//Setup some fields that we'll need.
|
||||
Boolean playerFound = false;
|
||||
String savedFile = "";
|
||||
String playerName = "";
|
||||
|
||||
//Loop until we have a valid player name entered.
|
||||
while (String.IsNullOrEmpty(playerName))
|
||||
{
|
||||
player.Send("Enter Character Name: ", false);
|
||||
playerName = player.ReadInput();
|
||||
}
|
||||
|
||||
//Check to make sure the saved players directory actually exists. If not, create it.
|
||||
if (!Directory.Exists(player.ActiveGame.DataPaths.Players))
|
||||
Directory.CreateDirectory(player.ActiveGame.DataPaths.Players);
|
||||
|
||||
//Setup some password fields we'll need
|
||||
Boolean passwordLegal = false;
|
||||
String playerPwrd = "";
|
||||
|
||||
//Loop through the password creation/entering process until we have a legal password
|
||||
//entered by the player logging in.
|
||||
while (!passwordLegal)
|
||||
{
|
||||
//Acquire a password from the player.
|
||||
player.Send("Enter Password: ", false);
|
||||
playerPwrd = player.ReadInput();
|
||||
|
||||
//Check if we have a legal password, meaning it's not empty and it's at least as long as the
|
||||
//current Active Game's minimum PasswordSize property has been set to.
|
||||
if ((!String.IsNullOrEmpty(playerPwrd)) && (playerPwrd.Length >= player.ActiveGame.MinimumPasswordSize))
|
||||
{
|
||||
passwordLegal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Let the user know that their password was invalid and they need to make sure that it conforms to the
|
||||
//current Active Game's minumum password size requirement.
|
||||
passwordLegal = false;
|
||||
player.Send("Invalid Password, minimum password length is " + player.ActiveGame.MinimumPasswordSize + " characters");
|
||||
}
|
||||
|
||||
//Check if the password is legal. If so, we need to find the file associated with this player.
|
||||
//If no file is found, then we will create a new one.
|
||||
if (passwordLegal)
|
||||
{
|
||||
//Iterate through the saved players directory.
|
||||
foreach (String filename in Directory.GetFiles(player.ActiveGame.DataPaths.Players))
|
||||
{
|
||||
if (Path.GetFileNameWithoutExtension(filename).ToLower() == playerName.ToLower())
|
||||
{
|
||||
//We found a file that matched the supplied user name. We set savedFile to the filename
|
||||
//found so that we can later varify the password before loading.
|
||||
savedFile = filename;
|
||||
playerFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Load the player from the saved file, if the password is legal. Once loaded
|
||||
//we need to look for any other player that might be logged in with this account. If found,
|
||||
//disconnect them from the server. Multiple log-ins of the same account is not permitted.
|
||||
if (playerFound)
|
||||
{
|
||||
//Load the player from file using a temporary character reference.
|
||||
//If we load the real player now, he will get disconnected when we check to see
|
||||
//if any player exists on the server already with this name.
|
||||
BaseCharacter p = new BaseCharacter(player.ActiveGame);
|
||||
p.Load(savedFile);
|
||||
|
||||
//Varify their password. If their password is matching the one on file, and the
|
||||
//current Active Game is a multiplayer game, then scan for other other currently
|
||||
//logged in with this account.
|
||||
if ((p.VarifyPassword(playerPwrd)) && (p.ActiveGame.IsMultiplayer))
|
||||
{
|
||||
for (Int32 i = 0; i <= player.ActiveGame.GetPlayerCollection().Length - 1; i++)
|
||||
{
|
||||
//Check if the current player in the iteration has a matching name as the player that
|
||||
//just logged in with his credentials.
|
||||
if (player.ActiveGame.GetPlayerCollection()[i].Name.ToLower() == p.Name.ToLower())
|
||||
{
|
||||
//If we found a match then we need to disconnect the
|
||||
//previously logged in player from the server.
|
||||
player.ActiveGame.GetPlayerCollection()[i].Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
//Now that we have no duplicate connections, load the real player.
|
||||
//no need to re-varify password as we have already done this above.
|
||||
player.Load(savedFile);
|
||||
|
||||
//If this is a single player game then we need to assign the player to the game collection.
|
||||
//Multiplayer games have this handled by the server automatically.
|
||||
if (!player.ActiveGame.IsMultiplayer)
|
||||
player.ActiveGame.GetPlayerCollection()[0] = player;
|
||||
|
||||
player.Send("Welcome back " + player.Name + "!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!p.VarifyPassword(playerPwrd))
|
||||
{
|
||||
player.Send("Invalid password!");
|
||||
passwordLegal = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Create(playerName, playerPwrd);
|
||||
player.Send("Welcome " + playerName + "!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Look to see if there are players in the Room, if there are then we need to let
|
||||
//other players know that the user walked/logged in.
|
||||
if (player.ActiveGame.IsMultiplayer)
|
||||
{
|
||||
for (Int32 i = 0; i != player.ActiveGame.GetPlayerCollection().Length; i++)
|
||||
{
|
||||
//Check if the current player in the iteration is the currently logging in player
|
||||
//or a un-used player slot. If it is we will skip them as the logging in player
|
||||
//doesn't need to be told that he has just logged in, and un-used players slots
|
||||
//in the collection array does not need to have anything broadcasted to them.
|
||||
if (player.ActiveGame.GetPlayerCollection()[i].Name == player.Name)
|
||||
continue;
|
||||
else if (player.ActiveGame.GetPlayerCollection()[i].Name == "New BaseCharacter")
|
||||
continue;
|
||||
|
||||
//If the current player in the iteration is within the same location as the player logging in
|
||||
//we can broadcast to them that the newly logged in player has entered the same Room.
|
||||
if (player.ActiveGame.GetPlayerCollection()[i].CurrentWorldLocation == player.CurrentWorldLocation)
|
||||
{
|
||||
player.ActiveGame.GetPlayerCollection()[i].Send(player.Name + " arrived.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/// <summary>
|
||||
/// The Look command is used to print the contents of the players current Room to the screen.
|
||||
/// The Room.Description property is printed to the players screen if it contains content.
|
||||
/// If the Room.DetailedDescription collection property contains content, it will be printed to the screen
|
||||
/// after the Room.Description property is printed (provided Room.Description is not empty.)
|
||||
/// </summary>
|
||||
public class CommandLook : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public CommandLook()
|
||||
{
|
||||
Help.Add("Prints a description of the current Room and the objects that reside within it.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
//If the players Room is null, then we need to let them know that they are
|
||||
//currently not residing within a Room. If this occures for some reason, the player will
|
||||
//need to be moved into an existing Room by an Admin.
|
||||
//TODO: Allow Admins to move Characters from one Room to another.
|
||||
if (player.CurrentRoom == null)
|
||||
{
|
||||
player.Send("You are not within any Room.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if the players current Room has a blank Description. If not, we print it for the player to read.
|
||||
if (!String.IsNullOrEmpty(player.CurrentRoom.Description))
|
||||
player.Send(player.CurrentRoom.Description);
|
||||
|
||||
//Check if the players current Room has a detailed description.
|
||||
//If the collection contains content, it will loop through each entry and print it to the screen as a new line.
|
||||
if (player.CurrentRoom.DetailedDescription.Count != 0)
|
||||
{
|
||||
foreach (String entry in player.CurrentRoom.DetailedDescription)
|
||||
player.Send(entry);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/// <summary>
|
||||
/// The Save command will save the current player to a hard-disk file.
|
||||
/// </summary>
|
||||
public class CommandSave : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public CommandSave()
|
||||
{
|
||||
Help.Add("Saves your character immediately.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
//Save the player to the hard-disk.
|
||||
player.Save();
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/// <summary>
|
||||
/// The Say command provides the player with the ability to chat with other players within the game world.
|
||||
/// Players using the Say command can only talk to players that are currently within the same Room.
|
||||
/// </summary>
|
||||
public class CommandSay : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public CommandSay()
|
||||
{
|
||||
Help.Add("Allows you to Chat with with players around you.");
|
||||
Help.Add("Note that you can only chat with players that reside within the same Room as yourself.");
|
||||
Help.Add("Usage: Say Hello everyone!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
//Check if the user only said 'Say ' or 'Say' with no message content.
|
||||
if (command.Length <= 4)
|
||||
{
|
||||
//If no message content, print the help for the command to the player.
|
||||
CommandHelp help = new CommandHelp();
|
||||
help.Execute("Help Say", player);
|
||||
return; //nothing to say, don't say anything at all.
|
||||
}
|
||||
|
||||
//Get the message out of the command String.
|
||||
String message = command.Substring("Say ".Length);
|
||||
|
||||
//Query the game world and find what players are within the same location as the chatting player.
|
||||
var playerQuery =
|
||||
from p in player.ActiveGame.GetPlayerCollection()
|
||||
where p.CurrentWorldLocation == player.CurrentWorldLocation
|
||||
select p;
|
||||
|
||||
//Send the message to each player found within our player query.
|
||||
foreach (var p in playerQuery)
|
||||
p.Send(player.Name + " says: " + message);
|
||||
|
||||
//Print the same message but in a alternate format to the player that sent the message originally.
|
||||
player.Send("You say: " + message);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
/// <summary>
|
||||
/// The Walk command allows players to walk from Room to Room, traversing the Mud world.
|
||||
/// The command supports all of the available travel directions found within the
|
||||
/// MudEngine.GameObjects.Environment.AvailableTravelDirections enum.
|
||||
/// </summary>
|
||||
public class CommandWalk : BaseCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public CommandWalk()
|
||||
{
|
||||
Help.Add("Allows you to traverse through the world.");
|
||||
Help.Add("You may walk in any direction available within the current Room.");
|
||||
Help.Add("You may use the Look command to see a description of the current Room, and decide where you would like to walk.");
|
||||
Help.Add("Usage: Walk 'Direction' where Direction may equal one of the following:");
|
||||
|
||||
//We will construct a String that contains all of the available travel directions for the player.
|
||||
StringBuilder directions = new StringBuilder();
|
||||
|
||||
//Store a array of existing values within the AvailableTravelDirection enum.
|
||||
//These values are the legal travel directions that are supported by the game.
|
||||
Array values = Enum.GetValues(typeof(AvailableTravelDirections));
|
||||
|
||||
//Loop through the array, printing each travel direction we found in the enum array collection
|
||||
//to the screen for the user to see and select from.
|
||||
foreach (Int32 v in values)
|
||||
{
|
||||
//Since enum values are not strings, we can't simply assign a String value to the enum.
|
||||
//The enum needs to be queried to retrieve a value that matches that of 'v' and convert it to a String
|
||||
String displayName = Enum.GetName(typeof(AvailableTravelDirections), v);
|
||||
|
||||
//Add the current travel direction to our String for later use.
|
||||
directions.Append(displayName + ", ");
|
||||
}
|
||||
|
||||
//Place the newly constructed String with all of our available travel directions into the help collection.
|
||||
Help.Add(directions.ToString());
|
||||
|
||||
//Note that you could have placed each direction in manually "Help.Add("West")" etc. however this would
|
||||
//prove an issue with maintanence if directions were changed within the engine, new ones added or old ones removed.
|
||||
//Getting the travel directions the way we did always ensures that the help command will always show every
|
||||
//available travel direction contained within the engine, regardless if we add or remove directions internally or not.
|
||||
//It's a dynamic way of displaying our directions.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the class.
|
||||
/// </summary>
|
||||
public override void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
//Since the walk command requires a second word (ex: walk north)
|
||||
//we split the words into an array so they are seperate.
|
||||
String[] words = command.Split(' ');
|
||||
List<String> directions = new List<String>();
|
||||
|
||||
//We only 1 word was found within the array, then the user failed to provide a second word
|
||||
//which would be the travel direction they are wanting to go.
|
||||
if (words.Length == 1)
|
||||
{
|
||||
player.Send("No direction provided!");
|
||||
return;
|
||||
}
|
||||
//The user supplied a traveling direction for us, lets ensure it's a valid one.
|
||||
else
|
||||
{
|
||||
//iterate through each door within the current Room and see if we have a Door that
|
||||
//contains a exit in the direction that the player supplied.
|
||||
foreach (Door door in player.CurrentRoom.Doorways)
|
||||
{
|
||||
//See if the current door has the same travel direction value as that of the users entered direction.
|
||||
if (door.TravelDirection == TravelDirections.GetTravelDirectionValue(words[1]))
|
||||
{
|
||||
//The matches the users direction, so move the player in the direction supplied by the user.
|
||||
player.Move(door.TravelDirection);
|
||||
|
||||
//BAD - Don't invoke commands directly by the player as it causes issues for them client-side.
|
||||
//Always invoke the command internally, passing a reference to the player instead.
|
||||
//player.ExecuteCommand("Look");
|
||||
|
||||
//Use the Look command to print the contents of the new Room to the Player.
|
||||
//Good - Correct way of invoking commands automatically for the player.
|
||||
//The command will be executed for which ever player is passed as a reference.
|
||||
IGameCommand look = CommandEngine.GetCommand("CommandLook");
|
||||
if (look != null)
|
||||
look.Execute("look", player);
|
||||
|
||||
//If the current Active Game has Auto-Save enabled, we will save the player.
|
||||
if (player.ActiveGame.AutoSave)
|
||||
player.Save();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If the user entered a travel direction that does not exist within the current Room, they will be told so
|
||||
//and no moving will be performed.
|
||||
player.Send("Unable to travel in that direction.");
|
||||
}
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
/// <summary>
|
||||
/// The WorldCalifornia script is used to construct the Game world.
|
||||
/// </summary>
|
||||
public class WorldCalifornia
|
||||
{
|
||||
//Our current Active Game. Allows us to add content to the game.
|
||||
private Game _Game;
|
||||
|
||||
/// <summary>
|
||||
/// Our Constructor.
|
||||
/// </summary>
|
||||
/// <param name="game"></param>
|
||||
public WorldCalifornia(Game game)
|
||||
{
|
||||
//Set _Game to reference the current Active Game.
|
||||
_Game = game;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the world the player will interact with.
|
||||
/// The WorldCalifornia is used soley for creating the California Realm.
|
||||
/// It is recommended that the creation of other Realms be done in their own respective classes mimicking this one.
|
||||
/// </summary>
|
||||
public void Create()
|
||||
{
|
||||
//Get a new Instance of a Realm.
|
||||
Realm myRealm = new Realm(_Game);
|
||||
|
||||
//Setup the Realm properties.
|
||||
myRealm.Name = "California";
|
||||
myRealm.Description = "The Beaches of California are relaxing and fun to be at.";
|
||||
|
||||
//Setting the Realms IsInitialRealm to true will let the current Active Game know where to place newly created players.
|
||||
myRealm.IsInitialRealm = true;
|
||||
|
||||
//Add the Realm to the current Active Game World.
|
||||
_Game.World.AddRealm(myRealm);
|
||||
|
||||
//Get a new Instance of a Zone.
|
||||
Zone myZone = new Zone(_Game);
|
||||
|
||||
//Setup the Zone properties
|
||||
myZone.Name = "San Diego";
|
||||
myZone.Description = "San Diego has many attractions, including Sea World!";
|
||||
|
||||
//Place this Zone within our previously created Realm
|
||||
myZone.Realm = myRealm.Filename;
|
||||
|
||||
//Setting the Zones IsInitialZone to true will let the current Active Game know where to place newly created players.
|
||||
myZone.IsInitialZone = true;
|
||||
|
||||
//Add the Zone to the current Active Game World
|
||||
myRealm.AddZone(myZone);
|
||||
|
||||
//Get a new Instance of a Room.
|
||||
Room myRoom = new Room(_Game);
|
||||
|
||||
//Setup the Room properties
|
||||
myRoom.Name = "Hotel Room B33";
|
||||
myRoom.DetailedDescription.Add("Your Hotel Room is pretty clean, it is small but not to far off from the beach so you can't complain.");
|
||||
myRoom.DetailedDescription.Add("You can exit your Hotel Room by walking West");
|
||||
|
||||
//Setting the Rooms IsInitialRoom to true will let the current Active Game know where to place newly created players.
|
||||
myRoom.IsInitialRoom = true;
|
||||
|
||||
//Add the Room to the previously created Zone.
|
||||
//TODO: The engine needs to provide World.AddObject() support to Rooms, so that Rooms may be added in the same
|
||||
//manor as Realms and Zones.
|
||||
myZone.AddRoom(myRoom);
|
||||
|
||||
//Get a new Instance of a Room
|
||||
Room myHallway = new Room(_Game);
|
||||
|
||||
//Setup the Room properties
|
||||
myHallway.Name = "Hotel Hallway";
|
||||
myHallway.DetailedDescription.Add("The Hotel Hallway is fairly narrow, but there is plenty of room for people to traverse through it.");
|
||||
myHallway.DetailedDescription.Add("Your Hotel Room B33 is to the East.");
|
||||
myHallway.DetailedDescription.Add("Hotel Room B34 is to your West.");
|
||||
|
||||
//Since more than one 'Hotel hallway' may exist, we will differentiate them by setting a custom filename.
|
||||
//Note that assigning a new Filename must be done AFTER assigning the objects Name property a value.
|
||||
//Each time a objects Name property is assigned a value, it automatically generates a filename.
|
||||
//If a Filename is assigned prior to assigning the Name property, your previous Filename will be over-wrote.
|
||||
myHallway.Filename = myHallway.Name + "1.Room";
|
||||
|
||||
//Add the Room to the previously created Zone.
|
||||
myZone.AddRoom(myHallway);
|
||||
|
||||
//Link the two previously created Rooms together.
|
||||
//Player must walk 'West' to exit myRoom and enter myHallway.
|
||||
//Zone Linking automatically places a reverse doorway in the myHallway Room,
|
||||
//allowing players to walk 'East' to exit myHallway and enter myRoom once again.
|
||||
myZone.LinkRooms(AvailableTravelDirections.West, myHallway, myRoom);
|
||||
|
||||
//Get a new Instance of a Room
|
||||
Room nextRoom = new Room(_Game);
|
||||
|
||||
//Setup the Room properties
|
||||
nextRoom.Name = "Hotel Room B34";
|
||||
nextRoom.DetailedDescription.Add("This Hotel Room is pretty dirty, they must not have cleaned it yet.");
|
||||
nextRoom.DetailedDescription.Add("You can exit this room by walking East");
|
||||
|
||||
//Add the Room to the previously created Zone
|
||||
myZone.AddRoom(nextRoom);
|
||||
|
||||
//Link the new Room to the previously created myHallway.
|
||||
//Players must walk West out of the hallway to enter this room.
|
||||
myZone.LinkRooms(AvailableTravelDirections.East, myHallway, nextRoom);
|
||||
|
||||
/* Current Room layout is as shown.
|
||||
*
|
||||
* Room B33 -> Hallway <- Room B34
|
||||
*
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
ScriptPath=Scripts
|
||||
ScriptExtension=.cs
|
Loading…
Add table
Add a link
Reference in a new issue