.NET Format Style Fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Frozen;
|
||||
using SPTarkov.Server.Core.Constants;
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.Constants;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
||||
using SPTarkov.Server.Core.Models.Enums;
|
||||
using SPTarkov.Server.Core.Models.Spt.Bots;
|
||||
@@ -24,18 +24,19 @@ public class BotGeneratorHelper(
|
||||
ProfileActivityService _profileActivityService,
|
||||
LocalisationService _localisationService,
|
||||
ConfigServer _configServer
|
||||
)
|
||||
)
|
||||
{
|
||||
// Equipment slot ids that do not conflict with other slots
|
||||
private static readonly FrozenSet<string> _slotsWithNoCompatIssues = [
|
||||
private static readonly FrozenSet<string> _slotsWithNoCompatIssues =
|
||||
[
|
||||
EquipmentSlots.Scabbard.ToString(),
|
||||
EquipmentSlots.Backpack.ToString(),
|
||||
EquipmentSlots.SecuredContainer.ToString(),
|
||||
EquipmentSlots.Holster.ToString(),
|
||||
EquipmentSlots.ArmBand.ToString()
|
||||
EquipmentSlots.ArmBand.ToString(),
|
||||
];
|
||||
|
||||
private static readonly string[] _pmcTypes = [ Sides.PmcBear.ToLower(), Sides.PmcUsec.ToLower() ];
|
||||
private static readonly string[] _pmcTypes = [Sides.PmcBear.ToLower(), Sides.PmcUsec.ToLower()];
|
||||
|
||||
private readonly BotConfig _botConfig = _configServer.GetConfig<BotConfig>();
|
||||
|
||||
@@ -49,62 +50,66 @@ public class BotGeneratorHelper(
|
||||
public Upd GenerateExtraPropertiesForItem(TemplateItem? itemTemplate, string? botRole = null)
|
||||
{
|
||||
// Get raid settings, if no raid, default to day
|
||||
var raidSettings = _profileActivityService.GetFirstProfileActivityRaidData()?.RaidConfiguration;
|
||||
var raidSettings = _profileActivityService
|
||||
.GetFirstProfileActivityRaidData()
|
||||
?.RaidConfiguration;
|
||||
|
||||
RandomisedResourceDetails randomisationSettings = null;
|
||||
if (botRole is not null)
|
||||
{
|
||||
_botConfig.LootItemResourceRandomization.TryGetValue(botRole, out randomisationSettings);
|
||||
_botConfig.LootItemResourceRandomization.TryGetValue(
|
||||
botRole,
|
||||
out randomisationSettings
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Upd itemProperties = new();
|
||||
var hasProperties = false;
|
||||
|
||||
if (itemTemplate?.Properties?.MaxDurability is not null && itemTemplate.Properties.MaxDurability > 0)
|
||||
if (
|
||||
itemTemplate?.Properties?.MaxDurability is not null
|
||||
&& itemTemplate.Properties.MaxDurability > 0
|
||||
)
|
||||
{
|
||||
if (itemTemplate.Properties.WeapClass is not null)
|
||||
{
|
||||
// Is weapon
|
||||
itemProperties.Repairable = GenerateWeaponRepairableProperties(itemTemplate, botRole);
|
||||
itemProperties.Repairable = GenerateWeaponRepairableProperties(
|
||||
itemTemplate,
|
||||
botRole
|
||||
);
|
||||
hasProperties = true;
|
||||
}
|
||||
else if (itemTemplate.Properties.ArmorClass is not null)
|
||||
{
|
||||
// Is armor
|
||||
itemProperties.Repairable = GenerateArmorRepairableProperties(itemTemplate, botRole);
|
||||
itemProperties.Repairable = GenerateArmorRepairableProperties(
|
||||
itemTemplate,
|
||||
botRole
|
||||
);
|
||||
hasProperties = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemTemplate?.Properties?.HasHinge ?? false)
|
||||
{
|
||||
itemProperties.Togglable = new UpdTogglable
|
||||
{
|
||||
On = true
|
||||
};
|
||||
itemProperties.Togglable = new UpdTogglable { On = true };
|
||||
hasProperties = true;
|
||||
}
|
||||
|
||||
if (itemTemplate?.Properties?.Foldable ?? false)
|
||||
{
|
||||
itemProperties.Foldable = new UpdFoldable
|
||||
{
|
||||
Folded = false
|
||||
};
|
||||
itemProperties.Foldable = new UpdFoldable { Folded = false };
|
||||
hasProperties = true;
|
||||
}
|
||||
|
||||
if (itemTemplate?.Properties?.WeapFireType?.Count == 0)
|
||||
{
|
||||
itemProperties.FireMode = itemTemplate.Properties.WeapFireType.Contains("fullauto")
|
||||
? new UpdFireMode
|
||||
{
|
||||
FireMode = "fullauto"
|
||||
}
|
||||
? new UpdFireMode { FireMode = "fullauto" }
|
||||
: new UpdFireMode
|
||||
{
|
||||
FireMode = _randomUtil.GetArrayValue(itemTemplate.Properties.WeapFireType)
|
||||
FireMode = _randomUtil.GetArrayValue(itemTemplate.Properties.WeapFireType),
|
||||
};
|
||||
hasProperties = true;
|
||||
}
|
||||
@@ -116,19 +121,22 @@ public class BotGeneratorHelper(
|
||||
HpResource = GetRandomizedResourceValue(
|
||||
itemTemplate.Properties.MaxHpResource ?? 0,
|
||||
randomisationSettings?.Meds
|
||||
)
|
||||
),
|
||||
};
|
||||
hasProperties = true;
|
||||
}
|
||||
|
||||
if (itemTemplate?.Properties?.MaxResource is not null && itemTemplate.Properties?.FoodUseTime is not null)
|
||||
if (
|
||||
itemTemplate?.Properties?.MaxResource is not null
|
||||
&& itemTemplate.Properties?.FoodUseTime is not null
|
||||
)
|
||||
{
|
||||
itemProperties.FoodDrink = new UpdFoodDrink
|
||||
{
|
||||
HpPercent = GetRandomizedResourceValue(
|
||||
itemTemplate.Properties.MaxResource ?? 0,
|
||||
randomisationSettings?.Food
|
||||
)
|
||||
),
|
||||
};
|
||||
hasProperties = true;
|
||||
}
|
||||
@@ -136,13 +144,22 @@ public class BotGeneratorHelper(
|
||||
if (itemTemplate?.Parent == BaseClasses.FLASHLIGHT)
|
||||
{
|
||||
// Get chance from botconfig for bot type
|
||||
var lightLaserActiveChance = raidSettings?.IsNightRaid ?? false
|
||||
? GetBotEquipmentSettingFromConfig(botRole, "lightIsActiveNightChancePercent", 50)
|
||||
: GetBotEquipmentSettingFromConfig(botRole, "lightIsActiveDayChancePercent", 25);
|
||||
var lightLaserActiveChance =
|
||||
raidSettings?.IsNightRaid ?? false
|
||||
? GetBotEquipmentSettingFromConfig(
|
||||
botRole,
|
||||
"lightIsActiveNightChancePercent",
|
||||
50
|
||||
)
|
||||
: GetBotEquipmentSettingFromConfig(
|
||||
botRole,
|
||||
"lightIsActiveDayChancePercent",
|
||||
25
|
||||
);
|
||||
itemProperties.Light = new UpdLight
|
||||
{
|
||||
IsActive = _randomUtil.GetChance100(lightLaserActiveChance),
|
||||
SelectedMode = 0
|
||||
SelectedMode = 0,
|
||||
};
|
||||
hasProperties = true;
|
||||
}
|
||||
@@ -157,7 +174,7 @@ public class BotGeneratorHelper(
|
||||
itemProperties.Light = new UpdLight
|
||||
{
|
||||
IsActive = _randomUtil.GetChance100(lightLaserActiveChance),
|
||||
SelectedMode = 0
|
||||
SelectedMode = 0,
|
||||
};
|
||||
hasProperties = true;
|
||||
}
|
||||
@@ -165,18 +182,22 @@ public class BotGeneratorHelper(
|
||||
if (itemTemplate?.Parent == BaseClasses.NIGHTVISION)
|
||||
{
|
||||
// Get chance from botconfig for bot type
|
||||
var nvgActiveChance = raidSettings?.IsNightRaid ?? false
|
||||
? GetBotEquipmentSettingFromConfig(botRole, "nvgIsActiveChanceNightPercent", 90)
|
||||
: GetBotEquipmentSettingFromConfig(botRole, "nvgIsActiveChanceDayPercent", 15);
|
||||
var nvgActiveChance =
|
||||
raidSettings?.IsNightRaid ?? false
|
||||
? GetBotEquipmentSettingFromConfig(botRole, "nvgIsActiveChanceNightPercent", 90)
|
||||
: GetBotEquipmentSettingFromConfig(botRole, "nvgIsActiveChanceDayPercent", 15);
|
||||
itemProperties.Togglable = new UpdTogglable
|
||||
{
|
||||
On = _randomUtil.GetChance100(nvgActiveChance)
|
||||
On = _randomUtil.GetChance100(nvgActiveChance),
|
||||
};
|
||||
hasProperties = true;
|
||||
}
|
||||
|
||||
// Togglable face shield
|
||||
if ((itemTemplate?.Properties?.HasHinge ?? false) && (itemTemplate.Properties.FaceShieldComponent ?? false))
|
||||
if (
|
||||
(itemTemplate?.Properties?.HasHinge ?? false)
|
||||
&& (itemTemplate.Properties.FaceShieldComponent ?? false)
|
||||
)
|
||||
{
|
||||
var faceShieldActiveChance = GetBotEquipmentSettingFromConfig(
|
||||
botRole,
|
||||
@@ -185,7 +206,7 @@ public class BotGeneratorHelper(
|
||||
);
|
||||
itemProperties.Togglable = new UpdTogglable
|
||||
{
|
||||
On = _randomUtil.GetChance100(faceShieldActiveChance)
|
||||
On = _randomUtil.GetChance100(faceShieldActiveChance),
|
||||
};
|
||||
hasProperties = true;
|
||||
}
|
||||
@@ -200,7 +221,10 @@ public class BotGeneratorHelper(
|
||||
/// <param name="maxResource">Max resource value of medical items</param>
|
||||
/// <param name="randomizationValues">Value provided from config</param>
|
||||
/// <returns>Randomized value from maxHpResource</returns>
|
||||
protected double GetRandomizedResourceValue(double maxResource, RandomisedResourceValues? randomizationValues)
|
||||
protected double GetRandomizedResourceValue(
|
||||
double maxResource,
|
||||
RandomisedResourceValues? randomizationValues
|
||||
)
|
||||
{
|
||||
if (randomizationValues is null)
|
||||
{
|
||||
@@ -225,7 +249,11 @@ public class BotGeneratorHelper(
|
||||
/// <param name="setting">the setting of the weapon attachment/helmet equipment to be activated</param>
|
||||
/// <param name="defaultValue">default value for the chance of activation if the botrole or bot equipment role is undefined</param>
|
||||
/// <returns>Percent chance to be active</returns>
|
||||
protected double? GetBotEquipmentSettingFromConfig(string? botRole, string setting, double defaultValue)
|
||||
protected double? GetBotEquipmentSettingFromConfig(
|
||||
string? botRole,
|
||||
string setting,
|
||||
double defaultValue
|
||||
)
|
||||
{
|
||||
if (botRole is null)
|
||||
{
|
||||
@@ -242,7 +270,7 @@ public class BotGeneratorHelper(
|
||||
{
|
||||
botRole,
|
||||
setting,
|
||||
defaultValue
|
||||
defaultValue,
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -251,8 +279,12 @@ public class BotGeneratorHelper(
|
||||
}
|
||||
|
||||
var props = botEquipmentSettings.GetType().GetProperties();
|
||||
var propValue = (double?) props.FirstOrDefault(x => string.Equals(x.Name, setting, StringComparison.CurrentCultureIgnoreCase))
|
||||
?.GetValue(botEquipmentSettings);
|
||||
var propValue = (double?)
|
||||
props
|
||||
.FirstOrDefault(x =>
|
||||
string.Equals(x.Name, setting, StringComparison.CurrentCultureIgnoreCase)
|
||||
)
|
||||
?.GetValue(botEquipmentSettings);
|
||||
|
||||
if (propValue is not null)
|
||||
{
|
||||
@@ -266,7 +298,7 @@ public class BotGeneratorHelper(
|
||||
{
|
||||
botRole,
|
||||
setting,
|
||||
defaultValue
|
||||
defaultValue,
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -280,9 +312,15 @@ public class BotGeneratorHelper(
|
||||
/// <param name="itemTemplate">weapon object being generated for</param>
|
||||
/// <param name="botRole">type of bot being generated for</param>
|
||||
/// <returns>Repairable object</returns>
|
||||
protected UpdRepairable GenerateWeaponRepairableProperties(TemplateItem itemTemplate, string? botRole = null)
|
||||
protected UpdRepairable GenerateWeaponRepairableProperties(
|
||||
TemplateItem itemTemplate,
|
||||
string? botRole = null
|
||||
)
|
||||
{
|
||||
var maxDurability = _durabilityLimitsHelper.GetRandomizedMaxWeaponDurability(itemTemplate, botRole);
|
||||
var maxDurability = _durabilityLimitsHelper.GetRandomizedMaxWeaponDurability(
|
||||
itemTemplate,
|
||||
botRole
|
||||
);
|
||||
var currentDurability = _durabilityLimitsHelper.GetRandomizedWeaponDurability(
|
||||
itemTemplate,
|
||||
botRole,
|
||||
@@ -292,7 +330,7 @@ public class BotGeneratorHelper(
|
||||
return new UpdRepairable
|
||||
{
|
||||
Durability = Math.Round(currentDurability, 5),
|
||||
MaxDurability = Math.Round(maxDurability, 5)
|
||||
MaxDurability = Math.Round(maxDurability, 5),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -302,7 +340,10 @@ public class BotGeneratorHelper(
|
||||
/// <param name="itemTemplate">weapon object being generated for</param>
|
||||
/// <param name="botRole">type of bot being generated for</param>
|
||||
/// <returns>Repairable object</returns>
|
||||
protected UpdRepairable GenerateArmorRepairableProperties(TemplateItem itemTemplate, string? botRole = null)
|
||||
protected UpdRepairable GenerateArmorRepairableProperties(
|
||||
TemplateItem itemTemplate,
|
||||
string? botRole = null
|
||||
)
|
||||
{
|
||||
double maxDurability;
|
||||
double currentDurability;
|
||||
@@ -313,7 +354,10 @@ public class BotGeneratorHelper(
|
||||
}
|
||||
else
|
||||
{
|
||||
maxDurability = _durabilityLimitsHelper.GetRandomizedMaxArmorDurability(itemTemplate, botRole);
|
||||
maxDurability = _durabilityLimitsHelper.GetRandomizedMaxArmorDurability(
|
||||
itemTemplate,
|
||||
botRole
|
||||
);
|
||||
currentDurability = _durabilityLimitsHelper.GetRandomizedArmorDurability(
|
||||
itemTemplate,
|
||||
botRole,
|
||||
@@ -324,7 +368,7 @@ public class BotGeneratorHelper(
|
||||
return new UpdRepairable
|
||||
{
|
||||
Durability = Math.Round(currentDurability, 5),
|
||||
MaxDurability = Math.Round(maxDurability, 5)
|
||||
MaxDurability = Math.Round(maxDurability, 5),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -335,7 +379,11 @@ public class BotGeneratorHelper(
|
||||
/// <param name="tplToCheck">Tpl of the item to check for incompatibilities</param>
|
||||
/// <param name="equipmentSlot">Slot the item will be placed into</param>
|
||||
/// <returns>false if no incompatibilities, also has incompatibility reason</returns>
|
||||
public ChooseRandomCompatibleModResult IsItemIncompatibleWithCurrentItems(List<Item> itemsEquipped, string tplToCheck, string equipmentSlot)
|
||||
public ChooseRandomCompatibleModResult IsItemIncompatibleWithCurrentItems(
|
||||
List<Item> itemsEquipped,
|
||||
string tplToCheck,
|
||||
string equipmentSlot
|
||||
)
|
||||
{
|
||||
// Skip slots that have no incompatibilities
|
||||
if (_slotsWithNoCompatIssues.Contains(equipmentSlot))
|
||||
@@ -344,12 +392,14 @@ public class BotGeneratorHelper(
|
||||
{
|
||||
Incompatible = false,
|
||||
Found = false,
|
||||
Reason = ""
|
||||
Reason = "",
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Can probably be optimized to cache itemTemplates as items are added to inventory
|
||||
var equippedItemsDb = itemsEquipped.Select(equippedItem => _itemHelper.GetItem(equippedItem.Template).Value).ToList();
|
||||
var equippedItemsDb = itemsEquipped
|
||||
.Select(equippedItem => _itemHelper.GetItem(equippedItem.Template).Value)
|
||||
.ToList();
|
||||
var (itemIsValid, itemToEquip) = _itemHelper.GetItem(tplToCheck);
|
||||
|
||||
if (!itemIsValid)
|
||||
@@ -357,11 +407,7 @@ public class BotGeneratorHelper(
|
||||
_logger.Warning(
|
||||
_localisationService.GetText(
|
||||
"bot-invalid_item_compatibility_check",
|
||||
new
|
||||
{
|
||||
itemTpl = tplToCheck,
|
||||
slot = equipmentSlot
|
||||
}
|
||||
new { itemTpl = tplToCheck, slot = equipmentSlot }
|
||||
)
|
||||
);
|
||||
|
||||
@@ -369,7 +415,7 @@ public class BotGeneratorHelper(
|
||||
{
|
||||
Incompatible = true,
|
||||
Found = false,
|
||||
Reason = $"item: {tplToCheck} does not exist in the database"
|
||||
Reason = $"item: {tplToCheck} does not exist in the database",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -382,7 +428,7 @@ public class BotGeneratorHelper(
|
||||
{
|
||||
id = itemToEquip?.Id,
|
||||
name = itemToEquip?.Name,
|
||||
slot = equipmentSlot
|
||||
slot = equipmentSlot,
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -391,51 +437,60 @@ public class BotGeneratorHelper(
|
||||
{
|
||||
Incompatible = true,
|
||||
Found = false,
|
||||
Reason = $"item: {tplToCheck} does not have a _props field"
|
||||
Reason = $"item: {tplToCheck} does not have a _props field",
|
||||
};
|
||||
}
|
||||
|
||||
// Does an equipped item have a property that blocks the desired item - check for prop "BlocksX" .e.g BlocksEarpiece / BlocksFaceCover
|
||||
var templateItems = equippedItemsDb.ToList();
|
||||
var blockingItem = templateItems.FirstOrDefault(item => HasBlockingProperty(item, equipmentSlot));
|
||||
var blockingItem = templateItems.FirstOrDefault(item =>
|
||||
HasBlockingProperty(item, equipmentSlot)
|
||||
);
|
||||
if (blockingItem is not null)
|
||||
// this.logger.warning(`1 incompatibility found between - {itemToEquip[1]._name} and {blockingItem._name} - {equipmentSlot}`);
|
||||
// this.logger.warning(`1 incompatibility found between - {itemToEquip[1]._name} and {blockingItem._name} - {equipmentSlot}`);
|
||||
{
|
||||
return new ChooseRandomCompatibleModResult
|
||||
{
|
||||
Incompatible = true,
|
||||
Found = false,
|
||||
Reason = $"{tplToCheck} {itemToEquip.Name} in slot: {equipmentSlot} blocked by: {blockingItem.Id} {blockingItem.Name}",
|
||||
SlotBlocked = true
|
||||
Reason =
|
||||
$"{tplToCheck} {itemToEquip.Name} in slot: {equipmentSlot} blocked by: {blockingItem.Id} {blockingItem.Name}",
|
||||
SlotBlocked = true,
|
||||
};
|
||||
}
|
||||
|
||||
// Check if any of the current inventory templates have the incoming item defined as incompatible
|
||||
blockingItem = templateItems.FirstOrDefault(x => x?.Properties?.ConflictingItems?.Contains(tplToCheck) ?? false);
|
||||
blockingItem = templateItems.FirstOrDefault(x =>
|
||||
x?.Properties?.ConflictingItems?.Contains(tplToCheck) ?? false
|
||||
);
|
||||
if (blockingItem is not null)
|
||||
// this.logger.warning(`2 incompatibility found between - {itemToEquip[1]._name} and {blockingItem._props.Name} - {equipmentSlot}`);
|
||||
// this.logger.warning(`2 incompatibility found between - {itemToEquip[1]._name} and {blockingItem._props.Name} - {equipmentSlot}`);
|
||||
{
|
||||
return new ChooseRandomCompatibleModResult
|
||||
{
|
||||
Incompatible = true,
|
||||
Found = false,
|
||||
Reason = $"{tplToCheck} {itemToEquip.Name} in slot: {equipmentSlot} blocked by: {blockingItem.Id} {blockingItem.Name}",
|
||||
SlotBlocked = true
|
||||
Reason =
|
||||
$"{tplToCheck} {itemToEquip.Name} in slot: {equipmentSlot} blocked by: {blockingItem.Id} {blockingItem.Name}",
|
||||
SlotBlocked = true,
|
||||
};
|
||||
}
|
||||
|
||||
// Does item being checked get blocked/block existing item
|
||||
if (itemToEquip.Properties.BlocksHeadwear ?? false)
|
||||
{
|
||||
var existingHeadwear = itemsEquipped.FirstOrDefault(x => x.SlotId == Containers.Headwear);
|
||||
var existingHeadwear = itemsEquipped.FirstOrDefault(x =>
|
||||
x.SlotId == Containers.Headwear
|
||||
);
|
||||
if (existingHeadwear is not null)
|
||||
{
|
||||
return new ChooseRandomCompatibleModResult
|
||||
{
|
||||
Incompatible = true,
|
||||
Found = false,
|
||||
Reason = $"{tplToCheck} {itemToEquip.Name} is blocked by: {existingHeadwear.Template} in slot: {existingHeadwear.SlotId}",
|
||||
SlotBlocked = true
|
||||
Reason =
|
||||
$"{tplToCheck} {itemToEquip.Name} is blocked by: {existingHeadwear.Template} in slot: {existingHeadwear.SlotId}",
|
||||
SlotBlocked = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -443,15 +498,18 @@ public class BotGeneratorHelper(
|
||||
// Does item being checked get blocked/block existing item
|
||||
if (itemToEquip.Properties.BlocksFaceCover.GetValueOrDefault(false))
|
||||
{
|
||||
var existingFaceCover = itemsEquipped.FirstOrDefault(item => item.SlotId == Containers.FaceCover);
|
||||
var existingFaceCover = itemsEquipped.FirstOrDefault(item =>
|
||||
item.SlotId == Containers.FaceCover
|
||||
);
|
||||
if (existingFaceCover is not null)
|
||||
{
|
||||
return new ChooseRandomCompatibleModResult
|
||||
{
|
||||
Incompatible = true,
|
||||
Found = false,
|
||||
Reason = $"{tplToCheck} {itemToEquip.Name} is blocked by: {existingFaceCover.Template} in slot: {existingFaceCover.SlotId}",
|
||||
SlotBlocked = true
|
||||
Reason =
|
||||
$"{tplToCheck} {itemToEquip.Name} is blocked by: {existingFaceCover.Template} in slot: {existingFaceCover.SlotId}",
|
||||
SlotBlocked = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -459,15 +517,18 @@ public class BotGeneratorHelper(
|
||||
// Does item being checked get blocked/block existing item
|
||||
if (itemToEquip.Properties.BlocksEarpiece.GetValueOrDefault(false))
|
||||
{
|
||||
var existingEarpiece = itemsEquipped.FirstOrDefault(item => item.SlotId == Containers.Earpiece);
|
||||
var existingEarpiece = itemsEquipped.FirstOrDefault(item =>
|
||||
item.SlotId == Containers.Earpiece
|
||||
);
|
||||
if (existingEarpiece is not null)
|
||||
{
|
||||
return new ChooseRandomCompatibleModResult
|
||||
{
|
||||
Incompatible = true,
|
||||
Found = false,
|
||||
Reason = $"{tplToCheck} {itemToEquip.Name} is blocked by: {existingEarpiece.Template} in slot: {existingEarpiece.SlotId}",
|
||||
SlotBlocked = true
|
||||
Reason =
|
||||
$"{tplToCheck} {itemToEquip.Name} is blocked by: {existingEarpiece.Template} in slot: {existingEarpiece.SlotId}",
|
||||
SlotBlocked = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -475,42 +536,46 @@ public class BotGeneratorHelper(
|
||||
// Does item being checked get blocked/block existing item
|
||||
if (itemToEquip.Properties.BlocksArmorVest.GetValueOrDefault(false))
|
||||
{
|
||||
var existingArmorVest = itemsEquipped.FirstOrDefault(item => item.SlotId == Containers.ArmorVest);
|
||||
var existingArmorVest = itemsEquipped.FirstOrDefault(item =>
|
||||
item.SlotId == Containers.ArmorVest
|
||||
);
|
||||
if (existingArmorVest is not null)
|
||||
{
|
||||
return new ChooseRandomCompatibleModResult
|
||||
{
|
||||
Incompatible = true,
|
||||
Found = false,
|
||||
Reason = $"{tplToCheck} {itemToEquip.Name} is blocked by: {existingArmorVest.Template} in slot: {existingArmorVest.SlotId}",
|
||||
SlotBlocked = true
|
||||
Reason =
|
||||
$"{tplToCheck} {itemToEquip.Name} is blocked by: {existingArmorVest.Template} in slot: {existingArmorVest.SlotId}",
|
||||
SlotBlocked = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the incoming item has any inventory items defined as incompatible
|
||||
var blockingInventoryItem = itemsEquipped.FirstOrDefault(x => itemToEquip.Properties.ConflictingItems?.Contains(x.Template) ?? false);
|
||||
var blockingInventoryItem = itemsEquipped.FirstOrDefault(x =>
|
||||
itemToEquip.Properties.ConflictingItems?.Contains(x.Template) ?? false
|
||||
);
|
||||
if (blockingInventoryItem is not null)
|
||||
// this.logger.warning(`3 incompatibility found between - {itemToEquip[1]._name} and {blockingInventoryItem._tpl} - {equipmentSlot}`)
|
||||
// this.logger.warning(`3 incompatibility found between - {itemToEquip[1]._name} and {blockingInventoryItem._tpl} - {equipmentSlot}`)
|
||||
{
|
||||
return new ChooseRandomCompatibleModResult
|
||||
{
|
||||
Incompatible = true,
|
||||
Found = false,
|
||||
Reason = $"{tplToCheck} blocks existing item {blockingInventoryItem.Template} in slot {blockingInventoryItem.SlotId}"
|
||||
Reason =
|
||||
$"{tplToCheck} blocks existing item {blockingInventoryItem.Template} in slot {blockingInventoryItem.SlotId}",
|
||||
};
|
||||
}
|
||||
|
||||
return new ChooseRandomCompatibleModResult
|
||||
{
|
||||
Incompatible = false,
|
||||
Reason = ""
|
||||
};
|
||||
return new ChooseRandomCompatibleModResult { Incompatible = false, Reason = "" };
|
||||
}
|
||||
|
||||
protected bool HasBlockingProperty(TemplateItem? item, string blockingPropertyName)
|
||||
{
|
||||
return item != null && item.Blocks.TryGetValue(blockingPropertyName, out var blocks) && blocks;
|
||||
return item != null
|
||||
&& item.Blocks.TryGetValue(blockingPropertyName, out var blocks)
|
||||
&& blocks;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -541,7 +606,8 @@ public class BotGeneratorHelper(
|
||||
string? rootItemTplId,
|
||||
List<Item> itemWithChildren,
|
||||
BotBaseInventory inventory,
|
||||
HashSet<string>? containersIdFull = null)
|
||||
HashSet<string>? containersIdFull = null
|
||||
)
|
||||
{
|
||||
// Track how many containers are unable to be found
|
||||
var missingContainerCount = 0;
|
||||
@@ -553,7 +619,9 @@ public class BotGeneratorHelper(
|
||||
}
|
||||
|
||||
// Get container to put item into
|
||||
var container = inventory.Items.FirstOrDefault(item => item.SlotId == equipmentSlotId.ToString());
|
||||
var container = inventory.Items.FirstOrDefault(item =>
|
||||
item.SlotId == equipmentSlotId.ToString()
|
||||
);
|
||||
if (container is null)
|
||||
{
|
||||
missingContainerCount++;
|
||||
@@ -578,20 +646,29 @@ public class BotGeneratorHelper(
|
||||
var (key, value) = _itemHelper.GetItem(container.Template);
|
||||
if (!key)
|
||||
{
|
||||
_logger.Warning(_localisationService.GetText("bot-missing_container_with_tpl", container.Template));
|
||||
_logger.Warning(
|
||||
_localisationService.GetText(
|
||||
"bot-missing_container_with_tpl",
|
||||
container.Template
|
||||
)
|
||||
);
|
||||
|
||||
// Bad item, skip
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value?.Properties?.Grids?.Count == 0)
|
||||
// Container has no slots to hold items
|
||||
// Container has no slots to hold items
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get x/y grid size of item
|
||||
var itemSize = _inventoryHelper.GetItemSize(rootItemTplId, rootItemId, itemWithChildren);
|
||||
var itemSize = _inventoryHelper.GetItemSize(
|
||||
rootItemTplId,
|
||||
rootItemId,
|
||||
itemWithChildren
|
||||
);
|
||||
|
||||
// Iterate over each grid in the container and look for a big enough space for the item to be placed in
|
||||
var currentGridCount = 1;
|
||||
@@ -599,27 +676,35 @@ public class BotGeneratorHelper(
|
||||
foreach (var slotGrid in value?.Properties?.Grids ?? [])
|
||||
{
|
||||
// Grid is empty, skip or item size is bigger than grid
|
||||
if (slotGrid.Props?.CellsH == 0 ||
|
||||
slotGrid.Props?.CellsV == 0 ||
|
||||
itemSize[0] * itemSize[1] > slotGrid.Props?.CellsV * slotGrid.Props?.CellsH)
|
||||
if (
|
||||
slotGrid.Props?.CellsH == 0
|
||||
|| slotGrid.Props?.CellsV == 0
|
||||
|| itemSize[0] * itemSize[1] > slotGrid.Props?.CellsV * slotGrid.Props?.CellsH
|
||||
)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Can't put item type in grid, skip all grids as we're assuming they have the same rules
|
||||
if (!ItemAllowedInContainer(slotGrid, rootItemTplId))
|
||||
// Multiple containers, maybe next one allows item, only break out of loop for the containers grids
|
||||
// Multiple containers, maybe next one allows item, only break out of loop for the containers grids
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Get all root items in found container
|
||||
var existingContainerItems = (inventory.Items ?? []).Where(item => item.ParentId == container.Id && item.SlotId == slotGrid.Name
|
||||
var existingContainerItems = (inventory.Items ?? []).Where(item =>
|
||||
item.ParentId == container.Id && item.SlotId == slotGrid.Name
|
||||
);
|
||||
|
||||
// Get root items in container we can iterate over to find out what space is free
|
||||
var containerItemsToCheck = existingContainerItems.Where(x => x.SlotId == slotGrid.Name);
|
||||
var containerItemsWithChildren = GetContainerItemsWithChildren(containerItemsToCheck, inventory.Items);
|
||||
var containerItemsToCheck = existingContainerItems.Where(x =>
|
||||
x.SlotId == slotGrid.Name
|
||||
);
|
||||
var containerItemsWithChildren = GetContainerItemsWithChildren(
|
||||
containerItemsToCheck,
|
||||
inventory.Items
|
||||
);
|
||||
|
||||
if (slotGrid.Props is not null)
|
||||
{
|
||||
@@ -632,7 +717,11 @@ public class BotGeneratorHelper(
|
||||
);
|
||||
|
||||
// Try to fit item into grid
|
||||
var findSlotResult = _containerHelper.FindSlotForItem(slotGridMap, itemSize[0], itemSize[1]);
|
||||
var findSlotResult = _containerHelper.FindSlotForItem(
|
||||
slotGridMap,
|
||||
itemSize[0],
|
||||
itemSize[1]
|
||||
);
|
||||
|
||||
// Free slot found, add item
|
||||
if (findSlotResult.Success ?? false)
|
||||
@@ -645,12 +734,14 @@ public class BotGeneratorHelper(
|
||||
parentItem.ParentId = container.Id;
|
||||
parentItem.SlotId = slotGrid.Name;
|
||||
parentItem.Location = new ItemLocation
|
||||
{
|
||||
X = findSlotResult.X,
|
||||
Y = findSlotResult.Y,
|
||||
R = findSlotResult.Rotation ?? false ? ItemRotation.Vertical : ItemRotation.Horizontal
|
||||
}
|
||||
;
|
||||
{
|
||||
X = findSlotResult.X,
|
||||
Y = findSlotResult.Y,
|
||||
R =
|
||||
findSlotResult.Rotation ?? false
|
||||
? ItemRotation.Vertical
|
||||
: ItemRotation.Horizontal,
|
||||
};
|
||||
}
|
||||
|
||||
(inventory.Items ?? []).AddRange(itemWithChildren);
|
||||
@@ -691,7 +782,10 @@ public class BotGeneratorHelper(
|
||||
/// <param name="containerRootItems"></param>
|
||||
/// <param name="inventoryItems"></param>
|
||||
/// <returns></returns>
|
||||
protected List<Item> GetContainerItemsWithChildren(IEnumerable<Item> containerRootItems, List<Item> inventoryItems)
|
||||
protected List<Item> GetContainerItemsWithChildren(
|
||||
IEnumerable<Item> containerRootItems,
|
||||
List<Item> inventoryItems
|
||||
)
|
||||
{
|
||||
var result = new List<Item>();
|
||||
if (!containerRootItems.Any())
|
||||
@@ -706,7 +800,10 @@ public class BotGeneratorHelper(
|
||||
{
|
||||
// Check item in container for children, store for later insertion into `containerItemsToCheck`
|
||||
// (used later when figuring out how much space weapon takes up)
|
||||
var itemWithChildItems = _itemHelper.FindAndReturnChildrenAsItems(itemsWithoutLocation, rootItem.Id);
|
||||
var itemWithChildItems = _itemHelper.FindAndReturnChildrenAsItems(
|
||||
itemsWithoutLocation,
|
||||
rootItem.Id
|
||||
);
|
||||
|
||||
// Item had children, replace existing data with item + its children
|
||||
result.Add(rootItem);
|
||||
@@ -729,7 +826,7 @@ public class BotGeneratorHelper(
|
||||
var filter = propFilters?.FirstOrDefault()?.Filter ?? [];
|
||||
|
||||
if (propFilters?.Count == 0)
|
||||
// no filters, item is fine to add
|
||||
// no filters, item is fine to add
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user