private void RelayTowedVehicleChanged(Vehicle sender, ElementChangedEventArgs <Vehicle, Vehicle?> args) { if (args.Source.IsSync) { return; } if (args.NewValue == null) { if (args.OldValue != null) { this.server.BroadcastPacket(VehiclePacketFactory.CreateTrailerDetachPacket(sender, args.OldValue)); } return; } this.server.BroadcastPacket(new VehicleTrailerSyncPacket() { VehicleId = sender.Id, AttachedVehicleId = args.NewValue.Id, IsAttached = true, Position = args.NewValue.Position, Rotation = args.NewValue.Rotation, TurnVelocity = args.NewValue.TurnVelocity, }); }
private void RelayTurretRotationChanged(Element sender, ElementChangedEventArgs <Vehicle, System.Numerics.Vector2?> args) { if (args.NewValue.HasValue && !args.IsSync) { this.server.BroadcastPacket(VehiclePacketFactory.CreateSetTurretRotationPacket(args.Source)); } }
private void HandleVehicleDimensionChange(Element sender, Elements.Events.ElementChangedEventArgs <ushort> args) { if (sender is not Vehicle vehicle) { return; } var players = this.elementCollection.GetByType <Player>(ElementType.Player) .Where(x => x.Dimension == vehicle.Dimension); VehiclePacketFactory.CreateVehicleResyncPacket(vehicle).SendTo(players); }
private void HandlePlayerDimensionChange(Element sender, Elements.Events.ElementChangedEventArgs <ushort> args) { if (sender is not Player player) { return; } var vehicles = this.elementCollection.GetByType <Vehicle>(ElementType.Vehicle) .Where(x => x.Dimension == player.Dimension); foreach (var vehicle in vehicles) { VehiclePacketFactory.CreateVehicleResyncPacket(vehicle).SendTo(player); } }
public void HandlePacket(Client client, VehicleTrailerSyncPacket packet) { var otherPlayers = this.middleware.GetPlayersToSyncTo(client.Player, packet); var player = client.Player; var vehicle = this.elementRepository.Get(packet.VehicleId) as Elements.Vehicle; var attachedVehicle = this.elementRepository.Get(packet.VehicleId) as Elements.Vehicle; if (vehicle != null && attachedVehicle != null) { vehicle.RunAsSync(() => { if (packet.IsAttached) { if (vehicle.TowedVehicle != null) { VehiclePacketFactory.CreateTrailerDetachPacket(vehicle, vehicle.TowedVehicle) .SendTo(otherPlayers); } if (attachedVehicle.TowingVehicle != null) { VehiclePacketFactory.CreateTrailerDetachPacket(attachedVehicle.TowingVehicle, attachedVehicle) .SendTo(otherPlayers); } attachedVehicle.RunAsSync(() => attachedVehicle.AttachToTower(vehicle, true)); } else { attachedVehicle.RunAsSync(() => attachedVehicle.AttachToTower(null, true)); } packet.SendTo(otherPlayers); }); } }
private void RelayLockedStateChanged(Element sender, ElementChangedEventArgs <Vehicle, bool> args) { this.server.BroadcastPacket(VehiclePacketFactory.CreateSetLockedPacket(args.Source)); }
private void RelayModelChange(object sender, ElementChangedEventArgs <Vehicle, ushort> args) { this.server.BroadcastPacket(VehiclePacketFactory.CreateSetModelPacket(args.Source)); }
private void RelayHeadlightColorChanged(Vehicle sender, ElementChangedEventArgs <Vehicle, Color> args) { this.server.BroadcastPacket(VehiclePacketFactory.CreateSetHeadlightColorPacket(args.Source)); }
private void RelayColorChanged(Vehicle sender, VehicleColorChangedEventsArgs args) { this.server.BroadcastPacket(VehiclePacketFactory.CreateSetColorPacket(args.Vehicle)); }
private void RelayPlateTextChanged(Element sender, ElementChangedEventArgs <Vehicle, string> args) { this.server.BroadcastPacket(VehiclePacketFactory.CreateSetPlateTextPacket(args.Source)); }
private void RelayFuelTankExplodable(Vehicle sender, ElementChangedEventArgs <Vehicle, bool> args) { this.server.BroadcastPacket(VehiclePacketFactory.CreateSetFuelTankExplodablePacket(args.Source)); }