Add code to add cartridge items to mod list for magazine items
each magazine needs a mod item with a key of its template id with a "cartridges" key + list of compatible cartridges to work correctly.
This commit is contained in:
parent
3067035494
commit
8b57a79fc7
@ -44,7 +44,7 @@ namespace PMCGenerator
|
||||
output.mods.Add(weapon.TemplateId, new Dictionary<string, List<string>>());
|
||||
}
|
||||
|
||||
// Get mods types for this gun, top level
|
||||
// Get top level mods types for this gun
|
||||
var uniqueModSlots = flatModList.Where(x => x.ParentId == weapon.Id).Select(x => x.SlotId).Distinct().ToList();
|
||||
var chamberedBulletModItemName = "patron_in_weapon";
|
||||
uniqueModSlots.AddUnique(chamberedBulletModItemName);
|
||||
@ -59,17 +59,9 @@ namespace PMCGenerator
|
||||
}
|
||||
|
||||
// Add compatible bullets to weapons gun chamber
|
||||
var modItemToAddBulletsTo = output.mods[weapon.TemplateId].FirstOrDefault(x=> x.Key == chamberedBulletModItemName);
|
||||
|
||||
foreach (var bullet in GetCompatibileBullets(itemLibrary, weapon))
|
||||
{
|
||||
if (BulletHelpers.BulletIsOnBlackList(bullet))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
modItemToAddBulletsTo.Value.AddUnique(bullet);
|
||||
}
|
||||
var modItemToAddBulletsTo = output.mods[weapon.TemplateId].FirstOrDefault(x => x.Key == chamberedBulletModItemName);
|
||||
var compatibleBullets = GetCompatibileBullets(itemLibrary, weapon);
|
||||
modItemToAddBulletsTo.Value.AddUniqueRange(compatibleBullets);
|
||||
|
||||
// Add compatabible mods to weapon
|
||||
var modsForWeapon = flatModList.Where(x => x.ParentId == weapon.Id).ToList();
|
||||
@ -77,6 +69,12 @@ namespace PMCGenerator
|
||||
foreach (var mod in modsForWeapon)
|
||||
{
|
||||
weaponMods[mod.SlotId].AddUnique(mod.TemplateId);
|
||||
|
||||
if (mod.SlotId == "mod_magazine")
|
||||
{
|
||||
// add special mod item for magazine that gives info on what cartridges can be used
|
||||
AddCartridgeItemToModListWithCompatibileCartridges(output.mods, compatibleBullets, mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,6 +120,27 @@ namespace PMCGenerator
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void AddCartridgeItemToModListWithCompatibileCartridges(Dictionary<string, Dictionary<string, List<string>>> mods, List<string> compatibiltBullets, ModDetails mod)
|
||||
{
|
||||
var cartridges = new Dictionary<string, List<string>>
|
||||
{
|
||||
{ "cartridges", compatibiltBullets }
|
||||
};
|
||||
if (!mods.ContainsKey(mod.TemplateId))
|
||||
{
|
||||
mods.Add(mod.TemplateId, cartridges); // no item at all, create fresh
|
||||
}
|
||||
else
|
||||
{
|
||||
// Item exists, iterate over bullets and add if they dont exist
|
||||
foreach (var bullet in compatibiltBullets)
|
||||
{
|
||||
mods[mod.TemplateId]["cartridges"].AddUnique(bullet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a strongly typed dictionary of BSGs items library
|
||||
/// </summary>
|
||||
@ -136,6 +155,9 @@ namespace PMCGenerator
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get combatible bullets for weapon that are not blacklisted
|
||||
/// </summary>
|
||||
private static List<string> GetCompatibileBullets(Dictionary<string, Item> itemLibrary, WeaponDetails weapon)
|
||||
{
|
||||
// Lookup weapon in itemdb
|
||||
@ -144,13 +166,29 @@ namespace PMCGenerator
|
||||
// Find the guns chamber and the bullets it can use
|
||||
var bullets = weaponInLibrary._props.Chambers.FirstOrDefault()?._props.filters[0]?.filter.ToList();
|
||||
|
||||
// return bullets or return default ammo type
|
||||
return bullets ?? new List<string>
|
||||
// no bullets found, return the default bullet the gun can use
|
||||
if (bullets == null)
|
||||
{
|
||||
return new List<string>
|
||||
{
|
||||
weaponInLibrary._props.defAmmo
|
||||
};
|
||||
}
|
||||
|
||||
var nonBlacklistedBullets = new List<string>();
|
||||
foreach (var bullet in bullets)
|
||||
{
|
||||
if (BulletHelpers.BulletIsOnBlackList(bullet))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
nonBlacklistedBullets.AddUnique(bullet);
|
||||
}
|
||||
|
||||
return nonBlacklistedBullets;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all the presets in the input/presets folder and return as a list of strongly typed objects
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user