Fix repair prices for all traders being the same (Should also fix other loyalty related issues) (!405)

- The client doesn't expect to receive the player's loyalty level in their profile, so set it to 0 before sending the profile
- Slight refactor of `getCompleteProfile` to always clone, so we can modify the data sent to the client without changing it on the server

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT/Server/pulls/405
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-09-03 06:09:23 +00:00 committed by chomp
parent 7de0a112dc
commit c793b7e0b3
2 changed files with 23 additions and 11 deletions

View File

@ -80,21 +80,24 @@ export class ProfileHelper {
return output; return output;
} }
const fullProfile = this.getFullProfile(sessionId); const fullProfileClone = this.cloner.clone(this.getFullProfile(sessionId));
// Sanitize any data the client can not receive
this.sanitizeProfileForClient(fullProfileClone);
// Edge-case, true post raid // Edge-case, true post raid
if (this.profileSnapshotService.hasProfileSnapshot(sessionId)) { if (this.profileSnapshotService.hasProfileSnapshot(sessionId)) {
return this.postRaidXpWorkaroundFix( return this.postRaidXpWorkaroundFix(
sessionId, sessionId,
fullProfile.characters.pmc, fullProfileClone.characters.pmc,
fullProfile.characters.scav, fullProfileClone.characters.scav,
output, output,
); );
} }
// PMC must be at array index 0, scav at 1 // PMC must be at array index 0, scav at 1
output.push(fullProfile.characters.pmc); output.push(fullProfileClone.characters.pmc);
output.push(fullProfile.characters.scav); output.push(fullProfileClone.characters.scav);
return output; return output;
} }
@ -113,13 +116,10 @@ export class ProfileHelper {
*/ */
protected postRaidXpWorkaroundFix( protected postRaidXpWorkaroundFix(
sessionId: string, sessionId: string,
pmcProfile: IPmcData, clonedPmc: IPmcData,
scavProfile: IPmcData, clonedScav: IPmcData,
output: IPmcData[], output: IPmcData[],
): IPmcData[] { ): IPmcData[] {
const clonedPmc = this.cloner.clone(pmcProfile);
const clonedScav = this.cloner.clone(scavProfile);
const profileSnapshot = this.profileSnapshotService.getProfileSnapshot(sessionId); const profileSnapshot = this.profileSnapshotService.getProfileSnapshot(sessionId);
clonedPmc.Info.Level = profileSnapshot.characters.pmc.Info.Level; clonedPmc.Info.Level = profileSnapshot.characters.pmc.Info.Level;
clonedPmc.Info.Experience = profileSnapshot.characters.pmc.Info.Experience; clonedPmc.Info.Experience = profileSnapshot.characters.pmc.Info.Experience;
@ -135,6 +135,18 @@ export class ProfileHelper {
return output; return output;
} }
/**
* Sanitize any information from the profile that the client does not expect to receive
* @param clonedProfile A clone of the full player profile
*/
protected sanitizeProfileForClient(clonedProfile: ISptProfile) {
// Remove `loyaltyLevel` from `TradersInfo`, as otherwise it causes the client to not
// properly calculate the player's `loyaltyLevel`
for (const traderInfo of Object.values(clonedProfile.characters.pmc.TradersInfo)) {
traderInfo.loyaltyLevel = undefined;
}
}
/** /**
* Check if a nickname is used by another profile loaded by the server * Check if a nickname is used by another profile loaded by the server
* @param nicknameRequest nickname request object * @param nicknameRequest nickname request object

View File

@ -458,7 +458,7 @@ export interface IQuestStatus {
} }
export interface TraderInfo { export interface TraderInfo {
loyaltyLevel: number; loyaltyLevel?: number;
salesSum: number; salesSum: number;
standing: number; standing: number;
nextResupply: number; nextResupply: number;