public List <ItemIndexEntry> Load() { Directory.CreateDirectory(Path.Combine(OutputFolder, "items")); var damageResistanceMacros = LoadDamageResistanceMacros(); var index = new List <ItemIndexEntry>(); index.AddRange(Load(@"Data\Libs\Foundry\Records\entities\scitem")); // Once all the items have been loaded, we have to spin through them again looking for // any that use ammunition magazines so we can load the magazine and then load the ammunition it uses foreach (var item in index) { var entity = ClassParser <EntityClassDefinition> .ClassByNameCache[item.className]; // If uses an ammunition magazine, then load it EntityClassDefinition magazine = null; if (!String.IsNullOrEmpty(entity.Components?.SCItemWeaponComponentParams?.ammoContainerRecord)) { magazine = ClassParser <EntityClassDefinition> .ClassByRefCache.GetValueOrDefault(entity.Components.SCItemWeaponComponentParams.ammoContainerRecord); } // If it is an ammo container or if it has a magazine then load the ammo properties AmmoIndexEntry ammoEntry = null; var ammoRef = magazine?.Components?.SAmmoContainerComponentParams?.ammoParamsRecord ?? entity.Components?.SAmmoContainerComponentParams?.ammoParamsRecord; if (!String.IsNullOrEmpty(ammoRef)) { ammoEntry = Ammo.FirstOrDefault(x => x.reference == ammoRef); } DamageResistance damageResistances = null; if (!String.IsNullOrEmpty(entity.Components?.SCItemSuitArmorParams?.damageResistance)) { var damageMacro = damageResistanceMacros.Find(y => y.__ref == entity.Components.SCItemSuitArmorParams.damageResistance); damageResistances = damageMacro?.damageResistance; } // Write the JSON of this entity to its own file var jsonFilename = Path.Combine(OutputFolder, "items", $"{entity.ClassName.ToLower()}.json"); var json = JsonConvert.SerializeObject(new { magazine = magazine, ammo = ammoEntry, Raw = new { Entity = entity, }, damageResistances = damageResistances }); File.WriteAllText(jsonFilename, json); } File.WriteAllText(Path.Combine(OutputFolder, "items.json"), JsonConvert.SerializeObject(index)); // Create an index file for each different item type var typeIndicies = new Dictionary <string, List <ItemIndexEntry> >(); foreach (var entry in index) { if (String.IsNullOrEmpty(entry.classification)) { continue; } var type = entry.classification.Split('.')[0]; if (!typeIndicies.ContainsKey(type)) { typeIndicies.Add(type, new List <ItemIndexEntry>()); } var typeIndex = typeIndicies[type]; typeIndex.Add(entry); } foreach (var pair in typeIndicies) { File.WriteAllText(Path.Combine(OutputFolder, pair.Key.ToLower() + "-items.json"), JsonConvert.SerializeObject(pair.Value)); } return(index); }