-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cs
106 lines (93 loc) · 3.79 KB
/
Utils.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using BrawlSharp.Model.Player.BattleLog;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
namespace BrawlEvents
{
public class Utils
{
public static List<Player> GetPlayersFromBattle(Battle battle)
{
List<Player> players = new List<Player>();
if (battle.Match.Players != null)
{
foreach (var player in battle.Match.Players)
{
if (!players.Contains(player))
players.Add(player);
}
}
else
{
foreach (var team in battle.Match.Teams)
{
foreach (var player in team)
{
if (!players.Contains(player))
players.Add(player);
}
}
}
return players;
}
public static List<Stat> GetBrawlerStatsFromBattles(List<Battle> battles, int brawlerId)
{
ConcurrentDictionary<int, int> matches = new ConcurrentDictionary<int, int>();
ConcurrentDictionary<int, int> wins = new ConcurrentDictionary<int, int>();
foreach (Battle battle in battles)
{
if (battle.Match.Type != "friendly" && battle.Map.Id != 0 && battle.Match.Mode != "duels")
{
bool hasBrawler = false;
if (battle.Match.Players != null)
{
foreach (Player player in battle.Match.Players)
{
if (player.Brawler.Id == brawlerId && !hasBrawler)
{
hasBrawler = true;
matches.AddOrUpdate(battle.Map.Id, 1, (id, value) => value + 1);
}
}
if (battle.Match.Players[0].Brawler.Id == brawlerId)
wins.AddOrUpdate(battle.Map.Id, 1, (id, value) => value + 1);
}
else
{
foreach (var team in battle.Match.Teams)
{
if (team.Any(p => p.Brawler.Id == brawlerId) && !hasBrawler)
{
hasBrawler = true;
matches.AddOrUpdate(battle.Map.Id, 1, (id, value) => value + 1);
}
}
if (battle.Match.Mode == "duoShowdown")
{
bool hasBrawlerWin = false;
foreach (Player player in battle.Match.Teams[0])
{
if (player.Brawler.Id == brawlerId && !hasBrawlerWin)
{
hasBrawlerWin = true;
wins.AddOrUpdate(battle.Map.Id, 1, (id, value) => value + 1);
}
}
}
if (battle.Match.StarPlayer?.Brawler.Id == brawlerId)
wins.AddOrUpdate(battle.Map.Id, 1, (id, value) => value + 1);
}
}
}
List<Stat> stats = new List<Stat>();
foreach (var map in matches)
{
if (wins.TryGetValue(map.Key, out int winCount))
stats.Add(new Stat(brawlerId, map.Key, map.Value, winCount));
else
stats.Add(new Stat(brawlerId, map.Key, map.Value, 0));
}
return stats;
}
}
}