Add sub levels

master
Liza 2023-08-22 22:35:08 +02:00
parent 5e51a7f6f1
commit b6bd9707b7
Signed by: liza
GPG Key ID: 7199F8D727D55F67
5 changed files with 125 additions and 5 deletions

View File

@ -37,9 +37,9 @@ internal class InfluxStatisticsClient : IDisposable
return;
DateTime date = DateTime.UtcNow;
IReadOnlyDictionary<Character, Currencies> stats = update.Currencies;
IReadOnlyDictionary<Character, Currencies> currencyStats = update.Currencies;
var validFcIds = stats.Keys
var validFcIds = currencyStats.Keys
.Where(x => x.CharacterType == CharacterType.Character)
.Select(x => x.FreeCompanyId)
.ToList();
@ -48,7 +48,7 @@ internal class InfluxStatisticsClient : IDisposable
try
{
List<PointData> values = new();
foreach (var (character, currencies) in stats)
foreach (var (character, currencies) in currencyStats)
{
if (character.CharacterType == CharacterType.Character)
{
@ -64,7 +64,7 @@ internal class InfluxStatisticsClient : IDisposable
}
else if (character.CharacterType == CharacterType.Retainer)
{
var owner = stats.Keys.First(x => x.CharacterId == character.OwnerId);
var owner = currencyStats.Keys.First(x => x.CharacterId == character.OwnerId);
values.Add(PointData.Measurement("currency")
.Tag("id", character.CharacterId.ToString())
.Tag("player_name", owner.Name)
@ -90,6 +90,23 @@ internal class InfluxStatisticsClient : IDisposable
}
}
foreach (var (fc, subs) in update.Submarines)
{
if (validFcIds.Contains(fc.CharacterId))
{
foreach (var sub in subs)
{
values.Add(PointData.Measurement("submersibles")
.Tag("id", fc.CharacterId.ToString())
.Tag("fc_name", fc.Name)
.Tag("sub_id", $"{fc.CharacterId}_{sub.Id}")
.Tag("sub_name", sub.Name)
.Field("level", sub.Level)
.Timestamp(date, WritePrecision.S));
}
}
}
var writeApi = _influxClient.GetWriteApiAsync();
await writeApi.WritePointsAsync(
values,

View File

@ -1,5 +1,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using Dalamud.Game.ClientState;
using Dalamud.Game.Command;
@ -10,6 +11,7 @@ using Dalamud.Plugin;
using ECommons;
using Influx.AllaganTools;
using Influx.Influx;
using Influx.SubmarineTracker;
using Influx.Windows;
namespace Influx;
@ -24,6 +26,7 @@ public class InfluxPlugin : IDalamudPlugin
private readonly ClientState _clientState;
private readonly CommandManager _commandManager;
private readonly AllaganToolsIpc _allaganToolsIpc;
private readonly SubmarineTrackerIpc _submarineTrackerIpc;
private readonly InfluxStatisticsClient _influxStatisticsClient;
private readonly WindowSystem _windowSystem;
private readonly StatisticsWindow _statisticsWindow;
@ -40,6 +43,7 @@ public class InfluxPlugin : IDalamudPlugin
_clientState = clientState;
_commandManager = commandManager;
_allaganToolsIpc = new AllaganToolsIpc(pluginInterface, chatGui, _configuration);
_submarineTrackerIpc = new SubmarineTrackerIpc(chatGui);
_influxStatisticsClient = new InfluxStatisticsClient(chatGui, _configuration);
_windowSystem = new WindowSystem(typeof(InfluxPlugin).FullName);
@ -76,9 +80,12 @@ public class InfluxPlugin : IDalamudPlugin
try
{
var currencies = _allaganToolsIpc.CountCurrencies();
var characters = currencies.Keys.ToList();
var update = new StatisticsUpdate
{
Currencies = _allaganToolsIpc.CountCurrencies(),
Currencies = currencies,
Submarines = _submarineTrackerIpc.GetSubmarineStats(characters),
};
_statisticsWindow.OnStatisticsUpdate(update);
_influxStatisticsClient.OnStatisticsUpdate(update);

View File

@ -1,9 +1,11 @@
using System.Collections.Generic;
using Influx.AllaganTools;
using Influx.SubmarineTracker;
namespace Influx;
internal sealed class StatisticsUpdate
{
public required IReadOnlyDictionary<Character, Currencies> Currencies { get; init; }
public required Dictionary<Character, List<SubmarineStats>> Submarines { get; init; }
}

View File

@ -0,0 +1,8 @@
namespace Influx.SubmarineTracker;
public class SubmarineStats
{
public string Name { get; init; }
public int Id { get; init; }
public ushort Level { get; init; }
}

View File

@ -0,0 +1,86 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Game.Gui;
using ECommons.Reflection;
using Influx.AllaganTools;
namespace Influx.SubmarineTracker;
internal sealed class SubmarineTrackerIpc
{
private readonly ChatGui _chatGui;
public SubmarineTrackerIpc(ChatGui chatGui)
{
_chatGui = chatGui;
}
public Dictionary<Character, List<SubmarineStats>> GetSubmarineStats(List<Character> characters)
{
if (DalamudReflector.TryGetDalamudPlugin("Submarine Tracker", out var it, false, true))
{
var submarineData = it.GetType().Assembly.GetType("SubmarineTracker.Data.Submarines");
var knownSubmarineData = submarineData!.GetField("KnownSubmarines")!;
return ((IEnumerable)knownSubmarineData.GetValue(null)!).Cast<object>()
.Select(x => new
{
OwnerId = (ulong)x.GetType().GetProperty("Key")!.GetValue(x)!,
FcWrapper = x.GetType().GetProperty("Value")!.GetValue(x)!
})
.Select(x => new
{
Owner = characters.FirstOrDefault(y => y.CharacterId == x.OwnerId),
Subs = new FcSubmarines(x.FcWrapper).Submarines,
})
.Where(x => x.Owner != null)
.Select(x => new
{
x.Subs,
Fc = characters.FirstOrDefault(y => y.CharacterId == x.Owner!.FreeCompanyId)
})
.Where(x => x.Fc != null)
.ToDictionary(
x => x.Fc!,
x => x.Subs.Select(y => new SubmarineStats
{
Id = x.Subs.IndexOf(y),
Name = y.Name,
Level = y.Level,
}).ToList());
}
else
return new Dictionary<Character, List<SubmarineStats>>();
}
}
public sealed class FcSubmarines
{
private readonly object _delegate;
public FcSubmarines(object @delegate)
{
_delegate = @delegate;
Submarines = ((IEnumerable)_delegate.GetType().GetField("Submarines")!.GetValue(_delegate)!)
.Cast<object>()
.Select(x => new Submarine(x))
.ToList();
}
public List<Submarine> Submarines { get; }
}
public sealed class Submarine
{
private readonly object _delegate;
public Submarine(object @delegate)
{
_delegate = @delegate;
Name = (string)_delegate.GetType().GetProperty("Name")!.GetValue(_delegate)!;
Level = (ushort)_delegate.GetType().GetProperty("Rank")!.GetValue(_delegate)!;
}
public string Name { get; set; }
public ushort Level { get; }
}