diff --git a/Influx/Influx.csproj b/Influx/Influx.csproj index b00ee1d..1c0b880 100644 --- a/Influx/Influx.csproj +++ b/Influx/Influx.csproj @@ -1,7 +1,7 @@ net7.0-windows - 0.6 + 0.7 11.0 enable true diff --git a/Influx/Influx/InfluxStatisticsClient.cs b/Influx/Influx/InfluxStatisticsClient.cs index 2b686a3..43599c5 100644 --- a/Influx/Influx/InfluxStatisticsClient.cs +++ b/Influx/Influx/InfluxStatisticsClient.cs @@ -69,7 +69,7 @@ internal sealed class InfluxStatisticsClient : IDisposable var validFcIds = currencyStats.Keys .Where(x => x.CharacterType == CharacterType.Character) .Where(x => _configuration.IncludedCharacters - .SingleOrDefault(config => config.LocalContentId == x.CharacterId)?.IncludeFreeCompany == true) + .Any(config => config.LocalContentId == x.CharacterId && config.IncludeFreeCompany)) .Select(x => x.FreeCompanyId) .ToList(); var client = _influxClient; diff --git a/Influx/InfluxPlugin.cs b/Influx/InfluxPlugin.cs index 43ea69a..46cb210 100644 --- a/Influx/InfluxPlugin.cs +++ b/Influx/InfluxPlugin.cs @@ -56,9 +56,12 @@ public class InfluxPlugin : IDalamudPlugin DalamudReflector dalamudReflector = new DalamudReflector(pluginInterface, framework, pluginLog); _allaganToolsIpc = new AllaganToolsIpc(pluginInterface, chatGui, dalamudReflector, framework, _pluginLog); _submarineTrackerIpc = new SubmarineTrackerIpc(dalamudReflector); - _localStatsCalculator = new LocalStatsCalculator(pluginInterface, clientState, addonLifecycle, pluginLog, dataManager); - _fcStatsCalculator = new FcStatsCalculator(this, pluginInterface, clientState, addonLifecycle, gameGui, framework, pluginLog); - _influxStatisticsClient = new InfluxStatisticsClient(chatGui, _configuration, dataManager, clientState, _pluginLog); + _localStatsCalculator = + new LocalStatsCalculator(pluginInterface, clientState, addonLifecycle, pluginLog, dataManager); + _fcStatsCalculator = new FcStatsCalculator(this, pluginInterface, clientState, addonLifecycle, gameGui, + framework, _configuration, pluginLog); + _influxStatisticsClient = + new InfluxStatisticsClient(chatGui, _configuration, dataManager, clientState, _pluginLog); _windowSystem = new WindowSystem(typeof(InfluxPlugin).FullName); _statisticsWindow = new StatisticsWindow(); diff --git a/Influx/LocalStatistics/FcStatsCalculator.cs b/Influx/LocalStatistics/FcStatsCalculator.cs index df5c0d6..7752340 100644 --- a/Influx/LocalStatistics/FcStatsCalculator.cs +++ b/Influx/LocalStatistics/FcStatsCalculator.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using AutoRetainerAPI; using Dalamud.Game.Addon.Lifecycle; using Dalamud.Game.Addon.Lifecycle.AddonArgTypes; @@ -13,6 +14,7 @@ using FFXIVClientStructs.FFXIV.Client.UI.Info; using FFXIVClientStructs.FFXIV.Component.GUI; using Newtonsoft.Json; using Task = System.Threading.Tasks.Task; + namespace Influx.LocalStatistics; public class FcStatsCalculator : IDisposable @@ -22,6 +24,7 @@ public class FcStatsCalculator : IDisposable private readonly IAddonLifecycle _addonLifecycle; private readonly IGameGui _gameGui; private readonly IFramework _framework; + private readonly Configuration _configuration; private readonly IPluginLog _pluginLog; private readonly AutoRetainerApi _autoRetainerApi; @@ -36,6 +39,7 @@ public class FcStatsCalculator : IDisposable IAddonLifecycle addonLifecycle, IGameGui gameGui, IFramework framework, + Configuration configuration, IPluginLog pluginLog) { _pluginInterface = pluginInterface; @@ -43,13 +47,14 @@ public class FcStatsCalculator : IDisposable _addonLifecycle = addonLifecycle; _gameGui = gameGui; _framework = framework; + _configuration = configuration; _pluginLog = pluginLog; ECommonsMain.Init(_pluginInterface, plugin); _autoRetainerApi = new(); _autoRetainerApi.OnCharacterPostprocessStep += CheckCharacterPostProcess; _autoRetainerApi.OnCharacterReadyToPostProcess += DoCharacterPostProcess; - _addonLifecycle.RegisterListener(AddonEvent.PostReceiveEvent ,"FreeCompany", CloseFcWindow); + _addonLifecycle.RegisterListener(AddonEvent.PostReceiveEvent, "FreeCompany", CloseFcWindow); foreach (var file in _pluginInterface.ConfigDirectory.GetFiles("f.*.json")) { @@ -70,6 +75,12 @@ public class FcStatsCalculator : IDisposable private unsafe void CheckCharacterPostProcess() { + bool includeFc = _configuration.IncludedCharacters.Any(x => + x.LocalContentId == _clientState.LocalContentId && + x.IncludeFreeCompany); + if (!includeFc) + return; + var infoProxy = Framework.Instance()->UIModule->GetInfoModule()->GetInfoProxyById(InfoProxyId.FreeCompany); if (infoProxy != null) { @@ -89,10 +100,18 @@ public class FcStatsCalculator : IDisposable private void DoCharacterPostProcess() { closeFcWindow = true; - Chat.Instance.SendMessage("/freecompanycmd"); + + unsafe + { + AtkUnitBase* addon = (AtkUnitBase*)_gameGui.GetAddonByName("FreeCompany"); + if (addon != null && addon->IsVisible) + CloseFcWindow(AddonEvent.PostReceiveEvent); + else + Chat.Instance.SendMessage("/freecompanycmd"); + } } - private void CloseFcWindow(AddonEvent type, AddonArgs args) + private void CloseFcWindow(AddonEvent type, AddonArgs? args = null) { _framework.RunOnTick(() => UpdateOnTick(0), TimeSpan.FromMilliseconds(100)); } @@ -191,7 +210,7 @@ public class FcStatsCalculator : IDisposable public void Dispose() { - _addonLifecycle.UnregisterListener(AddonEvent.PostReceiveEvent ,"FreeCompany", CloseFcWindow); + _addonLifecycle.UnregisterListener(AddonEvent.PostReceiveEvent, "FreeCompany", CloseFcWindow); _autoRetainerApi.OnCharacterPostprocessStep -= CheckCharacterPostProcess; _autoRetainerApi.OnCharacterReadyToPostProcess -= DoCharacterPostProcess; _autoRetainerApi.Dispose(); diff --git a/Influx/Windows/ConfigurationWindow.cs b/Influx/Windows/ConfigurationWindow.cs index 840fd72..24d2302 100644 --- a/Influx/Windows/ConfigurationWindow.cs +++ b/Influx/Windows/ConfigurationWindow.cs @@ -155,7 +155,7 @@ internal sealed class ConfigurationWindow : Window foreach (var characterInfo in world) { ImGui.Selectable( - $"{characterInfo.CachedPlayerName} @ {characterInfo.CachedWorldName} ({characterInfo.LocalContentId:X})"); + $"{characterInfo.CachedPlayerName} @ {characterInfo.CachedWorldName} ({characterInfo.LocalContentId:X}{(!characterInfo.IncludeFreeCompany ? ", no FC" : "")})"); } ImGui.Unindent(30);