-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.cs
78 lines (68 loc) · 2.13 KB
/
Config.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
global using static SMembersInfo.Faction;
namespace SMembersInfo
{
public class Faction
{
[XmlAttribute]
public string
Name;
public List<Rank> Ranks = new ();
public class Rank
{
[XmlAttribute]
public string
Group, DisplayName;
public override string ToString() => DisplayName;
}
public virtual Rank IsMember(UP up)
{
var groups = R.Permissions.GetGroups(up, false);
return Ranks.FirstOrDefault(x => groups.Any(y => y.Id == x.Group));
}
public class Member
{
public Member(int id, UnturnedPlayer player, Rank rank)
{
Id = id;
Player = player;
Rank = rank;
}
public int Id { get; }
public UP Player { get; }
public Rank Rank { get; }
}
public virtual IEnumerable<Member> FindMembers()
{
var counter = 0;
foreach(var up in UPList)
{
var rank = IsMember(up);
if (rank is null)
continue;
yield return new (++counter, up, rank);
}
}
public virtual string Format(out IEnumerable<Member> members, out int count)
{
members = FindMembers();
count = members.Count();
return TranslateFactionFormat(Name, count, count == 0 ? 0 : (count * 100d) / Provider.clients.Count, 1);
}
public virtual IEnumerable<string> FormatMembers(IEnumerable<Member> members) => members.Select(x => TranslateMemberFormat(x.Id, x.Player.CharacterName, x.Rank));
}
public partial class Config : IRocketPluginConfiguration
{
public List<Faction> Factions = new();
public void LoadDefaults()
{
Factions.Add(new()
{
Name = "Police",
Ranks = new()
{
new() { Group = "police1", DisplayName = "Officer" }
}
});
}
}
}