public Player(World world, Session.Client client, PlayerReference pr)
{
string botType;
World = world;
InternalName = pr.Name;
PlayerReference = pr;
// Real player or host-created bot
if (client != null)
{
ClientIndex = client.Index;
Color = client.Color;
PlayerName = client.Name;
botType = client.Bot;
Faction = ChooseFaction(world, client.Faction, !pr.LockFaction);
DisplayFaction = ChooseDisplayFaction(world, client.Faction);
}
else
{
// Map player
ClientIndex = 0; // Owned by the host (TODO: fix this)
Color = pr.Color;
PlayerName = pr.Name;
NonCombatant = pr.NonCombatant;
Playable = pr.Playable;
Spectating = pr.Spectating;
botType = pr.Bot;
Faction = ChooseFaction(world, pr.Faction, false);
DisplayFaction = ChooseDisplayFaction(world, pr.Faction);
}
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });
Shroud = PlayerActor.Trait<Shroud>();
fogVisibilities = PlayerActor.TraitsImplementing<IFogVisibilityModifier>().ToArray();
// Enable the bot logic on the host
IsBot = botType != null;
if (IsBot && Game.IsHost)
{
var logic = PlayerActor.TraitsImplementing<IBot>().FirstOrDefault(b => b.Info.Name == botType);
if (logic == null)
Log.Write("debug", "Invalid bot type: {0}", botType);
else
logic.Activate(this);
}
stanceColors.Self = ChromeMetrics.Get<Color>("PlayerStanceColorSelf");
stanceColors.Allies = ChromeMetrics.Get<Color>("PlayerStanceColorAllies");
stanceColors.Enemies = ChromeMetrics.Get<Color>("PlayerStanceColorEnemies");
stanceColors.Neutrals = ChromeMetrics.Get<Color>("PlayerStanceColorNeutrals");
}