Exemplo n.º 1
0
        private void SendBattleStateToNewPlayer(ConnectToBattleRequestMsg message,
                                                GameBattlePlayerInfo newPlayer)
        {
            var answer = new ConnectToBattleAnswerMsg();

            answer.IsCanConnect = true;
            answer.Player       = newPlayer;
            answer.Oponents     = new List <GameBattlePlayerInfo>();
            foreach (var unitId in Model.UnitsInBattle.Keys)
            {
                if (unitId != message.ClientId && Model.UnitsInBattle[unitId].IsAlive)
                {
                    answer.Oponents.Add(Model.UnitsInBattle[unitId]);
                }
            }
            answer.DropedItems = Model.ItemsInField;
            Server.SendToPlayer(answer, message.ClientId);
        }
        private void SendBattleState(int playerConnectionId)
        {
            var battlePlayer         = Model.GetBattlePlayer(playerConnectionId);
            var allPlayersConnection = Model.GetBattlePlayersConnections();

            var answer = new ConnectToBattleAnswerMsg
            {
                IsCanConnect = true,
                Player       = battlePlayer,
                Opponents    = new List <GameBattlePlayerInfo>(),
                DroppedItems = Model.ItemsInField
            };

            foreach (var connectionId in allPlayersConnection.Where(c => c != playerConnectionId))
            {
                GameBattlePlayerInfo gameBattlePlayerInfo = Model.GetBattlePlayer(connectionId);
                if (gameBattlePlayerInfo.IsAlive)
                {
                    answer.Opponents.Add(gameBattlePlayerInfo);
                }
            }

            Server.SendToPlayer(answer, playerConnectionId);
        }