-
Notifications
You must be signed in to change notification settings - Fork 0
/
Session.cs
87 lines (80 loc) · 2.94 KB
/
Session.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
namespace EventLogger
{
public class Session
{
public DateTime startTime;
public Dictionary<Tuple<ulong, int>, Player> players = new Dictionary<Tuple<ulong, int>, Player>();
public List<Event> events = new List<Event>();
public Event lastEvent;
public Session()
{
startTime = DateTime.Now;
}
public Event AddEvent(EventType type, Map map)
{
lastEvent = new Event(this, events.Count, type, map);
events.Add(lastEvent);
return lastEvent;
}
public Player AddPlayer(ulong steamId, int localIndex, string name)
{
Player player = new Player(steamId, localIndex, name);
players.Add(new Tuple<ulong, int>(steamId, localIndex), player);
return player;
}
public override string ToString()
{
List<Player> sortedPlayers = new List<Player>(players.Values);
sortedPlayers.Sort(ComparePlayers);
string s = "\tRESULTS";
foreach (Event e in events)
{
if (e.results.Count == 0)
{
continue; // no results for this event
}
s += "\t" + (MapAcronym)e.map;
}
s += "\t\tPoints\tTracks\tAverage\tTime";
for (int i = 0; i < sortedPlayers.Count; i++)
{
Player player = sortedPlayers[i];
s += "\r\n" + (i + 1) + "°\t" + player.name;
bool finishedAllRaces = true;
foreach (Event e in events)
{
if (e.results.Count == 0)
{
continue; // no results for this event
}
s += "\t";
if (player.results.TryGetValue(e.index, out Result result))
{
s += result.points;
if (e.type != EventType.CaptureTheChao && result.completion == Completion.DNF)
{
finishedAllRaces = false;
}
}
else
{
finishedAllRaces = false;
}
}
s += "\t\t" + player.totalPoints + "\t" + player.results.Count + "\t" + player.average + "\t" + Result.TruncatedTimeString(player.totalTime, 3);
if (!finishedAllRaces)
{
s += "*"; // asterisk on totals that don't include all timed events in the session
}
}
return s;
}
public int ComparePlayers(Player x, Player y)
{
int comp = y.totalPoints.CompareTo(x.totalPoints);
return comp != 0 ? comp : y.average.CompareTo(x.average);
}
}
}