This commit is contained in:
Dev 2024-02-28 18:34:37 +00:00
commit 854670d4d5
5 changed files with 47 additions and 36 deletions

View File

@ -920,19 +920,7 @@ export class HideoutController
{ {
for (const tool of production.sptRequiredTools) for (const tool of production.sptRequiredTools)
{ {
const toolToAdd: Item = { toolsToSendToPlayer.push([tool]);
_id: this.hashUtil.generate(),
_tpl: tool,
};
if (this.itemHelper.isItemTplStackable(tool))
{
toolToAdd.upd = {
StackObjectsCount: 1,
}
}
toolsToSendToPlayer.push([toolToAdd]);
} }
} }
@ -963,18 +951,23 @@ export class HideoutController
return; return;
} }
// Add the used tools to the stash as non-FiR // Add the tools to the stash, we have to do this individually due to FiR state potentially being different
for (const toolItem of toolsToSendToPlayer)
{
// Note: FIR state will be based on the first item's SpawnedInSession property per item group
const addToolsRequest: IAddItemsDirectRequest = { const addToolsRequest: IAddItemsDirectRequest = {
itemsWithModsToAdd: toolsToSendToPlayer, itemsWithModsToAdd: [toolItem],
foundInRaid: false, foundInRaid: toolItem[0].upd?.SpawnedInSession ?? false,
useSortingTable: false, useSortingTable: false,
callback: null, callback: null,
}; };
this.inventoryHelper.addItemsToStash(sessionID, addToolsRequest, pmcData, output); this.inventoryHelper.addItemsToStash(sessionID, addToolsRequest, pmcData, output);
if (output.warnings.length > 0) if (output.warnings.length > 0)
{ {
return; return;
} }
}
// Add the crafting result to the stash, marked as FiR // Add the crafting result to the stash, marked as FiR
const addItemsRequest: IAddItemsDirectRequest = { const addItemsRequest: IAddItemsDirectRequest = {

View File

@ -27,6 +27,7 @@ import { PlayerService } from "@spt-aki/services/PlayerService";
import { HashUtil } from "@spt-aki/utils/HashUtil"; import { HashUtil } from "@spt-aki/utils/HashUtil";
import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil"; import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil";
import { TimeUtil } from "@spt-aki/utils/TimeUtil"; import { TimeUtil } from "@spt-aki/utils/TimeUtil";
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
@injectable() @injectable()
export class HideoutHelper export class HideoutHelper
@ -53,6 +54,7 @@ export class HideoutHelper
@inject("LocalisationService") protected localisationService: LocalisationService, @inject("LocalisationService") protected localisationService: LocalisationService,
@inject("ItemHelper") protected itemHelper: ItemHelper, @inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("ConfigServer") protected configServer: ConfigServer, @inject("ConfigServer") protected configServer: ConfigServer,
@inject("JsonUtil") protected jsonUtil: JsonUtil,
) )
{ {
this.hideoutConfig = this.configServer.getConfig(ConfigTypes.HIDEOUT); this.hideoutConfig = this.configServer.getConfig(ConfigTypes.HIDEOUT);
@ -102,10 +104,28 @@ export class HideoutHelper
); );
// Store the tools used for this production, so we can return them later // Store the tools used for this production, so we can return them later
const productionTools = recipe.requirements.filter(req => req.type === "Tool").map(req => req.templateId); const bodyAsSingle = body as IHideoutSingleProductionStartRequestData;
if (productionTools.length > 0) if (bodyAsSingle && bodyAsSingle.tools.length > 0)
{ {
production.sptRequiredTools = productionTools; production.sptRequiredTools = [];
for (const tool of bodyAsSingle.tools)
{
const toolItem = this.jsonUtil.clone(pmcData.Inventory.items.find(x => x._id === tool.id));
// Make sure we only return as many as we took
if (!toolItem.upd)
{
toolItem.upd = {};
}
toolItem.upd.StackObjectsCount = tool.count;
production.sptRequiredTools.push({
_id: this.hashUtil.generate(),
_tpl: toolItem._tpl,
upd: toolItem.upd
});
}
} }
pmcData.Hideout.Production[body.recipeId] = production; pmcData.Hideout.Production[body.recipeId] = production;

View File

@ -393,8 +393,8 @@ export interface Productive
sptIsComplete?: boolean; sptIsComplete?: boolean;
/** Is the craft a Continuous, e.g bitcoins/water collector */ /** Is the craft a Continuous, e.g bitcoins/water collector */
sptIsContinuous?: boolean; sptIsContinuous?: boolean;
/** Stores a list of tools used in this craft, to give back once the craft is done */ /** Stores a list of tools used in this craft and whether they're FiR, to give back once the craft is done */
sptRequiredTools?: string[]; sptRequiredTools?: Item[];
} }
export interface Production extends Productive export interface Production extends Productive

View File

@ -229,6 +229,7 @@ export class RagfairOfferService
if (isPlayer && staleOffer.endTime <= this.timeUtil.getTimestamp()) if (isPlayer && staleOffer.endTime <= this.timeUtil.getTimestamp())
{ {
this.returnPlayerOffer(staleOffer); this.returnPlayerOffer(staleOffer);
return;
} }
// Remove expired existing offer from global offers // Remove expired existing offer from global offers

View File

@ -175,7 +175,7 @@ export class VFS
fs.writeFileSync(filepath, ""); fs.writeFileSync(filepath, "");
} }
this.lockFileSync(filepath); const releaseCallback = this.lockFileSync(filepath);
if (!append && atomic) if (!append && atomic)
{ {
@ -186,10 +186,7 @@ export class VFS
fs.writeFileSync(filepath, data, options); fs.writeFileSync(filepath, data, options);
} }
if (this.checkFileSync(filepath)) releaseCallback();
{
this.unlockFileSync(filepath);
}
} }
public async writeFileAsync(filepath: any, data = "", append = false, atomic = true): Promise<void> public async writeFileAsync(filepath: any, data = "", append = false, atomic = true): Promise<void>
@ -307,12 +304,12 @@ export class VFS
await this.renamePromisify(oldPath, newPath); await this.renamePromisify(oldPath, newPath);
} }
protected lockFileSync(filepath: any): void protected lockFileSync(filepath: any): () => void
{ {
lockfile.lockSync(filepath); return lockfile.lockSync(filepath);
} }
protected checkFileSync(filepath: any): any protected checkFileSync(filepath: any): boolean
{ {
return lockfile.checkSync(filepath); return lockfile.checkSync(filepath);
} }