Server/project/src/services/RagfairRequiredItemsService.ts

54 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-03-03 16:23:46 +01:00
import { inject, injectable } from "tsyringe";
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,
@inject("RagfairOfferService") protected ragfairOfferService: RagfairOfferService,
2023-03-03 16:23:46 +01:00
)
{}
2023-03-03 16:23:46 +01:00
public getRequiredItemsById(searchId: string): any
{
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;
}
}