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 Jul 4, 2023
2 parents 75588a2 + 8db589c commit d71920d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public PartyChangedOrderEventHandler(TrackingController trackingController) : ba

protected override async Task OnActionAsync(PartyChangedOrderEvent value)
{
await _trackingController.EntityController.SetPartyAsync(value.PartyUsers, true);
await _trackingController.EntityController.SetPartyAsync(value.PartyUsers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ public PartyJoinedEventHandler(TrackingController trackingController) : base((in

protected override async Task OnActionAsync(PartyJoinedEvent value)
{
_trackingController.EntityController.AddEntity(null, value.UserGuid, null, value.Username, value.GuildName, null, null, GameObjectType.Player, GameObjectSubType.LocalPlayer);
await _trackingController.EntityController.AddToPartyAsync(value.UserGuid);
if (!_trackingController.EntityController.IsLocalEntity(value.UserGuid) && !_trackingController.EntityController.ExistEntity(value.UserGuid))
{
_trackingController.EntityController
.AddEntity(null, value.UserGuid, null, value.Username, value.GuildName, null, null, GameObjectType.Player, GameObjectSubType.Player);
}

await Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using StatisticsAnalysisTool.Enumerations;
using StatisticsAnalysisTool.Network.Events;
using StatisticsAnalysisTool.Network.Manager;
using System;
using System.Threading.Tasks;

namespace StatisticsAnalysisTool.Network.Handler;
Expand All @@ -16,7 +17,7 @@ public PartyPlayerJoinedEventHandler(TrackingController trackingController) : ba

protected override async Task OnActionAsync(PartyPlayerJoinedEvent value)
{
if (value?.UserGuid != null)
if (value.UserGuid != Guid.Empty)
{
_trackingController.EntityController.AddEntity(null, value.UserGuid, null, value.Username, null, null, null, GameObjectType.Player, GameObjectSubType.Player);
await _trackingController.EntityController.AddToPartyAsync(value.UserGuid);
Expand Down
25 changes: 16 additions & 9 deletions src/StatisticsAnalysisTool/Network/Manager/EntityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void AddEntity(long? objectId, Guid userGuid, Guid? interactGuid, string
Name = name,
ObjectType = objectType,
UserGuid = userGuid,
Guild = guild,
Alliance = alliance,
InteractGuid = interactGuid,
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,
CombatStart = oldEntity.CombatStart,
Expand Down Expand Up @@ -142,6 +142,11 @@ public bool ExistEntity(Guid guid)

public async Task AddToPartyAsync(Guid guid)
{
if (guid == Guid.Empty)
{
return;
}

if (_knownPartyEntities.All(x => x != guid))
{
_knownPartyEntities.Add(guid);
Expand Down Expand Up @@ -183,12 +188,9 @@ public async Task AddLocalEntityToPartyAsync()
await UpdatePartyMemberUiAsync();
}

public async Task SetPartyAsync(Dictionary<Guid, string> party, bool resetPartyBefore = false)
public async Task SetPartyAsync(Dictionary<Guid, string> party)
{
if (resetPartyBefore)
{
await ResetPartyMemberAsync();
}
await ResetPartyMemberAsync();

foreach (var member in party)
{
Expand Down Expand Up @@ -219,7 +221,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
_mainWindowViewModel.PartyMemberCircles.Add(new PartyMemberCircle
{
UserGuid = memberGuid,
Name = user?.Value.Name ?? string.Empty
Name = user.Value.Value.Name ?? string.Empty
});
_mainWindowViewModel.PartyMemberNumber = _knownPartyEntities.Count;
}
Expand Down Expand Up @@ -495,6 +497,11 @@ public bool ExistLocalEntity()
return _knownEntities?.Any(x => x.Value.ObjectSubType == GameObjectSubType.LocalPlayer) ?? false;
}

public bool IsLocalEntity(Guid guid)
{
return _knownEntities?.Any(x => x.Value.ObjectSubType == GameObjectSubType.LocalPlayer && x.Value.UserGuid == guid) ?? false;
}

public KeyValuePair<Guid, PlayerGameObject>? GetLocalEntity() => _knownEntities?.ToArray().FirstOrDefault(x => x.Value.ObjectSubType == GameObjectSubType.LocalPlayer);

#endregion
Expand Down

0 comments on commit d71920d

Please sign in to comment.