Further output object changes

This commit is contained in:
Dev 2024-02-14 15:11:19 +00:00
parent 99df88ec24
commit f449a51f6a
4 changed files with 46 additions and 30 deletions

View File

@ -37,9 +37,16 @@ export class HideoutCallbacks implements OnUpdate
/** /**
* Handle HideoutUpgrade event * Handle HideoutUpgrade event
*/ */
public upgrade(pmcData: IPmcData, body: IHideoutUpgradeRequestData, sessionID: string): IItemEventRouterResponse public upgrade(
pmcData: IPmcData,
body: IHideoutUpgradeRequestData,
sessionID: string,
output: IItemEventRouterResponse,
): IItemEventRouterResponse
{ {
return this.hideoutController.startUpgrade(pmcData, body, sessionID); this.hideoutController.startUpgrade(pmcData, body, sessionID, output);
return output;
} }
/** /**
@ -49,9 +56,12 @@ export class HideoutCallbacks implements OnUpdate
pmcData: IPmcData, pmcData: IPmcData,
body: IHideoutUpgradeCompleteRequestData, body: IHideoutUpgradeCompleteRequestData,
sessionID: string, sessionID: string,
output: IItemEventRouterResponse,
): IItemEventRouterResponse ): IItemEventRouterResponse
{ {
return this.hideoutController.upgradeComplete(pmcData, body, sessionID); this.hideoutController.upgradeComplete(pmcData, body, sessionID, output);
return output;
} }
/** /**
@ -160,9 +170,12 @@ export class HideoutCallbacks implements OnUpdate
pmcData: IPmcData, pmcData: IPmcData,
request: IRecordShootingRangePoints, request: IRecordShootingRangePoints,
sessionId: string, sessionId: string,
output: IItemEventRouterResponse,
): IItemEventRouterResponse ): IItemEventRouterResponse
{ {
return this.hideoutController.recordShootingRangePoints(sessionId, pmcData, request); this.hideoutController.recordShootingRangePoints(sessionId, pmcData, request);
return output;
} }
/** /**

View File

@ -92,15 +92,15 @@ export class HideoutController
* @param pmcData Player profile * @param pmcData Player profile
* @param request upgrade start request * @param request upgrade start request
* @param sessionID Session id * @param sessionID Session id
* @returns IItemEventRouterResponse * @param output Client response
*/ */
public startUpgrade( public startUpgrade(
pmcData: IPmcData, pmcData: IPmcData,
request: IHideoutUpgradeRequestData, request: IHideoutUpgradeRequestData,
sessionID: string, sessionID: string,
): IItemEventRouterResponse output: IItemEventRouterResponse,
): void
{ {
const output = this.eventOutputHolder.getOutput(sessionID);
const items = request.items.map((reqItem) => const items = request.items.map((reqItem) =>
{ {
const item = pmcData.Inventory.items.find((invItem) => invItem._id === reqItem.id); const item = pmcData.Inventory.items.find((invItem) => invItem._id === reqItem.id);
@ -115,7 +115,9 @@ export class HideoutController
this.logger.error( this.logger.error(
this.localisationService.getText("hideout-unable_to_find_item_in_inventory", item.requestedItem.id), this.localisationService.getText("hideout-unable_to_find_item_in_inventory", item.requestedItem.id),
); );
return this.httpResponse.appendErrorToOutput(output); this.httpResponse.appendErrorToOutput(output);
return;
} }
if ( if (
@ -138,7 +140,9 @@ export class HideoutController
if (!profileHideoutArea) if (!profileHideoutArea)
{ {
this.logger.error(this.localisationService.getText("hideout-unable_to_find_area", request.areaType)); this.logger.error(this.localisationService.getText("hideout-unable_to_find_area", request.areaType));
return this.httpResponse.appendErrorToOutput(output); this.httpResponse.appendErrorToOutput(output);
return;
} }
const hideoutDataDb = this.databaseServer.getTables().hideout.areas.find((area) => const hideoutDataDb = this.databaseServer.getTables().hideout.areas.find((area) =>
@ -149,7 +153,9 @@ export class HideoutController
this.logger.error( this.logger.error(
this.localisationService.getText("hideout-unable_to_find_area_in_database", request.areaType), this.localisationService.getText("hideout-unable_to_find_area_in_database", request.areaType),
); );
return this.httpResponse.appendErrorToOutput(output); this.httpResponse.appendErrorToOutput(output);
return;
} }
let ctime = hideoutDataDb.stages[profileHideoutArea.level + 1].constructionTime; let ctime = hideoutDataDb.stages[profileHideoutArea.level + 1].constructionTime;
@ -164,8 +170,6 @@ export class HideoutController
profileHideoutArea.completeTime = Math.round(timestamp + ctime); profileHideoutArea.completeTime = Math.round(timestamp + ctime);
profileHideoutArea.constructing = true; profileHideoutArea.constructing = true;
} }
return output;
} }
/** /**
@ -174,22 +178,24 @@ export class HideoutController
* @param pmcData Player profile * @param pmcData Player profile
* @param request Completed upgrade request * @param request Completed upgrade request
* @param sessionID Session id * @param sessionID Session id
* @returns IItemEventRouterResponse * @param output Client response
*/ */
public upgradeComplete( public upgradeComplete(
pmcData: IPmcData, pmcData: IPmcData,
request: HideoutUpgradeCompleteRequestData, request: HideoutUpgradeCompleteRequestData,
sessionID: string, sessionID: string,
): IItemEventRouterResponse output: IItemEventRouterResponse,
): void
{ {
const output = this.eventOutputHolder.getOutput(sessionID);
const db = this.databaseServer.getTables(); const db = this.databaseServer.getTables();
const profileHideoutArea = pmcData.Hideout.Areas.find((area) => area.type === request.areaType); const profileHideoutArea = pmcData.Hideout.Areas.find((area) => area.type === request.areaType);
if (!profileHideoutArea) if (!profileHideoutArea)
{ {
this.logger.error(this.localisationService.getText("hideout-unable_to_find_area", request.areaType)); this.logger.error(this.localisationService.getText("hideout-unable_to_find_area", request.areaType));
return this.httpResponse.appendErrorToOutput(output); this.httpResponse.appendErrorToOutput(output);
return;
} }
// Upgrade profile values // Upgrade profile values
@ -203,7 +209,9 @@ export class HideoutController
this.logger.error( this.logger.error(
this.localisationService.getText("hideout-unable_to_find_area_in_database", request.areaType), this.localisationService.getText("hideout-unable_to_find_area_in_database", request.areaType),
); );
return this.httpResponse.appendErrorToOutput(output); this.httpResponse.appendErrorToOutput(output);
return;
} }
// Apply bonuses // Apply bonuses
@ -245,8 +253,6 @@ export class HideoutController
SkillTypes.HIDEOUT_MANAGEMENT, SkillTypes.HIDEOUT_MANAGEMENT,
db.globals.config.SkillsSettings.HideoutManagement.SkillPointsPerAreaUpgrade, db.globals.config.SkillsSettings.HideoutManagement.SkillPointsPerAreaUpgrade,
); );
return output;
} }
/** /**
@ -1132,11 +1138,7 @@ export class HideoutController
* @param request shooting range score request * @param request shooting range score request
* @returns IItemEventRouterResponse * @returns IItemEventRouterResponse
*/ */
public recordShootingRangePoints( public recordShootingRangePoints(sessionId: string, pmcData: IPmcData, request: IRecordShootingRangePoints): void
sessionId: string,
pmcData: IPmcData,
request: IRecordShootingRangePoints,
): IItemEventRouterResponse
{ {
// Check if counter exists, add placeholder if it doesnt // Check if counter exists, add placeholder if it doesnt
if (!pmcData.Stats.Eft.OverallCounters.Items.find((x) => x.Key.includes("ShootingRangePoints"))) if (!pmcData.Stats.Eft.OverallCounters.Items.find((x) => x.Key.includes("ShootingRangePoints")))
@ -1149,9 +1151,6 @@ export class HideoutController
x.Key.includes("ShootingRangePoints") x.Key.includes("ShootingRangePoints")
); );
shootingRangeHighScore.Value = request.points; shootingRangeHighScore.Value = request.points;
// Check against live, maybe a response isnt necessary
return this.eventOutputHolder.getOutput(sessionId);
} }
/** /**

View File

@ -1,4 +1,5 @@
import { IItemEventRouterBase } from "@spt-aki/models/eft/itemEvent/IItemEventRouterBase"; import { IItemEventRouterBase } from "@spt-aki/models/eft/itemEvent/IItemEventRouterBase";
/** An object sent back to the game client that contains alterations the client must make to ensure server/client are in sync */
export interface IItemEventRouterResponse extends IItemEventRouterBase export interface IItemEventRouterResponse extends IItemEventRouterBase
{} {}

