示例#1
0
    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,
        });
    }
示例#2
0
 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);
        }
    }
示例#5
0
    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);
            });
        }
    }
示例#6
0
 private void RelayLockedStateChanged(Element sender, ElementChangedEventArgs <Vehicle, bool> args)
 {
     this.server.BroadcastPacket(VehiclePacketFactory.CreateSetLockedPacket(args.Source));
 }
示例#7
0
 private void RelayModelChange(object sender, ElementChangedEventArgs <Vehicle, ushort> args)
 {
     this.server.BroadcastPacket(VehiclePacketFactory.CreateSetModelPacket(args.Source));
 }
示例#8
0
 private void RelayHeadlightColorChanged(Vehicle sender, ElementChangedEventArgs <Vehicle, Color> args)
 {
     this.server.BroadcastPacket(VehiclePacketFactory.CreateSetHeadlightColorPacket(args.Source));
 }
示例#9
0
 private void RelayColorChanged(Vehicle sender, VehicleColorChangedEventsArgs args)
 {
     this.server.BroadcastPacket(VehiclePacketFactory.CreateSetColorPacket(args.Vehicle));
 }
示例#10
0
 private void RelayPlateTextChanged(Element sender, ElementChangedEventArgs <Vehicle, string> args)
 {
     this.server.BroadcastPacket(VehiclePacketFactory.CreateSetPlateTextPacket(args.Source));
 }
示例#11
0
 private void RelayFuelTankExplodable(Vehicle sender, ElementChangedEventArgs <Vehicle, bool> args)
 {
     this.server.BroadcastPacket(VehiclePacketFactory.CreateSetFuelTankExplodablePacket(args.Source));
 }