Include enabled & return time in submersible stats

This commit is contained in:
Liza 2024-03-31 11:33:06 +02:00
parent 09c0424b95
commit e0358cba47
Signed by: liza
GPG Key ID: 7199F8D727D55F67
7 changed files with 48 additions and 6 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
<Version>0.12</Version> <Version>0.13</Version>
<LangVersion>12</LangVersion> <LangVersion>12</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

View File

@ -126,9 +126,11 @@ internal sealed class InfluxStatisticsClient : IDisposable
.Tag("part_bow", sub.Bow) .Tag("part_bow", sub.Bow)
.Tag("part_bridge", sub.Bridge) .Tag("part_bridge", sub.Bridge)
.Tag("build", sub.Build) .Tag("build", sub.Build)
.Field("enabled", sub.Enabled ? 1 : 0)
.Field("level", sub.Level) .Field("level", sub.Level)
.Field("predicted_level", sub.PredictedLevel) .Field("predicted_level", sub.PredictedLevel)
.Field("state", (int)sub.State) .Field("state", (int)sub.State)
.Field("return_time", new DateTimeOffset(sub.ReturnTime).ToUnixTimeSeconds())
.Timestamp(date, WritePrecision.S)); .Timestamp(date, WritePrecision.S));
} }
} }

View File

@ -141,7 +141,7 @@ internal sealed class InfluxPlugin : IDalamudPlugin
y.LocalContentId == z.CharacterId && z.FreeCompanyId == x.Key.CharacterId))) y.LocalContentId == z.CharacterId && z.FreeCompanyId == x.Key.CharacterId)))
.ToDictionary(x => x.Key, x => x.Value), .ToDictionary(x => x.Key, x => x.Value),
InventoryItems = inventoryItems, InventoryItems = inventoryItems,
Submarines = _submarineTrackerIpc.GetSubmarineStats(characters), Submarines = UpdateEnabledSubs(_submarineTrackerIpc.GetSubmarineStats(characters), characters),
LocalStats = _localStatsCalculator.GetAllCharacterStats() LocalStats = _localStatsCalculator.GetAllCharacterStats()
.Where(x => characters.Any(y => y.CharacterId == x.Key)) .Where(x => characters.Any(y => y.CharacterId == x.Key))
.ToDictionary(x => characters.First(y => y.CharacterId == x.Key), x => x.Value) .ToDictionary(x => characters.First(y => y.CharacterId == x.Key), x => x.Value)
@ -165,6 +165,24 @@ internal sealed class InfluxPlugin : IDalamudPlugin
} }
} }
private Dictionary<Character, List<SubmarineStats>> UpdateEnabledSubs(
Dictionary<Character, List<SubmarineStats>> allSubs, List<Character> characters)
{
foreach (var (character, subs) in allSubs)
{
var owner = characters.FirstOrDefault(x => x.FreeCompanyId == character.CharacterId);
if (owner == null)
continue;
var enabledSubs = _fcStatsCalculator.GetEnabledSubs(owner.CharacterId);
foreach (var sub in subs)
sub.Enabled = enabledSubs.Contains(sub.Name);
}
return allSubs;
}
private void UpdateOnLogout(ConditionFlag flag, bool value) private void UpdateOnLogout(ConditionFlag flag, bool value)
{ {
if (flag == ConditionFlag.LoggingOut && value) if (flag == ConditionFlag.LoggingOut && value)

View File

@ -215,6 +215,15 @@ internal sealed class FcStatsCalculator : IDisposable
public IReadOnlyDictionary<ulong, FcStats> GetAllFcStats() => _cache.AsReadOnly(); public IReadOnlyDictionary<ulong, FcStats> GetAllFcStats() => _cache.AsReadOnly();
public HashSet<string> GetEnabledSubs(ulong characterId)
{
var offlineCharacterData = _autoRetainerApi.GetOfflineCharacterData(characterId);
if (offlineCharacterData == null || !offlineCharacterData.WorkshopEnabled)
return [];
return offlineCharacterData.EnabledSubs;
}
public void Dispose() public void Dispose()
{ {
_clientState.Logout -= Logout; _clientState.Logout -= Logout;

View File

@ -14,15 +14,22 @@ internal sealed class Submarine
try try
{ {
(uint predictedLevel, double _) = ((uint, double))type.GetMethod("PredictExpGrowth")!.Invoke(@delegate, Array.Empty<object?>())!;
PredictedLevel = (ushort)predictedLevel;
bool onVoyage = (bool)type.GetMethod("IsOnVoyage")!.Invoke(@delegate, Array.Empty<object>())!; bool onVoyage = (bool)type.GetMethod("IsOnVoyage")!.Invoke(@delegate, Array.Empty<object>())!;
bool returned = (bool)type.GetMethod("IsDone")!.Invoke(@delegate, Array.Empty<object>())!; bool returned = (bool)type.GetMethod("IsDone")!.Invoke(@delegate, Array.Empty<object>())!;
if (onVoyage) if (onVoyage)
State = returned ? EState.Returned : EState.Voyage; State = returned ? EState.Returned : EState.Voyage;
else else
State = EState.NoVoyage; State = EState.NoVoyage;
if (State == EState.NoVoyage)
PredictedLevel = Level;
else
{
(uint predictedLevel, double _) = ((uint, double))type.GetMethod("PredictExpGrowth")!.Invoke(@delegate, Array.Empty<object?>())!;
PredictedLevel = (ushort)predictedLevel;
}
ReturnTime = (DateTime)type.GetField("ReturnTime")!.GetValue(@delegate)!;
} }
catch (Exception) catch (Exception)
{ {
@ -34,5 +41,6 @@ internal sealed class Submarine
public ushort Level { get; } public ushort Level { get; }
public ushort PredictedLevel { get; } public ushort PredictedLevel { get; }
public Build Build { get; } public Build Build { get; }
public DateTime ReturnTime { get; }
public EState State { get; } public EState State { get; }
} }

View File

@ -1,9 +1,12 @@
namespace Influx.SubmarineTracker; using System;
namespace Influx.SubmarineTracker;
internal sealed class SubmarineStats internal sealed class SubmarineStats
{ {
public required string Name { get; init; } public required string Name { get; init; }
public required int Id { get; init; } public required int Id { get; init; }
public bool Enabled { get; set; } = true;
public required ushort Level { get; init; } public required ushort Level { get; init; }
public required ushort PredictedLevel { get; init; } public required ushort PredictedLevel { get; init; }
@ -13,4 +16,5 @@ internal sealed class SubmarineStats
public required string Bridge { get; init; } public required string Bridge { get; init; }
public required string Build { get; init; } public required string Build { get; init; }
public required EState State { get; init; } public required EState State { get; init; }
public required DateTime ReturnTime { get; init; }
} }

View File

@ -56,6 +56,7 @@ internal sealed class SubmarineTrackerIpc
Bridge = y.Build.BridgeIdentifier, Bridge = y.Build.BridgeIdentifier,
Build = y.Build.FullIdentifier, Build = y.Build.FullIdentifier,
State = y.State, State = y.State,
ReturnTime = y.ReturnTime,
}).ToList()); }).ToList());
} }
else else