From 48f99ecfa60a0e29e39e4d8e0b569d038bbd66c7 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 13 Jan 2024 09:15:11 +0000 Subject: [PATCH] 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 --- project/assets/configs/ragfair.json | 2 +- .../src/generators/RagfairOfferGenerator.ts | 68 +++++++++++-------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/project/assets/configs/ragfair.json b/project/assets/configs/ragfair.json index bafb0542..7eff6b8d 100644 --- a/project/assets/configs/ragfair.json +++ b/project/assets/configs/ragfair.json @@ -130,7 +130,7 @@ }, "57bef4c42459772e8d35a53b": { "_name": "ARMORED_EQUIPMENT", - "conditionChance": 0.6, + "conditionChance": 0.25, "min": 0.05, "max": 1 }, diff --git a/project/src/generators/RagfairOfferGenerator.ts b/project/src/generators/RagfairOfferGenerator.ts index 87d72da8..5442b790 100644 --- a/project/src/generators/RagfairOfferGenerator.ts +++ b/project/src/generators/RagfairOfferGenerator.ts @@ -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,40 +676,44 @@ 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 - for (const item of armorWithMods) + const itemDurabilityConfigDict = this.ragfairConfig.dynamic.condition; + const childMultiplerValues = {}; + for (const item of armorWithMods) + { + const itemDbDetails = this.itemHelper.getItem(item._tpl)[1]; + if ((parseInt(itemDbDetails._props.armorClass)) > 0) { - const itemDbDetails = this.itemHelper.getItem(item._tpl)[1]; - if ((parseInt(itemDbDetails._props.armorClass)) > 0) + if (!item.upd) { - if (!item.upd) - { - item.upd = {}; - } - - // Store mod types durabiltiy multiplier for later use in current/max durability value calculation - 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; - } - - let maxDurability = Math.round( - this.randomUtil.getFloat(itemDbDetails._props.MaxDurability * this.randomUtil.getFloat(childMultiplerValues[itemDbDetails._parent], 1), itemDbDetails._props.MaxDurability), - ); - let durability = Math.round( - this.randomUtil.getFloat(maxDurability * this.randomUtil.getFloat(childMultiplerValues[itemDbDetails._parent], 1), maxDurability), - ); - item.upd.Repairable = { - Durability: durability || 1, - MaxDurability: maxDurability - }; + item.upd = {}; } + + // Store mod types durabiltiy multiplier for later use in current/max durability value calculation + if (!childMultiplerValues[itemDbDetails._parent]) + { + childMultiplerValues[itemDbDetails._parent] = this.randomUtil.getFloat( + itemDurabilityConfigDict[itemDbDetails._parent].min, + itemDurabilityConfigDict[itemDbDetails._parent].max, + ) / itemDurabilityConfigDict[itemDbDetails._parent].max; + } + + const modMultipler = childMultiplerValues[itemDbDetails._parent]; + const maxDurability = Math.round( + this.randomUtil.getFloat(itemDbDetails._props.MaxDurability * this.randomUtil.getFloat(modMultipler, 1), itemDbDetails._props.MaxDurability), + ); + const durability = Math.round( + this.randomUtil.getFloat(maxDurability * this.randomUtil.getFloat(modMultipler, 1), maxDurability), + ); + item.upd.Repairable = { + Durability: durability || 1, // Never let value become 0 + MaxDurability: maxDurability + }; } } }