From 1249b309cf0e49b9eb5658474549355245ecebbf Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 4 Jan 2024 21:28:47 +0000 Subject: [PATCH] Improve accuracy when handling `client/achievement/statistic` --- project/src/callbacks/AchievementCallbacks.ts | 2 +- .../src/controllers/AchievementController.ts | 20 ++++++++++++++++++- project/src/controllers/ProfileController.ts | 7 ------- .../src/models/spt/server/IDatabaseTables.ts | 1 + 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/project/src/callbacks/AchievementCallbacks.ts b/project/src/callbacks/AchievementCallbacks.ts index 057a08ad..693d3728 100644 --- a/project/src/callbacks/AchievementCallbacks.ts +++ b/project/src/callbacks/AchievementCallbacks.ts @@ -36,6 +36,6 @@ export class AchievementCallbacks // eslint-disable-next-line @typescript-eslint/no-unused-vars public statistic(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData { - return this.httpResponse.getBody(this.profileController.getCompletedAchievements(sessionID)); + return this.httpResponse.getBody(this.achievementController.getAchievementStatistics(sessionID)); } } \ No newline at end of file diff --git a/project/src/controllers/AchievementController.ts b/project/src/controllers/AchievementController.ts index 5f7d5e04..62cd388f 100644 --- a/project/src/controllers/AchievementController.ts +++ b/project/src/controllers/AchievementController.ts @@ -1,5 +1,6 @@ import { inject, injectable } from "tsyringe"; +import { ICompletedAchievementsResponse } from "@spt-aki/models/eft/profile/ICompletedAchievementsResponse"; import { IGetAchievementsResponse } from "@spt-aki/models/eft/profile/IGetAchievementsResponse"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"; @@ -10,7 +11,6 @@ import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"; @injectable() export class AchievementController { - constructor( @inject("WinstonLogger") protected logger: ILogger, @inject("DatabaseServer") protected databaseServer: DatabaseServer, @@ -25,4 +25,22 @@ export class AchievementController { return {elements: this.databaseServer.getTables().templates.achievements }; } + + /** + * Shows % of 'other' players who've completed each achievement + * @param sessionId Session id + * @returns ICompletedAchievementsResponse + */ + public getAchievementStatistics(sessionId: string): ICompletedAchievementsResponse + { + const achievements = this.databaseServer.getTables().templates.achievements; + const stats = {} + + for (const achievement of achievements) + { + stats[achievement.id] = 0; + } + + return {elements: stats}; + } } diff --git a/project/src/controllers/ProfileController.ts b/project/src/controllers/ProfileController.ts index 90322482..0c16593c 100644 --- a/project/src/controllers/ProfileController.ts +++ b/project/src/controllers/ProfileController.ts @@ -390,13 +390,6 @@ export class ProfileController return response; } - public getCompletedAchievements(sessionId: string): ICompletedAchievementsResponse - { - const profile = this.profileHelper.getFullProfile(sessionId); - - return {elements: profile.achievements}; - } - public getOtherProfile(sessionId: string, request: IGetOtherProfileRequest): IGetOtherProfileResponse { const player = this.profileHelper.getFullProfile(sessionId); diff --git a/project/src/models/spt/server/IDatabaseTables.ts b/project/src/models/spt/server/IDatabaseTables.ts index 770091b2..6d15b1f3 100644 --- a/project/src/models/spt/server/IDatabaseTables.ts +++ b/project/src/models/spt/server/IDatabaseTables.ts @@ -1,4 +1,5 @@ import { IGlobals } from "@spt-aki/models/eft/common/IGlobals"; +import { IAchievement } from "@spt-aki/models/eft/common/tables/IAchievement"; import { IBotBase } from "@spt-aki/models/eft/common/tables/IBotBase"; import { IBotCore } from "@spt-aki/models/eft/common/tables/IBotCore"; import { IBotType } from "@spt-aki/models/eft/common/tables/IBotType";