public void parseTeleportLocations(NpcTeleporterTemplates npc_teleporters) { Console.WriteLine("Starting Teleport Parse ..."); Console.WriteLine("Loading level strings ..."); Utility.LoadLevelStrings(root); Console.WriteLine("Loading original teleport_location.xml ..."); Utility.LoadOriginalTeleporterLocationTemplate(root); //Unused for now //Console.WriteLine("Loading source_sphere.csv ..."); //DataSet source_sphere = loadExcelData(); TeleporterLocationTemplates outputFile = new TeleporterLocationTemplates(); outputFile.teleloc_templates = new List<TeleporterLocationTemplate>(); // Create IEnumerable<NpcTeleporterTemplate> of passed templates var teleporters = npc_teleporters.teleporter_templates.Where(n => n.teleportId != 0); // Create List of loca_id that have already been processed List<int> processed = new List<int>(); // Parse location for each template foreach (var teleport in teleporters) { var locations = teleport.locations.telelocation.Where(n => n.loc_id != 0); foreach (var location in locations) { TeleporterLocationTemplate template = new TeleporterLocationTemplate(); // Skip if location already added if (processed.Contains(location.loc_id)) continue; // Get Old Template if it exists TeleporterLocationTemplate original_template = Utility.OriginalTeleporterLocationTemplate[location.loc_id]; // Use original info if it exists in teleport_location.xml until more definitive info on x,y,z if (original_template != null) { template.loc_id = original_template.loc_id; template.mapid = original_template.mapid; template.name = original_template.name; template.posX = original_template.posX; template.posY = original_template.posY; template.posZ = original_template.posZ; template.heading = original_template.heading; template.type = location.type == TeleporterType.REGULAR ? "REGULAR" : "FLIGHT"; } else { template.loc_id = location.loc_id; //template.mapid = getMapIdFromString(Utility.AirlineIndex[teleport.teleportId]); template.mapid = getMapIdFromString(Utility.AirportIndex[location.loc_id]); template.name = location.description; template.type = location.type == TeleporterType.REGULAR ? "REGULAR" : "FLIGHT"; // Some trickery to get spawn point from mission file if (template.type != "FLIGHT") { string[] split = location.name.Split('_'); // Special cases where map name is shortened if (split[0].StartsWith("HLFP")) split[0] = "HLFP"; if (split[0].StartsWith("HDFP")) split[0] = "HDFP"; switch (split[0]) { case "HLFP": split[0] = "housing_lf_personal"; break; case "HDFP": split[0] = "housing_df_personal"; break; } Point point = getPointFromLevelData(split[0], location.name); template.posX = point.x; template.posY = point.y; template.posZ = point.z; template.heading = point.heading; if (template.posX == 1) { template.posX = 1; } } } if (!processed.Contains(template.loc_id) && template.loc_id != 0) { processed.Add(template.loc_id); outputFile.teleloc_templates.Add(template); } } } // Reorder Templates outputFile.teleloc_templates = outputFile.teleloc_templates.OrderBy(n => n.loc_id).ToList<TeleporterLocationTemplate>(); string outputPath = Path.Combine(root, @".\output"); if (!Directory.Exists(outputPath)) Directory.CreateDirectory(outputPath); var settings = new XmlWriterSettings() { CheckCharacters = false, CloseOutput = false, Indent = true, IndentChars = "\t", NewLineChars = "\n", Encoding = new UTF8Encoding(false) }; using (var fs = new FileStream(Path.Combine(outputPath, "teleport_location.xml"), FileMode.Create, FileAccess.Write)) using (var writer = XmlWriter.Create(fs, settings)) { XmlSerializer ser = new XmlSerializer(typeof(TeleporterLocationTemplates)); ser.Serialize(writer, outputFile); } }
public void parseTeleportLocations(NpcTeleporterTemplates npc_teleporters) { Console.WriteLine("Starting Teleport Parse ..."); Console.WriteLine("Loading level strings ..."); Utility.LoadLevelStrings(root); Console.WriteLine("Loading original teleport_location.xml ..."); Utility.LoadOriginalTeleporterLocationTemplate(root); //Unused for now //Console.WriteLine("Loading source_sphere.csv ..."); //DataSet source_sphere = loadExcelData(); TeleporterLocationTemplates outputFile = new TeleporterLocationTemplates(); outputFile.teleloc_templates = new List <TeleporterLocationTemplate>(); // Create IEnumerable<NpcTeleporterTemplate> of passed templates var teleporters = npc_teleporters.teleporter_templates.Where(n => n.teleportId != 0); // Create List of loca_id that have already been processed List <int> processed = new List <int>(); // Parse location for each template foreach (var teleport in teleporters) { var locations = teleport.locations.telelocation.Where(n => n.loc_id != 0); foreach (var location in locations) { TeleporterLocationTemplate template = new TeleporterLocationTemplate(); // Skip if location already added if (processed.Contains(location.loc_id)) { continue; } // Get Old Template if it exists TeleporterLocationTemplate original_template = Utility.OriginalTeleporterLocationTemplate[location.loc_id]; // Use original info if it exists in teleport_location.xml until more definitive info on x,y,z if (original_template != null) { template.loc_id = original_template.loc_id; template.mapid = original_template.mapid; template.name = original_template.name; template.posX = original_template.posX; template.posY = original_template.posY; template.posZ = original_template.posZ; template.heading = original_template.heading; template.type = location.type == TeleporterType.REGULAR ? "REGULAR" : "FLIGHT"; } else { template.loc_id = location.loc_id; //template.mapid = getMapIdFromString(Utility.AirlineIndex[teleport.teleportId]); template.mapid = getMapIdFromString(Utility.AirportIndex[location.loc_id]); template.name = location.description; template.type = location.type == TeleporterType.REGULAR ? "REGULAR" : "FLIGHT"; // Some trickery to get spawn point from mission file if (template.type != "FLIGHT") { string[] split = location.name.Split('_'); // Special cases where map name is shortened if (split[0].StartsWith("HLFP")) { split[0] = "HLFP"; } if (split[0].StartsWith("HDFP")) { split[0] = "HDFP"; } switch (split[0]) { case "HLFP": split[0] = "housing_lf_personal"; break; case "HDFP": split[0] = "housing_df_personal"; break; } Point point = getPointFromLevelData(split[0], location.name); template.posX = point.x; template.posY = point.y; template.posZ = point.z; template.heading = point.heading; if (template.posX == 1) { template.posX = 1; } } } if (!processed.Contains(template.loc_id) && template.loc_id != 0) { processed.Add(template.loc_id); outputFile.teleloc_templates.Add(template); } } } // Reorder Templates outputFile.teleloc_templates = outputFile.teleloc_templates.OrderBy(n => n.loc_id).ToList <TeleporterLocationTemplate>(); string outputPath = Path.Combine(root, @".\output"); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } var settings = new XmlWriterSettings() { CheckCharacters = false, CloseOutput = false, Indent = true, IndentChars = "\t", NewLineChars = "\n", Encoding = new UTF8Encoding(false) }; using (var fs = new FileStream(Path.Combine(outputPath, "teleport_location.xml"), FileMode.Create, FileAccess.Write)) using (var writer = XmlWriter.Create(fs, settings)) { XmlSerializer ser = new XmlSerializer(typeof(TeleporterLocationTemplates)); ser.Serialize(writer, outputFile); } }