@@ -29,7 +29,7 @@ public static class MapPicker
2929 /// a multiple of player count
3030 /// </para>
3131 /// </remarks>
32- public static Resource GetRecommendedMap ( LobbyHostingContext context , MapSupportLevel minimumSupportLevel = MapSupportLevel . Featured )
32+ public static Resource GetRecommendedMap ( LobbyHostingContext context , MapSupportLevel minimumSupportLevel = MapSupportLevel . Featured , IQueryable < Resource > candidates = null )
3333 {
3434 var mode = context . Mode ;
3535 using ( var db = new ZkDataContext ( ) )
@@ -57,12 +57,13 @@ public static Resource GetRecommendedMap(LobbyHostingContext context, MapSupport
5757 if ( humanPlayers == 2 && botPlayers == 0 && allyteams == 2 ) mode = AutohostMode . Game1v1 ;
5858 break ;
5959 }
60+ var ret = candidates ?? db . Resources . AsQueryable ( ) ;
6061 switch ( mode )
6162 {
6263 case AutohostMode . Teams :
6364 case AutohostMode . None :
64- var ret =
65- db . Resources . Where (
65+
66+ ret = ret . Where (
6667 x => x . TypeID == ResourceType . Map && x . MapSupportLevel >= level && x . MapIsTeams != false && x . MapIsSpecial != true ) ;
6768 if ( humanPlayers > 11 ) ret = ret . Where ( x => x . MapHeight * x . MapHeight + x . MapWidth * x . MapWidth > 16 * 16 ) ;
6869 else if ( humanPlayers > 8 )
@@ -78,14 +79,13 @@ public static Resource GetRecommendedMap(LobbyHostingContext context, MapSupport
7879 break ;
7980 case AutohostMode . Game1v1 :
8081 list =
81- db . Resources . Where (
82+ ret . Where (
8283 x => x . TypeID == ResourceType . Map && x . MapSupportLevel >= level && x . MapIs1v1 == true && x . MapIsSpecial != true ) . ToList ( ) ;
8384 break ;
8485 case AutohostMode . GameChickens :
8586 if ( UseNormalMapForChickens )
8687 {
87- ret =
88- db . Resources . Where (
88+ ret = ret . Where (
8989 x =>
9090 x . TypeID == ResourceType . Map && x . MapSupportLevel >= level && x . MapIsSpecial != true &&
9191 ( x . MapWaterLevel == 1 ) ) ;
@@ -101,7 +101,7 @@ public static Resource GetRecommendedMap(LobbyHostingContext context, MapSupport
101101 } else
102102 {
103103 ret =
104- db . Resources . Where (
104+ ret . Where (
105105 x =>
106106 x . TypeID == ResourceType . Map && x . MapSupportLevel >= level && x . MapIsSpecial != true && x . MapIsChickens == true ) ;
107107 }
@@ -111,21 +111,22 @@ public static Resource GetRecommendedMap(LobbyHostingContext context, MapSupport
111111 break ;
112112 case AutohostMode . GameFFA :
113113 list =
114- db . Resources . Where (
114+ ret . Where (
115115 x => x . TypeID == ResourceType . Map && x . MapSupportLevel >= level && x . MapIsFfa == true && x . MapFFAMaxTeams == allyteams )
116116 . ToList ( ) ;
117117 if ( ! list . Any ( ) )
118118 list =
119- db . Resources . Where (
119+ ret . Where (
120120 x =>
121121 x . TypeID == ResourceType . Map && x . MapSupportLevel >= level && x . MapIsFfa == true &&
122122 ( humanPlayers % x . MapFFAMaxTeams == 0 ) ) . ToList ( ) ;
123- if ( ! list . Any ( ) ) list = db . Resources . Where ( x => x . TypeID == ResourceType . Map && x . MapSupportLevel >= level && x . MapIsFfa == true ) . ToList ( ) ;
123+ if ( ! list . Any ( ) ) list = ret . Where ( x => x . TypeID == ResourceType . Map && x . MapSupportLevel >= level && x . MapIsFfa == true ) . ToList ( ) ;
124124
125125 break ;
126126 }
127127 if ( list != null )
128128 {
129+ if ( ! list . Any ( ) && candidates != null ) list = candidates . ToList ( ) ;
129130 var r = new Random ( ) ;
130131 if ( list . Count > 0 )
131132 {
0 commit comments