EXPERIMENTAL - pass output object into handleItemEvent and into move function

This commit is contained in:
Dev 2024-02-10 15:44:21 +00:00
parent d436534ea0
commit 9fe739debb
5 changed files with 34 additions and 15 deletions

View File

@ -35,9 +35,16 @@ export class InventoryCallbacks
{}
/** Handle client/game/profile/items/moving Move event */
public moveItem(pmcData: IPmcData, body: IInventoryMoveRequestData, sessionID: string): IItemEventRouterResponse
public moveItem(
pmcData: IPmcData,
body: IInventoryMoveRequestData,
sessionID: string,
output: IItemEventRouterResponse,
): IItemEventRouterResponse
{
return this.inventoryController.moveItem(pmcData, body, sessionID);
this.inventoryController.moveItem(pmcData, body, sessionID, output);
return output;
}
/** Handle Remove event */

View File

@ -86,13 +86,12 @@ export class InventoryController
pmcData: IPmcData,
moveRequest: IInventoryMoveRequestData,
sessionID: string,
): IItemEventRouterResponse
output: IItemEventRouterResponse,
): void
{
const output = this.eventOutputHolder.getOutput(sessionID);
if (output.warnings.length > 0)
{
return output;
return;
}
// Changes made to result apply to character inventory
@ -102,7 +101,8 @@ export class InventoryController
// Dont move items from trader to profile, this can happen when editing a traders preset weapons
if (moveRequest.fromOwner?.type === "Trader" && !ownerInventoryItems.isMail)
{
return this.getTraderExploitErrorResponse(output);
this.getTraderExploitErrorResponse(output);
return;
}
// Check for item in inventory before allowing internal transfer
@ -111,13 +111,15 @@ export class InventoryController
if (!originalItemLocation)
{
// Internal item move but item never existed, possible dupe glitch
return this.getTraderExploitErrorResponse(output);
this.getTraderExploitErrorResponse(output);
return;
}
const moveResult = this.inventoryHelper.moveItemInternal(pmcData, ownerInventoryItems.from, moveRequest);
if (!moveResult.success)
{
return this.httpResponseUtil.appendErrorToOutput(output, moveResult.errorMessage);
this.httpResponseUtil.appendErrorToOutput(output, moveResult.errorMessage);
return;
}
// Item is moving into or out of place of fame dogtag slot
@ -130,7 +132,6 @@ export class InventoryController
{
this.inventoryHelper.moveItemToProfile(ownerInventoryItems.from, ownerInventoryItems.to, moveRequest);
}
return output;
}
/**

View File

@ -75,7 +75,13 @@ export class DynamicRouter extends Router
// So instead I added the definition
export class ItemEventRouterDefinition extends Router
{
public handleItemEvent(url: string, pmcData: IPmcData, body: any, sessionID: string): IItemEventRouterResponse
public handleItemEvent(
url: string,
pmcData: IPmcData,
body: any,
sessionID: string,
output: IItemEventRouterResponse,
): void
{
throw new Error("This method needs to be overrode by the router classes");
}

View File

@ -29,7 +29,7 @@ export class ItemEventRouter
{
this.eventOutputHolder.resetOutput(sessionID);
let result = this.eventOutputHolder.getOutput(sessionID);
const output = this.eventOutputHolder.getOutput(sessionID);
for (const body of info.data)
{
@ -39,7 +39,11 @@ export class ItemEventRouter
if (eventRouter)
{
this.logger.debug(`event: ${body.Action}`);
result = eventRouter.handleItemEvent(body.Action, pmcData, body, sessionID);
eventRouter.handleItemEvent(body.Action, pmcData, body, sessionID, output);
if (output.warnings.length > 0)
{
break;
}
}
else
{
@ -50,6 +54,6 @@ export class ItemEventRouter
this.eventOutputHolder.updateOutputProperties(sessionID);
return result;
return output;
}
}

View File

@ -51,12 +51,13 @@ export class InventoryItemEventRouter extends ItemEventRouterDefinition
pmcData: IPmcData,
body: any,
sessionID: string,
output: IItemEventRouterResponse,
): IItemEventRouterResponse
{
switch (url)
{
case ItemEventActions.MOVE:
return this.inventoryCallbacks.moveItem(pmcData, body, sessionID);
return this.inventoryCallbacks.moveItem(pmcData, body, sessionID, output);
case ItemEventActions.REMOVE:
return this.inventoryCallbacks.removeItem(pmcData, body, sessionID);
case ItemEventActions.SPLIT: