From bb4c3891803105e85c44c82872b7a93ba2c85edf Mon Sep 17 00:00:00 2001 From: CWX Date: Mon, 13 Jan 2025 11:08:42 +0000 Subject: [PATCH] implement method in trader helper --- Core/Helpers/TraderHelper.cs | 64 +++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/Core/Helpers/TraderHelper.cs b/Core/Helpers/TraderHelper.cs index 990f6787..b7030489 100644 --- a/Core/Helpers/TraderHelper.cs +++ b/Core/Helpers/TraderHelper.cs @@ -21,21 +21,28 @@ public class TraderHelper private readonly LocalisationService _localisationService; private readonly ConfigServer _configServer; private readonly TraderConfig _traderConfig; - private Dictionary? _highestTraderPriceItems; + private readonly ProfileHelper _profileHelper; + private readonly DatabaseService _databaseService; + + private Dictionary _highestTraderPriceItems = new(); public TraderHelper( ILogger logger, TimeUtil timeUtil, RandomUtil randomUtil, LocalisationService localisationService, - ConfigServer configServer) + ConfigServer configServer, + ProfileHelper profileHelper, + DatabaseService databaseService + ) { _logger = logger; _timeUtil = timeUtil; _randomUtil = randomUtil; _localisationService = localisationService; _configServer = configServer; - _highestTraderPriceItems = new Dictionary(); + _profileHelper = profileHelper; + _databaseService = databaseService; _traderConfig = _configServer.GetConfig(ConfigTypes.TRADER); } @@ -49,7 +56,31 @@ public class TraderHelper /// Trader base public TraderBase GetTrader(string traderID, string sessionID) { - throw new NotImplementedException(); + if (traderID == "ragfair") + { + return new() + { + Currency = "RUB" + }; + } + + var pmcData = _profileHelper.GetPmcProfile(sessionID); + if (pmcData == null) + throw new Exception(_localisationService.GetText("trader-unable_to_find_profile_with_id", sessionID)); + + // Profile has traderInfo dict (profile beyond creation stage) but no requested trader in profile + if (pmcData?.TradersInfo != null && (pmcData?.TradersInfo?.ContainsKey(traderID) ?? false)) + { + // Add trader values to profile + ResetTrader(sessionID, traderID); + LevelUp(traderID, pmcData); + } + + var traderBase = _databaseService.GetTrader(traderID).Base; + if (traderBase == null) + _logger.Error(_localisationService.GetText("trader-unable_to_find_trader_by_id", traderID)); + + return traderBase; } /// @@ -81,7 +112,8 @@ public class TraderHelper /// trader id to reset public void ResetTrader(string sessionID, string traderID) { - throw new NotImplementedException(); + // TODO: implement actually + return; } /// @@ -155,7 +187,8 @@ public class TraderHelper /// Profile to update trader in. public void LevelUp(string traderID, PmcData pmcData) { - throw new NotImplementedException(); + // TODO: implement actually + return; } /// @@ -180,17 +213,18 @@ public class TraderHelper var traderDetails = _traderConfig.UpdateTime.FirstOrDefault((x) => x.TraderId == traderId); if (traderDetails is null || traderDetails.Seconds?.Min is null || traderDetails.Seconds.Max is null) { - _logger.Warning(_localisationService.GetText("trader-missing_trader_details_using_default_refresh_time", new { + _logger.Warning(_localisationService.GetText("trader-missing_trader_details_using_default_refresh_time", new + { traderId = traderId, updateTime = _traderConfig.UpdateTimeDefault, })); - _traderConfig.UpdateTime.Add( new UpdateTime - // create temporary entry to prevent logger spam - { - TraderId = traderId, - Seconds = new MinMax { Min = _traderConfig.UpdateTimeDefault, Max = _traderConfig.UpdateTimeDefault } - }); + _traderConfig.UpdateTime.Add(new UpdateTime + // create temporary entry to prevent logger spam + { + TraderId = traderId, + Seconds = new MinMax { Min = _traderConfig.UpdateTimeDefault, Max = _traderConfig.UpdateTimeDefault } + }); return null; } @@ -202,7 +236,7 @@ public class TraderHelper { throw new NotImplementedException(); } - + /// /// Store the purchase of an assort from a trader in the player profile /// @@ -257,7 +291,7 @@ public class TraderHelper { throw new NotImplementedException(); } - + /// /// Validates that the provided traderEnumValue exists in the Traders enum. If the value is valid, it returns the /// same enum value, effectively serving as a trader ID; otherwise, it logs an error and returns an empty string.