From 3d99625d238e21e4bc26a0d368e20ada3f3a5bc8 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 19 Apr 2022 14:03:31 +0200 Subject: [PATCH 1/7] Create Vault Environment --- .../Common/Locations.cs | 1 + .../Enumerations/EventCodes.cs | 12 +-- .../Enumerations/OperationCodes.cs | 2 +- .../Enumerations/VaultLocation.cs | 19 +++++ .../Models/NetworkModel/Vault.cs | 23 ++++++ .../Network/AlbionPackageParser.cs | 22 ++++++ .../Network/Events/BaseVaultInfoEvent.cs | 74 +++++++++++++++++++ .../Network/Events/GuildVaultInfoEvent.cs | 74 +++++++++++++++++++ .../Events/InCombatStateUpdateEvent.cs | 8 +- .../Network/Events/PartyChangedOrderEvent.cs | 6 +- .../Handler/BaseVaultInfoEventHandler.cs | 23 ++++++ .../Handler/GuildVaultInfoEventHandler.cs | 22 ++++++ .../InCombatStateUpdateEventHandler.cs | 1 + .../Handler/PartyChangedOrderEventHandler.cs | 1 + .../Network/Manager/TrackingController.cs | 2 + .../Network/Manager/VaultController.cs | 42 +++++++++++ 16 files changed, 318 insertions(+), 14 deletions(-) create mode 100644 src/StatisticsAnalysisTool/Enumerations/VaultLocation.cs create mode 100644 src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs create mode 100644 src/StatisticsAnalysisTool/Network/Events/BaseVaultInfoEvent.cs create mode 100644 src/StatisticsAnalysisTool/Network/Events/GuildVaultInfoEvent.cs create mode 100644 src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs create mode 100644 src/StatisticsAnalysisTool/Network/Handler/GuildVaultInfoEventHandler.cs create mode 100644 src/StatisticsAnalysisTool/Network/Manager/VaultController.cs diff --git a/src/StatisticsAnalysisTool/Common/Locations.cs b/src/StatisticsAnalysisTool/Common/Locations.cs index 4d122fb51..9863d51e7 100644 --- a/src/StatisticsAnalysisTool/Common/Locations.cs +++ b/src/StatisticsAnalysisTool/Common/Locations.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Windows; using System.Windows.Media; +using StatisticsAnalysisTool.Enumerations; namespace StatisticsAnalysisTool.Common { diff --git a/src/StatisticsAnalysisTool/Enumerations/EventCodes.cs b/src/StatisticsAnalysisTool/Enumerations/EventCodes.cs index 091fd1fca..e179679e7 100644 --- a/src/StatisticsAnalysisTool/Enumerations/EventCodes.cs +++ b/src/StatisticsAnalysisTool/Enumerations/EventCodes.cs @@ -30,9 +30,9 @@ public enum EventCodes NewCharacter = 26, NewEquipmentItem = 27, // map[0:657 1:2036 2:1 4:28169331 5:Apolo540 6:3 7:90000000 8:[] 9:[0] 252:27] (0: ObjectId, 1: ItemId, 2: Amount, 4: Avarage Market Price, 5: CrafterName) NewSimpleItem = 28, // map[0:505 1:7006 2:1 3:true 4:29033970 252:27] (0: ObjectId, 1: ItemId, 2: Amount) - NewFurnitureItem, - NewJournalItem, - NewLaborerItem, + NewFurnitureItem = 29, + NewJournalItem = 30, + NewLaborerItem = 31, NewSimpleHarvestableObject, NewSimpleHarvestableObjectList, NewHarvestableObject, @@ -90,7 +90,7 @@ public enum EventCodes RegenerationHealthEnergyComboChanged, RegenerationPlayerComboChanged, DurabilityChanged, - NewLoot, + NewLoot = 88, AttachItemContainer, // map[0:78 1:[-99 -50 125 -49 86 0 -115 74 -74 67 9 101 -87 -71 -66 -10] 3:[0 0 0 0 0 0 656 657] 4:8 252:89] (0: ObjectId, 3: ItemId[]) DetachItemContainer, // map[0:[-95 72 -77 -75 -70 34 127 73 -114 -96 28 8 75 -107 -106 125] 252:90] InvalidateItemContainer, @@ -380,8 +380,8 @@ public enum EventCodes UnlockVanityUnlock, AvatarUnlocked, CustomizationChanged, - BaseVaultInfo, - GuildVaultInfo, + GuildVaultInfo = 385, + BaseVaultInfo = 386, BankVaultInfo, RecoveryVaultPlayerInfo, RecoveryVaultGuildInfo, diff --git a/src/StatisticsAnalysisTool/Enumerations/OperationCodes.cs b/src/StatisticsAnalysisTool/Enumerations/OperationCodes.cs index f45e91b23..275722f31 100644 --- a/src/StatisticsAnalysisTool/Enumerations/OperationCodes.cs +++ b/src/StatisticsAnalysisTool/Enumerations/OperationCodes.cs @@ -96,7 +96,7 @@ public enum OperationCodes AuctionGetMyOpenAuctions, AuctionGetItemAverageStats, AuctionGetItemAverageValue, - ContainerOpen, + ContainerOpen = 92, // map[0: ObjectId = 405 1:1 2: ObjectGuid = [-46 37 -21 125 -40 -77 125 76 -96 -6 39 120 -46 -21 11 -39] 253:92] ContainerClose, ContainerManageSubContainer, Respawn, diff --git a/src/StatisticsAnalysisTool/Enumerations/VaultLocation.cs b/src/StatisticsAnalysisTool/Enumerations/VaultLocation.cs new file mode 100644 index 000000000..da57c7b27 --- /dev/null +++ b/src/StatisticsAnalysisTool/Enumerations/VaultLocation.cs @@ -0,0 +1,19 @@ +namespace StatisticsAnalysisTool.Enumerations; + +public enum VaultLocation +{ + Unknown = 0, + BankOfThetford = 0006, + BankOfLymhurst = 1001, + ForestCross = 1006, + SteppeCross = 2002, + BankOfBridgewatch = 2003, + HighlandCross = 3002, + BankOfCaerleon = 3006, + BankOfMartlock = 3007, + BankOfFortSterling = 4001, + MountainCross = 4006, + ArthursRest = 4300, + MerlynsRest = -2, + MorganasRest = -3 +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs new file mode 100644 index 000000000..6c7c4cede --- /dev/null +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using StatisticsAnalysisTool.Enumerations; + +namespace StatisticsAnalysisTool.Models.NetworkModel; + +public class Vault +{ + public Vault(long? objectId, VaultLocation location, List vaultGuidList, List vaultNames, List iconTags) + { + ObjectId = objectId; + Location = location; + VaultGuidList = vaultGuidList; + VaultNames = vaultNames; + IconTags = iconTags; + } + + public long? ObjectId { get; set; } + public VaultLocation Location { get; set; } + public List VaultGuidList { get; set; } + public List VaultNames { get; set; } + public List IconTags { get; set; } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs b/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs index 9291b68ca..54e965819 100644 --- a/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs +++ b/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs @@ -42,6 +42,8 @@ public class AlbionPackageParser : PhotonParser private readonly UpdateFactionStandingEventHandler _updateFactionStandingEventHandler; private readonly ReceivedSeasonPointsEventHandler _receivedSeasonPointsEventHandler; private readonly MightFavorPointsEventHandler _mightFavorPointsEventHandler; + private readonly BaseVaultInfoEventHandler _baseVaultInfoEventHandler; + private readonly GuildVaultInfoEventHandler _guildVaultInfoEventHandler; private readonly UseShrineRequestHandler _useShrineRequestHandler; @@ -80,6 +82,8 @@ public AlbionPackageParser(TrackingController trackingController, MainWindowView _updateFactionStandingEventHandler = new UpdateFactionStandingEventHandler(trackingController); _receivedSeasonPointsEventHandler = new ReceivedSeasonPointsEventHandler(trackingController); _mightFavorPointsEventHandler = new MightFavorPointsEventHandler(trackingController); + _baseVaultInfoEventHandler = new BaseVaultInfoEventHandler(trackingController); + _guildVaultInfoEventHandler = new GuildVaultInfoEventHandler(trackingController); _useShrineRequestHandler = new UseShrineRequestHandler(trackingController); @@ -180,6 +184,12 @@ protected override async void OnEvent(byte code, Dictionary parame case EventCodes.MightFavorPoints: await MightFavorPointsEventHandlerAsync(parameters).ConfigureAwait(true); return; + case EventCodes.BaseVaultInfo: + await BaseVaultInfoEventHandlerAsync(parameters).ConfigureAwait(true); + return; + case EventCodes.RecoveryVaultPlayerInfo: + await RecoveryVaultPlayerInfoEventHandlerAsync(parameters).ConfigureAwait(true); + return; } } catch (Exception ex) @@ -421,6 +431,18 @@ private async Task MightFavorPointsEventHandlerAsync(Dictionary pa await _mightFavorPointsEventHandler.OnActionAsync(value); } + private async Task BaseVaultInfoEventHandlerAsync(Dictionary parameters) + { + var value = new BaseVaultInfoEvent(parameters); + await _baseVaultInfoEventHandler.OnActionAsync(value); + } + + private async Task RecoveryVaultPlayerInfoEventHandlerAsync(Dictionary parameters) + { + var value = new GuildVaultInfoEvent(parameters); + await _guildVaultInfoEventHandler.OnActionAsync(value); + } + #endregion #region Requests diff --git a/src/StatisticsAnalysisTool/Network/Events/BaseVaultInfoEvent.cs b/src/StatisticsAnalysisTool/Network/Events/BaseVaultInfoEvent.cs new file mode 100644 index 000000000..0233d1f10 --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Events/BaseVaultInfoEvent.cs @@ -0,0 +1,74 @@ +using StatisticsAnalysisTool.Common; +using System; +using System.Collections.Generic; +using System.Reflection; +using StatisticsAnalysisTool.Enumerations; +using StatisticsAnalysisTool.Network.Manager; + +namespace StatisticsAnalysisTool.Network.Events +{ + public class BaseVaultInfoEvent + { + public long? ObjectId; + public VaultLocation Location; + public List VaultGuidList = new (); + public List VaultNames = new (); + public List IconTags = new (); + + public BaseVaultInfoEvent(Dictionary parameters) + { + ConsoleManager.WriteLineForNetworkHandler(GetType().Name, parameters); + + try + { + if (parameters.ContainsKey(0)) + { + ObjectId = parameters[0].ObjectToLong(); + } + + if (parameters.ContainsKey(1)) + { + Location = VaultController.GetVaultLocation(parameters[1].ToString()); + } + + if (parameters.ContainsKey(2) && parameters[2] != null) + { + var vaultGuidArray = ((object[])parameters[2]).ToDictionary(); + + for (var i = 0; i < vaultGuidArray.Count; i++) + { + var guid = vaultGuidArray[i].ObjectToGuid(); + if (guid != null) + { + VaultGuidList.Add((Guid)guid); + } + } + } + + if (parameters.ContainsKey(3) && parameters[3] != null) + { + var vaultNameArray = ((object[])parameters[3]).ToDictionary(); + + for (var i = 0; i < vaultNameArray.Count; i++) + { + VaultNames.Add(vaultNameArray[i].ToString()); + } + } + + if (parameters.ContainsKey(4) && parameters[4] != null) + { + var iconTagArray = ((object[])parameters[4]).ToDictionary(); + + for (var i = 0; i < iconTagArray.Count; i++) + { + IconTags.Add(iconTagArray[i].ToString()); + } + } + } + catch (Exception e) + { + ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); + } + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Events/GuildVaultInfoEvent.cs b/src/StatisticsAnalysisTool/Network/Events/GuildVaultInfoEvent.cs new file mode 100644 index 000000000..e90cc2b9b --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Events/GuildVaultInfoEvent.cs @@ -0,0 +1,74 @@ +using StatisticsAnalysisTool.Common; +using System; +using System.Collections.Generic; +using System.Reflection; +using StatisticsAnalysisTool.Enumerations; +using StatisticsAnalysisTool.Network.Manager; + +namespace StatisticsAnalysisTool.Network.Events +{ + public class GuildVaultInfoEvent + { + public long? ObjectId; + public VaultLocation Location; + public List VaultGuidList = new (); + public List VaultNames = new (); + public List IconTags = new (); + + public GuildVaultInfoEvent(Dictionary parameters) + { + ConsoleManager.WriteLineForNetworkHandler(GetType().Name, parameters); + + try + { + if (parameters.ContainsKey(0)) + { + ObjectId = parameters[0].ObjectToLong(); + } + + if (parameters.ContainsKey(1)) + { + Location = VaultController.GetVaultLocation(parameters[1].ToString()); + } + + if (parameters.ContainsKey(2) && parameters[2] != null) + { + var vaultGuidArray = ((object[])parameters[2]).ToDictionary(); + + for (var i = 0; i < vaultGuidArray.Count; i++) + { + var guid = vaultGuidArray[i].ObjectToGuid(); + if (guid != null) + { + VaultGuidList.Add((Guid)guid); + } + } + } + + if (parameters.ContainsKey(3) && parameters[3] != null) + { + var vaultNameArray = ((object[])parameters[3]).ToDictionary(); + + for (var i = 0; i < vaultNameArray.Count; i++) + { + VaultNames.Add(vaultNameArray[i].ToString()); + } + } + + if (parameters.ContainsKey(4) && parameters[4] != null) + { + var iconTagArray = ((object[])parameters[4]).ToDictionary(); + + for (var i = 0; i < iconTagArray.Count; i++) + { + IconTags.Add(iconTagArray[i].ToString()); + } + } + } + catch (Exception e) + { + ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); + } + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Events/InCombatStateUpdateEvent.cs b/src/StatisticsAnalysisTool/Network/Events/InCombatStateUpdateEvent.cs index 3b7d121a3..8ce8b9bf7 100644 --- a/src/StatisticsAnalysisTool/Network/Events/InCombatStateUpdateEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/InCombatStateUpdateEvent.cs @@ -1,10 +1,10 @@ -using log4net; -using StatisticsAnalysisTool.Common; -using System; +using System; using System.Collections.Generic; using System.Reflection; +using log4net; +using StatisticsAnalysisTool.Common; -namespace StatisticsAnalysisTool.Network.Handler +namespace StatisticsAnalysisTool.Network.Events { public class InCombatStateUpdateEvent { diff --git a/src/StatisticsAnalysisTool/Network/Events/PartyChangedOrderEvent.cs b/src/StatisticsAnalysisTool/Network/Events/PartyChangedOrderEvent.cs index 92ccfb2c9..d8ae63b65 100644 --- a/src/StatisticsAnalysisTool/Network/Events/PartyChangedOrderEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/PartyChangedOrderEvent.cs @@ -1,9 +1,9 @@ -using StatisticsAnalysisTool.Common; -using System; +using System; using System.Collections.Generic; using System.Reflection; +using StatisticsAnalysisTool.Common; -namespace StatisticsAnalysisTool.Network.Handler +namespace StatisticsAnalysisTool.Network.Events { public class PartyChangedOrderEvent { diff --git a/src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs new file mode 100644 index 000000000..b2e1fdf3a --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs @@ -0,0 +1,23 @@ +using StatisticsAnalysisTool.Network.Events; +using StatisticsAnalysisTool.Network.Manager; +using System.Threading.Tasks; +using StatisticsAnalysisTool.Models.NetworkModel; + +namespace StatisticsAnalysisTool.Network.Handler +{ + public class BaseVaultInfoEventHandler + { + private readonly TrackingController _trackingController; + + public BaseVaultInfoEventHandler(TrackingController trackingController) + { + _trackingController = trackingController; + } + + public async Task OnActionAsync(BaseVaultInfoEvent value) + { + _trackingController.VaultController.SetCurrentVault(new Vault(value.ObjectId, value.Location, value.VaultGuidList, value.VaultNames, value.IconTags)); + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Handler/GuildVaultInfoEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/GuildVaultInfoEventHandler.cs new file mode 100644 index 000000000..cb258bab3 --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Handler/GuildVaultInfoEventHandler.cs @@ -0,0 +1,22 @@ +using StatisticsAnalysisTool.Network.Events; +using StatisticsAnalysisTool.Network.Manager; +using System.Threading.Tasks; + +namespace StatisticsAnalysisTool.Network.Handler +{ + public class GuildVaultInfoEventHandler + { + private readonly TrackingController _trackingController; + + public GuildVaultInfoEventHandler(TrackingController trackingController) + { + _trackingController = trackingController; + } + + public async Task OnActionAsync(GuildVaultInfoEvent value) + { + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Handler/InCombatStateUpdateEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/InCombatStateUpdateEventHandler.cs index e9ae15eed..f50d8b1e4 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/InCombatStateUpdateEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/InCombatStateUpdateEventHandler.cs @@ -1,5 +1,6 @@ using StatisticsAnalysisTool.Network.Manager; using System.Threading.Tasks; +using StatisticsAnalysisTool.Network.Events; namespace StatisticsAnalysisTool.Network.Handler { diff --git a/src/StatisticsAnalysisTool/Network/Handler/PartyChangedOrderEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/PartyChangedOrderEventHandler.cs index 7f8de9362..d284c9541 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/PartyChangedOrderEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/PartyChangedOrderEventHandler.cs @@ -1,5 +1,6 @@ using StatisticsAnalysisTool.Network.Manager; using System.Threading.Tasks; +using StatisticsAnalysisTool.Network.Events; namespace StatisticsAnalysisTool.Network.Handler { diff --git a/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs b/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs index 910e4d893..268e8c6e9 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs @@ -33,6 +33,7 @@ public class TrackingController : ITrackingController public LootController LootController; public StatisticController StatisticController; public MailController MailController; + public VaultController VaultController; private readonly List _notificationTypesFilters = new(); public TrackingController(MainWindowViewModel mainWindowViewModel, MainWindow mainWindow) @@ -45,6 +46,7 @@ public TrackingController(MainWindowViewModel mainWindowViewModel, MainWindow ma LootController = new LootController(this, mainWindowViewModel); StatisticController = new StatisticController(this, mainWindowViewModel); MailController = new MailController(mainWindowViewModel); + VaultController = new VaultController(mainWindowViewModel); CountUpTimer = new CountUpTimer(this, mainWindowViewModel); } diff --git a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs new file mode 100644 index 000000000..b5e7d6397 --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs @@ -0,0 +1,42 @@ +using log4net; +using StatisticsAnalysisTool.Enumerations; +using StatisticsAnalysisTool.Models.NetworkModel; +using StatisticsAnalysisTool.ViewModels; +using System; +using System.Linq; +using System.Reflection; + +namespace StatisticsAnalysisTool.Network.Manager; + +public class VaultController +{ + private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod()?.DeclaringType); + + private readonly MainWindowViewModel _mainWindowViewModel; + private Vault _currentVault; + + public VaultController(MainWindowViewModel mainWindowViewModel) + { + _mainWindowViewModel = mainWindowViewModel; + } + + public void SetCurrentVault(Vault vault) + { + _currentVault = vault; + } + + public static VaultLocation GetVaultLocation(string value) + { + var clusterInfoArray = value.Split("@"); + return clusterInfoArray.ElementAtOrDefault(1) != null ? GetVaultLocationByIndex(clusterInfoArray[1]) : VaultLocation.Unknown; + } + + #region Helper methods + + private static VaultLocation GetVaultLocationByIndex(string index) + { + return Enum.TryParse(index, true, out VaultLocation location) ? location : VaultLocation.Unknown; + } + + #endregion +} \ No newline at end of file From 357535acde23f3f4a5215c9f14944302c9c9e2da Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 19 Apr 2022 15:03:34 +0200 Subject: [PATCH 2/7] Added discovered items traccking --- .../{DiscoveredLoot.cs => DiscoveredItem.cs} | 8 +-- .../Network/AlbionPackageParser.cs | 44 ++++++++++++++ .../Network/Events/NewEquipmentItemEvent.cs | 6 +- .../Network/Events/NewFurnitureItemEvent.cs | 58 +++++++++++++++++++ .../Network/Events/NewJournalItemEvent.cs | 58 +++++++++++++++++++ .../Network/Events/NewLaborerItemEvent.cs | 58 +++++++++++++++++++ .../Network/Events/NewSimpleItemEvent.cs | 6 +- .../Handler/BaseVaultInfoEventHandler.cs | 6 +- .../Handler/NewEquipmentItemEventHandler.cs | 9 ++- .../Handler/NewFurnitureItemEventHandler.cs | 26 +++++++++ .../Handler/NewJournalItemEventHandler.cs | 26 +++++++++ .../Handler/NewLaborerItemEventHandler.cs | 26 +++++++++ .../Handler/NewSimpleItemEventHandler.cs | 9 ++- .../Handler/UseLootChestEventHandler.cs | 2 +- .../Network/Manager/ILootController.cs | 2 +- .../Network/Manager/LootController.cs | 8 +-- .../Network/Manager/TrackingController.cs | 3 +- .../Network/Manager/VaultController.cs | 21 ++++++- .../Responses/UseLootChestResponse.cs | 2 +- 19 files changed, 352 insertions(+), 26 deletions(-) rename src/StatisticsAnalysisTool/Models/NetworkModel/{DiscoveredLoot.cs => DiscoveredItem.cs} (72%) create mode 100644 src/StatisticsAnalysisTool/Network/Events/NewFurnitureItemEvent.cs create mode 100644 src/StatisticsAnalysisTool/Network/Events/NewJournalItemEvent.cs create mode 100644 src/StatisticsAnalysisTool/Network/Events/NewLaborerItemEvent.cs create mode 100644 src/StatisticsAnalysisTool/Network/Handler/NewFurnitureItemEventHandler.cs create mode 100644 src/StatisticsAnalysisTool/Network/Handler/NewJournalItemEventHandler.cs create mode 100644 src/StatisticsAnalysisTool/Network/Handler/NewLaborerItemEventHandler.cs diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/DiscoveredLoot.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/DiscoveredItem.cs similarity index 72% rename from src/StatisticsAnalysisTool/Models/NetworkModel/DiscoveredLoot.cs rename to src/StatisticsAnalysisTool/Models/NetworkModel/DiscoveredItem.cs index b7d66af87..4849aa79a 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/DiscoveredLoot.cs +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/DiscoveredItem.cs @@ -3,16 +3,16 @@ namespace StatisticsAnalysisTool.Models.NetworkModel { - public class DiscoveredLoot + public class DiscoveredItem { - public DiscoveredLoot() + public DiscoveredItem() { - UtcPickupTime = DateTime.UtcNow; + UtcDiscoveryTime = DateTime.UtcNow; } public long ObjectId { get; set; } public int ItemId { get; set; } - public DateTime UtcPickupTime { get; } + public DateTime UtcDiscoveryTime { get; } public int Quantity { get; set; } public string BodyName { get; set; } public string LooterName { get; set; } diff --git a/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs b/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs index 54e965819..1066fe1f0 100644 --- a/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs +++ b/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs @@ -18,6 +18,10 @@ namespace StatisticsAnalysisTool.Network public class AlbionPackageParser : PhotonParser { private readonly NewEquipmentItemEventHandler _newEquipmentItemEventHandler; + private readonly NewSimpleItemEventHandler _newSimpleItemEventHandler; + private readonly NewFurnitureItemEventHandler _newFurnitureItemEventHandler; + private readonly NewJournalItemEventHandler _newJournalItemEventHandler; + private readonly NewLaborerItemEventHandler _newLaborerItemEventHandler; private readonly OtherGrabbedLootEventHandler _grabbedLootEventHandler; private readonly InventoryDeleteItemEventHandler _inventoryDeleteItemEventHandler; private readonly InventoryPutItemEventHandler _inventoryPutItemEventHandler; @@ -58,6 +62,10 @@ public class AlbionPackageParser : PhotonParser public AlbionPackageParser(TrackingController trackingController, MainWindowViewModel mainWindowViewModel) { _newEquipmentItemEventHandler = new NewEquipmentItemEventHandler(trackingController); + _newSimpleItemEventHandler = new NewSimpleItemEventHandler(trackingController); + _newFurnitureItemEventHandler = new NewFurnitureItemEventHandler(trackingController); + _newJournalItemEventHandler = new NewJournalItemEventHandler(trackingController); + _newLaborerItemEventHandler = new NewLaborerItemEventHandler(trackingController); _grabbedLootEventHandler = new OtherGrabbedLootEventHandler(trackingController); _inventoryDeleteItemEventHandler = new InventoryDeleteItemEventHandler(trackingController); _inventoryPutItemEventHandler = new InventoryPutItemEventHandler(trackingController); @@ -112,6 +120,18 @@ protected override async void OnEvent(byte code, Dictionary parame case EventCodes.NewEquipmentItem: await NewEquipmentItemEventHandlerAsync(parameters); return; + case EventCodes.NewSimpleItem: + await NewSimpleItemEventHandlerAsync(parameters); + return; + case EventCodes.NewFurnitureItem: + await NewFurnitureItemEventHandlerAsync(parameters); + return; + case EventCodes.NewJournalItem: + await NewJournalItemEventHandlerAsync(parameters); + return; + case EventCodes.NewLaborerItem: + await NewLaborerItemEventHandlerAsync(parameters); + return; case EventCodes.GrabbedLoot: await GrabbedLootEventHandlerAsync(parameters).ConfigureAwait(true); return; @@ -287,6 +307,30 @@ private async Task NewEquipmentItemEventHandlerAsync(Dictionary pa await _newEquipmentItemEventHandler.OnActionAsync(value); } + private async Task NewSimpleItemEventHandlerAsync(Dictionary parameters) + { + var value = new NewSimpleItemEvent(parameters); + await _newSimpleItemEventHandler.OnActionAsync(value); + } + + private async Task NewFurnitureItemEventHandlerAsync(Dictionary parameters) + { + var value = new NewFurnitureItemEvent(parameters); + await _newFurnitureItemEventHandler.OnActionAsync(value); + } + + private async Task NewJournalItemEventHandlerAsync(Dictionary parameters) + { + var value = new NewJournalItemEvent(parameters); + await _newJournalItemEventHandler.OnActionAsync(value); + } + + private async Task NewLaborerItemEventHandlerAsync(Dictionary parameters) + { + var value = new NewLaborerItemEvent(parameters); + await _newLaborerItemEventHandler.OnActionAsync(value); + } + private async Task GrabbedLootEventHandlerAsync(Dictionary parameters) { var value = new GrabbedLootEvent(parameters); diff --git a/src/StatisticsAnalysisTool/Network/Events/NewEquipmentItemEvent.cs b/src/StatisticsAnalysisTool/Network/Events/NewEquipmentItemEvent.cs index 0bf07437e..36bcdee14 100644 --- a/src/StatisticsAnalysisTool/Network/Events/NewEquipmentItemEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/NewEquipmentItemEvent.cs @@ -8,7 +8,7 @@ namespace StatisticsAnalysisTool.Network.Events { public class NewEquipmentItemEvent { - public DiscoveredLoot Loot; + public DiscoveredItem Item; private readonly long? _objectId; private readonly int _itemId; @@ -67,7 +67,7 @@ public NewEquipmentItemEvent(Dictionary parameters) if (_objectId != null) { - Loot = new DiscoveredLoot() + Item = new DiscoveredItem() { ObjectId = (long)_objectId, ItemId = _itemId, @@ -77,7 +77,7 @@ public NewEquipmentItemEvent(Dictionary parameters) } else { - Loot = null; + Item = null; } } catch (Exception e) diff --git a/src/StatisticsAnalysisTool/Network/Events/NewFurnitureItemEvent.cs b/src/StatisticsAnalysisTool/Network/Events/NewFurnitureItemEvent.cs new file mode 100644 index 000000000..e3f6368a1 --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Events/NewFurnitureItemEvent.cs @@ -0,0 +1,58 @@ +using StatisticsAnalysisTool.Common; +using StatisticsAnalysisTool.Models.NetworkModel; +using System; +using System.Collections.Generic; +using System.Reflection; + +namespace StatisticsAnalysisTool.Network.Events +{ + public class NewFurnitureItemEvent + { + public DiscoveredItem Item; + + private readonly long? _objectId; + private readonly int _itemId; + private readonly int _quantity; + + public NewFurnitureItemEvent(Dictionary parameters) + { + ConsoleManager.WriteLineForNetworkHandler(GetType().Name, parameters); + + try + { + if (parameters.ContainsKey(0)) + { + _objectId = parameters[0].ObjectToLong(); + } + + if (parameters.ContainsKey(1)) + { + _itemId = parameters[1].ObjectToInt(); + } + + if (parameters.ContainsKey(2)) + { + _quantity = parameters[2].ObjectToInt(); + } + + if (_objectId != null) + { + Item = new DiscoveredItem() + { + ObjectId = (long)_objectId, + ItemId = _itemId, + Quantity = _quantity + }; + } + else + { + Item = null; + } + } + catch (Exception e) + { + ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); + } + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Events/NewJournalItemEvent.cs b/src/StatisticsAnalysisTool/Network/Events/NewJournalItemEvent.cs new file mode 100644 index 000000000..2caa46348 --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Events/NewJournalItemEvent.cs @@ -0,0 +1,58 @@ +using StatisticsAnalysisTool.Common; +using StatisticsAnalysisTool.Models.NetworkModel; +using System; +using System.Collections.Generic; +using System.Reflection; + +namespace StatisticsAnalysisTool.Network.Events +{ + public class NewJournalItemEvent + { + public DiscoveredItem Item; + + private readonly long? _objectId; + private readonly int _itemId; + private readonly int _quantity; + + public NewJournalItemEvent(Dictionary parameters) + { + ConsoleManager.WriteLineForNetworkHandler(GetType().Name, parameters); + + try + { + if (parameters.ContainsKey(0)) + { + _objectId = parameters[0].ObjectToLong(); + } + + if (parameters.ContainsKey(1)) + { + _itemId = parameters[1].ObjectToInt(); + } + + if (parameters.ContainsKey(2)) + { + _quantity = parameters[2].ObjectToInt(); + } + + if (_objectId != null) + { + Item = new DiscoveredItem() + { + ObjectId = (long)_objectId, + ItemId = _itemId, + Quantity = _quantity + }; + } + else + { + Item = null; + } + } + catch (Exception e) + { + ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); + } + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Events/NewLaborerItemEvent.cs b/src/StatisticsAnalysisTool/Network/Events/NewLaborerItemEvent.cs new file mode 100644 index 000000000..d0e7f116f --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Events/NewLaborerItemEvent.cs @@ -0,0 +1,58 @@ +using StatisticsAnalysisTool.Common; +using StatisticsAnalysisTool.Models.NetworkModel; +using System; +using System.Collections.Generic; +using System.Reflection; + +namespace StatisticsAnalysisTool.Network.Events +{ + public class NewLaborerItemEvent + { + public DiscoveredItem Item; + + private readonly long? _objectId; + private readonly int _itemId; + private readonly int _quantity; + + public NewLaborerItemEvent(Dictionary parameters) + { + ConsoleManager.WriteLineForNetworkHandler(GetType().Name, parameters); + + try + { + if (parameters.ContainsKey(0)) + { + _objectId = parameters[0].ObjectToLong(); + } + + if (parameters.ContainsKey(1)) + { + _itemId = parameters[1].ObjectToInt(); + } + + if (parameters.ContainsKey(2)) + { + _quantity = parameters[2].ObjectToInt(); + } + + if (_objectId != null) + { + Item = new DiscoveredItem() + { + ObjectId = (long)_objectId, + ItemId = _itemId, + Quantity = _quantity + }; + } + else + { + Item = null; + } + } + catch (Exception e) + { + ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); + } + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Events/NewSimpleItemEvent.cs b/src/StatisticsAnalysisTool/Network/Events/NewSimpleItemEvent.cs index d24493dd9..c32663975 100644 --- a/src/StatisticsAnalysisTool/Network/Events/NewSimpleItemEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/NewSimpleItemEvent.cs @@ -8,7 +8,7 @@ namespace StatisticsAnalysisTool.Network.Events { public class NewSimpleItemEvent { - public DiscoveredLoot Loot; + public DiscoveredItem Item; private readonly long? _objectId; private readonly int _itemId; @@ -37,7 +37,7 @@ public NewSimpleItemEvent(Dictionary parameters) if (_objectId != null) { - Loot = new DiscoveredLoot() + Item = new DiscoveredItem() { ObjectId = (long)_objectId, ItemId = _itemId, @@ -46,7 +46,7 @@ public NewSimpleItemEvent(Dictionary parameters) } else { - Loot = null; + Item = null; } } catch (Exception e) diff --git a/src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs index b2e1fdf3a..7ce8289ba 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs @@ -16,7 +16,11 @@ public BaseVaultInfoEventHandler(TrackingController trackingController) public async Task OnActionAsync(BaseVaultInfoEvent value) { - _trackingController.VaultController.SetCurrentVault(new Vault(value.ObjectId, value.Location, value.VaultGuidList, value.VaultNames, value.IconTags)); + if (_trackingController.IsTrackingAllowedByMainCharacter()) + { + _trackingController.VaultController.SetCurrentVault(new Vault(value.ObjectId, value.Location, value.VaultGuidList, value.VaultNames, value.IconTags)); + } + await Task.CompletedTask; } } diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs index ac9194377..40d9f5594 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs @@ -17,12 +17,15 @@ public NewEquipmentItemEventHandler(TrackingController trackingController) public async Task OnActionAsync(NewEquipmentItemEvent value) { - //_trackingController.LootController.AddDiscoveredLoot(value.Loot); + if (_trackingController.IsTrackingAllowedByMainCharacter()) + { + _trackingController.VaultController.Add(value.Item); + } _trackingController.EntityController.AddEquipmentItem(new EquipmentItemInternal { - ItemIndex = value.Loot.ItemId, - SpellDictionary = value.Loot.SpellDictionary + ItemIndex = value.Item.ItemId, + SpellDictionary = value.Item.SpellDictionary }); await Task.CompletedTask; } diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewFurnitureItemEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewFurnitureItemEventHandler.cs new file mode 100644 index 000000000..6cc964554 --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Handler/NewFurnitureItemEventHandler.cs @@ -0,0 +1,26 @@ +using StatisticsAnalysisTool.Network.Events; +using StatisticsAnalysisTool.Network.Manager; +using System.Threading.Tasks; + +namespace StatisticsAnalysisTool.Network.Handler +{ + public class NewFurnitureItemEventHandler + { + private readonly TrackingController _trackingController; + + public NewFurnitureItemEventHandler(TrackingController trackingController) + { + _trackingController = trackingController; + } + + public async Task OnActionAsync(NewFurnitureItemEvent value) + { + if (_trackingController.IsTrackingAllowedByMainCharacter()) + { + _trackingController.VaultController.Add(value.Item); + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewJournalItemEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewJournalItemEventHandler.cs new file mode 100644 index 000000000..1b1685bf2 --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Handler/NewJournalItemEventHandler.cs @@ -0,0 +1,26 @@ +using StatisticsAnalysisTool.Network.Events; +using StatisticsAnalysisTool.Network.Manager; +using System.Threading.Tasks; + +namespace StatisticsAnalysisTool.Network.Handler +{ + public class NewJournalItemEventHandler + { + private readonly TrackingController _trackingController; + + public NewJournalItemEventHandler(TrackingController trackingController) + { + _trackingController = trackingController; + } + + public async Task OnActionAsync(NewJournalItemEvent value) + { + if (_trackingController.IsTrackingAllowedByMainCharacter()) + { + _trackingController.VaultController.Add(value.Item); + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewLaborerItemEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewLaborerItemEventHandler.cs new file mode 100644 index 000000000..bc5625a50 --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Handler/NewLaborerItemEventHandler.cs @@ -0,0 +1,26 @@ +using StatisticsAnalysisTool.Network.Events; +using StatisticsAnalysisTool.Network.Manager; +using System.Threading.Tasks; + +namespace StatisticsAnalysisTool.Network.Handler +{ + public class NewLaborerItemEventHandler + { + private readonly TrackingController _trackingController; + + public NewLaborerItemEventHandler(TrackingController trackingController) + { + _trackingController = trackingController; + } + + public async Task OnActionAsync(NewLaborerItemEvent value) + { + if (_trackingController.IsTrackingAllowedByMainCharacter()) + { + _trackingController.VaultController.Add(value.Item); + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewSimpleItemEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewSimpleItemEventHandler.cs index 707ad6f5b..2ae05edbb 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/NewSimpleItemEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/NewSimpleItemEventHandler.cs @@ -1,6 +1,5 @@ -using StatisticsAnalysisTool.Enumerations; +using StatisticsAnalysisTool.Network.Events; using StatisticsAnalysisTool.Network.Manager; -using StatisticsAnalysisTool.Network.Events; using System.Threading.Tasks; namespace StatisticsAnalysisTool.Network.Handler @@ -16,7 +15,11 @@ public NewSimpleItemEventHandler(TrackingController trackingController) public async Task OnActionAsync(NewSimpleItemEvent value) { - //_trackingController.LootController.AddDiscoveredLoot(value.Loot); + if (_trackingController.IsTrackingAllowedByMainCharacter()) + { + _trackingController.VaultController.Add(value.Item); + } + await Task.CompletedTask; } } diff --git a/src/StatisticsAnalysisTool/Network/Handler/UseLootChestEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/UseLootChestEventHandler.cs index b292614cb..a382edfa8 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/UseLootChestEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/UseLootChestEventHandler.cs @@ -16,7 +16,7 @@ public UseLootChestEventHandler(TrackingController trackingController) public async Task OnActionAsync(UseLootChestResponse value) { - Debug.Print($"Loot: {value.Loot.LooterName}"); + Debug.Print($"Loot: {value.Item.LooterName}"); await Task.CompletedTask; } } diff --git a/src/StatisticsAnalysisTool/Network/Manager/ILootController.cs b/src/StatisticsAnalysisTool/Network/Manager/ILootController.cs index 88bece5a3..201388aa8 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/ILootController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/ILootController.cs @@ -7,7 +7,7 @@ namespace StatisticsAnalysisTool.Network.Manager public interface ILootController { public Task AddLootAsync(Loot loot); - public void AddDiscoveredLoot(DiscoveredLoot loot); + public void AddDiscoveredLoot(DiscoveredItem item); public Task AddPutLootAsync(long? objectId, Guid? playerGuid); public void ResetViewedLootLists(); } diff --git a/src/StatisticsAnalysisTool/Network/Manager/LootController.cs b/src/StatisticsAnalysisTool/Network/Manager/LootController.cs index 1120b2cc6..d44481b10 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/LootController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/LootController.cs @@ -21,7 +21,7 @@ public class LootController : ILootController private readonly MainWindowViewModel _mainWindowViewModel; private readonly Dictionary _putLoot = new(); - private readonly List _discoveredLoot = new(); + private readonly List _discoveredLoot = new(); private readonly List _lootLoggerObjects = new(); private readonly List _topLooters = new(); @@ -98,14 +98,14 @@ public void ClearLootLogger() _topLooters.Clear(); } - public void AddDiscoveredLoot(DiscoveredLoot loot) + public void AddDiscoveredLoot(DiscoveredItem item) { - if (_discoveredLoot.Exists(x => x.ObjectId == loot.ObjectId)) + if (_discoveredLoot.Exists(x => x.ObjectId == item.ObjectId)) { return; } - _discoveredLoot.Add(loot); + _discoveredLoot.Add(item); } public async Task AddPutLootAsync(long? objectId, Guid? interactGuid) diff --git a/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs b/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs index 268e8c6e9..7fddd89b7 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs @@ -46,7 +46,7 @@ public TrackingController(MainWindowViewModel mainWindowViewModel, MainWindow ma LootController = new LootController(this, mainWindowViewModel); StatisticController = new StatisticController(this, mainWindowViewModel); MailController = new MailController(mainWindowViewModel); - VaultController = new VaultController(mainWindowViewModel); + VaultController = new VaultController(this, mainWindowViewModel); CountUpTimer = new CountUpTimer(this, mainWindowViewModel); } @@ -100,6 +100,7 @@ public void SetNewCluster(MapType mapType, Guid? mapGuid, string clusterIndex, s } StatisticController.SetKillsDeathsValues(); + VaultController.ResetDiscoveredItems(); } private bool TryChangeCluster(string index, string mapName) diff --git a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs index b5e7d6397..8bea709c5 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs @@ -3,6 +3,7 @@ using StatisticsAnalysisTool.Models.NetworkModel; using StatisticsAnalysisTool.ViewModels; using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -12,11 +13,14 @@ public class VaultController { private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod()?.DeclaringType); + private readonly TrackingController _trackingController; private readonly MainWindowViewModel _mainWindowViewModel; private Vault _currentVault; + private List _discoveredItems = new (); - public VaultController(MainWindowViewModel mainWindowViewModel) + public VaultController(TrackingController trackingController, MainWindowViewModel mainWindowViewModel) { + _trackingController = trackingController; _mainWindowViewModel = mainWindowViewModel; } @@ -25,6 +29,21 @@ public void SetCurrentVault(Vault vault) _currentVault = vault; } + public void Add(DiscoveredItem item) + { + if (_discoveredItems.Exists(x => x.ObjectId == item.ObjectId)) + { + return; + } + + _discoveredItems.Add(item); + } + + public void ResetDiscoveredItems() + { + _discoveredItems.Clear(); + } + public static VaultLocation GetVaultLocation(string value) { var clusterInfoArray = value.Split("@"); diff --git a/src/StatisticsAnalysisTool/Network/Operations/Responses/UseLootChestResponse.cs b/src/StatisticsAnalysisTool/Network/Operations/Responses/UseLootChestResponse.cs index 227527948..015c3ebf0 100644 --- a/src/StatisticsAnalysisTool/Network/Operations/Responses/UseLootChestResponse.cs +++ b/src/StatisticsAnalysisTool/Network/Operations/Responses/UseLootChestResponse.cs @@ -8,7 +8,7 @@ namespace StatisticsAnalysisTool.Network.Operations.Responses { public class UseLootChestResponse { - public DiscoveredLoot Loot; + public DiscoveredItem Item; //private readonly long? _objectId; //private readonly string _deadPlayer; From a499d5f2361ec8c76ead4bf61bae902907d9297b Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 19 Apr 2022 18:56:05 +0200 Subject: [PATCH 3/7] Added vault parsing --- .../Common/ExtensionMethod.cs | 2 +- .../Enumerations/EventCodes.cs | 4 +- .../Models/NetworkModel/ContainerItem.cs | 7 ++ .../Models/NetworkModel/DiscoveredItem.cs | 2 +- .../NetworkModel/ItemContainerObject.cs | 18 +++ .../{Container.cs => LootContainer.cs} | 2 +- .../Models/NetworkModel/Vault.cs | 17 +-- .../Models/NetworkModel/VaultContainer.cs | 12 ++ .../Models/NetworkModel/VaultInfo.cs | 23 ++++ .../Network/AlbionPackageParser.cs | 11 ++ .../Events/AttachItemContainerEvent.cs | 68 ++++++++++++ .../Network/Events/NewEquipmentItemEvent.cs | 12 +- .../Network/Events/NewFurnitureItemEvent.cs | 2 +- .../Network/Events/NewJournalItemEvent.cs | 2 +- .../Network/Events/NewLaborerItemEvent.cs | 2 +- .../Network/Events/NewLootEvent.cs | 2 +- .../Network/Events/NewSimpleItemEvent.cs | 2 +- .../AttachItemContainerEventHandler.cs | 26 +++++ .../Handler/BaseVaultInfoEventHandler.cs | 2 +- .../Handler/NewEquipmentItemEventHandler.cs | 2 +- .../Network/Manager/LootController.cs | 4 +- .../Network/Manager/TrackingController.cs | 1 + .../Network/Manager/VaultController.cs | 105 +++++++++++++++++- 23 files changed, 289 insertions(+), 39 deletions(-) create mode 100644 src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs create mode 100644 src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs rename src/StatisticsAnalysisTool/Models/NetworkModel/{Container.cs => LootContainer.cs} (95%) create mode 100644 src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs create mode 100644 src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs create mode 100644 src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs create mode 100644 src/StatisticsAnalysisTool/Network/Handler/AttachItemContainerEventHandler.cs diff --git a/src/StatisticsAnalysisTool/Common/ExtensionMethod.cs b/src/StatisticsAnalysisTool/Common/ExtensionMethod.cs index ec5ed66a8..64fcb65e8 100644 --- a/src/StatisticsAnalysisTool/Common/ExtensionMethod.cs +++ b/src/StatisticsAnalysisTool/Common/ExtensionMethod.cs @@ -32,7 +32,7 @@ public static Dictionary ToDictionary(this IEnumerable array) .Select((v, i) => new { Key = i, Value = v }) .ToDictionary(o => o.Key, o => o.Value); } - + public static string ToTimerString(this TimeSpan span) { return $"{span.Hours:00}:{span.Minutes:00}:{span.Seconds:00}"; diff --git a/src/StatisticsAnalysisTool/Enumerations/EventCodes.cs b/src/StatisticsAnalysisTool/Enumerations/EventCodes.cs index e179679e7..400cf939b 100644 --- a/src/StatisticsAnalysisTool/Enumerations/EventCodes.cs +++ b/src/StatisticsAnalysisTool/Enumerations/EventCodes.cs @@ -90,8 +90,8 @@ public enum EventCodes RegenerationHealthEnergyComboChanged, RegenerationPlayerComboChanged, DurabilityChanged, - NewLoot = 88, - AttachItemContainer, // map[0:78 1:[-99 -50 125 -49 86 0 -115 74 -74 67 9 101 -87 -71 -66 -10] 3:[0 0 0 0 0 0 656 657] 4:8 252:89] (0: ObjectId, 3: ItemId[]) + NewLoot, + AttachItemContainer = 88, // map[0:78 1:[-99 -50 125 -49 86 0 -115 74 -74 67 9 101 -87 -71 -66 -10] 3:[0 0 0 0 0 0 656 657] 4:8 252:89] (0: ObjectId, 3: ItemId[]) DetachItemContainer, // map[0:[-95 72 -77 -75 -70 34 127 73 -114 -96 28 8 75 -107 -106 125] 252:90] InvalidateItemContainer, LockItemContainer, diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs new file mode 100644 index 000000000..f71a86e35 --- /dev/null +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs @@ -0,0 +1,7 @@ +namespace StatisticsAnalysisTool.Models.NetworkModel; + +public class ContainerItem +{ + public Item Item { get; set; } + public int Quantity { get; set; } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/DiscoveredItem.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/DiscoveredItem.cs index 4849aa79a..63ef15f32 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/DiscoveredItem.cs +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/DiscoveredItem.cs @@ -11,7 +11,7 @@ public DiscoveredItem() } public long ObjectId { get; set; } - public int ItemId { get; set; } + public int ItemIndex { get; set; } public DateTime UtcDiscoveryTime { get; } public int Quantity { get; set; } public string BodyName { get; set; } diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs new file mode 100644 index 000000000..1e551d47e --- /dev/null +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; + +namespace StatisticsAnalysisTool.Models.NetworkModel; + +public class ItemContainerObject +{ + public ItemContainerObject(long? objectId, Guid containerGuid, List slotItemId) + { + ObjectId = objectId; + ContainerGuid = containerGuid; + SlotItemId = slotItemId; + } + + public long? ObjectId { get; set; } + public Guid ContainerGuid { get; set; } + public List SlotItemId { get; set; } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/Container.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/LootContainer.cs similarity index 95% rename from src/StatisticsAnalysisTool/Models/NetworkModel/Container.cs rename to src/StatisticsAnalysisTool/Models/NetworkModel/LootContainer.cs index 4a333cac4..65b9dd876 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/Container.cs +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/LootContainer.cs @@ -11,7 +11,7 @@ public enum ContainerType Player } - public class Container + public class LootContainer { public string Id { get; set; } diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs index 6c7c4cede..5a632e121 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs @@ -1,23 +1,10 @@ -using System; +using StatisticsAnalysisTool.Enumerations; using System.Collections.Generic; -using StatisticsAnalysisTool.Enumerations; namespace StatisticsAnalysisTool.Models.NetworkModel; public class Vault { - public Vault(long? objectId, VaultLocation location, List vaultGuidList, List vaultNames, List iconTags) - { - ObjectId = objectId; - Location = location; - VaultGuidList = vaultGuidList; - VaultNames = vaultNames; - IconTags = iconTags; - } - - public long? ObjectId { get; set; } public VaultLocation Location { get; set; } - public List VaultGuidList { get; set; } - public List VaultNames { get; set; } - public List IconTags { get; set; } + public List VaultContainer { get; set; } = new (); } \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs new file mode 100644 index 000000000..41ff9f608 --- /dev/null +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; + +namespace StatisticsAnalysisTool.Models.NetworkModel; + +public class VaultContainer +{ + public Guid Guid { get; set; } + public string Name { get; set; } + public string Icon { get; set; } + public List Items { get; set; } = new (); +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs new file mode 100644 index 000000000..bca739a00 --- /dev/null +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using StatisticsAnalysisTool.Enumerations; + +namespace StatisticsAnalysisTool.Models.NetworkModel; + +public class VaultInfo +{ + public VaultInfo(long? objectId, VaultLocation location, List containerGuidList, List containerNames, List containerIconTags) + { + ObjectId = objectId; + Location = location; + ContainerGuidList = containerGuidList; + ContainerNames = containerNames; + ContainerIconTags = containerIconTags; + } + + public long? ObjectId { get; set; } + public VaultLocation Location { get; set; } + public List ContainerGuidList { get; set; } + public List ContainerNames { get; set; } + public List ContainerIconTags { get; set; } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs b/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs index 1066fe1f0..6d9515e8e 100644 --- a/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs +++ b/src/StatisticsAnalysisTool/Network/AlbionPackageParser.cs @@ -48,6 +48,7 @@ public class AlbionPackageParser : PhotonParser private readonly MightFavorPointsEventHandler _mightFavorPointsEventHandler; private readonly BaseVaultInfoEventHandler _baseVaultInfoEventHandler; private readonly GuildVaultInfoEventHandler _guildVaultInfoEventHandler; + private readonly AttachItemContainerEventHandler _attachItemContainerEventHandler; private readonly UseShrineRequestHandler _useShrineRequestHandler; @@ -92,6 +93,7 @@ public AlbionPackageParser(TrackingController trackingController, MainWindowView _mightFavorPointsEventHandler = new MightFavorPointsEventHandler(trackingController); _baseVaultInfoEventHandler = new BaseVaultInfoEventHandler(trackingController); _guildVaultInfoEventHandler = new GuildVaultInfoEventHandler(trackingController); + _attachItemContainerEventHandler = new AttachItemContainerEventHandler(trackingController); _useShrineRequestHandler = new UseShrineRequestHandler(trackingController); @@ -210,6 +212,9 @@ protected override async void OnEvent(byte code, Dictionary parame case EventCodes.RecoveryVaultPlayerInfo: await RecoveryVaultPlayerInfoEventHandlerAsync(parameters).ConfigureAwait(true); return; + case EventCodes.AttachItemContainer: + await AttachItemContainerEventHandlerAsync(parameters).ConfigureAwait(true); + return; } } catch (Exception ex) @@ -487,6 +492,12 @@ private async Task RecoveryVaultPlayerInfoEventHandlerAsync(Dictionary parameters) + { + var value = new AttachItemContainerEvent(parameters); + await _attachItemContainerEventHandler.OnActionAsync(value); + } + #endregion #region Requests diff --git a/src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs b/src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs new file mode 100644 index 000000000..c7d3b4256 --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs @@ -0,0 +1,68 @@ +using StatisticsAnalysisTool.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using StatisticsAnalysisTool.Models.NetworkModel; + +namespace StatisticsAnalysisTool.Network.Events +{ + public class AttachItemContainerEvent + { + public ItemContainerObject ItemContainerObject; + private readonly long? _objectId; + private readonly Guid _containerGuid; + private readonly List _containerSlots = new(); + + public AttachItemContainerEvent(Dictionary parameters) + { + ConsoleManager.WriteLineForNetworkHandler(GetType().Name, parameters); + + try + { + if (parameters.ContainsKey(0)) + { + _objectId = parameters[0].ObjectToLong(); + } + + if (parameters.ContainsKey(2)) + { + var guid = parameters[2].ObjectToGuid(); + if (guid != null) + { + _containerGuid = (Guid)guid; + } + } + + if (parameters.ContainsKey(3) && parameters[3] != null) + { + var valueType = parameters[3].GetType(); + if (valueType.IsArray && typeof(int[]) == valueType) + { + var intArray = ((int[])parameters[3]).ToDictionary(); + + foreach (var slot in intArray) + { + _containerSlots.Add(slot.Value); + } + } + else if (valueType.IsArray && typeof(byte[]) == valueType) + { + var byteArray = ((byte[])parameters[3]).ToDictionary(); + + foreach (var slot in byteArray) + { + _containerSlots.Add(0); + } + } + } + + ItemContainerObject = new ItemContainerObject(_objectId, _containerGuid, _containerSlots); + } + catch (Exception e) + { + ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); + } + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Events/NewEquipmentItemEvent.cs b/src/StatisticsAnalysisTool/Network/Events/NewEquipmentItemEvent.cs index 36bcdee14..ac36333f9 100644 --- a/src/StatisticsAnalysisTool/Network/Events/NewEquipmentItemEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/NewEquipmentItemEvent.cs @@ -13,7 +13,7 @@ public class NewEquipmentItemEvent private readonly long? _objectId; private readonly int _itemId; private readonly int _quantity; - private Dictionary _spellDictionary { get; } = new (); + private Dictionary SpellDictionary { get; } = new (); public NewEquipmentItemEvent(Dictionary parameters) { @@ -44,7 +44,7 @@ public NewEquipmentItemEvent(Dictionary parameters) var spells = ((byte[]) parameters[8]).ToDictionary(); foreach (var spell in spells) { - _spellDictionary.Add(spell.Key, spell.Value.ObjectToInt()); + SpellDictionary.Add(spell.Key, spell.Value.ObjectToInt()); } } else if (valueType.IsArray && typeof(short[]).Name == valueType.Name) @@ -52,7 +52,7 @@ public NewEquipmentItemEvent(Dictionary parameters) var spells = ((short[]) parameters[8]).ToDictionary(); foreach (var spell in spells) { - _spellDictionary.Add(spell.Key, spell.Value.ObjectToInt()); + SpellDictionary.Add(spell.Key, spell.Value.ObjectToInt()); } } else if (valueType.IsArray && typeof(int[]).Name == valueType.Name) @@ -60,7 +60,7 @@ public NewEquipmentItemEvent(Dictionary parameters) var spells = ((int[]) parameters[8]).ToDictionary(); foreach (var spell in spells) { - _spellDictionary.Add(spell.Key, spell.Value.ObjectToInt()); + SpellDictionary.Add(spell.Key, spell.Value.ObjectToInt()); } } } @@ -70,9 +70,9 @@ public NewEquipmentItemEvent(Dictionary parameters) Item = new DiscoveredItem() { ObjectId = (long)_objectId, - ItemId = _itemId, + ItemIndex = _itemId, Quantity = _quantity, - SpellDictionary = _spellDictionary + SpellDictionary = SpellDictionary }; } else diff --git a/src/StatisticsAnalysisTool/Network/Events/NewFurnitureItemEvent.cs b/src/StatisticsAnalysisTool/Network/Events/NewFurnitureItemEvent.cs index e3f6368a1..111b49c41 100644 --- a/src/StatisticsAnalysisTool/Network/Events/NewFurnitureItemEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/NewFurnitureItemEvent.cs @@ -40,7 +40,7 @@ public NewFurnitureItemEvent(Dictionary parameters) Item = new DiscoveredItem() { ObjectId = (long)_objectId, - ItemId = _itemId, + ItemIndex = _itemId, Quantity = _quantity }; } diff --git a/src/StatisticsAnalysisTool/Network/Events/NewJournalItemEvent.cs b/src/StatisticsAnalysisTool/Network/Events/NewJournalItemEvent.cs index 2caa46348..10eb4db01 100644 --- a/src/StatisticsAnalysisTool/Network/Events/NewJournalItemEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/NewJournalItemEvent.cs @@ -40,7 +40,7 @@ public NewJournalItemEvent(Dictionary parameters) Item = new DiscoveredItem() { ObjectId = (long)_objectId, - ItemId = _itemId, + ItemIndex = _itemId, Quantity = _quantity }; } diff --git a/src/StatisticsAnalysisTool/Network/Events/NewLaborerItemEvent.cs b/src/StatisticsAnalysisTool/Network/Events/NewLaborerItemEvent.cs index d0e7f116f..cd803e529 100644 --- a/src/StatisticsAnalysisTool/Network/Events/NewLaborerItemEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/NewLaborerItemEvent.cs @@ -40,7 +40,7 @@ public NewLaborerItemEvent(Dictionary parameters) Item = new DiscoveredItem() { ObjectId = (long)_objectId, - ItemId = _itemId, + ItemIndex = _itemId, Quantity = _quantity }; } diff --git a/src/StatisticsAnalysisTool/Network/Events/NewLootEvent.cs b/src/StatisticsAnalysisTool/Network/Events/NewLootEvent.cs index fc0ff4641..f611122b8 100644 --- a/src/StatisticsAnalysisTool/Network/Events/NewLootEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/NewLootEvent.cs @@ -21,7 +21,7 @@ public NewLootEvent(Dictionary parameters) // 2 = mob id? var bodyName = (string) parameters[3]; - var container = new Container + var container = new LootContainer { Id = containerId, Owner = bodyName, Type = BodyName.StartsWith("@MOB") ? ContainerType.Monster : ContainerType.Player diff --git a/src/StatisticsAnalysisTool/Network/Events/NewSimpleItemEvent.cs b/src/StatisticsAnalysisTool/Network/Events/NewSimpleItemEvent.cs index c32663975..998294c48 100644 --- a/src/StatisticsAnalysisTool/Network/Events/NewSimpleItemEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/NewSimpleItemEvent.cs @@ -40,7 +40,7 @@ public NewSimpleItemEvent(Dictionary parameters) Item = new DiscoveredItem() { ObjectId = (long)_objectId, - ItemId = _itemId, + ItemIndex = _itemId, Quantity = _quantity }; } diff --git a/src/StatisticsAnalysisTool/Network/Handler/AttachItemContainerEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/AttachItemContainerEventHandler.cs new file mode 100644 index 000000000..5125e3ec4 --- /dev/null +++ b/src/StatisticsAnalysisTool/Network/Handler/AttachItemContainerEventHandler.cs @@ -0,0 +1,26 @@ +using StatisticsAnalysisTool.Network.Events; +using StatisticsAnalysisTool.Network.Manager; +using System.Threading.Tasks; + +namespace StatisticsAnalysisTool.Network.Handler +{ + public class AttachItemContainerEventHandler + { + private readonly TrackingController _trackingController; + + public AttachItemContainerEventHandler(TrackingController trackingController) + { + _trackingController = trackingController; + } + + public async Task OnActionAsync(AttachItemContainerEvent value) + { + if (_trackingController.IsTrackingAllowedByMainCharacter()) + { + _trackingController.VaultController.AddContainer(value.ItemContainerObject); + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs index 7ce8289ba..4546e1563 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/BaseVaultInfoEventHandler.cs @@ -18,7 +18,7 @@ public async Task OnActionAsync(BaseVaultInfoEvent value) { if (_trackingController.IsTrackingAllowedByMainCharacter()) { - _trackingController.VaultController.SetCurrentVault(new Vault(value.ObjectId, value.Location, value.VaultGuidList, value.VaultNames, value.IconTags)); + _trackingController.VaultController.SetCurrentVault(new VaultInfo(value.ObjectId, value.Location, value.VaultGuidList, value.VaultNames, value.IconTags)); } await Task.CompletedTask; diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs index 40d9f5594..6b851cb57 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs @@ -24,7 +24,7 @@ public async Task OnActionAsync(NewEquipmentItemEvent value) _trackingController.EntityController.AddEquipmentItem(new EquipmentItemInternal { - ItemIndex = value.Item.ItemId, + ItemIndex = value.Item.ItemIndex, SpellDictionary = value.Item.SpellDictionary }); await Task.CompletedTask; diff --git a/src/StatisticsAnalysisTool/Network/Manager/LootController.cs b/src/StatisticsAnalysisTool/Network/Manager/LootController.cs index d44481b10..68a4450fb 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/LootController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/LootController.cs @@ -144,8 +144,8 @@ private async Task LootMergeAsync() var loot = new Loot() { LootedBody = discoveredLoot.BodyName, - IsTrash = ItemController.IsTrash(discoveredLoot.ItemId), - ItemIndex = discoveredLoot.ItemId, + IsTrash = ItemController.IsTrash(discoveredLoot.ItemIndex), + ItemIndex = discoveredLoot.ItemIndex, LooterName = discoveredLoot.LooterName, Quantity = discoveredLoot.Quantity }; diff --git a/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs b/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs index 7fddd89b7..7b9bac4fe 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs @@ -101,6 +101,7 @@ public void SetNewCluster(MapType mapType, Guid? mapGuid, string clusterIndex, s StatisticController.SetKillsDeathsValues(); VaultController.ResetDiscoveredItems(); + VaultController.ResetVaultContainer(); } private bool TryChangeCluster(string index, string mapName) diff --git a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs index 8bea709c5..6cb059b4c 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using StatisticsAnalysisTool.Common; namespace StatisticsAnalysisTool.Network.Manager; @@ -15,8 +16,10 @@ public class VaultController private readonly TrackingController _trackingController; private readonly MainWindowViewModel _mainWindowViewModel; - private Vault _currentVault; - private List _discoveredItems = new (); + private VaultInfo _currentVaultInfo; + private readonly List _discoveredItems = new (); + private readonly List _vaultContainer = new (); + private readonly List _vaults = new (); public VaultController(TrackingController trackingController, MainWindowViewModel mainWindowViewModel) { @@ -24,9 +27,9 @@ public VaultController(TrackingController trackingController, MainWindowViewMode _mainWindowViewModel = mainWindowViewModel; } - public void SetCurrentVault(Vault vault) + public void SetCurrentVault(VaultInfo vaultInfo) { - _currentVault = vault; + _currentVaultInfo = vaultInfo; } public void Add(DiscoveredItem item) @@ -44,6 +47,100 @@ public void ResetDiscoveredItems() _discoveredItems.Clear(); } + public void AddContainer(ItemContainerObject newContainerObject) + { + if (newContainerObject?.ContainerGuid == default) + { + return; + } + + var container = _vaultContainer.FirstOrDefault(x => x.ContainerGuid == newContainerObject.ContainerGuid); + if (container != null) + { + _vaultContainer.Remove(container); + } + + _vaultContainer.Add(newContainerObject); + + ParseVault(); + } + + public void ResetVaultContainer() + { + _vaultContainer.Clear(); + } + + private void ParseVault() + { + if (_currentVaultInfo == null) + { + return; + } + + var removableVaultInfo = _vaults.FirstOrDefault(x => x.Location == _currentVaultInfo.Location); + + if (removableVaultInfo != null) + { + _vaults.Remove(removableVaultInfo); + } + + var vault = new Vault() + { + Location = _currentVaultInfo.Location + }; + + try + { + for (var i = 0; i < _currentVaultInfo.ContainerGuidList.Count; i++) + { + var vaultContainer = new VaultContainer() + { + Guid = _currentVaultInfo.ContainerGuidList[i], + Icon = _currentVaultInfo.ContainerIconTags[i], + Name = _currentVaultInfo.ContainerNames[i] + }; + + var itemContainer = _vaultContainer.FirstOrDefault(x => x.ContainerGuid == vaultContainer.Guid); + + SetItemsToVaultContainer(itemContainer, vaultContainer, _discoveredItems); + + vault.VaultContainer.Add(vaultContainer); + } + + _vaults.Add(vault); + } + catch (Exception e) + { + ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); + } + } + + private void SetItemsToVaultContainer(ItemContainerObject containerObject, VaultContainer vaultContainer, List discoveredItems) + { + foreach (var slotItemId in containerObject?.SlotItemId ?? new List()) + { + var slotItem = discoveredItems.FirstOrDefault(x => x.ObjectId == slotItemId); + + if (slotItem == null || slotItem.ItemIndex == 0) + { + vaultContainer.Items.Add(new ContainerItem() + { + Item = null, + Quantity = 0 + }); + + continue; + } + + var item = ItemController.GetItemByIndex(slotItem.ItemIndex); + vaultContainer.Items.Add(new ContainerItem() + { + Item = item, + Quantity = slotItem.Quantity + }); + } + } + public static VaultLocation GetVaultLocation(string value) { var clusterInfoArray = value.Split("@"); From ffe4ca29e98dd389136b082b8ecb687fbf607db5 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 20 Apr 2022 12:39:11 +0200 Subject: [PATCH 4/7] Added save/load vault file + ui components --- src/StatisticsAnalysisTool/App.config | 3 + src/StatisticsAnalysisTool/App.xaml | 1 + .../Common/Locations.cs | 63 ++++++------ .../Models/BindingModel/VaultBindings.cs | 52 ++++++++++ .../Models/NetworkModel/ContainerItem.cs | 9 +- .../Models/NetworkModel/Vault.cs | 11 ++- .../Models/NetworkModel/VaultInfo.cs | 6 +- .../Models/VaultContainerContent.cs | 7 ++ .../Network/Events/BaseVaultInfoEvent.cs | 12 +-- .../Network/Manager/VaultController.cs | 95 +++++++++++++++++-- .../Properties/Settings.Designer.cs | 12 +++ .../Properties/Settings.settings | 3 + .../StatisticsAnalysisTool.csproj | 8 ++ .../Styles/StorageHistoryStyle.xaml | 3 + .../UserControls/StorageHistoryControl.xaml | 22 +++++ .../StorageHistoryControl.xaml.cs | 13 +++ .../ViewModels/MainWindowViewModel.cs | 14 +++ .../Views/MainWindow.xaml | 5 + 18 files changed, 286 insertions(+), 53 deletions(-) create mode 100644 src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs create mode 100644 src/StatisticsAnalysisTool/Models/VaultContainerContent.cs create mode 100644 src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml create mode 100644 src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml create mode 100644 src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml.cs diff --git a/src/StatisticsAnalysisTool/App.config b/src/StatisticsAnalysisTool/App.config index 0438cec2d..11d2f649a 100644 --- a/src/StatisticsAnalysisTool/App.config +++ b/src/StatisticsAnalysisTool/App.config @@ -67,6 +67,9 @@ Mails.json + + Vaults.json + diff --git a/src/StatisticsAnalysisTool/App.xaml b/src/StatisticsAnalysisTool/App.xaml index c577e1523..8a01aee4f 100644 --- a/src/StatisticsAnalysisTool/App.xaml +++ b/src/StatisticsAnalysisTool/App.xaml @@ -23,6 +23,7 @@ + diff --git a/src/StatisticsAnalysisTool/Common/Locations.cs b/src/StatisticsAnalysisTool/Common/Locations.cs index 9863d51e7..6dc27d923 100644 --- a/src/StatisticsAnalysisTool/Common/Locations.cs +++ b/src/StatisticsAnalysisTool/Common/Locations.cs @@ -1,11 +1,10 @@ -using System; using LiveChartsCore.SkiaSharpView.Painting; using SkiaSharp; +using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Media; -using StatisticsAnalysisTool.Enumerations; namespace StatisticsAnalysisTool.Common { @@ -13,40 +12,40 @@ public static class Locations { public static readonly Dictionary Names = new() { - {Location.Thetford, "Thetford"}, - {Location.SwampCross, "Swamp Cross"}, - {Location.Lymhurst, "Lymhurst"}, - {Location.ForestCross, "Forest Cross"}, - {Location.Bridgewatch, "Bridgewatch"}, - {Location.SteppeCross, "Steppe Cross"}, - {Location.HighlandCross, "Highland Cross"}, - {Location.BlackMarket, "Black Market"}, - {Location.Martlock, "Martlock"}, - {Location.Caerleon, "Caerleon"}, - {Location.FortSterling, "Fort Sterling"}, - {Location.MountainCross, "Mountain Cross"}, - {Location.ArthursRest, "Arthur's Rest"}, - {Location.MerlynsRest, "Merlyn's Rest"}, - {Location.MorganasRest, "Morgana's Rest"} + { Location.Thetford, "Thetford" }, + { Location.SwampCross, "Swamp Cross" }, + { Location.Lymhurst, "Lymhurst" }, + { Location.ForestCross, "Forest Cross" }, + { Location.Bridgewatch, "Bridgewatch" }, + { Location.SteppeCross, "Steppe Cross" }, + { Location.HighlandCross, "Highland Cross" }, + { Location.BlackMarket, "Black Market" }, + { Location.Martlock, "Martlock" }, + { Location.Caerleon, "Caerleon" }, + { Location.FortSterling, "Fort Sterling" }, + { Location.MountainCross, "Mountain Cross" }, + { Location.ArthursRest, "Arthur's Rest" }, + { Location.MerlynsRest, "Merlyn's Rest" }, + { Location.MorganasRest, "Morgana's Rest" } }; public static readonly Dictionary ParameterNames = new() { - {Location.Thetford, "Thetford"}, - {Location.SwampCross, "Swamp Cross"}, - {Location.Lymhurst, "Lymhurst"}, - {Location.ForestCross, "Forest Cross"}, - {Location.Bridgewatch, "Bridgewatch"}, - {Location.SteppeCross, "Steppe Cross"}, - {Location.HighlandCross, "Highland Cross"}, - {Location.BlackMarket, "Black Market"}, - {Location.Martlock, "Martlock"}, - {Location.Caerleon, "Caerleon"}, - {Location.FortSterling, "Fort Sterling"}, - {Location.MountainCross, "Mountain Cross"}, - {Location.ArthursRest, "Arthurs Rest"}, - {Location.MerlynsRest, "Merlyns Rest"}, - {Location.MorganasRest, "Morganas Rest"} + { Location.Thetford, "Thetford" }, + { Location.SwampCross, "Swamp Cross" }, + { Location.Lymhurst, "Lymhurst" }, + { Location.ForestCross, "Forest Cross" }, + { Location.Bridgewatch, "Bridgewatch" }, + { Location.SteppeCross, "Steppe Cross" }, + { Location.HighlandCross, "Highland Cross" }, + { Location.BlackMarket, "Black Market" }, + { Location.Martlock, "Martlock" }, + { Location.Caerleon, "Caerleon" }, + { Location.FortSterling, "Fort Sterling" }, + { Location.MountainCross, "Mountain Cross" }, + { Location.ArthursRest, "Arthurs Rest" }, + { Location.MerlynsRest, "Merlyns Rest" }, + { Location.MorganasRest, "Morganas Rest" } }; public static string GetName(Location location) diff --git a/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs b/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs new file mode 100644 index 000000000..c3ad336bf --- /dev/null +++ b/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs @@ -0,0 +1,52 @@ +using StatisticsAnalysisTool.Models.NetworkModel; +using StatisticsAnalysisTool.Properties; +using System.Collections.Generic; +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace StatisticsAnalysisTool.Models.BindingModel; + +public class VaultBindings : INotifyPropertyChanged +{ + private VaultContainerContent _vaultContainerContent; + private List _vaults; + private Vault _vaultSelected; + + public List Vaults + { + get => _vaults; + set + { + _vaults = value; + OnPropertyChanged(); + } + } + + public Vault VaultSelected + { + get => _vaultSelected; + set + { + _vaultSelected = value; + OnPropertyChanged(); + } + } + + public VaultContainerContent VaultContainerContent + { + get => _vaultContainerContent; + set + { + _vaultContainerContent = value; + OnPropertyChanged(); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs index f71a86e35..32881110d 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs @@ -1,7 +1,12 @@ -namespace StatisticsAnalysisTool.Models.NetworkModel; +using System.Text.Json.Serialization; +using StatisticsAnalysisTool.Common; + +namespace StatisticsAnalysisTool.Models.NetworkModel; public class ContainerItem { - public Item Item { get; set; } + public int ItemIndex { get; set; } + [JsonIgnore] + public Item Item => ItemController.GetItemByIndex(ItemIndex); public int Quantity { get; set; } } \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs index 5a632e121..e6ec55a6f 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs @@ -1,10 +1,17 @@ using StatisticsAnalysisTool.Enumerations; +using StatisticsAnalysisTool.GameData; +using StatisticsAnalysisTool.Network.Manager; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace StatisticsAnalysisTool.Models.NetworkModel; public class Vault { - public VaultLocation Location { get; set; } - public List VaultContainer { get; set; } = new (); + public string Location { get; set; } + [JsonIgnore] + public VaultLocation VaultLocation => VaultController.GetVaultLocation(Location); + [JsonIgnore] + public string LocationName => WorldData.GetUniqueNameOrDefault(VaultController.GetVaultLocationIndex(Location)); + public List VaultContainer { get; set; } = new(); } \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs index bca739a00..0fc71202d 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs @@ -1,12 +1,13 @@ using System; using System.Collections.Generic; using StatisticsAnalysisTool.Enumerations; +using StatisticsAnalysisTool.Network.Manager; namespace StatisticsAnalysisTool.Models.NetworkModel; public class VaultInfo { - public VaultInfo(long? objectId, VaultLocation location, List containerGuidList, List containerNames, List containerIconTags) + public VaultInfo(long? objectId, string location, List containerGuidList, List containerNames, List containerIconTags) { ObjectId = objectId; Location = location; @@ -16,7 +17,8 @@ public VaultInfo(long? objectId, VaultLocation location, List containerGui } public long? ObjectId { get; set; } - public VaultLocation Location { get; set; } + public string Location { get; set; } + public VaultLocation VaultLocation => VaultController.GetVaultLocation(Location); public List ContainerGuidList { get; set; } public List ContainerNames { get; set; } public List ContainerIconTags { get; set; } diff --git a/src/StatisticsAnalysisTool/Models/VaultContainerContent.cs b/src/StatisticsAnalysisTool/Models/VaultContainerContent.cs new file mode 100644 index 000000000..17f6361a7 --- /dev/null +++ b/src/StatisticsAnalysisTool/Models/VaultContainerContent.cs @@ -0,0 +1,7 @@ +namespace StatisticsAnalysisTool.Models; + +public class VaultContainerContent +{ + public Item Item { get; set; } + public int Quantity { get; set; } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Events/BaseVaultInfoEvent.cs b/src/StatisticsAnalysisTool/Network/Events/BaseVaultInfoEvent.cs index 0233d1f10..e5cf236b4 100644 --- a/src/StatisticsAnalysisTool/Network/Events/BaseVaultInfoEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/BaseVaultInfoEvent.cs @@ -2,18 +2,16 @@ using System; using System.Collections.Generic; using System.Reflection; -using StatisticsAnalysisTool.Enumerations; -using StatisticsAnalysisTool.Network.Manager; namespace StatisticsAnalysisTool.Network.Events { public class BaseVaultInfoEvent { public long? ObjectId; - public VaultLocation Location; - public List VaultGuidList = new (); - public List VaultNames = new (); - public List IconTags = new (); + public string Location; + public List VaultGuidList = new(); + public List VaultNames = new(); + public List IconTags = new(); public BaseVaultInfoEvent(Dictionary parameters) { @@ -28,7 +26,7 @@ public BaseVaultInfoEvent(Dictionary parameters) if (parameters.ContainsKey(1)) { - Location = VaultController.GetVaultLocation(parameters[1].ToString()); + Location = parameters[1].ToString(); } if (parameters.ContainsKey(2) && parameters[2] != null) diff --git a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs index 6cb059b4c..c7aec0e15 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs @@ -1,12 +1,19 @@ using log4net; +using StatisticsAnalysisTool.Common; using StatisticsAnalysisTool.Enumerations; using StatisticsAnalysisTool.Models.NetworkModel; +using StatisticsAnalysisTool.Properties; using StatisticsAnalysisTool.ViewModels; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.IO; using System.Linq; using System.Reflection; -using StatisticsAnalysisTool.Common; +using System.Text; +using System.Text.Json; +using System.Windows; namespace StatisticsAnalysisTool.Network.Manager; @@ -17,18 +24,27 @@ public class VaultController private readonly TrackingController _trackingController; private readonly MainWindowViewModel _mainWindowViewModel; private VaultInfo _currentVaultInfo; - private readonly List _discoveredItems = new (); - private readonly List _vaultContainer = new (); - private readonly List _vaults = new (); + private readonly List _discoveredItems = new(); + private readonly List _vaultContainer = new(); + private ObservableCollection _vaults = new(); public VaultController(TrackingController trackingController, MainWindowViewModel mainWindowViewModel) { _trackingController = trackingController; _mainWindowViewModel = mainWindowViewModel; + + OnVaultsChange += UpdateUi; } + public event Action OnVaultsChange; + public void SetCurrentVault(VaultInfo vaultInfo) { + if (vaultInfo == null || vaultInfo.VaultLocation == VaultLocation.Unknown) + { + return; + } + _currentVaultInfo = vaultInfo; } @@ -72,7 +88,7 @@ public void ResetVaultContainer() private void ParseVault() { - if (_currentVaultInfo == null) + if (_currentVaultInfo == null || GetVaultLocation(_currentVaultInfo?.Location) == VaultLocation.Unknown) { return; } @@ -108,6 +124,7 @@ private void ParseVault() } _vaults.Add(vault); + OnVaultsChange?.Invoke(); } catch (Exception e) { @@ -125,17 +142,16 @@ private void SetItemsToVaultContainer(ItemContainerObject containerObject, Vault { vaultContainer.Items.Add(new ContainerItem() { - Item = null, + ItemIndex = 0, Quantity = 0 }); continue; } - var item = ItemController.GetItemByIndex(slotItem.ItemIndex); vaultContainer.Items.Add(new ContainerItem() { - Item = item, + ItemIndex = slotItem.ItemIndex, Quantity = slotItem.Quantity }); } @@ -147,6 +163,69 @@ public static VaultLocation GetVaultLocation(string value) return clusterInfoArray.ElementAtOrDefault(1) != null ? GetVaultLocationByIndex(clusterInfoArray[1]) : VaultLocation.Unknown; } + public static string GetVaultLocationIndex(string value) + { + var clusterInfoArray = value.Split("@"); + return clusterInfoArray.ElementAtOrDefault(1) != null ? clusterInfoArray[1] : "UNKNOWN"; + } + + #region Ui + + private void UpdateUi() + { + Application.Current.Dispatcher.Invoke(() => + { + _mainWindowViewModel.VaultBindings.Vaults = _vaults.ToList(); + }); + } + + #endregion + + #region Load / Save local file data + + public void LoadFromFile() + { + var localFilePath = $"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.VaultsFileName}"; + + if (File.Exists(localFilePath)) + { + try + { + var localFileString = File.ReadAllText(localFilePath, Encoding.UTF8); + var vaults = JsonSerializer.Deserialize>(localFileString) ?? new List(); + _vaults = new ObservableCollection(vaults); + return; + } + catch (Exception e) + { + ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); + Log.Error(MethodBase.GetCurrentMethod()?.DeclaringType, e); + _vaults = new ObservableCollection(); + return; + } + } + + _vaults = new ObservableCollection(); + } + + public void SaveInFile() + { + var localFilePath = $"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.VaultsFileName}"; + + try + { + var fileString = JsonSerializer.Serialize(_vaults); + File.WriteAllText(localFilePath, fileString, Encoding.UTF8); + } + catch (Exception e) + { + ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); + Log.Error(MethodBase.GetCurrentMethod()?.DeclaringType, e); + } + } + + #endregion + #region Helper methods private static VaultLocation GetVaultLocationByIndex(string index) diff --git a/src/StatisticsAnalysisTool/Properties/Settings.Designer.cs b/src/StatisticsAnalysisTool/Properties/Settings.Designer.cs index db0d41d8d..0dcae18df 100644 --- a/src/StatisticsAnalysisTool/Properties/Settings.Designer.cs +++ b/src/StatisticsAnalysisTool/Properties/Settings.Designer.cs @@ -367,5 +367,17 @@ public string MailsFileName { this["MailsFileName"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("Vaults.json")] + public string VaultsFileName { + get { + return ((string)(this["VaultsFileName"])); + } + set { + this["VaultsFileName"] = value; + } + } } } diff --git a/src/StatisticsAnalysisTool/Properties/Settings.settings b/src/StatisticsAnalysisTool/Properties/Settings.settings index fdcaf9150..4afe550a5 100644 --- a/src/StatisticsAnalysisTool/Properties/Settings.settings +++ b/src/StatisticsAnalysisTool/Properties/Settings.settings @@ -98,5 +98,8 @@ Mails.json + + Vaults.json + \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/StatisticsAnalysisTool.csproj b/src/StatisticsAnalysisTool/StatisticsAnalysisTool.csproj index 787a9a261..98098fd52 100644 --- a/src/StatisticsAnalysisTool/StatisticsAnalysisTool.csproj +++ b/src/StatisticsAnalysisTool/StatisticsAnalysisTool.csproj @@ -396,6 +396,10 @@ + + $(DefaultXamlRuntime) + Designer + $(DefaultXamlRuntime) Designer @@ -472,11 +476,15 @@ $(DefaultXamlRuntime) Designer + + $(DefaultXamlRuntime) + $(DefaultXamlRuntime) + \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml b/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml new file mode 100644 index 000000000..d451e5f66 --- /dev/null +++ b/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml b/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml new file mode 100644 index 000000000..9667f2dae --- /dev/null +++ b/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml @@ -0,0 +1,22 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml.cs b/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml.cs new file mode 100644 index 000000000..b5aa0b96b --- /dev/null +++ b/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml.cs @@ -0,0 +1,13 @@ +namespace StatisticsAnalysisTool.UserControls +{ + /// + /// Interaction logic for StorageHistoryControl.xaml + /// + public partial class StorageHistoryControl + { + public StorageHistoryControl() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs b/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs index 9f1d867f5..ed6934321 100644 --- a/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs +++ b/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs @@ -26,6 +26,7 @@ using System.Windows; using System.Windows.Data; using System.Windows.Media; +using StatisticsAnalysisTool.Models.BindingModel; // ReSharper disable UnusedMember.Global @@ -133,6 +134,7 @@ public class MainWindowViewModel : INotifyPropertyChanged private string _mailsSearchText; private DateTime _datePickerMailsFrom = new (2017, 1, 1); private DateTime _datePickerMailsTo = DateTime.UtcNow.AddDays(1); + private VaultBindings _vaultBindings = new (); public MainWindowViewModel(MainWindow mainWindow) { @@ -710,6 +712,7 @@ public void StartTracking() TrackingController?.DungeonController?.SetOrUpdateDungeonsDataUiAsync(); TrackingController?.StatisticController?.LoadFromFile(); TrackingController?.MailController?.LoadFromFile(); + TrackingController?.VaultController?.LoadFromFile(); TrackingController?.CountUpTimer.Start(); @@ -724,6 +727,7 @@ public void StopTracking() TrackingController?.DungeonController?.SaveDungeonsInFile(); TrackingController?.StatisticController?.SaveInFile(); TrackingController?.MailController?.SaveInFile(); + TrackingController?.VaultController?.SaveInFile(); TrackingController?.UnregisterEvents(); TrackingController?.CountUpTimer?.Stop(); @@ -1877,6 +1881,16 @@ public MailStatsObject MailStatsObject } } + public VaultBindings VaultBindings + { + get => _vaultBindings; + set + { + _vaultBindings = value; + OnPropertyChanged(); + } + } + public string MailsSearchText { get => _mailsSearchText; diff --git a/src/StatisticsAnalysisTool/Views/MainWindow.xaml b/src/StatisticsAnalysisTool/Views/MainWindow.xaml index 98460e1df..d37fda593 100644 --- a/src/StatisticsAnalysisTool/Views/MainWindow.xaml +++ b/src/StatisticsAnalysisTool/Views/MainWindow.xaml @@ -151,6 +151,11 @@ + + + + + From 2f2225cefd9e2dfab4e6d72181105db3352a4f0d Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 20 Apr 2022 15:09:56 +0200 Subject: [PATCH 5/7] Added ui style and bindings --- .../Models/BindingModel/VaultBindings.cs | 29 +++++++++++++++++-- .../Models/VaultContainerContent.cs | 7 ----- .../Events/AttachItemContainerEvent.cs | 9 +++--- .../Network/Manager/VaultController.cs | 8 ++++- .../Styles/StorageHistoryStyle.xaml | 25 +++++++++++++++- .../UserControls/StorageHistoryControl.xaml | 17 +++++++---- .../ViewModels/MainWindowViewModel.cs | 3 +- 7 files changed, 76 insertions(+), 22 deletions(-) delete mode 100644 src/StatisticsAnalysisTool/Models/VaultContainerContent.cs diff --git a/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs b/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs index c3ad336bf..ae0e01dc7 100644 --- a/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs +++ b/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs @@ -2,15 +2,18 @@ using StatisticsAnalysisTool.Properties; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; using System.Runtime.CompilerServices; namespace StatisticsAnalysisTool.Models.BindingModel; public class VaultBindings : INotifyPropertyChanged { - private VaultContainerContent _vaultContainerContent; + private List _vaultContainerContent; private List _vaults; private Vault _vaultSelected; + private List _vaultContainer; + private VaultContainer _vaultContainerSelected; public List Vaults { @@ -28,11 +31,33 @@ public Vault VaultSelected set { _vaultSelected = value; + VaultContainer = _vaultSelected.VaultContainer; OnPropertyChanged(); } } - public VaultContainerContent VaultContainerContent + public List VaultContainer + { + get => _vaultContainer; + set + { + _vaultContainer = value; + OnPropertyChanged(); + } + } + + public VaultContainer VaultContainerSelected + { + get => _vaultContainerSelected; + set + { + _vaultContainerSelected = value; + VaultContainerContent = _vaultContainer?.FirstOrDefault(x => x.Guid == _vaultContainerSelected.Guid)?.Items ?? new List(); + OnPropertyChanged(); + } + } + + public List VaultContainerContent { get => _vaultContainerContent; set diff --git a/src/StatisticsAnalysisTool/Models/VaultContainerContent.cs b/src/StatisticsAnalysisTool/Models/VaultContainerContent.cs deleted file mode 100644 index 17f6361a7..000000000 --- a/src/StatisticsAnalysisTool/Models/VaultContainerContent.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace StatisticsAnalysisTool.Models; - -public class VaultContainerContent -{ - public Item Item { get; set; } - public int Quantity { get; set; } -} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs b/src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs index c7d3b4256..ce3c4c55a 100644 --- a/src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs @@ -1,9 +1,8 @@ using StatisticsAnalysisTool.Common; +using StatisticsAnalysisTool.Models.NetworkModel; using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; -using StatisticsAnalysisTool.Models.NetworkModel; namespace StatisticsAnalysisTool.Network.Events { @@ -37,9 +36,9 @@ public AttachItemContainerEvent(Dictionary parameters) if (parameters.ContainsKey(3) && parameters[3] != null) { var valueType = parameters[3].GetType(); - if (valueType.IsArray && typeof(int[]) == valueType) + if (valueType.IsArray && typeof(short[]) == valueType) { - var intArray = ((int[])parameters[3]).ToDictionary(); + var intArray = ((short[])parameters[3]).ToDictionary(); foreach (var slot in intArray) { @@ -50,7 +49,7 @@ public AttachItemContainerEvent(Dictionary parameters) { var byteArray = ((byte[])parameters[3]).ToDictionary(); - foreach (var slot in byteArray) + foreach (var unused in byteArray) { _containerSlots.Add(0); } diff --git a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs index c7aec0e15..0e5eea2c8 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs @@ -14,6 +14,7 @@ using System.Text; using System.Text.Json; using System.Windows; +using StatisticsAnalysisTool.Models.BindingModel; namespace StatisticsAnalysisTool.Network.Manager; @@ -175,7 +176,12 @@ private void UpdateUi() { Application.Current.Dispatcher.Invoke(() => { - _mainWindowViewModel.VaultBindings.Vaults = _vaults.ToList(); + var unknownVaultSelection = new Vault() { Location = "UNKNOWN" }; + var list = _vaults.ToList(); + list.Insert(0, unknownVaultSelection); + + _mainWindowViewModel.VaultBindings.Vaults = list; + _mainWindowViewModel.VaultBindings.VaultSelected = unknownVaultSelection; }); } diff --git a/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml b/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml index d451e5f66..671d9b4cf 100644 --- a/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml +++ b/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml @@ -1,3 +1,26 @@ - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml b/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml index 9667f2dae..f90073816 100644 --- a/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml +++ b/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml @@ -9,14 +9,21 @@ d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel}"> - - + + + - + + + + + + + \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs b/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs index ed6934321..8829ad66f 100644 --- a/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs +++ b/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs @@ -135,6 +135,7 @@ public class MainWindowViewModel : INotifyPropertyChanged private DateTime _datePickerMailsFrom = new (2017, 1, 1); private DateTime _datePickerMailsTo = DateTime.UtcNow.AddDays(1); private VaultBindings _vaultBindings = new (); + private Vault _vaultSelected; public MainWindowViewModel(MainWindow mainWindow) { @@ -1890,7 +1891,7 @@ public VaultBindings VaultBindings OnPropertyChanged(); } } - + public string MailsSearchText { get => _mailsSearchText; From 2f9de3f74c8d0275de2d8fd70d7b4813ccca113a Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 20 Apr 2022 15:23:15 +0200 Subject: [PATCH 6/7] Update vault ui on change --- .../Network/Manager/VaultController.cs | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs index 0e5eea2c8..1e4bceadd 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs @@ -27,7 +27,17 @@ public class VaultController private VaultInfo _currentVaultInfo; private readonly List _discoveredItems = new(); private readonly List _vaultContainer = new(); - private ObservableCollection _vaults = new(); + private ObservableCollection _vault = new(); + + private ObservableCollection Vaults + { + get => _vault; + set + { + _vault = value; + OnVaultsChange?.Invoke(); + } + } public VaultController(TrackingController trackingController, MainWindowViewModel mainWindowViewModel) { @@ -94,11 +104,11 @@ private void ParseVault() return; } - var removableVaultInfo = _vaults.FirstOrDefault(x => x.Location == _currentVaultInfo.Location); + var removableVaultInfo = Vaults.FirstOrDefault(x => x.Location == _currentVaultInfo.Location); if (removableVaultInfo != null) { - _vaults.Remove(removableVaultInfo); + Vaults.Remove(removableVaultInfo); } var vault = new Vault() @@ -124,7 +134,7 @@ private void ParseVault() vault.VaultContainer.Add(vaultContainer); } - _vaults.Add(vault); + Vaults.Add(vault); OnVaultsChange?.Invoke(); } catch (Exception e) @@ -177,7 +187,7 @@ private void UpdateUi() Application.Current.Dispatcher.Invoke(() => { var unknownVaultSelection = new Vault() { Location = "UNKNOWN" }; - var list = _vaults.ToList(); + var list = Vaults.ToList(); list.Insert(0, unknownVaultSelection); _mainWindowViewModel.VaultBindings.Vaults = list; @@ -199,19 +209,19 @@ public void LoadFromFile() { var localFileString = File.ReadAllText(localFilePath, Encoding.UTF8); var vaults = JsonSerializer.Deserialize>(localFileString) ?? new List(); - _vaults = new ObservableCollection(vaults); + Vaults = new ObservableCollection(vaults); return; } catch (Exception e) { ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); Log.Error(MethodBase.GetCurrentMethod()?.DeclaringType, e); - _vaults = new ObservableCollection(); + Vaults = new ObservableCollection(); return; } } - _vaults = new ObservableCollection(); + Vaults = new ObservableCollection(); } public void SaveInFile() @@ -220,7 +230,7 @@ public void SaveInFile() try { - var fileString = JsonSerializer.Serialize(_vaults); + var fileString = JsonSerializer.Serialize(Vaults); File.WriteAllText(localFilePath, fileString, Encoding.UTF8); } catch (Exception e) From ed74e115566330893ebcaacea69cb08c7b3e3085 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 20 Apr 2022 17:08:46 +0200 Subject: [PATCH 7/7] Added vault info reset + translations --- .../Languages/de-DE.xml | 2 + .../Languages/en-US.xml | 2 + .../Models/BindingModel/VaultBindings.cs | 30 +++++++++++++- .../Models/MainWindowTranslation.cs | 1 + .../NetworkModel/ItemContainerObject.cs | 3 ++ .../Models/NetworkModel/VaultContainer.cs | 1 + .../Events/AttachItemContainerEvent.cs | 11 ++++- .../Network/Manager/TrackingController.cs | 3 +- .../Network/Manager/VaultController.cs | 40 +++++++++---------- .../UserControls/StorageHistoryControl.xaml | 7 ++++ 10 files changed, 76 insertions(+), 24 deletions(-) diff --git a/src/StatisticsAnalysisTool/Languages/de-DE.xml b/src/StatisticsAnalysisTool/Languages/de-DE.xml index 93bbdc6c5..e3e492035 100644 --- a/src/StatisticsAnalysisTool/Languages/de-DE.xml +++ b/src/StatisticsAnalysisTool/Languages/de-DE.xml @@ -560,4 +560,6 @@ Verkauf abgelaufen Kauf abgelaufen bis + Lager Historie + Bank \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Languages/en-US.xml b/src/StatisticsAnalysisTool/Languages/en-US.xml index 3689cf00b..081f70d0b 100644 --- a/src/StatisticsAnalysisTool/Languages/en-US.xml +++ b/src/StatisticsAnalysisTool/Languages/en-US.xml @@ -560,4 +560,6 @@ Sell expired Buy expired to + Storage History + Bank \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs b/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs index ae0e01dc7..f8167975f 100644 --- a/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs +++ b/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs @@ -1,9 +1,11 @@ -using StatisticsAnalysisTool.Models.NetworkModel; +using System; +using StatisticsAnalysisTool.Models.NetworkModel; using StatisticsAnalysisTool.Properties; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; +using System.Windows; namespace StatisticsAnalysisTool.Models.BindingModel; @@ -14,6 +16,8 @@ public class VaultBindings : INotifyPropertyChanged private Vault _vaultSelected; private List _vaultContainer; private VaultContainer _vaultContainerSelected; + private Visibility _lastUpdateVisibility = Visibility.Hidden; + private DateTime _lastUpdate; public List Vaults { @@ -31,7 +35,7 @@ public Vault VaultSelected set { _vaultSelected = value; - VaultContainer = _vaultSelected.VaultContainer; + VaultContainer = _vaultSelected.VaultContainer.FindAll(x => x.LastUpdate.Ticks > 0).OrderBy(y => y.Name).ToList(); OnPropertyChanged(); } } @@ -53,6 +57,8 @@ public VaultContainer VaultContainerSelected { _vaultContainerSelected = value; VaultContainerContent = _vaultContainer?.FirstOrDefault(x => x.Guid == _vaultContainerSelected.Guid)?.Items ?? new List(); + LastUpdate = _vaultContainerSelected?.LastUpdate ?? new DateTime(0); + LastUpdateVisibility = _vaultContainerSelected?.LastUpdate.Ticks <= 1 ? Visibility.Hidden : Visibility.Visible; OnPropertyChanged(); } } @@ -67,6 +73,26 @@ public List VaultContainerContent } } + public Visibility LastUpdateVisibility + { + get => _lastUpdateVisibility; + set + { + _lastUpdateVisibility = value; + OnPropertyChanged(); + } + } + + public DateTime LastUpdate + { + get => _lastUpdate; + set + { + _lastUpdate = value; + OnPropertyChanged(); + } + } + public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] diff --git a/src/StatisticsAnalysisTool/Models/MainWindowTranslation.cs b/src/StatisticsAnalysisTool/Models/MainWindowTranslation.cs index f3cba473e..bd559770d 100644 --- a/src/StatisticsAnalysisTool/Models/MainWindowTranslation.cs +++ b/src/StatisticsAnalysisTool/Models/MainWindowTranslation.cs @@ -71,6 +71,7 @@ public class MainWindowTranslation public static string Dungeons => LanguageController.Translation("DUNGEONS"); public static string PlayerInformation => LanguageController.Translation("PLAYER_INFORMATION"); public static string MailMonitoring => LanguageController.Translation("MAIL_MONITORING"); + public static string StorageHistory => LanguageController.Translation("STORAGE_HISTORY"); public static string Logging => LanguageController.Translation("LOGGING"); public static string TrackingIsActive => LanguageController.Translation("TRACKING_IS_ACTIVE"); public static string TrackingIsPartiallyActive => LanguageController.Translation("TRACKING_IS_PARTIALLY_ACTIVE"); diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs index 1e551d47e..fd7329d73 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs @@ -10,8 +10,11 @@ public ItemContainerObject(long? objectId, Guid containerGuid, List slotIte ObjectId = objectId; ContainerGuid = containerGuid; SlotItemId = slotItemId; + + LastUpdate = DateTime.UtcNow; } + public DateTime LastUpdate { get; } public long? ObjectId { get; set; } public Guid ContainerGuid { get; set; } public List SlotItemId { get; set; } diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs index 41ff9f608..cb3709b23 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs @@ -5,6 +5,7 @@ namespace StatisticsAnalysisTool.Models.NetworkModel; public class VaultContainer { + public DateTime LastUpdate { get; set; } public Guid Guid { get; set; } public string Name { get; set; } public string Icon { get; set; } diff --git a/src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs b/src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs index ce3c4c55a..c37d3d572 100644 --- a/src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs +++ b/src/StatisticsAnalysisTool/Network/Events/AttachItemContainerEvent.cs @@ -36,7 +36,16 @@ public AttachItemContainerEvent(Dictionary parameters) if (parameters.ContainsKey(3) && parameters[3] != null) { var valueType = parameters[3].GetType(); - if (valueType.IsArray && typeof(short[]) == valueType) + if (valueType.IsArray && typeof(int[]) == valueType) + { + var intArray = ((int[])parameters[3]).ToDictionary(); + + foreach (var slot in intArray) + { + _containerSlots.Add(slot.Value); + } + } + else if (valueType.IsArray && typeof(short[]) == valueType) { var intArray = ((short[])parameters[3]).ToDictionary(); diff --git a/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs b/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs index 7b9bac4fe..509ed484d 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs @@ -46,7 +46,7 @@ public TrackingController(MainWindowViewModel mainWindowViewModel, MainWindow ma LootController = new LootController(this, mainWindowViewModel); StatisticController = new StatisticController(this, mainWindowViewModel); MailController = new MailController(mainWindowViewModel); - VaultController = new VaultController(this, mainWindowViewModel); + VaultController = new VaultController(mainWindowViewModel); CountUpTimer = new CountUpTimer(this, mainWindowViewModel); } @@ -102,6 +102,7 @@ public void SetNewCluster(MapType mapType, Guid? mapGuid, string clusterIndex, s StatisticController.SetKillsDeathsValues(); VaultController.ResetDiscoveredItems(); VaultController.ResetVaultContainer(); + VaultController.ResetCurrentVaultInfo(); } private bool TryChangeCluster(string index, string mapName) diff --git a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs index 1e4bceadd..989099be9 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs @@ -7,22 +7,19 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Collections.Specialized; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Text.Json; using System.Windows; -using StatisticsAnalysisTool.Models.BindingModel; namespace StatisticsAnalysisTool.Network.Manager; public class VaultController { private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod()?.DeclaringType); - - private readonly TrackingController _trackingController; + private readonly MainWindowViewModel _mainWindowViewModel; private VaultInfo _currentVaultInfo; private readonly List _discoveredItems = new(); @@ -39,9 +36,8 @@ private ObservableCollection Vaults } } - public VaultController(TrackingController trackingController, MainWindowViewModel mainWindowViewModel) + public VaultController(MainWindowViewModel mainWindowViewModel) { - _trackingController = trackingController; _mainWindowViewModel = mainWindowViewModel; OnVaultsChange += UpdateUi; @@ -53,6 +49,7 @@ public void SetCurrentVault(VaultInfo vaultInfo) { if (vaultInfo == null || vaultInfo.VaultLocation == VaultLocation.Unknown) { + _currentVaultInfo = null; return; } @@ -69,11 +66,6 @@ public void Add(DiscoveredItem item) _discoveredItems.Add(item); } - public void ResetDiscoveredItems() - { - _discoveredItems.Clear(); - } - public void AddContainer(ItemContainerObject newContainerObject) { if (newContainerObject?.ContainerGuid == default) @@ -97,6 +89,16 @@ public void ResetVaultContainer() _vaultContainer.Clear(); } + public void ResetDiscoveredItems() + { + _discoveredItems.Clear(); + } + + public void ResetCurrentVaultInfo() + { + _currentVaultInfo = null; + } + private void ParseVault() { if (_currentVaultInfo == null || GetVaultLocation(_currentVaultInfo?.Location) == VaultLocation.Unknown) @@ -124,12 +126,15 @@ private void ParseVault() { Guid = _currentVaultInfo.ContainerGuidList[i], Icon = _currentVaultInfo.ContainerIconTags[i], - Name = _currentVaultInfo.ContainerNames[i] + Name = (_currentVaultInfo.ContainerNames[i] == "@BUILDINGS_T1_BANK") ? LanguageController.Translation("BANK") : _currentVaultInfo.ContainerNames[i] }; var itemContainer = _vaultContainer.FirstOrDefault(x => x.ContainerGuid == vaultContainer.Guid); - - SetItemsToVaultContainer(itemContainer, vaultContainer, _discoveredItems); + if (itemContainer != null) + { + vaultContainer.LastUpdate = itemContainer.LastUpdate; + SetItemsToVaultContainer(itemContainer, vaultContainer, _discoveredItems); + } vault.VaultContainer.Add(vaultContainer); } @@ -186,12 +191,7 @@ private void UpdateUi() { Application.Current.Dispatcher.Invoke(() => { - var unknownVaultSelection = new Vault() { Location = "UNKNOWN" }; - var list = Vaults.ToList(); - list.Insert(0, unknownVaultSelection); - - _mainWindowViewModel.VaultBindings.Vaults = list; - _mainWindowViewModel.VaultBindings.VaultSelected = unknownVaultSelection; + _mainWindowViewModel.VaultBindings.Vaults = Vaults.ToList(); }); } diff --git a/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml b/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml index f90073816..a6a576e0c 100644 --- a/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml +++ b/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:viewModels="clr-namespace:StatisticsAnalysisTool.ViewModels" + xmlns:gl="clr-namespace:System.Globalization;assembly=System.Runtime" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel}"> @@ -14,6 +15,12 @@ + + + +