diff --git a/ReallifeGamemode.Client/Jobs/main.ts b/ReallifeGamemode.Client/Jobs/main.ts new file mode 100644 index 00000000..19053f72 --- /dev/null +++ b/ReallifeGamemode.Client/Jobs/main.ts @@ -0,0 +1,25 @@ +import * as NativeUI from 'NativeUI'; + +export default function (globalData: GlobalData) { + + mp.events.add("SERVER:Job_ShowJobMenu", (jobName: string) => { + if (globalData.InMenu) return; + + var menu = new NativeUI.Menu("Job", jobName, new NativeUI.Point(50, 50), null, null); + menu.AddItem(new NativeUI.UIMenuItem("Job starten")); + + globalData.InMenu = true; + + menu.ItemSelect.on((item: NativeUI.UIMenuItem, index: number) => { + if (index === 0) { // Job starten + mp.events.callRemote("CLIENT:Job_StartJob"); + } + menu.Close(); + }); + + menu.MenuClose.on(() => { + globalData.InMenu = false; + }) + }); + +} \ No newline at end of file diff --git a/ReallifeGamemode.Client/Player/keys.ts b/ReallifeGamemode.Client/Player/keys.ts index d31996b0..5c0e4779 100644 --- a/ReallifeGamemode.Client/Player/keys.ts +++ b/ReallifeGamemode.Client/Player/keys.ts @@ -132,10 +132,17 @@ export default function keys(globalData: GlobalData) { } }); - //X //Anschnallen + //X // Fahrzeug Verwaltung - Menü mp.keys.bind(0x58, false, function () { if (!globalData.InChat) { mp.events.callRemote("keyPress:X"); } }); + + //2 // Job Starten + mp.keys.bind(0x32, false, () => { + if (!globalData.InChat && !globalData.InInput && !globalData.InMenu && globalData.LoggedIn) { + mp.events.callRemote("CLIENT:JobManager_ShowJobMenu"); + } + }) } \ No newline at end of file diff --git a/ReallifeGamemode.Client/index.ts b/ReallifeGamemode.Client/index.ts index f8f3aef3..8e61d465 100644 --- a/ReallifeGamemode.Client/index.ts +++ b/ReallifeGamemode.Client/index.ts @@ -7,12 +7,25 @@ let globalData: GlobalData = { InTuning: false, HideGui: false, - InMenu: false, InChat: false, LoggedIn: false, - InInput: false + InInput: false, + + get InMenu(): boolean { + return inMenu; + }, + set InMenu(value: boolean) { + inMenu = value; + + mp.gui.chat.show(!value); + } }; +var inMenu = false; + +import jobMain from './Jobs/main'; +jobMain(globalData); + import cityHall from './Gui/cityhall'; cityHall(globalData); diff --git a/ReallifeGamemode.Server/Commands/AdminCommands.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs index 286060c0..10d6cbff 100644 --- a/ReallifeGamemode.Server/Commands/AdminCommands.cs +++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs @@ -300,6 +300,7 @@ namespace ReallifeGamemode.Server.Commands } } #endregion + #region ALevel1 [Command("a", "~m~Benutzung: ~s~/a [Nachricht]", GreedyArg = true)] public void CmdAdminA(Client player, string message) @@ -1050,8 +1051,6 @@ namespace ReallifeGamemode.Server.Commands return; } - WeaponHash weaponHash = (WeaponHash)uHash; - target.GiveWeapon((WeaponHash)uHash, ammo); target.SendChatMessage("~b~Du hast von " + player.Name + " eine/n " + hash + " mit einer Munition von " + ammo + " erhalten."); player.SendChatMessage("~b~Du hast " + target.Name + " eine/n " + hash + " mit einer Munition von " + ammo + " gegeben."); @@ -2394,10 +2393,9 @@ namespace ReallifeGamemode.Server.Commands DoorManager.ReloadDoors(); player.SendChatMessage("~b~[ADMIN]~s~ Die Türen wurden erfolgreich neugeladen."); } - #endregion - #region ALevel1338 + #region ALevel1338 [Command("whitelist", "~m~Benutzung: ~s~/whitelist [Add / Remove] [Socialclub Name]")] public void CmdAdminWhitelist(Client player, string option, string scName) { @@ -2478,8 +2476,6 @@ namespace ReallifeGamemode.Server.Commands player.SendChatMessage("Du hast " + target.Name + " auf Adminlevel " + target.GetUser().AdminLevel.GetName() + ":(" + rank + ") gesetzt."); } - #endregion - } } diff --git a/ReallifeGamemode.Server/Extensions/ListExtensions.cs b/ReallifeGamemode.Server/Extensions/ListExtensions.cs new file mode 100644 index 00000000..e8599db4 --- /dev/null +++ b/ReallifeGamemode.Server/Extensions/ListExtensions.cs @@ -0,0 +1,16 @@ +using GTANetworkAPI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ReallifeGamemode.Server.Extensions +{ + static class ListExtensions + { + public static bool Contains(this List list, Client client) + { + return list.Any(l => l.Handle.Value == client.Handle.Value); + } + } +} diff --git a/ReallifeGamemode.Server/Job/JobBase.cs b/ReallifeGamemode.Server/Job/JobBase.cs index 7aa07d89..e4c6bf59 100644 --- a/ReallifeGamemode.Server/Job/JobBase.cs +++ b/ReallifeGamemode.Server/Job/JobBase.cs @@ -1,6 +1,8 @@ using GTANetworkAPI; using ReallifeGamemode.Server.Entities; +using ReallifeGamemode.Server.Managers; using ReallifeGamemode.Server.Models; +using ReallifeGamemode.Server.Services; using System; using System.Collections.Generic; using System.Linq; @@ -22,21 +24,31 @@ namespace ReallifeGamemode.Server.Job public abstract string Name { get; } + public abstract bool NeedVehicleToStart { get; } + public void StartJob(Client player) { _inJob.Add(player); - JobStart(); + + if (NeedVehicleToStart && !GetJobVehicles().Any(v => VehicleManager.GetVehicleFromServerVehicle(v).Handle.Value == player.Vehicle?.Handle.Value)) + { + ChatService.Error(player, "Zum Start dieses Jobs musst du in einem Jobfahrzeug sein"); + return; + } + + JobStart?.Invoke(); } public void StopJob(Client player) { _inJob.Remove(player); - JobStop(); + + JobStop?.Invoke(); } public List GetJobVehicles() { - using(var dbContext = new DatabaseContext()) + using (var dbContext = new DatabaseContext()) { return dbContext.JobVehicles.Where(j => j.JobId == Id).ToList(); } diff --git a/ReallifeGamemode.Server/Job/PilotJob.cs b/ReallifeGamemode.Server/Job/PilotJob.cs index edece552..5e8fee70 100644 --- a/ReallifeGamemode.Server/Job/PilotJob.cs +++ b/ReallifeGamemode.Server/Job/PilotJob.cs @@ -9,5 +9,7 @@ namespace ReallifeGamemode.Server.Job public override int Id => 3; public override string Name => "Pilot"; + + public override bool NeedVehicleToStart => true; } } diff --git a/ReallifeGamemode.Server/Job/RefuseCollectorJob.cs b/ReallifeGamemode.Server/Job/RefuseCollectorJob.cs index a00cfe91..21b90bce 100644 --- a/ReallifeGamemode.Server/Job/RefuseCollectorJob.cs +++ b/ReallifeGamemode.Server/Job/RefuseCollectorJob.cs @@ -9,5 +9,7 @@ namespace ReallifeGamemode.Server.Job public override int Id => 2; public override string Name => "Müllmann"; + + public override bool NeedVehicleToStart => true; } } diff --git a/ReallifeGamemode.Server/Job/TaxiDriverJob.cs b/ReallifeGamemode.Server/Job/TaxiDriverJob.cs index ea548d35..0489844b 100644 --- a/ReallifeGamemode.Server/Job/TaxiDriverJob.cs +++ b/ReallifeGamemode.Server/Job/TaxiDriverJob.cs @@ -10,5 +10,7 @@ namespace ReallifeGamemode.Server.Job public override int Id => 1; public override string Name => "Taxifahrer"; + + public override bool NeedVehicleToStart => true; } } diff --git a/ReallifeGamemode.Server/Managers/JobManager.cs b/ReallifeGamemode.Server/Managers/JobManager.cs index bfde7267..f3ab6c67 100644 --- a/ReallifeGamemode.Server/Managers/JobManager.cs +++ b/ReallifeGamemode.Server/Managers/JobManager.cs @@ -96,5 +96,35 @@ namespace ReallifeGamemode.Server.Managers dbContext.SaveChanges(); } } + + [RemoteEvent("CLIENT:JobManager_ShowJobMenu")] + public void ShowJobMenuEvent(Client player) + { + User u = player.GetUser(); + + if (u.JobId == null) return; + + JobBase job = GetJob(u.JobId.Value); + + player.TriggerEvent("SERVER:Job_ShowJobMenu", job.Name); + } + + [RemoteEvent("CLIENT:Job_StartJob")] + public void StartJobEvent(Client player) + { + User u = player.GetUser(); + + if (u.JobId == null) return; + + JobBase job = GetJob(u.JobId.Value); + + if(job.GetUsersInJob().Contains(player)) + { + ChatService.Error(player, "Du bist schon in deinem Job aktiv"); + return; + } + + job.StartJob(player); + } } }