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 <jesse@archangel.wtf>
Co-committed-by: Archangel <jesse@archangel.wtf>
This commit is contained in:
Archangel 2024-09-20 14:31:01 +00:00 committed by chomp
parent 4851784626
commit fefa9b3b39
4 changed files with 16 additions and 5 deletions

View File

@ -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

View File

@ -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);
}
}
}

View File

@ -168,7 +168,7 @@ export interface Inventory {
/** Key is hideout area enum numeric as string e.g. "24", value is area _id */
hideoutAreaStashes: Record<string, string>;
fastPanel: Record<string, string>;
favoriteItems: string[];
favoriteItems: Item[];
}
export interface IBaseJsonSkills {

View File

@ -9,7 +9,7 @@ export interface IGetOtherProfileResponse {
skills: Skills;
equipment: IOtherProfileEquipment;
achievements: Record<string, number>;
favoriteItems: string[];
favoriteItems: Item[];
pmcStats: IOtherProfileStats;
scavStats: IOtherProfileStats;
}