Mud Designer:

- Removed from solution

Mud Engine:
 - Moved the CommandEngine, CommandResults and ICommand Interface out from the Commands namespace and into GameManagement since they manage the game commands.
 - Added CommandExit class to provide the ability to exit a game once running. This is fully implemented.
 - Realms, Zones and Rooms now have an IsInitial property for determining if this is an initial location for the Game.
 - Renamed GameSetup to Game.
 - Corrected GameObject being in the incorrect namespace.
 - Corrected the ScriptEngine not 
 - CommandEngine no longer needs a Name argument. Arguments changed from 5 to 4 due to this change.

Mud Game:
 - Added Example Game used for testing various MUDEngine features and testing constructability of games using the engine.
 - Currently only contains 1 Realm, 1 Zone and Two Rooms. Only working command is Exit.
This commit is contained in:
Scionwest_cp 2010-07-18 13:52:16 -07:00
parent 06266b7245
commit b8f6be12c0
16 changed files with 374 additions and 40 deletions

View file

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MudEngine.GameManagement;
using MudEngine.GameObjects.Environment;
namespace MUDGame.Environments
{
class Zeroth
{
internal Realm 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 Zones
Zone zone = new Zone();
zone.Name = "Home";
zone.Description = "Your home is small and does not contain many items, but it's still your home and someplace you can relax after your battles.";
zone.IsSafe = true;
zone.StatDrain = false;
zone.IsStartingZone = true;
//Build Rooms.
BuildHome(zone, realm);
zone.Realm = realm.Name;
//TODO: Remove this, as Zones and Rooms contain .IsStarting properties now.
zone.EntranceRoom = "Bedroom";
realm.Zones.Add(zone);
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.";
bedroom.Zone = zone.Name;
bedroom.Realm = realm.Name;
bedroom.IsStartingRoom = true;
Room closet = new Room();
closet.Name = "Closet";
closet.Description = "Your closet contains clothing and some shoes.";
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);
door = new Door();
door.TravelDirection = MudEngine.GameObjects.AvailableTravelDirections.East;
door.ConnectedRoom = "Bedroom";
door.Description = "To the East is your Bedroom.";
closet.Doorways.Add(door);
//Todo: Should work once MUDEngine supports Types
zone.Rooms.Add(bedroom);
zone.Rooms.Add(closet);
}
}
}

66
MUDGame/MUDGame.csproj Normal file
View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{048E755C-DD05-47EC-930E-F45146B66F7C}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MUDGame</RootNamespace>
<AssemblyName>MUDGame</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Environments\Zeroth.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MudEngine\MudEngine.csproj">
<Project>{498943A8-DF5A-4DB0-B506-0BFF44788657}</Project>
<Name>MudEngine</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

78
MUDGame/Program.cs Normal file
View file

@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MUDGame.Environments;
namespace MUDGame
{
class Program
{
//Setup our Fields
static MudEngine.GameManagement.Game game;
static MudEngine.GameManagement.CommandEngine commands;
static MudEngine.GameObjects.Characters.Controlled.PlayerBasic player;
static List<MudEngine.GameObjects.Environment.Realm> realmCollection;
static void Main(string[] args)
{
//Initialize them
game = new MudEngine.GameManagement.Game();
commands = new MudEngine.GameManagement.CommandEngine();
realmCollection = new List<MudEngine.GameObjects.Environment.Realm>();
//Setup the game
game.AutoSave = true;
game.BaseCurrencyName = "Copper";
game.BaseCurrencyAmount = 1;
game.CompanyName = "Mud Designer";
game.DayLength = 60 * 8;
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.TimeOfDayTransition = 30;
game.Version = "0.1";
game.Website = "http://MudDesigner.Codeplex.com";
//Create the world
BuildRealms();
//Setup our starting location
foreach (MudEngine.GameObjects.Environment.Realm realm in realmCollection)
{
if (realm.IsInitialRealm)
{
game.SetInitialRealm(realm);
break;
}
}
if (game.InitialRealm == null)
Console.WriteLine("Critical Error: No Initial Realm defined!");
//Start the game.
MudEngine.GameManagement.CommandEngine.LoadAllCommands();
game.IsRunning = true;
while (game.IsRunning)
{
Console.Write("Command: ");
string command = Console.ReadLine();
MudEngine.GameManagement.CommandEngine.ExecuteCommand(command, player, game, null);
}
Console.WriteLine("Press Enter to exit.");
Console.ReadKey();
}
static private void BuildRealms()
{
Zeroth zeroth = new Zeroth();
realmCollection.Add(zeroth.BuildZeroth());
}
}
}

