-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the major bug with kills and add API
- Loading branch information
1 parent
0ed5b67
commit 40083ea
Showing
5 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Exiled.API.Features; | ||
|
||
namespace SCPStats | ||
{ | ||
public static class RoundStats | ||
{ | ||
internal static Dictionary<string, int> Kills = new Dictionary<string, int>(); | ||
internal static Dictionary<string, int> Deaths = new Dictionary<string, int>(); | ||
internal static Dictionary<string, int> Escapes = new Dictionary<string, int>(); | ||
|
||
internal static void Reset() | ||
{ | ||
Kills.Clear(); | ||
Deaths.Clear(); | ||
Escapes.Clear(); | ||
} | ||
|
||
private static Player GetPlayer(string id) | ||
{ | ||
return Player.UserIdsCache.TryGetValue(id, out var player) ? player : null; | ||
} | ||
|
||
public static int GetRoundKills(this Player p) => Kills.TryGetValue(p.UserId, out var kills) ? kills : 0; | ||
public static int GetRoundDeaths(this Player p) => Deaths.TryGetValue(p.UserId, out var deaths) ? deaths : 0; | ||
|
||
public static float GetKD(this Player p) | ||
{ | ||
var kills = p.GetRoundKills(); | ||
var deaths = p.GetRoundDeaths(); | ||
|
||
return kills == 0 || deaths == 0 ? 0 : (float) kills / deaths; | ||
} | ||
|
||
public static Player GetMostKills() | ||
{ | ||
if (Kills.Count < 1) return null; | ||
var id = Kills.Aggregate((l, r) => l.Value > r.Value ? l : r).Key; | ||
|
||
return GetPlayer(id); | ||
} | ||
|
||
public static Player GetLeastKills() | ||
{ | ||
if (Kills.Count < 1) return null; | ||
var id = Kills.Aggregate((l, r) => l.Value < r.Value ? l : r).Key; | ||
|
||
return GetPlayer(id); | ||
} | ||
|
||
public static Player GetMostDeaths() | ||
{ | ||
if (Deaths.Count < 1) return null; | ||
var id = Deaths.Aggregate((l, r) => l.Value > r.Value ? l : r).Key; | ||
|
||
return GetPlayer(id); | ||
} | ||
|
||
public static Player GetLeastDeaths() | ||
{ | ||
if (Deaths.Count < 1) return null; | ||
var id = Deaths.Aggregate((l, r) => l.Value < r.Value ? l : r).Key; | ||
|
||
return GetPlayer(id); | ||
} | ||
|
||
public static Player GetBestKD() | ||
{ | ||
return Player.List.OrderBy(p => p.GetKD()).FirstOrDefault(); | ||
} | ||
|
||
public static Player GetWorstKD() | ||
{ | ||
return Player.List.OrderBy(p => p.GetKD()).LastOrDefault(); | ||
} | ||
|
||
public static Player GetFirstEscape() | ||
{ | ||
return Escapes.Count < 1 ? null : GetPlayer(Escapes.Keys.First()); | ||
} | ||
|
||
public static Player GetFirstKill() | ||
{ | ||
return Kills.Count < 1 ? null : GetPlayer(Kills.Keys.First()); | ||
} | ||
|
||
public static Player GetFirstDeath() | ||
{ | ||
return Deaths.Count < 1 ? null : GetPlayer(Deaths.Keys.First()); | ||
} | ||
|
||
public static List<Player> GetEscapes() | ||
{ | ||
return Escapes.Keys.Select(GetPlayer).Where(pl => pl != null).ToList(); | ||
} | ||
} | ||
} |