MudEngine:
- Fixed FileManager.GetDataSpan Index out of bounds exception. - Game.Save no long invokes the BaseCharacter.ExecuteCommand("Save"); rather it now just directly invokes BaseCharacter.Save(). This fixes the client typing bug where a new command line was printed to the screen everytime the game world saved. - GameWorld now supports storing and saving dynamically created Realms. - Renamed BaseCharacter.GetRoomByFilename() to just GetRoom() as all Get() named Methods require a filename. - Optimized the loading and saving of Realms, Zones and Rooms some. - Room now Loads and Saves the RoomLocation property instead of the Room's Zone and Realm properties individually. - GameWorld.GetRealm(), Realm.GetZone() and Zone.GetRoom() now perform case-insensitive checking when scanning for content. MudGame: - Re-wrote the 'Create' command script from the ground up. 50% less code and much better approach to creating content. Now to create content you will use the same formatting as the Room.RoomLocation property. Example: Creating a Realm is done with 'Create MyRealm' Example: Creating a Zone is done with 'Create MyRealm>MyZone' Example: Creating a Room is done with 'Create MyRealm>MyZone>MyRoom' If the Realm or Zone does not exist when creating a Room or Zone, then the parent will be created automatically for you. - Fixed a bug in the WorldCalifornia script were it was saving the Hallway Room with a Zone file extension, preventing it from working correctly during restoration.
This commit is contained in:
parent
de82476525
commit
de38cbf272
11 changed files with 204 additions and 300 deletions
|
@ -118,7 +118,7 @@ namespace MudEngine.FileSystem
|
||||||
String[] fileData = File.ReadAllLines(filename);
|
String[] fileData = File.ReadAllLines(filename);
|
||||||
Int32 line = 0;
|
Int32 line = 0;
|
||||||
|
|
||||||
while (line <= fileData.Length)
|
while (line <= fileData.Length - 1)
|
||||||
{
|
{
|
||||||
if (fileData[line].StartsWith(";"))
|
if (fileData[line].StartsWith(";"))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -327,7 +327,7 @@ namespace MudEngine.GameManagement
|
||||||
{
|
{
|
||||||
if (PlayerCollection[i].Name == "New BaseCharacter")
|
if (PlayerCollection[i].Name == "New BaseCharacter")
|
||||||
continue;
|
continue;
|
||||||
PlayerCollection[i].ExecuteCommand("Save");
|
PlayerCollection[i].Save(this.DataPaths.Players);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete the last saved version of the World. We will dump the current version onto disk.
|
//Delete the last saved version of the World. We will dump the current version onto disk.
|
||||||
|
@ -355,7 +355,10 @@ namespace MudEngine.GameManagement
|
||||||
FileManager.WriteLine(filename, this.DataPaths.Players, "DataPathPlayers");
|
FileManager.WriteLine(filename, this.DataPaths.Players, "DataPathPlayers");
|
||||||
FileManager.WriteLine(filename, this.GameTitle, "GameTitle");
|
FileManager.WriteLine(filename, this.GameTitle, "GameTitle");
|
||||||
FileManager.WriteLine(filename, this.HideRoomNames.ToString(), "HideRoomNames");
|
FileManager.WriteLine(filename, this.HideRoomNames.ToString(), "HideRoomNames");
|
||||||
FileManager.WriteLine(filename, this.InitialRealm.Filename, "InitialRealm");
|
|
||||||
|
if (this.InitialRealm.Name != "New Realm")
|
||||||
|
FileManager.WriteLine(filename, this.InitialRealm.Filename, "InitialRealm");
|
||||||
|
|
||||||
FileManager.WriteLine(filename, this.IsMultiplayer.ToString(), "IsMultiplayer");
|
FileManager.WriteLine(filename, this.IsMultiplayer.ToString(), "IsMultiplayer");
|
||||||
FileManager.WriteLine(filename, this.MaximumPlayers.ToString(), "MaximumPlayers");
|
FileManager.WriteLine(filename, this.MaximumPlayers.ToString(), "MaximumPlayers");
|
||||||
FileManager.WriteLine(filename, this.PreCacheObjects.ToString(), "PreCacheObjects");
|
FileManager.WriteLine(filename, this.PreCacheObjects.ToString(), "PreCacheObjects");
|
||||||
|
|
|
@ -117,6 +117,8 @@ namespace MudEngine.GameManagement
|
||||||
//Restore the Realm objects properties from file.
|
//Restore the Realm objects properties from file.
|
||||||
r.Load(Path.Combine(_Game.DataPaths.Environment, Path.GetFileNameWithoutExtension(realm), realm));
|
r.Load(Path.Combine(_Game.DataPaths.Environment, Path.GetFileNameWithoutExtension(realm), realm));
|
||||||
|
|
||||||
|
Boolean isFound = false;
|
||||||
|
|
||||||
//Loop through each of the Realm objects instanced during startup and find one matching the loaded filename
|
//Loop through each of the Realm objects instanced during startup and find one matching the loaded filename
|
||||||
for (int x = 0; x != RealmCollection.Count; x++)
|
for (int x = 0; x != RealmCollection.Count; x++)
|
||||||
{
|
{
|
||||||
|
@ -124,9 +126,13 @@ namespace MudEngine.GameManagement
|
||||||
if (RealmCollection[x].Filename == r.Filename)
|
if (RealmCollection[x].Filename == r.Filename)
|
||||||
{
|
{
|
||||||
RealmCollection[x] = r;
|
RealmCollection[x] = r;
|
||||||
|
isFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isFound)
|
||||||
|
RealmCollection.Add(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -182,7 +188,7 @@ namespace MudEngine.GameManagement
|
||||||
{
|
{
|
||||||
foreach (Realm r in RealmCollection)
|
foreach (Realm r in RealmCollection)
|
||||||
{
|
{
|
||||||
if (r.Filename == filename)
|
if (r.Filename.ToLower() == filename.ToLower())
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@
|
||||||
//TODO: determin which zone is the appropriate zone to assign if more than one exists.
|
//TODO: determin which zone is the appropriate zone to assign if more than one exists.
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Room> rooms = zone.GetRoomByFilename(FileManager.GetData(filename, "CurrentRoom"));
|
List<Room> rooms = zone.GetRoom(FileManager.GetData(filename, "CurrentRoom"));
|
||||||
|
|
||||||
if (rooms.Count == 0)
|
if (rooms.Count == 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -93,9 +93,9 @@ namespace MudEngine.GameObjects.Environment
|
||||||
Zone z = zlist[0];
|
Zone z = zlist[0];
|
||||||
|
|
||||||
//TODO: Load the Room via Game.World.GetRealm().GetZone(). Ensures that the Room is only loaded once in memory.
|
//TODO: Load the Room via Game.World.GetRealm().GetZone(). Ensures that the Room is only loaded once in memory.
|
||||||
if (z.GetRoomByFilename(path[2]) != null)
|
if (z.GetRoom(path[2]) != null)
|
||||||
{
|
{
|
||||||
List<Room> rlist = z.GetRoomByFilename(path[2]);
|
List<Room> rlist = z.GetRoom(path[2]);
|
||||||
|
|
||||||
if (roomType == RoomTravelType.Arrival)
|
if (roomType == RoomTravelType.Arrival)
|
||||||
ArrivalRoom = rlist[0];
|
ArrivalRoom = rlist[0];
|
||||||
|
|
|
@ -42,15 +42,12 @@ namespace MudEngine.GameObjects.Environment
|
||||||
|
|
||||||
IsInitialRealm = Convert.ToBoolean(FileManager.GetData(filename, "IsInitialRealm"));
|
IsInitialRealm = Convert.ToBoolean(FileManager.GetData(filename, "IsInitialRealm"));
|
||||||
|
|
||||||
String zoneFile = FileManager.GetData(filename, "InitialZone");
|
|
||||||
String realmPath = filename.Substring(0, filename.Length - Path.GetFileName(filename).Length);
|
|
||||||
String zonePath = Path.Combine(realmPath, "Zones", Path.GetFileNameWithoutExtension(zoneFile));
|
|
||||||
|
|
||||||
//Load all zones
|
//Load all zones
|
||||||
foreach (String zone in FileManager.GetCollectionData(filename, "ZoneCollection"))
|
foreach (String zone in FileManager.GetCollectionData(filename, "ZoneCollection"))
|
||||||
{
|
{
|
||||||
Zone z = new Zone(ActiveGame);
|
Zone z = new Zone(ActiveGame);
|
||||||
z.Load(Path.Combine(zonePath, zone));
|
String path = Path.Combine(ActiveGame.DataPaths.Environment, Path.GetFileNameWithoutExtension(this.Filename), "Zones", Path.GetFileNameWithoutExtension(zone));
|
||||||
|
z.Load(Path.Combine(path, zone));
|
||||||
|
|
||||||
//Check if this is the initial Zone.
|
//Check if this is the initial Zone.
|
||||||
if (z.IsInitialZone)
|
if (z.IsInitialZone)
|
||||||
|
@ -68,7 +65,8 @@ namespace MudEngine.GameObjects.Environment
|
||||||
String filename = Path.Combine(path, Filename);
|
String filename = Path.Combine(path, Filename);
|
||||||
|
|
||||||
FileManager.WriteLine(filename, this.IsInitialRealm.ToString(), "IsInitialRealm");
|
FileManager.WriteLine(filename, this.IsInitialRealm.ToString(), "IsInitialRealm");
|
||||||
FileManager.WriteLine(filename, this.InitialZone.Filename, "InitialZone");
|
if (this.InitialZone.Name != "New Zone")
|
||||||
|
FileManager.WriteLine(filename, this.InitialZone.Filename, "InitialZone");
|
||||||
|
|
||||||
String zonePath = Path.Combine(path, "Zones");
|
String zonePath = Path.Combine(path, "Zones");
|
||||||
foreach (Zone z in ZoneCollection)
|
foreach (Zone z in ZoneCollection)
|
||||||
|
@ -86,7 +84,7 @@ namespace MudEngine.GameObjects.Environment
|
||||||
|
|
||||||
foreach (Zone zone in ZoneCollection)
|
foreach (Zone zone in ZoneCollection)
|
||||||
{
|
{
|
||||||
if (zone.Filename == filename)
|
if (zone.Filename.ToLower() == filename.ToLower())
|
||||||
{
|
{
|
||||||
zones.Add(zone);
|
zones.Add(zone);
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,8 +106,7 @@ namespace MudEngine.GameObjects.Environment
|
||||||
|
|
||||||
FileManager.WriteLine(filename, IsInitialRoom.ToString(), "IsInitialRoom");
|
FileManager.WriteLine(filename, IsInitialRoom.ToString(), "IsInitialRoom");
|
||||||
FileManager.WriteLine(filename, this.IsSafe.ToString(), "IsSafe");
|
FileManager.WriteLine(filename, this.IsSafe.ToString(), "IsSafe");
|
||||||
FileManager.WriteLine(filename, this.Realm, "Realm");
|
FileManager.WriteLine(filename, this.RoomLocationWithoutExtension, "RoomLocation");
|
||||||
FileManager.WriteLine(filename, this.Zone, "Zone");
|
|
||||||
|
|
||||||
FileManager.WriteLine(filename, Doorways.Count.ToString(), "DoorwayCount");
|
FileManager.WriteLine(filename, Doorways.Count.ToString(), "DoorwayCount");
|
||||||
|
|
||||||
|
@ -128,8 +127,16 @@ namespace MudEngine.GameObjects.Environment
|
||||||
|
|
||||||
this.IsInitialRoom = Convert.ToBoolean(FileManager.GetData(filename, "IsInitialRoom"));
|
this.IsInitialRoom = Convert.ToBoolean(FileManager.GetData(filename, "IsInitialRoom"));
|
||||||
this.IsSafe = Convert.ToBoolean(FileManager.GetData(filename, "IsSafe"));
|
this.IsSafe = Convert.ToBoolean(FileManager.GetData(filename, "IsSafe"));
|
||||||
this.Realm = FileManager.GetData(filename, "Realm");
|
String[] env = FileManager.GetData(filename, "RoomLocation").Split('>');
|
||||||
this.Zone = FileManager.GetData(filename, "Zone");
|
|
||||||
|
if (env.Length != 3)
|
||||||
|
{
|
||||||
|
Log.Write("ERROR: Room " + filename + " does not contain a proper location path in Room.RoomLocation. Path is " + FileManager.GetData(filename, "RoomLocation"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Realm = env[0] + ".Realm";
|
||||||
|
this.Zone = env[1] + ".Zone";
|
||||||
|
|
||||||
//SetRoomToDoorNorth
|
//SetRoomToDoorNorth
|
||||||
//SetRoomToDoorEast
|
//SetRoomToDoorEast
|
||||||
|
|
|
@ -99,13 +99,15 @@ namespace MudEngine.GameObjects.Environment
|
||||||
FileManager.WriteLine(filename, this.Realm, "Realm");
|
FileManager.WriteLine(filename, this.Realm, "Realm");
|
||||||
FileManager.WriteLine(filename, this.StatDrain.ToString(), "StatDrain");
|
FileManager.WriteLine(filename, this.StatDrain.ToString(), "StatDrain");
|
||||||
FileManager.WriteLine(filename, this.StatDrainAmount.ToString(), "StatDrainAmount");
|
FileManager.WriteLine(filename, this.StatDrainAmount.ToString(), "StatDrainAmount");
|
||||||
FileManager.WriteLine(filename, this.InitialRoom.Filename, "InitialRoom");
|
|
||||||
|
if (this.InitialRoom.Name != "New Room")
|
||||||
|
FileManager.WriteLine(filename, this.InitialRoom.Filename, "InitialRoom");
|
||||||
|
|
||||||
String roomPath = Path.Combine(path, "Rooms");
|
String roomPath = Path.Combine(path, "Rooms");
|
||||||
foreach (Room r in RoomCollection)
|
foreach (Room r in RoomCollection)
|
||||||
{
|
{
|
||||||
FileManager.WriteLine(filename, r.Filename, "RoomCollection");
|
FileManager.WriteLine(filename, r.Filename, "RoomCollection");
|
||||||
r.Save(roomPath);
|
r.Save(roomPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,28 +121,16 @@ namespace MudEngine.GameObjects.Environment
|
||||||
this.StatDrain = Convert.ToBoolean(FileManager.GetData(filename, "StatDrain"));
|
this.StatDrain = Convert.ToBoolean(FileManager.GetData(filename, "StatDrain"));
|
||||||
this.StatDrainAmount = Convert.ToInt32(FileManager.GetData(filename, "StatDrainAmount"));
|
this.StatDrainAmount = Convert.ToInt32(FileManager.GetData(filename, "StatDrainAmount"));
|
||||||
|
|
||||||
//Load the InitialRoom
|
|
||||||
String roomFile = FileManager.GetData(filename, "InitialRoom");
|
|
||||||
String realmPath = Path.Combine(ActiveGame.DataPaths.Environment, Path.GetFileNameWithoutExtension(this.Realm));
|
|
||||||
String zonePath = Path.Combine(realmPath, "Zones", Path.GetFileNameWithoutExtension(this.Filename));
|
|
||||||
String roomPath = Path.Combine(zonePath, "Rooms");
|
|
||||||
|
|
||||||
//Now get the rooms in the zone
|
//Now get the rooms in the zone
|
||||||
foreach (String room in FileManager.GetCollectionData(filename, "RoomCollection"))
|
foreach (String room in FileManager.GetCollectionData(filename, "RoomCollection"))
|
||||||
{
|
{
|
||||||
Room r = new Room(ActiveGame);
|
Room r = new Room(ActiveGame);
|
||||||
r.Load(Path.Combine(roomPath, room));
|
String path = Path.Combine(ActiveGame.DataPaths.Environment, Path.GetFileNameWithoutExtension(this.Realm), "Zones", Path.GetFileNameWithoutExtension(this.Filename), "Rooms");
|
||||||
|
r.Load(Path.Combine(path, room));
|
||||||
RoomCollection.Add(r);
|
RoomCollection.Add(r);
|
||||||
}
|
|
||||||
|
|
||||||
//Set the initial Room.
|
|
||||||
foreach (Room r in RoomCollection)
|
|
||||||
{
|
|
||||||
if (r.IsInitialRoom)
|
if (r.IsInitialRoom)
|
||||||
{
|
this.InitialRoom = r;
|
||||||
InitialRoom = r;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,14 +162,14 @@ namespace MudEngine.GameObjects.Environment
|
||||||
room.Realm = Realm;
|
room.Realm = Realm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Room> GetRoomByFilename(String filename)
|
public List<Room> GetRoom(String filename)
|
||||||
{
|
{
|
||||||
|
|
||||||
List<Room> rooms = new List<Room>();
|
List<Room> rooms = new List<Room>();
|
||||||
|
|
||||||
foreach (Room r in RoomCollection)
|
foreach (Room r in RoomCollection)
|
||||||
{
|
{
|
||||||
if (r.Filename == filename)
|
if (r.Filename.ToLower() == filename.ToLower())
|
||||||
{
|
{
|
||||||
rooms.Add(r);
|
rooms.Add(r);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Include="Scripts\CommandCreate.cs">
|
<None Include="Scripts\CommandCreate.cs">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Include="Scripts\CommandSay.cs">
|
<None Include="Scripts\CommandSay.cs">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
|
|
@ -25,6 +25,11 @@ public class CommandCreate : IGameCommand
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<String> Help { get; set; }
|
public List<String> Help { get; set; }
|
||||||
|
|
||||||
|
//Private fields that are used during the creation of the environments.
|
||||||
|
private Realm realm;
|
||||||
|
private Zone zone;
|
||||||
|
private Room room;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor for the class.
|
/// Constructor for the class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -35,305 +40,200 @@ public class CommandCreate : IGameCommand
|
||||||
Help.Add("Content is created at run-time while the server/game is running and players are connected.");
|
Help.Add("Content is created at run-time while the server/game is running and players are connected.");
|
||||||
Help.Add("Newly created content will be available for players to use/traverse immediately after creation is completed.");
|
Help.Add("Newly created content will be available for players to use/traverse immediately after creation is completed.");
|
||||||
Help.Add("Rooms that are created may be linked together using the LinkRoom command.");
|
Help.Add("Rooms that are created may be linked together using the LinkRoom command.");
|
||||||
|
Help.Add("You may create Realms by simply supplying a Realm name. If you wish to create a Zone, you must specify the Realm name followed by a '>' then the Zone name.");
|
||||||
|
Help.Add("Example: 'Create MyRealm>MyZone'");
|
||||||
|
Help.Add("The same concept is applied for creating Rooms.");
|
||||||
|
Help.Add("Example: 'Create MyRealm>MyZone>MyRoom'");
|
||||||
|
Help.Add("Creating just a single Realm is used by supplying only the Realm name.");
|
||||||
|
Help.Add("Example: 'Create MyRealm'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This will execute the command allowing Admins to generate environment objects dynamically on-the-fly.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command"></param>
|
||||||
|
/// <param name="player"></param>
|
||||||
public void Execute(String command, BaseCharacter player)
|
public void Execute(String command, BaseCharacter player)
|
||||||
{
|
{
|
||||||
if ((player.Role == SecurityRoles.Player) || (player.Role == SecurityRoles.NPC))
|
//Check if the player has the proper security role in order to create content for the game world.
|
||||||
|
if ((player.Role != SecurityRoles.Admin) && (player.Role != SecurityRoles.GM))
|
||||||
{
|
{
|
||||||
return; //Don't let them know this even exists.
|
Log.Write("Player " + player.Name + " attempted to invoke the Create command without having the correct security role assigned!");
|
||||||
}
|
|
||||||
|
|
||||||
//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("At point during creation, you may type 'Cancel' to exit with no changes saved.");
|
|
||||||
player.Send("");
|
|
||||||
player.Send("Selection: ", false);
|
|
||||||
|
|
||||||
Int32 selection = 0;
|
|
||||||
String input = player.ReadInput();
|
|
||||||
|
|
||||||
//Allows for aborting the creation tool if the user wants too.
|
|
||||||
if (input.ToLower() == "cancel")
|
|
||||||
{
|
|
||||||
player.Send("Creation aborted.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
//Split the supplied string up. It wil give us an array of strings with the supplied
|
||||||
|
//object names if the admin has specified environment objects for creation.
|
||||||
|
String[] env = command.ToLower().Substring("Create ".Length).Split('>');
|
||||||
|
|
||||||
|
//No objects specified, so the admin didn't use the command correctly.
|
||||||
|
if (env.Length == 0)
|
||||||
{
|
{
|
||||||
selection = Convert.ToInt32(input);
|
player.Send("Invalid use of the 'Create' command. Please try 'Help Create' for help using the command.");
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
Log.Write("Invalid selection!");
|
|
||||||
player.Send("Invalid selection!");
|
|
||||||
player.Send("Creation aborted.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Fire off what ever Method we need to, according to the users input.
|
//Only 1 object name supplied, so we assume the admin wants a Realm created with the supplied name.
|
||||||
switch (selection)
|
else if (env.Length == 1)
|
||||||
{
|
{
|
||||||
case 1:
|
//Check if the supplied name is a valid Realm name, and if the Realm can be created.
|
||||||
CreateRealm(player);
|
//If it's valid, the Realm is instanced and stored in our private Field 'realm'
|
||||||
break;
|
Boolean validRealm = ValidateRealm(env[0], player);
|
||||||
case 2:
|
|
||||||
CreateZone(player);
|
if (validRealm)
|
||||||
break;
|
{
|
||||||
case 3:
|
player.ActiveGame.World.AddRealm(realm);
|
||||||
CreateRoom(player);
|
player.Send(env[0] + " created.");
|
||||||
break;
|
}
|
||||||
case 4:
|
//Add the 'realm' Field that was instanced via ValidateRealm
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Write("Failed to validate realm during dynamic Creation.");
|
||||||
|
player.Send("Failed to create Realm! Please ensure a duplicate file name does not exist!");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Recieved two names, so we assume the admin wants a Zone created.
|
||||||
|
//If the Realm that is supplied for this Zone does not create, we will create it.
|
||||||
|
else if (env.Length == 2)
|
||||||
|
{
|
||||||
|
//Check if the Realm name supplied already exists. If it does, this will return false (Invalid name due to already existing)
|
||||||
|
//If it returns true, then the Realm is valid, meaning non already exists, so we will create it.
|
||||||
|
Boolean validRealm = ValidateRealm(env[0], player);
|
||||||
|
|
||||||
|
//Add the Realm to the game world since this Zone is being created in a non-existant Realm.
|
||||||
|
if (validRealm)
|
||||||
|
{
|
||||||
|
player.ActiveGame.World.AddRealm(realm);
|
||||||
|
player.Send(env[0] + " created.");
|
||||||
|
}
|
||||||
|
Boolean validZone = ValidateZone(env[0], env[1], player);
|
||||||
|
|
||||||
|
if (validZone)
|
||||||
|
{
|
||||||
|
realm.AddZone(zone);
|
||||||
|
player.Send(env[1] + " created.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Write("Failed to validate Zone during dynamic creation.");
|
||||||
|
player.Send("Failed to create Zone! Please ensure a duplicate filename does not exist!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (env.Length == 3)
|
||||||
|
{
|
||||||
|
//Check if the Realm name supplied already exists. If it does, this will return false (Invalid name due to already existing)
|
||||||
|
//If it returns true, then the Realm is valid, meaning non already exists, so we will create it.
|
||||||
|
Boolean validRealm = ValidateRealm(env[0], player);
|
||||||
|
|
||||||
|
//Add the Realm to the game world since this Zone is being created in a non-existant Realm.
|
||||||
|
if (validRealm)
|
||||||
|
{
|
||||||
|
player.ActiveGame.World.AddRealm(realm);
|
||||||
|
player.Send(env[0] + " created.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean validZone = ValidateZone(env[0], env[1], player);
|
||||||
|
|
||||||
|
if (validZone)
|
||||||
|
{
|
||||||
|
realm.AddZone(zone);
|
||||||
|
player.Send(env[1] + " created.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean validRoom = ValidateRoom(env[0], env[1], env[2], player);
|
||||||
|
|
||||||
|
if (validRoom)
|
||||||
|
{
|
||||||
|
zone.AddRoom(room);
|
||||||
|
player.Send(env[2] + " created.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Write("Failed to validate Room during dynamic creation.");
|
||||||
|
player.Send("Failed to create Room! Please ensure a duplicate filename does not exist!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Creates a Realm.
|
/// <summary>
|
||||||
public void CreateRealm(BaseCharacter player)
|
/// Validates if the supplied Realm filename exists in the game world or not.
|
||||||
|
/// Returns True if it does not exist; False if it does exist (As if it exists it's not a valid name to use during creation).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <param name="player"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private Boolean ValidateRealm(String name, BaseCharacter player)
|
||||||
{
|
{
|
||||||
//Instance a new Realm.
|
if (player.ActiveGame.World.GetRealm(name + ".Realm") != null)
|
||||||
Realm realm = new Realm(player.ActiveGame);
|
|
||||||
Boolean isLegalName = false;
|
|
||||||
|
|
||||||
while (!isLegalName)
|
|
||||||
{
|
{
|
||||||
isLegalName = true;
|
realm = player.ActiveGame.World.GetRealm(name + ".Realm");
|
||||||
//Get the name of this Realm from the player.
|
return false;
|
||||||
player.Send("Realm Name: ", false);
|
|
||||||
realm.Name = player.ReadInput();
|
|
||||||
|
|
||||||
//Check for canceling
|
|
||||||
if (realm.Name.ToLower() == "cancel")
|
|
||||||
{
|
|
||||||
player.Send("Creation aborted.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//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!");
|
|
||||||
isLegalName = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.ActiveGame.World.AddRealm(realm);
|
realm = new Realm(player.ActiveGame);
|
||||||
Log.Write(player.Name + " has created a Realm called " + realm.Name);
|
realm.Name = name;
|
||||||
player.Send(realm.Name + " has been created and added to the world.");
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateZone(BaseCharacter player)
|
/// <summary>
|
||||||
|
/// Validates if the supplied Zone filename exists in the game world or not.
|
||||||
|
/// Returns True if it does not exist; False if it does exist (As if it exists it's not a valid name to use during creation).
|
||||||
|
/// If the Zones owning Realm does not exist, it returns false and fails.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="realmName"></param>
|
||||||
|
/// <param name="zoneName"></param>
|
||||||
|
/// <param name="player"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private Boolean ValidateZone(String realmName, String zoneName, BaseCharacter player)
|
||||||
{
|
{
|
||||||
player.Send("Select which Realm this Zone will belong to.");
|
if (realm == null)
|
||||||
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.
|
player.Send("Unable to validate Zone due to invalid Realm.");
|
||||||
foreach (Realm r in player.ActiveGame.World.RealmCollection)
|
return false;
|
||||||
{
|
|
||||||
player.Send(r.Filename + " | ", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
player.Send("");
|
|
||||||
player.Send("Selection: ", false);
|
|
||||||
|
|
||||||
input = player.ReadInput();
|
|
||||||
|
|
||||||
if (input.ToLower() == "cancel")
|
|
||||||
{
|
|
||||||
player.Send("Zone creation aborted.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//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);
|
if (realm.GetZone(zoneName + ".Zone").Count != 0)
|
||||||
//realm.AddZone(zone);
|
|
||||||
|
|
||||||
Boolean isValidZone = false;
|
|
||||||
player.Send(""); //blank line
|
|
||||||
|
|
||||||
while (!isValidZone)
|
|
||||||
{
|
{
|
||||||
isValidZone = true; //assume the user will enter a correct value.
|
zone = realm.GetZone(zoneName + ".Zone")[0];
|
||||||
player.Send("Enter a name for this Zone: ", false);
|
return 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Write(player.Name + " has created a Zone called " + zone.Name + " within the Realm " + realm.Name);
|
zone = new Zone(player.ActiveGame);
|
||||||
player.Send(zone.Name + " has been created and added to Realm " + realm.Name + ".");
|
zone.Name = zoneName;
|
||||||
realm.AddZone(zone);
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateRoom(BaseCharacter player)
|
/// <summary>
|
||||||
|
/// Validates if the supplied Room filename exists in the game world or not.
|
||||||
|
/// Returns True if it does not exist; False if it does exist (As if it exists it's not a valid name to use during creation).
|
||||||
|
/// If the Rooms owning Zone or Realm does not exist, it returns false and fails.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="realmName"></param>
|
||||||
|
/// <param name="zoneName"></param>
|
||||||
|
/// <param name="roomName"></param>
|
||||||
|
/// <param name="player"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private Boolean ValidateRoom(String realmName, String zoneName, String roomName, BaseCharacter player)
|
||||||
{
|
{
|
||||||
player.Send("Select which Realm this Zone will belong to.");
|
if ((realm == null) || (zone == null))
|
||||||
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.
|
player.Send("Unable to validate Room due to invalid Realm or Zone.");
|
||||||
foreach (Realm r in player.ActiveGame.World.RealmCollection)
|
return false;
|
||||||
{
|
|
||||||
player.Send(r.Filename + " | ", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
player.Send("");
|
|
||||||
player.Send("Selection: ", false);
|
|
||||||
|
|
||||||
input = player.ReadInput();
|
|
||||||
|
|
||||||
if (input.ToLower() == "cancel")
|
|
||||||
{
|
|
||||||
player.Send("Zone creation aborted.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//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);
|
if (zone.GetRoom(roomName + ".Room").Count != 0)
|
||||||
//realm.AddZone(zone);
|
|
||||||
|
|
||||||
Boolean isValidZone = false;
|
|
||||||
player.Send(""); //blank line
|
|
||||||
|
|
||||||
while (!isValidZone)
|
|
||||||
{
|
{
|
||||||
isValidZone = true;//Default to true, assume the user entered a valid name.
|
room = zone.GetRoom(roomName + ".Room")[0];
|
||||||
foreach (Zone z in realm.ZoneCollection)
|
return false;
|
||||||
{
|
|
||||||
player.Send(z.Filename + " | ", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
player.Send("");
|
|
||||||
player.Send("Selection: ", false);
|
|
||||||
|
|
||||||
input = player.ReadInput();
|
|
||||||
|
|
||||||
if (input.ToLower() == "cancel")
|
|
||||||
{
|
|
||||||
player.Send("Room creation aborted.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Ensure it's a valid name, if not then loop back and try again.
|
|
||||||
foreach (Zone z in realm.ZoneCollection)
|
|
||||||
{
|
|
||||||
if (z.Filename.ToLower() == input.ToLower())
|
|
||||||
{
|
|
||||||
isValidZone = true;
|
|
||||||
zone = z;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
isValidZone = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isValidZone)
|
|
||||||
player.Send("That Zone does not exist! Please try again.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create the Room.
|
room = new Room(player.ActiveGame);
|
||||||
Room room = new Room(player.ActiveGame);
|
room.Name = roomName;
|
||||||
|
|
||||||
Boolean isValidRoom = false;
|
return true;
|
||||||
player.Send(""); //blank line
|
|
||||||
|
|
||||||
while (!isValidRoom)
|
|
||||||
{
|
|
||||||
isValidRoom = true; //assume the user will enter a correct value.
|
|
||||||
player.Send("Enter a name for this Room: ", false);
|
|
||||||
String name = player.ReadInput();
|
|
||||||
|
|
||||||
if (String.IsNullOrEmpty(name))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
foreach (Room r in zone.RoomCollection)
|
|
||||||
{
|
|
||||||
if (r.Name == name)
|
|
||||||
{
|
|
||||||
isValidRoom = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isValidRoom)
|
|
||||||
{
|
|
||||||
room.Name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Log.Write(player.Name + " has created a Room called " + zone.Name + " within the Zone " + realm.Name + "->" + zone.Name);
|
|
||||||
player.Send(room.Name + " has been created and added to " + realm.Name + "->" + zone.Name + ".");
|
|
||||||
zone.AddRoom(room);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -81,7 +81,7 @@ public class WorldCalifornia
|
||||||
//Note that assigning a new Filename must be done AFTER assigning the objects Name property a value.
|
//Note that assigning a new Filename must be done AFTER assigning the objects Name property a value.
|
||||||
//Each time a objects Name property is assigned a value, it automatically generates a filename.
|
//Each time a objects Name property is assigned a value, it automatically generates a filename.
|
||||||
//If a Filename is assigned prior to assigning the Name property, your previous Filename will be over-wrote.
|
//If a Filename is assigned prior to assigning the Name property, your previous Filename will be over-wrote.
|
||||||
myHallway.Filename = myHallway.Name + "1.Zone";
|
myHallway.Filename = myHallway.Name + "1.Room";
|
||||||
|
|
||||||
//Add the Room to the previously created Zone.
|
//Add the Room to the previously created Zone.
|
||||||
myZone.AddRoom(myHallway);
|
myZone.AddRoom(myHallway);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue