private void LoadUniverseData(string Filename)
{
if (File.Exists(Filename))
{
StreamReader file = null;
try
{
var rx = new System.Text.RegularExpressions.Regex(@"\s+");
string line;
file = new StreamReader(Filename);
while ((line = file.ReadLine()) != null)
{
line = rx.Replace(line, @" ");
string[] data = line.Split(' ');
if (data.Length == 0) continue; //check only lines with data in them
//packet data
if (data[0].Equals("p") && data.Length >= 2)
{
int packettype = int.Parse(data[1]);
switch (packettype)
{
case 0x34: //new scene
{
int WorldID = int.Parse(data[2]);
World w = GetWorld(WorldID);
w.AddScene(line);
}
break;
case 0x37: //reveal world
{
int WorldID = int.Parse(data[2]);
World w = GetWorld(WorldID);
w.WorldSNO = int.Parse(data[3]);
}
break;
case 0x3b: //new actor
{
int WorldID = int.Parse(data[16]);
World w = GetWorld(WorldID);
w.AddActor(line);
}
break;
case 0x44: //new map scene
{
int WorldID = int.Parse(data[11]);
World w = GetWorld(WorldID);
w.AddMapScene(line);
}
break;
case 0x4b: //new portal
{
Actor a = GetActor(int.Parse(data[2]));
if (a != null)
{
World w = GetWorld(a.WorldId);
if (w != null) w.AddPortal(line);
}
}
break;
default:
Logger.Info("Unimplemented packet type encountered in universe file: " + packettype);
break;
}
}
//manual portal description
if (data[0].Equals("o") && data.Length >= 6)
{
Portal p = GetPortal(int.Parse(data[1]));
if (p != null)
{
p.TargetPos = new Vector3D();
p.TargetPos.X = float.Parse(data[2], System.Globalization.CultureInfo.InvariantCulture);
p.TargetPos.Y = float.Parse(data[3], System.Globalization.CultureInfo.InvariantCulture);
p.TargetPos.Z = float.Parse(data[4], System.Globalization.CultureInfo.InvariantCulture);
p.TargetWorldID = int.Parse(data[5]);
}
}
////spawn point
//if (data[0].Equals("s") && data.Length >= 4)
//{
// posx = float.Parse(data[1], System.Globalization.CultureInfo.InvariantCulture);
// posy = float.Parse(data[2], System.Globalization.CultureInfo.InvariantCulture);
// posz = float.Parse(data[3], System.Globalization.CultureInfo.InvariantCulture);
//}
}
}
catch (Exception e)
{
Logger.DebugException(e, "LoadUniverseData");
}
finally
{
if (file != null)
file.Close();
}
}
else
{
Logger.Error("Universe file {0} not found!", Filename);
}
foreach (World w in _worlds)
w.SortScenes();
}