Ejemplo n.º 1
0
 public void Receive(ServerPacket msg)
 {
     foreach (var item in msg.PlayersAngles)
     {
         _gameState.Players[item.Key].Angle = item.Value;
     }
 }
Ejemplo n.º 2
0
 public void Receive(ServerPacket msg)
 {
     // анимация выстрела
     foreach (var player in _gameState.Players.Values)
     {
         player.IsShooting = false;
     }
     lock (msg.ShootingPlayers)
     {
         foreach (var player in msg.ShootingPlayers)
         {
             _gameState.Players[player].IsShooting = true;
         }
     }
     // удаляем из пакета выстрелы игрока, которые уже были обработаны сервером
     HashSet<ushort> keysToRemove = new HashSet<ushort>();
     foreach (var shootSeq in _gameState.NetPlayer.ClientPacket.Shoots.Keys)
     {
         if (msg.Ack > shootSeq)
         {
             keysToRemove.Add(shootSeq);
         }
     }
     float deletedValue;
     foreach (var key in keysToRemove)
     {
         _gameState.NetPlayer.ClientPacket.Shoots.TryRemove(key, out deletedValue);
     }
 }
Ejemplo n.º 3
0
 public void Receive(ServerPacket msg)
 {
     // применяем новые имена
     foreach (var playerName in msg.PlayersNames)
     {
         _gameState.Players[playerName.Key].Name = playerName.Value;
     }
 }
Ejemplo n.º 4
0
 public void Receive(ServerPacket msg)
 {
     lock (_gameState.NetPlayer.ClientPacket.Moves)
     {
         DeleteProcessedMoves(msg);
         // обрабатываем пакет сервера на перемещения
         foreach (var playerPosition in msg.PlayersPositions)
         {
             if (playerPosition.Key == _gameState.Player.Id)
             {
                 _gameState.Player.Position = (Vector2)playerPosition.Value;
                 CalcPlayerLocalPosition(playerPosition.Value);
                 _collisionsActor.CheckForCollisions(_gameState.Player);
             }
             else
             {
                 if (_gameState.Players.ContainsKey(playerPosition.Key))
                     _gameState.Players[playerPosition.Key].Position = (Vector2)playerPosition.Value;
             }
         }
     }
 }
Ejemplo n.º 5
0
 private void DeleteProcessedMoves(ServerPacket msg)
 {
     List<ushort> keysToRemove = new List<ushort>();
     foreach (var moves in _gameState.NetPlayer.ClientPacket.Moves)
     {
         if (moves.Key <= msg.Ack)
         {
             keysToRemove.Add(moves.Key);
         }
     }
     foreach (var key in keysToRemove)
     {
         Moves removedMoves;
         _gameState.NetPlayer.ClientPacket.Moves.TryRemove(key, out removedMoves);
     }
 }