From f4180993cbde30456bd40e1c3f52abb66404a83f Mon Sep 17 00:00:00 2001 From: Chomp Date: Wed, 15 Jan 2025 10:29:35 +0000 Subject: [PATCH] Fixed prestiges not being persisted to profile --- .../assets/database/templates/profiles.json | 72 +++++++++---------- project/src/callbacks/PrestigeCallbacks.ts | 8 ++- project/src/controllers/PrestigeController.ts | 35 ++++++--- project/src/helpers/InventoryHelper.ts | 3 +- .../src/models/eft/common/tables/IBotBase.ts | 1 + .../eft/inventory/IAddItemDirectRequest.ts | 2 +- .../routers/static/PrestigeStaticRouter.ts | 2 +- 7 files changed, 74 insertions(+), 49 deletions(-) diff --git a/project/assets/database/templates/profiles.json b/project/assets/database/templates/profiles.json index 9e9f6f7c..6a01d163 100644 --- a/project/assets/database/templates/profiles.json +++ b/project/assets/database/templates/profiles.json @@ -3,8 +3,8 @@ "descriptionLocaleKey": "launcher-profile_standard", "bear": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -2701,8 +2701,8 @@ }, "usec": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -5595,8 +5595,8 @@ "descriptionLocaleKey": "launcher-profile_leftbehind", "bear": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -8852,8 +8852,8 @@ }, "usec": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -12213,8 +12213,8 @@ "descriptionLocaleKey": "launcher-profile_preparetoescape", "bear": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -15928,8 +15928,8 @@ }, "usec": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -19846,8 +19846,8 @@ "descriptionLocaleKey": "launcher-profile-edgeofdarkness", "bear": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -23612,8 +23612,8 @@ }, "usec": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -27509,8 +27509,8 @@ "descriptionLocaleKey": "launcher-profile-unheard", "bear": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -32014,8 +32014,8 @@ }, "usec": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -36740,8 +36740,8 @@ "descriptionLocaleKey": "launcher-profile-tournament", "bear": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -37729,8 +37729,8 @@ }, "usec": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -38719,8 +38719,8 @@ "descriptionLocaleKey": "launcher-profile_sptdeveloper", "bear": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -41870,8 +41870,8 @@ }, "usec": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -45008,8 +45008,8 @@ "descriptionLocaleKey": "launcher-profile_spteasystart", "bear": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -48427,8 +48427,8 @@ }, "usec": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -51849,8 +51849,8 @@ "descriptionLocaleKey": "launcher-profile_sptzerotohero", "bear": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", @@ -52828,8 +52828,8 @@ }, "usec": { "character": { - "Achievements": [], - "Prestige": [], + "Achievements": {}, + "Prestige": {}, "TaskConditionCounters": {}, "Bonuses": [{ "id": "64f5b9e5fa34f11b380756c0", diff --git a/project/src/callbacks/PrestigeCallbacks.ts b/project/src/callbacks/PrestigeCallbacks.ts index cb0f93fa..427e7691 100644 --- a/project/src/callbacks/PrestigeCallbacks.ts +++ b/project/src/callbacks/PrestigeCallbacks.ts @@ -22,8 +22,12 @@ export class PrestigeCallbacks { } /** Handle client/prestige/obtain */ - public obtainPrestige(url: string, info: IObtainPrestigeRequest[], sessionID: string): INullResponseData { - this.prestigeController.obtainPrestige(sessionID, info); + public async obtainPrestige( + url: string, + info: IObtainPrestigeRequest[], + sessionID: string, + ): Promise { + await this.prestigeController.obtainPrestige(sessionID, info); return this.httpResponse.nullResponse(); } diff --git a/project/src/controllers/PrestigeController.ts b/project/src/controllers/PrestigeController.ts index e74e9c9e..092ceabe 100644 --- a/project/src/controllers/PrestigeController.ts +++ b/project/src/controllers/PrestigeController.ts @@ -63,7 +63,7 @@ export class PrestigeController { /** * Handle /client/prestige/obtain */ - public obtainPrestige(sessionId: string, request: IObtainPrestigeRequest[]): void { + public async obtainPrestige(sessionId: string, request: IObtainPrestigeRequest[]): Promise { const prePrestigeProfileClone = this.cloner.clone(this.profileHelper.getFullProfile(sessionId)); const prePrestigePmc = prePrestigeProfileClone.characters.pmc; const createRequest: IProfileCreateRequestData = { @@ -73,14 +73,19 @@ export class PrestigeController { voiceId: Object.values(this.databaseService.getTemplates().customization).find( (customisation) => customisation._name === prePrestigePmc.Info.Voice, )._id, - sptForcePrestigeLevel: prePrestigeProfileClone.characters.pmc.Info.PrestigeLevel + 1, // Current + 1 + sptForcePrestigeLevel: prePrestigeProfileClone.characters.pmc.Info.PrestigeLevel + 1, // Current + 1, }; // Reset profile - this.createProfileService.createProfile(sessionId, createRequest); + await this.createProfileService.createProfile(sessionId, createRequest); // Get freshly reset profile ready for editing const newProfile = this.profileHelper.getFullProfile(sessionId); + if (!newProfile) { + this.logger.error(`Unable to create get new profile for: ${sessionId}`); + + return; + } // Skill copy const commonSKillsToCopy = prePrestigePmc.Skills.Common; @@ -109,18 +114,29 @@ export class PrestigeController { } } - const indexToGet = Math.min(createRequest.sptForcePrestigeLevel - 1, 1); // Index starts at 0 - const rewards = this.databaseService.getTemplates().prestige.elements[indexToGet].rewards; - this.addPrestigeRewardsToProfile(sessionId, newProfile, rewards); + const indexOfPrestigeObtained = Math.min(createRequest.sptForcePrestigeLevel - 1, 1); // Index starts at 0 + // Assumes Prestige data is in descending order + const matchingPrestigeData = this.databaseService.getTemplates().prestige.elements[indexOfPrestigeObtained]; + + this.addPrestigeRewardsToProfile(sessionId, newProfile, matchingPrestigeData.rewards); + + // Flag profile as having achieved this prestige level + newProfile.characters.pmc.Prestige[matchingPrestigeData.id] = this.timeUtil.getTimestamp(); // Copy transferred items for (const transferRequest of request) { const item = prePrestigePmc.Inventory.items.find((item) => item._id === transferRequest.id); + if (!item) { + this.logger.error( + `Unable to find item with id: ${transferRequest.id} in profile: ${sessionId}, skipping`, + ); + + continue; + } const addItemRequest: IAddItemDirectRequest = { itemWithModsToAdd: [item], - foundInRaid: item.upd?.SpawnedInSession, + foundInRaid: item.upd?.SpawnedInSession ?? false, useSortingTable: false, - callback: null, }; this.inventoryHelper.addItemToStash( sessionId, @@ -134,6 +150,9 @@ export class PrestigeController { if (!newProfile.achievements["676091c0f457869a94017a23"]) { newProfile.achievements["676091c0f457869a94017a23"] = this.timeUtil.getTimestamp(); } + + // Force save of above changes to disk + await this.saveServer.saveProfile(sessionId); } protected addPrestigeRewardsToProfile(sessionId: string, newProfile: ISptProfile, rewards: IReward[]) { diff --git a/project/src/helpers/InventoryHelper.ts b/project/src/helpers/InventoryHelper.ts index d4ab439a..801984ab 100644 --- a/project/src/helpers/InventoryHelper.ts +++ b/project/src/helpers/InventoryHelper.ts @@ -161,7 +161,8 @@ export class InventoryHelper { pmcData.Inventory.items.push(...itemWithModsToAddClone); this.logger.debug( - `Added ${itemWithModsToAddClone[0].upd?.StackObjectsCount ?? 1} item: ${itemWithModsToAddClone[0]._tpl + `Added ${itemWithModsToAddClone[0].upd?.StackObjectsCount ?? 1} item: ${ + itemWithModsToAddClone[0]._tpl } with: ${itemWithModsToAddClone.length - 1} mods to inventory`, ); } diff --git a/project/src/models/eft/common/tables/IBotBase.ts b/project/src/models/eft/common/tables/IBotBase.ts index 8f7c690c..418cc205 100644 --- a/project/src/models/eft/common/tables/IBotBase.ts +++ b/project/src/models/eft/common/tables/IBotBase.ts @@ -30,6 +30,7 @@ export interface IBotBase { RagfairInfo: IRagfairInfo; /** Achievement id and timestamp */ Achievements: Record; + Prestige: Record; RepeatableQuests: IPmcDataRepeatableQuest[]; Bonuses: IBonus[]; Notes: INotes; diff --git a/project/src/models/eft/inventory/IAddItemDirectRequest.ts b/project/src/models/eft/inventory/IAddItemDirectRequest.ts index 5d6bb8be..3903455d 100644 --- a/project/src/models/eft/inventory/IAddItemDirectRequest.ts +++ b/project/src/models/eft/inventory/IAddItemDirectRequest.ts @@ -4,6 +4,6 @@ export interface IAddItemDirectRequest { /** Item and child mods to add to player inventory */ itemWithModsToAdd: IItem[]; foundInRaid: boolean; - callback: (buyCount: number) => void; + callback?: (buyCount: number) => void; useSortingTable: boolean; } diff --git a/project/src/routers/static/PrestigeStaticRouter.ts b/project/src/routers/static/PrestigeStaticRouter.ts index dd108761..a803b85b 100644 --- a/project/src/routers/static/PrestigeStaticRouter.ts +++ b/project/src/routers/static/PrestigeStaticRouter.ts @@ -23,7 +23,7 @@ export class PrestigeStaticRouter extends StaticRouter { new RouteAction( "/client/prestige/obtain", async (url: string, info: any, sessionID: string, _output: string): Promise => { - return this.prestigeCallbacks.obtainPrestige(url, info, sessionID); + return await this.prestigeCallbacks.obtainPrestige(url, info, sessionID); }, ), ]);