Player: move player name resolve in a dedicated function
Signed-off-by: Paul Chote <pchote@users.noreply.github.com>
This commit is contained in:
@@ -123,6 +123,18 @@ namespace OpenRA
|
|||||||
return factions.FirstOrDefault(f => f.InternalName == factionName) ?? factions.First();
|
return factions.FirstOrDefault(f => f.InternalName == factionName) ?? factions.First();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ResolvePlayerName(Session.Client client, IEnumerable<Session.Client> clients, IEnumerable<IBotInfo> botInfos)
|
||||||
|
{
|
||||||
|
if (client.Bot != null)
|
||||||
|
{
|
||||||
|
var botInfo = botInfos.First(b => b.Type == client.Bot);
|
||||||
|
var botsOfSameType = clients.Where(c => c.Bot == client.Bot).ToArray();
|
||||||
|
return botsOfSameType.Length == 1 ? botInfo.Name : "{0} {1}".F(botInfo.Name, botsOfSameType.IndexOf(client) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.Name;
|
||||||
|
}
|
||||||
|
|
||||||
public Player(World world, Session.Client client, PlayerReference pr)
|
public Player(World world, Session.Client client, PlayerReference pr)
|
||||||
{
|
{
|
||||||
World = world;
|
World = world;
|
||||||
@@ -136,14 +148,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
ClientIndex = client.Index;
|
ClientIndex = client.Index;
|
||||||
Color = client.Color;
|
Color = client.Color;
|
||||||
if (client.Bot != null)
|
PlayerName = ResolvePlayerName(client, world.LobbyInfo.Clients, world.Map.Rules.Actors["player"].TraitInfos<IBotInfo>());
|
||||||
{
|
|
||||||
var botInfo = world.Map.Rules.Actors["player"].TraitInfos<IBotInfo>().First(b => b.Type == client.Bot);
|
|
||||||
var botsOfSameType = world.LobbyInfo.Clients.Where(c => c.Bot == client.Bot).ToArray();
|
|
||||||
PlayerName = botsOfSameType.Length == 1 ? botInfo.Name : "{0} {1}".F(botInfo.Name, botsOfSameType.IndexOf(client) + 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
PlayerName = client.Name;
|
|
||||||
|
|
||||||
BotType = client.Bot;
|
BotType = client.Bot;
|
||||||
Faction = ChooseFaction(world, client.Faction, !pr.LockFaction);
|
Faction = ChooseFaction(world, client.Faction, !pr.LockFaction);
|
||||||
|
|||||||
Reference in New Issue
Block a user