feat(tvt): per-character scoreboard (kills, statues, statue damage)

Server: new 0xFD HeykelSavasiScoreboard packet + view plugin; HeykelSavasiContext tracks per-player
kills (Player.AfterKilledPlayerAsync hook), statues broken (OnDestructibleDied), and statue damage
(AttackableNpcBase.AttackByAsync hook); broadcast top-8 by damage (desc) every ~1s, omitting zero-damage
characters.
This commit is contained in:
Acentech Dev
2026-07-21 16:34:15 +03:00
parent 586590e06f
commit 538189ea7c
8 changed files with 573 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
// <copyright file="HeykelSavasiScoreboardPlugIn.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
namespace MUnique.OpenMU.GameServer.RemoteView.MiniGames;
using System.Runtime.InteropServices;
using MUnique.OpenMU.GameLogic;
using MUnique.OpenMU.GameLogic.Views.MiniGames;
using MUnique.OpenMU.Network;
using MUnique.OpenMU.Network.Packets.ServerToClient;
using MUnique.OpenMU.PlugIns;
/// <summary>
/// The default implementation of the <see cref="IHeykelSavasiScoreboardPlugIn"/> which forwards the
/// per-character scoreboard to the game client with a <see cref="HeykelSavasiScoreboardRef"/> data packet
/// (code 0xFD).
/// </summary>
[PlugIn]
[Guid("a3d8f1c2-6b4e-4f7a-8c2d-9e1b3a5f7d20")]
public class HeykelSavasiScoreboardPlugIn : IHeykelSavasiScoreboardPlugIn
{
private readonly RemotePlayer _player;
/// <summary>
/// Initializes a new instance of the <see cref="HeykelSavasiScoreboardPlugIn"/> class.
/// </summary>
/// <param name="player">The player.</param>
public HeykelSavasiScoreboardPlugIn(RemotePlayer player) => this._player = player;
/// <inheritdoc/>
public async ValueTask UpdateScoreboardAsync(IReadOnlyList<(string Name, ushort Kills, byte Statues, uint Damage)> entries)
{
var connection = this._player.Connection;
if (connection is null)
{
return;
}
// A byte Count field caps the scoreboard at 255 entries; the caller sends far fewer (top contributors).
var count = entries.Count > byte.MaxValue ? byte.MaxValue : entries.Count;
int Write()
{
var size = HeykelSavasiScoreboardRef.GetRequiredSize(count);
var span = connection.Output.GetSpan(size)[..size];
var packet = new HeykelSavasiScoreboardRef(span)
{
Count = (byte)count,
};
for (var i = 0; i < count; i++)
{
var block = packet[i];
block.Name = entries[i].Name;
block.Kills = entries[i].Kills;
block.Statues = entries[i].Statues;
block.Damage = entries[i].Damage;
}
return size;
}
await connection.SendAsync(Write).ConfigureAwait(false);
}
}