From af70ea89477d53072899814c2442311936d84d21 Mon Sep 17 00:00:00 2001 From: CWX Date: Mon, 13 Jan 2025 10:24:03 +0000 Subject: [PATCH] Add temp fix to get around trader pathing issue, fix traderassortservice --- Core/Services/TraderAssortService.cs | 6 ++++-- Core/Utils/DatabaseImporter.cs | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Core/Services/TraderAssortService.cs b/Core/Services/TraderAssortService.cs index fbd7c694..276100b7 100644 --- a/Core/Services/TraderAssortService.cs +++ b/Core/Services/TraderAssortService.cs @@ -8,9 +8,11 @@ public class TraderAssortService { private Dictionary _pristineTraderAssorts = new(); - public TraderAssort GetPristineTraderAssort(string traderId) + public TraderAssort? GetPristineTraderAssort(string traderId) { - return _pristineTraderAssorts[traderId]; + _pristineTraderAssorts.TryGetValue(traderId, out var result); + + return result; } /// diff --git a/Core/Utils/DatabaseImporter.cs b/Core/Utils/DatabaseImporter.cs index 62bc7b3a..76f3e2ec 100644 --- a/Core/Utils/DatabaseImporter.cs +++ b/Core/Utils/DatabaseImporter.cs @@ -1,11 +1,13 @@ using Core.Annotations; using Core.DI; +using Core.Models.Eft.Common.Tables; using Core.Models.Enums; using Core.Models.Spt.Config; using Core.Models.Spt.Server; using Core.Routers; using Core.Servers; using Core.Services; +using Core.Utils.Cloners; using ILogger = Core.Models.Utils.ILogger; namespace Core.Utils; @@ -114,11 +116,25 @@ public class DatabaseImporter : OnLoad { _logger.Info(_localisationService.GetText("importing_database")); - var dataToImport = await _importerUtil.LoadRecursiveAsync( + var dataToImport = (DatabaseTables) await _importerUtil.LoadRecursiveAsync( $"{filepath}database/", typeof(DatabaseTables), OnReadValidate ); + + // TODO: Fix loading of traders, so their full path is not included as the key + + var tempTraders = new Dictionary(); + + // temp fix for trader keys + foreach (var trader in dataToImport.Traders) + { + // fix string for key + var tempKey = trader.Key.Split("/").Last(); + tempTraders.Add(tempKey, trader.Value); + } + + dataToImport.Traders = tempTraders; var validation = valid == ValidationResult.FAILED || valid == ValidationResult.NOT_FOUND ? "." : ""; _logger.Info($"{_localisationService.GetText("importing_database_finish")}{validation}");