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;
}
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,17 +486,25 @@ 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;
}
});
mp.events.add('setTaskTimeLeft', (taskTimeLeft) => {
if (activeTask) {
activeTask.TimeLeft = taskTimeLeft;
}
});
mp.events.add('render', () => {
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);
@@ -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
});
}
} */
}
}
});
}

View File

@@ -24,6 +24,7 @@ namespace ReallifeGamemode.Server.Factions.Medic
public static List<MedicTask> FireTasks = new List<MedicTask>();
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;

View File

@@ -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; }
}

View File

@@ -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(() =>