From da6244e1aca3ee00569001767c7c7739b73f81d1 Mon Sep 17 00:00:00 2001 From: Dev Date: Sun, 11 Feb 2024 13:03:38 +0000 Subject: [PATCH] Improvements to `calculateFenceStandingChangeFromKillsAsScav()` - should properly handle additional rep loss when over 6 fence rep --- project/src/controllers/InraidController.ts | 2 +- project/src/helpers/InRaidHelper.ts | 61 ++++++++++----------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/project/src/controllers/InraidController.ts b/project/src/controllers/InraidController.ts index 091613a2..b7e89148 100644 --- a/project/src/controllers/InraidController.ts +++ b/project/src/controllers/InraidController.ts @@ -487,7 +487,7 @@ export class InraidController let fenceStanding = Number(pmcData.TradersInfo[fenceId].standing); this.logger.debug(`pre-raid fence standing: ${fenceStanding}`); - fenceStanding = this.inRaidHelper.calculateFenceStandingChangeFromKills( + fenceStanding = this.inRaidHelper.calculateFenceStandingChangeFromKillsAsScav( fenceStanding, offraidData.profile.Stats.Eft.Victims, ); diff --git a/project/src/helpers/InRaidHelper.ts b/project/src/helpers/InRaidHelper.ts index 2f1c6d29..658b9cc2 100644 --- a/project/src/helpers/InRaidHelper.ts +++ b/project/src/helpers/InRaidHelper.ts @@ -88,45 +88,44 @@ export class InRaidHelper * @param victims Array of kills player performed * @returns adjusted karma level after kills are taken into account */ - public calculateFenceStandingChangeFromKills(existingFenceStanding: number, victims: Victim[]): number + public calculateFenceStandingChangeFromKillsAsScav(existingFenceStanding: number, victims: Victim[]): number { // Run callback on every victim, adding up the standings gained/lossed, starting value is existing fence standing - const newFenceStanding = victims.reduce((acc, victim) => + let fenceStanding = existingFenceStanding; + for (const victim of victims) { - const standingForKill = this.getFenceStandingChangeForKillAsScav(victim); + const standingChangeForKill = this.getFenceStandingChangeForKillAsScav(victim); + const additionalLossForKill = this.getAdditionalLossForKill(fenceStanding, standingChangeForKill); - let additionalReduction = 0; + this.logger.warning(`rep change: ${standingChangeForKill} - additional: ${additionalLossForKill}`); + fenceStanding += standingChangeForKill + additionalLossForKill; + } - // Only subtract (up to) 2 reputation on penalties, not on rewards - if (standingForKill < 0) - { - if (acc >= 6 && acc <= 8) - { - // Reset fence rep to 6 before subtracting penalty - additionalReduction = acc - 6.0; - } - else - { - additionalReduction = 2; - } - } + return fenceStanding; + } - if (standingForKill) - { - this.logger.warning(`Lost: ${standingForKill} - additional:${additionalReduction}`); - return (acc + standingForKill) - additionalReduction; - } - this.logger.warning( - this.localisationService.getText("inraid-missing_standing_for_kill", { - victimSide: victim.Side, - victimRole: victim.Role, - }), - ); + protected getAdditionalLossForKill(fenceStanding: number, repChangeForKill: number): number + { + // No loss for kill, skip + if (repChangeForKill >= 0) + { + return 0; + } - return acc; - }, existingFenceStanding); + // Over 8, big penalty + if (fenceStanding > 8) + { + return -2.0; + } - return newFenceStanding; + // Fence rep is between 6 and 8, appy additional penalty + if (fenceStanding >= 6) + { + return -1; + } + + // No additional penalty + return 0; } /**