diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/Entity.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/Entity.cs new file mode 100644 index 000000000..503080521 --- /dev/null +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/Entity.cs @@ -0,0 +1,17 @@ +using StatisticsAnalysisTool.Enumerations; +using System; + +namespace StatisticsAnalysisTool.Models.NetworkModel; + +public class Entity +{ + public long? ObjectId { get; set; } + public Guid UserGuid { get; set; } + public Guid? InteractGuid { get; set; } + public string Name { get; set; } + public string Guild { get; set; } + public string Alliance { get; set; } + public CharacterEquipment CharacterEquipment { get; set; } + public GameObjectType ObjectType { get; set; } + public GameObjectSubType ObjectSubType { get; set; } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Handler/JoinResponseHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/JoinResponseHandler.cs index dfddb352e..0978d2c05 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/JoinResponseHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/JoinResponseHandler.cs @@ -37,8 +37,17 @@ protected override async Task OnActionAsync(JoinResponse value) _mainWindowViewModel.DungeonBindings.DungeonCloseTimer.Visibility = Visibility.Collapsed; - await AddEntityAsync(value.UserObjectId, value.UserGuid, value.InteractGuid, - value.Username, value.GuildName, value.AllianceName, GameObjectType.Player, GameObjectSubType.LocalPlayer); + await AddEntityAsync(new Entity + { + ObjectId = value.UserObjectId, + UserGuid = value.UserGuid ?? Guid.Empty, + InteractGuid = value.InteractGuid, + Name = value.Username, + Guild = value.GuildName, + Alliance = value.AllianceName, + ObjectType = GameObjectType.Player, + ObjectSubType = GameObjectSubType.LocalPlayer + }); _trackingController.DungeonController?.AddDungeonAsync(value.MapType, value.MapGuid).ConfigureAwait(false); @@ -69,15 +78,15 @@ await _trackingController.EntityController.LocalUserData.SetValuesAsync(new Loca }); } - private async Task AddEntityAsync(long? userObjectId, Guid? guid, Guid? interactGuid, string name, string guild, string alliance, GameObjectType gameObjectType, GameObjectSubType gameObjectSubType) + private async Task AddEntityAsync(Entity entity) { - if (guid == null || interactGuid == null || userObjectId == null) + if (entity?.UserGuid == null || entity.InteractGuid == null || entity.ObjectId == null) { return; } - _trackingController.EntityController.AddEntity((long) userObjectId, (Guid) guid, interactGuid, name, guild, alliance, null, GameObjectType.Player, GameObjectSubType.LocalPlayer); - await _trackingController.EntityController.AddToPartyAsync((Guid) guid); + _trackingController.EntityController.AddEntity(entity); + await _trackingController.EntityController.AddToPartyAsync(entity.UserGuid); } private void SetTrackingActivityText() diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewCharacterEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewCharacterEventHandler.cs index cf4259558..d6cacedf2 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/NewCharacterEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/NewCharacterEventHandler.cs @@ -3,6 +3,7 @@ using StatisticsAnalysisTool.Network.Events; using System; using System.Threading.Tasks; +using StatisticsAnalysisTool.Models.NetworkModel; namespace StatisticsAnalysisTool.Network.Handler; @@ -19,8 +20,16 @@ protected override async Task OnActionAsync(NewCharacterEvent value) { if (value.Guid != null && value.ObjectId != null) { - _trackingController.EntityController.AddEntity((long) value.ObjectId, (Guid) value.Guid, null, - value.Name, value.GuildName, string.Empty, value.CharacterEquipment, GameObjectType.Player, GameObjectSubType.Player); + _trackingController.EntityController.AddEntity(new Entity + { + ObjectId = value.ObjectId, + UserGuid = value.Guid ?? Guid.Empty, + Name = value.Name, + Guild = value.GuildName, + CharacterEquipment = value.CharacterEquipment, + ObjectType = GameObjectType.Player, + ObjectSubType = GameObjectSubType.Player + }); } await Task.CompletedTask; diff --git a/src/StatisticsAnalysisTool/Network/Handler/PartyPlayerJoinedEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/PartyPlayerJoinedEventHandler.cs index 3d2c6442e..df7dbcfc6 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/PartyPlayerJoinedEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/PartyPlayerJoinedEventHandler.cs @@ -1,4 +1,5 @@ using StatisticsAnalysisTool.Enumerations; +using StatisticsAnalysisTool.Models.NetworkModel; using StatisticsAnalysisTool.Network.Events; using StatisticsAnalysisTool.Network.Manager; using System.Threading.Tasks; @@ -16,7 +17,14 @@ public PartyPlayerJoinedEventHandler(TrackingController trackingController) : ba protected override async Task OnActionAsync(PartyPlayerJoinedEvent value) { - _trackingController?.EntityController?.AddEntity(null, value.UserGuid, null, value.Username, null, null, null, GameObjectType.Player, GameObjectSubType.Mob); + _trackingController?.EntityController?.AddEntity(new Entity + { + UserGuid = value.UserGuid, + Name = value.Username, + ObjectType = GameObjectType.Player, + ObjectSubType = GameObjectSubType.Mob + }); + await _trackingController?.EntityController?.AddToPartyAsync(value.UserGuid)!; } } \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Manager/CombatController.cs b/src/StatisticsAnalysisTool/Network/Manager/CombatController.cs index 0f6f3db8a..b9b7a972c 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/CombatController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/CombatController.cs @@ -1,5 +1,6 @@ using Serilog; using StatisticsAnalysisTool.Common; +using StatisticsAnalysisTool.Common.UserSettings; using StatisticsAnalysisTool.DamageMeter; using StatisticsAnalysisTool.Enumerations; using StatisticsAnalysisTool.Models.ItemsJsonModel; @@ -22,8 +23,6 @@ public class CombatController private readonly TrackingController _trackingController; private bool _combatModeWasCombatOver; - public bool IsDamageMeterActive { get; set; } - public CombatController(TrackingController trackingController, MainWindowViewModel mainWindowViewModel) { _trackingController = trackingController; @@ -46,7 +45,7 @@ public CombatController(TrackingController trackingController, MainWindowViewMod public Task AddDamage(long affectedId, long causerId, double healthChange, double newHealthValue) { var healthChangeType = GetHealthChangeType(healthChange); - if (!IsDamageMeterActive || (affectedId == causerId && healthChangeType == HealthChangeType.Damage)) + if (!SettingsController.CurrentSettings.IsDamageMeterTrackingActive || (affectedId == causerId && healthChangeType == HealthChangeType.Damage)) { return Task.CompletedTask; } @@ -142,7 +141,7 @@ private static void UpdateDamageMeterFragment(DamageMeterFragment fragment, KeyV if (healthChangeObjectValue?.CharacterEquipment?.MainHand != null) { var item = ItemController.GetItemByIndex(healthChangeObjectValue.CharacterEquipment?.MainHand); - fragment.CauserMainHand = ((ItemJsonObject) item?.FullItemInformation)?.ItemType is ItemType.TransformationWeapon or ItemType.Weapon ? item : null; + fragment.CauserMainHand = ((ItemJsonObject) item?.FullItemInformation)?.ItemType is ItemType.TransformationWeapon or ItemType.Weapon ? item : null; } // Damage @@ -475,7 +474,18 @@ private List> SetRandomDamageValues(int pla Cape = Random.Next(1867, 1874) }; - _trackingController?.EntityController?.AddEntity(i, guid, interactGuid, name, guildName, allianceName, charItem, GameObjectType.Player, GameObjectSubType.Mob); + _trackingController?.EntityController?.AddEntity(new Entity + { + ObjectId = i, + UserGuid = guid, + InteractGuid = interactGuid, + Name = name, + Guild = guildName, + Alliance = allianceName, + CharacterEquipment = charItem, + ObjectType = GameObjectType.Player, + ObjectSubType = GameObjectSubType.Mob + }); _trackingController?.EntityController?.AddToPartyAsync(guid); } diff --git a/src/StatisticsAnalysisTool/Network/Manager/EntityController.cs b/src/StatisticsAnalysisTool/Network/Manager/EntityController.cs index bdd53c7ab..cc0e5b088 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/EntityController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/EntityController.cs @@ -37,33 +37,30 @@ public EntityController(TrackingController trackingController, MainWindowViewMod #region Entities - public event Action OnAddEntity; - - public void AddEntity(long? objectId, Guid userGuid, Guid? interactGuid, string name, string guild, string alliance, - CharacterEquipment characterEquipment, GameObjectType objectType, GameObjectSubType objectSubType) + public void AddEntity(Entity entity) { PlayerGameObject gameObject; - if (_knownEntities.TryRemove(userGuid, out var oldEntity)) + if (_knownEntities.TryRemove(entity.UserGuid, out var oldEntity)) { // Parties are recreated several times in HCE's and therefore the ObjectId may only be set to zero once after a map change. // However, this must not happen in AddEntity - long? newObjectId = oldEntity.ObjectId; - if (objectId != null) + long? newUserObjectId = oldEntity.ObjectId; + if (entity.ObjectId != null) { - newObjectId = objectId; + newUserObjectId = entity.ObjectId; } - gameObject = new PlayerGameObject(newObjectId) + gameObject = new PlayerGameObject(newUserObjectId) { - Name = name, - ObjectType = objectType, - UserGuid = userGuid, - Guild = string.Empty == guild ? oldEntity.Guild : guild, - Alliance = string.Empty == alliance ? oldEntity.Alliance : alliance, - InteractGuid = interactGuid == Guid.Empty || interactGuid == null ? oldEntity.InteractGuid : interactGuid, - ObjectSubType = objectSubType, - CharacterEquipment = characterEquipment ?? oldEntity.CharacterEquipment, + Name = entity.Name, + ObjectType = entity.ObjectType, + UserGuid = entity.UserGuid, + Guild = string.Empty == entity.Guild ? oldEntity.Guild : entity.Guild, + Alliance = string.Empty == entity.Alliance ? oldEntity.Alliance : entity.Alliance, + InteractGuid = entity.InteractGuid == Guid.Empty || entity.InteractGuid == null ? oldEntity.InteractGuid : entity.InteractGuid, + ObjectSubType = entity.ObjectSubType, + CharacterEquipment = entity.CharacterEquipment ?? oldEntity.CharacterEquipment, CombatStart = oldEntity.CombatStart, CombatTime = oldEntity.CombatTime, Damage = oldEntity.Damage, @@ -74,16 +71,21 @@ public void AddEntity(long? objectId, Guid userGuid, Guid? interactGuid, string } else { - gameObject = new PlayerGameObject(objectId) + gameObject = new PlayerGameObject(entity.ObjectId) { - Name = name, - ObjectType = objectType, - UserGuid = userGuid, - Guild = guild, - Alliance = alliance, - ObjectSubType = objectSubType, - CharacterEquipment = characterEquipment + Name = entity.Name, + ObjectType = entity.ObjectType, + UserGuid = entity.UserGuid, + Guild = entity.Guild, + Alliance = entity.Alliance, + ObjectSubType = entity.ObjectSubType, + CharacterEquipment = entity.CharacterEquipment }; + + if (gameObject.ObjectSubType == GameObjectSubType.LocalPlayer) + { + RemoveLocalEntityFromPartyAsync().GetAwaiter(); + } } // When players in a group and go to the Mist, the party player is indicated as PA @@ -92,15 +94,14 @@ public void AddEntity(long? objectId, Guid userGuid, Guid? interactGuid, string gameObject.Name = oldEntity.Name; } - if (objectId is not null && _tempCharacterEquipmentData.TryGetValue((long) objectId, out var characterEquipmentData)) + if (entity.ObjectId is not null && _tempCharacterEquipmentData.TryGetValue((long) entity.ObjectId, out var characterEquipmentData)) { ResetTempCharacterEquipment(); gameObject.CharacterEquipment = characterEquipmentData.CharacterEquipment; - _tempCharacterEquipmentData.TryRemove((long) objectId, out _); + _tempCharacterEquipmentData.TryRemove((long) entity.ObjectId, out _); } _knownEntities.TryAdd(gameObject.UserGuid, gameObject); - OnAddEntity?.Invoke(gameObject); } public void RemoveEntitiesByLastUpdate(int withoutAnUpdateForMinutes) @@ -182,6 +183,15 @@ public async Task AddToPartyAsync(Guid guid) } } + private async Task RemoveLocalEntityFromPartyAsync() + { + var entity = GetLocalEntity(); + if (entity?.Value is not null) + { + await RemoveFromPartyAsync(entity.Value.Key); + } + } + public async Task RemoveFromPartyAsync(Guid? guid) { if (guid is { } notNullGuid) @@ -235,7 +245,13 @@ public async Task SetPartyAsync(Dictionary party) { if (!ExistEntity(member.Key) && GetLocalEntity()?.Key != member.Key) { - AddEntity(null, member.Key, null, member.Value, null, null, null, GameObjectType.Player, GameObjectSubType.Player); + AddEntity(new Entity + { + UserGuid = member.Key, + Name = member.Value, + ObjectType = GameObjectType.Player, + ObjectSubType = GameObjectSubType.Player + }); } await AddToPartyAsync(member.Key); diff --git a/src/StatisticsAnalysisTool/Network/Manager/LootController.cs b/src/StatisticsAnalysisTool/Network/Manager/LootController.cs index 7e2c655c6..034b8555a 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/LootController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/LootController.cs @@ -1,5 +1,6 @@ using Serilog; using StatisticsAnalysisTool.Common; +using StatisticsAnalysisTool.Common.UserSettings; using StatisticsAnalysisTool.EventLogging; using StatisticsAnalysisTool.EventLogging.Notification; using StatisticsAnalysisTool.Localization; @@ -28,8 +29,6 @@ public class LootController : ILootController private const int MaxLoot = 5000; - public bool IsPartyLootOnly; - public LootController(TrackingController trackingController, MainWindowViewModel mainWindowViewModel) { _trackingController = trackingController; @@ -59,7 +58,9 @@ public async Task AddLootAsync(Loot loot) return; } - if (IsPartyLootOnly && !_trackingController.EntityController.IsEntityInParty(loot.LootedByName) && !_trackingController.EntityController.IsEntityInParty(loot.LootedFromName)) + if (SettingsController.CurrentSettings.IsTrackingPartyLootOnly + && !_trackingController.EntityController.IsEntityInParty(loot.LootedByName) + && !_trackingController.EntityController.IsEntityInParty(loot.LootedFromName)) { return; } diff --git a/src/StatisticsAnalysisTool/StatisticsAnalysisTool.csproj b/src/StatisticsAnalysisTool/StatisticsAnalysisTool.csproj index a8394fb52..70a02bd73 100644 --- a/src/StatisticsAnalysisTool/StatisticsAnalysisTool.csproj +++ b/src/StatisticsAnalysisTool/StatisticsAnalysisTool.csproj @@ -1,4 +1,4 @@ - + net7.0-windows WinExe @@ -640,10 +640,11 @@ - - + + + diff --git a/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs b/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs index 2d83918b1..d3c2162a5 100644 --- a/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs +++ b/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs @@ -501,8 +501,6 @@ public bool IsTrackingPartyLootOnly set { _isTrackingPartyLootOnly = value; - var trackingController = ServiceLocator.Resolve(); - trackingController.LootController.IsPartyLootOnly = _isTrackingPartyLootOnly; SettingsController.CurrentSettings.IsTrackingPartyLootOnly = _isTrackingPartyLootOnly; OnPropertyChanged(); @@ -703,17 +701,8 @@ public bool IsDamageMeterTrackingActive get => _isDamageMeterTrackingActive; set { - var trackingController = ServiceLocator.Resolve(); - - if (trackingController?.CombatController == null) - { - return; - } - _isDamageMeterTrackingActive = value; - trackingController.CombatController.IsDamageMeterActive = _isDamageMeterTrackingActive; - DamageMeterBindings.DamageMeterActivationToggleIcon = _isDamageMeterTrackingActive ? EFontAwesomeIcon.Solid_ToggleOn : EFontAwesomeIcon.Solid_ToggleOff; var colorOn = new SolidColorBrush((Color) Application.Current.Resources["Color.Accent.Blue.2"]);