View file

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MUDGame")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MUDGame")]
[assembly: AssemblyCopyright("Copyright © 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f8209c47-d989-49af-8264-be5064784104")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -1,24 +1,24 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C# Express 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mud Designer", "Mud Designer\Mud Designer.csproj", "{F0C50EA1-80F7-4CE6-93A3-A4E9F34F0434}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MudEngine", "MudEngine\MudEngine.csproj", "{498943A8-DF5A-4DB0-B506-0BFF44788657}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MUDGame", "MUDGame\MUDGame.csproj", "{048E755C-DD05-47EC-930E-F45146B66F7C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F0C50EA1-80F7-4CE6-93A3-A4E9F34F0434}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0C50EA1-80F7-4CE6-93A3-A4E9F34F0434}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0C50EA1-80F7-4CE6-93A3-A4E9F34F0434}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0C50EA1-80F7-4CE6-93A3-A4E9F34F0434}.Release|Any CPU.Build.0 = Release|Any CPU
{498943A8-DF5A-4DB0-B506-0BFF44788657}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{498943A8-DF5A-4DB0-B506-0BFF44788657}.Debug|Any CPU.Build.0 = Debug|Any CPU
{498943A8-DF5A-4DB0-B506-0BFF44788657}.Release|Any CPU.ActiveCfg = Release|Any CPU
{498943A8-DF5A-4DB0-B506-0BFF44788657}.Release|Any CPU.Build.0 = Release|Any CPU
{048E755C-DD05-47EC-930E-F45146B66F7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{048E755C-DD05-47EC-930E-F45146B66F7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{048E755C-DD05-47EC-930E-F45146B66F7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{048E755C-DD05-47EC-930E-F45146B66F7C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MudEngine.GameObjects.Characters;
using MudEngine.GameManagement;
using MudEngine.Commands;
using MudEngine.GameObjects.Environment;
namespace MudEngine.Commands
{
public class CommandExit : IGameCommand
{
public bool Override { get; set; }
public string Name { get; set; }
public CommandResults Execute(string command, BaseCharacter player, Game game, Room room)
{
game.IsRunning = false;
return new CommandResults();
}
}
}

View file

@ -10,7 +10,7 @@ using MudEngine.GameObjects.Characters;
using MudEngine.GameObjects.Environment;
using MudEngine.GameManagement;
namespace MudEngine.Commands
namespace MudEngine.GameManagement
{
public class CommandEngine
{
@ -46,14 +46,14 @@ namespace MudEngine.Commands
/// <param name="Name"></param>
/// <param name="Parameter"></param>
/// <returns></returns>
public static CommandResults ExecuteCommand(string Name, BaseCharacter player, GameSetup project, Room room, string command)
public static CommandResults ExecuteCommand(string command, BaseCharacter player, Game project, Room room)
{
Name = Name.Insert(0, "Command");
string commandKey = command.Insert(0, "Command");
foreach (string key in Commands.Keys)
{
if (Name.ToLower().Contains(key.ToLower()))
if (commandKey.ToLower().Contains(key.ToLower()))
{
return Commands[key.ToLower()].Execute(player, project, room, command);
return Commands[key.ToLower()].Execute(command, player, project, room);
}
}

View file

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MudEngine.Commands
namespace MudEngine.GameManagement
{
public class CommandResults
{

View file

@ -20,7 +20,7 @@ namespace MudEngine.GameManagement
/// </summary>
[XmlInclude(typeof(StartingLocation))]
[XmlInclude(typeof(Currency))]
public class GameSetup
public class Game
{
public enum TimeOfDayOptions
{
@ -29,6 +29,13 @@ namespace MudEngine.GameManagement
Transition,
}
[Browsable(false)]
public bool IsRunning
{
get;
set;
}
[Category("Company Settings")]
[Description("The name of the Company or Author building the game.")]
/// <summary>
@ -61,6 +68,9 @@ namespace MudEngine.GameManagement
/// </summary>
public bool HideRoomNames { get; set; }
/// <summary>
/// Gets or Sets what time of day the world is currently in.
/// </summary>
[Category("Day Management")]
[Description("Set what time of day the world will take place in.")]
public TimeOfDayOptions TimeOfDay
@ -69,6 +79,9 @@ namespace MudEngine.GameManagement
set;
}
/// <summary>
/// Gets or Sets how long in minutes it takes to transition from day to night.
/// </summary>
[Category("Day Management")]
[Description("Set how long in minutes it takes to transition from day to night.")]
public int TimeOfDayTransition
@ -77,6 +90,9 @@ namespace MudEngine.GameManagement
set;
}
/// <summary>
/// Gets or Sets how long in minutes a day lasts in the game world.
/// </summary>
[Category("Day Management")]
[Description("Sets how long in minutes a day lasts in the game world.")]
public int DayLength
@ -85,6 +101,9 @@ namespace MudEngine.GameManagement
set;
}
/// <summary>
/// Gets or Sets the current working version of the game.
/// </summary>
[Category("Project Settings")]
[Description("The current working version of the game.")]
public string Version { get; set; }
@ -99,9 +118,11 @@ namespace MudEngine.GameManagement
[DefaultValue("Copper")]
public string BaseCurrencyName { get; set; }
//TODO: Add Party support.
/// <summary>
/// Gets or Sets if all objects will be laoded during server startup. Enabling this results in a slower server start time, but faster object access.
/// </summary>
[Category("Project Settings")]
[Description("If enabled, all objects will be loaded during server startup resulting in a slower server start time, but faster load time during gameplay")]
public bool PreCacheObjects { get; set; }
@ -109,12 +130,19 @@ namespace MudEngine.GameManagement
[Browsable(false)]
public List<Currency> CurrencyList { get; set; }
/// <summary>
/// Gets or Sets the path to the current project
/// </summary>
[Browsable(false)]
public string ProjectPath { get; set; }
[Category("Environment Settings")]
[ReadOnly(true)]
public StartingLocation InitialLocation { get; set; }
public Realm InitialRealm
{
get;
private set;
}
[Browsable(false)]
public string Story
@ -133,14 +161,13 @@ namespace MudEngine.GameManagement
}
private string _Filename;
public GameSetup()
public Game()
{
CurrencyList = new List<Currency>();
GameTitle = "New Game";
_Filename = "Game.xml";
BaseCurrencyAmount = 1;
BaseCurrencyName = "Copper";
InitialLocation = new StartingLocation();
}
public void Save(string filename)
@ -160,8 +187,13 @@ namespace MudEngine.GameManagement
{
return null;
}
return FileManager.Load(fileName, this);
}
public void SetInitialRealm(Realm realm)
{
InitialRealm = realm;
}
}
}

View file

@ -10,7 +10,7 @@ using MudEngine.GameObjects.Characters;
using MudEngine.GameManagement;
using MudEngine.GameObjects.Environment;
namespace MudEngine.Commands
namespace MudEngine.GameManagement
{
public interface IGameCommand
{
@ -19,6 +19,6 @@ namespace MudEngine.Commands
//Used to override commands with the same name
bool Override { get; set; }
//Executes the command.
CommandResults Execute(BaseCharacter player, GameSetup project, Room room, string command);
CommandResults Execute(string command, BaseCharacter player, Game project, Room room);
}
}

View file

@ -18,11 +18,13 @@ namespace MudEngine.GameObjects.Environment
[Category("Environment Information")]
[Description("A collection of Zones that are contained within this Realm. Players can traverse the world be traveling through Rooms that are contained within Zones. Note that it is not required to place a Zone into a Realm.")]
//[EditorAttribute(typeof(UIRealmEditor), typeof(System.Drawing.Design.UITypeEditor))]
public List<string> Zones { get; set; }
public List<Zone> Zones { get; set; }
public bool IsInitialRealm { get; set; }
public Realm()
{
Zones = new List<string>();
Zones = new List<Zone>();
}
/// <summary>
@ -34,12 +36,12 @@ namespace MudEngine.GameObjects.Environment
{
var filterQuery =
from zone in Zones
where zone == filename
where zone.Filename == filename
select zone;
Zone z = new Zone();
foreach (var zone in filterQuery)
return (Zone)z.Load(zone);
return (Zone)z.Load(zone.Filename);
return null;
}

View file

@ -98,6 +98,17 @@ namespace MudEngine.GameObjects.Environment
}
}
/// <summary>
/// Gets or Sets if this is the starting room for the Zone that contains it.
/// </summary>
[Browsable(true)]
[Description("Sets if this is the starting room for the Zone that contains it.")]
public bool IsStartingRoom
{
get;
set;
}
public Room()
{
Doorways = new List<Door>();

View file

@ -52,17 +52,29 @@ namespace MudEngine.GameObjects.Environment
set;
}
/// <summary>
/// Gets or Sets the ability for this Zone to be the initial starting Zone for the game.
/// </summary>
[Category("Environment Information")]
[Description("Sets that this Zone is a starting Zone for the game.")]
[DefaultValue(false)]
public bool IsStartingZone
{
get;
set;
}
[Category("Environment Information")]
//[EditorAttribute(typeof(UIRoomEditor), typeof(UITypeEditor))]
[Description("Collection of Rooms that have been created. Editing the Rooms Collection lets you manage the Zones rooms.")]
public List<string> Rooms { get; set; }
public List<Room> Rooms { get; set; }
[Category("Environment Information")]
public string EntranceRoom { get; set; }
public Zone()
{
Rooms = new List<string>();
Rooms = new List<Room>();
IsSafe = false;
Realm = "No Realm Associated.";
}
@ -76,13 +88,13 @@ namespace MudEngine.GameObjects.Environment
{
var filterQuery =
from room in Rooms
where room == name
where room.Name == name
select room;
foreach (string room in filterQuery)
foreach (Room room in filterQuery)
{
Room r = new Room();
return (Room)r.Load(room, this.Name);
return (Room)r.Load(room.Name, this.Name);
}
return null;
}
@ -94,7 +106,7 @@ namespace MudEngine.GameObjects.Environment
/// </summary>
public void RebuildRoomCollection()
{
Rooms = new List<string>();
Rooms = new List<Room>();
//Create our collection of Rooms.
string realmPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), this.Realm);
string zonePath = Path.Combine(realmPath, this.Name);
@ -114,7 +126,7 @@ namespace MudEngine.GameObjects.Environment
Room r = new Room();
r = (Room)r.Load(Path.GetFileNameWithoutExtension(file));
//r = (Room)FileManager.Load(file, r);
this.Rooms.Add(r.Name);
this.Rooms.Add(r);
}
//Save the re-built Room collection

