Added TraderAssortExtensions
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
||||
|
||||
namespace SPTarkov.Server.Core.Extensions
|
||||
{
|
||||
public static class TraderAssortExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Remove an item from an assort
|
||||
/// Must be removed from the assorts; items + barterScheme + LoyaltyLevel
|
||||
/// </summary>
|
||||
/// <param name="assort">Assort to remove item from</param>
|
||||
/// <param name="itemId">Id of item to remove from assort</param>
|
||||
/// <param name="isFlea">Is the assort being modified the flea market assort</param>
|
||||
/// <returns>Modified assort</returns>
|
||||
public static TraderAssort RemoveItemFromAssort(
|
||||
this TraderAssort assort,
|
||||
string itemId,
|
||||
bool isFlea = false
|
||||
)
|
||||
{
|
||||
// Flea assort needs special handling, item must remain in assort but be flagged as locked
|
||||
if (isFlea && assort.BarterScheme.TryGetValue(itemId, out var listToUse))
|
||||
{
|
||||
foreach (var barterScheme in listToUse.SelectMany(barterSchemes => barterSchemes))
|
||||
{
|
||||
barterScheme.SptQuestLocked = true;
|
||||
}
|
||||
|
||||
return assort;
|
||||
}
|
||||
|
||||
assort.BarterScheme.Remove(itemId);
|
||||
assort.LoyalLevelItems.Remove(itemId);
|
||||
|
||||
// The item being removed may have children linked to it, find and remove them too
|
||||
var idsToRemove = assort.Items.FindAndReturnChildrenByItems(itemId);
|
||||
assort.Items.RemoveAll(item => idsToRemove.Contains(item.Id));
|
||||
|
||||
return assort;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given the blacklist provided, remove root items from assort
|
||||
/// </summary>
|
||||
/// <param name="assortToFilter">Trader assort to modify</param>
|
||||
/// <param name="itemsTplsToRemove">Item TPLs the assort should not have</param>
|
||||
public static void RemoveItemsFromAssort(
|
||||
this TraderAssort assortToFilter,
|
||||
HashSet<string> itemsTplsToRemove
|
||||
)
|
||||
{
|
||||
assortToFilter.Items = assortToFilter
|
||||
.Items.Where(item =>
|
||||
item.ParentId == "hideout" && itemsTplsToRemove.Contains(item.Template)
|
||||
)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class AssortHelper(
|
||||
);
|
||||
if (!unlockValues.Value.Value.Contains(questStatusInProfile))
|
||||
{
|
||||
strippedTraderAssorts = RemoveItemFromAssort(traderAssorts, assortId.Key, isFlea);
|
||||
strippedTraderAssorts = traderAssorts.RemoveItemFromAssort(assortId.Key, isFlea);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,45 +147,10 @@ public class AssortHelper(
|
||||
&& assort.LoyalLevelItems[item.Key] > info.LoyaltyLevel
|
||||
)
|
||||
{
|
||||
strippedAssort = RemoveItemFromAssort(assort, item.Key);
|
||||
strippedAssort = assort.RemoveItemFromAssort(item.Key);
|
||||
}
|
||||
}
|
||||
|
||||
return strippedAssort;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove an item from an assort
|
||||
/// Must be removed from the assorts; items + barterScheme + LoyaltyLevel
|
||||
/// </summary>
|
||||
/// <param name="assort">Assort to remove item from</param>
|
||||
/// <param name="itemId">Id of item to remove from assort</param>
|
||||
/// <param name="isFlea">Is the assort being modified the flea market assort</param>
|
||||
/// <returns>Modified assort</returns>
|
||||
public TraderAssort RemoveItemFromAssort(
|
||||
TraderAssort assort,
|
||||
string itemId,
|
||||
bool isFlea = false
|
||||
)
|
||||
{
|
||||
// Flea assort needs special handling, item must remain in assort but be flagged as locked
|
||||
if (isFlea && assort.BarterScheme.TryGetValue(itemId, out var listToUse))
|
||||
{
|
||||
foreach (var barterScheme in listToUse.SelectMany(barterSchemes => barterSchemes))
|
||||
{
|
||||
barterScheme.SptQuestLocked = true;
|
||||
}
|
||||
|
||||
return assort;
|
||||
}
|
||||
|
||||
assort.BarterScheme.Remove(itemId);
|
||||
assort.LoyalLevelItems.Remove(itemId);
|
||||
|
||||
// The item being removed may have children linked to it, find and remove them too
|
||||
var idsToRemove = assort.Items.FindAndReturnChildrenByItems(itemId);
|
||||
assort.Items.RemoveAll(item => idsToRemove.Contains(item.Id));
|
||||
|
||||
return assort;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.Extensions;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
||||
using SPTarkov.Server.Core.Models.Enums;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
@@ -90,7 +91,7 @@ public class TraderAssortHelper(
|
||||
if (_logger.IsLogEnabled(LogLevel.Debug))
|
||||
{
|
||||
_logger.Debug(
|
||||
$"Unable to adjust assort {assortToAdjust.Id} item: {assortToAdjust.Template} BuyRestrictionCurrent value, assort has a null upd object"
|
||||
$"Unable to adjust assort: {assortToAdjust.Id} item: {assortToAdjust.Template} BuyRestrictionCurrent value, assort has a null upd object"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -113,29 +114,12 @@ public class TraderAssortHelper(
|
||||
// Filter out root assorts that are blacklisted for this profile
|
||||
if (fullProfile.SptData.BlacklistedItemTemplates?.Count > 0)
|
||||
{
|
||||
RemoveItemsFromAssort(traderClone.Assort, fullProfile.SptData.BlacklistedItemTemplates);
|
||||
traderClone.Assort.RemoveItemsFromAssort(fullProfile.SptData.BlacklistedItemTemplates);
|
||||
}
|
||||
|
||||
return traderClone.Assort;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given the blacklist provided, remove root items from assort
|
||||
/// </summary>
|
||||
/// <param name="assortToFilter">Trader assort to modify</param>
|
||||
/// <param name="itemsTplsToRemove">Item TPLs the assort should not have</param>
|
||||
protected void RemoveItemsFromAssort(
|
||||
TraderAssort assortToFilter,
|
||||
HashSet<string> itemsTplsToRemove
|
||||
)
|
||||
{
|
||||
assortToFilter.Items = assortToFilter
|
||||
.Items.Where(item =>
|
||||
item.ParentId == "hideout" && itemsTplsToRemove.Contains(item.Template)
|
||||
)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset every traders root item `BuyRestrictionCurrent` property to 0
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user