예제 #1
0
    private void HandleNotifyIn(Client client, Elements.Vehicle vehicle)
    {
        if (client.Player.VehicleAction == VehicleAction.Entering)
        {
            client.Player.VehicleAction = VehicleAction.None;
            if (client.Player.Vehicle != null)
            {
                vehicle.IsEngineOn = true;
                vehicle.AddPassenger(client.Player.Seat ?? 0, client.Player, false);

                var replyPacket = new VehicleInOutPacket()
                {
                    PedId       = client.Player.Id,
                    VehicleId   = vehicle.Id,
                    Seat        = client.Player.Seat ?? 0,
                    OutActionId = VehicleInOutActionReturns.NotifyInReturn,
                };
                this.server.BroadcastPacket(replyPacket);
            }
        }
    }
예제 #2
0
    private void HandleNotifyJack(Client client, Elements.Vehicle vehicle, VehicleInOutPacket packet)
    {
        if (client.Player.VehicleAction != VehicleAction.Jacking)
        {
            return;
        }

        if (vehicle.Driver == null)
        {
            return;
        }

        var jackedPed = vehicle.Driver;

        if (jackedPed is Elements.Player jackedPlayer)
        {
            jackedPlayer.Vehicle       = null;
            jackedPlayer.VehicleAction = VehicleAction.None;
            vehicle.JackingPed         = null;

            client.Player.Vehicle       = vehicle;
            client.Player.VehicleAction = VehicleAction.None;
            vehicle.AddPassenger(0, client.Player, false);

            var replyPacket = new VehicleInOutPacket()
            {
                PedId       = client.Player.Id,
                PlayerInId  = client.Player.Id,
                PlayerOutId = jackedPlayer.Id,
                VehicleId   = vehicle.Id,
                OutActionId = VehicleInOutActionReturns.NotifyJackReturn,
                Seat        = packet.Seat
            };
            this.server.BroadcastPacket(replyPacket);
        }
    }
예제 #3
0
    private void HandleRequestIn(Client client, Elements.Vehicle vehicle, VehicleInOutPacket packet)
    {
        VehicleEnterFailReason failReason = VehicleEnterFailReason.Invalid;

        if (vehicle.IsTrailer)
        {
            SendInRequestFailResponse(client, vehicle, VehicleEnterFailReason.Trailer);
            return;
        }
        if (client.Player.VehicleAction != VehicleAction.None)
        {
            SendInRequestFailResponse(client, vehicle, VehicleEnterFailReason.Action);
            return;
        }
        if (client.Player.Vehicle != null)
        {
            SendInRequestFailResponse(client, vehicle, VehicleEnterFailReason.InVehicle);
            return;
        }

        float cutoffDistance = 50f;
        bool  warpIn         = false;

        if (
            (client.Player.IsInWater || packet.IsOnWater) && VehicleConstants.WaterEntryVehicles.Contains((VehicleModel)vehicle.Model) ||
            vehicle.Model == 464
            )
        {
            cutoffDistance = 10;
            warpIn         = true;
        }

        if (vehicle.Driver != null)
        {
            cutoffDistance = 10;
        }

        if (Vector3.Distance(client.Player.Position, vehicle.Position) > cutoffDistance)
        {
            SendInRequestFailResponse(client, vehicle, VehicleEnterFailReason.Distance);
            return;
        }

        if (failReason != VehicleEnterFailReason.Invalid)
        {
            SendInRequestFailResponse(client, vehicle, failReason);
            return;
        }

        if (packet.Seat == 0)
        {
            if (vehicle.Driver == null)
            {
                if (!vehicle.CanEnter(client.Player))
                {
                    SendInRequestFailResponse(client, vehicle, VehicleEnterFailReason.Script);
                    return;
                }

                client.Player.Seat = packet.Seat;
                if (warpIn)
                {
                    vehicle.AddPassenger(packet.Seat, client.Player, true);
                }
                else
                {
                    client.Player.Vehicle       = vehicle;
                    client.Player.VehicleAction = VehicleAction.Entering;

                    var replyPacket = new VehicleInOutPacket()
                    {
                        PedId       = client.Player.Id,
                        VehicleId   = vehicle.Id,
                        Door        = packet.Door,
                        Seat        = 0,
                        OutActionId = VehicleInOutActionReturns.RequestInConfirmed,
                    };
                    this.server.BroadcastPacket(replyPacket);
                }
            }
            else
            {
                if (!vehicle.CanEnter(client.Player))
                {
                    SendInRequestFailResponse(client, vehicle, VehicleEnterFailReason.Script);
                    return;
                }

                client.Player.Seat = packet.Seat;
                if (vehicle.Driver is Elements.Player player)
                {
                    client.Player.VehicleAction  = VehicleAction.Jacking;
                    client.Player.JackingVehicle = vehicle;
                    player.VehicleAction         = VehicleAction.Jacked;
                    vehicle.JackingPed           = client.Player;

                    var replyPacket = new VehicleInOutPacket()
                    {
                        PedId       = client.Player.Id,
                        VehicleId   = vehicle.Id,
                        Door        = packet.Door,
                        OutActionId = VehicleInOutActionReturns.RequestJackConfirmed,
                    };
                    this.server.BroadcastPacket(replyPacket);
                }
            }
        }
        else
        {
            byte?seat = packet.Seat;
            if (vehicle.GetOccupantInSeat(seat.Value) != null || seat > vehicle.GetMaxPassengers())
            {
                seat = vehicle.GetFreePassengerSeat();
            }
            if (seat == null || seat > 8)
            {
                SendInRequestFailResponse(client, vehicle, VehicleEnterFailReason.Seat);
                return;
            }
            if (!vehicle.CanEnter(client.Player))
            {
                SendInRequestFailResponse(client, vehicle, VehicleEnterFailReason.Script);
                return;
            }

            client.Player.Seat          = packet.Seat;
            client.Player.Vehicle       = vehicle;
            client.Player.VehicleAction = VehicleAction.Entering;

            if (warpIn)
            {
                vehicle.AddPassenger(seat.Value, client.Player, true);
            }
            else
            {
                client.Player.Seat = seat;
                var replyPacket = new VehicleInOutPacket()
                {
                    PedId       = client.Player.Id,
                    VehicleId   = vehicle.Id,
                    Seat        = seat.Value,
                    Door        = packet.Door,
                    OutActionId = VehicleInOutActionReturns.RequestInConfirmed,
                };
                this.server.BroadcastPacket(replyPacket);
            }
        }
    }