/heal preis 10-100

This commit is contained in:
hydrant
2020-05-06 23:46:32 +02:00
parent 599b056409
commit 385c73f017

View File

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