Implemented RagfairCategoriesService
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
using SptCommon.Annotations;
|
||||
using Core.Helpers;
|
||||
using Core.Models.Eft.Ragfair;
|
||||
using Core.Models.Enums;
|
||||
using Core.Models.Utils;
|
||||
using SptCommon.Annotations;
|
||||
|
||||
namespace Core.Services;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class RagfairCategoriesService
|
||||
public class RagfairCategoriesService(
|
||||
ISptLogger<RagfairCategoriesService> _logger,
|
||||
PaymentHelper _paymentHelper
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
/// Get a dictionary of each item the play can see in their flea menu, filtered by what is available for them to buy
|
||||
/// Get a dictionary of each item the play can see in their flea menu, filtered by what is available for them to buy
|
||||
/// </summary>
|
||||
/// <param name="offers">All offers in flea</param>
|
||||
/// <param name="searchRequestData">Search criteria requested</param>
|
||||
@@ -18,6 +24,47 @@ public class RagfairCategoriesService
|
||||
SearchRequestData searchRequestData,
|
||||
bool fleaUnlocked)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// Get offers valid for search request, then reduce them down to just the counts
|
||||
var results = new Dictionary<string, int>();
|
||||
return offers
|
||||
.Where(
|
||||
offer =>
|
||||
{
|
||||
var isTraderOffer = offer.User.MemberType == MemberCategory.TRADER;
|
||||
|
||||
// Not level 15 and offer is from player, skip
|
||||
if (!fleaUnlocked || !isTraderOffer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip items not for currency when `removeBartering` is enabled
|
||||
if (
|
||||
searchRequestData.RemoveBartering.GetValueOrDefault(false) &&
|
||||
(offer.Requirements.Count > 1 ||
|
||||
!_paymentHelper.IsMoneyTpl(offer.Requirements.FirstOrDefault().Template))
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove when filter set to players only + offer is from trader
|
||||
if (searchRequestData.OfferOwnerType == OfferOwnerType.PLAYEROWNERTYPE && isTraderOffer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove when filter set to traders only + offer is not from trader
|
||||
if (searchRequestData.OfferOwnerType == OfferOwnerType.TRADEROWNERTYPE && !isTraderOffer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Passed checks, it's a valid offer to process
|
||||
return true;
|
||||
}
|
||||
)
|
||||
.GroupBy(x => x.Items.FirstOrDefault().Template)
|
||||
.ToDictionary(group => group.Key, group => group.Count());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user