diff --git a/ReallifeGamemode.Client/Player/keys.ts b/ReallifeGamemode.Client/Player/keys.ts index 8f2e3751..09d81158 100644 --- a/ReallifeGamemode.Client/Player/keys.ts +++ b/ReallifeGamemode.Client/Player/keys.ts @@ -136,7 +136,8 @@ export default function keys(globalData: IGlobalData) { //J // Job Starten mp.keys.bind(0x4A, false, () => { if (!globalData.InChat && globalData.LoggedIn && !globalData.InTuning) { - mp.events.callRemote("CLIENT:JobManager_ShowJobMenu"); + //mp.events.callRemote("CLIENT:JobManager_ShowJobMenu"); + mp.events.callRemote("keyPress:J"); } }); diff --git a/ReallifeGamemode.Server/Commands/FactionCommands.cs b/ReallifeGamemode.Server/Commands/FactionCommands.cs index 236320a4..4cec07ea 100644 --- a/ReallifeGamemode.Server/Commands/FactionCommands.cs +++ b/ReallifeGamemode.Server/Commands/FactionCommands.cs @@ -347,7 +347,7 @@ namespace ReallifeGamemode.Server.Commands } [Command("heal", "~m~Benutzung: ~s~/heal [Spieler] (Preis)")] //TODO Eventuell noch mit Geldbetrag wie bei SA:MP - public void CmdFactionMedicHealive(Player player, string receiver, int price = 100) + public void CmdFactionMedicHealive(Player player, string receiver, int price = 10) { Player target = PlayerService.GetPlayerByNameOrId(receiver); if (player.GetUser()?.FactionId != 2) @@ -391,28 +391,9 @@ namespace ReallifeGamemode.Server.Commands return; } - using var dbContext = new DatabaseContext(); - User targetUser = target.GetUser(dbContext); - - if (targetUser.Handmoney >= price) - { - targetUser.Handmoney -= price; - } - else - { - int bankMoney = price - targetUser.Handmoney; - targetUser.Handmoney = 0; - targetUser.BankAccount.Balance -= bankMoney; - } - - dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Id == 2).First().BankAccount.Balance += price; - - dbContext.SaveChanges(); - - target.Health = 100; - target.SendNotification($"Du wurdest von ~g~{player.Name} ~s~ für ~g~{price.ToMoneyString()} geheilt.", false); - player.SendNotification($"Du hast ~g~{target.Name} ~s~ für {price.ToMoneyString()} geheilt.", false); - player.TriggerEvent("delHealTask"); + ChatService.SendMessage(target,"~g~" + player.GetUser().Name + " ~s~möchte dich für ~g~$" + price + " ~s~heilen. Drücke ~g~J~s~ zum Erlauben oder ~r~N ~s~zum Verbieten"); + target.SetData("healDecision", true); + Medic.HealDecisions.Add(new Medic.HealDecision {dMedic = player, dTarget = target, dPrice = price}); } #endregion Sanitäter Commands diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index 41e08be7..184dbb60 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using GTANetworkAPI; using Newtonsoft.Json; @@ -11,6 +12,7 @@ using ReallifeGamemode.Server.Factions.Medic; using ReallifeGamemode.Server.Finance; using ReallifeGamemode.Server.Inventory; using ReallifeGamemode.Server.Inventory.Interfaces; +using ReallifeGamemode.Server.Job; using ReallifeGamemode.Server.Managers; using ReallifeGamemode.Server.Services; using ReallifeGamemode.Server.Types; @@ -214,7 +216,7 @@ namespace ReallifeGamemode.Server.Events FriseurPoint nearestFriseurPoint = PositionManager.friseurPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5 && (!user.GetData("duty"))); ItemshopPoint nearestItemShopPoint = PositionManager.itemshopPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.5); JobPoint nearestJobPoint = PositionManager.JobPoints.Find(s => s.Position.DistanceTo(player.Position) <= 1.6); - + if (user?.FactionId != null) { BehindVehiclePoint nearestBehindVehiclePoint = MarkerBehinVehicle.behindVehiclePoints.Find(s => s.marker.Position.DistanceTo(player.Position) <= 3 && (user.FactionId == 8 || user.FactionId == 7 || user.FactionId == 1 || user.FactionId == 3)); @@ -624,6 +626,71 @@ namespace ReallifeGamemode.Server.Events InventoryManager.SetBackpackItems(player); } + [RemoteEvent("keyPress:J")] + public void KeyPressJ(Player player) + { + if (!player.IsLoggedIn()) return; + if (player.GetData("healDecision") == true) + { + player.SetData("healDecision", false); + Medic.MakeHealDecision(player, true); + } + + User u = player.GetUser(); + + if (u.JobId == null) return; + + JobBase job = JobManager.GetJob(u.JobId.Value); + + dynamic data = null; + + if (job.Id == 1 && job.GetUsersInJob().Contains(player)) + { + var taxiCalls = JobManager.GetJob().TaxiContracts; + if (!taxiCalls.Any(t => t.Driver?.Handle == player.Handle)) // Spieler in keiner aktiven Fahrt + { + data = new + { + job.Id, + Status = 0, + JobData = new + { + TaxiCalls = taxiCalls + .Where(t => t.Driver == null) + .Select(t => new + { + t.Name, + Distance = Math.Round(t.Position.DistanceTo(player.Position), 0) + }) + .OrderBy(t => t.Distance) + } + }; + } + else // Spieler in aktiver Fahrt + { + data = new + { + job.Id, + Status = 1, + JobData = new + { + taxiCalls.Where(t => t.Driver.Handle == player.Handle).First().Name + } + }; + } + } + //JobPoint nearJobPoint = PositionManager.JobPoints.Find(p => p.Position.DistanceTo(player.Position) <= 2); + if (u.JobId == 2 || u.JobId == 3 || u.JobId == 4) + { + return; + } + + var json = JsonConvert.SerializeObject(data); + + player.TriggerEvent("SERVER:Job_ShowJobMenu", job.Name, json); + } + + [RemoteEvent("keyPress:O")] public void KeyPressO(Player player) { @@ -715,6 +782,12 @@ namespace ReallifeGamemode.Server.Events if (!player.IsInVehicle) return; if (player.VehicleSeat != 0) return; + if (player.GetData("healDecision") == true) + { + player.SetData("healDecision", true); + Medic.MakeHealDecision(player, false); + } + GTANetworkAPI.Vehicle v = player.Vehicle; User u = player.GetUser(); diff --git a/ReallifeGamemode.Server/Factions/Medic/Medic.cs b/ReallifeGamemode.Server/Factions/Medic/Medic.cs index b5e03f2f..0621881a 100644 --- a/ReallifeGamemode.Server/Factions/Medic/Medic.cs +++ b/ReallifeGamemode.Server/Factions/Medic/Medic.cs @@ -8,6 +8,7 @@ using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Models; using Microsoft.EntityFrameworkCore; using System; +using ReallifeGamemode.Server.Extensions; /** * @overview Life of German Reallife - Server Factions Medic Medic.cs @@ -22,10 +23,18 @@ namespace ReallifeGamemode.Server.Factions.Medic public static List ReviveTasks = new List(); public static List HealTasks = new List(); public static List FireTasks = new List(); + public static List HealDecisions = new List(); public static int ReviveIncome = 100; public static int dutyMedics = 0; public static int reviveTaskTime = 240; + public class HealDecision + { + public Player dMedic; + public Player dTarget; + public int dPrice; + } + public static void AddTaskToList(MedicTask task) { if (task == null) @@ -72,6 +81,45 @@ namespace ReallifeGamemode.Server.Factions.Medic } } + public static void MakeHealDecision(Player target, bool decision) + { + var activeDecision = HealDecisions.FirstOrDefault(d => d.dTarget == target); + if(decision == false) + { + ChatService.SendMessage(activeDecision.dMedic, activeDecision.dTarget + " hat den Heal abgelehnt"); + return; + } + else + { + ChatService.SendMessage(activeDecision.dMedic, activeDecision.dTarget + " hat den Heal akzeptiert"); + using var dbContext = new DatabaseContext(); + { + User targetUser = target.GetUser(dbContext); + + if (targetUser.Handmoney >= activeDecision.dPrice) + { + targetUser.Handmoney -= activeDecision.dPrice; + } + else + { + int bankMoney = activeDecision.dPrice - targetUser.Handmoney; + targetUser.Handmoney = 0; + targetUser.BankAccount.Balance -= bankMoney; + } + + dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Id == 2).First().BankAccount.Balance += activeDecision.dPrice / 2; + activeDecision.dMedic.GetUser(dbContext).Wage += activeDecision.dPrice / 2; + + dbContext.SaveChanges(); + } + activeDecision.dTarget.Health = 100; + activeDecision.dTarget.SendNotification($"Du wurdest von ~g~{activeDecision.dMedic.Name} ~s~ für ~g~{activeDecision.dPrice.ToMoneyString()} geheilt", false); + activeDecision.dMedic.SendNotification($"Du hast ~g~{activeDecision.dTarget.Name} ~s~ für {activeDecision.dPrice.ToMoneyString()} geheilt", false); + delHealTask(activeDecision.dTarget); + } + HealDecisions.Remove(activeDecision); + } + public static void UpdateTaskTimeLeft() { DateTime actualTime = DateTime.Now; @@ -139,7 +187,7 @@ namespace ReallifeGamemode.Server.Factions.Medic public static void delHealTask(Player player) { MedicTask task = HealTasks.FirstOrDefault(t => t.Victim == player.Name); - RemoveTaskFromList(task); + if(task != null) RemoveTaskFromList(task); player.SetData("healauftrag", false); } diff --git a/ReallifeGamemode.Server/Managers/JobManager.cs b/ReallifeGamemode.Server/Managers/JobManager.cs index ee82abd5..0d910a14 100644 --- a/ReallifeGamemode.Server/Managers/JobManager.cs +++ b/ReallifeGamemode.Server/Managers/JobManager.cs @@ -124,63 +124,6 @@ namespace ReallifeGamemode.Server.Managers } } - [RemoteEvent("CLIENT:JobManager_ShowJobMenu")] - public void ShowJobMenuEvent(Player player) - { - User u = player.GetUser(); - - if (u.JobId == null) return; - - JobBase job = GetJob(u.JobId.Value); - - dynamic data = null; - - if (job.Id == 1 && job.GetUsersInJob().Contains(player)) - { - var taxiCalls = JobManager.GetJob().TaxiContracts; - if (!taxiCalls.Any(t => t.Driver?.Handle == player.Handle)) // Spieler in keiner aktiven Fahrt - { - data = new - { - job.Id, - Status = 0, - JobData = new - { - TaxiCalls = taxiCalls - .Where(t => t.Driver == null) - .Select(t => new - { - t.Name, - Distance = Math.Round(t.Position.DistanceTo(player.Position), 0) - }) - .OrderBy(t => t.Distance) - } - }; - } - else // Spieler in aktiver Fahrt - { - data = new - { - job.Id, - Status = 1, - JobData = new - { - taxiCalls.Where(t => t.Driver.Handle == player.Handle).First().Name - } - }; - } - } - //JobPoint nearJobPoint = PositionManager.JobPoints.Find(p => p.Position.DistanceTo(player.Position) <= 2); - if (u.JobId == 2 || u.JobId == 3 || u.JobId == 4) - { - return; - } - - var json = JsonConvert.SerializeObject(data); - - player.TriggerEvent("SERVER:Job_ShowJobMenu", job.Name, json); - } - [RemoteEvent("CLIENT:Job_StartJob")] public void StartJobEvent(Player player) {