-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add nomination menu * Add min rounds to enable command config * Add change immediatly config * Add localization * Add pt-br translation * Update README * Update module version
- Loading branch information
Showing
10 changed files
with
249 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,86 @@ | ||
| ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Modules.Menu; | ||
|
||
namespace cs2_rockthevote | ||
{ | ||
public class NominationManager | ||
{ | ||
Dictionary<int, string> Nominations = new(); | ||
Dictionary<int, List<string>> Nominations = new(); | ||
ChatMenu? nominationMenu = null; | ||
|
||
public RockTheVote Plugin { get; } | ||
|
||
private string[] Maps; | ||
public NominationManager(RockTheVote plugin, string[] maps) | ||
{ | ||
Plugin = plugin; | ||
Maps = maps; | ||
nominationMenu = new("Nomination"); | ||
foreach (var map in Maps) | ||
{ | ||
nominationMenu.AddMenuOption(map, (CCSPlayerController player, ChatMenuOption option) => | ||
{ | ||
Nominate(player, option.Text); | ||
}); | ||
} | ||
} | ||
|
||
public void Nominate(int userId, string map) | ||
public void OpenNominationMenu(CCSPlayerController player) | ||
{ | ||
Nominations[userId] = map; | ||
ChatMenus.OpenMenu(player!, nominationMenu!); | ||
} | ||
|
||
public void Nominate(CCSPlayerController player, string map) | ||
{ | ||
if (Maps.FirstOrDefault(x => x.ToLower() == map) is null) | ||
{ | ||
player!.PrintToChat(Plugin.Localize("invalid-map")); | ||
return; | ||
|
||
} | ||
|
||
if (map == Server.MapName) | ||
{ | ||
player!.PrintToChat(Plugin.Localize("nominate-current")); | ||
return; | ||
} | ||
|
||
var userId = player.UserId!.Value; | ||
if(!Nominations.ContainsKey(userId)) | ||
Nominations[userId] = new(); | ||
|
||
if(Nominations[userId].IndexOf(map) == -1) | ||
Nominations[userId].Add(map); | ||
|
||
var totalVotes = Nominations.Select(x => x.Value.Where(y => y == map).Count()) | ||
.Sum(); | ||
|
||
Server.PrintToChatAll(Plugin.Localize("nominated", player.PlayerName, map, totalVotes)); | ||
} | ||
|
||
public List<string> Votes() | ||
public List<string> NominationWinners() | ||
{ | ||
return Nominations | ||
if(Nominations.Count == 0) | ||
return new List<string>(); | ||
|
||
var rawNominations = Nominations | ||
.Select(x => x.Value) | ||
.Aggregate((acc, x) => acc.Concat(x).ToList()); | ||
|
||
return rawNominations | ||
.Distinct() | ||
.Select(map => new KeyValuePair<string, int>(map, Nominations.Select(x => x.Value == map).Count())) | ||
.Select(map => new KeyValuePair<string, int>(map, rawNominations.Count(x => x == map))) | ||
.OrderByDescending(x => x.Value) | ||
.Select(x => x.Key) | ||
.Take(5) | ||
.ToList(); | ||
} | ||
|
||
public void RemoveNominations(int userId) | ||
{ | ||
if (!Nominations.ContainsKey(userId)) | ||
Nominations.Remove(userId); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.