Cleaned up randomiseArmorModDurability()
This commit is contained in:
parent
8517e46ccb
commit
1ba6cbf2bd
@ -5,7 +5,7 @@ import { PresetHelper } from "@spt/helpers/PresetHelper";
|
|||||||
import { IFenceLevel } from "@spt/models/eft/common/IGlobals";
|
import { IFenceLevel } from "@spt/models/eft/common/IGlobals";
|
||||||
import { IPmcData } from "@spt/models/eft/common/IPmcData";
|
import { IPmcData } from "@spt/models/eft/common/IPmcData";
|
||||||
import { Item, Repairable } from "@spt/models/eft/common/tables/IItem";
|
import { Item, Repairable } from "@spt/models/eft/common/tables/IItem";
|
||||||
import { ITemplateItem } from "@spt/models/eft/common/tables/ITemplateItem";
|
import { ITemplateItem, Slot } from "@spt/models/eft/common/tables/ITemplateItem";
|
||||||
import { IBarterScheme, ITraderAssort } from "@spt/models/eft/common/tables/ITrader";
|
import { IBarterScheme, ITraderAssort } from "@spt/models/eft/common/tables/ITrader";
|
||||||
import { BaseClasses } from "@spt/models/enums/BaseClasses";
|
import { BaseClasses } from "@spt/models/enums/BaseClasses";
|
||||||
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
|
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
|
||||||
@ -1142,8 +1142,8 @@ export class FenceService
|
|||||||
*/
|
*/
|
||||||
protected randomiseArmorModDurability(armor: Item[], itemDbDetails: ITemplateItem): void
|
protected randomiseArmorModDurability(armor: Item[], itemDbDetails: ITemplateItem): void
|
||||||
{
|
{
|
||||||
// Armor has no mods, make no changes
|
// Armor has no mods, nothing to randomise
|
||||||
const hasMods = (itemDbDetails._props.Slots?.length ?? 0) > 0;
|
const hasMods = Boolean(itemDbDetails._props.Slots);
|
||||||
if (!hasMods)
|
if (!hasMods)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -1151,10 +1151,29 @@ export class FenceService
|
|||||||
|
|
||||||
// Check for and adjust soft insert durability values
|
// Check for and adjust soft insert durability values
|
||||||
const requiredSlots = itemDbDetails._props.Slots?.filter((slot) => slot._required);
|
const requiredSlots = itemDbDetails._props.Slots?.filter((slot) => slot._required);
|
||||||
const hasRequiredSlots = (requiredSlots?.length ?? 0) > 0;
|
if (Boolean(requiredSlots?.length))
|
||||||
if (hasRequiredSlots)
|
|
||||||
{
|
{
|
||||||
for (const requiredSlot of requiredSlots!)
|
this.randomiseArmorSoftInsertDurabilities(requiredSlots, armor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for and adjust plate durability values
|
||||||
|
const plateSlots = itemDbDetails._props.Slots?.filter((slot) =>
|
||||||
|
this.itemHelper.isRemovablePlateSlot(slot._name),
|
||||||
|
);
|
||||||
|
if (Boolean(plateSlots?.length))
|
||||||
|
{
|
||||||
|
this.randomiseArmorInsertsDurabilities(plateSlots, armor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Randomise the durability values of items on armor with a passed in slot
|
||||||
|
* @param softInsertSlots Slots of items to randomise
|
||||||
|
* @param armorItemAndMods Array of armor + inserts to get items from
|
||||||
|
*/
|
||||||
|
protected randomiseArmorSoftInsertDurabilities(softInsertSlots: Slot[], armorItemAndMods: Item[]): void
|
||||||
|
{
|
||||||
|
for (const requiredSlot of softInsertSlots!)
|
||||||
{
|
{
|
||||||
const modItemDbDetails = this.itemHelper.getItem(requiredSlot._props.filters[0].Plate!)[1];
|
const modItemDbDetails = this.itemHelper.getItem(requiredSlot._props.filters[0].Plate!)[1];
|
||||||
const durabilityValues = this.getRandomisedArmorDurabilityValues(
|
const durabilityValues = this.getRandomisedArmorDurabilityValues(
|
||||||
@ -1169,7 +1188,7 @@ export class FenceService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find items mod to apply dura changes to
|
// Find items mod to apply dura changes to
|
||||||
const modItemToAdjust = armor.find(
|
const modItemToAdjust = armorItemAndMods.find(
|
||||||
(mod) => mod.slotId!.toLowerCase() === requiredSlot._name.toLowerCase(),
|
(mod) => mod.slotId!.toLowerCase() === requiredSlot._name.toLowerCase(),
|
||||||
)!;
|
)!;
|
||||||
|
|
||||||
@ -1185,7 +1204,7 @@ export class FenceService
|
|||||||
modItemToAdjust.upd!.Repairable.Durability = durabilityValues.Durability;
|
modItemToAdjust.upd!.Repairable.Durability = durabilityValues.Durability;
|
||||||
modItemToAdjust.upd!.Repairable.MaxDurability = durabilityValues.MaxDurability;
|
modItemToAdjust.upd!.Repairable.MaxDurability = durabilityValues.MaxDurability;
|
||||||
|
|
||||||
// 25% chance to add shots to visor when its below max durability
|
// 25% chance to add shots to visor items when its below max durability
|
||||||
if (
|
if (
|
||||||
this.randomUtil.getChance100(25)
|
this.randomUtil.getChance100(25)
|
||||||
&& modItemToAdjust.parentId === BaseClasses.ARMORED_EQUIPMENT
|
&& modItemToAdjust.parentId === BaseClasses.ARMORED_EQUIPMENT
|
||||||
@ -1199,11 +1218,12 @@ export class FenceService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for and adjust plate durability values
|
/**
|
||||||
const plateSlots = itemDbDetails._props.Slots?.filter((slot) =>
|
* Randomise the durability values of plate items in armor
|
||||||
this.itemHelper.isRemovablePlateSlot(slot._name),
|
* @param plateSlots Slots of items to randomise
|
||||||
);
|
* @param armorItemAndMods Array of armor + inserts to get items from
|
||||||
if ((plateSlots?.length ?? 0) > 0)
|
*/
|
||||||
|
protected randomiseArmorInsertsDurabilities(plateSlots: Slot[], armorItemAndMods: Item[]): void
|
||||||
{
|
{
|
||||||
for (const plateSlot of plateSlots!)
|
for (const plateSlot of plateSlots!)
|
||||||
{
|
{
|
||||||
@ -1219,6 +1239,7 @@ export class FenceService
|
|||||||
// Bsg data lacks a default plate, skip adding mod
|
// Bsg data lacks a default plate, skip adding mod
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const modItemDbDetails = this.itemHelper.getItem(plateTpl)[1];
|
const modItemDbDetails = this.itemHelper.getItem(plateTpl)[1];
|
||||||
const durabilityValues = this.getRandomisedArmorDurabilityValues(
|
const durabilityValues = this.getRandomisedArmorDurabilityValues(
|
||||||
modItemDbDetails,
|
modItemDbDetails,
|
||||||
@ -1226,7 +1247,8 @@ export class FenceService
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Find items mod to apply dura changes to
|
// Find items mod to apply dura changes to
|
||||||
const modItemToAdjust = armor.find((mod) => mod.slotId!.toLowerCase() === plateSlot._name.toLowerCase());
|
const modItemToAdjust = armorItemAndMods
|
||||||
|
.find((mod) => mod.slotId!.toLowerCase() === plateSlot._name.toLowerCase());
|
||||||
this.itemHelper.addUpdObjectToItem(modItemToAdjust!);
|
this.itemHelper.addUpdObjectToItem(modItemToAdjust!);
|
||||||
|
|
||||||
if (!modItemToAdjust?.upd?.Repairable)
|
if (!modItemToAdjust?.upd?.Repairable)
|
||||||
@ -1241,7 +1263,6 @@ export class FenceService
|
|||||||
modItemToAdjust!.upd!.Repairable.MaxDurability = durabilityValues.MaxDurability;
|
modItemToAdjust!.upd!.Repairable.MaxDurability = durabilityValues.MaxDurability;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get stack size of a singular item (no mods)
|
* Get stack size of a singular item (no mods)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user