// Apply complete cycle of basic processing (open-close) static void ProcessBasicFile(string fileName) { CSVFile file = GenericOpen(fileName); GenericProcess(file); GenericClose(file); }
// Use the Junk Scrap and Component Quantity CSVFiles to generate a new file for Quantified Junk Scrap public static CSVFile ProcessJunkScrap(CSVFile junkFile, CSVFile componentQuantity) { string newFileHeader = junkFile.header; List <CSVRow> newFileRows = new List <CSVRow>(); foreach (CSVRow row in junkFile.rows) { string component = row.GetCellFromColumn("component"); string formID = row.GetCellFromColumn("junkFormID"); string lookupQuantity = row.GetCellFromColumn("componentQuantity"); int quantity = -1; // Find what the quantity is by looking up against the componentQuantity foreach (CSVRow quantityRow in componentQuantity.rows) { // Find the row where this component quantities are stored if (quantityRow.GetCellFromColumn("component") == component) { quantity = int.Parse(quantityRow.GetCellFromColumn(lookupQuantity)); } } string newRow = component + "," + quantity + "," + formID; newFileRows.Add(new CSVRow(newRow, newFileHeader)); } return(new CSVFile("SeventySix_Quantified_Scrap.csv", "component,componentQuantity,junkFormID", newFileRows)); }
// Apply the standard processing to a given coordinate file (Worldspace or interior) static void ProcessSpatialFile(string fileName) { CSVFile file = GenericOpen(fileName); file = NpcSpawnHelper.AddMonsterClassColumn(file); GenericProcess(file); GenericClose(file); }
// Validate the file, write it to disk and free the memory. static void GenericClose(CSVFile file) { file.Validate(); Directory.CreateDirectory(outputPathx64); file.WriteToFile(outputPathx64 + "//"); file.rows = null; GC.Collect(); Console.WriteLine(file.fileName + " done."); }
// Process the location CSVFile and then use it to generate a new file for NPCSpawns static void GenerateNPCSpawnFile() { CSVFile locationFile = GenericOpen("SeventySix_Location.csv"); GenericProcess(locationFile); CSVFile npcSpawns = NpcSpawnHelper.ProcessNPCSpawns(locationFile, NpcSpawnHelper.SumLocationSpawnChances(locationFile)); locationFile.rows = null; GenericProcess(npcSpawns); GenericClose(npcSpawns); }
// Using the actual locations file, and the pre-summed total odds for each location, calculate each spawn chance into an absolute chance public static CSVFile ProcessNPCSpawns(CSVFile locationFile, List <Location> spawnChances) { string npcSpawnHeader = "npc,spawnClass,locationFormID,chance"; List <CSVRow> rows = new List <CSVRow>(); foreach (CSVRow row in locationFile.rows) { string rowNPC = row.GetCellFromColumn("property"); string rowFormID = row.GetCellFromColumn("locationFormID"); // Calculate the 'class' (Main or Sub) string rowClass; if (rowNPC.Contains("Main")) { rowClass = "Main"; } else if (rowNPC.Contains("Sub")) { rowClass = "Sub"; } else { continue; } rowNPC = TrimNPCName(rowNPC); // Get the overall spawning odds for this location double locationOverallOdds = 0; foreach (Location spawnChance in spawnChances) { if (spawnChance.locationFormID == rowFormID) { locationOverallOdds = spawnChance.GetOdds(rowClass); } } // The NPC spawn chance is its individual chance over the sum spawn chances of the given location double rowSpawnChance = double.Parse(row.GetCellFromColumn("value")) / locationOverallOdds; rows.Add(new CSVRow(rowNPC + "," + rowClass + "," + rowFormID + "," + rowSpawnChance, npcSpawnHeader)); } return(new CSVFile("SeventySix_NPCSpawn.csv", string.Join(",", npcSpawnHeader), rows)); }
// For the Worldspace and Interior files, where monsters spawn, we should record the 'class' of monster spawn in a new column public static CSVFile AddMonsterClassColumn(CSVFile inputFile) { string newFileHeader = inputFile.header + ",spawnClass"; inputFile.header = newFileHeader; List <CSVRow> newFileRows = new List <CSVRow>(); // Add a new column for monster spawn class, or blank if not found foreach (CSVRow row in inputFile.rows) { string monsterClass = GetClassFromName(row.GetCellFromColumn("referenceFormID")); string newRow = row.ToString() + "," + monsterClass; newFileRows.Add(new CSVRow(newRow, newFileHeader)); } return(new CSVFile(inputFile.fileName, newFileHeader, newFileRows)); }
// Process the Junk Scrap and Component Quantity CSVFiles and then use them to generate a new file for Quantified Junk Scrap static void GenerateQuantifiedJunkScrapFile() { CSVFile componentQuantityFile = GenericOpen("SeventySix_Component_Quantity.csv"); GenericProcess(componentQuantityFile); CSVFile junkScrapFile = GenericOpen("SeventySix_Junk_Scrap.csv"); GenericProcess(junkScrapFile); CSVFile quantifiedJunkScrap = JunkScrap.ProcessJunkScrap(junkScrapFile, componentQuantityFile); junkScrapFile.rows = null; componentQuantityFile.rows = null; GenericProcess(quantifiedJunkScrap); GenericClose(quantifiedJunkScrap); }
// Sum the different spawn odds for each location public static List <Location> SumLocationSpawnChances(CSVFile file) { List <Location> spawnChances = new List <Location>(); foreach (CSVRow row in file.rows) { // skip the entries that are not ESSChance AKA monster spawns if (!row.GetCellFromColumn("property").Contains("ESSChance")) { continue; } string locationFormID = row.GetCellFromColumn("locationFormID"); // verify if the location already has an entry bool newEntry = true; foreach (Location locationSpawnChance in spawnChances) { // Use the existing location as already on record if (locationSpawnChance.locationFormID == locationFormID) { locationSpawnChance.AddOdds(row.GetCellFromColumn("value"), row.GetCellFromColumn("property")); newEntry = false; break; } } if (newEntry) { // The location is new to us, so create a new entry Location locChance = new Location(locationFormID); locChance.AddOdds(row.GetCellFromColumn("value"), row.GetCellFromColumn("property")); spawnChances.Add(locChance); } } return(spawnChances); }
// Apply the standard processing to the CSVFile static void GenericProcess(CSVFile file) { file.Sanitize(); file.ReduceReferences(); file.ReduceDecimals(); }