diff --git a/ReallifeGamemode.Server/Commands/FactionCommands.cs b/ReallifeGamemode.Server/Commands/FactionCommands.cs index b89d4c87..780de9ec 100644 --- a/ReallifeGamemode.Server/Commands/FactionCommands.cs +++ b/ReallifeGamemode.Server/Commands/FactionCommands.cs @@ -1,4 +1,4 @@ -using GTANetworkAPI; +using GTANetworkAPI; using Microsoft.EntityFrameworkCore; using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Models; @@ -237,16 +237,21 @@ namespace ReallifeGamemode.Server.Commands Medic.RemoveTaskFromList(task); } - [Command("heal", "~m~Benutzung: ~s~/heal [Spieler]")] //TODO Eventuell noch mit Geldbetrag wie bei SA:MP - public void CmdFactionMedicHealive(Player player, string receiver) + [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) { Player target = PlayerService.GetPlayerByNameOrId(receiver); - if (player.GetUser()?.FactionId == null || player.GetUser().FactionId != 2) + if (player.GetUser()?.FactionId != 2) { ChatService.NotAuthorized(player); return; } + if (price < 10 || price > 100) + { + ChatService.ErrorMessage(player, "Der Preis muss zwischen 10$ und 100$ liegen"); + } + if (!player.IsDuty()) { ChatService.ErrorMessage(player, "Du bist nicht im Dienst"); @@ -263,9 +268,28 @@ namespace ReallifeGamemode.Server.Commands ChatService.ErrorMessage(player, "Du kannst dich nicht selbst heilen."); 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~geheilt.", false); - player.SendNotification("Du hast ~g~" + target.Name + " ~s~geheilt.", false); + 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); } #endregion #region Staatsfraktionen (LSPD / FBI) Commands