Commit fc61a1c 1 parent 016fc2a commit fc61a1c Copy full SHA for fc61a1c
File tree 5 files changed +56
-17
lines changed
5 files changed +56
-17
lines changed Original file line number Diff line number Diff line change @@ -928,24 +928,17 @@ export class InventoryController {
928
928
}
929
929
930
930
public setFavoriteItem ( pmcData : IPmcData , request : ISetFavoriteItems , sessionId : string ) : void {
931
- if ( ! pmcData . Inventory . favoriteItems ) {
932
- pmcData . Inventory . favoriteItems = [ ] ;
933
- }
931
+ // The client sends the full list of favorite items, so clear the current favorites
932
+ pmcData . Inventory . favoriteItems = [ ] ;
934
933
935
934
for ( const itemId of request . items ) {
936
- // If id already exists in array, we're removing it
937
- const indexOfItemAlreadyFavorited = pmcData . Inventory . favoriteItems . findIndex ( ( x ) => x . _id === itemId ) ;
938
- if ( indexOfItemAlreadyFavorited > - 1 ) {
939
- pmcData . Inventory . favoriteItems . splice ( indexOfItemAlreadyFavorited , 1 ) ;
940
- } else {
941
- const item = pmcData . Inventory . items . find ( ( i ) => i . _id === itemId ) ;
942
-
943
- if ( item === undefined ) {
944
- continue ;
945
- }
946
-
947
- pmcData . Inventory . favoriteItems . push ( item ) ;
935
+ // Leaving this in as validation that the item exists in the profile
936
+ const item = pmcData . Inventory . items . find ( ( i ) => i . _id === itemId ) ;
937
+ if ( item === undefined ) {
938
+ continue ;
948
939
}
940
+
941
+ pmcData . Inventory . favoriteItems . push ( itemId ) ;
949
942
}
950
943
}
951
944
Original file line number Diff line number Diff line change @@ -401,6 +401,9 @@ export class ProfileController {
401
401
return response ;
402
402
}
403
403
404
+ /**
405
+ * Handle client/profile/view
406
+ */
404
407
public getOtherProfile ( sessionId : string , request : IGetOtherProfileRequest ) : IGetOtherProfileResponse {
405
408
const player = this . profileHelper . getFullProfile ( sessionId ) ;
406
409
const playerPmc = player . characters . pmc ;
@@ -432,7 +435,7 @@ export class ProfileController {
432
435
Items : playerPmc . Inventory . items ,
433
436
} ,
434
437
achievements : playerPmc . Achievements ,
435
- favoriteItems : playerPmc . Inventory . favoriteItems ?? [ ] ,
438
+ favoriteItems : this . profileHelper . getOtherProfileFavorites ( playerPmc ) ,
436
439
pmcStats : {
437
440
eft : {
438
441
totalInGameTime : playerPmc . Stats . Eft . TotalInGameTime ,
Original file line number Diff line number Diff line change @@ -533,4 +533,29 @@ export class ProfileHelper {
533
533
public getQuestItemsInProfile ( profile : IPmcData ) : IItem [ ] {
534
534
return profile . Inventory . items . filter ( ( item ) => item . parentId === profile . Inventory . questRaidItems ) ;
535
535
}
536
+
537
+ /**
538
+ * Return a favorites array in the format expected by the getOtherProfile call
539
+ * @param profile
540
+ * @returns An array of IItem objects representing the favorited data
541
+ */
542
+ public getOtherProfileFavorites ( profile : IPmcData ) : IItem [ ] {
543
+ let fullFavorites = [ ] ;
544
+
545
+ for ( const itemId of profile . Inventory . favoriteItems ?? [ ] )
546
+ {
547
+ // When viewing another users profile, the client expects a full item with children, so get that
548
+ const itemAndChildren = this . itemHelper . findAndReturnChildrenAsItems ( profile . Inventory . items , itemId ) ;
549
+ if ( itemAndChildren && itemAndChildren . length > 0 )
550
+ {
551
+ // 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
552
+ const clonedItems = this . cloner . clone ( itemAndChildren ) ;
553
+ clonedItems [ 0 ] . parentId = null ;
554
+
555
+ fullFavorites = fullFavorites . concat ( clonedItems ) ;
556
+ }
557
+ }
558
+
559
+ return fullFavorites ;
560
+ }
536
561
}
Original file line number Diff line number Diff line change @@ -169,7 +169,7 @@ export interface IInventory {
169
169
/** Key is hideout area enum numeric as string e.g. "24", value is area _id */
170
170
hideoutAreaStashes : Record < string , string > ;
171
171
fastPanel : Record < string , string > ;
172
- favoriteItems : IItem [ ] ;
172
+ favoriteItems : string [ ] ;
173
173
}
174
174
175
175
export interface IBaseJsonSkills {
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ export class ProfileFixerService {
64
64
this . removeDanglingTaskConditionCounters ( pmcProfile ) ;
65
65
this . removeOrphanedQuests ( pmcProfile ) ;
66
66
this . verifyQuestProductionUnlocks ( pmcProfile ) ;
67
+ this . fixFavorites ( pmcProfile ) ;
67
68
68
69
if ( pmcProfile . Hideout ) {
69
70
this . addHideoutEliteSlots ( pmcProfile ) ;
@@ -341,6 +342,23 @@ export class ProfileFixerService {
341
342
}
342
343
}
343
344
345
+ /**
346
+ * Initial release of SPT 3.10 used an incorrect favorites structure, reformat
347
+ * the structure to the correct MongoID array structure
348
+ * @param pmcProfile
349
+ */
350
+ protected fixFavorites ( pmcProfile : IPmcData ) : void {
351
+ const favoritesAsAny = pmcProfile . Inventory ?. favoriteItems as any ;
352
+ if ( favoritesAsAny )
353
+ {
354
+ const correctedFavorites = favoritesAsAny . map ( ( favorite ) => {
355
+ return favorite . _id ?? favorite ;
356
+ } ) ;
357
+
358
+ pmcProfile . Inventory . favoriteItems = correctedFavorites ?? [ ] ;
359
+ }
360
+ }
361
+
344
362
/**
345
363
* If the profile has elite Hideout Managment skill, add the additional slots from globals
346
364
* NOTE: This seems redundant, but we will leave it here just incase.
You can’t perform that action at this time.
0 commit comments