From 1c63d856490682b11485f35f28c35aa3123be754 Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 13 Feb 2024 12:10:17 +0000 Subject: [PATCH] merge encyclopedia dicts together post-raid --- project/src/controllers/InraidController.ts | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/project/src/controllers/InraidController.ts b/project/src/controllers/InraidController.ts index 14518f04..98cb62a4 100644 --- a/project/src/controllers/InraidController.ts +++ b/project/src/controllers/InraidController.ts @@ -331,6 +331,8 @@ export class InraidController this.inRaidHelper.updateProfileBaseStats(serverScavProfile, postRaidRequest, sessionID); this.inRaidHelper.updateScavProfileDataPostRaid(serverScavProfile, postRaidRequest, sessionID); + this.mergePmcAndScavEncyclopedias(serverScavProfile.Encyclopedia, serverPmcProfile.Encyclopedia); + // Completing scav quests create ConditionCounters, these values need to be transported to the PMC profile if (this.profileHasConditionCounters(serverScavProfile)) { @@ -355,6 +357,31 @@ export class InraidController this.handlePostRaidPlayerScavProcess(serverScavProfile, sessionID, postRaidRequest, serverPmcProfile, isDead); } + /** + * merge two dictionaries together + * Prioritise pair that has true as a value + * @param primary main dictionary + * @param secondary Secondary dictionary + */ + protected mergePmcAndScavEncyclopedias(primary: Record, secondary: Record): void + { + function extend(target: { [key: string]: boolean; }, source: Record) + { + for (const key in source) + { + if (Object.hasOwn(source, key)) + { + target[key] = source[key]; + } + } + return target; + } + + const merged = extend(extend({}, primary), secondary); + primary = merged; + secondary = merged; + } + /** * Does provided profile contain any condition counters * @param profile Profile to check for condition counters