From 14fdc1e1a4e7d3d55120094e4e89c6e2b2eb007c Mon Sep 17 00:00:00 2001 From: CroniX Date: Sun, 4 Apr 2021 14:58:33 +0200 Subject: [PATCH 1/3] Add playtime and warns in M menu --- ReallifeGamemode.Client/Interaction/interactionmenu.ts | 8 ++++++++ ReallifeGamemode.Client/global.d.ts | 2 ++ ReallifeGamemode.Server/Events/Key.cs | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ReallifeGamemode.Client/Interaction/interactionmenu.ts b/ReallifeGamemode.Client/Interaction/interactionmenu.ts index 1946fc78..3b81278e 100644 --- a/ReallifeGamemode.Client/Interaction/interactionmenu.ts +++ b/ReallifeGamemode.Client/Interaction/interactionmenu.ts @@ -226,6 +226,14 @@ export default function (globalData: IGlobalData) { menuItem.SetRightLabel(data.regDate); accountMenu.AddItem(menuItem); + menuItem = new UIMenuItem("Spielzeit"); + menuItem.SetRightLabel(data.playTime + "h"); + accountMenu.AddItem(menuItem); + + menuItem = new UIMenuItem("Verwarnungen"); + menuItem.SetRightLabel("~r~" + data.userWarn); + accountMenu.AddItem(menuItem); + menuItem = new UIMenuItem("Adminrang"); menuItem.SetRightLabel(data.adminLevel); accountMenu.AddItem(menuItem); diff --git a/ReallifeGamemode.Client/global.d.ts b/ReallifeGamemode.Client/global.d.ts index 44ec321c..266c36d6 100644 --- a/ReallifeGamemode.Client/global.d.ts +++ b/ReallifeGamemode.Client/global.d.ts @@ -21,6 +21,8 @@ declare type AccountData = { factionVehicles: VehicleData[]; nextPayday: number; stateFaction: boolean; + playTime: number; + userWarn: number; } declare type VehicleData = { diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index 47008c2e..703b4916 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -151,7 +151,9 @@ namespace ReallifeGamemode.Server.Events licenses, vehicles, factionVehicles, - nextPayday = u.PaydayTimer + nextPayday = u.PaydayTimer, + playTime = u.PlayedMinutes / 60, + userWarn = u.warn, }; string faction = u.Faction?.Name ?? "Zivilist"; From 1e7f2deac93adc2087f90a94c881fcf699b1a222 Mon Sep 17 00:00:00 2001 From: VegaZ Date: Sun, 4 Apr 2021 15:18:30 +0200 Subject: [PATCH 2/3] Fix Medic --- .../Interaction/factioninteraction.ts | 28 ++++++++++++------- .../Factions/Medic/Medic.cs | 25 ++++++++++++++++- .../Factions/Medic/MedicTask.cs | 1 + ReallifeGamemode.Server/Util/ThreadTimers.cs | 10 +++++++ 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/ReallifeGamemode.Client/Interaction/factioninteraction.ts b/ReallifeGamemode.Client/Interaction/factioninteraction.ts index dfa95f1c..bb670c6f 100644 --- a/ReallifeGamemode.Client/Interaction/factioninteraction.ts +++ b/ReallifeGamemode.Client/Interaction/factioninteraction.ts @@ -288,7 +288,7 @@ export default function factionInteraction(globalData: IGlobalData) { initTasks = tasks; } - mp.events.call("sortFactionTasks", false); + //mp.events.call("sortFactionTasks", false); mp.gui.chat.activate(false); globalData.InMenu = true; @@ -329,7 +329,7 @@ export default function factionInteraction(globalData: IGlobalData) { dimension: 0 }); reviveTaskMenuMedic.Close(); - deathTime = deathSeconds[index]; + deathTime = tasks[index].TimeLeft; mp.gui.chat.activate(true); globalData.InMenu = false; ambulanceImagePos = 0.325 @@ -337,7 +337,7 @@ export default function factionInteraction(globalData: IGlobalData) { taskFinish = tasks[index].Position; taskRange = mp.game.gameplay.getDistanceBetweenCoords(player.position.x, player.position.y, player.position.z, tasks[index].Position.x, tasks[index].Position.y, tasks[index].Position.z, true); activeTask = tasks[index]; - + mp.events.callRemote("getTaskTimeLeft", tasks[index].Victim); } } }); @@ -477,6 +477,7 @@ export default function factionInteraction(globalData: IGlobalData) { mp.events.add("destroyMedicTaskCheckpoint", () => { activeCheckpoint.destroy(); + activeCheckpoint = null; activeTask = null; timeLeft = 0; mp.events.callRemote("MedicTaskTimeout"); @@ -485,14 +486,22 @@ export default function factionInteraction(globalData: IGlobalData) { mp.events.add('playerEnterCheckpoint', (activeCheckpoint) => { if (deadRespawned == true) { activeCheckpoint.destroy(); + activeCheckpoint = null; mp.events.callRemote("PayCutMedicEarnings"); activeTask = null; deadRespawned = false; timeLeft = 0; } else if (activeTask.Type == 1){ activeCheckpoint.destroy(); + activeCheckpoint = null; mp.events.callRemote("delHealTaskAsMedic", activeTask.Victim); - activeTask = null; + activeTask = null; + } + }); + + mp.events.add('setTaskTimeLeft', (taskTimeLeft) => { + if (activeTask) { + activeTask.TimeLeft = taskTimeLeft; } }); @@ -521,16 +530,15 @@ export default function factionInteraction(globalData: IGlobalData) { var currentDate = new Date(); if (deadRespawned == false) { - timeLeft = Math.round(Math.abs(Math.floor(currentDate.getTime() / 1000) - deathTime - 30)); + timeLeft = Math.round(Math.abs(Math.floor(currentDate.getTime() / 1000) - activeTask.TimeLeft - 60)); if (timeLeft < 1) mp.events.call("cutMedicEarnings"); } else { - timeLeft = Math.round(Math.abs(Math.floor(currentDate.getTime() / 1000) - deathTime - 60)); + timeLeft = Math.round(Math.abs(Math.floor(currentDate.getTime() / 1000) - activeTask.TimeLeft - 120)); if (timeLeft < 1) mp.events.call("destroyMedicTaskCheckpoint"); } - /*DEBUG TIMER für die Zeit die man noch hat zur Wiederbelebung if (deadRespawned == false) { - mp.game.graphics.drawText(timeLeft.toString() + "s ", [0.5, 0.88], { + mp.game.graphics.drawText(activeTask.TimeLeft.toString() + "s ", [0.5, 0.88], { font: 7, color: [60, 179, 113, 255], scale: [0.3, 0.3], @@ -539,7 +547,7 @@ export default function factionInteraction(globalData: IGlobalData) { }); } else { { - mp.game.graphics.drawText(timeLeft.toString() + "s", [0.5, 0.88], { + mp.game.graphics.drawText(activeTask.TimeLeft.toString() + "s", [0.5, 0.88], { font: 7, color: [255, 203, 145, 255], scale: [0.3, 0.3], @@ -547,7 +555,7 @@ export default function factionInteraction(globalData: IGlobalData) { centre: true }); } - } */ + } } }); } \ No newline at end of file diff --git a/ReallifeGamemode.Server/Factions/Medic/Medic.cs b/ReallifeGamemode.Server/Factions/Medic/Medic.cs index 60442169..b0a10899 100644 --- a/ReallifeGamemode.Server/Factions/Medic/Medic.cs +++ b/ReallifeGamemode.Server/Factions/Medic/Medic.cs @@ -24,6 +24,7 @@ namespace ReallifeGamemode.Server.Factions.Medic public static List FireTasks = new List(); public static int ReviveIncome = 100; public static int dutyMedics = 0; + public static long reviveTaskTime = 120; public static void AddTaskToList(MedicTask task) { @@ -71,6 +72,15 @@ namespace ReallifeGamemode.Server.Factions.Medic } } + public static void UpdateTaskTimeLeft() + { + DateTime actualTime = DateTime.Now; + foreach(var task in ReviveTasks) + { + task.TimeLeft = ((DateTimeOffset)task.Time).ToUnixTimeSeconds() - ((DateTimeOffset)actualTime).ToUnixTimeSeconds() - reviveTaskTime; + } + } + [RemoteEvent("loadMedicTasks")] public void LoadMedicTasks(Player player, int type) { @@ -161,11 +171,13 @@ namespace ReallifeGamemode.Server.Factions.Medic [RemoteEvent("PayCutMedicEarnings")] public void PayCutMedicEarnings(Player player) { - using var dbContext = new DatabaseContext(); + using var dbContext = new DatabaseContext(); + { dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Id == 2).First().BankAccount.Balance += Medic.ReviveIncome / 2; player.SendNotification($"Du hast den Einsatzort erreicht und ~g~{Medic.ReviveIncome / 2}$ ~s~für die Fraktion verdient."); Medic.delReviveTaskMedic(player); dbContext.SaveChanges(); + } } [RemoteEvent("MedicTaskTimeout")] @@ -174,6 +186,17 @@ namespace ReallifeGamemode.Server.Factions.Medic Medic.delReviveTaskMedic(player); } + [RemoteEvent("getTaskTimeLeft")] + public void GetTaskTimeLeft(Player player, string victimName) + { + using var dbContext = new DatabaseContext(); + { + var activeTaskTime = ReviveTasks.FirstOrDefault(t => t.MedicName == player.Name && t.Victim == victimName).TimeLeft; + + player.TriggerEvent("setTaskTimeLeft", activeTaskTime); + } + } + public static void UpdateDutyMedics(int modifier) { dutyMedics = dutyMedics + modifier; diff --git a/ReallifeGamemode.Server/Factions/Medic/MedicTask.cs b/ReallifeGamemode.Server/Factions/Medic/MedicTask.cs index 50c0f2a8..24d413ee 100644 --- a/ReallifeGamemode.Server/Factions/Medic/MedicTask.cs +++ b/ReallifeGamemode.Server/Factions/Medic/MedicTask.cs @@ -18,6 +18,7 @@ namespace ReallifeGamemode.Server.Factions.Medic public string Description { get; set; } public string Caller { get; set; } public DateTime Time { get; set; } + public long TimeLeft { get; set; } public string MedicName { get; set; } } diff --git a/ReallifeGamemode.Server/Util/ThreadTimers.cs b/ReallifeGamemode.Server/Util/ThreadTimers.cs index f5dd07ec..ff3f417f 100644 --- a/ReallifeGamemode.Server/Util/ThreadTimers.cs +++ b/ReallifeGamemode.Server/Util/ThreadTimers.cs @@ -1,5 +1,6 @@ using System.Timers; using GTANetworkAPI; +using ReallifeGamemode.Server.Factions.Medic; using ReallifeGamemode.Server.Finance; using ReallifeGamemode.Server.Job; using ReallifeGamemode.Server.Managers; @@ -11,6 +12,7 @@ namespace ReallifeGamemode.Server.Util public class ThreadTimers { private static Timer timer500 = new Timer(500); //0.5 seconds timer + private static Timer timer1000 = new Timer(1000); //1 seconds timer private static Timer timer2500 = new Timer(2500); //2.5 seconds timer private static Timer timer10000 = new Timer(10000); // 10 second timer private static Timer timer60000 = new Timer(60000); //60 seconds timer @@ -39,6 +41,14 @@ namespace ReallifeGamemode.Server.Util }); } + private static void Timer1000_Elapsed(object sender, ElapsedEventArgs e) + { + NAPI.Task.Run(() => + { + Medic.UpdateTaskTimeLeft(); + }); + } + private static void Timer60000_Elapsed(object sender, ElapsedEventArgs e) { NAPI.Task.Run(() => From 88b60168634fcef104341f797395d9a272769c65 Mon Sep 17 00:00:00 2001 From: VegaZ Date: Sun, 4 Apr 2021 15:26:29 +0200 Subject: [PATCH 3/3] Fix Medic 2 --- ReallifeGamemode.Server/Factions/Medic/Medic.cs | 4 ++-- ReallifeGamemode.Server/Factions/Medic/MedicTask.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ReallifeGamemode.Server/Factions/Medic/Medic.cs b/ReallifeGamemode.Server/Factions/Medic/Medic.cs index b0a10899..3a223c12 100644 --- a/ReallifeGamemode.Server/Factions/Medic/Medic.cs +++ b/ReallifeGamemode.Server/Factions/Medic/Medic.cs @@ -24,7 +24,7 @@ namespace ReallifeGamemode.Server.Factions.Medic public static List FireTasks = new List(); public static int ReviveIncome = 100; public static int dutyMedics = 0; - public static long reviveTaskTime = 120; + public static int reviveTaskTime = 120; public static void AddTaskToList(MedicTask task) { @@ -77,7 +77,7 @@ namespace ReallifeGamemode.Server.Factions.Medic DateTime actualTime = DateTime.Now; foreach(var task in ReviveTasks) { - task.TimeLeft = ((DateTimeOffset)task.Time).ToUnixTimeSeconds() - ((DateTimeOffset)actualTime).ToUnixTimeSeconds() - reviveTaskTime; + task.TimeLeft = (Int32)(((DateTimeOffset)task.Time).ToUnixTimeSeconds() - ((DateTimeOffset)actualTime).ToUnixTimeSeconds() - reviveTaskTime); } } diff --git a/ReallifeGamemode.Server/Factions/Medic/MedicTask.cs b/ReallifeGamemode.Server/Factions/Medic/MedicTask.cs index 24d413ee..9a6ae7f6 100644 --- a/ReallifeGamemode.Server/Factions/Medic/MedicTask.cs +++ b/ReallifeGamemode.Server/Factions/Medic/MedicTask.cs @@ -18,7 +18,7 @@ namespace ReallifeGamemode.Server.Factions.Medic public string Description { get; set; } public string Caller { get; set; } public DateTime Time { get; set; } - public long TimeLeft { get; set; } + public int TimeLeft { get; set; } public string MedicName { get; set; } }