From a3eb1b5fadce961ca46a8d64ffa15d5de47f7902 Mon Sep 17 00:00:00 2001 From: Scionwest_cp Date: Sun, 4 Mar 2012 11:48:11 -0800 Subject: [PATCH] Began initial work on the game world. World, Realm, Zone, Room and Doorway classes created but not implemented. --- MudEngine/WinPC_Engine/Core/CommandSystem.cs | 2 +- .../WinPC_Engine/Core/Interfaces/ICommand.cs | 2 +- .../Game/Characters/CharacterRoles.cs | 1 + .../Game/Characters/StandardCharacter.cs | 56 +++++++-------- .../WinPC_Engine/Game/Environment/Doorway.cs | 29 ++++++++ .../WinPC_Engine/Game/Environment/Realm.cs | 70 +++++++++++++++++++ .../WinPC_Engine/Game/Environment/Room.cs | 33 +++++++++ .../WinPC_Engine/Game/Environment/Zone.cs | 55 +++++++++++++++ MudEngine/WinPC_Engine/Game/StandardGame.cs | 10 ++- MudEngine/WinPC_Engine/Game/World.cs | 39 +++++++++++ .../WinPC_Engine/GameScripts/BaseScript.cs | 3 + .../Commands/CommandCreatePlayer.cs | 2 +- .../GameScripts/Commands/CommandLogin.cs | 2 +- .../GameScripts/Commands/CommandLook.cs | 33 +++++++++ .../GameScripts/Commands/CommandSay.cs | 2 +- .../GameScripts/Commands/CommandSetRole.cs | 2 +- .../GameScripts/Commands/CommandStop.cs | 2 +- MudEngine/WinPC_Engine/WinPC_Engine.csproj | 6 ++ 18 files changed, 313 insertions(+), 36 deletions(-) create mode 100644 MudEngine/WinPC_Engine/Game/Environment/Doorway.cs create mode 100644 MudEngine/WinPC_Engine/Game/Environment/Realm.cs create mode 100644 MudEngine/WinPC_Engine/Game/Environment/Room.cs create mode 100644 MudEngine/WinPC_Engine/Game/Environment/Zone.cs create mode 100644 MudEngine/WinPC_Engine/Game/World.cs create mode 100644 MudEngine/WinPC_Engine/GameScripts/Commands/CommandLook.cs diff --git a/MudEngine/WinPC_Engine/Core/CommandSystem.cs b/MudEngine/WinPC_Engine/Core/CommandSystem.cs index f0af70c..d37d9f8 100644 --- a/MudEngine/WinPC_Engine/Core/CommandSystem.cs +++ b/MudEngine/WinPC_Engine/Core/CommandSystem.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Reflection; -using MudEngine.Core.Interface; +using MudEngine.Core.Interfaces; using MudEngine.Game.Characters; namespace MudEngine.Core diff --git a/MudEngine/WinPC_Engine/Core/Interfaces/ICommand.cs b/MudEngine/WinPC_Engine/Core/Interfaces/ICommand.cs index 9d83582..71f3a1f 100644 --- a/MudEngine/WinPC_Engine/Core/Interfaces/ICommand.cs +++ b/MudEngine/WinPC_Engine/Core/Interfaces/ICommand.cs @@ -5,7 +5,7 @@ using System.Text; using MudEngine.Game.Characters; -namespace MudEngine.Core.Interface +namespace MudEngine.Core.Interfaces { public interface ICommand { diff --git a/MudEngine/WinPC_Engine/Game/Characters/CharacterRoles.cs b/MudEngine/WinPC_Engine/Game/Characters/CharacterRoles.cs index 08c9fdd..ac7b794 100644 --- a/MudEngine/WinPC_Engine/Game/Characters/CharacterRoles.cs +++ b/MudEngine/WinPC_Engine/Game/Characters/CharacterRoles.cs @@ -13,6 +13,7 @@ namespace MudEngine.Game.Characters Admin, Immortal, GM, + Builder, QuestGiver, Player, NPC diff --git a/MudEngine/WinPC_Engine/Game/Characters/StandardCharacter.cs b/MudEngine/WinPC_Engine/Game/Characters/StandardCharacter.cs index f3d4bfb..a1f4470 100644 --- a/MudEngine/WinPC_Engine/Game/Characters/StandardCharacter.cs +++ b/MudEngine/WinPC_Engine/Game/Characters/StandardCharacter.cs @@ -13,6 +13,7 @@ using MudEngine.GameScripts; using MudEngine.Core.Interfaces; using MudEngine.Networking; using MudEngine.Core; +using MudEngine.Game.Environment; namespace MudEngine.Game.Characters { @@ -24,7 +25,6 @@ namespace MudEngine.Game.Characters /// /// Gets a reference to the currently active game. /// - public StandardGame Game { get; private set; } public string Filename { @@ -87,11 +87,11 @@ namespace MudEngine.Game.Characters protected CommandSystem Commands { get; private set; } + public Room CurrentRoom { get; private set; } + public StandardCharacter(StandardGame game, String name, String description) : base(game, name, description) { - this.Game = game; - this.Role = CharacterRoles.Player; //Instance this Characters personal Command System with a copy of the command @@ -114,7 +114,7 @@ namespace MudEngine.Game.Characters this._Writer.AutoFlush = true; //Flushes the stream automatically. } - public void Initialize() + public virtual void Initialize() { //throw new NotImplementedException(); this.Enabled = true; @@ -124,7 +124,7 @@ namespace MudEngine.Game.Characters /// Destroys any resources used by this character. /// Assumes that Save() has already been invoked. /// - public void Destroy() + public virtual void Destroy() { this.Commands = null; } @@ -163,31 +163,12 @@ namespace MudEngine.Game.Characters this.Role = GetRole(role); } - private CharacterRoles GetRole(String role) - { - //Blow all of the available values up into an array. - Array values = Enum.GetValues(typeof(CharacterRoles)); - - //Loop through each available value, converting it into a string. - foreach (Int32 value in values) - { - //Get the string representation of the current value - String displayName = Enum.GetName(typeof(CharacterRoles), value); - - //Check if this value matches that of the supplied one. - //If so, return it as a enum - if (displayName.ToLower() == role.ToLower()) - return (CharacterRoles)Enum.Parse(typeof(CharacterRoles), displayName); - } - return CharacterRoles.Player; - } - /// /// Executes the specified command if it exists in the Command library. /// /// /// - public Boolean ExecuteCommand(string command) + public virtual Boolean ExecuteCommand(string command) { if (this.Enabled && this.Connected) { @@ -209,7 +190,7 @@ namespace MudEngine.Game.Characters /// /// /// - public Boolean ExecuteSilentCommand(string command) + public virtual Boolean ExecuteSilentCommand(string command) { if (this.Enabled) { @@ -245,12 +226,12 @@ namespace MudEngine.Game.Characters this.OnDisconnectEvent(); } - public void SendMessage(String data) + public virtual void SendMessage(String data) { this.SendMessage(data, true); } - public void SendMessage(String data, Boolean newLine) + public virtual void SendMessage(String data, Boolean newLine) { try { @@ -393,6 +374,25 @@ namespace MudEngine.Game.Characters } } + private CharacterRoles GetRole(String role) + { + //Blow all of the available values up into an array. + Array values = Enum.GetValues(typeof(CharacterRoles)); + + //Loop through each available value, converting it into a string. + foreach (Int32 value in values) + { + //Get the string representation of the current value + String displayName = Enum.GetName(typeof(CharacterRoles), value); + + //Check if this value matches that of the supplied one. + //If so, return it as a enum + if (displayName.ToLower() == role.ToLower()) + return (CharacterRoles)Enum.Parse(typeof(CharacterRoles), displayName); + } + return CharacterRoles.Player; + } + private Socket _Connection; private StreamReader _Reader; private StreamWriter _Writer; diff --git a/MudEngine/WinPC_Engine/Game/Environment/Doorway.cs b/MudEngine/WinPC_Engine/Game/Environment/Doorway.cs new file mode 100644 index 0000000..976cef5 --- /dev/null +++ b/MudEngine/WinPC_Engine/Game/Environment/Doorway.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using MudEngine.GameScripts; + +namespace MudEngine.Game.Environment +{ + public class Doorway + { + public Boolean Locked { get; set; } + + public BaseScript RequiredKey { get; private set; } + + public Int32 LevelRequirement { get; set; } + + public AvailableTravelDirections TravelDirection { get; set; } + + public Room ArrivalRoom { get; private set; } + + public Room DepartureRoom { get; private set; } + + public Doorway(StandardGame game) + { + this.LevelRequirement = 0; + } + } +} diff --git a/MudEngine/WinPC_Engine/Game/Environment/Realm.cs b/MudEngine/WinPC_Engine/Game/Environment/Realm.cs new file mode 100644 index 0000000..151c3b0 --- /dev/null +++ b/MudEngine/WinPC_Engine/Game/Environment/Realm.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.IO; +using System.Text; + +using MudEngine.Core.Interfaces; +using MudEngine.Game.Characters; +using MudEngine.Game; +using MudEngine.GameScripts; + +namespace MudEngine.Game.Environment +{ + public class Realm : BaseScript, IGameComponent, ISavable, IUpdatable + { + public string Filename { get; set; } + + public Realm(StandardGame game, String name, String description) : base(game, name, description) + { + this._ZoneCollection = new List(); + } + + public void Initialize() + { + + } + + public void Destroy() + { + throw new NotImplementedException(); + } + + public bool Save(string filename) + { + throw new NotImplementedException(); + } + + public bool Save(string filename, bool ignoreFileWrite) + { + throw new NotImplementedException(); + } + + public void Load(string filename) + { + throw new NotImplementedException(); + } + + public void Update() + { + throw new NotImplementedException(); + } + + public void CreateZone(String name, String description) + { + Zone zone = new Zone(this.Game, name, description); + this._ZoneCollection.Add(zone); + } + + public Zone GetZone(String name) + { + var v = from zone in this._ZoneCollection + where zone.Name == name + select zone; + + return v.First(); + } + + private List _ZoneCollection; + } +} diff --git a/MudEngine/WinPC_Engine/Game/Environment/Room.cs b/MudEngine/WinPC_Engine/Game/Environment/Room.cs new file mode 100644 index 0000000..38ff972 --- /dev/null +++ b/MudEngine/WinPC_Engine/Game/Environment/Room.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using MudEngine.Core.Interfaces; +using MudEngine.Core; +using MudEngine.Game; +using MudEngine.Game.Characters; +using MudEngine.GameScripts; +namespace MudEngine.Game.Environment +{ + public class Room : BaseScript, IUpdatable + { + public Room(StandardGame game, String name, String description) + : base(game, name, description) + { + this._Doors = new List(); + } + + public void Update() + { + throw new NotImplementedException(); + } + + public String[] GetDescription() + { + return new List().ToArray(); + } + + private List _Doors; + } +} diff --git a/MudEngine/WinPC_Engine/Game/Environment/Zone.cs b/MudEngine/WinPC_Engine/Game/Environment/Zone.cs new file mode 100644 index 0000000..72d6248 --- /dev/null +++ b/MudEngine/WinPC_Engine/Game/Environment/Zone.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using MudEngine.Core.Interfaces; +using MudEngine.GameScripts; +using MudEngine.Game.Characters; + +namespace MudEngine.Game.Environment +{ + public class Zone : BaseScript, IGameComponent, ISavable, IUpdatable + { + /// + /// Gets or Sets the what stats + /// + public CharacterStats StatDrain { get; set; } + + public Boolean Safe { get; set; } + + public String Realm { get; private set; } + + public Zone(StandardGame game, String name, String description) : base(game, name, description) + { + this._RoomCollection = new List(); + } + + public void Initialize() + { + throw new NotImplementedException(); + } + + public void Destroy() + { + throw new NotImplementedException(); + } + + public string Filename + { + get { throw new NotImplementedException(); } + } + + public void Update() + { + throw new NotImplementedException(); + } + + public void CreateRoom(String name, String description) + { + + } + + private List _RoomCollection; + } +} diff --git a/MudEngine/WinPC_Engine/Game/StandardGame.cs b/MudEngine/WinPC_Engine/Game/StandardGame.cs index 3e9faad..80c22ab 100644 --- a/MudEngine/WinPC_Engine/Game/StandardGame.cs +++ b/MudEngine/WinPC_Engine/Game/StandardGame.cs @@ -71,10 +71,15 @@ namespace MudEngine.Game public Boolean Debugging { get; set; } /// - /// Gets or reference to the currently running Server. + /// Gets a reference to the currently running Server. /// public Server Server { get; protected set; } + /// + /// Gets a reference to the current Game World + /// + public World World { get; protected set; } + /// /// Gets or Sets the paths that content is saved to. /// @@ -113,6 +118,8 @@ namespace MudEngine.Game this.SavePaths = paths; SetupPaths(); + + this.World = new World(this); } /// @@ -134,6 +141,7 @@ namespace MudEngine.Game CommandSystem.LoadCommands(); //Load World + this.World.CreateRealm("Azeroth", "The realm of Azeroth is full of jungles and small villages"); //Start our server. this.Server.Start(maxPlayers, maxQueueSize); diff --git a/MudEngine/WinPC_Engine/Game/World.cs b/MudEngine/WinPC_Engine/Game/World.cs new file mode 100644 index 0000000..541bf19 --- /dev/null +++ b/MudEngine/WinPC_Engine/Game/World.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using MudEngine.Game.Environment; + +namespace MudEngine.Game +{ + public class World + { + public StandardGame Game { get; private set; } + + public World(StandardGame game) + { + this.Game = game; + this._RealmCollection = new List(); + } + + public void CreateRealm(String name, String description) + { + Realm r = new Realm(this.Game, name, description); + + this._RealmCollection.Add(r); + } + + public Realm GetRealm(String name) + { + var v = from realm in this._RealmCollection + where realm.Name == name + select realm; + + Realm r = v.First(); + return r; + } + + private List _RealmCollection; + } +} diff --git a/MudEngine/WinPC_Engine/GameScripts/BaseScript.cs b/MudEngine/WinPC_Engine/GameScripts/BaseScript.cs index 81686c9..7a1f421 100644 --- a/MudEngine/WinPC_Engine/GameScripts/BaseScript.cs +++ b/MudEngine/WinPC_Engine/GameScripts/BaseScript.cs @@ -23,10 +23,13 @@ namespace MudEngine.GameScripts public XMLData SaveData { get; protected set; } + public StandardGame Game { get; private set; } + public BaseScript(StandardGame game, String name, String description) { this.Name = name; this.Description = description; + this.Game = game; this.ID = Guid.NewGuid().ToString(); diff --git a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandCreatePlayer.cs b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandCreatePlayer.cs index 9e7227d..a45c11d 100644 --- a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandCreatePlayer.cs +++ b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandCreatePlayer.cs @@ -6,7 +6,7 @@ using System.Text.RegularExpressions; using System.IO; using System.Diagnostics; -using MudEngine.Core.Interface; +using MudEngine.Core.Interfaces; using MudEngine.Game; using MudEngine.Game.Characters; using MudEngine.Game.Environment; diff --git a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandLogin.cs b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandLogin.cs index b9795b8..4623ad9 100644 --- a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandLogin.cs +++ b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandLogin.cs @@ -5,7 +5,7 @@ using System.Text; using System.Text.RegularExpressions; using System.IO; -using MudEngine.Core.Interface; +using MudEngine.Core.Interfaces; using MudEngine.Game; using MudEngine.Game.Characters; using MudEngine.Game.Environment; diff --git a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandLook.cs b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandLook.cs new file mode 100644 index 0000000..7ebbe50 --- /dev/null +++ b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandLook.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using MudEngine.Game; +using MudEngine.Game.Characters; +using MudEngine.Game.Environment; +using MudEngine.Core.Interfaces; + +namespace MudEngine.GameScripts.Commands +{ + public class CommandLook : ICommand + { + public string Name { get; set; } + + public string Description { get; set; } + + public List Help { get; set; } + + public CommandLook() + { + this.Name = "Look"; + } + + public bool Execute(string command, StandardCharacter character) + { + + + return false; + } + } +} diff --git a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandSay.cs b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandSay.cs index 8168003..232cfa9 100644 --- a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandSay.cs +++ b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandSay.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using MudEngine.Core.Interface; +using MudEngine.Core.Interfaces; using MudEngine.Game; using MudEngine.Game.Characters; using MudEngine.Networking; diff --git a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandSetRole.cs b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandSetRole.cs index 6304eb8..403d18a 100644 --- a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandSetRole.cs +++ b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandSetRole.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; -using MudEngine.Core.Interface; +using MudEngine.Core.Interfaces; using MudEngine.Game; using MudEngine.Game.Characters; using MudEngine.Networking; diff --git a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandStop.cs b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandStop.cs index 4cbe795..c159110 100644 --- a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandStop.cs +++ b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandStop.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading; -using MudEngine.Core.Interface; +using MudEngine.Core.Interfaces; using MudEngine.Game; using MudEngine.Game.Characters; using MudEngine.Networking; diff --git a/MudEngine/WinPC_Engine/WinPC_Engine.csproj b/MudEngine/WinPC_Engine/WinPC_Engine.csproj index 4af31ec..abb7e1c 100644 --- a/MudEngine/WinPC_Engine/WinPC_Engine.csproj +++ b/MudEngine/WinPC_Engine/WinPC_Engine.csproj @@ -55,6 +55,7 @@ + @@ -65,8 +66,13 @@ + + + + +