Fix Medic

This commit is contained in:
VegaZ
2021-04-04 15:18:30 +02:00
parent 3dd15de267
commit 1e7f2deac9
4 changed files with 53 additions and 11 deletions

View File

@@ -288,7 +288,7 @@ export default function factionInteraction(globalData: IGlobalData) {
initTasks = tasks; initTasks = tasks;
} }
mp.events.call("sortFactionTasks", false); //mp.events.call("sortFactionTasks", false);
mp.gui.chat.activate(false); mp.gui.chat.activate(false);
globalData.InMenu = true; globalData.InMenu = true;
@@ -329,7 +329,7 @@ export default function factionInteraction(globalData: IGlobalData) {
dimension: 0 dimension: 0
}); });
reviveTaskMenuMedic.Close(); reviveTaskMenuMedic.Close();
deathTime = deathSeconds[index]; deathTime = tasks[index].TimeLeft;
mp.gui.chat.activate(true); mp.gui.chat.activate(true);
globalData.InMenu = false; globalData.InMenu = false;
ambulanceImagePos = 0.325 ambulanceImagePos = 0.325
@@ -337,7 +337,7 @@ export default function factionInteraction(globalData: IGlobalData) {
taskFinish = tasks[index].Position; 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); 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]; activeTask = tasks[index];
mp.events.callRemote("getTaskTimeLeft", tasks[index].Victim);
} }
} }
}); });
@@ -477,6 +477,7 @@ export default function factionInteraction(globalData: IGlobalData) {
mp.events.add("destroyMedicTaskCheckpoint", () => { mp.events.add("destroyMedicTaskCheckpoint", () => {
activeCheckpoint.destroy(); activeCheckpoint.destroy();
activeCheckpoint = null;
activeTask = null; activeTask = null;
timeLeft = 0; timeLeft = 0;
mp.events.callRemote("MedicTaskTimeout"); mp.events.callRemote("MedicTaskTimeout");
@@ -485,17 +486,25 @@ export default function factionInteraction(globalData: IGlobalData) {
mp.events.add('playerEnterCheckpoint', (activeCheckpoint) => { mp.events.add('playerEnterCheckpoint', (activeCheckpoint) => {
if (deadRespawned == true) { if (deadRespawned == true) {
activeCheckpoint.destroy(); activeCheckpoint.destroy();
activeCheckpoint = null;
mp.events.callRemote("PayCutMedicEarnings"); mp.events.callRemote("PayCutMedicEarnings");
activeTask = null; activeTask = null;
deadRespawned = false; deadRespawned = false;
timeLeft = 0; timeLeft = 0;
} else if (activeTask.Type == 1){ } else if (activeTask.Type == 1){
activeCheckpoint.destroy(); activeCheckpoint.destroy();
activeCheckpoint = null;
mp.events.callRemote("delHealTaskAsMedic", activeTask.Victim); mp.events.callRemote("delHealTaskAsMedic", activeTask.Victim);
activeTask = null; activeTask = null;
} }
}); });
mp.events.add('setTaskTimeLeft', (taskTimeLeft) => {
if (activeTask) {
activeTask.TimeLeft = taskTimeLeft;
}
});
mp.events.add('render', () => { mp.events.add('render', () => {
if (activeTask) { if (activeTask) {
rangeLeft = mp.game.gameplay.getDistanceBetweenCoords(player.position.x, player.position.y, player.position.z, taskFinish.x, taskFinish.y, taskFinish.z, true).toFixed(2); rangeLeft = mp.game.gameplay.getDistanceBetweenCoords(player.position.x, player.position.y, player.position.z, taskFinish.x, taskFinish.y, taskFinish.z, true).toFixed(2);
@@ -521,16 +530,15 @@ export default function factionInteraction(globalData: IGlobalData) {
var currentDate = new Date(); var currentDate = new Date();
if (deadRespawned == false) { 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"); if (timeLeft < 1) mp.events.call("cutMedicEarnings");
} else { } 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"); if (timeLeft < 1) mp.events.call("destroyMedicTaskCheckpoint");
} }
/*DEBUG TIMER für die Zeit die man noch hat zur Wiederbelebung
if (deadRespawned == false) { 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, font: 7,
color: [60, 179, 113, 255], color: [60, 179, 113, 255],
scale: [0.3, 0.3], scale: [0.3, 0.3],
@@ -539,7 +547,7 @@ export default function factionInteraction(globalData: IGlobalData) {
}); });
} else { } 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, font: 7,
color: [255, 203, 145, 255], color: [255, 203, 145, 255],
scale: [0.3, 0.3], scale: [0.3, 0.3],
@@ -547,7 +555,7 @@ export default function factionInteraction(globalData: IGlobalData) {
centre: true centre: true
}); });
} }
} */ }
} }
}); });
} }

View File

@@ -24,6 +24,7 @@ namespace ReallifeGamemode.Server.Factions.Medic
public static List<MedicTask> FireTasks = new List<MedicTask>(); public static List<MedicTask> FireTasks = new List<MedicTask>();
public static int ReviveIncome = 100; public static int ReviveIncome = 100;
public static int dutyMedics = 0; public static int dutyMedics = 0;
public static long reviveTaskTime = 120;
public static void AddTaskToList(MedicTask task) 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")] [RemoteEvent("loadMedicTasks")]
public void LoadMedicTasks(Player player, int type) public void LoadMedicTasks(Player player, int type)
{ {
@@ -162,11 +172,13 @@ namespace ReallifeGamemode.Server.Factions.Medic
public void PayCutMedicEarnings(Player player) 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; 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."); player.SendNotification($"Du hast den Einsatzort erreicht und ~g~{Medic.ReviveIncome / 2}$ ~s~für die Fraktion verdient.");
Medic.delReviveTaskMedic(player); Medic.delReviveTaskMedic(player);
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
}
[RemoteEvent("MedicTaskTimeout")] [RemoteEvent("MedicTaskTimeout")]
public void RemoveMedicTask(Player player) public void RemoveMedicTask(Player player)
@@ -174,6 +186,17 @@ namespace ReallifeGamemode.Server.Factions.Medic
Medic.delReviveTaskMedic(player); 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) public static void UpdateDutyMedics(int modifier)
{ {
dutyMedics = dutyMedics + modifier; dutyMedics = dutyMedics + modifier;

View File

@@ -18,6 +18,7 @@ namespace ReallifeGamemode.Server.Factions.Medic
public string Description { get; set; } public string Description { get; set; }
public string Caller { get; set; } public string Caller { get; set; }
public DateTime Time { get; set; } public DateTime Time { get; set; }
public long TimeLeft { get; set; }
public string MedicName { get; set; } public string MedicName { get; set; }
} }

View File

@@ -1,5 +1,6 @@
using System.Timers; using System.Timers;
using GTANetworkAPI; using GTANetworkAPI;
using ReallifeGamemode.Server.Factions.Medic;
using ReallifeGamemode.Server.Finance; using ReallifeGamemode.Server.Finance;
using ReallifeGamemode.Server.Job; using ReallifeGamemode.Server.Job;
using ReallifeGamemode.Server.Managers; using ReallifeGamemode.Server.Managers;
@@ -11,6 +12,7 @@ namespace ReallifeGamemode.Server.Util
public class ThreadTimers public class ThreadTimers
{ {
private static Timer timer500 = new Timer(500); //0.5 seconds timer 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 timer2500 = new Timer(2500); //2.5 seconds timer
private static Timer timer10000 = new Timer(10000); // 10 second timer private static Timer timer10000 = new Timer(10000); // 10 second timer
private static Timer timer60000 = new Timer(60000); //60 seconds 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) private static void Timer60000_Elapsed(object sender, ElapsedEventArgs e)
{ {
NAPI.Task.Run(() => NAPI.Task.Run(() =>