Skip to content

Commit

Permalink
find a map containing the given name instead of selection directly
Browse files Browse the repository at this point in the history
  • Loading branch information
exd02 committed Feb 28, 2024
1 parent 621aefd commit a56e48e
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions Features/NominationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,39 @@ void Nominate(CCSPlayerController player, string map)
return;
}

if (_mapLister.Maps!.Select(x => x.Name).FirstOrDefault(x => x.ToLower() == map) is null)
var matchingMaps = _mapLister.Maps!
.Select(x => x.Name)
.Where(x => x.ToLower().Contains(map.ToLower()))
.ToList();

if (matchingMaps.Count == 0)
{
player!.PrintToChat(_localizer.LocalizeWithPrefix("general.invalid-map"));
return;

}
else if (matchingMaps.Count > 1)
{
player!.PrintToChat(_localizer.LocalizeWithPrefix("nominate.multiple-maps-containing-name"));
return;
}

string matchingMap = matchingMaps[0];

var userId = player.UserId!.Value;
if (!Nominations.ContainsKey(userId))
Nominations[userId] = new();

bool alreadyVoted = Nominations[userId].IndexOf(map) != -1;
bool alreadyVoted = Nominations[userId].IndexOf(matchingMap) != -1;
if (!alreadyVoted)
Nominations[userId].Add(map);
Nominations[userId].Add(matchingMap);

var totalVotes = Nominations.Select(x => x.Value.Where(y => y == map).Count())
var totalVotes = Nominations.Select(x => x.Value.Where(y => y == matchingMap).Count())
.Sum();

if (!alreadyVoted)
Server.PrintToChatAll(_localizer.LocalizeWithPrefix("nominate.nominated", player.PlayerName, map, totalVotes));
Server.PrintToChatAll(_localizer.LocalizeWithPrefix("nominate.nominated", player.PlayerName, matchingMap, totalVotes));
else
player.PrintToChat(_localizer.LocalizeWithPrefix("nominate.already-nominated", map, totalVotes));
player.PrintToChat(_localizer.LocalizeWithPrefix("nominate.already-nominated", matchingMap, totalVotes));
}

public List<string> NominationWinners()
Expand Down

0 comments on commit a56e48e

Please sign in to comment.