Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Triky313 committed Nov 21, 2023
2 parents 9740219 + c8df612 commit 383a212
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 60 deletions.
17 changes: 17 additions & 0 deletions src/StatisticsAnalysisTool/Models/NetworkModel/Entity.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
21 changes: 15 additions & 6 deletions src/StatisticsAnalysisTool/Network/Handler/JoinResponseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using StatisticsAnalysisTool.Network.Events;
using System;
using System.Threading.Tasks;
using StatisticsAnalysisTool.Models.NetworkModel;

namespace StatisticsAnalysisTool.Network.Handler;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using StatisticsAnalysisTool.Enumerations;
using StatisticsAnalysisTool.Models.NetworkModel;
using StatisticsAnalysisTool.Network.Events;
using StatisticsAnalysisTool.Network.Manager;
using System.Threading.Tasks;
Expand All @@ -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)!;
}
}
20 changes: 15 additions & 5 deletions src/StatisticsAnalysisTool/Network/Manager/CombatController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Serilog;
using StatisticsAnalysisTool.Common;
using StatisticsAnalysisTool.Common.UserSettings;
using StatisticsAnalysisTool.DamageMeter;
using StatisticsAnalysisTool.Enumerations;
using StatisticsAnalysisTool.Models.ItemsJsonModel;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -475,7 +474,18 @@ private List<KeyValuePair<Guid, PlayerGameObject>> 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);
}

Expand Down
74 changes: 45 additions & 29 deletions src/StatisticsAnalysisTool/Network/Manager/EntityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,30 @@ public EntityController(TrackingController trackingController, MainWindowViewMod

#region Entities

public event Action<GameObject> 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,
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -235,7 +245,13 @@ public async Task SetPartyAsync(Dictionary<Guid, string> 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);
Expand Down
7 changes: 4 additions & 3 deletions src/StatisticsAnalysisTool/Network/Manager/LootController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Serilog;
using StatisticsAnalysisTool.Common;
using StatisticsAnalysisTool.Common.UserSettings;
using StatisticsAnalysisTool.EventLogging;
using StatisticsAnalysisTool.EventLogging.Notification;
using StatisticsAnalysisTool.Localization;
Expand Down Expand Up @@ -28,8 +29,6 @@ public class LootController : ILootController

private const int MaxLoot = 5000;

public bool IsPartyLootOnly;

public LootController(TrackingController trackingController, MainWindowViewModel mainWindowViewModel)
{
_trackingController = trackingController;
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions src/StatisticsAnalysisTool/StatisticsAnalysisTool.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
Expand Down Expand Up @@ -640,10 +640,11 @@
<PackageReference Include="FontAwesome5" Version="2.1.6" />
<PackageReference Include="Notification.Wpf" Version="7.0.0" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="VirtualizingWrapPanel" Version="1.5.7" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
Expand Down
11 changes: 0 additions & 11 deletions src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,6 @@ public bool IsTrackingPartyLootOnly
set
{
_isTrackingPartyLootOnly = value;
var trackingController = ServiceLocator.Resolve<TrackingController>();
trackingController.LootController.IsPartyLootOnly = _isTrackingPartyLootOnly;

SettingsController.CurrentSettings.IsTrackingPartyLootOnly = _isTrackingPartyLootOnly;
OnPropertyChanged();
Expand Down Expand Up @@ -703,17 +701,8 @@ public bool IsDamageMeterTrackingActive
get => _isDamageMeterTrackingActive;
set
{
var trackingController = ServiceLocator.Resolve<TrackingController>();

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"]);
Expand Down

0 comments on commit 383a212

Please sign in to comment.