diff --git a/PMCGenerator/Program.cs b/PMCGenerator/Program.cs index 2a9aed1..4c0931b 100644 --- a/PMCGenerator/Program.cs +++ b/PMCGenerator/Program.cs @@ -13,7 +13,9 @@ namespace PMCGenerator { static void Main(string[] args) { - var presetPath = CreateInputFolder(); + var itemLibrary = GetItemLibraryFileAndParse(); + + var presetPath = CreateInputFolder("presets"); var presetFiles = GetPresetFileList(presetPath); @@ -41,6 +43,7 @@ namespace PMCGenerator // Get mods types for this gun, top level var uniqueModSlots = flatModList.Where(x => x.ParentId == weapon.Id).Select(x => x.SlotId).Distinct().ToList(); + uniqueModSlots.AddUnique("patron_in_weapon"); // Add bullet in chamber item foreach (var modSlotId in uniqueModSlots) { Dictionary> weaponModsToModify = output.mods[weapon.TemplateId]; @@ -51,13 +54,29 @@ namespace PMCGenerator } } + // Add compatible bullets to weapons gun chamber + var modItemToAddBulletsTo = output.mods[weapon.TemplateId].FirstOrDefault(x=> x.Key == "patron_in_weapon"); + var bulletTemplateIds = GetCompatibileBullets(itemLibrary, weapon); + + foreach (var bullet in bulletTemplateIds) + { + if (BulletHelpers.BulletIsOnBlackList(bullet)) + { + continue; + } + + modItemToAddBulletsTo.Value.AddUnique(bullet); + } + + + // Add compatabible mods to weapon var modsForWeapon = flatModList.Where(x => x.ParentId == weapon.Id).ToList(); Dictionary> weaponMods = output.mods[weapon.TemplateId]; - foreach (var mod in modsForWeapon) { weaponMods[mod.SlotId].AddUnique(mod.TemplateId); } + } // Get mods where parent is not weapon and add to output @@ -94,6 +113,39 @@ namespace PMCGenerator CreateJsonFile(outputPath, outputJson); } + private static Dictionary GetItemLibraryFileAndParse() + { + CreateInputFolder(string.Empty); + + var workingPath = Directory.GetCurrentDirectory(); + + var itemsLibraryJson = File.ReadAllText(workingPath + "\\input" + "\\items.json"); + var itemsLibrary = JsonConvert.DeserializeObject>(itemsLibraryJson); + + return itemsLibrary; + + } + + private static List GetCompatibileBullets(Dictionary itemLibrary, WeaponDetails weapon) + { + // Lookup weapon in itemdb + var weaponInLibrary = itemLibrary[weapon.TemplateId]; + + // Find the guns chamber and the bullets it can use + var bullets = weaponInLibrary._props.Chambers.FirstOrDefault()?._props.filters[0]?.filter.ToList(); + + // no chamber found, return default ammo type + if (bullets == null) + { + return new List + { + weaponInLibrary._props.defAmmo + }; + } + + return bullets; + } + private static List ParsePresetJsons(List presetFiles) { var result = new List(); @@ -217,10 +269,10 @@ namespace PMCGenerator /// /// Create folder structure to read from /// - private static string CreateInputFolder() + private static string CreateInputFolder(string folder) { var workingPath = Directory.GetCurrentDirectory(); - var presetPath = $"{workingPath}//input//presets"; + var presetPath = $"{workingPath}//input//{folder}"; DiskHelpers.CreateDirIfDoesntExist(presetPath); return presetPath;