public void InstallLoadout(StandardisedItemPort port, List <StandardisedLoadoutEntry> loadout) { var loadoutEntry = FindLoadoutEntry(port.PortName, loadout); if (String.IsNullOrEmpty(loadoutEntry?.ClassName)) { return; } port.Loadout = loadoutEntry.ClassName; var item = entitySvc.GetByClassName(loadoutEntry.ClassName); if (item == null) { return; } var standardisedItem = itemBuilder.BuildItem(item); port.InstalledItem = standardisedItem; // Update the loadout with anything this item brings with it var newLoadout = loadoutLoader.Load(item); loadoutEntry.Entries.AddRange(newLoadout); InstallLoadout(standardisedItem.Ports, loadoutEntry.Entries); }
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); }