2023-03-03 16:23:46 +01:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 19:21:17 +02:00
|
|
|
import { PaymentHelper } from "@spt-aki/helpers/PaymentHelper";
|
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
|
|
import { RagfairOfferService } from "@spt-aki/services/RagfairOfferService";
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class RagfairRequiredItemsService
|
|
|
|
{
|
|
|
|
protected requiredItemsCache = {};
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@inject("WinstonLogger") protected logger: ILogger,
|
|
|
|
@inject("PaymentHelper") protected paymentHelper: PaymentHelper,
|
2023-11-16 22:42:06 +01:00
|
|
|
@inject("RagfairOfferService") protected ragfairOfferService: RagfairOfferService,
|
2023-03-03 16:23:46 +01:00
|
|
|
)
|
2023-11-16 22:42:06 +01:00
|
|
|
{}
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
public getRequiredItemsById(searchId: string): any
|
|
|
|
{
|
2023-03-22 15:31:05 +01:00
|
|
|
return this.requiredItemsCache[searchId] || [];
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public buildRequiredItemTable(): void
|
|
|
|
{
|
|
|
|
const requiredItems = {};
|
|
|
|
const getRequiredItems = (id: string) =>
|
|
|
|
{
|
|
|
|
if (!(id in requiredItems))
|
|
|
|
{
|
|
|
|
requiredItems[id] = new Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
return requiredItems[id];
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const offer of this.ragfairOfferService.getOffers())
|
|
|
|
{
|
|
|
|
for (const requirement of offer.requirements)
|
|
|
|
{
|
|
|
|
if (this.paymentHelper.isMoneyTpl(requirement._tpl))
|
|
|
|
{
|
|
|
|
// This would just be too noisy.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
getRequiredItems(requirement._tpl).add(offer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.requiredItemsCache = requiredItems;
|
|
|
|
}
|
2023-11-16 22:42:06 +01:00
|
|
|
}
|