diff --git a/Core/Models/Eft/Common/PmcData.cs b/Core/Models/Eft/Common/PmcData.cs index 07031528..e9e7d94a 100644 --- a/Core/Models/Eft/Common/PmcData.cs +++ b/Core/Models/Eft/Common/PmcData.cs @@ -1,11 +1,13 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Tables; +using Core.Utils.Json.Converters; namespace Core.Models.Eft.Common; public class PmcData : BotBase { [JsonPropertyName("Prestige")] + [JsonConverter(typeof(ArrayToObjectFactoryConverter))] public Tables.Prestige Prestige { get; set; } } diff --git a/Core/Models/Eft/Common/Tables/BotBase.cs b/Core/Models/Eft/Common/Tables/BotBase.cs index 7b264efd..46fc153b 100644 --- a/Core/Models/Eft/Common/Tables/BotBase.cs +++ b/Core/Models/Eft/Common/Tables/BotBase.cs @@ -153,6 +153,7 @@ public class Info public string? Voice { get; set; } public double? Level { get; set; } public double? Experience { get; set; } + [JsonConverter(typeof(StringToNumberFactoryConverter))] public long? RegistrationDate { get; set; } public string? GameVersion { get; set; } public double? AccountType { get; set; } @@ -181,6 +182,7 @@ public class Info [JsonPropertyName("isMigratedSkills")] public bool? IsMigratedSkills { get; set; } + public double? PrestigeLevel { get; set; } } public class BotInfoSettings @@ -219,6 +221,7 @@ public class Customization public string? Body { get; set; } public string? Feet { get; set; } public string? Hands { get; set; } + public string? DogTag { get; set; } } public class BotBaseHealth @@ -518,6 +521,7 @@ public class Hideout [JsonPropertyName("sptUpdateLastRunTimestamp")] public long? SptUpdateLastRunTimestamp { get; set; } + public Dictionary? Customization { get; set; } } public class HideoutCounters @@ -751,6 +755,7 @@ public class Bonus public string? Id { get; set; } [JsonPropertyName("type")] + [JsonConverter(typeof(JsonStringEnumConverter))] public BonusType? Type { get; set; } [JsonPropertyName("templateId")] diff --git a/Core/Models/Eft/Common/Tables/Trader.cs b/Core/Models/Eft/Common/Tables/Trader.cs index 4fe0aacb..a20c5142 100644 --- a/Core/Models/Eft/Common/Tables/Trader.cs +++ b/Core/Models/Eft/Common/Tables/Trader.cs @@ -197,6 +197,10 @@ public class TraderRepair [JsonPropertyName("quality")] [JsonConverter(typeof(StringToNumberFactoryConverter))] public double? Quality { get; set; } + + [JsonPropertyName("price_rate")] + public double? PriceRate { get; set; } + } public class TraderAssort diff --git a/Core/Models/Spt/Services/TraderServiceModel.cs b/Core/Models/Spt/Services/TraderServiceModel.cs index ff9e7ea4..48c14054 100644 --- a/Core/Models/Spt/Services/TraderServiceModel.cs +++ b/Core/Models/Spt/Services/TraderServiceModel.cs @@ -6,6 +6,7 @@ namespace Core.Models.Spt.Services; public class TraderServiceModel { [JsonPropertyName("serviceType")] + [JsonConverter(typeof(JsonStringEnumConverter))] public TraderServiceType? ServiceType { get; set; } [JsonPropertyName("itemsToPay")] @@ -27,5 +28,5 @@ public class TraderServiceRequirementsModel public List? CompletedQuests { get; set; } [JsonPropertyName("standings")] - public Dictionary? Standings { get; set; } -} \ No newline at end of file + public Dictionary? Standings { get; set; } +} diff --git a/Core/Utils/ImporterUtil.cs b/Core/Utils/ImporterUtil.cs index 0d5f3112..35291092 100644 --- a/Core/Utils/ImporterUtil.cs +++ b/Core/Utils/ImporterUtil.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Text; using System.Text.Json; using System.Text.Json.Serialization; using Core.Annotations; @@ -11,6 +10,8 @@ public class ImporterUtil { private readonly FileUtil _fileUtil; + private readonly HashSet filesToIgnore = ["bearsuits.json", "usecsuits.json", "archivedquests.json"]; + public ImporterUtil(FileUtil fileUtil) { _fileUtil = fileUtil; @@ -39,8 +40,7 @@ public class ImporterUtil foreach (var file in files) { if (_fileUtil.GetFileExtension(file) != "json") continue; - // to skip ArchivedQuests.json - if (file.ToLower().Contains("archived")) continue; + if (filesToIgnore.Contains(Path.GetFileName(file).ToLower())) continue; tasks.Add( Task.Factory.StartNew(() => { diff --git a/Core/Utils/Json/Converters/StringToNumberFactoryConverter.cs b/Core/Utils/Json/Converters/StringToNumberFactoryConverter.cs index 8736d7fb..8812fb4b 100644 --- a/Core/Utils/Json/Converters/StringToNumberFactoryConverter.cs +++ b/Core/Utils/Json/Converters/StringToNumberFactoryConverter.cs @@ -25,7 +25,24 @@ public class StringToNumberFactoryConverter : JsonConverterFactory var value = reader.GetString(); if (string.IsNullOrWhiteSpace(value)) return default; - goto case JsonTokenType.Number; + var type = typeToConvert; + try + { + if (typeToConvert.IsGenericType && + typeToConvert.GetGenericTypeDefinition() == typeof(Nullable<>)) + { + type = typeToConvert.GenericTypeArguments[0]; + } + return (T) type.GetMethods().First(m => + m.Name == "Parse" && m.GetParameters().Length == 1 && + m.GetParameters().First().ParameterType == typeof(string)).Invoke(null, [value]); + } + catch (Exception ex) + { + Console.WriteLine($"Tried to convert {value} into {type.Name} but failed to parse it, null value will be used instead."); + } + + return default; case JsonTokenType.Number: using (var jsonDocument = JsonDocument.ParseValue(ref reader)) { @@ -46,4 +63,4 @@ public class StringToNumberFactoryConverter : JsonConverterFactory JsonSerializer.Serialize(writer, value, options); } } -} \ No newline at end of file +}