Include enabled & return time in submersible stats
This commit is contained in:
parent
09c0424b95
commit
e0358cba47
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Version>0.12</Version>
|
||||
<Version>0.13</Version>
|
||||
<LangVersion>12</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
|
@ -126,9 +126,11 @@ internal sealed class InfluxStatisticsClient : IDisposable
|
||||
.Tag("part_bow", sub.Bow)
|
||||
.Tag("part_bridge", sub.Bridge)
|
||||
.Tag("build", sub.Build)
|
||||
.Field("enabled", sub.Enabled ? 1 : 0)
|
||||
.Field("level", sub.Level)
|
||||
.Field("predicted_level", sub.PredictedLevel)
|
||||
.Field("state", (int)sub.State)
|
||||
.Field("return_time", new DateTimeOffset(sub.ReturnTime).ToUnixTimeSeconds())
|
||||
.Timestamp(date, WritePrecision.S));
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ internal sealed class InfluxPlugin : IDalamudPlugin
|
||||
y.LocalContentId == z.CharacterId && z.FreeCompanyId == x.Key.CharacterId)))
|
||||
.ToDictionary(x => x.Key, x => x.Value),
|
||||
InventoryItems = inventoryItems,
|
||||
Submarines = _submarineTrackerIpc.GetSubmarineStats(characters),
|
||||
Submarines = UpdateEnabledSubs(_submarineTrackerIpc.GetSubmarineStats(characters), characters),
|
||||
LocalStats = _localStatsCalculator.GetAllCharacterStats()
|
||||
.Where(x => characters.Any(y => y.CharacterId == x.Key))
|
||||
.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)
|
||||
{
|
||||
if (flag == ConditionFlag.LoggingOut && value)
|
||||
|
@ -215,6 +215,15 @@ internal sealed class FcStatsCalculator : IDisposable
|
||||
|
||||
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()
|
||||
{
|
||||
_clientState.Logout -= Logout;
|
||||
|
@ -14,15 +14,22 @@ internal sealed class Submarine
|
||||
|
||||
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 returned = (bool)type.GetMethod("IsDone")!.Invoke(@delegate, Array.Empty<object>())!;
|
||||
if (onVoyage)
|
||||
State = returned ? EState.Returned : EState.Voyage;
|
||||
else
|
||||
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)
|
||||
{
|
||||
@ -34,5 +41,6 @@ internal sealed class Submarine
|
||||
public ushort Level { get; }
|
||||
public ushort PredictedLevel { get; }
|
||||
public Build Build { get; }
|
||||
public DateTime ReturnTime { get; }
|
||||
public EState State { get; }
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
namespace Influx.SubmarineTracker;
|
||||
using System;
|
||||
|
||||
namespace Influx.SubmarineTracker;
|
||||
|
||||
internal sealed class SubmarineStats
|
||||
{
|
||||
public required string Name { get; init; }
|
||||
public required int Id { get; init; }
|
||||
public bool Enabled { get; set; } = true;
|
||||
public required ushort Level { 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 Build { get; init; }
|
||||
public required EState State { get; init; }
|
||||
public required DateTime ReturnTime { get; init; }
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ internal sealed class SubmarineTrackerIpc
|
||||
Bridge = y.Build.BridgeIdentifier,
|
||||
Build = y.Build.FullIdentifier,
|
||||
State = y.State,
|
||||
ReturnTime = y.ReturnTime,
|
||||
}).ToList());
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user