2024-05-21 17:59:04 +00:00
|
|
|
import { TraderController } from "@spt/controllers/TraderController";
|
|
|
|
import { OnLoad } from "@spt/di/OnLoad";
|
|
|
|
import { OnUpdate } from "@spt/di/OnUpdate";
|
|
|
|
import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData";
|
|
|
|
import { ITraderAssort, ITraderBase } from "@spt/models/eft/common/tables/ITrader";
|
|
|
|
import { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData";
|
2024-09-04 08:31:15 +00:00
|
|
|
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
|
2024-10-19 12:43:38 +01:00
|
|
|
import { IModdedTraders, ITraderConfig } from "@spt/models/spt/config/ITraderConfig";
|
2024-09-04 08:31:15 +00:00
|
|
|
import { ConfigServer } from "@spt/servers/ConfigServer";
|
2024-05-21 17:59:04 +00:00
|
|
|
import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil";
|
2024-07-23 11:12:53 -04:00
|
|
|
import { inject, injectable } from "tsyringe";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
@injectable()
|
2024-07-23 11:12:53 -04:00
|
|
|
export class TraderCallbacks implements OnLoad, OnUpdate {
|
2023-03-03 15:23:46 +00:00
|
|
|
constructor(
|
2023-11-10 15:19:56 -05:00
|
|
|
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil, // TODO: delay required
|
|
|
|
@inject("TraderController") protected traderController: TraderController,
|
2024-09-04 08:31:15 +00:00
|
|
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
2024-07-23 11:12:53 -04:00
|
|
|
) {}
|
2023-11-10 15:19:56 -05:00
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
public async onLoad(): Promise<void> {
|
2023-03-03 15:23:46 +00:00
|
|
|
this.traderController.load();
|
|
|
|
}
|
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
public async onUpdate(): Promise<boolean> {
|
2023-03-03 15:23:46 +00:00
|
|
|
return this.traderController.update();
|
|
|
|
}
|
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
public getRoute(): string {
|
2024-05-21 17:59:04 +00:00
|
|
|
return "spt-traders";
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 14:49:25 +01:00
|
|
|
/** Handle client/trading/api/traderSettings */
|
2023-11-10 15:19:56 -05:00
|
|
|
public getTraderSettings(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
2024-07-23 11:12:53 -04:00
|
|
|
): IGetBodyResponseData<ITraderBase[]> {
|
2023-03-03 15:23:46 +00:00
|
|
|
return this.httpResponse.getBody(this.traderController.getAllTraders(sessionID));
|
|
|
|
}
|
|
|
|
|
2023-07-15 14:49:25 +01:00
|
|
|
/** Handle client/trading/api/getTrader */
|
2024-07-23 11:12:53 -04:00
|
|
|
public getTrader(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<ITraderBase> {
|
2023-03-03 15:23:46 +00:00
|
|
|
const traderID = url.replace("/client/trading/api/getTrader/", "");
|
|
|
|
return this.httpResponse.getBody(this.traderController.getTrader(sessionID, traderID));
|
|
|
|
}
|
|
|
|
|
2023-07-15 14:49:25 +01:00
|
|
|
/** Handle client/trading/api/getTraderAssort */
|
2024-07-23 11:12:53 -04:00
|
|
|
public getAssort(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<ITraderAssort> {
|
2023-03-03 15:23:46 +00:00
|
|
|
const traderID = url.replace("/client/trading/api/getTraderAssort/", "");
|
|
|
|
return this.httpResponse.getBody(this.traderController.getAssort(sessionID, traderID));
|
|
|
|
}
|
2024-09-04 08:31:15 +00:00
|
|
|
|
|
|
|
/** Handle /singleplayer/moddedTraders */
|
|
|
|
public getModdedTraderData(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
2024-10-19 12:43:38 +01:00
|
|
|
): IGetBodyResponseData<IModdedTraders> {
|
2024-09-04 08:31:15 +00:00
|
|
|
const traderConfig = this.configServer.getConfig(ConfigTypes.TRADER) as ITraderConfig;
|
|
|
|
return this.httpResponse.noBody(traderConfig.moddedTraders);
|
|
|
|
}
|
2023-11-10 15:19:56 -05:00
|
|
|
}
|