OpenRA.GameInformation.AddPlayer C# (CSharp) Method

AddPlayer() public method

Adds the player information at start-up.
public AddPlayer ( OpenRA runtimePlayer, Session lobbyInfo ) : void
runtimePlayer OpenRA
lobbyInfo OpenRA.Network.Session
return void
        public void AddPlayer(OpenRA.Player runtimePlayer, Session lobbyInfo)
        {
            if (runtimePlayer == null)
                throw new ArgumentNullException("runtimePlayer");

            if (lobbyInfo == null)
                throw new ArgumentNullException("lobbyInfo");

            // We don't care about spectators and map players
            if (runtimePlayer.NonCombatant || !runtimePlayer.Playable)
                return;

            // Find the lobby client that created the runtime player
            var client = lobbyInfo.ClientWithIndex(runtimePlayer.ClientIndex);
            if (client == null)
                return;

            var player = new Player
            {
                ClientIndex = runtimePlayer.ClientIndex,
                Name = runtimePlayer.PlayerName,
                IsHuman = !runtimePlayer.IsBot,
                IsBot = runtimePlayer.IsBot,
                FactionName = runtimePlayer.Faction.Name,
                FactionId = runtimePlayer.Faction.InternalName,
                Color = runtimePlayer.Color,
                Team = client.Team,
                SpawnPoint = runtimePlayer.SpawnPoint,
                IsRandomFaction = runtimePlayer.Faction.InternalName != client.Faction,
                IsRandomSpawnPoint = runtimePlayer.SpawnPoint != client.SpawnPoint
            };

            playersByRuntime.Add(runtimePlayer, player);
            Players.Add(player);
        }

Usage Example

Beispiel #1
0
        public void LoadComplete(WorldRenderer wr)
        {
            // ScreenMap must be initialized before anything else
            using (new PerfTimer("ScreenMap.WorldLoaded"))
                ScreenMap.WorldLoaded(this, wr);

            foreach (var wlh in WorldActor.TraitsImplementing <IWorldLoaded>())
            {
                // These have already been initialized
                if (wlh == ScreenMap)
                {
                    continue;
                }

                using (new PerfTimer(wlh.GetType().Name + ".WorldLoaded"))
                    wlh.WorldLoaded(this, wr);
            }

            gameInfo.StartTimeUtc = DateTime.UtcNow;
            foreach (var player in Players)
            {
                gameInfo.AddPlayer(player, OrderManager.LobbyInfo);
            }

            var echo = OrderManager.Connection as EchoConnection;
            var rc   = echo != null ? echo.Recorder : null;

            if (rc != null)
            {
                rc.Metadata = new ReplayMetadata(gameInfo);
            }
        }
All Usage Examples Of OpenRA.GameInformation::AddPlayer