Fix player being charged multiple times
Fix issue with `findBarterItems()` where it would incorrectly wipe out found results each loop
This commit is contained in:
parent
33d1395dea
commit
93edb3e074
@ -615,32 +615,36 @@ export class ItemHelper
|
|||||||
/**
|
/**
|
||||||
* 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
|
||||||
* @param {Item[]} items Array of items to iterate over
|
* @param {Item[]} itemsToSearch Array of items to iterate over
|
||||||
* @param {string} barterItemId
|
* @param {string} desiredBarterItemIds
|
||||||
* @returns Array of Item objects
|
* @returns Array of Item objects
|
||||||
*/
|
*/
|
||||||
public findBarterItems(by: "tpl" | "id", items: Item[], barterItemId: string): Item[]
|
public findBarterItems(by: "tpl" | "id", itemsToSearch: Item[], desiredBarterItemIds: string | string[]): Item[]
|
||||||
{
|
{
|
||||||
// find required items to take after buying (handles multiple items)
|
// Find required items to take after buying (handles multiple items)
|
||||||
const barterIDs = typeof barterItemId === "string" ? [barterItemId] : barterItemId;
|
const desiredBarterIds = typeof desiredBarterItemIds === "string"
|
||||||
|
? [desiredBarterItemIds]
|
||||||
|
: desiredBarterItemIds;
|
||||||
|
|
||||||
let barterItems: Item[] = [];
|
const matchingItems: Item[] = [];
|
||||||
for (const barterID of barterIDs)
|
for (const barterId of desiredBarterIds)
|
||||||
{
|
{
|
||||||
const filterResult = items.filter((item) =>
|
const filterResult = itemsToSearch.filter((item) =>
|
||||||
{
|
{
|
||||||
return by === "tpl" ? (item._tpl === barterID) : (item._id === barterID);
|
return by === "tpl"
|
||||||
|
? (item._tpl === barterId)
|
||||||
|
: (item._id === barterId);
|
||||||
});
|
});
|
||||||
|
|
||||||
barterItems = Object.assign(barterItems, filterResult);
|
matchingItems.push(...this.jsonUtil.clone(filterResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (barterItems.length === 0)
|
if (matchingItems.length === 0)
|
||||||
{
|
{
|
||||||
this.logger.warning(`No items found for barter Id: ${barterIDs}`);
|
this.logger.warning(`No items found for barter Id: ${desiredBarterIds}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return barterItems;
|
return matchingItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,15 +99,6 @@ export class TradeHelper
|
|||||||
};
|
};
|
||||||
this.traderHelper.addTraderPurchasesToPlayerProfile(sessionID, itemPurchaseDat);
|
this.traderHelper.addTraderPurchasesToPlayerProfile(sessionID, itemPurchaseDat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pay for item
|
|
||||||
this.paymentService.payMoney(pmcData, buyRequestData, sessionID, output);
|
|
||||||
if (output.warnings.length > 0)
|
|
||||||
{
|
|
||||||
this.logger.error(`Flea transaction failed: ${output.warnings[0].errmsg}`);
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (assortHasBuyRestrictions)
|
if (assortHasBuyRestrictions)
|
||||||
{
|
{
|
||||||
@ -132,16 +123,6 @@ export class TradeHelper
|
|||||||
// Decrement trader item count
|
// Decrement trader item count
|
||||||
itemPurchased.upd.StackObjectsCount -= buyCount;
|
itemPurchased.upd.StackObjectsCount -= buyCount;
|
||||||
|
|
||||||
/// Pay for item
|
|
||||||
this.paymentService.payMoney(pmcData, buyRequestData, sessionID, output);
|
|
||||||
if (output.warnings.length > 0)
|
|
||||||
{
|
|
||||||
const errorMessage = `Transaction failed: ${output.warnings[0].errmsg}`;
|
|
||||||
this.httpResponse.appendErrorToOutput(output, errorMessage);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.fenceService.removeFenceOffer(buyRequestData.item_id);
|
this.fenceService.removeFenceOffer(buyRequestData.item_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -190,13 +171,6 @@ export class TradeHelper
|
|||||||
this.traderHelper.addTraderPurchasesToPlayerProfile(sessionID, itemPurchaseDat);
|
this.traderHelper.addTraderPurchasesToPlayerProfile(sessionID, itemPurchaseDat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pay for item
|
|
||||||
this.paymentService.payMoney(pmcData, buyRequestData, sessionID, output);
|
|
||||||
if (output.warnings.length > 0)
|
|
||||||
{
|
|
||||||
return this.httpResponse.appendErrorToOutput(output, output.warnings[0].errmsg, BackendErrorCodes.UNKNOWN_TRADING_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (assortHasBuyRestrictions)
|
if (assortHasBuyRestrictions)
|
||||||
{
|
{
|
||||||
// Increment non-fence trader item buy count
|
// Increment non-fence trader item buy count
|
||||||
@ -217,6 +191,8 @@ export class TradeHelper
|
|||||||
const itemMaxStackSize = itemDbDetails._props.StackMaxSize;
|
const itemMaxStackSize = itemDbDetails._props.StackMaxSize;
|
||||||
const itemsToSendTotalCount = buyRequestData.count;
|
const itemsToSendTotalCount = buyRequestData.count;
|
||||||
let itemsToSendRemaining = itemsToSendTotalCount;
|
let itemsToSendRemaining = itemsToSendTotalCount;
|
||||||
|
|
||||||
|
// Loop until all items have been sent to player stash
|
||||||
while (itemsToSendRemaining > 0)
|
while (itemsToSendRemaining > 0)
|
||||||
{
|
{
|
||||||
// Handle edge case when remaining items to send < max stack size
|
// Handle edge case when remaining items to send < max stack size
|
||||||
@ -240,9 +216,18 @@ export class TradeHelper
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove amount of items added to player stash
|
// Remove amount of items added to player stash
|
||||||
itemsToSendRemaining -= itemCountToSend;
|
itemsToSendRemaining -= itemCountToSend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pay for purchase
|
||||||
|
this.paymentService.payMoney(pmcData, buyRequestData, sessionID, output);
|
||||||
|
if (output.warnings.length > 0)
|
||||||
|
{
|
||||||
|
const errorMessage = `Transaction failed: ${output.warnings[0].errmsg}`;
|
||||||
|
this.httpResponse.appendErrorToOutput(output, errorMessage, BackendErrorCodes.UNKNOWN_TRADING_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +46,7 @@ export class PaymentService
|
|||||||
output: IItemEventRouterResponse,
|
output: IItemEventRouterResponse,
|
||||||
): IItemEventRouterResponse
|
): IItemEventRouterResponse
|
||||||
{
|
{
|
||||||
|
// May need to convert to trader currency
|
||||||
const trader = this.traderHelper.getTrader(request.tid, sessionID);
|
const trader = this.traderHelper.getTrader(request.tid, sessionID);
|
||||||
|
|
||||||
// Track the amounts of each type of currency involved in the trade.
|
// Track the amounts of each type of currency involved in the trade.
|
||||||
|
Loading…
Reference in New Issue
Block a user