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, }); } }