Refactor default difficulty setting into its own method

This commit is contained in:
Scott_NZ
2012-12-12 13:19:37 +13:00
parent 32721ac8cb
commit 4b2e45bbae

View File

@@ -261,6 +261,7 @@ namespace OpenRA.Mods.RA.Server
server.lobbyInfo.GlobalSettings.Map = s; server.lobbyInfo.GlobalSettings.Map = s;
var oldSlots = server.lobbyInfo.Slots.Keys.ToArray(); var oldSlots = server.lobbyInfo.Slots.Keys.ToArray();
LoadMap(server); LoadMap(server);
SetDefaultDifficulty(server);
// Reassign players into new slots based on their old slots: // Reassign players into new slots based on their old slots:
// - Observers remain as observers // - Observers remain as observers
@@ -474,7 +475,12 @@ namespace OpenRA.Mods.RA.Server
return a(cmdValue); return a(cmdValue);
} }
public void ServerStarted(S server) { LoadMap(server); } public void ServerStarted(S server)
{
LoadMap(server);
SetDefaultDifficulty(server);
}
static Session.Slot MakeSlotFromPlayerReference(PlayerReference pr) static Session.Slot MakeSlotFromPlayerReference(PlayerReference pr)
{ {
if (!pr.Playable) return null; if (!pr.Playable) return null;
@@ -498,14 +504,16 @@ namespace OpenRA.Mods.RA.Server
.Select(p => MakeSlotFromPlayerReference(p.Value)) .Select(p => MakeSlotFromPlayerReference(p.Value))
.Where(s => s != null) .Where(s => s != null)
.ToDictionary(s => s.PlayerReference, s => s); .ToDictionary(s => s.PlayerReference, s => s);
}
static void SetDefaultDifficulty(S server)
{
if (server.Map.Difficulties != null && server.Map.Difficulties.Any()) if (server.Map.Difficulties != null && server.Map.Difficulties.Any())
{ {
if (!server.Map.Difficulties.Contains(server.lobbyInfo.GlobalSettings.Difficulty)) if (!server.Map.Difficulties.Contains(server.lobbyInfo.GlobalSettings.Difficulty))
server.lobbyInfo.GlobalSettings.Difficulty = server.Map.Difficulties.First(); server.lobbyInfo.GlobalSettings.Difficulty = server.Map.Difficulties.First();
} }
else else server.lobbyInfo.GlobalSettings.Difficulty = null;
server.lobbyInfo.GlobalSettings.Difficulty = null;
} }
} }
} }