AmmoParams GetAmmoParams(EntityClassDefinition item) { // If this a weapon that contains its own ammo, or if it is a magazine, then it will have an SCAmmoContainerComponentParams component. var ammoRef = item.Components.SAmmoContainerComponentParams?.ammoParamsRecord; if (ammoRef != null) { return(ammoSvc.GetByReference(ammoRef)); } // Otherwise if this is a weapon then SCItemWeaponComponentParams.ammoContainerRecord should be the reference of a magazine entity var magRef = item.Components.SCItemWeaponComponentParams?.ammoContainerRecord; if (magRef == null) { return(null); } var mag = entitySvc.GetByReference(magRef); if (mag == null) { return(null); } // And the magazine's SAmmoContainerComponentParams will tell us about the ammo return(ammoSvc.GetByReference(mag.Components.SAmmoContainerComponentParams.ammoParamsRecord)); }
public List <ItemIndexEntry> Load(string typeFilter = null) { Directory.CreateDirectory(Path.Combine(OutputFolder, "items")); Directory.CreateDirectory(Path.Combine(OutputFolder, "v2", "items")); var damageResistanceMacros = LoadDamageResistanceMacros(); Console.WriteLine($"ItemLoader: Creating index..."); var index = CreateIndex(typeFilter); // 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 Console.WriteLine($"ItemLoader: Creating {index.Count} item files..."); foreach (var item in index) { var entity = entitySvc.GetByClassName(item.className); // If uses an ammunition magazine, then load it EntityClassDefinition magazine = null; if (!String.IsNullOrEmpty(entity.Components?.SCItemWeaponComponentParams?.ammoContainerRecord)) { magazine = entitySvc.GetByReference(entity.Components.SCItemWeaponComponentParams.ammoContainerRecord); } // If it is an ammo container or if it has a magazine then load the ammo properties AmmoParams ammoEntry = null; var ammoRef = magazine?.Components?.SAmmoContainerComponentParams?.ammoParamsRecord ?? entity.Components?.SAmmoContainerComponentParams?.ammoParamsRecord; if (!String.IsNullOrEmpty(ammoRef)) { ammoEntry = ammoSvc.GetByReference(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; } var stdItem = itemBuilder.BuildItem(entity); var loadout = loadoutLoader.Load(entity); itemInstaller.InstallLoadout(stdItem, loadout); stdItem.Classification = item.classification; item.stdItem = stdItem; File.WriteAllText(Path.Combine(OutputFolder, "v2", "items", $"{entity.ClassName.ToLower()}.json"), JsonConvert.SerializeObject(stdItem)); File.WriteAllText(Path.Combine(OutputFolder, "v2", "items", $"{entity.ClassName.ToLower()}-raw.json"), JsonConvert.SerializeObject(entity)); // 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); }