Converted more strings to mongoIds and fixed issue with buying items from pmcs on flea

This commit is contained in:
Chomp
2025-07-07 11:56:19 +01:00
parent 7ccb388030
commit 61f62f191d
18 changed files with 47 additions and 46 deletions
@@ -179,7 +179,7 @@ public class InventoryController(
/// <param name="pmcData">Players PMC profile</param>
/// <param name="request"></param>
/// <param name="sessionId">Session/Player id</param>
public void SetFavoriteItem(PmcData pmcData, SetFavoriteItems request, string sessionId)
public void SetFavoriteItem(PmcData pmcData, SetFavoriteItems request, MongoId sessionId)
{
// The client sends the full list of favorite items, so clear the current favorites
pmcData.Inventory.FavoriteItems = [];
@@ -989,7 +989,7 @@ public class RagfairController(
/// <param name="sellInOnePiece">Is this a pack offer</param>
/// <returns>RagfairOffer</returns>
protected RagfairOffer CreatePlayerOffer(
string sessionId,
MongoId sessionId,
List<Requirement> requirements,
List<Item> items,
bool sellInOnePiece
@@ -1272,7 +1272,7 @@ public class RagfairController(
return ragfairPriceService.GetAllStaticPrices();
}
public RagfairOffer? GetOfferByInternalId(string sessionId, GetRagfairOfferByIdRequest request)
public RagfairOffer? GetOfferByInternalId(MongoId sessionId, GetRagfairOfferByIdRequest request)
{
var offers = ragfairOfferService.GetOffers();
var offerToReturn = offers.FirstOrDefault(offer => offer.InternalId == request.Id);
@@ -422,7 +422,7 @@ public class RepeatableQuestController(
public RepeatableQuest? PickAndGenerateRandomRepeatableQuest(
MongoId sessionId,
int pmcLevel,
Dictionary<string, TraderInfo> pmcTraderInfo,
Dictionary<MongoId, TraderInfo> pmcTraderInfo,
QuestTypePool questTypePool,
RepeatableQuestConfig repeatableConfig
)
@@ -1,4 +1,5 @@
using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Enums;
namespace SPTarkov.Server.Core.Extensions
{
@@ -9,7 +10,7 @@ namespace SPTarkov.Server.Core.Extensions
/// </summary>
/// <param name="currency"></param>
/// <returns>Tpl of currency</returns>
public static string GetCurrencyTpl(this CurrencyType currency)
public static MongoId GetCurrencyTpl(this CurrencyType currency)
{
return currency switch
{
@@ -1,4 +1,5 @@
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Eft.ItemEvent;
namespace SPTarkov.Server.Core.Extensions
@@ -13,10 +14,11 @@ namespace SPTarkov.Server.Core.Extensions
/// <param name="item">Item that was adjusted</param>
public static void AddItemStackSizeChangeIntoEventResponse(
this ItemEventRouterResponse output,
string sessionId,
MongoId sessionId,
Item item
)
{
// TODO: replace with something safer like TryGet
output
.ProfileChanges[sessionId]
.Items.ChangedItems.Add(
@@ -60,7 +60,7 @@ public class RagfairOfferGenerator(
/// <param name="sellInOnePiece">Flags sellInOnePiece to be true</param>
/// <returns>RagfairOffer</returns>
public RagfairOffer CreateAndAddFleaOffer(
string userId,
MongoId userId,
long time,
List<Item> items,
List<BarterScheme> barterScheme,
@@ -95,7 +95,7 @@ public class RagfairOfferGenerator(
/// <param name="isPackOffer">Is offer being created flagged as a pack</param>
/// <returns>RagfairOffer</returns>
protected RagfairOffer CreateOffer(
string userId,
MongoId userId,
long time,
List<Item> items,
List<BarterScheme> barterScheme,
@@ -177,7 +177,7 @@ public class RagfairOfferGenerator(
/// <param name="userId">User creating the offer</param>
/// <param name="isTrader">Is the user creating the offer a trader</param>
/// <returns>RagfairOfferUser</returns>
protected RagfairOfferUser CreateUserDataForFleaOffer(string userId, bool isTrader)
protected RagfairOfferUser CreateUserDataForFleaOffer(MongoId userId, bool isTrader)
{
// Trader offer
if (isTrader)
@@ -191,7 +191,7 @@ public class RagfairOfferGenerator(
var playerProfile = profileHelper.GetPmcProfile(userId);
return new RagfairOfferUser
{
Id = playerProfile.Id,
Id = playerProfile.Id.Value,
MemberType = playerProfile.Info.MemberCategory,
SelectedMemberCategory = playerProfile.Info.SelectedMemberCategory,
Nickname = playerProfile.Info.Nickname,
@@ -39,6 +39,7 @@ public class InventoryHelper(
BaseClasses.FUNCTIONAL_MOD,
BaseClasses.MOD,
];
protected readonly InventoryConfig _inventoryConfig = configServer.GetConfig<InventoryConfig>();
/// <summary>
@@ -213,7 +214,7 @@ public class InventoryHelper(
/// <param name="sessionId">Player id</param>
/// <param name="itemsWithChildren">Array of items with children to try and fit</param>
/// <returns>True all items fit</returns>
public bool CanPlaceItemsInInventory(string sessionId, List<List<Item>> itemsWithChildren)
public bool CanPlaceItemsInInventory(MongoId sessionId, List<List<Item>> itemsWithChildren)
{
var pmcData = profileHelper.GetPmcProfile(sessionId);
@@ -63,8 +63,8 @@ public class NotifierHelper(HttpServerHelper httpServerHelper)
};
}
public string GetWebSocketServer(string sessionId)
public string GetWebSocketServer(MongoId sessionId)
{
return $"{httpServerHelper.GetWebsocketUrl()}/notifierServer/getwebsocket/{sessionId}";
return $"{httpServerHelper.GetWebsocketUrl()}/notifierServer/getwebsocket/{sessionId.ToString()}";
}
}
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Models.Common;
@@ -29,7 +30,7 @@ public class TraderHelper(
ConfigServer configServer
)
{
protected readonly List<string> _gameVersions =
protected readonly FrozenSet<string> _gameVersionsWithHigherBuyRestrictions =
[
GameEditions.EDGE_OF_DARKNESS,
GameEditions.UNHEARD,
@@ -37,6 +38,11 @@ public class TraderHelper(
protected readonly Dictionary<string, double> _highestTraderPriceItems = new();
protected readonly TraderConfig _traderConfig = configServer.GetConfig<TraderConfig>();
/// <summary>
/// Get a traders base data from its nickname, case insensitive
/// </summary>
/// <param name="traderName">Nickname of trader, e.g. prapor</param>
/// <returns>TraderBase</returns>
public TraderBase? GetTraderByNickName(string traderName)
{
return databaseService
@@ -244,7 +250,7 @@ public class TraderHelper(
{
if (rawProfileTemplate.InitialStanding.TryGetValue(traderId, out var standing))
{
// Edge case for Lightkeeper, 0 standing means seeing `Make Amends - Buyout` quest
// Edge case for Lightkeeper trader, 0 standing means seeing `Make Amends - Buyout` quest
if (traderId == Traders.LIGHTHOUSEKEEPER && standing == 0)
{
return 0.01;
@@ -515,7 +521,7 @@ public class TraderHelper(
string gameVersion
)
{
if (_gameVersions.Contains(gameVersion))
if (_gameVersionsWithHigherBuyRestrictions.Contains(gameVersion))
{
return Math.Floor(buyRestrictionMax * 1.2);
}
@@ -69,7 +69,7 @@ public record BotBase
public List<QuestStatus>? Quests { get; set; }
[JsonPropertyName("TradersInfo")]
public Dictionary<string, TraderInfo>? TradersInfo { get; set; }
public Dictionary<MongoId, TraderInfo> TradersInfo { get; set; }
[JsonPropertyName("UnlockedInfo")]
public UnlockedInfo? UnlockedInfo { get; set; }
@@ -80,7 +80,7 @@ public record ProfileChange
public BotBaseHealth Health { get; set; }
[JsonPropertyName("traderRelations")]
public Dictionary<string, TraderData>? TraderRelations { get; set; }
public Dictionary<MongoId, TraderData>? TraderRelations { get; set; }
[JsonPropertyName("moneyTransferLimitData")]
public MoneyTransferLimits? MoneyTransferLimitData { get; set; }
@@ -18,11 +18,7 @@ public record RagfairOffer
public List<SellResult>? SellResults { get; set; }
[JsonPropertyName("_id")]
public string? Id
{
get { return _id; }
set { _id = string.Intern(value); }
}
public MongoId Id { get; set; }
[JsonPropertyName("items")]
public List<Item>? Items { get; set; }
@@ -31,11 +27,7 @@ public record RagfairOffer
public List<OfferRequirement>? Requirements { get; set; }
[JsonPropertyName("root")]
public string? Root
{
get { return _root; }
set { _root = string.Intern(value); }
}
public MongoId Root { get; set; }
[JsonPropertyName("intId")]
public int? InternalId { get; set; }
@@ -128,11 +120,7 @@ public record RagfairOfferUser
private string? _id;
[JsonPropertyName("id")]
public string? Id
{
get { return _id; }
set { _id = string.Intern(value); }
}
public MongoId Id { get; set; }
[JsonPropertyName("nickname")]
public string? Nickname { get; set; }
@@ -52,7 +52,7 @@ public class EventOutputHolder(
sessionId,
new ItemEventRouterResponse
{
ProfileChanges = new Dictionary<string, ProfileChange>
ProfileChanges = new Dictionary<MongoId, ProfileChange>
{
{
sessionId,
@@ -79,7 +79,7 @@ public class EventOutputHolder(
Points = 0,
},
Health = cloner.Clone(pmcProfile.Health),
TraderRelations = new Dictionary<string, TraderData>(),
TraderRelations = new Dictionary<MongoId, TraderData>(),
QuestsStatus = [],
}
},
@@ -255,8 +255,8 @@ public class EventOutputHolder(
/// </summary>
/// <param name="traderData"> Server data for traders </param>
/// <returns> Dict of trader id + TraderData </returns>
protected Dictionary<string, TraderData> ConstructTraderRelations(
Dictionary<string, TraderInfo> traderData
protected Dictionary<MongoId, TraderData> ConstructTraderRelations(
Dictionary<MongoId, TraderInfo> traderData
)
{
return traderData.ToDictionary(
@@ -1755,7 +1755,7 @@ public class FenceService(
/// </summary>
/// <param name="assortId"> Assort ID to adjust </param>
/// <param name="buyCount">`Count of items bought </param>
public void AmendOrRemoveFenceOffer(string assortId, int buyCount)
public void AmendOrRemoveFenceOffer(MongoId assortId, int buyCount)
{
var isNormalAssort = true;
var fenceAssortItem = fenceAssort.Items.FirstOrDefault(item => item.Id == assortId);
@@ -1786,7 +1786,7 @@ public class FenceService(
fenceAssortItem.Upd.StackObjectsCount -= buyCount;
}
protected void DeleteOffer(string assortId, List<Item> assorts)
protected void DeleteOffer(MongoId assortId, List<Item> assorts)
{
// Assort could have child items, remove those too
var itemWithChildrenToRemove = assorts.FindAndReturnChildrenAsItems(assortId);
@@ -1117,8 +1117,8 @@ public class LocationLifecycleService(
/// <param name="tradersServerProfile"> Server </param>
/// <param name="tradersClientProfile"> Client </param>
protected void ApplyTraderStandingAdjustments(
Dictionary<string, TraderInfo>? tradersServerProfile,
Dictionary<string, TraderInfo>? tradersClientProfile
Dictionary<MongoId, TraderInfo>? tradersServerProfile,
Dictionary<MongoId, TraderInfo>? tradersClientProfile
)
{
foreach (var traderId in tradersClientProfile)
@@ -25,7 +25,7 @@ public class MatchBotDetailsCacheService(ISptLogger<MatchBotDetailsCacheService>
/// <param name="botToCache"> Bot details to cache </param>
public void CacheBot(BotBase botToCache)
{
if (botToCache is null || botToCache.Id is null)
if (botToCache?.Id is null)
{
return;
}
@@ -47,7 +47,8 @@ public class PaymentService(
{
// May need to convert to trader currency
var trader = traderHelper.GetTrader(request.TransactionId, sessionID);
var payToTrader = traderHelper.TraderExists(request.TransactionId);
var payToTrader =
request.TransactionId != "ragfair" && traderHelper.TraderExists(request.TransactionId);
// Track the amounts of each type of currency involved in the trade.
var currencyAmounts = new Dictionary<string, double?>();
@@ -190,7 +190,9 @@ public class RagfairOfferService(
}
// Handle dynamic offer from PMCs
var isPlayer = profileHelper.IsPlayer(staleOffer.User.Id.RegexReplace("^pmc", ""));
var isPlayer = profileHelper.IsPlayer(
staleOffer.User.Id.ToString().RegexReplace("^pmc", "")
);
if (flagOfferAsExpired && !isPlayer)
{
// Not trader or a player offer