MudEngine:
- Rooms can now be linked automatically via the new Zone.LinkRooms method. Room linking can no longer be done manually as the Doorways property is now read-only. - Door.Description has been removed. Doorway description will need to be included in Room.Description or Room.DetailedDescription properties. - Added DetailedDescription to make creating multi-line descriptions easier. Not supported by the Look command yet. - Game.IsRunning is now read-only. The Game will manage this property on its own. - BaseCharacter.ExecuteCommand now will always return a string. Simplifying the game loop for users as they no longer need to check what Type was returned by the command. - Doors now contain a DepartureRoom and a ArrivalRoom property allowing for easy access to Rooms that are linked together. - Fixed a bug where Game, Realms and Zones always assigned IsInitial to Realms, Zones and Rooms when added to the collections. Collection would contain multiple IsInitial objects. - Removed Room.InstalledDoorways property as that was used only by the old Designer - Removed Room.Load() as that implementation of it is obsolete. MudGame: - Revised Zeroth to build it's Zone and Rooms using the new Zone.LinkRooms function. - Greatly revised Program.cs and the Game loop to take advantage of many of the automations provided by the Engine now.
This commit is contained in:
parent
7e3cf1eb0c
commit
e145d57682
11 changed files with 138 additions and 184 deletions
|
@ -4,26 +4,34 @@ using System.Linq;
|
|||
using System.Text;
|
||||
|
||||
using MudEngine.GameManagement;
|
||||
using MudEngine.GameObjects;
|
||||
using MudEngine.GameObjects.Environment;
|
||||
|
||||
namespace MUDGame.Environments
|
||||
{
|
||||
class Zeroth
|
||||
internal class Zeroth
|
||||
{
|
||||
Game game;
|
||||
Realm realm;
|
||||
|
||||
internal Zeroth(Game game)
|
||||
{
|
||||
this.game = game;
|
||||
realm = new Realm();
|
||||
}
|
||||
|
||||
internal Realm BuildZeroth()
|
||||
internal void BuildZeroth()
|
||||
{
|
||||
Realm realm = new Realm();
|
||||
realm.Name = "Zeroth";
|
||||
realm.Description = "The land of " + realm.Name + " is fully of large forests and dangerous creatures.";
|
||||
realm.IsInitialRealm = true;
|
||||
|
||||
//Build Rooms.
|
||||
BuildHome();
|
||||
}
|
||||
|
||||
private void BuildHome()
|
||||
{
|
||||
//Build Zones
|
||||
Zone zone = new Zone();
|
||||
zone.Name = "Home";
|
||||
|
@ -32,19 +40,6 @@ namespace MUDGame.Environments
|
|||
zone.StatDrain = false;
|
||||
zone.IsInitialZone = true;
|
||||
|
||||
//Build Rooms.
|
||||
BuildHome(zone, realm);
|
||||
|
||||
zone.Realm = realm.Name;
|
||||
|
||||
realm.AddZone(zone);
|
||||
game.AddRealm(realm);
|
||||
|
||||
return realm;
|
||||
}
|
||||
|
||||
private void BuildHome(Zone zone, Realm realm)
|
||||
{
|
||||
Room bedroom = new Room();
|
||||
bedroom.Name = "Bedroom";
|
||||
bedroom.Description = "This is your bedroom, it's small but comfortable. You have a bed, a book shelf and a rug on the floor.";
|
||||
|
@ -58,21 +53,12 @@ namespace MUDGame.Environments
|
|||
closet.Zone = zone.Name;
|
||||
closet.Realm = realm.Name;
|
||||
|
||||
Door door = new Door();
|
||||
door.TravelDirection = MudEngine.GameObjects.AvailableTravelDirections.West;
|
||||
door.ConnectedRoom = "Closet";
|
||||
door.Description = "To the West is your Closet.";
|
||||
bedroom.Doorways.Add(door);
|
||||
zone.LinkRooms(AvailableTravelDirections.West, closet, bedroom);
|
||||
|
||||
door = new Door();
|
||||
door.TravelDirection = MudEngine.GameObjects.AvailableTravelDirections.East;
|
||||
door.ConnectedRoom = "Bedroom";
|
||||
door.Description = "To the East is your Bedroom.";
|
||||
closet.Doorways.Add(door);
|
||||
zone.Realm = realm.Name;
|
||||
|
||||
//Todo: Should work once MUDEngine supports Types
|
||||
zone.AddRoom(bedroom);
|
||||
zone.AddRoom(closet);
|
||||
realm.AddZone(zone);
|
||||
game.AddRealm(realm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,24 +6,24 @@ using System.Net;
|
|||
using System.Net.Sockets;
|
||||
|
||||
using MUDGame.Environments;
|
||||
using MudEngine.GameManagement;
|
||||
using MudEngine.GameObjects;
|
||||
using MudEngine.GameObjects.Characters;
|
||||
using MudEngine.GameObjects.Environment;
|
||||
using MudEngine.FileSystem;
|
||||
|
||||
namespace MUDGame
|
||||
{
|
||||
class Program
|
||||
{
|
||||
//Setup our Fields
|
||||
static MudEngine.GameManagement.Game game;
|
||||
static MudEngine.GameManagement.CommandEngine commands;
|
||||
static MudEngine.GameObjects.Characters.BaseCharacter player;
|
||||
|
||||
static List<MudEngine.GameObjects.Environment.Realm> realmCollection;
|
||||
static Game game;
|
||||
static BaseCharacter player;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//Initialize them
|
||||
game = new MudEngine.GameManagement.Game();
|
||||
commands = new MudEngine.GameManagement.CommandEngine();
|
||||
realmCollection = new List<MudEngine.GameObjects.Environment.Realm>();
|
||||
game = new Game();
|
||||
|
||||
//Setup the game
|
||||
game.AutoSave = true;
|
||||
|
@ -34,8 +34,8 @@ namespace MUDGame
|
|||
game.GameTitle = "Test Mud Project";
|
||||
game.HideRoomNames = false;
|
||||
game.PreCacheObjects = true;
|
||||
game.ProjectPath = MudEngine.FileSystem.FileManager.GetDataPath(MudEngine.FileSystem.SaveDataTypes.Root);
|
||||
game.TimeOfDay = MudEngine.GameManagement.Game.TimeOfDayOptions.Transition;
|
||||
game.ProjectPath = FileManager.GetDataPath(SaveDataTypes.Root);
|
||||
game.TimeOfDay = Game.TimeOfDayOptions.Transition;
|
||||
game.TimeOfDayTransition = 30;
|
||||
game.Version = "0.1";
|
||||
game.Website = "http://MudDesigner.Codeplex.com";
|
||||
|
@ -46,19 +46,16 @@ namespace MUDGame
|
|||
//Create the world
|
||||
BuildRealms();
|
||||
|
||||
//Load all of the available commands from the engine
|
||||
MudEngine.GameManagement.CommandEngine.LoadAllCommands();
|
||||
|
||||
//Player must be instanced AFTER BuildRealms as it needs Game.InitialRealm.InitialZone.InitialRoom
|
||||
//property so that it can set it's starting room correctly.
|
||||
player = new MudEngine.GameObjects.Characters.BaseCharacter(game);
|
||||
player = new BaseCharacter(game);
|
||||
|
||||
// Start the game & server
|
||||
if (!game.Start())
|
||||
// Start the game & server.
|
||||
game.Start();
|
||||
|
||||
if (!game.IsRunning)
|
||||
Console.WriteLine("Error starting game!\nReview Log file for details.");
|
||||
|
||||
game.IsRunning = true;
|
||||
|
||||
game.PlayerCollection.Add(player);
|
||||
|
||||
//Send game info to player
|
||||
|
@ -72,29 +69,15 @@ namespace MUDGame
|
|||
Console.WriteLine("Available Commands are\n Look\n Exit\n Walk 'direction' where direction = north/south/east/west/up/down\n");
|
||||
|
||||
//Invoke the Look command so the player knows whats around him/her
|
||||
Console.WriteLine(player.ExecuteCommand("Look").Result[0]);
|
||||
Console.WriteLine(player.ExecuteCommand("Look"));
|
||||
|
||||
while (game.IsRunning)
|
||||
{
|
||||
Console.Write("Command: ");
|
||||
string command = Console.ReadLine();
|
||||
|
||||
//TODO: Does the CommandResult really need to return an array of Objects?
|
||||
//All object management should be dealt with by the Game and Player so this should just be an array of strings.
|
||||
Object[] result = player.ExecuteCommand(command).Result;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
//Search through each object in the array returned to us from the command execution and print the strings.
|
||||
foreach (object o in result)
|
||||
{
|
||||
if (o is string)
|
||||
Console.WriteLine(o.ToString());
|
||||
}
|
||||
}
|
||||
Console.WriteLine(player.ExecuteCommand(Console.ReadLine()));
|
||||
}
|
||||
|
||||
game.End();
|
||||
// - Exit command handles this now - game.Shutdown();
|
||||
Console.WriteLine("Press Enter to exit.");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace MudEngine.Commands
|
|||
|
||||
public CommandResults Execute(string command, BaseCharacter player)
|
||||
{
|
||||
player.Game.IsRunning = false;
|
||||
player.Game.Shutdown();
|
||||
|
||||
return new CommandResults();
|
||||
}
|
||||
|
|
|
@ -27,13 +27,6 @@ namespace MudEngine.Commands
|
|||
}
|
||||
|
||||
desc.AppendLine(player.CurrentRoom.Description);
|
||||
foreach (Door door in player.CurrentRoom.Doorways)
|
||||
{
|
||||
if (door.TravelDirection != MudEngine.GameObjects.AvailableTravelDirections.Down && door.TravelDirection != MudEngine.GameObjects.AvailableTravelDirections.Up)
|
||||
{
|
||||
desc.AppendLine(door.Description);
|
||||
}
|
||||
}
|
||||
|
||||
return new CommandResults(desc.ToString());
|
||||
}
|
||||
|
|
|
@ -34,11 +34,7 @@ namespace MudEngine.GameManagement
|
|||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public bool IsRunning
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public bool IsRunning { get; internal set; }
|
||||
|
||||
[Category("Company Settings")]
|
||||
[Description("The name of the Company or Author building the game.")]
|
||||
|
@ -208,6 +204,9 @@ namespace MudEngine.GameManagement
|
|||
}
|
||||
}
|
||||
|
||||
//Load all of the engine commands
|
||||
CommandEngine.LoadAllCommands();
|
||||
|
||||
//See if we have an Initial Realm set
|
||||
foreach (Realm r in RealmCollection)
|
||||
{
|
||||
|
@ -227,14 +226,18 @@ namespace MudEngine.GameManagement
|
|||
//Start the Telnet server
|
||||
this.StartServer();
|
||||
|
||||
IsRunning = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void End()
|
||||
public void Shutdown()
|
||||
{
|
||||
//Place ending code here for game shut down.
|
||||
//TODO: Save content on shutdown.
|
||||
Server.EndServer();
|
||||
|
||||
IsRunning = false;
|
||||
}
|
||||
|
||||
public void Save(string filename)
|
||||
|
@ -272,9 +275,11 @@ namespace MudEngine.GameManagement
|
|||
}
|
||||
}
|
||||
|
||||
if (realm.IsInitialRealm)
|
||||
InitialRealm = realm;
|
||||
|
||||
//TODO: Check for duplicate Realms.
|
||||
RealmCollection.Add(realm);
|
||||
InitialRealm = realm;
|
||||
}
|
||||
|
||||
public Realm GetRealm(string realmName)
|
||||
|
|
|
@ -39,6 +39,11 @@ namespace MudEngine.GameObjects
|
|||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A detailed description that treats each entry as a seperete line when outputted to the player
|
||||
/// </summary>
|
||||
public List<string> DetailedDescription { get; set; }
|
||||
|
||||
[Category("Object Setup")]
|
||||
[Description("The object script that can manipulate the object during the games life.")]
|
||||
//[EditorAttribute(typeof(UIScriptEditor), typeof(System.Drawing.Design.UITypeEditor))]
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace MudEngine.GameObjects.Characters
|
|||
}
|
||||
|
||||
//We have a doorway, lets move to the next room.
|
||||
CurrentRoom = Game.GetRealm(CurrentRoom.Realm).GetZone(CurrentRoom.Zone).GetRoom(CurrentRoom.GetDoor(travelDirection).ConnectedRoom);
|
||||
CurrentRoom = CurrentRoom.GetDoor(travelDirection).ArrivalRoom;
|
||||
|
||||
OnTravel(travelDirection);
|
||||
|
||||
|
@ -70,11 +70,23 @@ namespace MudEngine.GameObjects.Characters
|
|||
//TODO: Check the Room/Zone/Realm to see if anything needs to occure during travel.
|
||||
}
|
||||
|
||||
public CommandResults ExecuteCommand(string command)
|
||||
public String ExecuteCommand(string command)
|
||||
{
|
||||
//TODO: Character class can handle a lot of the command management here, checking various things prior to sending
|
||||
//the command off to the command engine for execution.
|
||||
return CommandEngine.ExecuteCommand(command, this);
|
||||
CommandResults result = CommandEngine.ExecuteCommand(command, this);
|
||||
|
||||
|
||||
if (result.Result is string[])
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (string item in result.Result)
|
||||
sb.AppendLine(item);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public void Initialize(ref MudEngine.Networking.ClientSocket rcs)
|
||||
|
|
|
@ -42,11 +42,15 @@ namespace MudEngine.GameObjects.Environment
|
|||
[Category("Door Settings")]
|
||||
public AvailableTravelDirections TravelDirection { get; set; }
|
||||
|
||||
public string ConnectedRoom { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or Sets the Room that the player will be arriving.
|
||||
/// </summary>
|
||||
public Room ArrivalRoom { get; set; }
|
||||
|
||||
[Category("Environment Information")]
|
||||
[Description("The description displayed to the user when a 'Look' command is used.")]
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or Sets the Room that the user is leaving.
|
||||
/// </summary>
|
||||
public Room DepartureRoom { get; set; }
|
||||
|
||||
public Door()
|
||||
{
|
||||
|
@ -54,12 +58,5 @@ namespace MudEngine.GameObjects.Environment
|
|||
IsLocked = false;
|
||||
RequiredKey = new BaseItem();
|
||||
}
|
||||
|
||||
public Door(AvailableTravelDirections travelDirection, string connectedRoom)
|
||||
: this()
|
||||
{
|
||||
ConnectedRoom = connectedRoom;
|
||||
TravelDirection = travelDirection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,11 @@ namespace MudEngine.GameObjects.Environment
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (zone.IsInitialZone)
|
||||
InitialZone = zone;
|
||||
|
||||
//TODO: Check fo duplicates
|
||||
ZoneCollection.Add(zone);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,46 +10,19 @@ using System.IO;
|
|||
|
||||
//MUD Engine
|
||||
using MudEngine.FileSystem;
|
||||
using MudEngine.GameObjects.Items;
|
||||
using MudEngine.GameManagement;
|
||||
|
||||
namespace MudEngine.GameObjects.Environment
|
||||
{
|
||||
[XmlInclude(typeof(Door))]
|
||||
public class Room : BaseObject
|
||||
{
|
||||
[Category("Environment Information")]
|
||||
[Description("Shows what rooms are currently created and linked to within this Room.")]
|
||||
[ReadOnly(true)]
|
||||
public string InstalledDoorways
|
||||
{
|
||||
get
|
||||
{
|
||||
string installed = "";
|
||||
if (this.Doorways.Count != 0)
|
||||
{
|
||||
foreach (Door d in Doorways)
|
||||
{
|
||||
installed += d.TravelDirection.ToString() + ",";
|
||||
}
|
||||
if (Doorways.Count >= 2)
|
||||
{
|
||||
installed = installed.Substring(0, installed.Length - 1);
|
||||
}
|
||||
return installed;
|
||||
}
|
||||
else
|
||||
return "None Installed.";
|
||||
}
|
||||
}
|
||||
|
||||
[Category("Environment Information")]
|
||||
[Description("Allows for linking of Rooms together via Doorways")]
|
||||
//[EditorAttribute(typeof(UIDoorwayEditor), typeof(UITypeEditor))]
|
||||
[RefreshProperties(RefreshProperties.All)]
|
||||
public List<Door> Doorways
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public List<Door> Doorways { get; internal set; }
|
||||
|
||||
[ReadOnly(true)]
|
||||
[Description("This is the Zone that the Room is currently assigned to.")]
|
||||
|
@ -116,6 +89,11 @@ namespace MudEngine.GameObjects.Environment
|
|||
IsSafe = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if a doorway in the travelDirection exists.
|
||||
/// </summary>
|
||||
/// <param name="travelDirection"></param>
|
||||
/// <returns></returns>
|
||||
public bool DoorwayExist(AvailableTravelDirections travelDirection)
|
||||
{
|
||||
foreach (Door door in Doorways)
|
||||
|
@ -127,6 +105,11 @@ namespace MudEngine.GameObjects.Environment
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets reference to the Rooms door connected in the supplied travelDirection
|
||||
/// </summary>
|
||||
/// <param name="travelDirection"></param>
|
||||
/// <returns></returns>
|
||||
public Door GetDoor(AvailableTravelDirections travelDirection)
|
||||
{
|
||||
foreach (Door door in this.Doorways)
|
||||
|
@ -136,63 +119,5 @@ namespace MudEngine.GameObjects.Environment
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load a Room that exists within the same Zone as the current Room
|
||||
/// </summary>
|
||||
/// <param name="roomName"></param>
|
||||
/// <returns></returns>
|
||||
public override object Load(string roomName)
|
||||
{
|
||||
//Correct the filename incase it doesnt contain a file extension
|
||||
if (!roomName.ToLower().EndsWith(this.GetType().Name.ToLower()))
|
||||
roomName.Insert(roomName.Length, this.GetType().Name.ToLower());
|
||||
|
||||
//If the current room does not belong within a Realm, then load it from the
|
||||
//Zones root directory
|
||||
if (this.Realm != null || this.Realm != "No Realm Associated.")
|
||||
{
|
||||
return this.Load(roomName, this.Zone);
|
||||
}
|
||||
//This Zone is contained within a Realm so we have to load it from within the
|
||||
//Realm and not from within the Zones root directory
|
||||
else
|
||||
return this.Load(roomName, this.Zone, this.Realm);
|
||||
}
|
||||
|
||||
public object Load(string roomName, string zoneName)
|
||||
{
|
||||
string filename = "";
|
||||
if (!roomName.ToLower().EndsWith(".room"))
|
||||
roomName += ".room";
|
||||
|
||||
if (this.Realm != null && this.Realm != "No Realm Associated.")
|
||||
{
|
||||
return this.Load(roomName, zoneName, this.Realm);
|
||||
}
|
||||
else
|
||||
filename = FileManager.GetDataPath(SaveDataTypes.Zones);
|
||||
|
||||
filename = Path.Combine(filename, zoneName);
|
||||
filename = Path.Combine(filename, "Rooms");
|
||||
filename = Path.Combine(filename, roomName);
|
||||
|
||||
return base.Load(filename);
|
||||
}
|
||||
|
||||
public object Load(string roomName, string zoneName, string realmName)
|
||||
{
|
||||
if (!roomName.ToLower().EndsWith(".room"))
|
||||
roomName += ".room";
|
||||
|
||||
string filename = FileManager.GetDataPath(realmName, zoneName);
|
||||
filename = Path.Combine(filename, "Rooms");
|
||||
filename = Path.Combine(filename, roomName);
|
||||
|
||||
if (realmName == null || realmName == "No Realm Associated.")
|
||||
return this.Load(roomName, zoneName);
|
||||
|
||||
return base.Load(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ using System.Xml.Serialization;
|
|||
//MUD Engine
|
||||
using MudEngine.FileSystem;
|
||||
using MudEngine.GameObjects;
|
||||
using MudEngine.GameObjects.Items;
|
||||
|
||||
namespace MudEngine.GameObjects.Environment
|
||||
{
|
||||
|
@ -116,9 +117,52 @@ namespace MudEngine.GameObjects.Environment
|
|||
}
|
||||
}
|
||||
|
||||
RoomCollection.Add(room);
|
||||
if (room.IsInitialRoom)
|
||||
InitialRoom = room;
|
||||
|
||||
//TODO: Check for duplicate Rooms.
|
||||
RoomCollection.Add(room);
|
||||
}
|
||||
|
||||
public void LinkRooms(AvailableTravelDirections departureDirection, Room arrivalRoom, Room departureRoom)
|
||||
{
|
||||
LinkRooms(departureDirection, arrivalRoom, departureRoom, 0);
|
||||
}
|
||||
|
||||
public void LinkRooms(AvailableTravelDirections departureDirection, Room arrivalRoom, Room departureRoom, Int32 requiredLevel)
|
||||
{
|
||||
LinkRooms(departureDirection, arrivalRoom, departureRoom, requiredLevel, false, null);
|
||||
}
|
||||
|
||||
public void LinkRooms(AvailableTravelDirections departureDirection, Room departureRoom, Room arrivalRoom, Int32 requiredLevel, Boolean isLocked, BaseItem requiredKey)
|
||||
{
|
||||
Door door = new Door();
|
||||
door.ArrivalRoom = arrivalRoom;
|
||||
door.DepartureRoom = departureRoom;
|
||||
|
||||
if (isLocked)
|
||||
{
|
||||
door.IsLocked = isLocked;
|
||||
door.RequiredKey = requiredKey;
|
||||
}
|
||||
|
||||
door.TravelDirection = departureDirection;
|
||||
|
||||
departureRoom.Doorways.Add(door);
|
||||
|
||||
//Now we set up the door for the opposite room.
|
||||
door = new Door();
|
||||
|
||||
door.DepartureRoom = arrivalRoom;
|
||||
door.ArrivalRoom = departureRoom;
|
||||
if (isLocked)
|
||||
{
|
||||
door.IsLocked = isLocked;
|
||||
door.RequiredKey = requiredKey;
|
||||
}
|
||||
|
||||
door.TravelDirection = TravelDirections.GetReverseDirection(departureDirection);
|
||||
arrivalRoom.Doorways.Add(door);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue