Reset client output object data at end of function, instead of at start - fixes issue where old profile change data persists in memory after player logs out and into another profile

Pass output into failquest function
This commit is contained in:
Dev 2024-02-10 16:23:26 +00:00
parent 4232ba6db1
commit f7a16e15f9
4 changed files with 26 additions and 9 deletions

View File

@ -206,8 +206,13 @@ export class InventoryCallbacks
* TODO - MOVE INTO QUEST CODE
* Handle game/profile/items/moving - QuestFail
*/
public failQuest(pmcData: IPmcData, request: IFailQuestRequestData, sessionID: string): IItemEventRouterResponse
public failQuest(
pmcData: IPmcData,
request: IFailQuestRequestData,
sessionID: string,
output: IItemEventRouterResponse,
): IItemEventRouterResponse
{
return this.questController.failQuest(pmcData, request, sessionID);
return this.questController.failQuest(pmcData, request, sessionID, output);
}
}

View File

@ -842,7 +842,10 @@ export class QuestController
// element `location` properties of the parent so they are sequential, while retaining order
if (typeof removedItem.location === "number")
{
const childItems = this.itemHelper.findAndReturnChildrenAsItems(pmcData.Inventory.items, removedItem.parentId);
const childItems = this.itemHelper.findAndReturnChildrenAsItems(
pmcData.Inventory.items,
removedItem.parentId,
);
childItems.shift(); // Remove the parent
// Sort by the current `location` and update
@ -948,8 +951,13 @@ export class QuestController
* @param sessionID Session id
* @returns IItemEventRouterResponse
*/
public failQuest(pmcData: IPmcData, request: IFailQuestRequestData, sessionID: string): IItemEventRouterResponse
public failQuest(
pmcData: IPmcData,
request: IFailQuestRequestData,
sessionID: string,
output: IItemEventRouterResponse,
): IItemEventRouterResponse
{
return this.questHelper.failQuest(pmcData, request, sessionID);
return this.questHelper.failQuest(pmcData, request, sessionID, output);
}
}

View File

@ -7,12 +7,14 @@ import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEve
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { EventOutputHolder } from "@spt-aki/routers/EventOutputHolder";
import { LocalisationService } from "@spt-aki/services/LocalisationService";
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
@injectable()
export class ItemEventRouter
{
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("JsonUtil") protected jsonUtil: JsonUtil,
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
@injectAll("IERouters") protected itemEventRouters: ItemEventRouterDefinition[],
@inject("LocalisationService") protected localisationService: LocalisationService,
@ -27,8 +29,6 @@ export class ItemEventRouter
*/
public handleEvents(info: IItemEventRouterRequest, sessionID: string): IItemEventRouterResponse
{
this.eventOutputHolder.resetOutput(sessionID);
const output = this.eventOutputHolder.getOutput(sessionID);
for (const body of info.data)
@ -54,6 +54,10 @@ export class ItemEventRouter
this.eventOutputHolder.updateOutputProperties(sessionID);
return output;
// Clone output before resetting the output object ready for use next time
const outputClone = this.jsonUtil.clone(output);
this.eventOutputHolder.resetOutput(sessionID);
return outputClone;
}
}

View File

@ -99,7 +99,7 @@ export class InventoryItemEventRouter extends ItemEventRouterDefinition
case ItemEventActions.SET_FAVORITE_ITEMS:
return this.inventoryCallbacks.setFavoriteItem(pmcData, body, sessionID);
case ItemEventActions.QUEST_FAIL:
return this.inventoryCallbacks.failQuest(pmcData, body, sessionID);
return this.inventoryCallbacks.failQuest(pmcData, body, sessionID, output);
default:
throw new Error(`Unhandled event ${url} request: ${JSON.stringify(body)}`);
}