Fix the "Unable to transfer stack" exception on scav post-raid screen (!230)

Switched `transferItem` to use the `getOwnerInventoryItems` method, so that it properly handles transfer events on the scav inventory

Bit of cleanup and consistency changes made to the `transferItem` method

Testing instructions in issue: https://dev.sp-tarkov.com/SPT-AKI/Issues/issues/483

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/230
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-02-17 20:53:47 +00:00 committed by chomp
parent 8853ff9aad
commit b84531bb27
2 changed files with 10 additions and 35 deletions

View File

@ -324,7 +324,6 @@ export class InventoryController
/** /**
* TODO: Adds no data to output to send to client, is this by design? * TODO: Adds no data to output to send to client, is this by design?
* TODO: should make use of getOwnerInventoryItems(), stack being transferred may not always be on pmc
* Transfer items from one stack into another while keeping original stack * Transfer items from one stack into another while keeping original stack
* Used to take items from scav inventory into stash or to insert ammo into mags (shotgun ones) and reloading weapon by clicking "Reload" * Used to take items from scav inventory into stash or to insert ammo into mags (shotgun ones) and reloading weapon by clicking "Reload"
* @param pmcData Player profile * @param pmcData Player profile
@ -340,28 +339,9 @@ export class InventoryController
output: IItemEventRouterResponse, output: IItemEventRouterResponse,
): IItemEventRouterResponse ): IItemEventRouterResponse
{ {
let sourceItem: Item = null; const inventoryItems = this.inventoryHelper.getOwnerInventoryItems(body, sessionID);
let destinationItem: Item = null; const sourceItem = inventoryItems.from.find(item => item._id == body.item);
const destinationItem = inventoryItems.to.find(item => item._id == body.with);
for (const iterItem of pmcData.Inventory.items)
{
if (iterItem._id === body.item)
{
// Found source item
sourceItem = iterItem;
}
else if (iterItem._id === body.with)
{
// Found destination item
destinationItem = iterItem;
}
if (sourceItem !== null && destinationItem !== null)
{
// Both items found, exit loop
break;
}
}
if (sourceItem === null) if (sourceItem === null)
{ {
@ -383,13 +363,12 @@ export class InventoryController
return output; return output;
} }
let sourceStackCount = 1;
if (!sourceItem.upd) if (!sourceItem.upd)
{ {
sourceItem.upd = { StackObjectsCount: 1 }; sourceItem.upd = { StackObjectsCount: 1 };
} }
sourceStackCount = sourceItem.upd.StackObjectsCount;
const sourceStackCount = sourceItem.upd.StackObjectsCount;
if (sourceStackCount > body.count) if (sourceStackCount > body.count)
{ {
// Source items stack count greater than new desired count // Source items stack count greater than new desired count
@ -401,16 +380,11 @@ export class InventoryController
sourceItem.upd.StackObjectsCount = sourceStackCount - 1; sourceItem.upd.StackObjectsCount = sourceStackCount - 1;
} }
let destinationStackCount = 1; if (!destinationItem.upd)
if (destinationItem.upd)
{ {
destinationStackCount = destinationItem.upd.StackObjectsCount; destinationItem.upd = { StackObjectsCount: 1 };
} }
else const destinationStackCount = destinationItem.upd.StackObjectsCount;
{
Object.assign(destinationItem, { upd: { StackObjectsCount: 1 } });
}
destinationItem.upd.StackObjectsCount = destinationStackCount + body.count; destinationItem.upd.StackObjectsCount = destinationStackCount + body.count;
return output; return output;

View File

@ -11,13 +11,14 @@ import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
import { Inventory } from "@spt-aki/models/eft/common/tables/IBotBase"; import { Inventory } from "@spt-aki/models/eft/common/tables/IBotBase";
import { Item, Location, Upd } from "@spt-aki/models/eft/common/tables/IItem"; import { Item, Location, Upd } from "@spt-aki/models/eft/common/tables/IItem";
import { IAddItemDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemDirectRequest"; import { IAddItemDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemDirectRequest";
import { AddItem, IAddItemRequestData } from "@spt-aki/models/eft/inventory/IAddItemRequestData"; import { AddItem } from "@spt-aki/models/eft/inventory/IAddItemRequestData";
import { IAddItemTempObject } from "@spt-aki/models/eft/inventory/IAddItemTempObject"; import { IAddItemTempObject } from "@spt-aki/models/eft/inventory/IAddItemTempObject";
import { IAddItemsDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemsDirectRequest"; import { IAddItemsDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemsDirectRequest";
import { IInventoryMergeRequestData } from "@spt-aki/models/eft/inventory/IInventoryMergeRequestData"; import { IInventoryMergeRequestData } from "@spt-aki/models/eft/inventory/IInventoryMergeRequestData";
import { IInventoryMoveRequestData } from "@spt-aki/models/eft/inventory/IInventoryMoveRequestData"; import { IInventoryMoveRequestData } from "@spt-aki/models/eft/inventory/IInventoryMoveRequestData";
import { IInventoryRemoveRequestData } from "@spt-aki/models/eft/inventory/IInventoryRemoveRequestData"; import { IInventoryRemoveRequestData } from "@spt-aki/models/eft/inventory/IInventoryRemoveRequestData";
import { IInventorySplitRequestData } from "@spt-aki/models/eft/inventory/IInventorySplitRequestData"; import { IInventorySplitRequestData } from "@spt-aki/models/eft/inventory/IInventorySplitRequestData";
import { IInventoryTransferRequestData } from "@spt-aki/models/eft/inventory/IInventoryTransferRequestData";
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse"; import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
import { BaseClasses } from "@spt-aki/models/enums/BaseClasses"; import { BaseClasses } from "@spt-aki/models/enums/BaseClasses";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
@ -840,7 +841,7 @@ export class InventoryHelper
* @returns OwnerInventoryItems with inventory of player/scav to adjust * @returns OwnerInventoryItems with inventory of player/scav to adjust
*/ */
public getOwnerInventoryItems( public getOwnerInventoryItems(
request: IInventoryMoveRequestData | IInventorySplitRequestData | IInventoryMergeRequestData, request: IInventoryMoveRequestData | IInventorySplitRequestData | IInventoryMergeRequestData | IInventoryTransferRequestData,
sessionId: string, sessionId: string,
): IOwnerInventoryItems ): IOwnerInventoryItems
{ {