using System; using System.Collections.Generic; using System.Text; using GTANetworkAPI; using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Models; using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Managers; using ReallifeGamemode.Server.Services; namespace ReallifeGamemode.Server.Util { class Rentcar : Script { //In Sekunden public static int PAY_TIMER = 30; //In Stunden private static int PAYTIME_FREE = 30; public static List noobspawnVehicleProperties = new List(); private static Vector3 noobspawnVehicleSpawnPosition = new Vector3(-1020.18695, -2695.2253, 13.988778); private static double noobspawnVehicleSpawnHeading = 151.39877; public static Vector3 noobSpawnBlipPosition = new Vector3(-1023.3046, -2694.8992, 13.906858); public static List stadthalleVehicleProperties = new List(); private static Vector3 stadthalleVehicleSpawnPosition = new Vector3(-373, -236.31334, 35.8506); private static double stadthalleVehicleSpawnHeading = 109.96821; public static Vector3 stadthalleBlipPosition = new Vector3(-369.7236, -231.82654, 35.993023); public static List knastVehicleProperties = new List(); private static Vector3 knastVehicleSpawnPosition = new Vector3(1212.741, 2726.6135, 38.00415); private static double knastVehicleSpawnHeading = 173.14825; public static Vector3 knastBlipPosition = new Vector3(1220.3483, 2725.4932, 38.00414); public static Dictionary mapPlayerRentcarBill = new Dictionary(); public static void Setup() { noobspawnVehicleProperties.Add(new RentcarProperty("bmx", 10)); noobspawnVehicleProperties.Add(new RentcarProperty("faggio3", 50)); stadthalleVehicleProperties.Add(new RentcarProperty("bmx", 10)); stadthalleVehicleProperties.Add(new RentcarProperty("faggio3", 50)); knastVehicleProperties.Add(new RentcarProperty("bmx", 10)); knastVehicleProperties.Add(new RentcarProperty("faggio3", 50)); } public static void cancelRent(Player player) { using (var dbContext = new DatabaseContext()) { User user = player.GetUser(dbContext); user.BankAccount.Balance -= mapPlayerRentcarBill[player.Name].Item2; dbContext.SaveChanges(); } player.SetData("hasRentcar", false); player.TriggerEvent("abortRentcarTimer"); player.SendChatMessage("Fahrzeugmiete erfolgreich gekündigt. Kosten: ~g~$" + mapPlayerRentcarBill[player.Name].Item2); VehicleManager.DeleteVehicle(mapPlayerRentcarBill[player.Name].Item1); Rentcar.mapPlayerRentcarBill.Remove(player.Name); } [RemoteEvent("SERVER:updateRentCarBill")] public void updateRentCarBill(Player player, int bill, int time) { if (canRentForFree(player)) { return; } using (var dbContext = new DatabaseContext()) { User user = player.GetUser(dbContext); if (bill > user.BankAccount.Balance) { ChatService.ErrorMessage(player, "Du hast nicht genügend Geld auf dem Konto. Die Fahrzeugmiete wird somit gekündigt"); cancelRent(player); dbContext.SaveChanges(); return; } dbContext.SaveChanges(); } if (!mapPlayerRentcarBill.ContainsKey(player.Name)) { return; } player.TriggerEvent("BN_Show", "Fahrzeug seit ~b~" + time + "~w~ Sekunden gemietet. Gesamtkosten: ~g~$" + bill); mapPlayerRentcarBill[player.Name] = (mapPlayerRentcarBill[player.Name].Item1, bill); } [RemoteEvent("SERVER:rentcarBooked")] public void rentcarBooked(Player player, string vehicleName, int price, String rentcarLocation) { if (player.GetData("hasRentcar") == true) { ChatService.ErrorMessage(player, "Du hast bereits ein Fahrzeug gemietet. Mit '/rent stop' kündigst du die Miete"); return; } if (!uint.TryParse(vehicleName, out uint uHash)) uHash = NAPI.Util.GetHashKey(vehicleName); if (!VehicleManager.IsValidHash(uHash)) { return; } using (var dbContext = new DatabaseContext()) { User user = player.GetUser(dbContext); if (price > user.BankAccount.Balance) { ChatService.ErrorMessage(player, "Du hast nicht genügend Geld auf dem Konto."); dbContext.SaveChanges(); return; } dbContext.SaveChanges(); } Vehicle v = null; if (rentcarLocation == "noobspawn") { v = NAPI.Vehicle.CreateVehicle(uHash, noobspawnVehicleSpawnPosition, (float)noobspawnVehicleSpawnHeading, 111, 111, engine: true); } else if (rentcarLocation == "stadthalle") { v = NAPI.Vehicle.CreateVehicle(uHash, stadthalleVehicleSpawnPosition, (float)stadthalleVehicleSpawnHeading, 111, 111, engine: true); } else if (rentcarLocation == "knast") { v = NAPI.Vehicle.CreateVehicle(uHash, knastVehicleSpawnPosition, (float)knastVehicleSpawnHeading, 111, 111, engine: true); } if (v == null) { return; } VehicleStreaming.SetEngineState(v, true); VehicleStreaming.SetLockStatus(v, false); mapPlayerRentcarBill[player.Name] = (v, 0); player.SendChatMessage("RentCar: Viel Spaß mit deinem Fahrzeug! Mit '/rent stop' kannst du die Miete kündigen"); if (canRentForFree(player)) { player.SendChatMessage("RentCar: Da du neu in der Stadt bist, wird dir für die Fahrt keine Rechnung gestellt"); } player.SetData("hasRentcar", true); player.TriggerEvent("triggerRentcarTimer", PAY_TIMER, price); } public static bool canRentForFree(Player player) { bool ret = false; using (var dbContext = new DatabaseContext()) { User user = player.GetUser(dbContext); if (user.PlayedMinutes < PAYTIME_FREE * 60) { ret = true; } dbContext.SaveChanges(); } return ret; } } }