Skip to content

Commit

Permalink
Allow doing /CTF/LS/TW start to autostart on a configured map even wh…
Browse files Browse the repository at this point in the history
…en there are only 1-2 maps configured

Previously although '/game start [level name]' would work even when only 1-2 maps configured, '/game start' wouldn't work unless 3 or more maps were configured
  • Loading branch information
UnknownShadow200 committed Oct 20, 2022
1 parent a17c717 commit 2152efb
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions MCGalaxy/Games/RoundsGame/LevelPicker.cs
Expand Up @@ -19,17 +19,19 @@
using System.Collections.Generic;
using System.Threading;

namespace MCGalaxy.Games {
public class LevelPicker {
namespace MCGalaxy.Games
{
public class LevelPicker
{
public string QueuedMap;
public List<string> RecentMaps = new List<string>();
public int VoteTime = 20;
public bool Voting;

internal string Candidate1 = "", Candidate2 = "", Candidate3 = "";
internal int Votes1, Votes2, Votes3;
const int minMaps = 3;
const int MIN_MAPS = 3;

public void AddRecentMap(string map) {
if (RecentMaps.Count >= 20)
RecentMaps.RemoveAt(0);
Expand All @@ -40,12 +42,16 @@ public class LevelPicker {
QueuedMap = null;
RecentMaps.Clear();
}

public string ChooseNextLevel(RoundsGame game) {
if (QueuedMap != null) return QueuedMap;

try {
List<string> maps = GetCandidateMaps(game);
if (maps.Count < MIN_MAPS) {
Logger.Log(LogType.Warning, "You must have 3 or more maps configured to change levels in " + game.GameName);
return null;
}
if (maps == null) return null;

RemoveRecentLevels(maps);
Expand All @@ -70,14 +76,15 @@ public class LevelPicker {
void RemoveRecentLevels(List<string> maps) {
// Try to avoid recently played levels, avoiding most recent
List<string> recent = RecentMaps;
for (int i = recent.Count - 1; i >= 0; i--) {
if (maps.Count > minMaps) maps.CaselessRemove(recent[i]);
for (int i = recent.Count - 1; i >= 0; i--)
{
if (maps.Count > MIN_MAPS) maps.CaselessRemove(recent[i]);
}

// Try to avoid maps voted last round if possible
if (maps.Count > minMaps) maps.CaselessRemove(Candidate1);
if (maps.Count > minMaps) maps.CaselessRemove(Candidate2);
if (maps.Count > minMaps) maps.CaselessRemove(Candidate3);
if (maps.Count > MIN_MAPS) maps.CaselessRemove(Candidate1);
if (maps.Count > MIN_MAPS) maps.CaselessRemove(Candidate2);
if (maps.Count > MIN_MAPS) maps.CaselessRemove(Candidate3);
}

void DoLevelVote(IGame game) {
Expand Down Expand Up @@ -140,12 +147,7 @@ public class LevelPicker {
}

public virtual List<string> GetCandidateMaps(RoundsGame game) {
List<string> maps = new List<string>(game.GetConfig().Maps);
if (maps.Count < minMaps) {
Logger.Log(LogType.Warning, "You must have 3 or more maps configured to change levels in " + game.GameName);
return null;
}
return maps;
return new List<string>(game.GetConfig().Maps);
}

public void SendVoteMessage(Player p) {
Expand Down

0 comments on commit 2152efb

Please sign in to comment.