private void OnDataMessage(NetIncomingMessage msg) { var type = (PacketType)msg.ReadByte(); if (type == PacketType.Connected) { InitializeFromServer(Packets.Connected.Read(msg)); } if (!Loaded) { return; } switch (type) { case PacketType.PlayerPreferences: PacketReceived(PlayerPreferences.Read(msg)); break; case PacketType.PlayerConnected: PacketReceived(PlayerConnected.Read(msg)); break; case PacketType.PlayerDisconnected: PacketReceived(PlayerDisconnected.Read(msg)); break; case PacketType.WorldState: AddWorldState(WorldState.Read(msg).worldState); break; case PacketType.PlayerDeath: PacketReceived(Packets.PlayerDeath.Read(msg)); break; case PacketType.PlayerShoot: PacketReceived(PlayerShoot.Read(msg)); break; case PacketType.ChangeLevel: PacketReceived(ChangeLevel.Read(msg)); break; case PacketType.GameOver: PacketReceived(Packets.GameOver.Read(msg)); break; } }
private void PacketReceived(PlayerShoot packet) { if (Players == null || LocalPlayer == null || packet.playerId == PlayerId) { return; } var ply = Players[packet.playerId]; if (!ply.PlayerObject.playerMechanics.CurrentWeapon) { return; } foreach (var b in packet.bullets) { var hit = new BulletInfo(); if (b.hit) { hit = new BulletInfo { hit = true, hitPlayer = b.hitPlayer, hitNormal = b.hitNormal } } ; ply.PlayerObject.playerMechanics.CurrentWeapon.ShootEffect(ply.PlayerObject, packet.from, b.to, hit); Debug.Assert(PlayerId != null, nameof(PlayerId) + " != null"); if (b.hitPlayer && b.victimId == PlayerId.Value) { OnSelfHurt(packet.playerId, b.damage); } } }