Server/project/src/callbacks/RagfairCallbacks.ts

132 lines
5.6 KiB
TypeScript
Raw Normal View History

2023-03-03 16:23:46 +01:00
import { inject, injectable } from "tsyringe";
import { RagfairController } from "@spt-aki/controllers/RagfairController";
import { OnLoad } from "@spt-aki/di/OnLoad";
import { OnUpdate } from "@spt-aki/di/OnUpdate";
import { IEmptyRequestData } from "@spt-aki/models/eft/common/IEmptyRequestData";
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
import { IGetBodyResponseData } from "@spt-aki/models/eft/httpResponse/IGetBodyResponseData";
import { INullResponseData } from "@spt-aki/models/eft/httpResponse/INullResponseData";
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
import { IAddOfferRequestData } from "@spt-aki/models/eft/ragfair/IAddOfferRequestData";
import { IExtendOfferRequestData } from "@spt-aki/models/eft/ragfair/IExtendOfferRequestData";
import { IGetItemPriceResult } from "@spt-aki/models/eft/ragfair/IGetItemPriceResult";
import { IGetMarketPriceRequestData } from "@spt-aki/models/eft/ragfair/IGetMarketPriceRequestData";
import { IGetOffersResult } from "@spt-aki/models/eft/ragfair/IGetOffersResult";
import { IRemoveOfferRequestData } from "@spt-aki/models/eft/ragfair/IRemoveOfferRequestData";
import { ISearchRequestData } from "@spt-aki/models/eft/ragfair/ISearchRequestData";
import { ISendRagfairReportRequestData } from "@spt-aki/models/eft/ragfair/ISendRagfairReportRequestData";
import { IStorePlayerOfferTaxAmountRequestData } from "@spt-aki/models/eft/ragfair/IStorePlayerOfferTaxAmountRequestData";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { IRagfairConfig } from "@spt-aki/models/spt/config/IRagfairConfig";
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
import { RagfairServer } from "@spt-aki/servers/RagfairServer";
import { RagfairTaxService } from "@spt-aki/services/RagfairTaxService";
import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil";
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
2023-03-03 16:23:46 +01:00
/**
* Handle ragfair related callback events
*/
@injectable()
export class RagfairCallbacks implements OnLoad, OnUpdate
{
protected ragfairConfig: IRagfairConfig;
constructor(
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
@inject("JsonUtil") protected jsonUtil: JsonUtil,
@inject("RagfairServer") protected ragfairServer: RagfairServer,
@inject("RagfairController") protected ragfairController: RagfairController,
@inject("RagfairTaxService") protected ragfairTaxService: RagfairTaxService,
2023-03-03 16:23:46 +01:00
@inject("ConfigServer") protected configServer: ConfigServer
)
{
this.ragfairConfig = this.configServer.getConfig(ConfigTypes.RAGFAIR);
}
public async onLoad(): Promise<void>
{
await this.ragfairServer.load();
}
public getRoute(): string
{
return "aki-ragfair";
}
2023-07-15 15:49:25 +02:00
public async onUpdate(timeSinceLastRun: number): Promise<boolean>
{
if (timeSinceLastRun > this.ragfairConfig.runIntervalSeconds)
{
// There is a flag inside this class that only makes it run once.
this.ragfairServer.addPlayerOffers();
await this.ragfairServer.update();
// function below used to be split, merged
this.ragfairController.update();
return true;
}
return false;
}
/**
* Handle client/ragfair/search
* Handle client/ragfair/find
*/
2023-03-03 16:23:46 +01:00
public search(url: string, info: ISearchRequestData, sessionID: string): IGetBodyResponseData<IGetOffersResult>
{
return this.httpResponse.getBody(this.ragfairController.getOffers(sessionID, info));
}
2023-07-15 15:49:25 +02:00
/** Handle client/ragfair/itemMarketPrice */
2023-03-03 16:23:46 +01:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public getMarketPrice(url: string, info: IGetMarketPriceRequestData, sessionID: string): IGetBodyResponseData<IGetItemPriceResult>
{
return this.httpResponse.getBody(this.ragfairController.getItemMinAvgMaxFleaPriceValues(info));
}
2023-07-15 15:49:25 +02:00
/** Handle RagFairAddOffer event */
2023-03-03 16:23:46 +01:00
public addOffer(pmcData: IPmcData, info: IAddOfferRequestData, sessionID: string): IItemEventRouterResponse
{
return this.ragfairController.addPlayerOffer(pmcData, info, sessionID);
}
2023-07-15 15:49:25 +02:00
/** \Handle RagFairRemoveOffer event */
2023-03-03 16:23:46 +01:00
public removeOffer(pmcData: IPmcData, info: IRemoveOfferRequestData, sessionID: string): IItemEventRouterResponse
{
return this.ragfairController.removeOffer(info.offerId, sessionID);
}
2023-07-15 15:49:25 +02:00
/** Handle RagFairRenewOffer event */
2023-03-03 16:23:46 +01:00
public extendOffer(pmcData: IPmcData, info: IExtendOfferRequestData, sessionID: string): IItemEventRouterResponse
{
return this.ragfairController.extendOffer(info, sessionID);
}
/**
* Handle /client/items/prices
* Called when clicking an item to list on flea
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public getFleaPrices(url: string, request: IEmptyRequestData, sessionID: string): IGetBodyResponseData<Record<string, number>>
{
return this.httpResponse.getBody(this.ragfairController.getAllFleaPrices());
}
2023-07-15 15:49:25 +02:00
/** Handle client/reports/ragfair/send */
2023-03-03 16:23:46 +01:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public sendReport(url: string, info: ISendRagfairReportRequestData, sessionID: string): INullResponseData
{
return this.httpResponse.nullResponse();
}
public storePlayerOfferTaxAmount(url: string, request: IStorePlayerOfferTaxAmountRequestData, sessionId: string): INullResponseData
{
this.ragfairTaxService.storeClientOfferTaxValue(sessionId, request);
return this.httpResponse.nullResponse();
}
2023-03-03 16:23:46 +01:00
}