From dd56749ae1b657d9395f42544655fbe3f32539be Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 9 Jul 2024 12:35:37 +0100 Subject: [PATCH] Generate player scav with lowest Hp bodyparts --- project/src/generators/BotGenerator.ts | 35 ++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/project/src/generators/BotGenerator.ts b/project/src/generators/BotGenerator.ts index ae4c7665..c501c159 100644 --- a/project/src/generators/BotGenerator.ts +++ b/project/src/generators/BotGenerator.ts @@ -15,7 +15,7 @@ import { Health as PmcHealth, Skills as botSkills, } from "@spt/models/eft/common/tables/IBotBase"; -import { Appearance, Health, IBotType, Inventory } from "@spt/models/eft/common/tables/IBotType"; +import { Appearance, BodyPart, Health, IBotType, Inventory } from "@spt/models/eft/common/tables/IBotType"; import { Item, Upd } from "@spt/models/eft/common/tables/IItem"; import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; import { GameEditions } from "@spt/models/enums/GameEditions"; @@ -402,7 +402,9 @@ export class BotGenerator */ protected generateHealth(healthObj: Health, playerScav = false): PmcHealth { - const bodyParts = playerScav ? healthObj.BodyParts[0] : this.randomUtil.getArrayValue(healthObj.BodyParts); + const bodyParts = playerScav + ? this.getLowestHpBody(healthObj.BodyParts) + : this.randomUtil.getArrayValue(healthObj.BodyParts); const newHealth: PmcHealth = { Hydration: { @@ -467,6 +469,35 @@ export class BotGenerator return newHealth; } + /** + * Sum up body parts max hp values, return the bodypart collection with lowest value + * @param bodies Body parts to sum up + * @returns Lowest hp collection + */ + protected getLowestHpBody(bodies: BodyPart[]): BodyPart | undefined + { + if (bodies.length === 0) + { + // Handle empty input + return undefined; + } + + let result: BodyPart; + let currentHighest = 0; + for (const bodyParts of bodies) + { + const hpTotal = Object.values(bodyParts).reduce((acc, curr) => acc + curr.max, 0); + if (hpTotal < currentHighest) + { + // Found collection with lower value that previous, use it + currentHighest = hpTotal; + result = bodyParts; + } + } + + return result; + } + /** * Get a bots skills with randomsied progress value between the min and max values * @param botSkills Skills that should have their progress value randomised