Migrate getBTC() to use addItemToStash()

This commit is contained in:
Dev 2024-01-20 20:26:55 +00:00
parent ceba6b3064
commit 80b549a2d5

View File

@ -10,6 +10,7 @@ import { IHideoutContinuousProductionStartRequestData } from "@spt-aki/models/ef
import { IHideoutProduction } from "@spt-aki/models/eft/hideout/IHideoutProduction";
import { IHideoutSingleProductionStartRequestData } from "@spt-aki/models/eft/hideout/IHideoutSingleProductionStartRequestData";
import { IHideoutTakeProductionRequestData } from "@spt-aki/models/eft/hideout/IHideoutTakeProductionRequestData";
import { IAddItemDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemDirectRequest";
import { IAddItemRequestData } from "@spt-aki/models/eft/inventory/IAddItemRequestData";
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
@ -955,11 +956,33 @@ export class HideoutHelper
return this.httpResponse.appendErrorToOutput(output, errorMsg);
}
const btcCoinCreationRequest = this.createBitcoinRequest(pmcData);
const coinSlotCount = this.getBTCSlots(pmcData);
const btcCoinCreationRequest = this.createBitcoinRequest(pmcData, coinSlotCount);
// Run callback after coins are added to player inventory
const callback = () =>
// Add FiR coins to player inventory
this.inventoryHelper.addItemToStash(sessionId, btcCoinCreationRequest, pmcData, output);
}
/**
* Create a bitcoin request object
* @param pmcData Player profile
* @returns IAddItemRequestData
*/
protected createBitcoinRequest(pmcData: IPmcData, coinSlotCount: number): IAddItemDirectRequest
{
return {
itemWithModsToAdd: [
{
_id: this.hashUtil.generate(),
_tpl: HideoutHelper.bitcoin,
upd: {
StackObjectsCount: pmcData.Hideout.Production[HideoutHelper.bitcoinFarm].Products.length
}
}
],
foundInRaid: true,
useSortingTable: true,
callback: () =>
{
// Is at max capacity
if (pmcData.Hideout.Production[HideoutHelper.bitcoinFarm].Products.length >= coinSlotCount)
@ -968,27 +991,9 @@ export class HideoutHelper
pmcData.Hideout.Production[HideoutHelper.bitcoinFarm].StartTimestamp = this.timeUtil.getTimestamp();
}
// Remove crafted coins from production in profile
// Remove crafted coins from production in profile now they've been collected
pmcData.Hideout.Production[HideoutHelper.bitcoinFarm].Products = [];
};
// Add FiR coins to player inventory
return this.inventoryHelper.addItem(pmcData, btcCoinCreationRequest, output, sessionId, callback, true);
}
/**
* Create a single bitcoin request object
* @param pmcData Player profile
* @returns IAddItemRequestData
*/
protected createBitcoinRequest(pmcData: IPmcData): IAddItemRequestData
{
return {
items: [{
item_id: HideoutHelper.bitcoin,
count: pmcData.Hideout.Production[HideoutHelper.bitcoinFarm].Products.length,
}],
tid: "ragfair",
};
}