- Changed the IGameCommand Interface constructor for the Execute method. - Updated all of the game commands to make use of the new Execute Method Constructor requirements set by the updated interface. - Look command now returns a description of the players current Room. - Walk command now supports moving players from one Room to another. Use 'Walk Direction' where Direction equals the direction you want to travel (Example: 'Walk North") - TravelDirections.GetTravelDirectionValue now checks the supplied direction value in a case-insensitive manor. - Add a new CommandEngine that handles the commands inputed from the user. - Modified CommandResult to return an array of objects rather than a single object. Runtime: - Now scans the supplied collection of objects returned to the runtime after executing a game command, and adjusts the runtime components as needed, including printing information to the console. - Now displays various warnings during startup to let the user know if certain content hasn't been set within the ProjectInformation yet. - Now executes the 'Look' command on startup to display the users current location. - Fully supports the 'Look' and 'Walk' commands.
67 lines
2.5 KiB
C#
67 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
|
|
using MudDesigner.MudEngine.Interfaces;
|
|
using MudDesigner.MudEngine.Characters;
|
|
using MudDesigner.MudEngine.GameManagement;
|
|
using MudDesigner.MudEngine.GameObjects.Environment;
|
|
using MudDesigner.MudEngine.GameObjects;
|
|
using MudDesigner.MudEngine.FileSystem;
|
|
|
|
namespace MudDesigner.MudEngine.GameCommands
|
|
{
|
|
public class CommandWalk : IGameCommand
|
|
{
|
|
public string Name { get; set; }
|
|
public bool Override { get; set; }
|
|
|
|
public CommandResults Execute(BaseCharacter player, ProjectInformation project, Room room, string command)
|
|
{
|
|
string[] words = command.Split(' ');
|
|
List<string> directions = new List<string>();
|
|
|
|
if (words.Length == 1)
|
|
return new CommandResults("No direction supplied");
|
|
else
|
|
{
|
|
foreach (Door door in room.Doorways)
|
|
{
|
|
AvailableTravelDirections direction = TravelDirections.GetTravelDirectionValue(words[1]);
|
|
|
|
if (door.TravelDirection == direction)
|
|
{
|
|
string zonePath = "";
|
|
string roomPath = "";
|
|
string roomFilename = "";
|
|
|
|
if (room.Realm == "No Realm Associated.")
|
|
{
|
|
zonePath = FileManager.GetDataPath(SaveDataTypes.Zones);
|
|
zonePath = Path.Combine(zonePath, room.Zone);
|
|
}
|
|
else
|
|
{
|
|
zonePath = FileManager.GetDataPath(room.Realm, room.Zone);
|
|
}
|
|
|
|
roomPath = Path.Combine(zonePath, "Rooms");
|
|
roomFilename = Path.Combine(roomPath, door.ConnectedRoom + ".room");
|
|
room = (Room)room.Load(roomFilename);
|
|
CommandResults cmd = CommandEngine.ExecuteCommand("Look", player, project, room, "Look");
|
|
string lookValue = "";
|
|
|
|
if (cmd.Result.Length != 0)
|
|
lookValue = cmd.Result[0].ToString();
|
|
|
|
return new CommandResults(new object[] { lookValue, room });
|
|
|
|
}
|
|
}
|
|
}
|
|
return new CommandResults("Unable to travel in that direction.");
|
|
}
|
|
}
|
|
}
|