From bba265f9d9f6924b5d18d226c930b4d5e4569a18 Mon Sep 17 00:00:00 2001 From: Mac_Slash Date: Tue, 28 Apr 2020 18:53:22 +0200 Subject: [PATCH] =?UTF-8?q?Nachtr=C3=A4gliche=20Migrations=C3=A4nderung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReallifeGamemode.Client/util/checkpoint.ts | 8 +- .../DatabaseContextModelSnapshot.cs | 4 +- .../DrivingSchool/DrivingSchool.cs | 8 +- .../DrivingSchool/PlaneSchool.cs | 4 +- .../Events/EnterVehicle.cs | 2 +- ReallifeGamemode.Server/Events/ExitVehicle.cs | 6 + ReallifeGamemode.Server/Events/Key.cs | 81 +++--- ReallifeGamemode.Server/Job/BusDriverJob.cs | 46 ++-- ReallifeGamemode.Server/Job/PilotJob.cs | 89 ++++++- .../Managers/JobManager.cs | 238 +++++++++++++++--- .../Util/CheckPointHandle.cs | 51 ++-- 11 files changed, 413 insertions(+), 124 deletions(-) diff --git a/ReallifeGamemode.Client/util/checkpoint.ts b/ReallifeGamemode.Client/util/checkpoint.ts index ae5c3bf2..334d0ffa 100644 --- a/ReallifeGamemode.Client/util/checkpoint.ts +++ b/ReallifeGamemode.Client/util/checkpoint.ts @@ -12,17 +12,19 @@ export default function checkpointHandle(globalData: IGlobalData) { var delayCounter; var markerID; var markerSize; + var markerDist; var event; var checkPointsDone = 0; var activeBlip = null; - mp.events.add('setCheckPoint', (position, player, checkPointID, nDelay, nMarkerID, nMarkerSize, nEvent) => { + mp.events.add('setCheckPoint', (position, player, checkPointID, nDelay, nMarkerID, nMarkerSize, nMarkerDist, nEvent) => { inCheckpoint = false; posCp = position; Player = player; delay = nDelay; markerID = nMarkerID; markerSize = nMarkerSize; + markerDist = nMarkerDist; delayCounter = 0; checkPointsDone = checkPointID; event = nEvent; @@ -43,7 +45,7 @@ export default function checkpointHandle(globalData: IGlobalData) { clearInterval(myVar); //mp.events.call("SERVER:Util_setWaypoint", posCp.X, posCp.Z); //mp.game.ui.setNewWaypoint(posCp.x, posCp.y); - myVar = setInterval(myTimer, 100); + myVar = setInterval(myTimer, 50); }); mp.events.add('destroyCP', () => { @@ -65,7 +67,7 @@ export default function checkpointHandle(globalData: IGlobalData) { function myTimer() { let dist = mp.game.gameplay.getDistanceBetweenCoords(Player.position.x, Player.position.y, 0, posCp.x, posCp.y, 0, false); //mp.gui.chat.push("delay: " + delay + " | delayCounter: " + delayCounter); - if (dist <= 3) { + if (dist <= markerDist) { if (!inCheckpoint) { if (delay != 0) { diff --git a/ReallifeGamemode.Database/Migrations/DatabaseContextModelSnapshot.cs b/ReallifeGamemode.Database/Migrations/DatabaseContextModelSnapshot.cs index a6cfde7f..2f8003eb 100644 --- a/ReallifeGamemode.Database/Migrations/DatabaseContextModelSnapshot.cs +++ b/ReallifeGamemode.Database/Migrations/DatabaseContextModelSnapshot.cs @@ -1308,10 +1308,10 @@ namespace ReallifeGamemode.Database.Migrations b.Property("BankAccountId") .HasColumnType("int"); - b.Property("BusSkill") + b.Property("BusSkill") .HasColumnType("int"); - b.Property("BusinessId") + b.Property("BusinessId") .HasColumnType("int"); b.Property("CharacterId") diff --git a/ReallifeGamemode.Server/DrivingSchool/DrivingSchool.cs b/ReallifeGamemode.Server/DrivingSchool/DrivingSchool.cs index f3946034..982d3b89 100644 --- a/ReallifeGamemode.Server/DrivingSchool/DrivingSchool.cs +++ b/ReallifeGamemode.Server/DrivingSchool/DrivingSchool.cs @@ -146,13 +146,13 @@ namespace ReallifeGamemode.Server.DrivingSchool { user.TriggerEvent("renderTextOnScreen", "Gut nun kann die Prüfung losgehen."); user.TriggerEvent("stopTimer"); - CheckPointHandle.StartCheckPointRoute(user, DrivingRoute, 0, 1, 7, "drivingSchoolEvent"); + CheckPointHandle.StartCheckPointRoute(user, DrivingRoute, 0, 1, 7, 3, "drivingSchoolEvent"); } if (schoolVehicle.SchoolId == 2 && user.IsInVehicle) { user.TriggerEvent("renderTextOnScreen", "Gut nun kann die Prüfung losgehen."); user.TriggerEvent("stopTimer"); - CheckPointHandle.StartCheckPointRoute(user, BikeRoute, 0, 1, 7, "bikeSchoolEvent"); + CheckPointHandle.StartCheckPointRoute(user, BikeRoute, 0, 1, 7, 3, "bikeSchoolEvent"); } } } @@ -201,7 +201,7 @@ namespace ReallifeGamemode.Server.DrivingSchool else if (checkpoint == 32) { user.TriggerEvent("renderTextOnScreen", "Parke nun das Auto an der markierten Stelle."); - CheckPointHandle.StartCheckPointRoute(user, StopCar, 5000, 1, 7, "drivingSchoolEventEnd"); + CheckPointHandle.StartCheckPointRoute(user, StopCar, 5000, 1, 7, 3, "drivingSchoolEventEnd"); } } @@ -269,7 +269,7 @@ namespace ReallifeGamemode.Server.DrivingSchool else if (checkpoint == 12) { user.TriggerEvent("renderTextOnScreen", "Parke nun das Auto an der markierten Stelle."); - CheckPointHandle.StartCheckPointRoute(user, StopBike, 5000, 1, 7, "bikeSchoolEventEnd"); + CheckPointHandle.StartCheckPointRoute(user, StopBike, 5000, 1, 7, 3, "bikeSchoolEventEnd"); } } diff --git a/ReallifeGamemode.Server/DrivingSchool/PlaneSchool.cs b/ReallifeGamemode.Server/DrivingSchool/PlaneSchool.cs index b428052e..c2479826 100644 --- a/ReallifeGamemode.Server/DrivingSchool/PlaneSchool.cs +++ b/ReallifeGamemode.Server/DrivingSchool/PlaneSchool.cs @@ -105,7 +105,7 @@ namespace ReallifeGamemode.Server.DrivingSchool { user.TriggerEvent("renderTextOnScreen", "Fahren Sie langsam und sicher zur Roten Markierung."); user.TriggerEvent("stopTimer"); - CheckPointHandle.StartCheckPointRoute(user, planeRoute, 0, 6, 12, "planeSchoolEvent"); + CheckPointHandle.StartCheckPointRoute(user, planeRoute, 0, 6, 12, 5, "planeSchoolEvent"); } } } @@ -175,7 +175,7 @@ namespace ReallifeGamemode.Server.DrivingSchool case 14: user.TriggerEvent("renderTextOnScreen", "Setze zum landeflug an. Drücke 'G' um ihr Fahrwerk auszufahren."); - CheckPointHandle.StartCheckPointRoute(user, planeRouteEnd, 5000, 6, 12, "planeSchoolEventEnd"); + CheckPointHandle.StartCheckPointRoute(user, planeRouteEnd, 5000, 6, 12, 5, "planeSchoolEventEnd"); break; diff --git a/ReallifeGamemode.Server/Events/EnterVehicle.cs b/ReallifeGamemode.Server/Events/EnterVehicle.cs index d4bbceea..e6fb5c76 100644 --- a/ReallifeGamemode.Server/Events/EnterVehicle.cs +++ b/ReallifeGamemode.Server/Events/EnterVehicle.cs @@ -29,7 +29,7 @@ namespace ReallifeGamemode.Server.Events return; List dealPoint = new List(); dealPoint.Add(vector); - CheckPointHandle.StartCheckPointRoute(client, dealPoint, 5000, 1, 7, "loadWeaponTransport"); + CheckPointHandle.StartCheckPointRoute(client, dealPoint, 5000, 1, 7, 4, "loadWeaponTransport"); } } } diff --git a/ReallifeGamemode.Server/Events/ExitVehicle.cs b/ReallifeGamemode.Server/Events/ExitVehicle.cs index 19313cb9..f6896ebd 100644 --- a/ReallifeGamemode.Server/Events/ExitVehicle.cs +++ b/ReallifeGamemode.Server/Events/ExitVehicle.cs @@ -14,10 +14,12 @@ namespace ReallifeGamemode.Server.Events { public class ExitVehicle : Script { + object LastVehicle; public static Timer timerNoobRollerRespawn = new Timer(10000); //10 Minuten Timer NoobRollerRespawn [ServerEvent(Event.PlayerExitVehicleAttempt)] public void OnPlayerExitVehicle(Player client, GTANetworkAPI.Vehicle vehicle) { + LastVehicle = vehicle; if (client.VehicleSeat != 0) return; if (vehicle.GetServerVehicle() is FactionVehicle veh) @@ -48,10 +50,14 @@ namespace ReallifeGamemode.Server.Events vehicle.SetData("NoobSpawnVehicleTimer", true); timerNoobRollerRespawn.AutoReset = false; timerNoobRollerRespawn.Elapsed += Timer600000_Elapsed; + //LastVehicle = vehicle; + //timerNoobRollerRespawn.Elapsed += async (sender, e) => {await } } private static void Timer600000_Elapsed(object sender, ElapsedEventArgs e) { + //ExitVehicle c = new ExitVehicle(); + //Vehicle veh = c.LastVehicle; NAPI.Task.Run(() => { NAPI.Pools.GetAllVehicles().ForEach(v => diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index ee3aab4f..f71591b4 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -483,7 +483,10 @@ namespace ReallifeGamemode.Server.Events } else if (sV is FactionVehicle fV) { - if (!fV.GetOwners().Contains(u.FactionId ?? 0) && !state && !(u.IsAdmin(AdminLevel.HEADADMIN) && player.IsAdminDuty())) + if (u.IsAdmin(AdminLevel.HEADADMIN) && player.IsAdminDuty()) + { + } + else if (!fV.GetOwners().Contains(u.FactionId ?? 0) && !state && !(u.IsAdmin(AdminLevel.HEADADMIN))) { player.SendNotification("~r~Du hast keinen Schlüssel."); return; @@ -491,7 +494,10 @@ namespace ReallifeGamemode.Server.Events } else if (sV is GroupVehicle gV) { - if (gV.GroupId != u.Group.Id && !state && !u.IsAdmin(AdminLevel.ADMIN3)) + if (u.IsAdmin(AdminLevel.ADMIN3) && player.IsAdminDuty()) + { + } + else if (gV.GroupId != u.Group.Id && !state && !u.IsAdmin(AdminLevel.ADMIN3)) { player.SendNotification("~r~Du hast keinen Schlüssel."); return; @@ -499,56 +505,73 @@ namespace ReallifeGamemode.Server.Events } else if (sV is JobVehicle jV) { - if (!jV.GetJob().GetUsersInJob().Contains(player) && !u.IsAdmin(AdminLevel.ADMIN3) && player.IsAdminDuty()) - { - player.SendNotification("~r~Du hast keinen Schlüssel."); - return; - } - if(player.IsAdminDuty()) + //if (jV.GetJob().GetUsersInJob().Contains(player)) + if (u.IsAdmin(AdminLevel.ADMIN3) && player.IsAdminDuty()) { } - else + else if (jV.GetJob().Id == u.JobId) { - if (u.JobId == 4) - { - if (v.Model == (uint)Types.VehicleModel.Coach) + { + if (u.JobId == 3) { - if (u.BusSkill < 300) + if (v.Model == (uint)Types.VehicleModel.Cuban800) { - player.SendNotification("~r~Dein Skilllevel(2) ist nicht hoch genug!"); - return; } - else + if (v.Model == (uint)Types.VehicleModel.Velum || v.Model == (uint)Types.VehicleModel.Velum2) { - + if (u.PilotSkill < 300) + { + player.SendNotification("~r~Dein Skilllevel(2) ist nicht hoch genug!"); + return; + } + else + { + } } } - if (v.Model == (uint)Types.VehicleModel.Tourbus) + if (u.JobId == 4) { - if (u.BusSkill < 800) + if (v.Model == (uint)Types.VehicleModel.Coach) { - player.SendNotification("~r~Dein Skilllevel(3) ist nicht hoch genug!"); - return; + if (u.BusSkill < 300) + { + player.SendNotification("~r~Dein Skilllevel(2) ist nicht hoch genug!"); + return; + } + else + { + } } - else + if (v.Model == (uint)Types.VehicleModel.Tourbus) { - + if (u.BusSkill < 800) + { + player.SendNotification("~r~Dein Skilllevel(3) ist nicht hoch genug!"); + return; + } + else + { + } } } } } - } - else if (sV is UserVehicle uV) - { - if (uV.UserId != u.Id) + else { player.SendNotification("~r~Du hast keinen Schlüssel."); return; } } - else if (sV is JobVehicle) + else if (sV is UserVehicle uV) { - return; + if (u.IsAdmin(AdminLevel.HEADADMIN) && player.IsAdminDuty()) + { + } + else if (uV.UserId != u.Id && !u.IsAdmin(AdminLevel.HEADADMIN)) + { + player.SendNotification("~r~Du hast keinen Schlüssel."); + return; + } } } VehicleStreaming.SetEngineState(v, !state); diff --git a/ReallifeGamemode.Server/Job/BusDriverJob.cs b/ReallifeGamemode.Server/Job/BusDriverJob.cs index ff08f230..a208c692 100644 --- a/ReallifeGamemode.Server/Job/BusDriverJob.cs +++ b/ReallifeGamemode.Server/Job/BusDriverJob.cs @@ -9,7 +9,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; namespace ReallifeGamemode.Server.Job { - class BusDriverJob : JobBase + public class BusDriverJob : JobBase { public override int Id => 4; @@ -108,14 +108,14 @@ namespace ReallifeGamemode.Server.Job Vehicle veh = player.Vehicle; - if (veh.DisplayName == "Bus") + if ((VehicleHash)veh.Model == VehicleHash.Bus) { listRouteTexts2.Add("Kurz 1"); listRouteTexts2.Add("Kurz 2"); ; player.TriggerEvent("showBusRouteMenu", JsonConvert.SerializeObject(listRouteTexts2)); } - else if (veh.DisplayName == "Tourbus") + else if ((VehicleHash)veh.Model == VehicleHash.Tourbus) { listRouteTexts3.Add("Mittel 1"); player.TriggerEvent("showBusRouteMenu", JsonConvert.SerializeObject(listRouteTexts3)); @@ -134,23 +134,23 @@ namespace ReallifeGamemode.Server.Job { if (type == "Kurz 1") { - CheckPointHandle.StartCheckPointRoute(player, Route1, 3000, 1, 7, "busDriverJob"); + CheckPointHandle.StartCheckPointRoute(player, Route1, 3000, 1, 7, 5, "busDriverJob"); } else if (type == "Kurz 2") { - CheckPointHandle.StartCheckPointRoute(player, Route2, 3000, 1, 7, "busDriverJob"); + CheckPointHandle.StartCheckPointRoute(player, Route2, 3000, 1, 7, 5, "busDriverJob"); } else if (type == "Mittel 1") { - CheckPointHandle.StartCheckPointRoute(player, Route3, 3000, 1, 7, "busDriverJob"); + CheckPointHandle.StartCheckPointRoute(player, Route3, 3000, 1, 7, 5, "busDriverJob"); } else if (type == "Lang 1") { - CheckPointHandle.StartCheckPointRoute(player, RouteLong, 3000, 1, 7, "busDriverJob"); + CheckPointHandle.StartCheckPointRoute(player, RouteLong, 3000, 1, 7, 5, "busDriverJob"); } else if (type == "Lang 2") { - CheckPointHandle.StartCheckPointRoute(player, RouteVeryLong, 3000, 1, 7, "busDriverJob"); + CheckPointHandle.StartCheckPointRoute(player, RouteVeryLong, 3000, 1, 7, 5, "busDriverJob"); } } @@ -160,6 +160,9 @@ namespace ReallifeGamemode.Server.Job using (var dbContext = new DatabaseContext()) { jobber.GetUser(dbContext).BankAccount.Balance += wage; + jobber.SendChatMessage($"~y~[JOB] ~w~Du hast ~g~${wage} ~w~bekommen."); + jobber.GetUser(dbContext).BusSkill++; + dbContext.SaveChanges(); if (jobber.GetUser(dbContext).BusSkill == 300) { jobber.SendChatMessage($"~y~[JOB] ~w~Du hast nun ~g~Skill-Level 2 ~w~erreicht!"); @@ -170,13 +173,15 @@ namespace ReallifeGamemode.Server.Job jobber.SendChatMessage($"~y~[JOB] ~w~Du hast nun ~g~Skill-Level 3 ~w~erreicht!"); jobber.SendChatMessage($"~y~[JOB] ~w~Du kannst jetzt mit dem Coach, und dem Tourbus fahren!"); } - jobber.GetUser(dbContext).BusSkill++; - jobber.SendChatMessage($"~y~[JOB] ~w~Du hast ~g~${wage} ~w~bekommen."); - dbContext.SaveChanges(); + //BusLetzterCheckpoint(jobber); + //BusDriverJob rt = null; + //rt.BusLetzterCheckpoint() } } - public void BusLetzterCheckpoint(Player player) + [RemoteEvent("BusLetzterCheckpoint")] + public static void BusLetzterCheckpoint(Player player) { + BusDriverJob c = new BusDriverJob(); Vehicle v = player.Vehicle; if (v.Model == (uint)Types.VehicleModel.Bus) { @@ -186,13 +191,15 @@ namespace ReallifeGamemode.Server.Job { case 1: { - StartBusRoute(player, "Kurz 1"); + c.StartBusRoute(player, "Kurz 1"); + player.SendChatMessage("~y~[JOB] ~w~Eine neue Route wurde gesetzt.: ~g~Kurz 1"); break; } case 2: { - StartBusRoute(player, "Kurz 2"); - break; + c.StartBusRoute(player, "Kurz 2"); + player.SendChatMessage("~y~[JOB] ~w~Eine neue Route wurde gesetzt.: ~g~Kurz 2"); + break; } } } @@ -204,19 +211,22 @@ namespace ReallifeGamemode.Server.Job { case 1: { - StartBusRoute(player, "Lang 1"); + c.StartBusRoute(player, "Lang 1"); + player.SendChatMessage("~y~[JOB] ~w~Eine neue Route wurde gesetzt.: ~g~Lang 1"); break; } case 2: { - StartBusRoute(player, "Lang 2"); + c.StartBusRoute(player, "Lang 2"); + player.SendChatMessage("~y~[JOB] ~w~Eine neue Route wurde gesetzt.: ~g~Lang 2"); break; } } } if (v.Model == (uint)Types.VehicleModel.Tourbus) { - StartBusRoute(player, "Mittel 1"); + c.StartBusRoute(player, "Mittel 1"); + player.SendChatMessage("~y~[JOB] ~w~Eine neue Route wurde gesetzt.: ~g~Mittel 1"); } } } diff --git a/ReallifeGamemode.Server/Job/PilotJob.cs b/ReallifeGamemode.Server/Job/PilotJob.cs index 2abe86b2..6d05bb99 100644 --- a/ReallifeGamemode.Server/Job/PilotJob.cs +++ b/ReallifeGamemode.Server/Job/PilotJob.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using GTANetworkAPI; using ReallifeGamemode.Server.Util; using Newtonsoft.Json; +using ReallifeGamemode.Server.Extensions; +using ReallifeGamemode.Database.Models; namespace ReallifeGamemode.Server.Job { class PilotJob : JobBase @@ -115,7 +117,7 @@ namespace ReallifeGamemode.Server.Job Vehicle veh = player.Vehicle; - if (veh.DisplayName == "Velum") + if ((VehicleHash)veh.Model == VehicleHash.Velum || (VehicleHash)veh.Model == VehicleHash.Velum2) { listRouteTexts2.Add("Route 4"); @@ -139,27 +141,100 @@ namespace ReallifeGamemode.Server.Job { if (type == "Route 1") { - CheckPointHandle.StartCheckPointRoute(player, Route1, 0, 6, 12, ""); + CheckPointHandle.StartCheckPointRoute(player, Route1, 0, 6, 40, 40, "pilotJob"); //6, 23, 25, 26, 27, 28 } else if (type == "Route 2") { - CheckPointHandle.StartCheckPointRoute(player, Route2, 0, 6, 12, ""); + CheckPointHandle.StartCheckPointRoute(player, Route2, 0, 6, 40, 40, "pilotJob"); } else if (type == "Route 3") { - CheckPointHandle.StartCheckPointRoute(player, Route3, 0, 6, 12, ""); + CheckPointHandle.StartCheckPointRoute(player, Route3, 0, 6, 40, 40, "pilotJob"); } else if (type == "Route 4") { - CheckPointHandle.StartCheckPointRoute(player, Route4, 0, 6, 12, ""); + CheckPointHandle.StartCheckPointRoute(player, Route4, 0, 6, 40, 40, "pilotJob"); } else if (type == "Route 5") { - CheckPointHandle.StartCheckPointRoute(player, Route5, 0, 6, 12, ""); + CheckPointHandle.StartCheckPointRoute(player, Route5, 0, 6, 40, 40, "pilotJob"); } else if (type == "Route 6") { - CheckPointHandle.StartCheckPointRoute(player, Route6, 0, 6, 12, ""); + CheckPointHandle.StartCheckPointRoute(player, Route6, 0, 6, 40, 40, "pilotJob"); + } + } + public static void payWage(Player jobber, int wage) + { + using (var dbContext = new DatabaseContext()) + { + jobber.GetUser(dbContext).BankAccount.Balance += wage; + jobber.SendChatMessage($"~y~[JOB] ~w~Du hast ~g~${wage} ~w~bekommen."); + jobber.GetUser(dbContext).PilotSkill++; + dbContext.SaveChanges(); + if (jobber.GetUser(dbContext).PilotSkill == 300) + { + jobber.SendChatMessage($"~y~[JOB] ~w~Du hast nun ~g~Skill-Level 2 ~w~erreicht!"); + jobber.SendChatMessage($"~y~[JOB] ~w~Du kannst jetzt auch mit dem Velum Flugzeug (LS Airport) fliegen!"); + } + } + } + [RemoteEvent("PilotLetzterCheckpoint")] + public static void PilotLetzterCheckpoint(Player player) + { + PilotJob c = new PilotJob(); + Vehicle v = player.Vehicle; + if (v.Model == (uint)Types.VehicleModel.Cuban800) + { + Random rnd = new Random(); + int rroute = rnd.Next(1, 4); + switch (rroute) + { + case 1: + { + c.StartPilotRoute(player, "Route 1"); + player.SendChatMessage("~y~[JOB] ~w~Eine neue Route wurde gesetzt.: ~g~Route 1"); + break; + } + case 2: + { + c.StartPilotRoute(player, "Route 2"); + player.SendChatMessage("~y~[JOB] ~w~Eine neue Route wurde gesetzt.: ~g~Route 2"); + break; + } + case 3: + { + c.StartPilotRoute(player, "Route 3"); + player.SendChatMessage("~y~[JOB] ~w~Eine neue Route wurde gesetzt.: ~g~Route 2"); + break; + } + } + } + if (v.Model == (uint)Types.VehicleModel.Velum || v.Model == (uint)Types.VehicleModel.Velum2) + { + Random rnd = new Random(); + int rroute = rnd.Next(1, 4); + switch (rroute) + { + case 1: + { + c.StartPilotRoute(player, "Route 4"); + player.SendChatMessage("~y~[JOB] ~w~Eine neue Route wurde gesetzt.: ~g~Route 4"); + break; + } + case 2: + { + c.StartPilotRoute(player, "Route 5"); + player.SendChatMessage("~y~[JOB] ~w~Eine neue Route wurde gesetzt.: ~g~Route 5"); + break; + } + case 3: + { + c.StartPilotRoute(player, "Route 6"); + player.SendChatMessage("~y~[JOB] ~w~Eine neue Route wurde gesetzt.: ~g~Route 6"); + break; + } + } } } } diff --git a/ReallifeGamemode.Server/Managers/JobManager.cs b/ReallifeGamemode.Server/Managers/JobManager.cs index e09f54b6..8405ae8a 100644 --- a/ReallifeGamemode.Server/Managers/JobManager.cs +++ b/ReallifeGamemode.Server/Managers/JobManager.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Timers; namespace ReallifeGamemode.Server.Managers { @@ -18,6 +19,8 @@ namespace ReallifeGamemode.Server.Managers { private static List _jobs = new List(); + private static Timer timerJobVehicleRespawn = new Timer(30000); //30 Sekunden Timer JobVehicleRespawn + public static void LoadJobs() { IEnumerable jobTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(JobBase)) && !t.IsAbstract); @@ -30,7 +33,7 @@ namespace ReallifeGamemode.Server.Managers throw new InvalidOperationException($"Double Job ID found: {instance.Id} | {instance.Name}"); } _jobs.Add(instance); - NAPI.Util.ConsoleOutput($"Loading job {instance.Name}"); + NAPI.Util.ConsoleOutput($"Loading job {instance.Name}"); } NAPI.Util.ConsoleOutput($"Loaded {_jobs.Count} jobs"); } @@ -145,12 +148,12 @@ namespace ReallifeGamemode.Server.Managers } } - JobPoint nearJobPoint = PositionManager.jobPoints.Find(p => p.Position.DistanceTo(player.Position) <= 2); - if (nearJobPoint == null && u.JobId == 2) return; - + JobPoint nearJobPoint = PositionManager.jobPoints.Find(p => p.Position.DistanceTo(player.Position) <= 2); + if (nearJobPoint == null && u.JobId == 2) return; - var json = JsonConvert.SerializeObject(data); + + var json = JsonConvert.SerializeObject(data); player.TriggerEvent("SERVER:Job_ShowJobMenu", job.Name, json); } @@ -199,9 +202,61 @@ namespace ReallifeGamemode.Server.Managers VehicleStreaming.SetEngineState(player.Vehicle, false); } + //if (LastVehicle.GetData("timerJobVehicleRespawn") == true) + //Vehicle v = player.Vehicle; job.StopJob(player); + if (player.GetUser().JobId == 1)//Taxifahrer + { + player.Position = new Vector3(-628.598388671875, -2107.609130859375, 6.072586536407471); + player.Heading = (-171.50303649902344f); + } + if (player.GetUser().JobId == 2)//Müllmann + { + player.Position = new Vector3(-428.9902038574219, -1726.5357666015625, 19.783836364746094); + player.Heading = (-15.922085762023926f); + } + if (player.GetUser().JobId == 3)//Pilot + { + if (LastVehicle != null) + { + if ((VehicleHash)LastVehicle.Model == VehicleHash.Cuban800) + { + player.Position = new Vector3(1707.2711181640625, 3276.216064453125, 41.155494689941406); + player.Heading = (-154.65234375f); + ChatService.SendMessage(player, $"~y~[JOB]~s~ Debug 5"); + } + if ((VehicleHash)LastVehicle.Model == VehicleHash.Velum || (VehicleHash)LastVehicle.Model == VehicleHash.Velum2) + { + player.Position = new Vector3(-1615.156982421875, -3140.54833984375, 13.991917610168457); + player.Heading = (60.65372848510742f); + ChatService.SendMessage(player, $"~y~[JOB]~s~ Debug 6"); + } + } + } + if (player.GetUser().JobId == 4)//Busfahrer + { + if (LastVehicle != null) + { + if ((VehicleHash)LastVehicle.Model == VehicleHash.Bus || (VehicleHash)LastVehicle.Model == VehicleHash.Coach) + { + player.Position = new Vector3(-604.0092163085938, -2229.08447265625, 6.004401683807373); + player.Heading = (17.64179039001465f); + ChatService.SendMessage(player, $"~y~[JOB]~s~ Debug 7"); + } + if ((VehicleHash)LastVehicle.Model == VehicleHash.Tourbus) + { + player.Position = new Vector3(458.98468017578125, -657.942138671875, 27.58537483215332); + player.Heading = (-8.147048950195312f); + ChatService.SendMessage(player, $"~y~[JOB]~s~ Debug 8"); + } + } + } + ServerVehicle sVeh = VehicleManager.GetServerVehicleFromVehicle(LastVehicle); + ServerVehicleExtensions.Spawn(sVeh, LastVehicle); + CheckPointHandle.DeleteCheckpoints(player); + ChatService.SendMessage(player, $"~y~[JOB]~s~ Du hast deinen Job ~o~{job.Name}~s~ beendet."); } - + Vehicle LastVehicle; [ServerEvent(Event.PlayerExitVehicle)] public void JobManagerPlayerExitVehicle(Player player, Vehicle veh) { @@ -210,53 +265,154 @@ namespace ReallifeGamemode.Server.Managers if (u.JobId == null) return; JobBase job = GetJob(u.JobId.Value); - - if (job.GetUsersInJob().Contains(player) && job.NeedVehicleToStart) + if (veh.GetServerVehicle() is JobVehicle vehJ) { - job.StopJob(player); - return; + if (vehJ.GetJob().GetUsersInJob().Contains(player) && job.NeedVehicleToStart) + { + if (u.JobId != 2) + { + timerJobVehicleRespawn.Start(); + veh.SetData("timerJobVehicleRespawn", true); + LastVehicle = veh; + timerJobVehicleRespawn.AutoReset = false; + timerJobVehicleRespawn.Elapsed += Timer30000_Elapsed; + player.SendChatMessage("~y~[JOB] ~w~Du hast das Fahrzeug verlassen,"); + player.SendChatMessage("~y~[JOB] ~w~Bist du nicht in 30 Sekunden zurück, ~r~wird der Job beendet!"); + //job.StopJob(player); + return; + } + } } } - + public void Timer30000_Elapsed(object sender, ElapsedEventArgs e) + { + NAPI.Task.Run(() => + { + NAPI.Pools.GetAllPlayers().ForEach(p => + { + NAPI.Pools.GetAllVehicles().ForEach(v => + { + if (LastVehicle.GetServerVehicle() is JobVehicle vehJ) + { + if (LastVehicle.GetData("timerJobVehicleRespawn") == true) + { + JobBase job = GetJob(p.GetUser().JobId.Value); + ServerVehicle sVeh = VehicleManager.GetServerVehicleFromVehicle(LastVehicle); + if (vehJ.GetJob().GetUsersInJob().Contains(p)) + { + if (LastVehicle != null) + { + job.StopJob(p); + ChatService.SendMessage(p, $"~y~[JOB]~s~ Du hast deinen Job ~o~{job.Name}~s~ beendet."); + LastVehicle.ResetData("timerJobVehicleRespawn"); + CheckPointHandle.DeleteCheckpoints(p); + ServerVehicleExtensions.Spawn(sVeh, LastVehicle); + if (p.GetData("isDead") == true) + { + if (p.GetUser().JobId == 1)//Taxifahrer + { + //VehicleManager.DeleteVehicle(v); + } + if (p.GetUser().JobId == 2)//Müllmann + { + //VehicleManager.DeleteVehicle(v); + } + if (p.GetUser().JobId == 3)//Pilot + { + if ((VehicleHash)LastVehicle.Model == VehicleHash.Cuban800) + { + p.Position = new Vector3(1707.2711181640625, 3276.216064453125, 41.155494689941406); + p.Heading = (-154.65234375f); + } + if ((VehicleHash)LastVehicle.Model == VehicleHash.Velum || (VehicleHash)LastVehicle.Model == VehicleHash.Velum2) + { + p.Position = new Vector3(-1615.156982421875, -3140.54833984375, 13.991917610168457); + p.Heading = (60.65372848510742f); + } + //VehicleManager.DeleteVehicle(v); + } + if (p.GetUser().JobId == 4) //Busfahrer + { + if ((VehicleHash)LastVehicle.Model == VehicleHash.Bus || (VehicleHash)LastVehicle.Model == VehicleHash.Coach) + { + p.Position = new Vector3(-604.0092163085938, -2229.08447265625, 6.004401683807373); + p.Heading = (17.64179039001465f); + } + if ((VehicleHash)LastVehicle.Model == VehicleHash.Tourbus) + { + p.Position = new Vector3(458.98468017578125, -657.942138671875, 27.58537483215332); + p.Heading = (-8.147048950195312f); + } + //VehicleManager.DeleteVehicle(v); + } + } + } + } + } + } + }); + }); + }); + } + [ServerEvent(Event.PlayerEnterVehicle)] public void JobManagerPlayerEnterVehicle(Player player, Vehicle veh, sbyte seat) { - if (seat == 0) return; ServerVehicle sVeh = veh.GetServerVehicle(); if (sVeh == null) return; - if (sVeh is JobVehicle jV && jV.JobId == 1) // Spieler steigt in Taxi ein + if (seat != 0) { - var taxiJob = JobManager.GetJob(); - - Player driver = veh.GetDriver(); - if (!driver.HasData("DriverPrice")) return; - int taxiPrice = driver.GetData("DriverPrice"); - float km = 0; - if (!driver.HasData("FareKm")) { driver.SetData("FareKm", km); } - km = driver.GetData("FareKm"); - if (driver.HasData("Passager")) return; - driver.SetData("Passager", player.GetUser().Id); - driver.SetData("hasPassager", true); - using (var dbContext = new DatabaseContext()) + if (sVeh is JobVehicle jV && jV.JobId == 1) // Spieler steigt in Taxi ein { - User contractUser = player.GetUser(dbContext); - contractUser.Handmoney -= (int)Math.Round(km * taxiPrice); - dbContext.SaveChanges(); - contractUser.Player.TriggerEvent("SERVER:SET_HANDMONEY", contractUser.Handmoney); + var taxiJob = JobManager.GetJob(); + + Player driver = veh.GetDriver(); + if (!driver.HasData("DriverPrice")) return; + int taxiPrice = driver.GetData("DriverPrice"); + float km = 0; + if (!driver.HasData("FareKm")) { driver.SetData("FareKm", km); } + km = driver.GetData("FareKm"); + if (driver.HasData("Passager")) return; + driver.SetData("Passager", player.GetUser().Id); + driver.SetData("hasPassager", true); + using (var dbContext = new DatabaseContext()) + { + User contractUser = player.GetUser(dbContext); + contractUser.Handmoney -= (int)Math.Round(km * taxiPrice); + dbContext.SaveChanges(); + contractUser.Player.TriggerEvent("SERVER:SET_HANDMONEY", contractUser.Handmoney); + } + player.TriggerEvent("CLIENT:startCustomerFare", taxiPrice, km); + + var taxiContracts = taxiJob.TaxiContracts.Where(t => t.Name == player.Name); + if (taxiContracts.Count() == 0) return; + + var contract = taxiContracts.First(); + taxiJob.TaxiContracts.Remove(contract); + + if (driver != null && contract.Driver != null && contract.Driver.Handle != veh.GetDriver().Handle) + { + ChatService.SendMessage(contract.Driver, $"!{{02FCFF}}{player.Name} ist in ein Taxi eingestiegen, der Auftrag wurde beendet."); + ChatService.SendMessage(player, $"!{{02FCFF}}Du bist in ein Taxi eingestiegen, der Auftrag wurde beendet."); + } } - player.TriggerEvent("CLIENT:startCustomerFare", taxiPrice, km); - - var taxiContracts = taxiJob.TaxiContracts.Where(t => t.Name == player.Name); - if (taxiContracts.Count() == 0) return; - - var contract = taxiContracts.First(); - taxiJob.TaxiContracts.Remove(contract); - - if (driver != null && contract.Driver != null && contract.Driver.Handle != veh.GetDriver().Handle) + } + else + { + if (sVeh != null) { - ChatService.SendMessage(contract.Driver, $"!{{02FCFF}}{player.Name} ist in ein Taxi eingestiegen, der Auftrag wurde beendet."); - ChatService.SendMessage(player, $"!{{02FCFF}}Du bist in ein Taxi eingestiegen, der Auftrag wurde beendet."); - } + if (sVeh is JobVehicle JV) + { + JobVehicle c = new JobVehicle(); + if (JV.GetJob().GetUsersInJob().Contains(player)) + { + timerJobVehicleRespawn.Stop(); + veh.SetData("timerJobVehicleRespawn", false); + } + else return; + } + } + return; } } diff --git a/ReallifeGamemode.Server/Util/CheckPointHandle.cs b/ReallifeGamemode.Server/Util/CheckPointHandle.cs index ef03a3a5..ccb57c51 100644 --- a/ReallifeGamemode.Server/Util/CheckPointHandle.cs +++ b/ReallifeGamemode.Server/Util/CheckPointHandle.cs @@ -3,7 +3,7 @@ using ReallifeGamemode.Server.Services; using GTANetworkAPI; using System.Linq; using ReallifeGamemode.Server.Extensions; - +using ReallifeGamemode.Server.Job; namespace ReallifeGamemode.Server.Util { @@ -17,15 +17,20 @@ namespace ReallifeGamemode.Server.Util player.TriggerEvent("destroyCP"); } - public static void StartCheckPointRoute(Player player, IEnumerable nListCps, int delay, int markerID, int markerSize, string nEvent) + public static void StartCheckPointRoute(Player player, IEnumerable nListCps, int delay, int markerID, int markerSize, int markerDist, string nEvent) { + RemovePlayerHandlerFromList(player); - CheckPointListForPlayer playerHandle = new CheckPointListForPlayer(player, nListCps, delay, markerID, markerSize, nEvent); + CheckPointListForPlayer playerHandle = new CheckPointListForPlayer(player, nListCps, delay, markerID, markerSize, markerDist, nEvent); playerHandle.DeleteCheckpoints(); listHandle.Add(playerHandle); playerHandle.StartRoute(); + /*if(player.GetUser().BusSkill >= 1000) + { + playerHandle.LastCheckpoint = 2; + }*/ } public static void RemovePlayerHandlerFromList(Player player) { @@ -44,7 +49,6 @@ namespace ReallifeGamemode.Server.Util public void PlayerInCheckpoint(Player user) { CheckPointListForPlayer temp = null; - Job.BusDriverJob temp2 = null; for (int a = 0; a < listHandle.Count; a++) { temp = listHandle[a]; @@ -55,19 +59,18 @@ namespace ReallifeGamemode.Server.Util } if (temp.LastCheckpoint != 1) { + if (user.GetUser().JobId == 3) + { + PilotJob.payWage(user, 100); + } if (user.GetUser().JobId == 4) { - Job.BusDriverJob.payWage(user, 100); + BusDriverJob.payWage(user, 100); } } else { - if (user.GetUser().JobId == 4) - { - Job.BusDriverJob.payWage(user, 200); - temp2.BusLetzterCheckpoint(user); - } - } + } temp.NextCheckpoint(); } } @@ -80,24 +83,26 @@ namespace ReallifeGamemode.Server.Util public int delay = 0; public int markerID; public int markerSize; + public int markerDist; public string eventInCheckpoint = ""; int checkPointsDone = 0; - public CheckPointListForPlayer(Player nPlayer, IEnumerable nList, int nDelay, int nMarkerID, int nMarkerSize, string nEvent) + public CheckPointListForPlayer(Player nPlayer, IEnumerable nList, int nDelay, int nMarkerID, int nMarkerSize, int nMarkerDist, string nEvent) { this.player = nPlayer; this.list = nList; this.delay = nDelay; this.markerID = nMarkerID; this.markerSize = nMarkerSize; + this.markerDist = nMarkerDist; this.eventInCheckpoint = nEvent; this.checkPointsDone = 0; } public void StartRoute() { - player.TriggerEvent("setCheckPoint", this.list.ElementAt(0), player, 0, this.delay, this.markerID, this.markerSize, this.eventInCheckpoint); + player.TriggerEvent("setCheckPoint", this.list.ElementAt(0), player, 0, this.delay, this.markerID, this.markerSize, this.markerDist, this.eventInCheckpoint); } public void NextCheckpoint() { @@ -106,17 +111,29 @@ namespace ReallifeGamemode.Server.Util { LastCheckpoint = 0; Vector3 nextCp = list.ElementAt(checkPointsDone); - this.player.TriggerEvent("setCheckPoint", nextCp, player, this.checkPointsDone, delay, this.markerID, this.markerSize, this.eventInCheckpoint); + this.player.TriggerEvent("setCheckPoint", nextCp, player, this.checkPointsDone, delay, this.markerID, this.markerSize, this.markerDist, this.eventInCheckpoint); } - if (this.list.Count() == checkPointsDone-1) + if (checkPointsDone == this.list.Count()-1) { LastCheckpoint = 1; } if (this.list.Count() == checkPointsDone) { - LastCheckpoint = 0; - CheckPointHandle.RemovePlayerHandlerFromList(this.player); + LastCheckpoint = 0; + CheckPointHandle.RemovePlayerHandlerFromList(this.player); + DeleteCheckpoints(); + if (player.GetUser().JobId == 3) + { + PilotJob.payWage(player, 200); + PilotJob.PilotLetzterCheckpoint(player); + } + if (player.GetUser().JobId == 4) + { + BusDriverJob.payWage(player, 200); + BusDriverJob.BusLetzterCheckpoint(player); + } } + //NAPI.Chat.SendChatMessageToAll($"this.list.Count() = {this.list.Count()}, checkPointsDone = {checkPointsDone}, LastCheckpoint = {LastCheckpoint}"); } public void DeleteCheckpoints()