Skip to content

Commit

Permalink
assure there are no duplicate maps in the map selection poll
Browse files Browse the repository at this point in the history
  • Loading branch information
DeinFreund committed Feb 16, 2019
1 parent 77623dc commit ce1528b
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions ZkLobbyServer/ServerBattle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -907,37 +907,49 @@ protected virtual async Task OnDedicatedExited(SpringBattleContext springBattleC

private void discussionTimer_Elapsed(object sender, ElapsedEventArgs e)
{
discussionTimer.Stop();
var poll = new CommandPoll(this, false, false, true);
poll.PollEnded += MapVoteEnded;
var options = new List<PollOption>();
for (int i = 0; i < NumberOfMapChoices; i++)
try
{
Resource map;
if (i < NumberOfMapChoices / 2)
{
map = MapPicker.GetRecommendedMap(GetContext(), MinimalMapSupportLevel, MapRatings.GetMapRanking().TakeWhile(x => x.Percentile < 0.2).Select(x => x.Map).AsQueryable()); //choose at least 50% popular maps
}
else
discussionTimer.Stop();
var poll = new CommandPoll(this, false, false, true);
poll.PollEnded += MapVoteEnded;
var options = new List<PollOption>();
List<Resource> pickedMaps = new List<Resource>();
using (var db = new ZkDataContext())
{
map = MapPicker.GetRecommendedMap(GetContext(), (MinimalMapSupportLevel < MapSupportLevel.Featured) ? MapSupportLevel.Supported : MinimalMapSupportLevel);
}
options.Add(new PollOption()
{
Name = map.InternalName,
URL = $"{GlobalConst.BaseSiteUrl}/Maps/Detail/{map.ResourceID}",
ResourceID = map.ResourceID,
Action = async () =>
for (int i = 0; i < NumberOfMapChoices; i++)
{
var cmd = new CmdMap().Create();
cmd.Arm(this, null, map.ResourceID.ToString());
if (cmd.Access == BattleCommand.AccessType.NotIngame && spring.IsRunning) return;
if (cmd.Access == BattleCommand.AccessType.Ingame && !spring.IsRunning) return;
await cmd.ExecuteArmed(this, null);
Resource map;
if (i < NumberOfMapChoices / 2)
{
map = MapPicker.GetRecommendedMap(GetContext(), MinimalMapSupportLevel, MapRatings.GetMapRanking().TakeWhile(x => x.Percentile < 0.2).Select(x => x.Map).Except(pickedMaps).AsQueryable()); //choose at least 50% popular maps
}
else
{
map = MapPicker.GetRecommendedMap(GetContext(), (MinimalMapSupportLevel < MapSupportLevel.Featured) ? MapSupportLevel.Supported : MinimalMapSupportLevel, db.Resources.Where(x => !pickedMaps.Contains(x)));
}
pickedMaps.Add(map);
options.Add(new PollOption()
{
Name = map.InternalName,
URL = $"{GlobalConst.BaseSiteUrl}/Maps/Detail/{map.ResourceID}",
ResourceID = map.ResourceID,
Action = async () =>
{
var cmd = new CmdMap().Create();
cmd.Arm(this, null, map.ResourceID.ToString());
if (cmd.Access == BattleCommand.AccessType.NotIngame && spring.IsRunning) return;
if (cmd.Access == BattleCommand.AccessType.Ingame && !spring.IsRunning) return;
await cmd.ExecuteArmed(this, null);
}
});
}
});
}
StartVote(new CmdMap().GetIneligibilityReasonFunc(this), options, null, "Choose the next map", poll, MapVoteTime);
}
catch (Exception ex)
{
Trace.TraceError("Error creating map poll: " + ex);
}
StartVote(new CmdMap().GetIneligibilityReasonFunc(this), options, null, "Choose the next map", poll, MapVoteTime);
}

private void MapVoteEnded(object sender, PollOutcome e)
Expand Down

0 comments on commit ce1528b

Please sign in to comment.