View file

@ -45,13 +45,14 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\CommandEngine.cs" />
<Compile Include="Commands\CommandResults.cs" />
<Compile Include="Commands\ICommand.cs" />
<Compile Include="Commands\CommandExit.cs" />
<Compile Include="GameManagement\CommandEngine.cs" />
<Compile Include="GameManagement\CommandResults.cs" />
<Compile Include="GameManagement\ICommand.cs" />
<Compile Include="FileSystem\FileManager.cs" />
<Compile Include="FileSystem\SaveDataTypes.cs" />
<Compile Include="FileSystem\XmlSerialization.cs" />
<Compile Include="GameManagement\GameSetup.cs" />
<Compile Include="GameManagement\Game.cs" />
<Compile Include="GameObjects\Bag.cs" />
<Compile Include="GameObjects\BaseObject.cs" />
<Compile Include="GameObjects\Characters\BaseCharacter.cs" />

View file

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using BlitScript;
using MudEngine.Scripting;
namespace MudEngine.Scripting
{
@ -47,12 +47,12 @@ namespace MudEngine.Scripting
}
}
}
/* Dynamic Type Instancing isn't supported in .NET 3.5
public dynamic SetProperty()
{
return Instance;
}
*/
public object GetProperty(string propertyName)
{
string[] tokens = propertyName.Split('.');

View file

@ -130,7 +130,7 @@ namespace MudEngine.Scripting
/// Initializes the script engine, loading the compiled scripts into memory
/// </summary>
/// <param name="scriptAssembly"></param>
public override void Initialize()
public void Initialize()
{
if (_ScriptTypes == ScriptTypes.Assembly)
{