Further clean up of paying to trader code inside payMoney()

This commit is contained in:
Dev 2024-11-01 13:41:16 +00:00
parent fb32466c76
commit 8e3ee3f30e

View File

@ -47,6 +47,7 @@ export class PaymentService {
): void {
// May need to convert to trader currency
const trader = this.traderHelper.getTrader(request.tid, sessionID);
const payToTrader = this.traderHelper.traderEnumHasValue(request.tid);
// Track the amounts of each type of currency involved in the trade.
const currencyAmounts: { [key: string]: number } = {};
@ -95,6 +96,7 @@ export class PaymentService {
return;
}
if (payToTrader) {
// Convert the amount to the trader's currency and update the sales sum.
const costOfPurchaseInCurrency = this.handbookHelper.fromRUB(
this.handbookHelper.inRUB(currencyAmount, currencyTpl),
@ -102,14 +104,13 @@ export class PaymentService {
);
// Only update traders
if (this.traderHelper.traderEnumHasValue(request.tid)) {
pmcData.TradersInfo[request.tid].salesSum += costOfPurchaseInCurrency;
}
}
}
// If no currency-based payment is involved, handle it separately
if (totalCurrencyAmount === 0) {
if (totalCurrencyAmount === 0 && payToTrader) {
this.logger.debug(this.localisationService.getText("payment-zero_price_no_payment"));
// Convert the handbook price to the trader's currency and update the sales sum.
@ -117,10 +118,11 @@ export class PaymentService {
this.getTraderItemHandbookPriceRouble(request.item_id, request.tid),
this.paymentHelper.getCurrency(trader.currency),
);
pmcData.TradersInfo[request.tid].salesSum += costOfPurchaseInCurrency;
}
if (this.traderHelper.traderEnumHasValue(request.tid)) {
if (payToTrader) {
this.traderHelper.lvlUp(request.tid, pmcData);
}