feat: Add special round stats tracking

This commit is contained in:
MSWS
2025-11-10 01:36:15 -08:00
parent 3a463b29c6
commit e7dfbca35d
2 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
using System.Text;
using System.Text.Json;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using SpecialRound.Events;
using SpecialRoundAPI;
using TTT.API.Events;
using TTT.API.Game;
using TTT.Game.Events.Game;
using TTT.Game.Listeners;
namespace Stats;
public class SpecialRoundListener(IServiceProvider provider)
: BaseListener(provider) {
private readonly IRoundTracker tracker =
provider.GetRequiredService<IRoundTracker>();
private readonly HttpClient client =
provider.GetRequiredService<HttpClient>();
private AbstractSpecialRound? round;
[UsedImplicitly]
[EventHandler]
public void OnRoundStart(SpecialRoundStartEvent ev) { round = ev.Round; }
[UsedImplicitly]
[EventHandler]
public void OnRoundEnd(GameStateUpdateEvent ev) {
if (ev.NewState != State.FINISHED) return;
if (round == null) return;
var data = new { special_round = round.Name };
var payload = new StringContent(JsonSerializer.Serialize(data),
Encoding.UTF8, "application/json");
Task.Run(async () => {
var id = tracker.CurrentRoundId;
if (id == null) return;
await client.PatchAsync("round/" + id.Value, payload);
});
}
}

View File

@@ -9,6 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\Game\Game.csproj"/>
<ProjectReference Include="..\ShopAPI\ShopAPI.csproj"/>
<ProjectReference Include="..\SpecialRound\SpecialRound.csproj" />
</ItemGroup>
</Project>