Fix selling to trader an amount above stack size causing currency to not stack
This commit is contained in:
parent
a1e84992a2
commit
8dab47b3fd
@ -514,7 +514,7 @@ export class ItemHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split item stack if it exceeds its items StackMaxSize property
|
* Split item stack if it exceeds its items StackMaxSize property into child items of passed in parent
|
||||||
* @param itemToSplit Item to split into smaller stacks
|
* @param itemToSplit Item to split into smaller stacks
|
||||||
* @returns Array of root item + children
|
* @returns Array of root item + children
|
||||||
*/
|
*/
|
||||||
@ -552,6 +552,39 @@ export class ItemHelper
|
|||||||
return rootAndChildren;
|
return rootAndChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn items like money into separate stacks that adhere to max stack size
|
||||||
|
* @param itemToSplit Item to split into smaller stacks
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public splitStackIntoSeparateItems(itemToSplit: Item): Item[][]
|
||||||
|
{
|
||||||
|
const itemTemplate = this.getItem(itemToSplit._tpl)[1];
|
||||||
|
const itemMaxStackSize = itemTemplate._props.StackMaxSize ?? 1;
|
||||||
|
|
||||||
|
// item already within bounds of stack size, return it
|
||||||
|
if (itemToSplit.upd?.StackObjectsCount <= itemMaxStackSize)
|
||||||
|
{
|
||||||
|
return [[itemToSplit]];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split items stack into chunks
|
||||||
|
const result: Item[][] = [];
|
||||||
|
let remainingCount = itemToSplit.upd.StackObjectsCount;
|
||||||
|
while (remainingCount)
|
||||||
|
{
|
||||||
|
const amount = Math.min(remainingCount, itemMaxStackSize);
|
||||||
|
const newItem = this.jsonUtil.clone(itemToSplit);
|
||||||
|
|
||||||
|
newItem._id = this.hashUtil.generate();
|
||||||
|
newItem.upd.StackObjectsCount = amount;
|
||||||
|
remainingCount -= amount;
|
||||||
|
result.push([newItem]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find Barter items from array of items
|
* Find Barter items from array of items
|
||||||
* @param {string} by tpl or id
|
* @param {string} by tpl or id
|
||||||
|
@ -7,7 +7,7 @@ import { PaymentHelper } from "@spt-aki/helpers/PaymentHelper";
|
|||||||
import { TraderHelper } from "@spt-aki/helpers/TraderHelper";
|
import { TraderHelper } from "@spt-aki/helpers/TraderHelper";
|
||||||
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
|
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
|
||||||
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
|
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
|
||||||
import { IAddItemDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemDirectRequest";
|
import { IAddItemsDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemsDirectRequest";
|
||||||
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
|
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
|
||||||
import { IProcessBuyTradeRequestData } from "@spt-aki/models/eft/trade/IProcessBuyTradeRequestData";
|
import { IProcessBuyTradeRequestData } from "@spt-aki/models/eft/trade/IProcessBuyTradeRequestData";
|
||||||
import { IProcessSellTradeRequestData } from "@spt-aki/models/eft/trade/IProcessSellTradeRequestData";
|
import { IProcessSellTradeRequestData } from "@spt-aki/models/eft/trade/IProcessSellTradeRequestData";
|
||||||
@ -219,23 +219,24 @@ export class PaymentService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rootCurrencyReward = {
|
||||||
|
_id: this.hashUtil.generate(),
|
||||||
|
_tpl: currency,
|
||||||
|
upd: {
|
||||||
|
StackObjectsCount: calcAmount
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const rewards = this.itemHelper.splitStackIntoSeparateItems(rootCurrencyReward);
|
||||||
|
|
||||||
if (!skipSendingMoneyToStash)
|
if (!skipSendingMoneyToStash)
|
||||||
{
|
{
|
||||||
const addItemToStashRequest: IAddItemDirectRequest = {
|
const addItemToStashRequest: IAddItemsDirectRequest = {
|
||||||
itemWithModsToAdd: [
|
itemsWithModsToAdd: rewards,
|
||||||
{
|
|
||||||
_id: this.hashUtil.generate(),
|
|
||||||
_tpl: currency,
|
|
||||||
upd: {
|
|
||||||
StackObjectsCount: calcAmount
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
foundInRaid: false,
|
foundInRaid: false,
|
||||||
callback: null,
|
callback: null,
|
||||||
useSortingTable: true
|
useSortingTable: true
|
||||||
};
|
};
|
||||||
this.inventoryHelper.addItemToStash(sessionID, addItemToStashRequest, pmcData, output);
|
this.inventoryHelper.addItemsToStash(sessionID, addItemToStashRequest, pmcData, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set current sale sum
|
// set current sale sum
|
||||||
|
Loading…
x
Reference in New Issue
Block a user