Format Style Fixes
This commit is contained in:
@@ -37,9 +37,7 @@ public class BotWeaponGenerator(
|
||||
{
|
||||
protected const string _modMagazineSlotId = "mod_magazine";
|
||||
protected readonly BotConfig _botConfig = configServer.GetConfig<BotConfig>();
|
||||
protected readonly IEnumerable<IInventoryMagGen> _inventoryMagGenComponents = MagGenSetUp(
|
||||
inventoryMagGenComponents
|
||||
);
|
||||
protected readonly IEnumerable<IInventoryMagGen> _inventoryMagGenComponents = MagGenSetUp(inventoryMagGenComponents);
|
||||
protected readonly PmcConfig _pmcConfig = configServer.GetConfig<PmcConfig>();
|
||||
protected readonly RepairConfig _repairConfig = configServer.GetConfig<RepairConfig>();
|
||||
|
||||
@@ -93,10 +91,7 @@ public class BotWeaponGenerator(
|
||||
/// <param name="equipmentSlot">Primary/secondary/holster</param>
|
||||
/// <param name="botTemplateInventory">e.g. assault.json</param>
|
||||
/// <returns>Weapon template</returns>
|
||||
public MongoId PickWeightedWeaponTemplateFromPool(
|
||||
string equipmentSlot,
|
||||
BotTypeInventory botTemplateInventory
|
||||
)
|
||||
public MongoId PickWeightedWeaponTemplateFromPool(string equipmentSlot, BotTypeInventory botTemplateInventory)
|
||||
{
|
||||
if (!Enum.TryParse(equipmentSlot, out EquipmentSlots key))
|
||||
{
|
||||
@@ -146,23 +141,14 @@ public class BotWeaponGenerator(
|
||||
// Find ammo to use when filling magazines/chamber
|
||||
if (botTemplateInventory.Ammo is null)
|
||||
{
|
||||
logger.Error(
|
||||
serverLocalisationService.GetText("bot-no_ammo_found_in_bot_json", botRole)
|
||||
);
|
||||
logger.Error(serverLocalisationService.GetText("bot-no_ammo_found_in_bot_json", botRole));
|
||||
logger.Error(serverLocalisationService.GetText("bot-generation_failed"));
|
||||
}
|
||||
|
||||
var ammoTpl = GetWeightedCompatibleAmmo(botTemplateInventory.Ammo, weaponItemTemplate);
|
||||
|
||||
// Create with just base weapon item
|
||||
var weaponWithModsArray = ConstructWeaponBaseList(
|
||||
weaponTpl,
|
||||
weaponParentId,
|
||||
slotName,
|
||||
weaponItemTemplate,
|
||||
botRole
|
||||
)
|
||||
.ToList();
|
||||
var weaponWithModsArray = ConstructWeaponBaseList(weaponTpl, weaponParentId, slotName, weaponItemTemplate, botRole).ToList();
|
||||
|
||||
// Chance to add randomised weapon enhancement
|
||||
if (isPmc && randomUtil.GetChance100(_pmcConfig.WeaponHasEnhancementChancePercent))
|
||||
@@ -198,28 +184,17 @@ public class BotWeaponGenerator(
|
||||
WeaponStats = new WeaponStats(),
|
||||
ConflictingItemTpls = [],
|
||||
};
|
||||
weaponWithModsArray = botEquipmentModGenerator.GenerateModsForWeapon(
|
||||
sessionId,
|
||||
generateWeaponModsRequest
|
||||
);
|
||||
weaponWithModsArray = botEquipmentModGenerator.GenerateModsForWeapon(sessionId, generateWeaponModsRequest);
|
||||
}
|
||||
|
||||
// Use weapon preset from globals.json if weapon isn't valid
|
||||
if (!IsWeaponValid(weaponWithModsArray, botRole))
|
||||
// Weapon is bad, fall back to weapons preset
|
||||
{
|
||||
weaponWithModsArray = GetPresetWeaponMods(
|
||||
weaponTpl,
|
||||
slotName,
|
||||
weaponParentId,
|
||||
weaponItemTemplate,
|
||||
botRole
|
||||
);
|
||||
weaponWithModsArray = GetPresetWeaponMods(weaponTpl, slotName, weaponParentId, weaponItemTemplate, botRole);
|
||||
}
|
||||
|
||||
var tempList = cloner.Clone(
|
||||
weaponWithModsArray.Where(item => item.SlotId == _modMagazineSlotId)
|
||||
);
|
||||
var tempList = cloner.Clone(weaponWithModsArray.Where(item => item.SlotId == _modMagazineSlotId));
|
||||
// Fill existing magazines to full and sync ammo type
|
||||
foreach (var magazine in tempList)
|
||||
{
|
||||
@@ -229,16 +204,11 @@ public class BotWeaponGenerator(
|
||||
// Add cartridge(s) to gun chamber(s)
|
||||
if (
|
||||
(weaponItemTemplate.Properties?.Chambers).Any()
|
||||
&& weaponItemTemplate
|
||||
.Properties.Chambers.FirstOrDefault()
|
||||
.Props.Filters.FirstOrDefault()
|
||||
.Filter.Contains(ammoTpl)
|
||||
&& weaponItemTemplate.Properties.Chambers.FirstOrDefault().Props.Filters.FirstOrDefault().Filter.Contains(ammoTpl)
|
||||
)
|
||||
{
|
||||
// Guns have variety of possible Chamber ids, patron_in_weapon/patron_in_weapon_000/patron_in_weapon_001
|
||||
var chamberSlotNames = weaponItemTemplate.Properties.Chambers.Select(chamberSlot =>
|
||||
chamberSlot.Name
|
||||
);
|
||||
var chamberSlotNames = weaponItemTemplate.Properties.Chambers.Select(chamberSlot => chamberSlot.Name);
|
||||
AddCartridgeToChamber(weaponWithModsArray, ammoTpl, chamberSlotNames.ToList());
|
||||
}
|
||||
|
||||
@@ -274,11 +244,7 @@ public class BotWeaponGenerator(
|
||||
/// <param name="weaponWithModsList">Weapon and mods</param>
|
||||
/// <param name="ammoTemplate">Cartridge to add to weapon</param>
|
||||
/// <param name="chamberSlotIds">Name of slots to create or add ammo to</param>
|
||||
protected void AddCartridgeToChamber(
|
||||
List<Item> weaponWithModsList,
|
||||
MongoId ammoTemplate,
|
||||
IEnumerable<string> chamberSlotIds
|
||||
)
|
||||
protected void AddCartridgeToChamber(List<Item> weaponWithModsList, MongoId ammoTemplate, IEnumerable<string> chamberSlotIds)
|
||||
{
|
||||
foreach (var slotId in chamberSlotIds)
|
||||
{
|
||||
@@ -332,10 +298,7 @@ public class BotWeaponGenerator(
|
||||
Template = weaponTemplate,
|
||||
ParentId = weaponParentId,
|
||||
SlotId = equipmentSlot,
|
||||
Upd = botGeneratorHelper.GenerateExtraPropertiesForItem(
|
||||
weaponItemTemplate,
|
||||
botRole
|
||||
),
|
||||
Upd = botGeneratorHelper.GenerateExtraPropertiesForItem(weaponItemTemplate, botRole),
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -359,10 +322,7 @@ public class BotWeaponGenerator(
|
||||
{
|
||||
// Invalid weapon generated, fallback to preset
|
||||
logger.Warning(
|
||||
serverLocalisationService.GetText(
|
||||
"bot-weapon_generated_incorrect_using_default",
|
||||
$"{weaponTemplate} - {itemTemplate.Name}"
|
||||
)
|
||||
serverLocalisationService.GetText("bot-weapon_generated_incorrect_using_default", $"{weaponTemplate} - {itemTemplate.Name}")
|
||||
);
|
||||
List<Item> weaponMods = [];
|
||||
|
||||
@@ -383,18 +343,13 @@ public class BotWeaponGenerator(
|
||||
var parentItem = preset.Items[0];
|
||||
parentItem.ParentId = weaponParentId;
|
||||
parentItem.SlotId = equipmentSlot;
|
||||
parentItem.Upd = botGeneratorHelper.GenerateExtraPropertiesForItem(
|
||||
itemTemplate,
|
||||
botRole
|
||||
);
|
||||
parentItem.Upd = botGeneratorHelper.GenerateExtraPropertiesForItem(itemTemplate, botRole);
|
||||
preset.Items[0] = parentItem;
|
||||
weaponMods.AddRange(preset.Items);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error(
|
||||
serverLocalisationService.GetText("bot-missing_weapon_preset", weaponTemplate)
|
||||
);
|
||||
logger.Error(serverLocalisationService.GetText("bot-missing_weapon_preset", weaponTemplate));
|
||||
}
|
||||
|
||||
return weaponMods;
|
||||
@@ -417,16 +372,10 @@ public class BotWeaponGenerator(
|
||||
}
|
||||
|
||||
// Iterate over required slots in db item, check mod exists for that slot
|
||||
foreach (
|
||||
var modSlotTemplate in modTemplate.Properties.Slots?.Where(slot =>
|
||||
slot.Required.GetValueOrDefault(false)
|
||||
) ?? []
|
||||
)
|
||||
foreach (var modSlotTemplate in modTemplate.Properties.Slots?.Where(slot => slot.Required.GetValueOrDefault(false)) ?? [])
|
||||
{
|
||||
var slotName = modSlotTemplate.Name;
|
||||
var hasWeaponSlotItem = weaponItemList.Any(weaponItem =>
|
||||
weaponItem.ParentId == mod.Id && weaponItem.SlotId == slotName
|
||||
);
|
||||
var hasWeaponSlotItem = weaponItemList.Any(weaponItem => weaponItem.ParentId == mod.Id && weaponItem.SlotId == slotName);
|
||||
if (!hasWeaponSlotItem)
|
||||
{
|
||||
logger.Warning(
|
||||
@@ -467,18 +416,12 @@ public class BotWeaponGenerator(
|
||||
{
|
||||
var weaponAndMods = generatedWeaponResult.Weapon;
|
||||
var weaponTemplate = generatedWeaponResult.WeaponTemplate;
|
||||
var magazineTpl = GetMagazineTemplateFromWeaponTemplate(
|
||||
weaponAndMods,
|
||||
weaponTemplate,
|
||||
botRole
|
||||
);
|
||||
var magazineTpl = GetMagazineTemplateFromWeaponTemplate(weaponAndMods, weaponTemplate, botRole);
|
||||
|
||||
var magTemplate = itemHelper.GetItem(magazineTpl.Value).Value;
|
||||
if (magTemplate is null)
|
||||
{
|
||||
logger.Error(
|
||||
serverLocalisationService.GetText("bot-unable_to_find_magazine_item", magazineTpl)
|
||||
);
|
||||
logger.Error(serverLocalisationService.GetText("bot-unable_to_find_magazine_item", magazineTpl));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -487,36 +430,20 @@ public class BotWeaponGenerator(
|
||||
var ammoTemplate = itemHelper.GetItem(generatedWeaponResult.ChosenAmmoTemplate);
|
||||
if (!ammoTemplate.Key)
|
||||
{
|
||||
logger.Error(
|
||||
serverLocalisationService.GetText(
|
||||
"bot-unable_to_find_ammo_item",
|
||||
generatedWeaponResult.ChosenAmmoTemplate
|
||||
)
|
||||
);
|
||||
logger.Error(serverLocalisationService.GetText("bot-unable_to_find_ammo_item", generatedWeaponResult.ChosenAmmoTemplate));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Has an UBGL
|
||||
if (
|
||||
generatedWeaponResult.ChosenUbglAmmoTemplate is not null
|
||||
&& !generatedWeaponResult.ChosenUbglAmmoTemplate.Value.IsEmpty()
|
||||
)
|
||||
if (generatedWeaponResult.ChosenUbglAmmoTemplate is not null && !generatedWeaponResult.ChosenUbglAmmoTemplate.Value.IsEmpty())
|
||||
{
|
||||
AddUbglGrenadesToBotInventory(weaponAndMods, generatedWeaponResult, inventory);
|
||||
}
|
||||
|
||||
var inventoryMagGenModel = new InventoryMagGen(
|
||||
magWeights,
|
||||
magTemplate,
|
||||
weaponTemplate,
|
||||
ammoTemplate.Value,
|
||||
inventory
|
||||
);
|
||||
var inventoryMagGenModel = new InventoryMagGen(magWeights, magTemplate, weaponTemplate, ammoTemplate.Value, inventory);
|
||||
|
||||
_inventoryMagGenComponents
|
||||
.FirstOrDefault(v => v.CanHandleInventoryMagGen(inventoryMagGenModel))
|
||||
.Process(inventoryMagGenModel);
|
||||
_inventoryMagGenComponents.FirstOrDefault(v => v.CanHandleInventoryMagGen(inventoryMagGenModel)).Process(inventoryMagGenModel);
|
||||
|
||||
// Add x stacks of bullets to SecuredContainer (bots use a magic mag packing skill to reload instantly)
|
||||
AddAmmoToSecureContainer(
|
||||
@@ -551,29 +478,14 @@ public class BotWeaponGenerator(
|
||||
};
|
||||
|
||||
// get ammo template from db
|
||||
var ubglAmmoDbTemplate = itemHelper
|
||||
.GetItem(generatedWeaponResult.ChosenUbglAmmoTemplate.Value)
|
||||
.Value;
|
||||
var ubglAmmoDbTemplate = itemHelper.GetItem(generatedWeaponResult.ChosenUbglAmmoTemplate.Value).Value;
|
||||
|
||||
// Add greandes to bot inventory
|
||||
var ubglAmmoGenModel = new InventoryMagGen(
|
||||
ubglMinMax,
|
||||
ubglDbTemplate,
|
||||
ubglDbTemplate,
|
||||
ubglAmmoDbTemplate,
|
||||
inventory
|
||||
);
|
||||
_inventoryMagGenComponents
|
||||
.FirstOrDefault(v => v.CanHandleInventoryMagGen(ubglAmmoGenModel))
|
||||
.Process(ubglAmmoGenModel);
|
||||
var ubglAmmoGenModel = new InventoryMagGen(ubglMinMax, ubglDbTemplate, ubglDbTemplate, ubglAmmoDbTemplate, inventory);
|
||||
_inventoryMagGenComponents.FirstOrDefault(v => v.CanHandleInventoryMagGen(ubglAmmoGenModel)).Process(ubglAmmoGenModel);
|
||||
|
||||
// Store extra grenades in secure container
|
||||
AddAmmoToSecureContainer(
|
||||
5,
|
||||
generatedWeaponResult.ChosenUbglAmmoTemplate.Value,
|
||||
20,
|
||||
inventory
|
||||
);
|
||||
AddAmmoToSecureContainer(5, generatedWeaponResult.ChosenUbglAmmoTemplate.Value, 20, inventory);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -583,12 +495,7 @@ public class BotWeaponGenerator(
|
||||
/// <param name="ammoTpl">Ammo type to add.</param>
|
||||
/// <param name="stackSize">Size of the ammo stack to add.</param>
|
||||
/// <param name="inventory">Player inventory.</param>
|
||||
protected void AddAmmoToSecureContainer(
|
||||
int stackCount,
|
||||
MongoId ammoTpl,
|
||||
int stackSize,
|
||||
BotBaseInventory inventory
|
||||
)
|
||||
protected void AddAmmoToSecureContainer(int stackCount, MongoId ammoTpl, int stackSize, BotBaseInventory inventory)
|
||||
{
|
||||
var container = new HashSet<EquipmentSlots> { EquipmentSlots.SecuredContainer };
|
||||
for (var i = 0; i < stackCount; i++)
|
||||
@@ -618,11 +525,7 @@ public class BotWeaponGenerator(
|
||||
/// <param name="weaponTemplate">Weapon to get magazine template for.</param>
|
||||
/// <param name="botRole">The bot type we are getting the magazine for.</param>
|
||||
/// <returns>Magazine template string.</returns>
|
||||
protected MongoId? GetMagazineTemplateFromWeaponTemplate(
|
||||
IEnumerable<Item> weaponMods,
|
||||
TemplateItem weaponTemplate,
|
||||
string botRole
|
||||
)
|
||||
protected MongoId? GetMagazineTemplateFromWeaponTemplate(IEnumerable<Item> weaponMods, TemplateItem weaponTemplate, string botRole)
|
||||
{
|
||||
var magazine = weaponMods.FirstOrDefault(m => m.SlotId == _modMagazineSlotId);
|
||||
if (magazine is null)
|
||||
@@ -667,16 +570,10 @@ public class BotWeaponGenerator(
|
||||
/// <param name="cartridgePool">Dictionary of all cartridges keyed by type e.g. Caliber556x45NATO</param>
|
||||
/// <param name="weaponTemplate">Weapon details from database we want to pick ammo for</param>
|
||||
/// <returns>Ammo template that works with the desired gun</returns>
|
||||
protected MongoId GetWeightedCompatibleAmmo(
|
||||
Dictionary<string, Dictionary<MongoId, double>> cartridgePool,
|
||||
TemplateItem weaponTemplate
|
||||
)
|
||||
protected MongoId GetWeightedCompatibleAmmo(Dictionary<string, Dictionary<MongoId, double>> cartridgePool, TemplateItem weaponTemplate)
|
||||
{
|
||||
var desiredCaliber = GetWeaponCaliber(weaponTemplate);
|
||||
if (
|
||||
!cartridgePool.TryGetValue(desiredCaliber, out var cartridgePoolForWeapon)
|
||||
|| cartridgePoolForWeapon?.Count == 0
|
||||
)
|
||||
if (!cartridgePool.TryGetValue(desiredCaliber, out var cartridgePoolForWeapon) || cartridgePoolForWeapon?.Count == 0)
|
||||
{
|
||||
if (logger.IsLogEnabled(LogLevel.Debug))
|
||||
{
|
||||
@@ -699,9 +596,7 @@ public class BotWeaponGenerator(
|
||||
}
|
||||
|
||||
// Get cartridges the weapons first chamber allow
|
||||
var compatibleCartridgesInTemplate = GetCompatibleCartridgesFromWeaponTemplate(
|
||||
weaponTemplate
|
||||
);
|
||||
var compatibleCartridgesInTemplate = GetCompatibleCartridgesFromWeaponTemplate(weaponTemplate);
|
||||
if (compatibleCartridgesInTemplate.Count == 0)
|
||||
// No chamber data found in weapon, send default
|
||||
{
|
||||
@@ -722,9 +617,7 @@ public class BotWeaponGenerator(
|
||||
if (!compatibleCartridges.Any())
|
||||
{
|
||||
// Get cartridges from the weapons first magazine in filters
|
||||
var compatibleCartridgesInMagazine = GetCompatibleCartridgesFromMagazineTemplate(
|
||||
weaponTemplate
|
||||
);
|
||||
var compatibleCartridgesInMagazine = GetCompatibleCartridgesFromMagazineTemplate(weaponTemplate);
|
||||
if (compatibleCartridgesInMagazine.Count == 0)
|
||||
{
|
||||
// No compatible cartridges found in magazine, use default
|
||||
@@ -732,9 +625,7 @@ public class BotWeaponGenerator(
|
||||
}
|
||||
|
||||
// Get the caliber data from the first compatible round in the magazine
|
||||
var magazineCaliberData = itemHelper
|
||||
.GetItem(compatibleCartridgesInMagazine.FirstOrDefault())
|
||||
.Value.Properties.Caliber;
|
||||
var magazineCaliberData = itemHelper.GetItem(compatibleCartridgesInMagazine.FirstOrDefault()).Value.Properties.Caliber;
|
||||
cartridgePoolForWeapon = cartridgePool[magazineCaliberData];
|
||||
|
||||
foreach (var cartridgeKvP in cartridgePoolForWeapon)
|
||||
@@ -760,16 +651,11 @@ public class BotWeaponGenerator(
|
||||
/// </summary>
|
||||
/// <param name="weaponTemplate">Weapon db template to get cartridges for</param>
|
||||
/// <returns>List of cartridge tpls</returns>
|
||||
protected HashSet<MongoId> GetCompatibleCartridgesFromWeaponTemplate(
|
||||
TemplateItem weaponTemplate
|
||||
)
|
||||
protected HashSet<MongoId> GetCompatibleCartridgesFromWeaponTemplate(TemplateItem weaponTemplate)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(weaponTemplate);
|
||||
|
||||
var cartridges = weaponTemplate
|
||||
.Properties?.Chambers?.FirstOrDefault()
|
||||
?.Props?.Filters?.First()
|
||||
.Filter;
|
||||
var cartridges = weaponTemplate.Properties?.Chambers?.FirstOrDefault()?.Props?.Filters?.First().Filter;
|
||||
if (cartridges is not null)
|
||||
{
|
||||
return cartridges;
|
||||
@@ -785,24 +671,19 @@ public class BotWeaponGenerator(
|
||||
/// <param name="weaponTemplate">Weapon db template to get magazine cartridges for</param>
|
||||
/// <returns>Hashset of cartridge tpls</returns>
|
||||
/// <exception cref="ArgumentNullException">Thrown when weaponTemplate is null.</exception>
|
||||
protected HashSet<MongoId> GetCompatibleCartridgesFromMagazineTemplate(
|
||||
TemplateItem weaponTemplate
|
||||
)
|
||||
protected HashSet<MongoId> GetCompatibleCartridgesFromMagazineTemplate(TemplateItem weaponTemplate)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(weaponTemplate);
|
||||
|
||||
// Get the first magazine's template from the weapon
|
||||
var magazineSlot = weaponTemplate.Properties.Slots?.FirstOrDefault(slot =>
|
||||
slot.Name == "mod_magazine"
|
||||
);
|
||||
var magazineSlot = weaponTemplate.Properties.Slots?.FirstOrDefault(slot => slot.Name == "mod_magazine");
|
||||
if (magazineSlot is null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var magazineTemplate = itemHelper.GetItem(
|
||||
magazineSlot.Props?.Filters.FirstOrDefault()?.Filter?.FirstOrDefault()
|
||||
?? new MongoId(null)
|
||||
magazineSlot.Props?.Filters.FirstOrDefault()?.Filter?.FirstOrDefault() ?? new MongoId(null)
|
||||
);
|
||||
if (!magazineTemplate.Key)
|
||||
{
|
||||
@@ -811,14 +692,8 @@ public class BotWeaponGenerator(
|
||||
|
||||
// Try to get cartridges from slots array first, if none found, try Cartridges array
|
||||
var cartridges =
|
||||
magazineTemplate
|
||||
.Value.Properties.Slots.FirstOrDefault()
|
||||
?.Props?.Filters.FirstOrDefault()
|
||||
?.Filter
|
||||
?? magazineTemplate
|
||||
.Value.Properties.Cartridges.FirstOrDefault()
|
||||
?.Props?.Filters.FirstOrDefault()
|
||||
?.Filter;
|
||||
magazineTemplate.Value.Properties.Slots.FirstOrDefault()?.Props?.Filters.FirstOrDefault()?.Filter
|
||||
?? magazineTemplate.Value.Properties.Cartridges.FirstOrDefault()?.Props?.Filters.FirstOrDefault()?.Filter;
|
||||
|
||||
return cartridges ?? [];
|
||||
}
|
||||
@@ -838,18 +713,13 @@ public class BotWeaponGenerator(
|
||||
if (!string.IsNullOrEmpty(weaponTemplate.Properties.AmmoCaliber))
|
||||
// 9x18pmm has a typo, should be Caliber9x18PM
|
||||
{
|
||||
return weaponTemplate.Properties.AmmoCaliber == "Caliber9x18PMM"
|
||||
? "Caliber9x18PM"
|
||||
: weaponTemplate.Properties.AmmoCaliber;
|
||||
return weaponTemplate.Properties.AmmoCaliber == "Caliber9x18PMM" ? "Caliber9x18PM" : weaponTemplate.Properties.AmmoCaliber;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(weaponTemplate.Properties.LinkedWeapon))
|
||||
{
|
||||
var ammoInChamber = itemHelper.GetItem(
|
||||
weaponTemplate
|
||||
.Properties.Chambers.First()
|
||||
.Props.Filters.First()
|
||||
.Filter.FirstOrDefault()
|
||||
weaponTemplate.Properties.Chambers.First().Props.Filters.First().Filter.FirstOrDefault()
|
||||
);
|
||||
return !ammoInChamber.Key ? null : ammoInChamber.Value.Properties.Caliber;
|
||||
}
|
||||
@@ -863,21 +733,12 @@ public class BotWeaponGenerator(
|
||||
/// <param name="weaponMods">Weapon with children</param>
|
||||
/// <param name="magazine">Magazine item</param>
|
||||
/// <param name="cartridgeTemplate">Cartridge to insert into magazine</param>
|
||||
protected void FillExistingMagazines(
|
||||
List<Item> weaponMods,
|
||||
Item magazine,
|
||||
MongoId cartridgeTemplate
|
||||
)
|
||||
protected void FillExistingMagazines(List<Item> weaponMods, Item magazine, MongoId cartridgeTemplate)
|
||||
{
|
||||
var magazineTemplate = itemHelper.GetItem(magazine.Template).Value;
|
||||
if (magazineTemplate is null)
|
||||
{
|
||||
logger.Error(
|
||||
serverLocalisationService.GetText(
|
||||
"bot-unable_to_find_magazine_item",
|
||||
magazine.Template
|
||||
)
|
||||
);
|
||||
logger.Error(serverLocalisationService.GetText("bot-unable_to_find_magazine_item", magazine.Template));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -894,12 +755,7 @@ public class BotWeaponGenerator(
|
||||
}
|
||||
else
|
||||
{
|
||||
AddOrUpdateMagazinesChildWithAmmo(
|
||||
weaponMods,
|
||||
magazine,
|
||||
cartridgeTemplate,
|
||||
magazineTemplate
|
||||
);
|
||||
AddOrUpdateMagazinesChildWithAmmo(weaponMods, magazine, cartridgeTemplate, magazineTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -937,9 +793,7 @@ public class BotWeaponGenerator(
|
||||
TemplateItem magazineTemplate
|
||||
)
|
||||
{
|
||||
var magazineCartridgeChildItem = weaponWithMods.FirstOrDefault(m =>
|
||||
m.ParentId == magazine.Id && m.SlotId == "cartridges"
|
||||
);
|
||||
var magazineCartridgeChildItem = weaponWithMods.FirstOrDefault(m => m.ParentId == magazine.Id && m.SlotId == "cartridges");
|
||||
if (magazineCartridgeChildItem is not null)
|
||||
{
|
||||
// Delete the existing cartridge object and create fresh below
|
||||
@@ -950,20 +804,13 @@ public class BotWeaponGenerator(
|
||||
List<Item> magazineWithCartridges = [magazine];
|
||||
|
||||
// Add cartridges as children to above mag array
|
||||
itemHelper.FillMagazineWithCartridge(
|
||||
magazineWithCartridges,
|
||||
magazineTemplate,
|
||||
chosenAmmoTpl,
|
||||
1
|
||||
);
|
||||
itemHelper.FillMagazineWithCartridge(magazineWithCartridges, magazineTemplate, chosenAmmoTpl, 1);
|
||||
|
||||
// Replace existing magazine with above array of mag + cartridge stacks
|
||||
var magazineIndex = weaponWithMods.FindIndex(i => i.Id == magazine.Id); // magazineWithCartridges
|
||||
if (magazineIndex == -1)
|
||||
{
|
||||
logger.Error(
|
||||
$"Unable to add cartridges: {chosenAmmoTpl} to magazine: {magazine.Id} as none found"
|
||||
);
|
||||
logger.Error($"Unable to add cartridges: {chosenAmmoTpl} to magazine: {magazine.Id} as none found");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -980,20 +827,12 @@ public class BotWeaponGenerator(
|
||||
/// <param name="weaponMods">Weapon mods to find and update camora mod(s) from</param>
|
||||
/// <param name="magazineId">Magazine id to find and add to</param>
|
||||
/// <param name="ammoTpl">Ammo template id to hydrate with</param>
|
||||
protected void FillCamorasWithAmmo(
|
||||
IEnumerable<Item> weaponMods,
|
||||
MongoId magazineId,
|
||||
MongoId ammoTpl
|
||||
)
|
||||
protected void FillCamorasWithAmmo(IEnumerable<Item> weaponMods, MongoId magazineId, MongoId ammoTpl)
|
||||
{
|
||||
// for CylinderMagazine we exchange the ammo in the "camoras".
|
||||
// This might not be necessary since we already filled the camoras with a random whitelisted and compatible ammo type,
|
||||
// but I'm not sure whether this is also used elsewhere
|
||||
var camoras = weaponMods
|
||||
.Where(x =>
|
||||
x.ParentId == magazineId && x.SlotId.StartsWith("camora", StringComparison.Ordinal)
|
||||
)
|
||||
.ToList();
|
||||
var camoras = weaponMods.Where(x => x.ParentId == magazineId && x.SlotId.StartsWith("camora", StringComparison.Ordinal)).ToList();
|
||||
|
||||
if (camoras.Count == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user