Snapshot for release 2026.10.7.1 (internal 2a9c773)
This commit is contained in:
parent
bf702ebc67
commit
26907e6ab1
29 changed files with 1900 additions and 110 deletions
188
Plugins/RynthCore.Plugin.RynthTracker/KillCounter.cs
Normal file
188
Plugins/RynthCore.Plugin.RynthTracker/KillCounter.cs
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RynthCore.Plugin.RynthTracker;
|
||||
|
||||
/// <summary>
|
||||
/// Counts your kills, including the extra monsters a ring, wall, blast or chain spell kills.
|
||||
///
|
||||
/// Two ways a kill is counted:
|
||||
/// 1. The server's killer notification (it goes only to whoever landed the killing blow).
|
||||
/// One notification is one kill, as before.
|
||||
/// 2. A corpse ("Corpse of X") with no notification for it, when you hit an X with a
|
||||
/// multi-target spell in the last <see cref="TokenLifeMs"/>. Some servers send no
|
||||
/// notification for the extra monsters a spell kills (chain spells on Conquest), and on
|
||||
/// ACE a killing blow sends no damage line either, so the corpse is the one sign left.
|
||||
///
|
||||
/// "Multi-target" is read from the combat log: one cast's damage lines (and kill notices)
|
||||
/// arrive together, so lines no more than <see cref="VolleyGapMs"/> apart are one volley, and
|
||||
/// a volley with two or more of them hit several monsters. Each name hit in such a volley may
|
||||
/// be counted from its corpse as many times as that volley hit it (tokens). A single-target
|
||||
/// hit never makes a corpse count: a monster you hit once that someone else then finished
|
||||
/// isn't yours, the same as before.
|
||||
///
|
||||
/// A notification is matched to its corpse later (the corpse forms after the death animation),
|
||||
/// so a kill counted by its notification isn't counted again by its corpse.
|
||||
///
|
||||
/// Pure logic, no host: the plugin passes every event with its time, so tests can drive it.
|
||||
/// </summary>
|
||||
internal sealed class KillCounter
|
||||
{
|
||||
/// <summary>Damage lines and kill notices this close together belong to one cast.</summary>
|
||||
public const double VolleyGapMs = 800;
|
||||
/// <summary>How long after a multi-target hit a monster's corpse still counts as your kill.</summary>
|
||||
public const double TokenLifeMs = 15000;
|
||||
/// <summary>How long a kill notice waits for its corpse.</summary>
|
||||
public const double NoticeLifeMs = 20000;
|
||||
/// <summary>How long a single-target hit is remembered (only to explain an uncounted corpse in the log).</summary>
|
||||
public const double HitMemoryMs = 15000;
|
||||
|
||||
public int Kills { get; private set; }
|
||||
public int NoticeKills { get; private set; }
|
||||
public int CorpseKills { get; private set; }
|
||||
|
||||
private readonly List<(string Message, DateTime At)> _notices = new();
|
||||
private readonly Dictionary<string, (int Count, DateTime Until)> _tokens = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, DateTime> _lastHit = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// The volley in progress: hits per name, and how many members (lines + notices) it has.
|
||||
private readonly Dictionary<string, int> _volley = new(StringComparer.OrdinalIgnoreCase);
|
||||
private int _volleyMembers;
|
||||
private DateTime _volleyLast = DateTime.MinValue;
|
||||
|
||||
/// <summary>The server's killer notification: always one kill.</summary>
|
||||
public void OnKillNotice(string? message, DateTime now)
|
||||
{
|
||||
Kills++;
|
||||
NoticeKills++;
|
||||
Prune(now);
|
||||
_notices.Add((message ?? "", now));
|
||||
JoinVolley(now);
|
||||
// A notice is one of the volley's monsters too (the killing blow sends no damage line),
|
||||
// under the name of a monster we hit that the message contains.
|
||||
string? name = LongestRecentHitIn(message ?? "", now);
|
||||
if (name != null) _volley[name] = _volley.TryGetValue(name, out int n) ? n + 1 : 1;
|
||||
GrantTokens(now);
|
||||
}
|
||||
|
||||
private string? LongestRecentHitIn(string message, DateTime now)
|
||||
{
|
||||
string? best = null;
|
||||
foreach (var kv in _lastHit)
|
||||
{
|
||||
if ((now - kv.Value).TotalMilliseconds > HitMemoryMs) continue;
|
||||
if (message.IndexOf(kv.Key, StringComparison.OrdinalIgnoreCase) < 0) continue;
|
||||
if (best == null || kv.Key.Length > best.Length) best = kv.Key;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/// <summary>One of your damage lines, naming the monster it hurt.</summary>
|
||||
public void OnHit(string victim, DateTime now)
|
||||
{
|
||||
if (string.IsNullOrEmpty(victim)) return;
|
||||
JoinVolley(now);
|
||||
_volley[victim] = _volley.TryGetValue(victim, out int n) ? n + 1 : 1;
|
||||
_lastHit[victim] = now;
|
||||
GrantTokens(now);
|
||||
}
|
||||
|
||||
/// <summary>What a corpse turned out to be.</summary>
|
||||
public enum CorpseResult
|
||||
{
|
||||
/// <summary>Its kill notice already counted it.</summary>
|
||||
Notified,
|
||||
/// <summary>No notice, but you hit it with a multi-target spell: counted now.</summary>
|
||||
Counted,
|
||||
/// <summary>You hit a monster of that name, but only single-target: not counted (someone else's kill?).</summary>
|
||||
HitNotCounted,
|
||||
/// <summary>Nothing of yours.</summary>
|
||||
NotOurs,
|
||||
}
|
||||
|
||||
/// <summary>A corpse appeared; <paramref name="monsterName"/> is the X of "Corpse of X".</summary>
|
||||
public CorpseResult OnCorpse(string monsterName, DateTime now)
|
||||
{
|
||||
if (string.IsNullOrEmpty(monsterName)) return CorpseResult.NotOurs;
|
||||
Prune(now);
|
||||
|
||||
// The oldest notice that names this monster.
|
||||
int match = -1;
|
||||
for (int i = 0; i < _notices.Count; i++)
|
||||
if (_notices[i].Message.IndexOf(monsterName, StringComparison.OrdinalIgnoreCase) >= 0) { match = i; break; }
|
||||
if (match >= 0)
|
||||
{
|
||||
_notices.RemoveAt(match);
|
||||
// It was one of the monsters a multi-target volley hit: it no longer vouches for another.
|
||||
if (_tokens.TryGetValue(monsterName, out var used) && used.Count > 0)
|
||||
_tokens[monsterName] = (used.Count - 1, used.Until);
|
||||
return CorpseResult.Notified;
|
||||
}
|
||||
|
||||
if (_tokens.TryGetValue(monsterName, out var t) && t.Count > 0 && t.Until >= now)
|
||||
{
|
||||
_tokens[monsterName] = (t.Count - 1, t.Until);
|
||||
Kills++;
|
||||
CorpseKills++;
|
||||
return CorpseResult.Counted;
|
||||
}
|
||||
|
||||
return _lastHit.TryGetValue(monsterName, out DateTime h) && (now - h).TotalMilliseconds <= HitMemoryMs
|
||||
? CorpseResult.HitNotCounted
|
||||
: CorpseResult.NotOurs;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Kills = NoticeKills = CorpseKills = 0;
|
||||
_notices.Clear();
|
||||
_tokens.Clear();
|
||||
_lastHit.Clear();
|
||||
_volley.Clear();
|
||||
_volleyMembers = 0;
|
||||
_volleyLast = DateTime.MinValue;
|
||||
}
|
||||
|
||||
private void JoinVolley(DateTime now)
|
||||
{
|
||||
if ((now - _volleyLast).TotalMilliseconds > VolleyGapMs)
|
||||
{
|
||||
_volley.Clear();
|
||||
_volleyMembers = 0;
|
||||
}
|
||||
_volleyMembers++;
|
||||
_volleyLast = now;
|
||||
}
|
||||
|
||||
// A volley that hit several monsters makes each name it hit countable from its corpse, as
|
||||
// many times as the volley hit that name. Max, not sum: the next cast hits the same monsters
|
||||
// again, and two casts at two monsters are still two monsters.
|
||||
private void GrantTokens(DateTime now)
|
||||
{
|
||||
if (_volleyMembers < 2) return;
|
||||
DateTime until = now.AddMilliseconds(TokenLifeMs);
|
||||
foreach (var kv in _volley)
|
||||
{
|
||||
int have = _tokens.TryGetValue(kv.Key, out var t) && t.Until >= now ? t.Count : 0;
|
||||
_tokens[kv.Key] = (Math.Max(have, kv.Value), until);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<string> _pruneScratch = new();
|
||||
private void Prune(DateTime now)
|
||||
{
|
||||
_notices.RemoveAll(n => (now - n.At).TotalMilliseconds > NoticeLifeMs);
|
||||
if (_tokens.Count > 32)
|
||||
{
|
||||
_pruneScratch.Clear();
|
||||
foreach (var kv in _tokens) if (kv.Value.Until < now) _pruneScratch.Add(kv.Key);
|
||||
foreach (string k in _pruneScratch) _tokens.Remove(k);
|
||||
}
|
||||
if (_lastHit.Count > 64)
|
||||
{
|
||||
_pruneScratch.Clear();
|
||||
foreach (var kv in _lastHit) if ((now - kv.Value).TotalMilliseconds > HitMemoryMs) _pruneScratch.Add(kv.Key);
|
||||
foreach (string k in _pruneScratch) _lastHit.Remove(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +40,10 @@ public static unsafe class PluginExports
|
|||
public static void OnUpdateHealth(uint targetId, float healthRatio, uint currentHealth, uint maxHealth)
|
||||
=> Runtime.OnUpdateHealth(targetId, healthRatio, currentHealth, maxHealth);
|
||||
|
||||
// Corpses (0.3.0): a kill a ring, wall or chain spell made without a kill notice is found by its corpse.
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnCreateObject", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void OnCreateObject(uint objectId) => Runtime.OnCreateObject(objectId);
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnDeleteObject", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void OnDeleteObject(uint objectId) => Runtime.OnDeleteObject(objectId);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@
|
|||
<RynthPluginDescription>Kills, experience and luminance per hour for each session.</RynthPluginDescription>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Reading our hits out of the combat log (victim + amount); RynthAi reads the same lines. -->
|
||||
<Compile Include="..\Shared\CombatText.cs" Link="Shared\CombatText.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\RynthCore\src\RynthCore.PluginCore\RynthCore.PluginCore.csproj" />
|
||||
<ProjectReference Include="..\..\..\RynthCore\src\RynthCore.PluginSdk\RynthCore.PluginSdk.csproj" />
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RynthCore.Plugin.Shared;
|
||||
using RynthCore.PluginCore;
|
||||
|
||||
namespace RynthCore.Plugin.RynthTracker;
|
||||
|
|
@ -8,7 +9,7 @@ namespace RynthCore.Plugin.RynthTracker;
|
|||
public sealed class RynthTrackerPlugin : RynthPluginBase
|
||||
{
|
||||
internal static readonly IntPtr NamePointer = Marshal.StringToHGlobalAnsi("RynthTracker");
|
||||
internal static readonly IntPtr VersionPointer = Marshal.StringToHGlobalAnsi("0.2.1");
|
||||
internal static readonly IntPtr VersionPointer = Marshal.StringToHGlobalAnsi("0.3.0");
|
||||
|
||||
private uint _playerId;
|
||||
private bool _loginComplete;
|
||||
|
|
@ -24,12 +25,28 @@ public sealed class RynthTrackerPlugin : RynthPluginBase
|
|||
// blow: a fellow's kill, a summon's kill or a mob someone else finished never counts,
|
||||
// and neither does the XP they bring (damage share, fellowship share, quests). That XP
|
||||
// still counts toward the totals and XP/hour.
|
||||
//
|
||||
// 0.3.0: plus the extra monsters a ring, wall, blast or chain spell kills when the
|
||||
// server sends no notification for them (chain spells on Conquest): their corpse counts
|
||||
// when you hit that monster with a multi-target spell just before (KillCounter.cs).
|
||||
private long _killXp;
|
||||
private int _xpKills; // kills that closed their window (the per-kill divisor)
|
||||
private int _openKills; // kills whose window is still open
|
||||
private DateTime _killWindowUntil; // XP rises seen until then belong to those kills
|
||||
private const double KillWindowSec = 2.5;
|
||||
|
||||
// Kill notices, our damage lines and corpses, for the kills a notice doesn't cover.
|
||||
private readonly KillCounter _killCounter = new();
|
||||
// Corpses waiting for their name (the client may not have it on the create tick).
|
||||
private readonly List<(uint Id, DateTime Seen)> _pendingCorpses = new();
|
||||
private const double CorpseNameWaitSec = 3.0;
|
||||
private const int MaxPendingCorpses = 256;
|
||||
// XP that landed outside any kill window: a kill found by its corpse (seconds after the
|
||||
// death animation) takes the XP of the few seconds before it.
|
||||
private readonly List<(DateTime At, long Xp)> _unattributedXp = new();
|
||||
private const double CorpseXpLookbackSec = 8.0;
|
||||
private int _corpseLogCount;
|
||||
|
||||
private int _tickCounter;
|
||||
|
||||
// Everything comes from the player's own properties, never from chat text:
|
||||
|
|
@ -126,6 +143,76 @@ public sealed class RynthTrackerPlugin : RynthPluginBase
|
|||
_killsTotal++;
|
||||
_openKills++;
|
||||
_killWindowUntil = DateTime.UtcNow.AddSeconds(KillWindowSec);
|
||||
_killCounter.OnKillNotice(deathMessage, DateTime.UtcNow);
|
||||
}
|
||||
|
||||
// Our damage lines name each monster a spell hurt (one line per monster for rings, walls,
|
||||
// blasts and chain spells): that is how a multi-target hit is recognised.
|
||||
public override void OnChatWindowText(string? text, int chatType, ref int eat)
|
||||
{
|
||||
if (!_loginComplete) return;
|
||||
if (CombatText.TryParseOutgoingHit(text, out string victim, out _))
|
||||
_killCounter.OnHit(victim, DateTime.UtcNow);
|
||||
}
|
||||
|
||||
// Corpses are read on the tick (their name may not be readable yet on the create).
|
||||
public override void OnCreateObject(uint objectId)
|
||||
{
|
||||
if (!_loginComplete || objectId == 0) return;
|
||||
if (_pendingCorpses.Count >= MaxPendingCorpses) _pendingCorpses.RemoveAt(0);
|
||||
_pendingCorpses.Add((objectId, DateTime.UtcNow));
|
||||
}
|
||||
|
||||
public override void OnDeleteObject(uint objectId)
|
||||
{
|
||||
for (int i = _pendingCorpses.Count - 1; i >= 0; i--)
|
||||
if (_pendingCorpses[i].Id == objectId) _pendingCorpses.RemoveAt(i);
|
||||
}
|
||||
|
||||
/// <summary>Reads the names of newly created objects; a "Corpse of X" goes to the kill counter.</summary>
|
||||
private void CheckPendingCorpses()
|
||||
{
|
||||
if (_pendingCorpses.Count == 0) return;
|
||||
if (!Host.HasGetObjectName) { _pendingCorpses.Clear(); return; }
|
||||
DateTime now = DateTime.UtcNow;
|
||||
for (int i = _pendingCorpses.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var (id, seen) = _pendingCorpses[i];
|
||||
if (!Host.TryGetObjectName(id, out string name) || string.IsNullOrEmpty(name))
|
||||
{
|
||||
if ((now - seen).TotalSeconds > CorpseNameWaitSec) _pendingCorpses.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
_pendingCorpses.RemoveAt(i);
|
||||
string? monster = CombatText.CorpseOwnerName(name);
|
||||
if (monster == null) continue;
|
||||
var result = _killCounter.OnCorpse(monster, now);
|
||||
if (result == KillCounter.CorpseResult.Counted)
|
||||
CountCorpseKill(now);
|
||||
if ((result == KillCounter.CorpseResult.Counted || result == KillCounter.CorpseResult.HitNotCounted)
|
||||
&& _corpseLogCount < 40)
|
||||
{
|
||||
_corpseLogCount++;
|
||||
Host.Log(result == KillCounter.CorpseResult.Counted
|
||||
? $"[RynthTracker] Kill counted from its corpse (no kill notice): '{name}' 0x{id:X8}, hit by a multi-target spell. Kills {_killsTotal}."
|
||||
: $"[RynthTracker] Not counted: '{name}' 0x{id:X8} - you hit it, single-target, and got no kill notice (someone else's kill?).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A kill found by its corpse: one more kill, and the XP of the seconds before it.</summary>
|
||||
private void CountCorpseKill(DateTime now)
|
||||
{
|
||||
_killsTotal++;
|
||||
bool inKillWindow = _openKills > 0 && now <= _killWindowUntil;
|
||||
if (inKillWindow) _openKills++; // closes with the window, its XP already in it
|
||||
else _xpKills++;
|
||||
for (int i = _unattributedXp.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if ((now - _unattributedXp[i].At).TotalSeconds > CorpseXpLookbackSec) continue;
|
||||
_killXp += _unattributedXp[i].Xp;
|
||||
_unattributedXp.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnUpdateHealth(uint targetId, float healthRatio, uint currentHealth, uint maxHealth)
|
||||
|
|
@ -148,6 +235,8 @@ public sealed class RynthTrackerPlugin : RynthPluginBase
|
|||
Host.Log("[RynthTracker] Session reset.");
|
||||
}
|
||||
|
||||
if (_loginComplete) CheckPendingCorpses();
|
||||
|
||||
if (++_tickCounter < 30) return; // rebuild every ~0.5s at 60Hz
|
||||
_tickCounter = 0;
|
||||
if (_loginComplete) PollExperience();
|
||||
|
|
@ -171,6 +260,12 @@ public sealed class RynthTrackerPlugin : RynthPluginBase
|
|||
long gained = _xpRise.Take(xp);
|
||||
_xpTotal += gained;
|
||||
if (inKillWindow) _killXp += gained;
|
||||
else if (gained > 0)
|
||||
{
|
||||
DateTime now = DateTime.UtcNow;
|
||||
_unattributedXp.RemoveAll(e => (now - e.At).TotalSeconds > CorpseXpLookbackSec);
|
||||
_unattributedXp.Add((now, gained));
|
||||
}
|
||||
// Capped only when past retail's 275 total AND kills keep bringing nothing: an
|
||||
// awakened character's cap is higher (Aelrynth), so the total alone can't say.
|
||||
_maxLevel = xp >= MaxLevelXp && _xpKills >= 3 && _xpTotal == 0;
|
||||
|
|
@ -213,6 +308,9 @@ public sealed class RynthTrackerPlugin : RynthPluginBase
|
|||
_xpKills = 0;
|
||||
_openKills = 0;
|
||||
_radTotal = 0;
|
||||
_killCounter.Reset();
|
||||
_pendingCorpses.Clear();
|
||||
_unattributedXp.Clear();
|
||||
// The next read of each is the new baseline.
|
||||
_xpRise.Clear(); _lumRise.Clear(); _radRise.Clear(); _bankedRise.Clear(); _drawnRise.Clear();
|
||||
_snapshot = EmptySnapshot;
|
||||
|
|
|
|||
Loading…
Reference in a new issue