From 1551a5e793b427c4162d90849de5590e46f3caa6 Mon Sep 17 00:00:00 2001 From: CZPZ Date: Sun, 21 Jan 2024 17:39:37 +0000 Subject: [PATCH] feature: add probability for extra rep gain on pmc kills as pscav (!204) Feel free to rename everything. We can also use the new function from randomutil and replace code block below on InsuranceController.ts ``` const maxRoll = 9999; const conversionFactor = 100; const returnChance = this.randomUtil.getInt(0, maxRoll) / conversionFactor; const traderReturnChance = this.insuranceConfig.returnChancePercent[traderId]; const roll = returnChance >= traderReturnChance; ``` I killed 2 PMCs with 100% chance and gained 0.07 rep (rounding issue probably somewhere else) ![image](/attachments/00f00922-eb18-4fdc-8958-129b680af704) Some JS problems :S ![image](/attachments/dcbeb1d1-2ee3-4809-890e-e19fe3190840) Implements: https://dev.sp-tarkov.com/SPT-AKI/Issues/issues/150 Co-authored-by: alimoncul Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/204 Co-authored-by: CZPZ Co-committed-by: CZPZ --- project/assets/configs/inraid.json | 1 + project/src/controllers/InraidController.ts | 10 +++++----- project/src/controllers/MatchController.ts | 12 ++++++------ project/src/helpers/InRaidHelper.ts | 12 +++++++++++- project/src/models/spt/config/IInRaidConfig.ts | 2 ++ project/src/utils/RandomUtil.ts | 17 +++++++++++++++++ 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/project/assets/configs/inraid.json b/project/assets/configs/inraid.json index e08176c6..5e836fe9 100644 --- a/project/assets/configs/inraid.json +++ b/project/assets/configs/inraid.json @@ -35,5 +35,6 @@ "carExtractBaseStandingGain": 0.4, "coopExtractBaseStandingGain": 0.25, "scavExtractGain": 0.01, + "pmcKillProbabilityForScavGain": 0.2, "keepFiRSecureContainerOnDeath": false } diff --git a/project/src/controllers/InraidController.ts b/project/src/controllers/InraidController.ts index c1138995..0e44b5c2 100644 --- a/project/src/controllers/InraidController.ts +++ b/project/src/controllers/InraidController.ts @@ -46,7 +46,7 @@ export class InraidController { protected airdropConfig: IAirdropConfig; protected btrConfig: IBTRConfig; - protected inraidConfig: IInRaidConfig; + protected inRaidConfig: IInRaidConfig; protected traderConfig: ITraderConfig; constructor( @@ -74,7 +74,7 @@ export class InraidController { this.airdropConfig = this.configServer.getConfig(ConfigTypes.AIRDROP); this.btrConfig = this.configServer.getConfig(ConfigTypes.BTR); - this.inraidConfig = this.configServer.getConfig(ConfigTypes.IN_RAID); + this.inRaidConfig = this.configServer.getConfig(ConfigTypes.IN_RAID); this.traderConfig = this.configServer.getConfig(ConfigTypes.TRADER); } @@ -100,7 +100,7 @@ export class InraidController { this.logger.debug(`Raid outcome: ${offraidData.exit}`); - if (!this.inraidConfig.save.loot) + if (!this.inRaidConfig.save.loot) { return; } @@ -486,7 +486,7 @@ export class InraidController // Successful extract with scav adds 0.01 standing if (offraidData.exit === PlayerRaidEndState.SURVIVED) { - fenceStanding += this.inraidConfig.scavExtractGain; + fenceStanding += this.inRaidConfig.scavExtractGain; } // Make standing changes to pmc profile @@ -502,7 +502,7 @@ export class InraidController */ public getInraidConfig(): IInRaidConfig { - return this.inraidConfig; + return this.inRaidConfig; } /** diff --git a/project/src/controllers/MatchController.ts b/project/src/controllers/MatchController.ts index 10f2d544..64f287b8 100644 --- a/project/src/controllers/MatchController.ts +++ b/project/src/controllers/MatchController.ts @@ -38,7 +38,7 @@ import { TimeUtil } from "@spt-aki/utils/TimeUtil"; export class MatchController { protected matchConfig: IMatchConfig; - protected inraidConfig: IInRaidConfig; + protected inRaidConfig: IInRaidConfig; protected traderConfig: ITraderConfig; protected pmcConfig: IPmcConfig; @@ -61,7 +61,7 @@ export class MatchController ) { this.matchConfig = this.configServer.getConfig(ConfigTypes.MATCH); - this.inraidConfig = this.configServer.getConfig(ConfigTypes.IN_RAID); + this.inRaidConfig = this.configServer.getConfig(ConfigTypes.IN_RAID); this.traderConfig = this.configServer.getConfig(ConfigTypes.TRADER); this.pmcConfig = this.configServer.getConfig(ConfigTypes.PMC); } @@ -213,7 +213,7 @@ export class MatchController return false; } - return (this.inraidConfig.coopExtracts.includes(extractName.trim())); + return (this.inRaidConfig.coopExtracts.includes(extractName.trim())); } protected sendCoopTakenFenceMessage(sessionId: string): void @@ -269,7 +269,7 @@ export class MatchController // Get new fence standing value const newFenceStanding = this.getFenceStandingAfterExtract( pmcData, - this.inraidConfig.coopExtractBaseStandingGain, + this.inRaidConfig.coopExtractBaseStandingGain, pmcData.CoopExtractCounts[extractName], ); const fenceId: string = Traders.FENCE; @@ -298,7 +298,7 @@ export class MatchController return true; } - return this.inraidConfig.carExtracts.includes(extractName.trim()); + return this.inRaidConfig.carExtracts.includes(extractName.trim()); } /** @@ -322,7 +322,7 @@ export class MatchController // Simplified for now, no real reason to do the whole (unconfirmed) extra 0.01 standing per day regeneration mechanic const newFenceStanding = this.getFenceStandingAfterExtract( pmcData, - this.inraidConfig.carExtractBaseStandingGain, + this.inRaidConfig.carExtractBaseStandingGain, pmcData.CarExtractCounts[extractName], ); const fenceId: string = Traders.FENCE; diff --git a/project/src/helpers/InRaidHelper.ts b/project/src/helpers/InRaidHelper.ts index d200eccc..c081320b 100644 --- a/project/src/helpers/InRaidHelper.ts +++ b/project/src/helpers/InRaidHelper.ts @@ -22,6 +22,7 @@ import { LocalisationService } from "@spt-aki/services/LocalisationService"; import { ProfileFixerService } from "@spt-aki/services/ProfileFixerService"; import { JsonUtil } from "@spt-aki/utils/JsonUtil"; import { TimeUtil } from "@spt-aki/utils/TimeUtil"; +import { RandomUtil } from "@spt-aki/utils/RandomUtil"; import { ProfileHelper } from "./ProfileHelper"; @injectable() @@ -44,6 +45,7 @@ export class InRaidHelper @inject("LocalisationService") protected localisationService: LocalisationService, @inject("ProfileFixerService") protected profileFixerService: ProfileFixerService, @inject("ConfigServer") protected configServer: ConfigServer, + @inject("RandomUtil") protected randomUtil: RandomUtil ) { this.lostOnDeathConfig = this.configServer.getConfig(ConfigTypes.LOST_ON_DEATH); @@ -124,7 +126,15 @@ export class InRaidHelper } // PMCs - get by bear/usec - return botTypes[victim.Side.toLowerCase()]?.experience?.standingForKill; + let pmcStandingForKill = botTypes[victim.Side.toLowerCase()]?.experience?.standingForKill; + const pmcKillProbabilityForScavGain = this.inRaidConfig.pmcKillProbabilityForScavGain; + + if(this.randomUtil.rollForChanceProbability(pmcKillProbabilityForScavGain)) + { + pmcStandingForKill += this.inRaidConfig.scavExtractGain + } + + return pmcStandingForKill; } /** diff --git a/project/src/models/spt/config/IInRaidConfig.ts b/project/src/models/spt/config/IInRaidConfig.ts index 7f357594..201e2db1 100644 --- a/project/src/models/spt/config/IInRaidConfig.ts +++ b/project/src/models/spt/config/IInRaidConfig.ts @@ -18,6 +18,8 @@ export interface IInRaidConfig extends IBaseConfig coopExtractBaseStandingGain: number; /** Fence rep gain when successfully extracting as pscav */ scavExtractGain: number; + /** The likelihood of PMC eliminating a minimum of 2 scavs while you engage them as a pscav. */ + pmcKillProbabilityForScavGain: number; /** On death should items in your secure keep their Find in raid status regardless of how you finished the raid */ keepFiRSecureContainerOnDeath: boolean; } diff --git a/project/src/utils/RandomUtil.ts b/project/src/utils/RandomUtil.ts index 6ff7f7a3..4f3ae262 100644 --- a/project/src/utils/RandomUtil.ts +++ b/project/src/utils/RandomUtil.ts @@ -472,4 +472,21 @@ export class RandomUtil return array; } + + /** + * Rolls for a probability based on chance + * @param number Probability Chance as float (0-1) + * @returns If roll succeed or not + * @example + * rollForChanceProbability(0.25); // returns true 25% probability + */ + public rollForChanceProbability(probabilityChance: number): boolean + { + const maxRoll = 9999; + + // Roll a number between 0 and 1 + const rolledChance = this.getInt(0, maxRoll) / 10000; + + return rolledChance <= probabilityChance; + } }