2023-03-03 16:23:46 +01:00
|
|
|
import { inject, injectable } from "tsyringe";
|
2024-05-21 19:59:04 +02:00
|
|
|
import { RagfairController } from "@spt/controllers/RagfairController";
|
|
|
|
import { OnLoad } from "@spt/di/OnLoad";
|
|
|
|
import { OnUpdate } from "@spt/di/OnUpdate";
|
|
|
|
import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData";
|
|
|
|
import { IPmcData } from "@spt/models/eft/common/IPmcData";
|
|
|
|
import { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData";
|
|
|
|
import { INullResponseData } from "@spt/models/eft/httpResponse/INullResponseData";
|
|
|
|
import { IItemEventRouterResponse } from "@spt/models/eft/itemEvent/IItemEventRouterResponse";
|
|
|
|
import { IAddOfferRequestData } from "@spt/models/eft/ragfair/IAddOfferRequestData";
|
|
|
|
import { IExtendOfferRequestData } from "@spt/models/eft/ragfair/IExtendOfferRequestData";
|
|
|
|
import { IGetItemPriceResult } from "@spt/models/eft/ragfair/IGetItemPriceResult";
|
|
|
|
import { IGetMarketPriceRequestData } from "@spt/models/eft/ragfair/IGetMarketPriceRequestData";
|
|
|
|
import { IGetOffersResult } from "@spt/models/eft/ragfair/IGetOffersResult";
|
|
|
|
import { IGetRagfairOfferByIdRequest } from "@spt/models/eft/ragfair/IGetRagfairOfferByIdRequest";
|
|
|
|
import { IRagfairOffer } from "@spt/models/eft/ragfair/IRagfairOffer";
|
|
|
|
import { IRemoveOfferRequestData } from "@spt/models/eft/ragfair/IRemoveOfferRequestData";
|
|
|
|
import { ISearchRequestData } from "@spt/models/eft/ragfair/ISearchRequestData";
|
|
|
|
import { ISendRagfairReportRequestData } from "@spt/models/eft/ragfair/ISendRagfairReportRequestData";
|
|
|
|
import { IStorePlayerOfferTaxAmountRequestData } from "@spt/models/eft/ragfair/IStorePlayerOfferTaxAmountRequestData";
|
|
|
|
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
|
|
|
|
import { IRagfairConfig } from "@spt/models/spt/config/IRagfairConfig";
|
|
|
|
import { ConfigServer } from "@spt/servers/ConfigServer";
|
|
|
|
import { RagfairServer } from "@spt/servers/RagfairServer";
|
|
|
|
import { RagfairTaxService } from "@spt/services/RagfairTaxService";
|
|
|
|
import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil";
|
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("RagfairServer") protected ragfairServer: RagfairServer,
|
|
|
|
@inject("RagfairController") protected ragfairController: RagfairController,
|
2023-10-10 13:03:20 +02:00
|
|
|
@inject("RagfairTaxService") protected ragfairTaxService: RagfairTaxService,
|
2023-11-10 21:19:56 +01:00
|
|
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
2023-03-03 16:23:46 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
this.ragfairConfig = this.configServer.getConfig(ConfigTypes.RAGFAIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async onLoad(): Promise<void>
|
|
|
|
{
|
|
|
|
await this.ragfairServer.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
public getRoute(): string
|
|
|
|
{
|
2024-05-21 19:59:04 +02:00
|
|
|
return "spt-ragfair";
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
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();
|
2023-12-18 23:32:46 +01:00
|
|
|
|
|
|
|
// Check player offers and mail payment to player if sold
|
2023-07-15 15:49:25 +02:00
|
|
|
this.ragfairController.update();
|
|
|
|
|
2023-12-18 23:32:46 +01:00
|
|
|
// Process all offers / expire offers
|
|
|
|
await this.ragfairServer.update();
|
2024-02-02 19:54:07 +01:00
|
|
|
|
2023-07-15 15:49:25 +02:00
|
|
|
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-11-10 21:19:56 +01:00
|
|
|
public getMarketPrice(
|
|
|
|
url: string,
|
|
|
|
info: IGetMarketPriceRequestData,
|
|
|
|
sessionID: string,
|
|
|
|
): IGetBodyResponseData<IGetItemPriceResult>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
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-11-10 21:19:56 +01:00
|
|
|
/** Handle RagFairRemoveOffer event */
|
2023-03-03 16:23:46 +01:00
|
|
|
public removeOffer(pmcData: IPmcData, info: IRemoveOfferRequestData, sessionID: string): IItemEventRouterResponse
|
|
|
|
{
|
2024-01-26 11:49:06 +01:00
|
|
|
return this.ragfairController.removeOffer(info, sessionID);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2023-11-10 21:19:56 +01:00
|
|
|
public getFleaPrices(
|
|
|
|
url: string,
|
|
|
|
request: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
|
|
|
): IGetBodyResponseData<Record<string, number>>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
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
|
|
|
public sendReport(url: string, info: ISendRagfairReportRequestData, sessionID: string): INullResponseData
|
|
|
|
{
|
|
|
|
return this.httpResponse.nullResponse();
|
|
|
|
}
|
|
|
|
|
2023-11-10 21:19:56 +01:00
|
|
|
public storePlayerOfferTaxAmount(
|
|
|
|
url: string,
|
|
|
|
request: IStorePlayerOfferTaxAmountRequestData,
|
|
|
|
sessionId: string,
|
|
|
|
): INullResponseData
|
2023-10-10 13:03:20 +02:00
|
|
|
{
|
|
|
|
this.ragfairTaxService.storeClientOfferTaxValue(sessionId, request);
|
|
|
|
return this.httpResponse.nullResponse();
|
|
|
|
}
|
2023-12-20 00:52:39 +01:00
|
|
|
|
|
|
|
/** Handle client/ragfair/offer/findbyid */
|
2024-02-02 19:54:07 +01:00
|
|
|
public getFleaOfferById(
|
|
|
|
url: string,
|
|
|
|
request: IGetRagfairOfferByIdRequest,
|
|
|
|
sessionID: string,
|
|
|
|
): IGetBodyResponseData<IRagfairOffer>
|
2023-12-20 00:52:39 +01:00
|
|
|
{
|
|
|
|
return this.httpResponse.getBody(this.ragfairController.getOfferById(sessionID, request));
|
|
|
|
}
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|