From 3110b74b58e914f308a1fad0366a988e13e1148a Mon Sep 17 00:00:00 2001 From: Scionwest_cp Date: Sun, 15 Aug 2010 14:57:41 -0700 Subject: [PATCH] MudEngine: - Script Engine now compiles scripts as C# 4.0 Types instead of 3.5. Scripts can now use Dynamic Types. MudGame: - CommandCreate script added. Provides Admins the ability to create Realms and Zones from within the game during runtime. At the moment Realm creation and Zone creation (and placement within Realms) is implemented. --- MudEngine/Scripting/ScriptEngine.cs | 3 +- MudGame/MudGame.csproj | 3 + MudGame/Scripts/CommandCreate.cs | 127 ++++++++++++++++++ .../bin/Debug/Scripts/..svnbridge/.svnbridge | 5 + MudGame/bin/Debug/Scripts/WorldCalifornia.cs | 50 +++++++ 5 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 MudGame/Scripts/CommandCreate.cs create mode 100644 MudGame/bin/Debug/Scripts/..svnbridge/.svnbridge create mode 100644 MudGame/bin/Debug/Scripts/WorldCalifornia.cs diff --git a/MudEngine/Scripting/ScriptEngine.cs b/MudEngine/Scripting/ScriptEngine.cs index 35f8ca2..6223d04 100644 --- a/MudEngine/Scripting/ScriptEngine.cs +++ b/MudEngine/Scripting/ScriptEngine.cs @@ -169,7 +169,7 @@ namespace MudEngine.Scripting //Prepare the compiler. Dictionary providerOptions = new Dictionary(); - providerOptions.Add("CompilerVersion", "v3.5"); + providerOptions.Add("CompilerVersion", "v4.0"); CompilerParameters param = new CompilerParameters(new String[] {"mscorlib.dll", "System.dll", "MudEngine.dll"}); param.GenerateExecutable = false; @@ -182,6 +182,7 @@ namespace MudEngine.Scripting //Compile the scripts with the C# CodeProvider CSharpCodeProvider codeProvider = new CSharpCodeProvider(providerOptions); + //codeProvider.LanguageOptions = LanguageOptions.CaseInsensitive; CompilerResults results = new CompilerResults(new TempFileCollection()); scripts = Directory.GetFiles(ScriptPath, "*" + ScriptExtension, SearchOption.AllDirectories); results = codeProvider.CompileAssemblyFromFile(param, scripts); diff --git a/MudGame/MudGame.csproj b/MudGame/MudGame.csproj index 50a581a..3facf31 100644 --- a/MudGame/MudGame.csproj +++ b/MudGame/MudGame.csproj @@ -45,6 +45,9 @@ + + PreserveNewest + PreserveNewest diff --git a/MudGame/Scripts/CommandCreate.cs b/MudGame/Scripts/CommandCreate.cs new file mode 100644 index 0000000..f994496 --- /dev/null +++ b/MudGame/Scripts/CommandCreate.cs @@ -0,0 +1,127 @@ + public class CommandCreate : IGameCommand + { + public Boolean Override { get; set; } + public String Name { get; set; } + + public void Execute(String command, BaseCharacter player) + { + if ((player.Role == SecurityRoles.Player) || (player.Role == SecurityRoles.NPC)) + { + return; //Don't let them know this even exists. + } + + //Build our create menu. + player.Send(""); + player.Send("Welcome to " + player.ActiveGame.GameTitle + " World Creation Tool."); + player.Send("What would you like to create?"); + player.Send(""); + player.Send("1: Realm"); + player.Send("2: Zone"); + player.Send("3: Room"); + player.Send("4: Exit Tool"); + player.Send("Selection: ", false); + Int32 selection = Convert.ToInt32(player.ReadInput()); + + //Fire off what ever Method we need to, according to the users input. + switch (selection) + { + case 1: + CreateRealm(player); + break; + case 2: + CreateZone(player); + break; + } + } + + //Creates a Realm. + public void CreateRealm(BaseCharacter player) + { + //Instance a new Realm. + Realm realm = new Realm(player.ActiveGame); + + //Get the name of this Realm from the player. + player.Send("Realm Name: ", false); + realm.Name = player.ReadInput(); + + //Check if a Realm with this name already exists. + foreach (Realm r in player.ActiveGame.World.RealmCollection) + { + if (r.Name == realm.Name) + { + player.Send("Realm already exists!"); + } + } + + player.ActiveGame.World.AddRealm(realm); + player.Send(realm.Name + " has been created and added to the world."); + } + + public void CreateZone(BaseCharacter player) + { + player.Send("Select which Realm this Zone will belong to."); + Boolean isValidRealm = false; + String input = ""; + Realm realm = new Realm(player.ActiveGame); + + while (!isValidRealm) + { + isValidRealm = true;//Default to true, assume the user entered a valid name. + foreach (Realm r in player.ActiveGame.World.RealmCollection) + { + player.Send(r.Filename + " | ", false); + } + + input = player.ReadInput(); + + //Ensure it's a valid name, if not then loop back and try again. + foreach (Realm r in player.ActiveGame.World.RealmCollection) + { + if (r.Filename.ToLower() == input.ToLower()) + { + isValidRealm = true; + realm = r; + break; + } + else + { + isValidRealm = false; + } + } + + if (!isValidRealm) + player.Send("That Realm does not exist! Please try again."); + } + + Zone zone = new Zone(player.ActiveGame); + realm.AddZone(zone); + + Boolean isValidZone = false; + + while (!isValidZone) + { + isValidZone = true; //assume the user will enter a correct value. + player.Send("Enter a name for this Zone: ", false); + String name = player.ReadInput(); + + if (String.IsNullOrEmpty(name)) + continue; + + foreach (Zone z in realm.ZoneCollection) + { + if (z.Name == name) + { + isValidZone = false; + break; + } + } + + if (isValidZone) + { + zone.Name = name; + } + } + + player.Send(zone.Name + " has been created and added to Realm " + realm.Name + "."); + } + } \ No newline at end of file diff --git a/MudGame/bin/Debug/Scripts/..svnbridge/.svnbridge b/MudGame/bin/Debug/Scripts/..svnbridge/.svnbridge new file mode 100644 index 0000000..5c1933d --- /dev/null +++ b/MudGame/bin/Debug/Scripts/..svnbridge/.svnbridge @@ -0,0 +1,5 @@ +svn:ignoreCommandClear.cs +CommandCreate.cs +CommandSay.cs +EarthGame.cs + \ No newline at end of file diff --git a/MudGame/bin/Debug/Scripts/WorldCalifornia.cs b/MudGame/bin/Debug/Scripts/WorldCalifornia.cs new file mode 100644 index 0000000..0e47cc6 --- /dev/null +++ b/MudGame/bin/Debug/Scripts/WorldCalifornia.cs @@ -0,0 +1,50 @@ +public class WorldCalifornia +{ + private Game _Game; + + public WorldCalifornia(Game game) + { + _Game = game; + } + + public void Create() + { + //Instance our Realm + Realm myRealm = new Realm(_Game); + myRealm.Name = "California"; + myRealm.Description = "The Beaches of California are relaxing and fun to be at."; + myRealm.IsInitialRealm = true; + _Game.World.AddRealm(myRealm); + + Zone myZone = new Zone(_Game); + myZone.Name = "San Diego"; + myZone.Realm = myRealm.Name; + myZone.Description = "San Diego has many attractions, including Sea World!"; + myZone.IsInitialZone = true; + myRealm.AddZone(myZone); + + //Create our HotelRoom + Room myRoom = new Room(_Game); + myRoom.Name = "Hotel Room B33"; + myRoom.IsInitialRoom = true; + myZone.AddRoom(myRoom); + myRoom.DetailedDescription.Add("Your Hotel Room is pretty clean, it is small but not to far off from the beach so you can't complain."); + myRoom.DetailedDescription.Add("You can exit your Hotel Room by walking West"); + + Room myHallway = new Room(_Game); + myHallway.Name = "Hotel Hallway"; + myHallway.DetailedDescription.Add("The Hotel Hallway is fairly narrow, but there is plenty of room for people to traverse through it."); + myHallway.DetailedDescription.Add("Your Hotel Room B33 is to the East."); + myHallway.DetailedDescription.Add("Hotel Room B34 is to your West."); + myZone.AddRoom(myHallway); + myZone.LinkRooms(AvailableTravelDirections.West, myHallway, myRoom); + + Room nextRoom = new Room(_Game); + nextRoom.Name = "Hotel Room B34"; + nextRoom.DetailedDescription.Add("This Hotel Room is pretty dirty, they must not have cleaned it yet."); + nextRoom.DetailedDescription.Add("You can exit this room by walking East"); + myZone.AddRoom(nextRoom); + //Link + myZone.LinkRooms(AvailableTravelDirections.East, myHallway, nextRoom); + } +} \ No newline at end of file