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

View File

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