From e512a83fa30e504985aa1f7ebf5de887538ccb95 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sun, 12 Jan 2025 11:56:21 +0000 Subject: [PATCH] Updated `ItemEventRouterBase` types to better match live Added EventOutputHolder class + stubbed out some functions --- .../Eft/ItemEvent/ItemEventRouterBase.cs | 14 +-- Core/Routers/EventOutputHolder.cs | 103 ++++++++++++++++++ 2 files changed, 108 insertions(+), 9 deletions(-) create mode 100644 Core/Routers/EventOutputHolder.cs diff --git a/Core/Models/Eft/ItemEvent/ItemEventRouterBase.cs b/Core/Models/Eft/ItemEvent/ItemEventRouterBase.cs index cee473fb..b13de36e 100644 --- a/Core/Models/Eft/ItemEvent/ItemEventRouterBase.cs +++ b/Core/Models/Eft/ItemEvent/ItemEventRouterBase.cs @@ -1,4 +1,4 @@ -using Core.Models.Eft.Common.Tables; +using Core.Models.Eft.Common.Tables; using Core.Models.Eft.Ragfair; using Core.Models.Enums; @@ -12,11 +12,7 @@ public class ItemEventRouterBase public List? Warnings { get; set; } [JsonPropertyName("profileChanges")] - public object ProfileChanges { get; set; } // TODO: Types given TProfileChanges | "" -} - -public class TProfileChanges : Dictionary -{ + public Dictionary ProfileChanges { get; set; } } public class Warning @@ -40,7 +36,7 @@ public class ProfileChange public string? Id { get; set; } [JsonPropertyName("experience")] - public int? Experience { get; set; } + public double? Experience { get; set; } [JsonPropertyName("quests")] public List? Quests { get; set; } @@ -68,7 +64,7 @@ public class ProfileChange public Skills? Skills { get; set; } [JsonPropertyName("health")] - public Common.Health Health { get; set; } + public BotBaseHealth Health { get; set; } [JsonPropertyName("traderRelations")] public Dictionary? TraderRelations { get; set; } @@ -187,4 +183,4 @@ public class Product [JsonPropertyName("upd")] public Upd? Upd { get; set; } -} \ No newline at end of file +} diff --git a/Core/Routers/EventOutputHolder.cs b/Core/Routers/EventOutputHolder.cs new file mode 100644 index 00000000..e8799bf8 --- /dev/null +++ b/Core/Routers/EventOutputHolder.cs @@ -0,0 +1,103 @@ +using Core.Annotations; +using Core.Helpers; +using Core.Models.Eft.Common.Tables; +using Core.Models.Eft.ItemEvent; +using Core.Utils; +using Core.Utils.Cloners; +using Core.Utils.Json; + +namespace Core.Routers; + +[Injectable] +public class EventOutputHolder +{ + private readonly ProfileHelper _profileHelper; + private readonly TimeUtil _timeUtil; + private readonly ICloner _cloner; + + private readonly Dictionary _outputStore = new(); + + public EventOutputHolder( + ProfileHelper profileHelper, + TimeUtil timeUtil, + ICloner cloner + ) + { + _profileHelper = profileHelper; + _timeUtil = timeUtil; + _cloner = cloner; + } + + public ItemEventRouterResponse GetOutput(string sessionId) + { + var resultFound = _outputStore.TryGetValue(sessionId, out ItemEventRouterResponse? result); + if (resultFound) + { + return result; + } + + // Nothing found, reset to default + ResetOutput(sessionId); + _outputStore.TryGetValue(sessionId, out result!); + + return result; + } + + public void ResetOutput(string sessionId) + { + var pmcProfile = _profileHelper.GetPmcProfile(sessionId); + + _outputStore.Add(sessionId, new ItemEventRouterResponse + { + ProfileChanges = new Dictionary() + { + { + sessionId, new ProfileChange + { + Id = sessionId, + Experience = pmcProfile.Info.Experience, + Quests = [], + RagFairOffers = [], + WeaponBuilds = [], + EquipmentBuilds = [], + Items = new ItemChanges(){ NewItems = [], ChangedItems = [], DeletedItems = []}, + Production = new Dictionary(), + Improvements = new Dictionary(), + Skills = new Skills{ Common = new DictionaryOrList(null, []), Mastering = [], Points = 0}, + Health = _cloner.Clone(pmcProfile.Health), + TraderRelations = new Dictionary(), + RecipeUnlocked = {}, + QuestsStatus = [] + } + } + }, + Warnings = {} + }); + } + + public void UpdateOutputProperties() + { + throw new NotImplementedException(); + } + + private void ResetMoneyTransferLimit(MoneyTransferLimits limit) + { + if (limit.NextResetTime < this._timeUtil.GetTimeStamp()) + { + limit.NextResetTime += limit.ResetInterval; + limit.RemainingLimit = limit.TotalLimit; + } + } + + private Dictionary ConstructTraderRelations(Dictionary traderData) + { + return traderData.ToDictionary(trader => trader.Key, trader => new TraderData() + { + SalesSum = trader.Value.SalesSum, + Disabled = trader.Value.Disabled, + Loyalty = trader.Value.LoyaltyLevel, + Standing = trader.Value.Standing, + Unlocked = trader.Value.Unlocked, + }); + } +}