View File

@ -37,14 +37,15 @@ export class HideoutItemEventRouter extends ItemEventRouterDefinition
pmcData: IPmcData, pmcData: IPmcData,
body: any, body: any,
sessionID: string, sessionID: string,
output: IItemEventRouterResponse,
): IItemEventRouterResponse ): IItemEventRouterResponse
{ {
switch (url) switch (url)
{ {
case HideoutEventActions.HIDEOUT_UPGRADE: case HideoutEventActions.HIDEOUT_UPGRADE:
return this.hideoutCallbacks.upgrade(pmcData, body, sessionID); return this.hideoutCallbacks.upgrade(pmcData, body, sessionID, output);
case HideoutEventActions.HIDEOUT_UPGRADE_COMPLETE: case HideoutEventActions.HIDEOUT_UPGRADE_COMPLETE:
return this.hideoutCallbacks.upgradeComplete(pmcData, body, sessionID); return this.hideoutCallbacks.upgradeComplete(pmcData, body, sessionID, output);
case HideoutEventActions.HIDEOUT_PUT_ITEMS_IN_AREA_SLOTS: case HideoutEventActions.HIDEOUT_PUT_ITEMS_IN_AREA_SLOTS:
return this.hideoutCallbacks.putItemsInAreaSlots(pmcData, body, sessionID); return this.hideoutCallbacks.putItemsInAreaSlots(pmcData, body, sessionID);
case HideoutEventActions.HIDEOUT_TAKE_ITEMS_FROM_AREA_SLOTS: case HideoutEventActions.HIDEOUT_TAKE_ITEMS_FROM_AREA_SLOTS:
@ -60,11 +61,13 @@ export class HideoutItemEventRouter extends ItemEventRouterDefinition
case HideoutEventActions.HIDEOUT_TAKE_PRODUCTION: case HideoutEventActions.HIDEOUT_TAKE_PRODUCTION:
return this.hideoutCallbacks.takeProduction(pmcData, body, sessionID); return this.hideoutCallbacks.takeProduction(pmcData, body, sessionID);
case HideoutEventActions.HIDEOUT_RECORD_SHOOTING_RANGE_POINTS: case HideoutEventActions.HIDEOUT_RECORD_SHOOTING_RANGE_POINTS:
return this.hideoutCallbacks.recordShootingRangePoints(pmcData, body, sessionID); return this.hideoutCallbacks.recordShootingRangePoints(pmcData, body, sessionID, output);
case HideoutEventActions.HIDEOUT_IMPROVE_AREA: case HideoutEventActions.HIDEOUT_IMPROVE_AREA:
return this.hideoutCallbacks.improveArea(pmcData, body, sessionID); return this.hideoutCallbacks.improveArea(pmcData, body, sessionID);
case HideoutEventActions.HIDEOUT_CANCEL_PRODUCTION_COMMAND: case HideoutEventActions.HIDEOUT_CANCEL_PRODUCTION_COMMAND:
return this.hideoutCallbacks.cancelProduction(pmcData, body, sessionID); return this.hideoutCallbacks.cancelProduction(pmcData, body, sessionID);
default:
throw new Error(`Unhandled event ${url} request: ${JSON.stringify(body)}`);
} }
} }
} }