Improve armor slot compatibility checking
This commit is contained in:
parent
81960a23fe
commit
9616f9b34b
@ -49,6 +49,7 @@ import { TimeUtil } from "@spt-aki/utils/TimeUtil";
|
|||||||
@injectable()
|
@injectable()
|
||||||
export class HideoutController
|
export class HideoutController
|
||||||
{
|
{
|
||||||
|
/** Key used in TaskConditionCounters array */
|
||||||
protected static nameTaskConditionCountersCrafting = "CounterHoursCrafting";
|
protected static nameTaskConditionCountersCrafting = "CounterHoursCrafting";
|
||||||
protected hideoutConfig: IHideoutConfig;
|
protected hideoutConfig: IHideoutConfig;
|
||||||
|
|
||||||
|
@ -239,11 +239,19 @@ export class BotInventoryGenerator
|
|||||||
randomisationDetails: randomistionDetails
|
randomisationDetails: randomistionDetails
|
||||||
});
|
});
|
||||||
|
|
||||||
// Bot has no armor vest
|
// Bot has no armor vest and flagged to be foreced to wear armored rig in this event
|
||||||
if (botEquipConfig.forceOnlyArmoredRigWhenNoArmor && !botInventory.items.find(item => item.slotId === "ArmorVest"))
|
const hasArmorVest = botInventory.items.some(item => item.slotId === "ArmorVest")
|
||||||
|
if (botEquipConfig.forceOnlyArmoredRigWhenNoArmor && !hasArmorVest)
|
||||||
{
|
{
|
||||||
// Filter rigs down to only those with armor
|
// Filter rigs down to only those with armor
|
||||||
this.filterRigsToOnlyThoseWithProtection(templateInventory);
|
this.filterRigsToThoseWithProtection(templateInventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optimisation - Remove armored rigs from pool
|
||||||
|
if (hasArmorVest)
|
||||||
|
{
|
||||||
|
// Filter rigs down to only those with armor
|
||||||
|
this.filterRigsToThoseWithoutProtection(templateInventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.generateEquipment({
|
this.generateEquipment({
|
||||||
@ -263,7 +271,7 @@ export class BotInventoryGenerator
|
|||||||
* Remove non-armored rigs from parameter data
|
* Remove non-armored rigs from parameter data
|
||||||
* @param templateInventory
|
* @param templateInventory
|
||||||
*/
|
*/
|
||||||
protected filterRigsToOnlyThoseWithProtection(templateInventory: Inventory): void
|
protected filterRigsToThoseWithProtection(templateInventory: Inventory): void
|
||||||
{
|
{
|
||||||
const tacVestsWithArmor = Object.entries(templateInventory.equipment.TacticalVest)
|
const tacVestsWithArmor = Object.entries(templateInventory.equipment.TacticalVest)
|
||||||
.reduce((newVestDictionary, [tplKey]) =>
|
.reduce((newVestDictionary, [tplKey]) =>
|
||||||
@ -278,6 +286,25 @@ export class BotInventoryGenerator
|
|||||||
templateInventory.equipment.TacticalVest = tacVestsWithArmor;
|
templateInventory.equipment.TacticalVest = tacVestsWithArmor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove armored rigs from parameter data
|
||||||
|
* @param templateInventory
|
||||||
|
*/
|
||||||
|
protected filterRigsToThoseWithoutProtection(templateInventory: Inventory): void
|
||||||
|
{
|
||||||
|
const tacVestsWithoutArmor = Object.entries(templateInventory.equipment.TacticalVest)
|
||||||
|
.reduce((newVestDictionary, [tplKey]) =>
|
||||||
|
{
|
||||||
|
if (this.itemHelper.getItem(tplKey)[1]._props.Slots?.length === 0)
|
||||||
|
{
|
||||||
|
newVestDictionary[tplKey] = templateInventory.equipment.TacticalVest[tplKey];
|
||||||
|
}
|
||||||
|
return newVestDictionary;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
templateInventory.equipment.TacticalVest = tacVestsWithoutArmor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a piece of equipment with mods to inventory from the provided pools
|
* Add a piece of equipment with mods to inventory from the provided pools
|
||||||
* @param settings Values to adjust how item is chosen and added to bot
|
* @param settings Values to adjust how item is chosen and added to bot
|
||||||
@ -302,6 +329,8 @@ export class BotInventoryGenerator
|
|||||||
{
|
{
|
||||||
let pickedItemDb: ITemplateItem;
|
let pickedItemDb: ITemplateItem;
|
||||||
let found = false;
|
let found = false;
|
||||||
|
|
||||||
|
const maxAttempts = Math.round(Object.keys(settings.rootEquipmentPool).length * 0.75); // Roughly 75% of pool size
|
||||||
let attempts = 0;
|
let attempts = 0;
|
||||||
while (!found)
|
while (!found)
|
||||||
{
|
{
|
||||||
@ -332,14 +361,8 @@ export class BotInventoryGenerator
|
|||||||
settings.rootEquipmentSlot);
|
settings.rootEquipmentSlot);
|
||||||
if (compatabilityResult.incompatible)
|
if (compatabilityResult.incompatible)
|
||||||
{
|
{
|
||||||
// Entire slot is blocked by another item, no point in checking other items
|
// Tried x different items that failed, stop
|
||||||
if (compatabilityResult.slotBlocked)
|
if (attempts > maxAttempts)
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tried 8 different items that failed, stop
|
|
||||||
if (attempts >= 8)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user