using System.Collections.Concurrent; using SPTarkov.DI.Annotations; using SPTarkov.Server.Core.Helpers; using SPTarkov.Server.Core.Models.Common; namespace SPTarkov.Server.Core.Services; [Injectable(InjectionType.Singleton)] public class RagfairRequiredItemsService(RagfairOfferService ragfairOfferService, PaymentHelper paymentHelper) { /// /// Key = tpl /// protected readonly ConcurrentDictionary> _requiredItemsCache = new(); /// /// Get the offerId of offers that require the supplied tpl /// /// Tpl to find offers ids for /// public HashSet GetRequiredOffersById(MongoId tpl) { if (_requiredItemsCache.TryGetValue(tpl, out var offerIds)) { return offerIds; } return []; } /// /// Create a cache of requirements to purchase item /// public void BuildRequiredItemTable() { _requiredItemsCache.Clear(); foreach (var offer in ragfairOfferService.GetOffers()) foreach (var requirement in offer.Requirements) { if (paymentHelper.IsMoneyTpl(requirement.TemplateId)) // This would just be too noisy { continue; } // Ensure key is init _requiredItemsCache.TryAdd(requirement.TemplateId, []); // Add matching offer _requiredItemsCache.GetValueOrDefault(requirement.TemplateId)?.Add(offer.Id); } } }