Skip to content

Commit

Permalink
Fix PickRandomMap not working with Favourited map list (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
11EJDE11 authored Feb 5, 2025
1 parent 034090e commit f11f56f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,8 @@ private void PickRandomMap()
return;

int random = new Random().Next(0, maps.Count);
GameModeMap = GameModeMaps.Find(gmm => gmm.GameMode == GameMode && gmm.Map == maps[random]);

bool isFavoriteMapsSelected = IsFavoriteMapsSelected();
GameModeMap = GameModeMaps.Find(gmm => (gmm.GameMode == GameMode || gmm.IsFavorite && isFavoriteMapsSelected) && gmm.Map == maps[random]);
Logger.Log("PickRandomMap: Rolled " + random + " out of " + maps.Count + ". Picked map: " + Map.Name);

ChangeMap(GameModeMap);
Expand All @@ -747,17 +747,18 @@ private void PickRandomMap()

private List<Map> GetMapList(int playerCount)
{
if (playerCount == 1)
{
List<Map> allMaps = GameMode?.Maps.ToList() ?? new List<Map>();
return allMaps;
}

List<Map> mapList = (GameMode?.Maps.Where(x => x.MaxPlayers == playerCount) ?? Array.Empty<Map>()).ToList();
if (mapList.Count < 1 && playerCount <= MAX_PLAYER_COUNT)
return GetMapList(playerCount + 1);
else
return mapList;
List<Map> maps = IsFavoriteMapsSelected()
? GetFavoriteGameModeMaps().Select(gmm => gmm.Map).ToList()
: GameMode?.Maps.ToList() ?? new List<Map>();

if (playerCount != 1)
{
maps = maps.Where(x => x.MaxPlayers == playerCount).ToList();
if (maps.Count < 1 && playerCount <= MAX_PLAYER_COUNT)
return GetMapList(playerCount + 1);
}

return maps;
}

/// <summary>
Expand Down

0 comments on commit f11f56f

Please sign in to comment.