Snapshot for release 2026.10.30.1 (internal 50ae062)

This commit is contained in:
Tom Bohar 2026-10-31 06:01:30 -04:00
commit 76aca938b6
52 changed files with 6242 additions and 60 deletions

View file

@ -27,6 +27,18 @@
// Fallback "You've banked N Luminance." counts on its own only until a
// bank property (9005 or 9102) is read; after that the property
// covers every source and the chat line would double-count.
//
// Deaths (2026-10-30), from two readings of the player each tick:
// health the engine's own vitals: 0 (with a max) after a reading above
// 0. The player's health never comes through OnUpdateHealth (that
// is a target's health), which is why the count used to stay 0.
// 0/0 (a login, before the vitals) is no reading.
// NumDeaths the server's death counter (PropertyInt 43): a rise counts,
// so a death while the plugin was unloaded (a reload) is not lost.
// A character that never died has no counter until its first death.
// ACE sends both in one packet (Player.Die: health 0, then NumDeaths), so one
// death shows on both: the first to show it counts it, the other is matched to
// it until the player reads alive again. Kill notices never count a death.
// ============================================================================
using System;
using System.Collections.Generic;
@ -146,6 +158,13 @@ internal sealed class SessionStats
private readonly List<(DateTime At, long Amount)> _recentLum = new();
private long _recentLumSum;
// Deaths (see the header): the last health reading, the NumDeaths baseline, and the death
// each reading has counted that the other one hasn't shown yet.
private bool? _alive; // null = no reading yet this session (or since a reload)
private TrackerRise _deathCountRise;
private bool _deathOpenByHealth; // counted from health 0; its NumDeaths rise hasn't come
private int _deathsOpenByCount; // counted from NumDeaths; their health 0 hasn't been read
public SessionStats() => Reset(DateTime.UtcNow);
public DateTime SessionStartUtc => _sessionStart;
@ -184,6 +203,10 @@ internal sealed class SessionStats
_movedIntoBankUntil = DateTime.MinValue;
_recentLum.Clear();
_recentLumSum = 0;
_alive = null;
_deathCountRise.Clear();
_deathOpenByHealth = false;
_deathsOpenByCount = 0;
}
// ── Events ───────────────────────────────────────────────────────────────
@ -228,8 +251,41 @@ internal sealed class SessionStats
return result;
}
/// <summary>The player's health reached 0.</summary>
public void OnPlayerDied() => _deaths++;
/// <summary>
/// The player's health from the engine's vitals. 0 after a reading above 0 is a death, unless
/// NumDeaths already counted it; max 0 (the 0/0 before a login's vitals) is no reading. Read
/// before <see cref="OnDeathCount"/> in the same tick: the server sends the health first.
/// </summary>
public void OnPlayerHealth(uint current, uint max)
{
if (max == 0) return;
bool alive = current > 0;
if (alive)
{
// Alive again (or still): whatever comes from now on is a new death.
_deathOpenByHealth = false;
_deathsOpenByCount = 0;
}
else if (_alive == true)
{
if (_deathsOpenByCount > 0) _deathsOpenByCount--;
else { _deaths++; _deathOpenByHealth = true; }
}
_alive = alive;
}
/// <summary>
/// The server's death counter (NumDeaths). Its first read is the baseline; a rise is that many
/// deaths, less the one health 0 has already counted.
/// </summary>
public void OnDeathCount(int numDeaths)
{
long up = _deathCountRise.Take(numDeaths);
if (up <= 0) return;
if (_deathOpenByHealth) { _deathOpenByHealth = false; up--; }
_deaths += (int)up;
_deathsOpenByCount += (int)up;
}
private void CountCorpseKill(DateTime now)
{
@ -378,6 +434,8 @@ internal sealed class SessionStats
s.LumOwn = _lumOwn;
s.BankIncome = _bankIncome;
s.OwnSinceBank = _ownSinceBank;
s.DeathCountBase = _deathCountRise.Baseline;
s.DeathOpen = _deathOpenByHealth;
s.RecentLum.Clear();
foreach (var (at, amount) in _recentLum) s.RecentLum.Add((at.Ticks, amount));
}
@ -405,6 +463,11 @@ internal sealed class SessionStats
_lumOwn = s.LumOwn;
_bankIncome = s.BankIncome;
_ownSinceBank = s.OwnSinceBank;
// The last health reading is not carried over: after an engine reload the vitals can read
// 0 with a max for a moment before the health is seeded, and that is no death. A death the
// reload hid comes in through NumDeaths' saved baseline instead.
_deathCountRise.Restore(s.DeathCountBase);
_deathOpenByHealth = s.DeathOpen;
foreach (var (at, amount) in s.RecentLum)
{
_recentLum.Add((new DateTime(at, DateTimeKind.Utc), amount));

View file

@ -1,9 +1,10 @@
// ============================================================================
// RynthSuite - Plugins/Shared/SessionStatsTracker.cs
// Feeds a SessionStats from the game: the player's properties every 0.5 s,
// kill notices, chat, corpses and the player's health, and keeps the session
// across plugin reloads (TrackerSessionStore). RynthTracker and RynthAi's
// Mini Remote each own one, so both show the same numbers (2026-10-11).
// kill notices, chat, corpses, and the player's health and death counter
// every tick, and keeps the session across plugin reloads
// (TrackerSessionStore). RynthTracker and RynthAi's Mini Remote each own one,
// so both show the same numbers (2026-10-11).
//
// Threading: every call except RequestReset and View runs on the pump
// thread. RequestReset only sets a flag (any thread); View is an immutable
@ -24,6 +25,8 @@ internal sealed class SessionStatsTracker
private const uint Int64RadianceEarned = 9101; // Aelrynth Bank mod session totals
private const uint Int64LuminanceBanked = 9102;
private const uint Int64LuminanceDrawn = 9103;
// The server's death counter (PropertyInt). The engine serves the player's own record to any thread.
private const uint IntNumDeaths = 43;
private const long PollIntervalMs = 500;
private static readonly TimeSpan SaveInterval = TimeSpan.FromSeconds(30);
@ -149,12 +152,9 @@ internal sealed class SessionStatsTracker
if (_pendingCorpses[i].Id == objectId) _pendingCorpses.RemoveAt(i);
}
/// <summary>The player's health reaching 0 is a death (maxHealth &gt; 0 skips spurious 0/0 packets at login).</summary>
public void OnUpdateHealth(uint targetId, uint currentHealth, uint maxHealth)
{
if (_active && targetId == _playerId && currentHealth == 0 && maxHealth > 0)
_stats.OnPlayerDied();
}
// Deaths are read every tick (CheckDeaths), not from OnUpdateHealth: the engine never sends the
// player's own health through it (that is a target's health: 0x01C0 and creature vitals), so the
// death count stayed 0 (2026-10-30).
// ── Tick (pump thread) ───────────────────────────────────────────────────
@ -180,6 +180,7 @@ internal sealed class SessionStatsTracker
}
if (!_active) return;
CheckDeaths();
CheckPendingCorpses(now);
long nowMs = Environment.TickCount64;
@ -211,6 +212,27 @@ internal sealed class SessionStatsTracker
private long? Read(uint stype)
=> _host.TryGetObjectQuadProperty(_playerId, stype, out long value) ? value : null;
/// <summary>
/// The player's health from the engine's vitals (the same reading RynthAi's death hold uses),
/// then the server's death counter, in the order the server sends them (SessionStats counts
/// each death once). Every tick: the health reads 0 for a few seconds only.
/// </summary>
private void CheckDeaths()
{
int before = _stats.Deaths;
if (_host.HasGetPlayerVitals
&& _host.TryGetPlayerVitals(out uint health, out uint maxHealth, out _, out _, out _, out _))
_stats.OnPlayerHealth(health, maxHealth);
if (_host.HasGetObjectIntProperty
&& _host.TryGetObjectIntProperty(_playerId, IntNumDeaths, out int numDeaths))
_stats.OnDeathCount(numDeaths);
if (_stats.Deaths != before)
{
_view = _stats.View(DateTime.UtcNow); // shown at once, not at the next poll
_host.Log($"{_tag} Death counted ({_stats.Deaths} this session).");
}
}
/// <summary>Reads the names of newly created objects; a "Corpse of X" goes to the kill counter.</summary>
private void CheckPendingCorpses(DateTime now)
{

View file

@ -90,6 +90,12 @@ internal sealed class TrackerSessionState
public long OwnSinceBank;
/// <summary>Luminance of the last five minutes, oldest first: (UTC ticks, amount).</summary>
public List<(long AtTicks, long Amount)> RecentLum = new();
// Added 2026-10-30 (deaths from the vitals and NumDeaths). Optional in the file, like the above.
/// <summary>The server's death counter (PropertyInt 43, NumDeaths) baseline.</summary>
public long? DeathCountBase;
/// <summary>A death counted from health 0 whose NumDeaths rise hadn't been read yet.</summary>
public bool DeathOpen;
}
internal static class TrackerSessionStore
@ -152,6 +158,8 @@ internal static class TrackerSessionStore
Line(sb, "bankincome", s.BankIncome.ToString(Ic));
Line(sb, "ownsincebank", s.OwnSinceBank.ToString(Ic));
Line(sb, "recentlum", Recent(s.RecentLum));
Line(sb, "deathsbase", Opt(s.DeathCountBase));
Line(sb, "deathopen", s.DeathOpen ? "1" : "0");
Line(sb, "end", "1"); // a torn write never parses
return sb.ToString();
}
@ -204,7 +212,10 @@ internal static class TrackerSessionStore
(!map.ContainsKey("lumown") || Long(map, "lumown", out s.LumOwn)) &&
(!map.ContainsKey("bankincome") || Long(map, "bankincome", out s.BankIncome)) &&
(!map.ContainsKey("ownsincebank") || Long(map, "ownsincebank", out s.OwnSinceBank)) &&
(!map.ContainsKey("recentlum") || ParseRecent(map["recentlum"], s.RecentLum));
(!map.ContainsKey("recentlum") || ParseRecent(map["recentlum"], s.RecentLum)) &&
// The 2026-10-30 keys may be absent too.
(!map.ContainsKey("deathsbase") || OptLong(map, "deathsbase", out s.DeathCountBase)) &&
(!map.ContainsKey("deathopen") || Bool(map, "deathopen", out s.DeathOpen));
if (!ok) return false;
// Ticks outside DateTime's range would throw when the plugin builds a DateTime.