0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00
server/project/src/services/RagfairRequiredItemsService.ts
Refringe 50c7a26a58
ESLint Pass
This is the first pass of ESLint on the codebase.

ESLint formatting is less strict when it comes to line-length and line-breaks then dprint/biome, so if you see formatting that you don't like... fix it! It shouldn't require a configuration change.

- This should merge clean into master (when the time comes).
- This will not merge clean into `3.9.0-DEV`, but the conflicts aren't that bad.
2024-05-07 23:57:08 -04:00

54 lines
1.6 KiB
TypeScript

import { inject, injectable } from "tsyringe";
import { PaymentHelper } from "@spt-aki/helpers/PaymentHelper";
import { IRagfairOffer } from "@spt-aki/models/eft/ragfair/IRagfairOffer";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { RagfairOfferService } from "@spt-aki/services/RagfairOfferService";
@injectable()
export class RagfairRequiredItemsService
{
protected requiredItemsCache = {};
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("PaymentHelper") protected paymentHelper: PaymentHelper,
@inject("RagfairOfferService") protected ragfairOfferService: RagfairOfferService,
)
{}
public getRequiredItemsById(searchId: string): IRagfairOffer[]
{
return Array.from(this.requiredItemsCache[searchId] ?? {}) || [];
}
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;
}
}