Reduce instances of IItemEventRouterResponse
being passed into a function and then returned, its an object and passed by ref, no need to return it
Reduce instances of `IItemEventRouterResponse` being reassigned in a function Rename `getMoney` to `giveProfileMoney`
This commit is contained in:
parent
9daa706325
commit
0166e30dd1
@ -114,7 +114,7 @@ export class HealthController
|
||||
*/
|
||||
public offraidEat(pmcData: IPmcData, request: IOffraidEatRequestData, sessionID: string): IItemEventRouterResponse
|
||||
{
|
||||
let output = this.eventOutputHolder.getOutput(sessionID);
|
||||
const output = this.eventOutputHolder.getOutput(sessionID);
|
||||
let resourceLeft = 0;
|
||||
|
||||
const itemToConsume = pmcData.Inventory.items.find((x) => x._id === request.item);
|
||||
@ -145,7 +145,7 @@ export class HealthController
|
||||
// Remove item from inventory if resource has dropped below threshold
|
||||
if (consumedItemMaxResource === 1 || resourceLeft < 1)
|
||||
{
|
||||
output = this.inventoryHelper.removeItem(pmcData, request.item, sessionID, output);
|
||||
this.inventoryHelper.removeItem(pmcData, request.item, sessionID, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
@ -165,7 +165,7 @@ export class HealthController
|
||||
sessionID: string,
|
||||
): IItemEventRouterResponse
|
||||
{
|
||||
let output = this.eventOutputHolder.getOutput(sessionID);
|
||||
const output = this.eventOutputHolder.getOutput(sessionID);
|
||||
const payMoneyRequest: IProcessBuyTradeRequestData = {
|
||||
Action: healthTreatmentRequest.Action,
|
||||
tid: Traders.THERAPIST,
|
||||
@ -179,7 +179,7 @@ export class HealthController
|
||||
scheme_id: 0,
|
||||
};
|
||||
|
||||
output = this.paymentService.payMoney(pmcData, payMoneyRequest, sessionID, output);
|
||||
this.paymentService.payMoney(pmcData, payMoneyRequest, sessionID, output);
|
||||
if (output.warnings.length > 0)
|
||||
{
|
||||
return output;
|
||||
|
@ -368,7 +368,7 @@ export class HideoutController
|
||||
sessionID: string,
|
||||
): IItemEventRouterResponse
|
||||
{
|
||||
let output = this.eventOutputHolder.getOutput(sessionID);
|
||||
const output = this.eventOutputHolder.getOutput(sessionID);
|
||||
|
||||
const itemsToAdd = Object.entries(addItemToHideoutRequest.items).map((kvp) =>
|
||||
{
|
||||
@ -410,7 +410,7 @@ export class HideoutController
|
||||
upd: item.inventoryItem.upd,
|
||||
}];
|
||||
|
||||
output = this.inventoryHelper.removeItem(pmcData, item.inventoryItem._id, sessionID, output);
|
||||
this.inventoryHelper.removeItem(pmcData, item.inventoryItem._id, sessionID, output);
|
||||
}
|
||||
|
||||
// Trigger a forced update
|
||||
@ -609,7 +609,7 @@ export class HideoutController
|
||||
sessionID: string,
|
||||
): IItemEventRouterResponse
|
||||
{
|
||||
let output = this.eventOutputHolder.getOutput(sessionID);
|
||||
const output = this.eventOutputHolder.getOutput(sessionID);
|
||||
|
||||
for (const requestedItem of body.items)
|
||||
{
|
||||
@ -631,7 +631,7 @@ export class HideoutController
|
||||
}
|
||||
else
|
||||
{
|
||||
output = this.inventoryHelper.removeItem(pmcData, requestedItem.id, sessionID, output);
|
||||
this.inventoryHelper.removeItem(pmcData, requestedItem.id, sessionID, output);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -587,7 +587,7 @@ export class InsuranceController
|
||||
*/
|
||||
public insure(pmcData: IPmcData, body: IInsureRequestData, sessionID: string): IItemEventRouterResponse
|
||||
{
|
||||
let output = this.eventOutputHolder.getOutput(sessionID);
|
||||
const output = this.eventOutputHolder.getOutput(sessionID);
|
||||
const itemsToInsureCount = body.items.length;
|
||||
const itemsToPay = [];
|
||||
const inventoryItemsHash = {};
|
||||
@ -617,7 +617,7 @@ export class InsuranceController
|
||||
};
|
||||
|
||||
// pay for the item insurance
|
||||
output = this.paymentService.payMoney(pmcData, options, sessionID, output);
|
||||
this.paymentService.payMoney(pmcData, options, sessionID, output);
|
||||
if (output.warnings.length > 0)
|
||||
{
|
||||
return output;
|
||||
@ -644,7 +644,7 @@ export class InsuranceController
|
||||
*/
|
||||
public cost(request: IGetInsuranceCostRequestData, sessionID: string): IGetInsuranceCostResponseData
|
||||
{
|
||||
const output: IGetInsuranceCostResponseData = {};
|
||||
const response: IGetInsuranceCostResponseData = {};
|
||||
const pmcData = this.profileHelper.getPmcProfile(sessionID);
|
||||
const inventoryItemsHash: Record<string, Item> = {};
|
||||
|
||||
@ -671,10 +671,10 @@ export class InsuranceController
|
||||
);
|
||||
}
|
||||
|
||||
output[trader] = items;
|
||||
response[trader] = items;
|
||||
}
|
||||
|
||||
return output;
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,13 +173,17 @@ export class InventoryController
|
||||
sessionID: string,
|
||||
): IItemEventRouterResponse
|
||||
{
|
||||
const output = this.eventOutputHolder.getOutput(sessionID);
|
||||
|
||||
if (body.fromOwner?.type === "Mail")
|
||||
{
|
||||
return this.inventoryHelper.removeItemAndChildrenFromMailRewards(
|
||||
this.inventoryHelper.removeItemAndChildrenFromMailRewards(
|
||||
sessionID,
|
||||
body,
|
||||
this.eventOutputHolder.getOutput(sessionID),
|
||||
output,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const profileToRemoveItemFrom = (!body.fromOwner || body.fromOwner.id === pmcData._id)
|
||||
@ -190,7 +194,7 @@ export class InventoryController
|
||||
profileToRemoveItemFrom,
|
||||
body.item,
|
||||
sessionID,
|
||||
this.eventOutputHolder.getOutput(sessionID),
|
||||
output,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -711,7 +711,7 @@ export class RagfairController
|
||||
|
||||
public extendOffer(info: IExtendOfferRequestData, sessionID: string): IItemEventRouterResponse
|
||||
{
|
||||
let output = this.eventOutputHolder.getOutput(sessionID);
|
||||
const output = this.eventOutputHolder.getOutput(sessionID);
|
||||
const pmcData = this.saveServer.getProfile(sessionID).characters.pmc;
|
||||
const offers = pmcData.RagfairInfo.offers;
|
||||
const index = offers.findIndex((offer) => offer._id === info.offerId);
|
||||
@ -743,7 +743,7 @@ export class RagfairController
|
||||
);
|
||||
|
||||
const request = this.createBuyTradeRequestObject("RUB", tax);
|
||||
output = this.paymentService.payMoney(pmcData, request, sessionID, output);
|
||||
this.paymentService.payMoney(pmcData, request, sessionID, output);
|
||||
if (output.warnings.length > 0)
|
||||
{
|
||||
return this.httpResponse.appendErrorToOutput(
|
||||
|
@ -435,7 +435,7 @@ export class RepeatableQuestController
|
||||
break;
|
||||
}
|
||||
|
||||
let output = this.eventOutputHolder.getOutput(sessionID);
|
||||
const output = this.eventOutputHolder.getOutput(sessionID);
|
||||
if (!repeatableToChange)
|
||||
{
|
||||
const message = "Unable to find repeatable quest to replace";
|
||||
@ -447,7 +447,7 @@ export class RepeatableQuestController
|
||||
// Charge player money for replacing quest
|
||||
for (const cost of changeRequirement.changeCost)
|
||||
{
|
||||
output = this.paymentService.addPaymentToOutput(pmcData, cost.templateId, cost.count, sessionID, output);
|
||||
this.paymentService.addPaymentToOutput(pmcData, cost.templateId, cost.count, sessionID, output);
|
||||
if (output.warnings.length > 0)
|
||||
{
|
||||
return output;
|
||||
|
@ -68,14 +68,18 @@ export class TradeController
|
||||
{
|
||||
const foundInRaid = this.traderConfig.purchasesAreFoundInRaid;
|
||||
const buyData = <IProcessBuyTradeRequestData>request;
|
||||
return this.tradeHelper.buyItem(pmcData, buyData, sessionID, foundInRaid, output);
|
||||
this.tradeHelper.buyItem(pmcData, buyData, sessionID, foundInRaid, output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
// Selling
|
||||
if (request.type === "sell_to_trader")
|
||||
{
|
||||
const sellData = <IProcessSellTradeRequestData>request;
|
||||
return this.tradeHelper.sellItem(pmcData, pmcData, sellData, sessionID);
|
||||
this.tradeHelper.sellItem(pmcData, pmcData, sellData, sessionID, output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
const errorMessage = `Unhandled trade event: ${request.type}`;
|
||||
@ -226,16 +230,19 @@ export class TradeController
|
||||
sessionId: string,
|
||||
): IItemEventRouterResponse
|
||||
{
|
||||
const output = this.eventOutputHolder.getOutput(sessionId);
|
||||
const scavProfile = this.profileHelper.getFullProfile(sessionId)?.characters?.scav;
|
||||
if (!scavProfile)
|
||||
{
|
||||
return this.httpResponse.appendErrorToOutput(
|
||||
this.eventOutputHolder.getOutput(sessionId),
|
||||
output,
|
||||
`Profile ${request.fromOwner.id} has no scav account`,
|
||||
);
|
||||
}
|
||||
|
||||
return this.sellInventoryToTrader(sessionId, scavProfile, pmcData, Traders.FENCE);
|
||||
this.sellInventoryToTrader(sessionId, scavProfile, pmcData, Traders.FENCE, output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -245,14 +252,15 @@ export class TradeController
|
||||
* @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
|
||||
* @returns IItemEventRouterResponse
|
||||
* @param output IItemEventRouterResponse
|
||||
*/
|
||||
protected sellInventoryToTrader(
|
||||
sessionId: string,
|
||||
profileWithItemsToSell: IPmcData,
|
||||
profileThatGetsMoney: IPmcData,
|
||||
trader: Traders,
|
||||
): IItemEventRouterResponse
|
||||
output: IItemEventRouterResponse
|
||||
): void
|
||||
{
|
||||
const handbookPrices = this.ragfairPriceService.getAllStaticPrices();
|
||||
// TODO, apply trader sell bonuses?
|
||||
@ -291,7 +299,7 @@ export class TradeController
|
||||
});
|
||||
}
|
||||
this.logger.debug(`Selling scav items to fence for ${sellRequest.price} roubles`);
|
||||
return this.tradeHelper.sellItem(profileWithItemsToSell, profileThatGetsMoney, sellRequest, sessionId);
|
||||
this.tradeHelper.sellItem(profileWithItemsToSell, profileThatGetsMoney, sellRequest, sessionId, output);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -915,7 +915,7 @@ export class InventoryHelper
|
||||
sessionId: string,
|
||||
removeRequest: IInventoryRemoveRequestData,
|
||||
output: IItemEventRouterResponse,
|
||||
): IItemEventRouterResponse
|
||||
): void
|
||||
{
|
||||
const fullProfile = this.profileHelper.getFullProfile(sessionId);
|
||||
|
||||
@ -951,8 +951,6 @@ export class InventoryHelper
|
||||
messageWithReward.rewardCollected = !hasRewardItemsRemaining;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public removeItemByCount(
|
||||
|
@ -10,6 +10,7 @@ import { IAddItemDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemDir
|
||||
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
|
||||
import { IProcessBuyTradeRequestData } from "@spt-aki/models/eft/trade/IProcessBuyTradeRequestData";
|
||||
import { IProcessSellTradeRequestData } from "@spt-aki/models/eft/trade/IProcessSellTradeRequestData";
|
||||
import { BackendErrorCodes } from "@spt-aki/models/enums/BackendErrorCodes";
|
||||
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
||||
import { Traders } from "@spt-aki/models/enums/Traders";
|
||||
import { IInventoryConfig } from "@spt-aki/models/spt/config/IInventoryConfig";
|
||||
@ -65,7 +66,7 @@ export class TradeHelper
|
||||
sessionID: string,
|
||||
foundInRaid: boolean,
|
||||
output: IItemEventRouterResponse,
|
||||
): IItemEventRouterResponse
|
||||
): void
|
||||
{
|
||||
let offerItems: Item[] = [];
|
||||
let buyCallback: { (buyCount: number) };
|
||||
@ -132,10 +133,13 @@ export class TradeHelper
|
||||
itemPurchased.upd.StackObjectsCount -= buyCount;
|
||||
|
||||
/// Pay for item
|
||||
output = this.paymentService.payMoney(pmcData, buyRequestData, sessionID, output);
|
||||
this.paymentService.payMoney(pmcData, buyRequestData, sessionID, output);
|
||||
if (output.warnings.length > 0)
|
||||
{
|
||||
throw new Error(`Transaction failed: ${output.warnings[0].errmsg}`);
|
||||
const errorMessage = `Transaction failed: ${output.warnings[0].errmsg}`;
|
||||
this.httpResponse.appendErrorToOutput(output, errorMessage);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.fenceService.removeFenceOffer(buyRequestData.item_id);
|
||||
@ -147,7 +151,9 @@ export class TradeHelper
|
||||
{
|
||||
this.logger.debug(`Tried to buy item ${buyRequestData.item_id} from fence that no longer exists`);
|
||||
const message = this.localisationService.getText("ragfair-offer_no_longer_exists");
|
||||
return this.httpResponse.appendErrorToOutput(output, message);
|
||||
this.httpResponse.appendErrorToOutput(output, message);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
offerItems = this.itemHelper.findAndReturnChildrenAsItems(fenceItems, buyRequestData.item_id);
|
||||
@ -185,10 +191,10 @@ export class TradeHelper
|
||||
}
|
||||
|
||||
/// Pay for item
|
||||
output = this.paymentService.payMoney(pmcData, buyRequestData, sessionID, output);
|
||||
this.paymentService.payMoney(pmcData, buyRequestData, sessionID, output);
|
||||
if (output.warnings.length > 0)
|
||||
{
|
||||
throw new Error(`Transaction failed: ${output.warnings[0].errmsg}`);
|
||||
return this.httpResponse.appendErrorToOutput(output, output.warnings[0].errmsg, BackendErrorCodes.UNKNOWN_TRADING_ERROR);
|
||||
}
|
||||
|
||||
if (assortHasBuyRestrictions)
|
||||
@ -232,13 +238,11 @@ export class TradeHelper
|
||||
this.inventoryHelper.addItemToStash(sessionID, request, pmcData, output);
|
||||
if (output.warnings.length > 0)
|
||||
{
|
||||
return output;
|
||||
return;
|
||||
}
|
||||
// Remove amount of items added to player stash
|
||||
itemsToSendRemaining -= itemCountToSend;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -247,17 +251,16 @@ export class TradeHelper
|
||||
* @param profileToReceiveMoney Profile to accept the money for selling item
|
||||
* @param sellRequest Request data
|
||||
* @param sessionID Session id
|
||||
* @returns IItemEventRouterResponse
|
||||
* @param output IItemEventRouterResponse
|
||||
*/
|
||||
public sellItem(
|
||||
profileWithItemsToSell: IPmcData,
|
||||
profileToReceiveMoney: IPmcData,
|
||||
sellRequest: IProcessSellTradeRequestData,
|
||||
sessionID: string,
|
||||
): IItemEventRouterResponse
|
||||
output: IItemEventRouterResponse,
|
||||
): void
|
||||
{
|
||||
let output = this.eventOutputHolder.getOutput(sessionID);
|
||||
|
||||
// Find item in inventory and remove it
|
||||
for (const itemToBeRemoved of sellRequest.items)
|
||||
{
|
||||
@ -270,17 +273,19 @@ export class TradeHelper
|
||||
const errorMessage = `Unable to sell item ${itemToBeRemoved.id}, cannot be found in player inventory`;
|
||||
this.logger.error(errorMessage);
|
||||
|
||||
return this.httpResponse.appendErrorToOutput(output, errorMessage);
|
||||
this.httpResponse.appendErrorToOutput(output, errorMessage);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.debug(`Selling: id: ${matchingItemInInventory._id} tpl: ${matchingItemInInventory._tpl}`);
|
||||
|
||||
// Also removes children
|
||||
output = this.inventoryHelper.removeItem(profileWithItemsToSell, itemToBeRemoved.id, sessionID, output);
|
||||
this.inventoryHelper.removeItem(profileWithItemsToSell, itemToBeRemoved.id, sessionID, output);
|
||||
}
|
||||
|
||||
// Give player money for sold item(s)
|
||||
return this.paymentService.getMoney(profileToReceiveMoney, sellRequest.price, sellRequest, output, sessionID);
|
||||
this.paymentService.giveProfileMoney(profileToReceiveMoney, sellRequest.price, sellRequest, output, sessionID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,7 +61,7 @@ export class PaymentService
|
||||
if (!this.paymentHelper.isMoneyTpl(item._tpl))
|
||||
{
|
||||
// If the item is not money, remove it from the inventory.
|
||||
output = this.inventoryHelper.removeItem(pmcData, item._id, sessionID, output);
|
||||
this.inventoryHelper.removeItem(pmcData, item._id, sessionID, output);
|
||||
request.scheme_items[index].count = 0;
|
||||
}
|
||||
else
|
||||
@ -91,7 +91,7 @@ export class PaymentService
|
||||
if (currencyAmount > 0)
|
||||
{
|
||||
// Find money stacks in inventory and remove amount needed + update output object to inform client of changes
|
||||
output = this.addPaymentToOutput(pmcData, currencyTpl, currencyAmount, sessionID, output);
|
||||
this.addPaymentToOutput(pmcData, currencyTpl, currencyAmount, sessionID, output);
|
||||
|
||||
// If there are warnings, exit early.
|
||||
if (output.warnings.length > 0)
|
||||
@ -163,13 +163,13 @@ export class PaymentService
|
||||
* @param {string} sessionID
|
||||
* @returns IItemEventRouterResponse
|
||||
*/
|
||||
public getMoney(
|
||||
public giveProfileMoney(
|
||||
pmcData: IPmcData,
|
||||
amount: number,
|
||||
body: IProcessSellTradeRequestData,
|
||||
output: IItemEventRouterResponse,
|
||||
sessionID: string,
|
||||
): IItemEventRouterResponse
|
||||
): void
|
||||
{
|
||||
const trader = this.traderHelper.getTrader(body.tid, sessionID);
|
||||
const currency = this.paymentHelper.getCurrency(trader.currency);
|
||||
@ -233,8 +233,6 @@ export class PaymentService
|
||||
|
||||
pmcData.TradersInfo[body.tid].salesSum = saleSum;
|
||||
this.traderHelper.lvlUp(body.tid, pmcData);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -269,7 +267,6 @@ export class PaymentService
|
||||
* @param amountToPay money value to pay
|
||||
* @param sessionID Session id
|
||||
* @param output output object to send to client
|
||||
* @returns IItemEventRouterResponse
|
||||
*/
|
||||
public addPaymentToOutput(
|
||||
pmcData: IPmcData,
|
||||
@ -277,7 +274,7 @@ export class PaymentService
|
||||
amountToPay: number,
|
||||
sessionID: string,
|
||||
output: IItemEventRouterResponse,
|
||||
): IItemEventRouterResponse
|
||||
): void
|
||||
{
|
||||
const moneyItemsInInventory = this.getSortedMoneyItemsInInventory(
|
||||
pmcData,
|
||||
@ -298,13 +295,13 @@ export class PaymentService
|
||||
amountAvailable: amountAvailable,
|
||||
}),
|
||||
);
|
||||
output = this.httpResponse.appendErrorToOutput(
|
||||
this.httpResponse.appendErrorToOutput(
|
||||
output,
|
||||
this.localisationService.getText("payment-not_enough_money_to_complete_transation_short"),
|
||||
BackendErrorCodes.UNKNOWN_TRADING_ERROR,
|
||||
);
|
||||
|
||||
return output;
|
||||
return;
|
||||
}
|
||||
|
||||
let leftToPay = amountToPay;
|
||||
@ -314,7 +311,7 @@ export class PaymentService
|
||||
if (leftToPay >= itemAmount)
|
||||
{
|
||||
leftToPay -= itemAmount;
|
||||
output = this.inventoryHelper.removeItem(pmcData, moneyItem._id, sessionID, output);
|
||||
this.inventoryHelper.removeItem(pmcData, moneyItem._id, sessionID, output);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -328,8 +325,6 @@ export class PaymentService
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user