From fefa9b3b39b83b1d4911031e22864d42babf4a2c Mon Sep 17 00:00:00 2001 From: Archangel Date: Fri, 20 Sep 2024 14:31:01 +0000 Subject: [PATCH] Set correct data to favoriteItems array (!411) This PR fixes an inconsistency in favoriteItems, at least in the latest EFT it deserializes an actual item rather than a string of item id's I also made it empty out the array if the profile is converted, I tacked this onto the karma system as it only needs to happen and I was lazy to write more code to check for this, however if it's required for this PR to be merged feel free to say so. Reviewed-on: https://dev.sp-tarkov.com/SPT/Server/pulls/411 Co-authored-by: Archangel Co-committed-by: Archangel --- project/src/controllers/GameController.ts | 6 +++++- project/src/controllers/InventoryController.ts | 11 +++++++++-- project/src/models/eft/common/tables/IBotBase.ts | 2 +- .../models/eft/profile/IGetOtherProfileResponse.ts | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/project/src/controllers/GameController.ts b/project/src/controllers/GameController.ts index 92c9e33a..ce73134b 100644 --- a/project/src/controllers/GameController.ts +++ b/project/src/controllers/GameController.ts @@ -245,10 +245,14 @@ export class GameController { } protected migrate39xProfile(fullProfile: ISptProfile) { - // Karma + // Karma & Favorite items if (typeof fullProfile.characters.pmc.karmaValue === "undefined") { this.logger.warning("Migration: Added karma value of 0.2 to profile"); fullProfile.characters.pmc.karmaValue = 0.2; + + // Reset the PMC's favorite items, as the previous data was incorrect. + this.logger.warning("Migration: Emptied out favoriteItems array on profile."); + fullProfile.characters.pmc.Inventory.favoriteItems = []; } // Equipment area diff --git a/project/src/controllers/InventoryController.ts b/project/src/controllers/InventoryController.ts index ab3d02f1..ac94d0ce 100644 --- a/project/src/controllers/InventoryController.ts +++ b/project/src/controllers/InventoryController.ts @@ -933,11 +933,18 @@ export class InventoryController { for (const itemId of request.items) { // If id already exists in array, we're removing it - const indexOfItemAlreadyFavorited = pmcData.Inventory.favoriteItems.findIndex((x) => x === itemId); + const indexOfItemAlreadyFavorited = pmcData.Inventory.favoriteItems.findIndex(x => x._id === itemId); if (indexOfItemAlreadyFavorited > -1) { pmcData.Inventory.favoriteItems.splice(indexOfItemAlreadyFavorited, 1); } else { - pmcData.Inventory.favoriteItems.push(itemId); + let item = pmcData.Inventory.items.find(i => i._id === itemId); + + if (item === undefined) + { + continue; + } + + pmcData.Inventory.favoriteItems.push(item); } } } diff --git a/project/src/models/eft/common/tables/IBotBase.ts b/project/src/models/eft/common/tables/IBotBase.ts index ba58badd..314cf980 100644 --- a/project/src/models/eft/common/tables/IBotBase.ts +++ b/project/src/models/eft/common/tables/IBotBase.ts @@ -168,7 +168,7 @@ export interface Inventory { /** Key is hideout area enum numeric as string e.g. "24", value is area _id */ hideoutAreaStashes: Record; fastPanel: Record; - favoriteItems: string[]; + favoriteItems: Item[]; } export interface IBaseJsonSkills { diff --git a/project/src/models/eft/profile/IGetOtherProfileResponse.ts b/project/src/models/eft/profile/IGetOtherProfileResponse.ts index 7623b30d..54f9727b 100644 --- a/project/src/models/eft/profile/IGetOtherProfileResponse.ts +++ b/project/src/models/eft/profile/IGetOtherProfileResponse.ts @@ -9,7 +9,7 @@ export interface IGetOtherProfileResponse { skills: Skills; equipment: IOtherProfileEquipment; achievements: Record; - favoriteItems: string[]; + favoriteItems: Item[]; pmcStats: IOtherProfileStats; scavStats: IOtherProfileStats; }