diff --git a/UncreatedWarfare/Layouts/Phases/LeaderboardPhase.cs b/UncreatedWarfare/Layouts/Phases/LeaderboardPhase.cs index 7f612c8c..128cbff2 100644 --- a/UncreatedWarfare/Layouts/Phases/LeaderboardPhase.cs +++ b/UncreatedWarfare/Layouts/Phases/LeaderboardPhase.cs @@ -1,9 +1,10 @@ -using DanielWillett.ReflectionTools.Emit; +using DanielWillett.ReflectionTools.Emit; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Globalization; +using System.Linq; using System.Reflection; using System.Reflection.Emit; using Uncreated.Warfare.Events.Models; @@ -137,6 +138,24 @@ public void Dispose() public virtual LeaderboardSet[] CreateLeaderboardSets() { + for (int i = 0; i < _players.Length; ++i) + { + List players = _players[i]; + foreach (LeaderboardPlayer player in players) + { + for (int j = 0; j < _players.Length; ++j) + { + if (j == i) + continue; + + List otherPlayers = _players[j]; + int olderPlayer = otherPlayers.FindIndex(x => x.Player.Equals(player) && x.LastJoinedTeam <= player.LastJoinedTeam); + if (olderPlayer >= 0) + otherPlayers.RemoveAt(olderPlayer); + } + } + } + LeaderboardSet[] set = new LeaderboardSet[TeamManager.AllTeams.Count]; for (int i = 0; i < TeamManager.AllTeams.Count; ++i) @@ -245,8 +264,11 @@ private void CheckPlayer(WarfarePlayer player) List players = _players[teamIndex]; foreach (LeaderboardPlayer pl in players) { - if (pl.Player.Equals(player)) - return; + if (!pl.Player.Equals(player)) + continue; + + pl.LastJoinedTeam = Time.realtimeSinceStartup; + return; } players.Add(new LeaderboardPlayer(player, team)); @@ -264,7 +286,7 @@ public class LeaderboardPhaseStatInfo public string Name { get; set; } = string.Empty; public string? FormulaName { get; set; } - public bool Visible { get; set; } = true; + public bool IsLeaderboardColumn { get; set; } = true; public string? Expression { get; set; } } \ No newline at end of file diff --git a/UncreatedWarfare/Layouts/UI/Leaderboards/LeaderboardPlayer.cs b/UncreatedWarfare/Layouts/UI/Leaderboards/LeaderboardPlayer.cs index 7d03f0ec..6922cb7a 100644 --- a/UncreatedWarfare/Layouts/UI/Leaderboards/LeaderboardPlayer.cs +++ b/UncreatedWarfare/Layouts/UI/Leaderboards/LeaderboardPlayer.cs @@ -1,4 +1,4 @@ -using Uncreated.Warfare.Layouts.Teams; +using Uncreated.Warfare.Layouts.Teams; using Uncreated.Warfare.Players; namespace Uncreated.Warfare.Layouts.UI.Leaderboards; @@ -6,9 +6,11 @@ public class LeaderboardPlayer { public WarfarePlayer Player { get; } public Team Team { get; } + public float LastJoinedTeam { get; set; } public LeaderboardPlayer(WarfarePlayer player, Team team) { Player = player; Team = team; + LastJoinedTeam = Time.realtimeSinceStartup; } } diff --git a/UncreatedWarfare/Layouts/UI/Leaderboards/LeaderboardSet.cs b/UncreatedWarfare/Layouts/UI/Leaderboards/LeaderboardSet.cs index 9a43500d..4b64a9f7 100644 --- a/UncreatedWarfare/Layouts/UI/Leaderboards/LeaderboardSet.cs +++ b/UncreatedWarfare/Layouts/UI/Leaderboards/LeaderboardSet.cs @@ -45,7 +45,7 @@ public LeaderboardSet(CreateRow callback, LeaderboardPhaseStatInfo[] stats, IEnu int visibleColumns = 0; for (int i = 0; i < stats.Length; ++i) { - if (stats[i].Visible) + if (stats[i].IsLeaderboardColumn) ++visibleColumns; } @@ -54,7 +54,7 @@ public LeaderboardSet(CreateRow callback, LeaderboardPhaseStatInfo[] stats, IEnu for (int i = 0; i < stats.Length; ++i) { LeaderboardPhaseStatInfo stat = stats[i]; - if (stat.Visible) + if (stat.IsLeaderboardColumn) visibleStats[++visibleColumns] = stat; } @@ -81,7 +81,7 @@ public LeaderboardSet(CreateRow callback, LeaderboardPhaseStatInfo[] stats, IEnu _inverseSortMaps = new int[visibleStats.Length * 2][]; } - public double GetStatisticValue(string statName, CSteamID player) + public int GetStatisticIndex(string statName) { int statIndex = -1; for (int i = 0; i < Stats.Length; ++i) @@ -93,6 +93,12 @@ public double GetStatisticValue(string statName, CSteamID player) break; } + return statIndex; + } + + public double GetStatisticValue(string statName, CSteamID player) + { + int statIndex = GetStatisticIndex(statName); if (statIndex == -1) return 0;