From bc8e98dadc8404dfb2db2ec03f824b9a07783a87 Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Thu, 8 Feb 2024 09:10:06 +0000 Subject: [PATCH] Fix the server sell all price not matching the client displayed value (!216) Resolved by having the client send the sell price instead of trying to calculate it on the server. Same route, just with an extra parameter passed in Removed unnecessary value calculation code, and renamed method to match new behaviour Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/216 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- project/src/controllers/TradeController.ts | 39 ++----------------- .../trade/ISellScavItemsToFenceRequestData.ts | 1 + 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/project/src/controllers/TradeController.ts b/project/src/controllers/TradeController.ts index 7b2b9b7f..68994aeb 100644 --- a/project/src/controllers/TradeController.ts +++ b/project/src/controllers/TradeController.ts @@ -262,55 +262,24 @@ export class TradeController ): IItemEventRouterResponse { const output = this.eventOutputHolder.getOutput(sessionId); - const scavProfile = this.profileHelper.getFullProfile(sessionId)?.characters?.scav; - if (!scavProfile) - { - return this.httpResponse.appendErrorToOutput(output, `Profile ${request.fromOwner.id} has no scav account`); - } - this.calculateCostOfScavInventoryAndMailMoneyToPlayer(sessionId, scavProfile, Traders.FENCE); + this.mailMoneyToPlayer(sessionId, request.totalValue, Traders.FENCE); return output; } /** - * Get cost of items in inventory and send rouble total to player as mail + * Send the specified rouble total to player as mail * @param sessionId Session id - * @param profileWithItemsToSell Profile with items to be sold to trader - * @param profileThatGetsMoney Profile that gets the money after selling items * @param trader Trader to sell items to * @param output IItemEventRouterResponse */ - protected calculateCostOfScavInventoryAndMailMoneyToPlayer( + protected mailMoneyToPlayer( sessionId: string, - profileWithItemsToSell: IPmcData, + roublesToSend: number, trader: Traders, ): void { - const handbookPrices = this.ragfairPriceService.getAllStaticPrices(); - // TODO, apply trader sell bonuses? - const traderDetails = this.traderHelper.getTrader(trader, sessionId); - - // Get all base items that scav has (primaryweapon/backpack/pockets etc) - // Add items that trader will buy (only sell items that have the container as parent) to request object - let roublesToSend = 0; - const containerAndEquipmentItems = profileWithItemsToSell.Inventory.items.filter((item) => - item.parentId === profileWithItemsToSell.Inventory.equipment - ); - for (const itemToSell of containerAndEquipmentItems) - { - // Increment sell price in request - roublesToSend += this.getPriceOfItemAndChildren( - itemToSell._id, - profileWithItemsToSell.Inventory.items, - handbookPrices, - traderDetails, - ); - } - - // Server-side calcualted isnt matching clientside calcualtion, temp fix to get it to be closer - roublesToSend /= 2; - this.logger.debug(`Selling scav items to fence for ${roublesToSend} roubles`); // Create single currency item with all currency on it diff --git a/project/src/models/eft/trade/ISellScavItemsToFenceRequestData.ts b/project/src/models/eft/trade/ISellScavItemsToFenceRequestData.ts index bb40b787..c8f9adb6 100644 --- a/project/src/models/eft/trade/ISellScavItemsToFenceRequestData.ts +++ b/project/src/models/eft/trade/ISellScavItemsToFenceRequestData.ts @@ -3,6 +3,7 @@ import { OwnerInfo } from "@spt-aki/models/eft/common/request/IBaseInteractionRe export interface ISellScavItemsToFenceRequestData { Action: "SellAllFromSavage"; + totalValue: number; fromOwner: OwnerInfo; toOwner: OwnerInfo; }