Additional changes to randomiseWeaponDurabilityValues()

Move chance to make changes check outside of function
Aliased ragfair config property
Aliased chosen child multipler value
Added comment to function
This commit is contained in:
Dev 2024-01-13 09:15:11 +00:00
parent a87129c541
commit 48f99ecfa6
2 changed files with 40 additions and 30 deletions

View File

@ -130,7 +130,7 @@
},
"57bef4c42459772e8d35a53b": {
"_name": "ARMORED_EQUIPMENT",
"conditionChance": 0.6,
"conditionChance": 0.25,
"min": 0.05,
"max": 1
},

View File

@ -588,6 +588,12 @@ export class RagfairOfferGenerator
// Randomise armor
if (this.itemHelper.armorItemCanHoldMods(rootItem._tpl))
{
// Chance to not adjust armor
if (!this.randomUtil.getChance100(this.ragfairConfig.dynamic.condition[BaseClasses.ARMORED_EQUIPMENT]))
{
return;
}
this.randomiseArmorDurabilityValues(itemWithMods);
return;
@ -670,10 +676,14 @@ export class RagfairOfferGenerator
item.upd.Repairable.MaxDurability = tempMaxDurability;
}
/**
* Randomise the durabiltiy values for an armors plates and soft inserts
* @param armorWithMods Armor item with its child mods
*/
protected randomiseArmorDurabilityValues(armorWithMods: Item[]): void
{
let childMultiplerValues = {};
if (this.randomUtil.getChance100(25)) { // chance the armor is damaged
const itemDurabilityConfigDict = this.ragfairConfig.dynamic.condition;
const childMultiplerValues = {};
for (const item of armorWithMods)
{
const itemDbDetails = this.itemHelper.getItem(item._tpl)[1];
@ -688,25 +698,25 @@ export class RagfairOfferGenerator
if (!childMultiplerValues[itemDbDetails._parent])
{
childMultiplerValues[itemDbDetails._parent] = this.randomUtil.getFloat(
this.ragfairConfig.dynamic.condition[itemDbDetails._parent].min,
this.ragfairConfig.dynamic.condition[itemDbDetails._parent].max,
)/this.ragfairConfig.dynamic.condition[itemDbDetails._parent].max;
itemDurabilityConfigDict[itemDbDetails._parent].min,
itemDurabilityConfigDict[itemDbDetails._parent].max,
) / itemDurabilityConfigDict[itemDbDetails._parent].max;
}
let maxDurability = Math.round(
this.randomUtil.getFloat(itemDbDetails._props.MaxDurability * this.randomUtil.getFloat(childMultiplerValues[itemDbDetails._parent], 1), itemDbDetails._props.MaxDurability),
const modMultipler = childMultiplerValues[itemDbDetails._parent];
const maxDurability = Math.round(
this.randomUtil.getFloat(itemDbDetails._props.MaxDurability * this.randomUtil.getFloat(modMultipler, 1), itemDbDetails._props.MaxDurability),
);
let durability = Math.round(
this.randomUtil.getFloat(maxDurability * this.randomUtil.getFloat(childMultiplerValues[itemDbDetails._parent], 1), maxDurability),
const durability = Math.round(
this.randomUtil.getFloat(maxDurability * this.randomUtil.getFloat(modMultipler, 1), maxDurability),
);
item.upd.Repairable = {
Durability: durability || 1,
Durability: durability || 1, // Never let value become 0
MaxDurability: maxDurability
};
}
}
}
}
/**
* Add missing conditions to an item if needed