MudCompiler:
- Updated to work with ScriptingEngine changes. MudEngine: - Game.PlayerCollection changed to a List<>. Server obtains a array version of it within Server.initialize() via players = pbs.ToArray(). - All BaseObject classes now require a reference to the Game and contain a property called ActiveGame. - Player.Game removed and now uses it's parent objects ActiveGame property. - Player.Role property added. Uses the new SecurityRoles enum that specifies what level of access the player has. - ScriptEngine now loads all libraries found within the specified ScriptsPath directory, instances the scripts and places them into a collection. - Custom character script instancing is now supported, but not fully implemented throughout the engine. They can be loaded, but not used during runtime at this time.
This commit is contained in:
parent
631ce62e73
commit
9b023a2092
24 changed files with 127 additions and 74 deletions
|
@ -46,7 +46,8 @@ namespace MUDCompiler
|
|||
|
||||
static void CompileScripts()
|
||||
{
|
||||
ScriptEngine se = new ScriptEngine(ScriptEngine.ScriptTypes.SourceFiles);
|
||||
MudEngine.GameManagement.Game game = new MudEngine.GameManagement.Game();
|
||||
ScriptEngine se = new ScriptEngine(game, ScriptEngine.ScriptTypes.SourceFiles);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Compiling...");
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace MudEngine.Commands
|
|||
|
||||
public CommandResults Execute(string command, BaseCharacter player)
|
||||
{
|
||||
player.Game.Shutdown();
|
||||
player.ActiveGame.Shutdown();
|
||||
|
||||
return new CommandResults();
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@ namespace MudEngine.Commands
|
|||
|
||||
public CommandResults Execute(string command, BaseCharacter player)
|
||||
{
|
||||
if (player.IsAdmin)
|
||||
if (player.Role == SecurityRoles.Admin)
|
||||
{
|
||||
for (int i = 0; i < player.Game.PlayerCollection./*Count*/Length; i++)
|
||||
player.Game.PlayerCollection[i].Save(player.Game.PlayerCollection[i].Name + ".dat");
|
||||
player.Game.Server.EndServer();
|
||||
player.Game.Server.Initialize(555, ref player.Game.PlayerCollection);
|
||||
for (int i = 0; i < player.ActiveGame.PlayerCollection.Count/*Length*/; i++)
|
||||
player.ActiveGame.PlayerCollection[i].Save(player.ActiveGame.PlayerCollection[i].Name + ".dat");
|
||||
player.ActiveGame.Server.EndServer();
|
||||
player.ActiveGame.Server.Initialize(555, ref player.ActiveGame.PlayerCollection);
|
||||
return new CommandResults("Server Restarted.");
|
||||
}
|
||||
return new CommandResults("Access Denied.");
|
||||
|
|
|
@ -178,9 +178,9 @@ namespace MudEngine.GameManagement
|
|||
public Game()
|
||||
{
|
||||
CurrencyList = new List<Currency>();
|
||||
scriptEngine = new Scripting.ScriptEngine();
|
||||
scriptEngine = new Scripting.ScriptEngine(this);
|
||||
RealmCollection = new List<Realm>();
|
||||
//PlayerCollection = new List<BaseCharacter>();
|
||||
PlayerCollection = new List<BaseCharacter>();
|
||||
|
||||
GameTitle = "New Game";
|
||||
_Filename = "Game.xml";
|
||||
|
@ -202,7 +202,7 @@ namespace MudEngine.GameManagement
|
|||
//Loads the MudEngine Game Commands
|
||||
CommandEngine.LoadBaseCommands();
|
||||
//Loads any commands found in the users custom scripts library loaded by the script engine.
|
||||
CommandEngine.LoadCommandLibrary(scriptEngine.Assembly);
|
||||
//CommandEngine.LoadCommandLibrary(scriptEngine.Assembly);
|
||||
|
||||
//Ensure custom commands are loaded until everything is fleshed out.
|
||||
if (Game.IsDebug)
|
||||
|
@ -236,6 +236,9 @@ namespace MudEngine.GameManagement
|
|||
//Start the Telnet server
|
||||
if (IsMultiplayer)
|
||||
this.StartServer();
|
||||
else
|
||||
//TODO: Need to load a previously saved character or allow for creation of one by user.
|
||||
//PlayerCollection.Add(new BaseCharacter(this)); //If this is single player, then add a new character to the game.
|
||||
|
||||
IsRunning = true;
|
||||
|
||||
|
@ -310,8 +313,8 @@ namespace MudEngine.GameManagement
|
|||
}
|
||||
|
||||
//TODO: This should be internal only; C# property using get; internal set; so only MudEngine.dll may edit this collection
|
||||
//public List<BaseCharacter> PlayerCollection;
|
||||
public BaseCharacter[] PlayerCollection;
|
||||
public List<BaseCharacter> PlayerCollection;
|
||||
//public BaseCharacter[] PlayerCollection;
|
||||
|
||||
public MudEngine.Networking.Server Server { get; internal set; }
|
||||
public ProtocolType ServerType = ProtocolType.Tcp;
|
||||
|
@ -322,10 +325,9 @@ namespace MudEngine.GameManagement
|
|||
|
||||
private void StartServer()
|
||||
{
|
||||
//This is handled by the Game() Constructor
|
||||
//PlayerCollection = new List<BaseCharacter>(MaximumPlayers);
|
||||
PlayerCollection = new BaseCharacter[MaximumPlayers];
|
||||
for (int i = 0; i < MaximumPlayers; i++)
|
||||
PlayerCollection[i] = new BaseCharacter(this);
|
||||
PlayerCollection.Add(new BaseCharacter(this));
|
||||
Server = new Networking.Server();
|
||||
Server.Initialize(ServerPort, ref PlayerCollection);
|
||||
Server.Start();
|
||||
|
|
14
MudEngine/GameManagement/SecurityRoles.cs
Normal file
14
MudEngine/GameManagement/SecurityRoles.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
|
||||
namespace MudEngine.GameManagement
|
||||
{
|
||||
public enum SecurityRoles
|
||||
{
|
||||
Admin,
|
||||
Immortal,
|
||||
GM,
|
||||
QuestGiver,
|
||||
Player,
|
||||
NPC
|
||||
}
|
||||
}
|
|
@ -22,6 +22,10 @@ namespace MudEngine.GameObjects
|
|||
|
||||
private List<Items.BaseItem> Items { get; set; }
|
||||
|
||||
public Bag(GameManagement.Game game) : base(game)
|
||||
{
|
||||
}
|
||||
|
||||
public void Add(BaseItem item)
|
||||
{
|
||||
if (Items.Count < Size)
|
||||
|
|
|
@ -9,6 +9,7 @@ using System.IO;
|
|||
|
||||
//MUD Engine
|
||||
using MudEngine.FileSystem;
|
||||
using MudEngine.GameManagement;
|
||||
|
||||
namespace MudEngine.GameObjects
|
||||
{
|
||||
|
@ -99,15 +100,17 @@ namespace MudEngine.GameObjects
|
|||
|
||||
private string _Filename = "";
|
||||
private string _Name = "";
|
||||
internal Game ActiveGame { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the base object
|
||||
/// </summary>
|
||||
public BaseObject()
|
||||
public BaseObject(Game game)
|
||||
{
|
||||
Script = "";
|
||||
_Name = "New " + this.GetType().Name;
|
||||
_Filename = _Name + "." + this.GetType().Name;
|
||||
ActiveGame = game;
|
||||
|
||||
this.Feel = "You feel nothing.";
|
||||
this.Listen = "You hear nothing of interest.";
|
||||
|
|
|
@ -32,21 +32,16 @@ namespace MudEngine.GameObjects.Characters
|
|||
/// <summary>
|
||||
/// Gets or Sets if this user has Admin privileges or not.
|
||||
/// </summary>
|
||||
public Boolean IsAdmin { get; private set; }
|
||||
public SecurityRoles Role { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets if this player is active.
|
||||
/// </summary>
|
||||
public Boolean IsActive { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the currently running game.
|
||||
/// </summary>
|
||||
public Game Game { get; private set; }
|
||||
|
||||
public BaseCharacter(Game game)
|
||||
public BaseCharacter(Game game) : base(game)
|
||||
{
|
||||
Game = game;
|
||||
ActiveGame = game;
|
||||
IsActive = false;
|
||||
CurrentRoom = game.InitialRealm.InitialZone.InitialRoom;
|
||||
}
|
||||
|
@ -99,7 +94,7 @@ namespace MudEngine.GameObjects.Characters
|
|||
|
||||
internal void Initialize()
|
||||
{
|
||||
CurrentRoom = Game.InitialRealm.InitialZone.InitialRoom;
|
||||
CurrentRoom = ActiveGame.InitialRealm.InitialZone.InitialRoom;
|
||||
|
||||
IsActive = true;
|
||||
}
|
||||
|
@ -116,7 +111,7 @@ namespace MudEngine.GameObjects.Characters
|
|||
// convert the result back to bytes and send it back
|
||||
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
||||
Send(encoding.GetBytes(str));
|
||||
if (!Game.IsRunning)
|
||||
if (!ActiveGame.IsRunning)
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace MudEngine.GameObjects
|
|||
set;
|
||||
}
|
||||
|
||||
public Currency()
|
||||
public Currency(GameManagement.Game game) : base(game)
|
||||
{
|
||||
this.Name = "New Currency";
|
||||
this.Value = 100;
|
||||
|
|
|
@ -52,11 +52,11 @@ namespace MudEngine.GameObjects.Environment
|
|||
/// </summary>
|
||||
public Room DepartureRoom { get; set; }
|
||||
|
||||
public Door()
|
||||
public Door(GameManagement.Game game)
|
||||
{
|
||||
LevelRequirement = 0;
|
||||
IsLocked = false;
|
||||
RequiredKey = new BaseItem();
|
||||
RequiredKey = new BaseItem(game);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace MudEngine.GameObjects.Environment
|
|||
/// </summary>
|
||||
public Zone InitialZone { get; private set; }
|
||||
|
||||
public Realm()
|
||||
public Realm(GameManagement.Game game) : base(game)
|
||||
{
|
||||
ZoneCollection = new List<Zone>();
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace MudEngine.GameObjects.Environment
|
|||
set;
|
||||
}
|
||||
|
||||
public Room()
|
||||
public Room(Game game) :base(game)
|
||||
{
|
||||
Doorways = new List<Door>();
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ namespace MudEngine.GameObjects.Environment
|
|||
[Category("Environment Information")]
|
||||
public Room InitialRoom { get; private set; }
|
||||
|
||||
public Zone()
|
||||
public Zone(GameManagement.Game game) : base(game)
|
||||
{
|
||||
RoomCollection = new List<Room>();
|
||||
IsSafe = false;
|
||||
|
@ -136,7 +136,7 @@ namespace MudEngine.GameObjects.Environment
|
|||
|
||||
public void LinkRooms(AvailableTravelDirections departureDirection, Room arrivalRoom, Room departureRoom, Int32 requiredLevel, Boolean isLocked, BaseItem requiredKey)
|
||||
{
|
||||
Door door = new Door();
|
||||
Door door = new Door(ActiveGame);
|
||||
door.ArrivalRoom = arrivalRoom;
|
||||
door.DepartureRoom = departureRoom;
|
||||
|
||||
|
@ -151,7 +151,7 @@ namespace MudEngine.GameObjects.Environment
|
|||
departureRoom.Doorways.Add(door);
|
||||
|
||||
//Now we set up the door for the opposite room.
|
||||
door = new Door();
|
||||
door = new Door(ActiveGame);
|
||||
|
||||
door.DepartureRoom = arrivalRoom;
|
||||
door.ArrivalRoom = departureRoom;
|
||||
|
|
|
@ -8,6 +8,8 @@ namespace MudEngine.GameObjects.Items
|
|||
{
|
||||
public class BaseItem : BaseObject
|
||||
{
|
||||
|
||||
public BaseItem(GameManagement.Game game) : base(game)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
|
@ -61,6 +62,7 @@
|
|||
<Compile Include="FileSystem\XmlSerialization.cs" />
|
||||
<Compile Include="GameManagement\Game.cs" />
|
||||
<Compile Include="GameManagement\Log.cs" />
|
||||
<Compile Include="GameManagement\SecurityRoles.cs" />
|
||||
<Compile Include="GameObjects\Bag.cs" />
|
||||
<Compile Include="GameObjects\BaseObject.cs" />
|
||||
<Compile Include="GameObjects\Characters\BaseCharacter.cs" />
|
||||
|
|
|
@ -30,15 +30,15 @@ namespace MudEngine.Networking
|
|||
stage = 0;
|
||||
port = 0;
|
||||
}
|
||||
public bool Initialize(int p, ref /*List<BaseCharacter>*/BaseCharacter[] pbs)
|
||||
public bool Initialize(int p, ref List<BaseCharacter>/*BaseCharacter[]*/ pbs)
|
||||
{
|
||||
if (stage != 0)
|
||||
return false;
|
||||
if (p <= 0)
|
||||
return false;
|
||||
port = p;
|
||||
clientThreads = new Thread[pbs./*Capacity*/Length];
|
||||
players = pbs;
|
||||
clientThreads = new Thread[pbs.Capacity/*Length*/];
|
||||
players = pbs.ToArray();
|
||||
stage++;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,12 @@ namespace MudEngine.Scripting
|
|||
/// </summary>
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
public GameObject(object instance, string name)
|
||||
{
|
||||
Instance = instance;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public object CreateObject()
|
||||
{
|
||||
return Instance;
|
||||
|
|
|
@ -30,8 +30,15 @@ namespace MudEngine.Scripting
|
|||
public string InstallPath { get; private set; }
|
||||
public GameObjectCollection ObjectCollection { get; private set; }
|
||||
|
||||
public Assembly Assembly { get { return _ScriptAssembly; } private set { _ScriptAssembly = value; } }
|
||||
/// <summary>
|
||||
/// Collection of currently loaded objects created from compiled scripts
|
||||
/// </summary>
|
||||
public List<GameObject> GameObjects { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Collection of currently loaded game commecnts that can be used. These must be compiled scripts inheriting from IGameCommand
|
||||
/// </summary>
|
||||
public List<IGameCommand> GameCommands { get; private set; }
|
||||
/// <summary>
|
||||
/// File Extension for the scripts
|
||||
/// </summary>
|
||||
|
@ -59,11 +66,13 @@ namespace MudEngine.Scripting
|
|||
|
||||
private ScriptTypes _ScriptTypes;
|
||||
private Assembly _ScriptAssembly;
|
||||
private List<Assembly> _AssemblyCollection;
|
||||
private string[] _ErrorMessages;
|
||||
Game _Game;
|
||||
|
||||
public ScriptEngine() : this(ScriptTypes.Assembly)
|
||||
public ScriptEngine(Game game) : this(game, ScriptTypes.Assembly)
|
||||
{
|
||||
//Empty constructor. Only here for end-user ease of use. ScriptEngine(Game, ScriptTypes) is called from here.
|
||||
_Game = game;
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,15 +80,19 @@ namespace MudEngine.Scripting
|
|||
/// Instances a new copy of the script engine
|
||||
/// </summary>
|
||||
/// <param name="scriptTypes">Tells the engine what kind of scripts will be loaded. Source File or assembly based.</param>
|
||||
public ScriptEngine(ScriptTypes scriptTypes)
|
||||
public ScriptEngine(Game game, ScriptTypes scriptTypes)
|
||||
{
|
||||
//Initialize our engine fields
|
||||
_ScriptTypes = scriptTypes;
|
||||
ScriptExtension = ".cs";
|
||||
|
||||
//Get our current install path
|
||||
ScriptPath = Environment.CurrentDirectory;
|
||||
ScriptPath = Path.Combine(Environment.CurrentDirectory, "Scripts");
|
||||
InstallPath = Environment.CurrentDirectory;
|
||||
GameObjects = new List<GameObject>();
|
||||
_AssemblyCollection = new List<Assembly>();
|
||||
|
||||
_Game = game;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -183,26 +196,48 @@ namespace MudEngine.Scripting
|
|||
{
|
||||
InitializeSourceFiles();
|
||||
}
|
||||
|
||||
foreach (Assembly assembly in _AssemblyCollection)
|
||||
{
|
||||
foreach (Type t in assembly.GetTypes())
|
||||
{
|
||||
if (t.BaseType == null)
|
||||
continue;
|
||||
if (t.BaseType.Name == "BaseObject")
|
||||
{
|
||||
GameObjects.Add(new GameObject(Activator.CreateInstance(t, new object[] {_Game}), t.Name));
|
||||
continue;
|
||||
}
|
||||
else if (t.BaseType.Name == "BaseCharacter")
|
||||
{
|
||||
GameObject obj = new GameObject(Activator.CreateInstance(t, new object[] {_Game}), t.Name);
|
||||
GameObjects.Add(obj);
|
||||
obj.GetProperty().CurrentRoom = _Game.InitialRealm.InitialZone.InitialRoom;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeAssembly()
|
||||
{
|
||||
if (!System.IO.File.Exists("Scripts.dll"))
|
||||
if (!Directory.Exists(ScriptPath))
|
||||
{
|
||||
ErrorMessage = "Failed to load Script Assembly!";
|
||||
Log.Write(ErrorMessage);
|
||||
Log.Write("Supplied script path does not exist! No scripts loaded.");
|
||||
return;
|
||||
}
|
||||
string[] libraries = Directory.GetFiles(ScriptPath, "*.dll", SearchOption.AllDirectories);
|
||||
|
||||
if (libraries.Length == 0)
|
||||
{
|
||||
Log.Write("Failed to load Script Assembly!");
|
||||
return;
|
||||
}
|
||||
|
||||
_ScriptAssembly = Assembly.LoadFile(Path.Combine(InstallPath, "Scripts.dll"));
|
||||
foreach (string library in libraries)
|
||||
_AssemblyCollection.Add(Assembly.LoadFile(library));
|
||||
|
||||
foreach (Type type in _ScriptAssembly.GetTypes())
|
||||
{
|
||||
if (type.BaseType == typeof(BaseCharacter))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
_AssemblyCollection.Add(Assembly.GetExecutingAssembly());
|
||||
}
|
||||
|
||||
private void InitializeSourceFiles()
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace MUDGame
|
|||
internal Zeroth(Game game)
|
||||
{
|
||||
this.game = game;
|
||||
realm = new Realm();
|
||||
realm = new Realm(game);
|
||||
}
|
||||
|
||||
internal void BuildZeroth()
|
||||
|
@ -31,7 +31,7 @@ namespace MUDGame
|
|||
private void BuildHome()
|
||||
{
|
||||
//Build Zones
|
||||
Zone zone = new Zone();
|
||||
Zone zone = new Zone(game);
|
||||
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;
|
||||
|
@ -40,7 +40,7 @@ namespace MUDGame
|
|||
zone.Realm = realm.Name;
|
||||
realm.AddZone(zone);
|
||||
|
||||
Room bedroom = new Room();
|
||||
Room bedroom = new Room(game);
|
||||
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.\nYou may walk to the WEST to find you Closet.";
|
||||
bedroom.Zone = zone.Name;
|
||||
|
@ -48,7 +48,7 @@ namespace MUDGame
|
|||
bedroom.IsInitialRoom = true;
|
||||
zone.AddRoom(bedroom);
|
||||
|
||||
Room closet = new Room();
|
||||
Room closet = new Room(game);
|
||||
closet.Name = "Closet";
|
||||
closet.Description = "Your closet contains clothing and some shoes.\nYou may walk to your EAST to find your Room.";
|
||||
closet.Zone = zone.Name;
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace MUDGame
|
|||
player = new BaseCharacter(game);
|
||||
//Add the player to the game.
|
||||
//Note once the server is fully implemented the player will be generated automatically by Game.
|
||||
//game.PlayerCollection.Add(player);
|
||||
game.PlayerCollection.Add(player);
|
||||
|
||||
//Send game info to player
|
||||
Console.WriteLine(game.GameTitle);
|
||||
|
|
|
@ -39,28 +39,17 @@ namespace MudServer
|
|||
game.ServerType = ProtocolType.Tcp;
|
||||
game.ServerPort = 555;
|
||||
game.MaximumPlayers = 1000;
|
||||
|
||||
game.PlayerCollection.Add(serverAdmin);
|
||||
Game.IsDebug = true;
|
||||
|
||||
game.Start();
|
||||
string command = "";
|
||||
|
||||
while (game.IsRunning)
|
||||
{
|
||||
if (!Console.KeyAvailable)
|
||||
{
|
||||
Console.Write(Log.GetMessages());
|
||||
Log.FlushMessages();
|
||||
System.Threading.Thread.Sleep(1);
|
||||
}
|
||||
//TODO: Fix Me D:
|
||||
else if (Console.ReadKey().Key == ConsoleKey.Enter)
|
||||
CommandEngine.ExecuteCommand(command, serverAdmin);
|
||||
else if (Console.ReadKey().Key == ConsoleKey.Backspace)
|
||||
Log.Write("Backspace is not currently supported :(");
|
||||
else
|
||||
command += Console.ReadKey().KeyChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
BIN
MudServer/bin/Debug/Scripts/Scripts.dll
Normal file
BIN
MudServer/bin/Debug/Scripts/Scripts.dll
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue