Updated ItemEventRouterBase types to better match live
Added EventOutputHolder class + stubbed out some functions
This commit is contained in:
@@ -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<Warning>? Warnings { get; set; }
|
||||
|
||||
[JsonPropertyName("profileChanges")]
|
||||
public object ProfileChanges { get; set; } // TODO: Types given TProfileChanges | ""
|
||||
}
|
||||
|
||||
public class TProfileChanges : Dictionary<string, ProfileChange>
|
||||
{
|
||||
public Dictionary<string, ProfileChange> 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<Quest>? 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<string, TraderData>? TraderRelations { get; set; }
|
||||
@@ -187,4 +183,4 @@ public class Product
|
||||
|
||||
[JsonPropertyName("upd")]
|
||||
public Upd? Upd { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string, ItemEventRouterResponse> _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<string, ProfileChange>()
|
||||
{
|
||||
{
|
||||
sessionId, new ProfileChange
|
||||
{
|
||||
Id = sessionId,
|
||||
Experience = pmcProfile.Info.Experience,
|
||||
Quests = [],
|
||||
RagFairOffers = [],
|
||||
WeaponBuilds = [],
|
||||
EquipmentBuilds = [],
|
||||
Items = new ItemChanges(){ NewItems = [], ChangedItems = [], DeletedItems = []},
|
||||
Production = new Dictionary<string, Productive>(),
|
||||
Improvements = new Dictionary<string, HideoutImprovement>(),
|
||||
Skills = new Skills{ Common = new DictionaryOrList<string, Common>(null, []), Mastering = [], Points = 0},
|
||||
Health = _cloner.Clone(pmcProfile.Health),
|
||||
TraderRelations = new Dictionary<string, TraderData>(),
|
||||
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<string, TraderData> ConstructTraderRelations(Dictionary<string, TraderInfo> 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user