Various code linting changes
This commit is contained in:
@@ -101,16 +101,14 @@ public class BotEquipmentModGenerator
|
||||
var forceSpawn = shouldForceSpawn;
|
||||
|
||||
// Get mod pool for the desired item
|
||||
var compatibleModsPool = settings.ModPool[parentTemplate.Id];
|
||||
if (compatibleModsPool is null)
|
||||
if (!settings.ModPool.TryGetValue(parentTemplate.Id, out var compatibleModsPool))
|
||||
{
|
||||
_logger.Warning($"bot: {settings.BotData.Role} lacks a mod slot pool for item: {parentTemplate.Id} {parentTemplate.Name}");
|
||||
}
|
||||
|
||||
// Iterate over mod pool and choose mods to add to item
|
||||
foreach (var modSlotKvP in compatibleModsPool)
|
||||
foreach (var (modSlotName, modPool) in compatibleModsPool)
|
||||
{
|
||||
var modSlotName = modSlotKvP.Key;
|
||||
// Get the templates slot object from db
|
||||
var itemSlotTemplate = GetModItemSlotFromDb(modSlotName, parentTemplate);
|
||||
if (itemSlotTemplate is null)
|
||||
@@ -138,7 +136,7 @@ public class BotEquipmentModGenerator
|
||||
settings.BotEquipmentConfig
|
||||
);
|
||||
|
||||
// Rolled to skip mod and it shouldnt be force-spawned
|
||||
// Rolled to skip mod and it shouldn't be force-spawned
|
||||
if (modSpawnResult == ModSpawn.SKIP && !forceSpawn)
|
||||
{
|
||||
continue;
|
||||
@@ -151,7 +149,7 @@ public class BotEquipmentModGenerator
|
||||
}
|
||||
|
||||
// Get pool of items we can add for this slot
|
||||
var modPoolToChooseFrom = modSlotKvP.Value;
|
||||
var modPoolToChooseFrom = modPool;
|
||||
|
||||
// Filter the pool of items in blacklist
|
||||
var filteredModPool = FilterModsByBlacklist(modPoolToChooseFrom, specificBlacklist, modSlotName);
|
||||
@@ -173,18 +171,17 @@ public class BotEquipmentModGenerator
|
||||
compatibleModsPool[modSlotName],
|
||||
parentTemplate
|
||||
);
|
||||
if (plateSlotFilteringOutcome.Result is Result.UNKNOWN_FAILURE or Result.NO_DEFAULT_FILTER)
|
||||
switch (plateSlotFilteringOutcome.Result)
|
||||
{
|
||||
_logger.Debug($"Plate slot: {modSlotName} selection for armor: {parentTemplate.Id} failed: {plateSlotFilteringOutcome.Result}, skipping");
|
||||
case Result.UNKNOWN_FAILURE or Result.NO_DEFAULT_FILTER:
|
||||
_logger.Debug($"Plate slot: {modSlotName} selection for armor: {parentTemplate.Id} failed: {plateSlotFilteringOutcome.Result}, skipping");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (plateSlotFilteringOutcome.Result == Result.LACKS_PLATE_WEIGHTS)
|
||||
{
|
||||
_logger.Warning(
|
||||
$"Plate slot: {modSlotName} lacks weights for armor: {parentTemplate.Id}, unable to adjust plate choice, using existing data"
|
||||
);
|
||||
continue;
|
||||
case Result.LACKS_PLATE_WEIGHTS:
|
||||
_logger.Warning(
|
||||
$"Plate slot: {modSlotName} lacks weights for armor: {parentTemplate.Id}, unable to adjust plate choice, using existing data"
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
// Replace mod pool with pool of chosen plate items
|
||||
@@ -1145,12 +1142,12 @@ public List<Item> GenerateModsForWeapon(string sessionId, GenerateWeaponRequest
|
||||
_logger.Debug($"{request.BotData.Role} No default: {request.ModSlot} mod found for: {weaponTemplate.Name}, using existing pool");
|
||||
}
|
||||
|
||||
// Couldnt find default in globals, use existing mod pool data
|
||||
// Couldn't find default in globals, use existing mod pool data
|
||||
return request.ItemModPool[request.ModSlot];
|
||||
}
|
||||
|
||||
// Only filter mods down to single default item if it already exists in existing itemModPool, OR the default item has no children
|
||||
// Filtering mod pool to item that wasnt already there can have problems;
|
||||
// Filtering mod pool to item that wasn't already there can have problems;
|
||||
// You'd have a mod being picked without any sub-mods in its chain, possibly resulting in missing required mods not being added
|
||||
// Mod is in existing mod pool
|
||||
if (request.ItemModPool[request.ModSlot].Contains(matchingModFromPreset.Template))
|
||||
@@ -1162,11 +1159,11 @@ public List<Item> GenerateModsForWeapon(string sessionId, GenerateWeaponRequest
|
||||
// Get an array of items that are allowed in slot from parent item
|
||||
// Check the filter of the slot to ensure a chosen mod fits
|
||||
var parentSlotCompatibleItems = request.ParentTemplate.Properties.Slots?.FirstOrDefault(
|
||||
(slot) => slot.Name.ToLower() == request.ModSlot.ToLower()
|
||||
(slot) => string.Equals(slot.Name.ToLower(), request.ModSlot.ToLower(), StringComparison.Ordinal)
|
||||
)
|
||||
?.Props.Filters[0].Filter;
|
||||
|
||||
// Mod isnt in existing pool, only add if it has no children and exists inside parent filter
|
||||
// Mod isn't in existing pool, only add if it has no children and exists inside parent filter
|
||||
if (
|
||||
parentSlotCompatibleItems?.Contains(matchingModFromPreset.Template) ??
|
||||
false &&
|
||||
@@ -1208,10 +1205,10 @@ public List<Item> GenerateModsForWeapon(string sessionId, GenerateWeaponRequest
|
||||
return request.ItemModPool[request.ModSlot];
|
||||
}
|
||||
|
||||
public Item GetMatchingModFromPreset(ModToSpawnRequest request, TemplateItem weaponTemplate)
|
||||
public Item? GetMatchingModFromPreset(ModToSpawnRequest request, TemplateItem weaponTemplate)
|
||||
{
|
||||
var matchingPreset = GetMatchingPreset(weaponTemplate, request.ParentTemplate.Id);
|
||||
return matchingPreset?.Items.FirstOrDefault((item) => item?.SlotId?.ToLower() == request.ModSlot.ToLower());
|
||||
return matchingPreset?.Items?.FirstOrDefault((item) => item?.SlotId?.ToLower() == request.ModSlot.ToLower());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -416,11 +416,11 @@ public class BotGenerator
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var equipmentKvP in blacklist.Gear)
|
||||
foreach (var (equipmentSlot, blacklistedTpls) in blacklist.Gear)
|
||||
{
|
||||
var equipmentDict = botJsonTemplate.BotInventory.Equipment[equipmentKvP.Key];
|
||||
var equipmentDict = botJsonTemplate.BotInventory.Equipment[equipmentSlot];
|
||||
|
||||
foreach (var blacklistedTpl in equipmentKvP.Value)
|
||||
foreach (var blacklistedTpl in blacklistedTpls)
|
||||
{
|
||||
// Set weighting to 0, will never be picked
|
||||
equipmentDict[blacklistedTpl] = 0;
|
||||
@@ -452,7 +452,7 @@ public class BotGenerator
|
||||
// Remove blacklisted loot from loot containers
|
||||
foreach (var lootContainerKey in lootContainersToFilter)
|
||||
{
|
||||
var prop = props.FirstOrDefault(x => x.Name.ToLower() == lootContainerKey.ToLower());
|
||||
var prop = props.FirstOrDefault(x => string.Equals(x.Name, lootContainerKey, StringComparison.CurrentCultureIgnoreCase));
|
||||
var propValue = (Dictionary<string, double>)prop.GetValue(botInventory.Items);
|
||||
|
||||
// No container, skip
|
||||
@@ -462,11 +462,11 @@ public class BotGenerator
|
||||
}
|
||||
|
||||
List<string> tplsToRemove = [];
|
||||
foreach (var item in propValue)
|
||||
foreach (var (key, _) in propValue)
|
||||
{
|
||||
if (_itemFilterService.IsLootableItemBlacklisted(item.Key))
|
||||
if (_itemFilterService.IsLootableItemBlacklisted(key))
|
||||
{
|
||||
tplsToRemove.Add(item.Key);
|
||||
tplsToRemove.Add(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -221,19 +221,19 @@ public class BotInventoryGenerator
|
||||
// Iterate over all equipment slots of bot, do it in specifc order to reduce conflicts
|
||||
// e.g. ArmorVest should be generated after TactivalVest
|
||||
// or FACE_COVER before HEADWEAR
|
||||
foreach (var equipmentSlotKvP in templateInventory.Equipment)
|
||||
foreach (var (equipmentSlot, value) in templateInventory.Equipment)
|
||||
{
|
||||
// Skip some slots as they need to be done in a specific order + with specific parameter values
|
||||
// e.g. Weapons
|
||||
if (excludedSlots.Contains(equipmentSlotKvP.Key))
|
||||
if (excludedSlots.Contains(equipmentSlot))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
GenerateEquipment(new GenerateEquipmentProperties
|
||||
{
|
||||
RootEquipmentSlot = equipmentSlotKvP.Key,
|
||||
RootEquipmentPool = equipmentSlotKvP.Value,
|
||||
RootEquipmentSlot = equipmentSlot,
|
||||
RootEquipmentPool = value,
|
||||
ModPool = templateInventory.Mods,
|
||||
SpawnChances = wornItemChances,
|
||||
BotData = new BotData { Role = botRole, Level = botLevel, EquipmentRole = botEquipmentRole },
|
||||
@@ -372,11 +372,10 @@ public class BotInventoryGenerator
|
||||
/// <summary>
|
||||
/// Remove armored rigs from parameter data
|
||||
/// </summary>
|
||||
/// <param name="templateEquipment">Equpiment to filter TacticalVest of</param>
|
||||
/// <param name="templateEquipment">Equipment to filter TacticalVest by</param>
|
||||
/// <param name="botRole">Role of bot vests are being filtered for</param>
|
||||
/// <param name="allowEmptyRequest">Should the function return all rigs when 0 unarmored are found</param>
|
||||
public void FilterRigsToThoseWithoutProtection(Dictionary<EquipmentSlots, Dictionary<string, double>> templateEquipment, string botRole,
|
||||
bool allowEmptyResult = true)
|
||||
/// <param name="allowEmptyResult">Should the function return all rigs when 0 unarmored are found</param>
|
||||
public void FilterRigsToThoseWithoutProtection(Dictionary<EquipmentSlots, Dictionary<string, double>> templateEquipment, string botRole, bool allowEmptyResult = true)
|
||||
{
|
||||
var tacVestsWithoutArmor = templateEquipment[EquipmentSlots.TacticalVest].Where(kvp => !_itemHelper.ItemHasSlots(kvp.Key))
|
||||
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
@@ -537,7 +536,7 @@ public class BotInventoryGenerator
|
||||
var blacklistedMods = equipmentBlacklist[modSlot] ?? [];
|
||||
var filteredMods = modPool[modSlot].Where((slotName) => !blacklistedMods.Contains(slotName));
|
||||
|
||||
if (filteredMods.Count() > 0)
|
||||
if (filteredMods.Any())
|
||||
{
|
||||
modPool[modSlot] = filteredMods.ToList();
|
||||
}
|
||||
@@ -561,14 +560,14 @@ public class BotInventoryGenerator
|
||||
string botRole, bool isPmc, Generation itemGenerationLimitsMinMax, int botLevel)
|
||||
{
|
||||
var weaponSlotsToFill = GetDesiredWeaponsForBot(equipmentChances);
|
||||
foreach (var weaponSlot in weaponSlotsToFill)
|
||||
foreach (var desiredWeapons in weaponSlotsToFill)
|
||||
{
|
||||
// Add weapon to bot if true and bot json has something to put into the slot
|
||||
if (weaponSlot.ShouldSpawn && templateInventory.Equipment[weaponSlot.Slot].Any())
|
||||
if (desiredWeapons.ShouldSpawn && templateInventory.Equipment[desiredWeapons.Slot].Any())
|
||||
{
|
||||
AddWeaponAndMagazinesToInventory(
|
||||
sessionId,
|
||||
weaponSlot,
|
||||
desiredWeapons,
|
||||
templateInventory,
|
||||
botInventory,
|
||||
equipmentChances,
|
||||
@@ -586,7 +585,7 @@ public class BotInventoryGenerator
|
||||
/// </summary>
|
||||
/// <param name="equipmentChances">Chances bot has certain equipment</param>
|
||||
/// <returns>What slots bot should have weapons generated for</returns>
|
||||
public List<DesiredWeapons> GetDesiredWeaponsForBot(Chances equipmentChances) // TODO: Type fuckery { slot: EquipmentSlots; shouldSpawn: boolean }[]
|
||||
public List<DesiredWeapons> GetDesiredWeaponsForBot(Chances equipmentChances)
|
||||
{
|
||||
var shouldSpawnPrimary = _randomUtil.GetChance100(equipmentChances.EquipmentChances["FirstPrimaryWeapon"]);
|
||||
return
|
||||
@@ -628,7 +627,7 @@ public class BotInventoryGenerator
|
||||
Chances equipmentChances, string botRole,
|
||||
bool isPmc, Generation itemGenerationWeights, int botLevel)
|
||||
{
|
||||
var generatedweapon = _botWeaponGenerator.GenerateRandomWeapon(
|
||||
var generatedWeapon = _botWeaponGenerator.GenerateRandomWeapon(
|
||||
sessionId,
|
||||
weaponSlot.Slot.ToString(),
|
||||
templateInventory,
|
||||
@@ -639,10 +638,10 @@ public class BotInventoryGenerator
|
||||
botLevel
|
||||
);
|
||||
|
||||
botInventory.Items.AddRange(generatedweapon.Weapon);
|
||||
botInventory.Items.AddRange(generatedWeapon.Weapon);
|
||||
|
||||
_botWeaponGenerator.AddExtraMagazinesToInventory(
|
||||
generatedweapon,
|
||||
generatedWeapon,
|
||||
itemGenerationWeights.Items.Magazines,
|
||||
botInventory,
|
||||
botRole);
|
||||
|
||||
@@ -684,10 +684,10 @@ public class BotLootGenerator
|
||||
/// Add generated weapons to inventory as loot
|
||||
/// </summary>
|
||||
/// <param name="sessionId"></param>
|
||||
/// <param name="botInventory">inventory to add preset to</param>
|
||||
/// <param name="equipmentSlot">slot to place the preset in (backpack)</param>
|
||||
/// <param name="templateInventory">bots template, assault.json</param>
|
||||
/// <param name="modsChances">chances for mods to spawn on weapon</param>
|
||||
/// <param name="botInventory">Inventory to add preset to</param>
|
||||
/// <param name="equipmentSlot">Slot to place the preset in (backpack)</param>
|
||||
/// <param name="templateInventory">Bots template, assault.json</param>
|
||||
/// <param name="modChances">Chances for mods to spawn on weapon</param>
|
||||
/// <param name="botRole">bots role .e.g. pmcBot</param>
|
||||
/// <param name="isPmc">are we generating for a pmc</param>
|
||||
/// <param name="botLevel"></param>
|
||||
@@ -714,33 +714,36 @@ public class BotLootGenerator
|
||||
(int)_pmcConfig.LooseWeaponInBackpackLootMinMax.Min,
|
||||
(int)_pmcConfig.LooseWeaponInBackpackLootMinMax.Max
|
||||
);
|
||||
if (randomisedWeaponCount > 0)
|
||||
{
|
||||
for (var i = 0; i < randomisedWeaponCount; i++)
|
||||
{
|
||||
var generatedWeapon = _botWeaponGenerator.GenerateRandomWeapon(
|
||||
sessionId,
|
||||
chosenWeaponType,
|
||||
templateInventory,
|
||||
botInventory.Equipment,
|
||||
modChances,
|
||||
botRole,
|
||||
isPmc,
|
||||
botLevel
|
||||
);
|
||||
var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot(
|
||||
[equipmentSlot],
|
||||
generatedWeapon.Weapon[0].Id,
|
||||
generatedWeapon.Weapon[0].Template,
|
||||
generatedWeapon.Weapon,
|
||||
botInventory,
|
||||
containersIdFull
|
||||
);
|
||||
|
||||
if (result != ItemAddedResult.SUCCESS)
|
||||
{
|
||||
_logger.Debug($"Failed to add additional weapon {generatedWeapon.Weapon[0].Id} to bot backpack, reason: {result.ToString()}");
|
||||
}
|
||||
if (randomisedWeaponCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < randomisedWeaponCount; i++)
|
||||
{
|
||||
var generatedWeapon = _botWeaponGenerator.GenerateRandomWeapon(
|
||||
sessionId,
|
||||
chosenWeaponType,
|
||||
templateInventory,
|
||||
botInventory.Equipment,
|
||||
modChances,
|
||||
botRole,
|
||||
isPmc,
|
||||
botLevel
|
||||
);
|
||||
var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot(
|
||||
[equipmentSlot],
|
||||
generatedWeapon.Weapon[0].Id,
|
||||
generatedWeapon.Weapon[0].Template,
|
||||
generatedWeapon.Weapon,
|
||||
botInventory,
|
||||
containersIdFull
|
||||
);
|
||||
|
||||
if (result != ItemAddedResult.SUCCESS)
|
||||
{
|
||||
_logger.Debug($"Failed to add additional weapon {generatedWeapon.Weapon[0].Id} to bot backpack, reason: {result.ToString()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -768,7 +771,7 @@ public class BotLootGenerator
|
||||
/// <param name="botRole">Bot type</param>
|
||||
/// <param name="itemSpawnLimits"></param>
|
||||
/// <returns>true if item has reached spawn limit</returns>
|
||||
public bool ItemHasReachedSpawnLimit(TemplateItem itemTemplate, string botRole, ItemSpawnLimitSettings itemSpawnLimits)
|
||||
public bool ItemHasReachedSpawnLimit(TemplateItem itemTemplate, string botRole, ItemSpawnLimitSettings? itemSpawnLimits)
|
||||
{
|
||||
// PMCs and scavs have different sections of bot config for spawn limits
|
||||
if (itemSpawnLimits is not null && itemSpawnLimits.GlobalLimits?.Count == 0) {
|
||||
@@ -884,7 +887,7 @@ public class BotLootGenerator
|
||||
return itemTemplate.Parent;
|
||||
}
|
||||
|
||||
// parentId and tplid not found
|
||||
// parentId and tplId not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,13 +339,14 @@ public class BotWeaponGenerator
|
||||
);
|
||||
List<Item> weaponMods = [];
|
||||
|
||||
// TODO: Right now, preset weapons trigger a lot of warnings regarding missing ammo in magazines & such
|
||||
// TODO: Preset weapons trigger a lot of warnings regarding missing ammo in magazines & such
|
||||
Preset preset = null;
|
||||
foreach (var presetObj in _databaseService.GetGlobals().ItemPresets)
|
||||
foreach (var (_, itemPreset) in _databaseService.GetGlobals().ItemPresets)
|
||||
{
|
||||
if (presetObj.Value.Items[0].Template == weaponTemplate)
|
||||
if (itemPreset.Items[0].Template == weaponTemplate)
|
||||
{
|
||||
preset = _cloner.Clone(presetObj.Value);
|
||||
preset = _cloner.Clone(itemPreset);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,8 +92,13 @@ namespace Core.Generators
|
||||
* @param rewardTplBlacklist OPTIONAL: list of tpls to NOT use when picking a reward
|
||||
* @returns IQuestRewards
|
||||
*/
|
||||
public QuestRewards GenerateReward(int pmcLevel, double difficulty, string traderId, RepeatableQuestConfig repeatableConfig,
|
||||
EliminationConfig eliminationConfig, BaseQuestConfig baseQuestConfig, List<string>? rewardTplBlacklist = null)
|
||||
public QuestRewards GenerateReward(
|
||||
int pmcLevel,
|
||||
double difficulty,
|
||||
string traderId,
|
||||
RepeatableQuestConfig repeatableConfig,
|
||||
EliminationConfig eliminationConfig,
|
||||
List<string>? rewardTplBlacklist = null)
|
||||
{
|
||||
// Get vars to configure rewards with
|
||||
var rewardParams = GetQuestRewardValues(repeatableConfig.RewardScaling, difficulty, pmcLevel);
|
||||
@@ -208,7 +213,7 @@ namespace Core.Generators
|
||||
// Chance of adding skill reward
|
||||
if (_randomUtil.GetChance100((double)rewardParams.SkillRewardChance * 100))
|
||||
{
|
||||
var targetSkill = _randomUtil.GetArrayValue(baseQuestConfig.PossibleSkillRewards);
|
||||
var targetSkill = _randomUtil.GetArrayValue(eliminationConfig.PossibleSkillRewards);
|
||||
Reward reward = new()
|
||||
{
|
||||
Id = _hashUtil.Generate(),
|
||||
|
||||
Reference in New Issue
Block a user