muddesigner/MudGame/Scripts/CommandCreate.cs
Scionwest_cp f3b4c40010 MudEngine:
- GameTime updates; Still not fully functioning correctly.

MudGame:
 - Create command received some error checks when creating Realms.
2010-08-17 19:57:33 -07:00

135 lines
No EOL
4.7 KiB
C#

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);
Boolean isLegalName = false;
while (!isLegalName)
{
isLegalName = true;
//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!");
isLegalName = false;
}
}
}
player.ActiveGame.World.AddRealm(realm);
Log.Write(player.Name + " has created a Realm called " + realm.Name);
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;
}
}
Log.Write(player.Name + " has created a Zone called " + zone.Name + " within the Realm " + realm.Name);
player.Send(zone.Name + " has been created and added to Realm " + realm.Name + ".");
}
}