2023-02-15 22:17:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Dalamud.Game.Gui;
|
|
|
|
|
using Grpc.Core;
|
|
|
|
|
using Pal.Client.Configuration;
|
|
|
|
|
using Pal.Client.Extensions;
|
|
|
|
|
using Pal.Client.Net;
|
|
|
|
|
using Pal.Client.Properties;
|
|
|
|
|
using Pal.Client.Windows;
|
|
|
|
|
|
|
|
|
|
namespace Pal.Client.DependencyInjection
|
|
|
|
|
{
|
|
|
|
|
internal sealed class StatisticsService
|
|
|
|
|
{
|
|
|
|
|
private readonly IPalacePalConfiguration _configuration;
|
|
|
|
|
private readonly RemoteApi _remoteApi;
|
|
|
|
|
private readonly StatisticsWindow _statisticsWindow;
|
2023-02-17 14:51:45 +00:00
|
|
|
|
private readonly Chat _chat;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
|
|
|
|
|
public StatisticsService(IPalacePalConfiguration configuration, RemoteApi remoteApi,
|
2023-02-17 14:51:45 +00:00
|
|
|
|
StatisticsWindow statisticsWindow, Chat chat)
|
2023-02-15 22:17:19 +00:00
|
|
|
|
{
|
|
|
|
|
_configuration = configuration;
|
|
|
|
|
_remoteApi = remoteApi;
|
|
|
|
|
_statisticsWindow = statisticsWindow;
|
2023-02-17 14:51:45 +00:00
|
|
|
|
_chat = chat;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowGlobalStatistics()
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () => await FetchFloorStatistics());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task FetchFloorStatistics()
|
|
|
|
|
{
|
2023-02-16 12:27:28 +00:00
|
|
|
|
if (!_configuration.HasRoleOnCurrentServer(RemoteApi.RemoteUrl, "statistics:view"))
|
2023-02-15 22:17:19 +00:00
|
|
|
|
{
|
2023-02-17 14:51:45 +00:00
|
|
|
|
_chat.Error(Localization.Command_pal_stats_CurrentFloor);
|
2023-02-15 22:17:19 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var (success, floorStatistics) = await _remoteApi.FetchStatistics();
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
_statisticsWindow.SetFloorData(floorStatistics);
|
|
|
|
|
_statisticsWindow.IsOpen = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-02-17 14:51:45 +00:00
|
|
|
|
_chat.Error(Localization.Command_pal_stats_UnableToFetchStatistics);
|
2023-02-15 22:17:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (RpcException e) when (e.StatusCode == StatusCode.PermissionDenied)
|
|
|
|
|
{
|
2023-02-17 14:51:45 +00:00
|
|
|
|
_chat.Error(Localization.Command_pal_stats_CurrentFloor);
|
2023-02-15 22:17:19 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2023-02-17 14:51:45 +00:00
|
|
|
|
_chat.Error(e.ToString());
|
2023-02-15 22:17:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|