示例#1
0
        public MatchContext MakeMatchContext(Scenario StaticScenario)
        {
            var match      = new Match(StaticScenario, IsHost ? new FullOrderAutomater() : null);
            var serializer = new OrderSerializer(match);

            if (IsHost)
            {
                var armyConnections = new Dictionary <Army, Player>();
                foreach (Player p in Lobby.Players)
                {
                    if (ConnectionCache.Connections.ContainsKey(p))
                    {
                        var a = match.Armies.FirstOrDefault(
                            i => i.Configuration.UniqueKey == Lobby.GetPlayerArmy(p).UniqueKey);
                        armyConnections.Add(a, p);
                    }
                }

                Server.RPCHandler.WaitForPromises();
                Server.MessageAdapter = new MatchMessageSerializer(serializer);
                Server.RPCHandler     =
                    new RPCHandler().Install(new MatchServerLayer(match, armyConnections, ConnectionCache));
                match.OnExecuteOrder += (sender, e) => Server.Broadcast(new ExecuteOrderRequest(e.Order, serializer));
                return(new MatchContext(
                           Server,
                           ConnectionCache,
                           match,
                           serializer,
                           match.Armies.First(
                               i => i.Configuration.UniqueKey == Lobby.GetPlayerArmy(GameData.Player).UniqueKey)));
            }

            Client.MessageAdapter = new MatchMessageSerializer(serializer);
            Client.RPCHandler     = new RPCHandler().Install(new MatchLayer(match));
            return(new MatchContext(
                       Client,
                       match,
                       serializer,
                       match.Armies.First(
                           i => i.Configuration.UniqueKey == Lobby.GetPlayerArmy(GameData.Player).UniqueKey)));
        }
示例#2
0
        public MatchLobbyPlayerSection(Player Player, MatchLobby Lobby, bool Enabled)
            : base("match-lobby-player-section")
        {
            this.Player = Player;

            var header = new Button("match-lobby-player-section-header")
            {
                DisplayedString = Player.Name
            };
            var select = new Select <ArmyConfiguration>("match-lobby-player-section-select");
            var ready  = new Checkbox("match-lobby-player-section-checkbox");

            select.Add(new SelectionOption <ArmyConfiguration>("match-lobby-player-section-select-option")
            {
                DisplayedString = "Spectator",
                Value           = null
            });
            foreach (ArmyConfiguration a in Lobby.Scenario.ArmyConfigurations)
            {
                select.Add(new SelectionOption <ArmyConfiguration>("match-lobby-player-section-select-option")
                {
                    DisplayedString = a.Faction.Name,
                    Value           = a
                });
            }
            if (Enabled)
            {
                select.OnChange += HandleArmyConfigurationSelected;
            }
            select.Position = new Vector2f(0, header.Size.Y + 6);
            select.Enabled  = Enabled && !Lobby.GetPlayerReady(Player);
            select.SetValue(i => i.Value == Lobby.GetPlayerArmy(Player));

            if (Enabled)
            {
                ready.OnChange += HandlePlayerReadyStateChanged;
            }
            ready.Position = new Vector2f(Size.X - ready.Size.X - 16, 0);
            ready.Value    = Lobby.GetPlayerReady(Player);
            ready.Enabled  = Enabled;

            Add(header);
            Add(select);
            Add(ready);
        }