From 848302e7696a969b1a7d752c8cb7b3fc87eaa883 Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 24 Jul 2023 16:30:03 +0100 Subject: [PATCH] Convert post-raid player status into an enum and update usages --- project/src/controllers/InraidController.ts | 13 +++++++------ .../models/eft/inRaid/ISaveProgressRequestData.ts | 3 ++- project/src/models/enums/PlayerRaidEndState.ts | 8 ++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 project/src/models/enums/PlayerRaidEndState.ts diff --git a/project/src/controllers/InraidController.ts b/project/src/controllers/InraidController.ts index 45e53606..2acd1ca3 100644 --- a/project/src/controllers/InraidController.ts +++ b/project/src/controllers/InraidController.ts @@ -16,6 +16,7 @@ import { Item } from "../models/eft/common/tables/IItem"; import { IRegisterPlayerRequestData } from "../models/eft/inRaid/IRegisterPlayerRequestData"; import { ISaveProgressRequestData } from "../models/eft/inRaid/ISaveProgressRequestData"; import { ConfigTypes } from "../models/enums/ConfigTypes"; +import { PlayerRaidEndState } from "../models/enums/PlayerRaidEndState"; import { Traders } from "../models/enums/Traders"; import { IAirdropConfig } from "../models/spt/config/IAirdropConfig"; import { IInRaidConfig } from "../models/spt/config/IInRaidConfig"; @@ -198,11 +199,11 @@ export class InraidController { switch (postRaidSaveRequest.exit) { - case "left": + case PlayerRaidEndState.LEFT.toString(): // Naughty pmc left the raid early! this.reducePmcHealthToPercent(pmcData, 0.01); // 1% break; - case "missinginaction": + case PlayerRaidEndState.MISSING_IN_ACTION.toString(): // Didn't reach exit in time this.reducePmcHealthToPercent(pmcData, 0.3); // 30% break; @@ -254,9 +255,9 @@ export class InraidController * @param statusOnExit exit value from offraidData object * @returns true if dead */ - protected isPlayerDead(statusOnExit: string): boolean + protected isPlayerDead(statusOnExit: PlayerRaidEndState): boolean { - return (statusOnExit !== "survived" && statusOnExit !== "runner"); + return (statusOnExit !== PlayerRaidEndState.SURVIVED && statusOnExit !== PlayerRaidEndState.RUNNER); } /** @@ -267,7 +268,7 @@ export class InraidController */ protected markOrRemoveFoundInRaidItems(offraidData: ISaveProgressRequestData, pmcData: IPmcData, isPlayerScav: boolean): void { - if (offraidData.exit.toLowerCase() === "survived") + if (offraidData.exit === PlayerRaidEndState.SURVIVED) { // Mark found items and replace item ID's if the player survived offraidData.profile = this.inRaidHelper.addSpawnedInSessionPropertyToItems(pmcData, offraidData.profile, isPlayerScav); @@ -327,7 +328,7 @@ export class InraidController fenceStanding = this.inRaidHelper.calculateFenceStandingChangeFromKills(fenceStanding, offraidData.profile.Stats.Victims); // Successful extract with scav adds 0.01 standing - if (offraidData.exit === "survived") + if (offraidData.exit === PlayerRaidEndState.SURVIVED) { fenceStanding += this.inraidConfig.scavExtractGain; } diff --git a/project/src/models/eft/inRaid/ISaveProgressRequestData.ts b/project/src/models/eft/inRaid/ISaveProgressRequestData.ts index 161a994c..48a40e02 100644 --- a/project/src/models/eft/inRaid/ISaveProgressRequestData.ts +++ b/project/src/models/eft/inRaid/ISaveProgressRequestData.ts @@ -1,9 +1,10 @@ +import { PlayerRaidEndState } from "../../../models/enums/PlayerRaidEndState"; import { IPmcData } from "../common/IPmcData"; import { ISyncHealthRequestData } from "../health/ISyncHealthRequestData"; export interface ISaveProgressRequestData { - exit: string // Survived" | "Killed" | "Left" | "runner" | "MissingInAction + exit: PlayerRaidEndState // survived" | "killed" | "left" | "runner" | "missinginaction profile: IPmcData isPlayerScav: boolean health: ISyncHealthRequestData diff --git a/project/src/models/enums/PlayerRaidEndState.ts b/project/src/models/enums/PlayerRaidEndState.ts new file mode 100644 index 00000000..f06f2090 --- /dev/null +++ b/project/src/models/enums/PlayerRaidEndState.ts @@ -0,0 +1,8 @@ +export enum PlayerRaidEndState + { + SURVIVED = "survived", + LEFT = "left", + RUNNER = "runner", + MISSING_IN_ACTION = "missinginaction", + KILLED = "killed" +} \ No newline at end of file