From 3e760e88e474141e142aecd90a20744b2c45d72b Mon Sep 17 00:00:00 2001 From: Chomp Date: Tue, 7 Jan 2025 13:06:28 +0000 Subject: [PATCH] Added code to add hideout customisation unlocks to profile when quest completion rewards an achievement Fixed inaccurate `rewards` type for achievement object --- .../controllers/CustomizationController.ts | 2 +- project/src/helpers/ProfileHelper.ts | 43 +++++++++++++++++-- project/src/helpers/QuestHelper.ts | 2 +- .../models/eft/common/tables/IAchievement.ts | 4 +- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/project/src/controllers/CustomizationController.ts b/project/src/controllers/CustomizationController.ts index 9888cc0a..f48ba7ed 100644 --- a/project/src/controllers/CustomizationController.ts +++ b/project/src/controllers/CustomizationController.ts @@ -235,7 +235,7 @@ export class CustomizationController { return customisationResultsClone; } - // Append on customisations unlocked by player to results + // Append customisations unlocked by player to results customisationResultsClone.push(...(profile.customisationUnlocks ?? [])); return customisationResultsClone; diff --git a/project/src/helpers/ProfileHelper.ts b/project/src/helpers/ProfileHelper.ts index 5a8d8d4d..48dd8628 100644 --- a/project/src/helpers/ProfileHelper.ts +++ b/project/src/helpers/ProfileHelper.ts @@ -544,12 +544,47 @@ export class ProfileHelper { } /** - * Add an achievement to player profile - * @param pmcProfile Profile to add achievement to + * Add an achievement to player profile + check for and add any hideout customisation unlocks to profile + * @param fullProfile Profile to add achievement to * @param achievementId Id of achievement to add */ - public addAchievementToProfile(pmcProfile: IPmcData, achievementId: string): void { - pmcProfile.Achievements[achievementId] = this.timeUtil.getTimestamp(); + public addAchievementToProfile(fullProfile: ISptProfile, achievementId: string): void { + // Add achievement id to profile with timestamp it was unlocked + fullProfile.characters.pmc.Achievements[achievementId] = this.timeUtil.getTimestamp(); + + // Check for any customisation unlocks + const achievementDataDb = this.databaseService + .getTemplates() + .achievements.find((achievement) => achievement.id === achievementId); + if (!achievementDataDb) { + return; + } + + // Get customisation reward object from achievement db + const customizationDirectReward = achievementDataDb.rewards.find( + (reward) => reward.type === "CustomizationDirect", + ); + if (!customizationDirectReward) { + return; + } + + const customisationDataDb = this.databaseService + .getHideout() + .customisation.globals.find((customisation) => customisation.itemId === customizationDirectReward.target); + if (!customisationDataDb) { + this.logger.error( + `Unable to find customisation data for ${customizationDirectReward.target} in profile ${fullProfile.info.id}`, + ); + + return; + } + + // Reward found, add to profile + fullProfile.customisationUnlocks.push({ + id: customizationDirectReward.target, + source: "achievement", + type: customisationDataDb.type, + }); } public hasAccessToRepeatableFreeRefreshSystem(pmcProfile: IPmcData): boolean { diff --git a/project/src/helpers/QuestHelper.ts b/project/src/helpers/QuestHelper.ts index 35b0bfa0..192b4076 100644 --- a/project/src/helpers/QuestHelper.ts +++ b/project/src/helpers/QuestHelper.ts @@ -979,7 +979,7 @@ export class QuestHelper { // Handled by getAssort(), locked assorts are stripped out by `assortHelper.stripLockedLoyaltyAssort()` before being sent to player break; case QuestRewardType.ACHIEVEMENT: - this.profileHelper.addAchievementToProfile(pmcProfile, reward.target); + this.profileHelper.addAchievementToProfile(fullProfile, reward.target); break; case QuestRewardType.STASH_ROWS: this.profileHelper.addStashRowsBonusToProfile(sessionId, Number.parseInt(reward.value)); // Add specified stash rows from quest reward - requires client restart diff --git a/project/src/models/eft/common/tables/IAchievement.ts b/project/src/models/eft/common/tables/IAchievement.ts index 5ea9c66e..8a1d3967 100644 --- a/project/src/models/eft/common/tables/IAchievement.ts +++ b/project/src/models/eft/common/tables/IAchievement.ts @@ -1,10 +1,10 @@ -import { IQuestConditionTypes, IQuestRewards } from "@spt/models/eft/common/tables/IQuest"; +import { IQuestConditionTypes, IQuestReward } from "@spt/models/eft/common/tables/IQuest"; export interface IAchievement { id: string; imageUrl: string; assetPath: string; - rewards: IQuestRewards; + rewards: IQuestReward[]; conditions: IQuestConditionTypes; instantComplete: boolean; showNotificationsInGame: boolean;