Exemple #1
0
        // Attempts to pay for an impounded vehicle
        private void RetrieveImpoundVehicle(Session.Session playerSession, dynamic vehData)
        {
            var impoundPrice = (int)(vehData.VehiclePrice * 0.1f);

            if (Server.Get <PaymentHandler>().CanPayForItem(playerSession, impoundPrice))
            {
                Server.Get <PaymentHandler>().PayForItem(playerSession, impoundPrice, $"getting {vehData.VehicleName} #({vehData.VehID}) from impound");

                playerSession.TriggerEvent("Vehicle.SpawnGarageVehicle", vehData.Plate, vehData.VehID, vehData.Mods);
                var vehicle = new Models.Vehicle(vehData, playerSession)
                {
                    Impounded = false
                };
                currentVehicles.Add(vehicle);
                AddPlayerOwnedVehicle(playerSession, vehData.VehID);
                MySQL.execute("UPDATE vehicle_data SET OutGarage = true, Impounded = false WHERE VehID = @id", new Dictionary <string, dynamic>
                {
                    ["@id"] = vehData.VehID
                });

                Log.Verbose($"Loaded impounded vehicle ({vehData.VehID}) for {playerSession.PlayerName} (CharID: {playerSession.GetGlobalData<int>("Character.CharID")})");
            }
            else
            {
                Log.ToClient("[Bank]", $"You cannot afford to do this", ConstantColours.Bank, playerSession.Source);
                Log.Verbose($"{playerSession.PlayerName} was unable to pay for impounded vehicle ({vehData.VehID})");
            }
        }
Exemple #2
0
        public int GetMaxRefuelAmount(Session.Session playerSession, Models.Vehicle veh)
        {
            var currentBalance = paymentHandler.GetPaymentTypeBalance(playerSession);
            var amountToRefuel = Math.Ceiling(100 - veh.Mods.VehicleFuel);

            if (amountToRefuel >= 99)
            {
                amountToRefuel = 100;
            }
            var maxFuelCost = amountToRefuel * pricePerLitre;

            //Log.SendNotify("Refuelling");
            if (currentBalance >= maxFuelCost)
            {
                return((int)amountToRefuel);
            }

            while (currentBalance < maxFuelCost)
            {
                amountToRefuel--;
                maxFuelCost = amountToRefuel * pricePerLitre;
                if (currentBalance <= 0)
                {
                    break;
                }

                //await BaseScript.Delay(0);
            }

            return((int)amountToRefuel);
        }
Exemple #3
0
 public void RemoveVehicle(Models.Vehicle veh)
 {
     try
     {
         currentVehicles.Remove(veh);
     }
     catch (Exception e)
     {
         // none
     }
 }
Exemple #4
0
        private async Task <bool> DoRefuel(Session.Session playerSession, Models.Vehicle vehObj, Entity vehEntity, float refuelAmount)
        {
            var source = playerSession.Source;
            var startingPlayerPosition = playerSession.GetPlayerPosition();
            var startingVehPosition    = vehEntity.Position;

            var   previousFuelAmount = vehObj.Mods.VehicleFuel;
            var   refueled           = 0f;
            int   refuelTick         = 1;
            float refuelTickAmount   = 0.5f;

            Log.ToClient("[Fuel]", $"Refuelling...", ConstantColours.Fuel, source);

            Log.Info($"{playerSession.PlayerName} is refueling vehicle #{vehObj.VehID}");
            while (refueled < refuelAmount)
            {
                if (startingVehPosition != vehEntity.Position)
                {
                    Log.ToClient("[Fuel]", $"Your vehicle moved while refuelling.", ConstantColours.Fuel, source);
                    vehObj.Mods.VehicleFuel = previousFuelAmount;
                    return(false);
                }

                if (startingPlayerPosition.DistanceToSquared(playerSession.GetPlayerPosition()) > 3f)
                {
                    Log.ToClient("[Fuel]", "You moved while refuelling", ConstantColours.Fuel, source);
                    vehObj.Mods.VehicleFuel = previousFuelAmount;
                    return(false);
                }

                if (vehObj.Mods.VehicleFuel >= 100)
                {
                    return(true);
                }

                refueled += refuelTickAmount;
                vehObj.Mods.VehicleFuel += refuelTickAmount;
                await BaseScript.Delay(refuelTick);

                vehObj.Mods.VehicleFuel = Math.Min(100f, vehObj.Mods.VehicleFuel);
            }

            return(true);
        }
Exemple #5
0
        public void SaveVehicle(Models.Vehicle vehicle, bool removeVehicle = false)
        {
            MySQL.execute("UPDATE vehicle_data SET CharID = @charid, VehicleName = @veh, Plate = @plate, Mods = @mods, Inventory = @inv, VehiclePrice = @price, Garage = @garage, Impounded = @impound, OutGarage = @outstate WHERE VehID = @id", new Dictionary <string, dynamic>
            {
                ["@charid"]   = vehicle.CharID,
                ["@veh"]      = vehicle.VehicleName,
                ["@plate"]    = vehicle.Plate,
                ["@mods"]     = JsonConvert.SerializeObject(vehicle.Mods),
                ["@inv"]      = vehicle.Inventory.ToString(),
                ["@price"]    = vehicle.VehiclePrice,
                ["@garage"]   = vehicle.Garage,
                ["@impound"]  = vehicle.Impounded,
                ["@outstate"] = !removeVehicle,
                ["@id"]       = vehicle.VehID
            });

            if (removeVehicle)
            {
                currentVehicles.Remove(vehicle);
            }
        }
Exemple #6
0
        public void OnCreateExternalVehicle([FromSource] Player source, string vehData, bool isRentedVeh = false)
        {
            try
            {
                Log.Verbose($"{source.Name} is attempting to create an external vehicle. Is rented = {isRentedVeh}");
                Session.Session playerSession = Sessions.GetPlayer(source);
                if (playerSession == null)
                {
                    return;
                }

                var externalVeh = new Models.Vehicle
                {
                    VehicleOwner        = playerSession,
                    VehID               = externalVehs,
                    Mods                = JsonConvert.DeserializeObject <VehicleDataModel>(vehData),
                    KeyAccessCharacters = new List <int>
                    {
                        playerSession.GetGlobalData <int>("Character.CharID")
                    },
                    RentedVehicle = isRentedVeh
                };

                externalVeh.Plate     = externalVeh.Mods.LicensePlate;
                externalVeh.Inventory = new VehicleInventory("", externalVeh);
                currentVehicles.Add(externalVeh);

                GivePlayerVehicleAccess(playerSession, externalVehs);
                playerSession.TriggerEvent("Vehicle.ReceiveExternalVehID", externalVehs);

                Log.Verbose($"Created an extneral vehicle with a Vehicle.ID of {externalVehs} and a plate of {externalVeh.Plate}");
                externalVehs += 1;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Exemple #7
0
 public void AddVehicle(Models.Vehicle veh)
 {
     currentVehicles.Add(veh);
 }