diff --git a/ReallifeGamemode.Client/Player/reportmenu.ts b/ReallifeGamemode.Client/Player/reportmenu.ts index bee77944..35d0c38b 100644 --- a/ReallifeGamemode.Client/Player/reportmenu.ts +++ b/ReallifeGamemode.Client/Player/reportmenu.ts @@ -30,16 +30,11 @@ cancelItem.HighlightedBackColor = new Color(229, 57, 53); export default function reportList(globalData: IGlobalData) { var reportMenu: NativeUI.Menu; - var users; var reportTexts; - var user = ""; var reportText = ""; - - //Weapon Menu - mp.events.add('showReportMenu', (userTickets, TicketsArr) => { if (!globalData.InMenu) { diff --git a/ReallifeGamemode.Client/global.d.ts b/ReallifeGamemode.Client/global.d.ts index dfd560c5..d5a9c43a 100644 --- a/ReallifeGamemode.Client/global.d.ts +++ b/ReallifeGamemode.Client/global.d.ts @@ -89,4 +89,9 @@ declare type Weapon = { declare type WeaponCategory = { Category: number; Weapons: Weapon[]; +} + +declare type RentcarProperty = { + Name: string; + Price: number; } \ No newline at end of file diff --git a/ReallifeGamemode.Client/index.ts b/ReallifeGamemode.Client/index.ts index 1d47c140..2dc0210b 100644 --- a/ReallifeGamemode.Client/index.ts +++ b/ReallifeGamemode.Client/index.ts @@ -280,6 +280,9 @@ bigmap(); import notification from './Gui/notification'; notification(); +import rentCar from './util/rentcar'; +rentCar(globalData); + require('./Gui/policedepartment'); require('./Gui/helptext'); require('./admin/spectate'); diff --git a/ReallifeGamemode.Client/util/rentcar.ts b/ReallifeGamemode.Client/util/rentcar.ts new file mode 100644 index 00000000..68955ba2 --- /dev/null +++ b/ReallifeGamemode.Client/util/rentcar.ts @@ -0,0 +1,102 @@ +import * as NativeUI from '../libs/NativeUI'; + +const Menu = NativeUI.Menu; +const UIMenuItem = NativeUI.UIMenuItem; +const UIMenuListItem = NativeUI.UIMenuListItem; +const Point = NativeUI.Point; +const ItemsCollection = NativeUI.ItemsCollection; +const Color = NativeUI.Color; + + +let screenRes = mp.game.graphics.getScreenResolution(0, 0); + +let sendItem = new UIMenuItem("Mieten", "Fahrzeug Mieten"); +sendItem.BackColor = new Color(13, 71, 161); +sendItem.HighlightedBackColor = new Color(25, 118, 210); + +let cancelItem = new UIMenuItem("Abbrechen", ""); +cancelItem.BackColor = new Color(213, 0, 0); +cancelItem.HighlightedBackColor = new Color(229, 57, 53); + + +export default function rentCar(globalData: IGlobalData) { + + var rentcarMenu: NativeUI.Menu; + var vehiclesToRent: RentcarProperty[] = []; + var vehicleNames: string[] = []; + var vehiclePrices: number[] = []; + var selectedIndex: number; + + var payTimer; + var totalTime: number = 0; + var totalBill: number = 0; + + mp.events.add('showRentcarMenu', (vehiclestring, rentcarLocation) => { + if (globalData.InMenu) { + return; + } + + globalData.InMenu = true; + + vehiclesToRent = JSON.parse(vehiclestring); + + vehicleNames = []; + vehiclePrices = []; + for (let entry of vehiclesToRent) { + vehicleNames.push(entry.Name); + vehiclePrices.push(entry.Price); + } + + rentcarMenu = new Menu("Fahrzeugverleih", "", new Point(0, screenRes.y / 3), null, null); + rentcarMenu.AddItem(new UIMenuListItem("Fahrzeug", vehiclePrices[0] + "$ alle 5 Minuten", new ItemsCollection(vehicleNames))); + + rentcarMenu.AddItem(sendItem); + rentcarMenu.AddItem(cancelItem); + rentcarMenu.Visible = true; + //outeText = "Route 1"; + + selectedIndex = 0; + + rentcarMenu.ListChange.on((item: NativeUI.UIMenuListItem, index) => { + switch (item.Text) { + case "Fahrzeug": + item.Description = vehiclePrices[index] + "$ alle 5 Minuten"; + selectedIndex = index; + //item.Description = item.SelectedValue; + break; + } + }); + + rentcarMenu.ItemSelect.on((item) => { + if (item.Text === "Mieten") { + mp.events.callRemote("SERVER:rentcarBooked", vehicleNames[selectedIndex], vehiclePrices[selectedIndex], rentcarLocation); + rentcarMenu.Close(); + globalData.InMenu = false; + } else if (item.Text === "Abbrechen") { + rentcarMenu.Close(); + globalData.InMenu = false; + } + }); + + rentcarMenu.MenuClose.on(() => { + globalData.InMenu = false; + }); + }); + + mp.events.add('triggerRentcarTimer', (interval, pricePerInterval) => { + clearInterval(payTimer); + + payTimer = setInterval(() => { + totalTime += interval; + totalBill += pricePerInterval; + + if (totalTime != 0) { + mp.events.callRemote("SERVER:updateRentCarBill", totalBill, totalTime); + } + }, interval * 1000); + }); + + mp.events.add('abortRentcarTimer', () => { + clearInterval(payTimer); + }); +} \ No newline at end of file diff --git a/ReallifeGamemode.Server/Commands/UserCommands.cs b/ReallifeGamemode.Server/Commands/UserCommands.cs index cf5d581b..204c681f 100644 --- a/ReallifeGamemode.Server/Commands/UserCommands.cs +++ b/ReallifeGamemode.Server/Commands/UserCommands.cs @@ -17,6 +17,25 @@ namespace ReallifeGamemode.Server.Commands { internal class UserCommands : Script { + [Command("rent", "~m~rent stop")] + public void CmdUserStopRent(Player player, String option = "") { + if (!player.IsLoggedIn()) return; + + if (option != "stop") + { + player.SendChatMessage("Mit \"/rent stop\" kannst du die Miete kündigen"); + return; + } + + if (!player.HasData("hasRentcar")) + { + ChatService.ErrorMessage(player, "Du hast zurzeit kein Fahrzeug gemietet"); + return; + } + + Rentcar.cancelRent(player); + } + [Command("eventport", "~m~eventport")] public void CmdUserEventport(Player player, String option = "") { diff --git a/ReallifeGamemode.Server/Events/Connect.cs b/ReallifeGamemode.Server/Events/Connect.cs index 485a13b4..9d38702e 100644 --- a/ReallifeGamemode.Server/Events/Connect.cs +++ b/ReallifeGamemode.Server/Events/Connect.cs @@ -78,6 +78,9 @@ namespace ReallifeGamemode.Server.Events player.TriggerEvent("CLIENT:AddPed", 3, "s_m_m_pilot_01", -1621.4542236328125, -3152.724365234375, 13.991769790649414, 50.73009490966797, 0, false, true, 0, "none", true, true, true);//Ped_Pilot LS Airport player.TriggerEvent("CLIENT:AddPed", 4, "u_m_o_finguru_01", -534.4425659179688, -2145.747314453125, 5.992100715637207, 53.96156692504883, 0, false, true, 0, "none", true, true, true);//Ped Busfahrer player.TriggerEvent("CLIENT:AddPed", 5, "csb_prolsec", 1690.84, 2591.17 , 45.91, -2.66, 0, false, true, 0, "none", true, true, true);//Ped Knast + player.TriggerEvent("CLIENT:AddPed", 6, "ig_siemonyetarian", -1023.1589, -2693.6948, 13.98, 173.95613, 0, false, true, 0, "none", true, true, true);//Ped Rentcar NoobSpawn + player.TriggerEvent("CLIENT:AddPed", 7, "ig_siemonyetarian", -369.1589, -230.92816, 36.028805, 150.26433, 0, false, true, 0, "none", true, true, true);//Ped Rentcar KH/Stadthalle + player.TriggerEvent("CLIENT:AddPed", 8, "ig_siemonyetarian", 1222.0868, 2726.5286, 38.00415, 113.77263, 0, false, true, 0, "none", true, true, true);//Ped Rentcar Knast TimeSpan currentTime = TimeManager.CurrentTime; bool disableLightMode = currentTime > LightModeTimeFrom && currentTime < LightModeTimeTo; diff --git a/ReallifeGamemode.Server/Events/Disconnect.cs b/ReallifeGamemode.Server/Events/Disconnect.cs index 356d548b..e4708593 100644 --- a/ReallifeGamemode.Server/Events/Disconnect.cs +++ b/ReallifeGamemode.Server/Events/Disconnect.cs @@ -127,6 +127,11 @@ namespace ReallifeGamemode.Server.Events } } + if (Rentcar.mapPlayerRentcarBill.ContainsKey(player.Name)) + { + Rentcar.cancelRent(player); + } + //Vehicle LastVehicle = player.GetData("LastVehicle"); JobBase job = JobManager.GetJob(player.GetUser().JobId ?? -1); if (job != null) diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index 5079b3ee..dccf9685 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using GTANetworkAPI; @@ -188,6 +189,7 @@ namespace ReallifeGamemode.Server.Events int ticket_amount = 0; int pay_amount = 0; bool house = false; + bool hasRentcar = player.GetData("hasRentcar") == true; if (u.House != null) { @@ -203,7 +205,8 @@ namespace ReallifeGamemode.Server.Events { pay_amount = player.GetData("pay_amount"); } - player.TriggerEvent("SERVER:InteractionMenu_OpenMenu", JsonConvert.SerializeObject(accountData), factionleader, JsonConvert.SerializeObject(memberList), JsonConvert.SerializeObject(jobData), faction, group, factionInvite, groupInvite, ticket_boolean, ticket_amount, pay_amount, house); + + player.TriggerEvent("SERVER:InteractionMenu_OpenMenu", JsonConvert.SerializeObject(accountData), factionleader, JsonConvert.SerializeObject(memberList), JsonConvert.SerializeObject(jobData), faction, group, factionInvite, groupInvite, ticket_boolean, ticket_amount, pay_amount, JsonConvert.SerializeObject(hasRentcar), house); } [RemoteEvent("keyPress:E")] @@ -233,6 +236,7 @@ namespace ReallifeGamemode.Server.Events JobPoint nearestJobPoint = PositionManager.JobPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.6); Player nearestCuffPlayer = PositionManager.cuffPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.6 && user.GetData("duty")); AmmunationPoint nearestAmmunationPoint = PositionManager.AmmunationPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5); + RentcarPoint nearestRentcarPoint = PositionManager.rentcarPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5); if (user?.FactionId != null) { @@ -351,6 +355,31 @@ namespace ReallifeGamemode.Server.Events user.SetBlipAndNametagColor(); } + //Rentcar Points + if (nearestRentcarPoint != null) + { + if (player.IsInVehicle) + { + return; + } + + //Noobspawn + if (player.Position.DistanceTo(PositionManager.rentcarPoints[0].Position) <= 1.5) + { + player.TriggerEvent("showRentcarMenu", JsonConvert.SerializeObject(Rentcar.noobspawnVehicleProperties), "noobspawn"); + } + //Stadthalle + else if (player.Position.DistanceTo(PositionManager.rentcarPoints[1].Position) <= 1.5) + { + player.TriggerEvent("showRentcarMenu", JsonConvert.SerializeObject(Rentcar.stadthalleVehicleProperties), "stadthalle"); + } + //Knast + else if (player.Position.DistanceTo(PositionManager.rentcarPoints[2].Position) <= 1.5) + { + player.TriggerEvent("showRentcarMenu", JsonConvert.SerializeObject(Rentcar.knastVehicleProperties), "knast"); + } + } + if (nearestWeapon != null) // Weapon Point { List primarys = new List(); diff --git a/ReallifeGamemode.Server/Main.cs b/ReallifeGamemode.Server/Main.cs index 6ade1d26..d6314dfc 100644 --- a/ReallifeGamemode.Server/Main.cs +++ b/ReallifeGamemode.Server/Main.cs @@ -146,6 +146,7 @@ namespace ReallifeGamemode.Server Introduction.Setup(); PositionManager.LoadPositionManager(); LoadManager.LoadLoadManager(); + Rentcar.Setup(); TempBlip tempBlip = new TempBlip() { diff --git a/ReallifeGamemode.Server/Managers/PositionManager.cs b/ReallifeGamemode.Server/Managers/PositionManager.cs index c23a06b3..7fca7348 100644 --- a/ReallifeGamemode.Server/Managers/PositionManager.cs +++ b/ReallifeGamemode.Server/Managers/PositionManager.cs @@ -32,6 +32,8 @@ namespace ReallifeGamemode.Server.Managers public static List AmmunationPoints = new List(); + public static List rentcarPoints = new List(); + public static Vector3 eventportPosition; public static bool eventportActive = false; @@ -307,6 +309,35 @@ namespace ReallifeGamemode.Server.Managers } #endregion Shops + + #region RentCar + + RentcarPoint rentCarNoobSpawn = new RentcarPoint() + { + Position = Rentcar.noobSpawnBlipPosition + }; + RentcarPoint rentCarStadthalle = new RentcarPoint() + { + Position = Rentcar.stadthalleBlipPosition + }; + RentcarPoint rentCarKnast = new RentcarPoint() + { + Position = Rentcar.knastBlipPosition + }; + + rentcarPoints.Add(rentCarNoobSpawn); + rentcarPoints.Add(rentCarStadthalle); + rentcarPoints.Add(rentCarKnast); + + foreach (RentcarPoint j in rentcarPoints) + { + NAPI.Marker.CreateMarker(1, new Vector3(j.Position.X, j.Position.Y, j.Position.Z - 2), new Vector3(j.Position.X, j.Position.Y, j.Position.Z + 1), + new Vector3(0, 0, 0), 1.5f, new Color(255, 255, 255, 50), false, 0); + NAPI.TextLabel.CreateTextLabel("~y~Fahrzeugverleih\n~w~Drücke ~b~E~w~ um ein Fahrzeug zu mieten", j.Position, 7, 1, 0, new Color(255, 255, 255), false, 0); + } + + + #endregion RentCar } [RemoteEvent("sendClientToStage")] @@ -439,3 +470,9 @@ public class AmmunationPoint public Vector3 Position { get; set; } public Ammunation Ammunation { get; set; } } + +public class RentcarPoint +{ + public Vector3 Position { get; set; } +} + diff --git a/ReallifeGamemode.Server/Managers/VehicleManager.cs b/ReallifeGamemode.Server/Managers/VehicleManager.cs index 2ccc52a5..8d14c826 100644 --- a/ReallifeGamemode.Server/Managers/VehicleManager.cs +++ b/ReallifeGamemode.Server/Managers/VehicleManager.cs @@ -5,7 +5,9 @@ using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Models; using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Log; +using ReallifeGamemode.Server.Services; using ReallifeGamemode.Server.Util; +using ReallifeGamemode.Services; using System; using System.Collections.Generic; using System.Linq; @@ -955,6 +957,17 @@ namespace ReallifeGamemode.Server.Managers [ServerEvent(Event.VehicleDeath)] public static void VehicleManagerVehicleDeath(Vehicle vehicle) { + /* + String rentCarOwner = Rentcar.mapPlayerRentcarBill.FirstOrDefault(x => x.Value.Item1 == vehicle).Key; + + ChatService.Broadcast("a:" + ""); + if (rentCarOwner != null) + { + Player target = PlayerService.GetPlayerByNameOrId(rentCarOwner); + Rentcar.cancelRent(target); + } + */ + ServerVehicle serverVehicle = GetServerVehicleFromVehicle(vehicle); if (serverVehicle == null) diff --git a/ReallifeGamemode.Server/Util/Rentcar.cs b/ReallifeGamemode.Server/Util/Rentcar.cs new file mode 100644 index 00000000..271f6cb8 --- /dev/null +++ b/ReallifeGamemode.Server/Util/Rentcar.cs @@ -0,0 +1,180 @@ +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 = 10; + + //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 gemeietet"); + 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; + } + } +} diff --git a/ReallifeGamemode.Server/Util/RentcarProperty.cs b/ReallifeGamemode.Server/Util/RentcarProperty.cs new file mode 100644 index 00000000..6bd31143 --- /dev/null +++ b/ReallifeGamemode.Server/Util/RentcarProperty.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace ReallifeGamemode.Server.Util +{ + class RentcarProperty + { + public string Name { get; set; } + public int Price { get; set; } + + public RentcarProperty(String n, int p){ + Name = n; + Price = p; + } + } +}