Handle generating a fence armor item and a default plate is not found

Add extra plates to pool

Centralise plate-related checks into itemhelper
This commit is contained in:
Dev 2024-01-10 14:47:09 +00:00
parent 7ee3be1e2b
commit dc1e172df0
3 changed files with 30 additions and 10 deletions

View File

@ -180,7 +180,7 @@ export class BotEquipmentModGenerator
protected filterPlateModsForSlotByLevel(settings: IGenerateEquipmentProperties, modSlot: string, modPool: string[], armorItem: ITemplateItem): string[]
{
// Not pmc or not a plate slot, return original mod pool array
if (!this.slotIsPlate(modSlot))
if (!this.itemHelper.isRemovablePlateSlot(modSlot))
{
return modPool;
}
@ -225,11 +225,6 @@ export class BotEquipmentModGenerator
}
protected slotIsPlate(modSlot: string): boolean
{
return ["front_plate", "back_plate", "side_plate"].includes(modSlot.toLowerCase());
}
/**
* Add mods to a weapon using the provided mod pool
* @param sessionId session id

View File

@ -1276,6 +1276,25 @@ export class ItemHelper
return chosenTpl;
}
/**
* Is the provided item._props.Slots._name property a plate slot
* @param slotName Name of slot (_name) of Items Slot array
* @returns True if its a slot that holds a removable palte
*/
public isRemovablePlateSlot(slotName: string): boolean
{
return this.getRevovablePlateSlotIds().includes(slotName.toLowerCase());
}
/**
* Get a list of slot names that hold removable plates
* @returns Array of slot ids (e.g. front_plate)
*/
public getRevovablePlateSlotIds(): string[]
{
return ["front_plate", "back_plate", "side_plate", "left_side_plate", "right_side_plate"];
}
}
namespace ItemHelper

View File

@ -532,9 +532,8 @@ export class FenceService
}
// Check for and add plate items
const plateSlots = itemDbDetails._props.Slots.filter(slot => ["front_plate", "back_plate", "side_plate"].includes(slot._name.toLowerCase()));
const hasPlateSlots = plateSlots.length > 0;
if (hasPlateSlots)
const plateSlots = itemDbDetails._props.Slots.filter(slot => this.itemHelper.isRemovablePlateSlot(slot._name));
if (plateSlots.length > 0)
{
for (const plateSlot of plateSlots)
{
@ -544,7 +543,14 @@ export class FenceService
continue;
}
const modItemDbDetails = this.itemHelper.getItem(plateSlot._props.filters[0].Plate)[1];
const plateTpl = plateSlot._props.filters[0].Plate
if (!plateTpl)
{
this.logger.warning(`Fence generation: item: ${itemDbDetails._id} ${itemDbDetails._name} lacks a default plate for slot: ${plateSlot._name}, skipping`);
continue;
}
const modItemDbDetails = this.itemHelper.getItem(plateTpl)[1];
const durabilityValues = this.getRandomisedArmorDurabilityValues(modItemDbDetails, this.traderConfig.fence.armorMaxDurabilityPercentMinMax);
armor.push({
_id: this.hashUtil.generate(),