0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00

Generate player scav with lowest Hp bodyparts

This commit is contained in:
Dev 2024-07-09 12:35:37 +01:00
parent 18af98e86d
commit dd56749ae1

View File

@ -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