mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 01:50:44 -05:00
Further favorite item/weapon functionality and fixes (#974)
- Resolve issue where we were storing favorites in the incorrect format, resulting in a client error on game load - Resolve issue where we were clearing favorites when they were meant to be saved - On login, fix any previously corrupted favorites array - Properly implement favorite data in `getOtherProfile`, now shows your favorites when viewing your profile Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Co-authored-by: Chomp <27521899+chompDev@users.noreply.github.com>
This commit is contained in:
parent
fdca5d39f6
commit
d34eca32bb
@ -928,24 +928,17 @@ export class InventoryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public setFavoriteItem(pmcData: IPmcData, request: ISetFavoriteItems, sessionId: string): void {
|
public setFavoriteItem(pmcData: IPmcData, request: ISetFavoriteItems, sessionId: string): void {
|
||||||
if (!pmcData.Inventory.favoriteItems) {
|
// The client sends the full list of favorite items, so clear the current favorites
|
||||||
pmcData.Inventory.favoriteItems = [];
|
pmcData.Inventory.favoriteItems = [];
|
||||||
}
|
|
||||||
|
|
||||||
for (const itemId of request.items) {
|
for (const itemId of request.items) {
|
||||||
// If id already exists in array, we're removing it
|
// Leaving this in as validation that the item exists in the profile
|
||||||
const indexOfItemAlreadyFavorited = pmcData.Inventory.favoriteItems.findIndex((x) => x._id === itemId);
|
const item = pmcData.Inventory.items.find((i) => i._id === itemId);
|
||||||
if (indexOfItemAlreadyFavorited > -1) {
|
if (item === undefined) {
|
||||||
pmcData.Inventory.favoriteItems.splice(indexOfItemAlreadyFavorited, 1);
|
continue;
|
||||||
} else {
|
|
||||||
const item = pmcData.Inventory.items.find((i) => i._id === itemId);
|
|
||||||
|
|
||||||
if (item === undefined) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
pmcData.Inventory.favoriteItems.push(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pmcData.Inventory.favoriteItems.push(itemId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,6 +401,9 @@ export class ProfileController {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle client/profile/view
|
||||||
|
*/
|
||||||
public getOtherProfile(sessionId: string, request: IGetOtherProfileRequest): IGetOtherProfileResponse {
|
public getOtherProfile(sessionId: string, request: IGetOtherProfileRequest): IGetOtherProfileResponse {
|
||||||
const player = this.profileHelper.getFullProfile(sessionId);
|
const player = this.profileHelper.getFullProfile(sessionId);
|
||||||
const playerPmc = player.characters.pmc;
|
const playerPmc = player.characters.pmc;
|
||||||
@ -431,7 +434,7 @@ export class ProfileController {
|
|||||||
Items: playerPmc.Inventory.items,
|
Items: playerPmc.Inventory.items,
|
||||||
},
|
},
|
||||||
achievements: playerPmc.Achievements,
|
achievements: playerPmc.Achievements,
|
||||||
favoriteItems: playerPmc.Inventory.favoriteItems ?? [],
|
favoriteItems: this.profileHelper.getOtherProfileFavorites(playerPmc),
|
||||||
pmcStats: {
|
pmcStats: {
|
||||||
eft: {
|
eft: {
|
||||||
totalInGameTime: playerPmc.Stats.Eft.TotalInGameTime,
|
totalInGameTime: playerPmc.Stats.Eft.TotalInGameTime,
|
||||||
|
@ -533,4 +533,29 @@ export class ProfileHelper {
|
|||||||
public getQuestItemsInProfile(profile: IPmcData): IItem[] {
|
public getQuestItemsInProfile(profile: IPmcData): IItem[] {
|
||||||
return profile.Inventory.items.filter((item) => item.parentId === profile.Inventory.questRaidItems);
|
return profile.Inventory.items.filter((item) => item.parentId === profile.Inventory.questRaidItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a favorites array in the format expected by the getOtherProfile call
|
||||||
|
* @param profile
|
||||||
|
* @returns An array of IItem objects representing the favorited data
|
||||||
|
*/
|
||||||
|
public getOtherProfileFavorites(profile: IPmcData): IItem[] {
|
||||||
|
let fullFavorites = [];
|
||||||
|
|
||||||
|
for (const itemId of profile.Inventory.favoriteItems ?? [])
|
||||||
|
{
|
||||||
|
// When viewing another users profile, the client expects a full item with children, so get that
|
||||||
|
const itemAndChildren = this.itemHelper.findAndReturnChildrenAsItems(profile.Inventory.items, itemId);
|
||||||
|
if (itemAndChildren && itemAndChildren.length > 0)
|
||||||
|
{
|
||||||
|
// To get the client to actually see the items, we set the main item's parent to null, so it's treated as a root item
|
||||||
|
const clonedItems = this.cloner.clone(itemAndChildren);
|
||||||
|
clonedItems[0].parentId = null;
|
||||||
|
|
||||||
|
fullFavorites = fullFavorites.concat(clonedItems);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fullFavorites;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ export interface IInventory {
|
|||||||
/** Key is hideout area enum numeric as string e.g. "24", value is area _id */
|
/** Key is hideout area enum numeric as string e.g. "24", value is area _id */
|
||||||
hideoutAreaStashes: Record<string, string>;
|
hideoutAreaStashes: Record<string, string>;
|
||||||
fastPanel: Record<string, string>;
|
fastPanel: Record<string, string>;
|
||||||
favoriteItems: IItem[];
|
favoriteItems: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBaseJsonSkills {
|
export interface IBaseJsonSkills {
|
||||||
|
@ -64,6 +64,7 @@ export class ProfileFixerService {
|
|||||||
this.removeDanglingTaskConditionCounters(pmcProfile);
|
this.removeDanglingTaskConditionCounters(pmcProfile);
|
||||||
this.removeOrphanedQuests(pmcProfile);
|
this.removeOrphanedQuests(pmcProfile);
|
||||||
this.verifyQuestProductionUnlocks(pmcProfile);
|
this.verifyQuestProductionUnlocks(pmcProfile);
|
||||||
|
this.fixFavorites(pmcProfile);
|
||||||
|
|
||||||
if (pmcProfile.Hideout) {
|
if (pmcProfile.Hideout) {
|
||||||
this.addHideoutEliteSlots(pmcProfile);
|
this.addHideoutEliteSlots(pmcProfile);
|
||||||
@ -341,6 +342,23 @@ export class ProfileFixerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initial release of SPT 3.10 used an incorrect favorites structure, reformat
|
||||||
|
* the structure to the correct MongoID array structure
|
||||||
|
* @param pmcProfile
|
||||||
|
*/
|
||||||
|
protected fixFavorites(pmcProfile: IPmcData): void {
|
||||||
|
const favoritesAsAny = pmcProfile.Inventory?.favoriteItems as any;
|
||||||
|
if (favoritesAsAny)
|
||||||
|
{
|
||||||
|
const correctedFavorites = favoritesAsAny.map((favorite) => {
|
||||||
|
return favorite._id ?? favorite;
|
||||||
|
});
|
||||||
|
|
||||||
|
pmcProfile.Inventory.favoriteItems = correctedFavorites ?? [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the profile has elite Hideout Managment skill, add the additional slots from globals
|
* If the profile has elite Hideout Managment skill, add the additional slots from globals
|
||||||
* NOTE: This seems redundant, but we will leave it here just incase.
|
* NOTE: This seems redundant, but we will leave it here just incase.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user