diff --git a/ReallifeGamemode.Server/Commands/AdminCommands.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs index ae7e5180..1e46f6be 100644 --- a/ReallifeGamemode.Server/Commands/AdminCommands.cs +++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs @@ -3002,7 +3002,7 @@ namespace ReallifeGamemode.Server.Commands { if (target.IsLoggedIn()) { - Economy.SetPaycheck(target); + Economy.SetPaycheck(target, false); } } diff --git a/ReallifeGamemode.Server/Finance/Economy.cs b/ReallifeGamemode.Server/Finance/Economy.cs index 5b8f2b9f..500f609a 100644 --- a/ReallifeGamemode.Server/Finance/Economy.cs +++ b/ReallifeGamemode.Server/Finance/Economy.cs @@ -16,6 +16,7 @@ using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Database.Models; using ReallifeGamemode.Server.Services; using Newtonsoft.Json; +using ReallifeGamemode.Server.Wanted; namespace ReallifeGamemode.Server.Finance { @@ -70,7 +71,7 @@ namespace ReallifeGamemode.Server.Finance } - public static void SetPaycheck(Player client) + public static void SetPaycheck(Player client, bool minusJail = true) { User user = client.GetUser(); int wage = user.Wage; @@ -93,7 +94,7 @@ namespace ReallifeGamemode.Server.Finance Paycheck paycheck = new Paycheck(financialHelp, financialInterest, vehicleTaxation, propertyTax, wage, amount, rentalFees, healthInsurance, factionMoney); Paychecks[user.Id] = paycheck; - ReleasePayDay(client, paycheck); + ReleasePayDay(client, paycheck, minusJail); } private static int GetRentalFees(Player client) @@ -105,7 +106,7 @@ namespace ReallifeGamemode.Server.Finance } } - public static void ReleasePayDay(Player client, Paycheck paycheck) + public static void ReleasePayDay(Player client, Paycheck paycheck, bool minusJail) { NAPI.Util.ConsoleOutput("in release payday"); if (client == null || paycheck == null) @@ -113,49 +114,66 @@ namespace ReallifeGamemode.Server.Finance return; } - NAPI.Util.ConsoleOutput($"client = {client.Name}, paycheck = {JsonConvert.SerializeObject(paycheck)}"); + int putInJail = 0; - using (var dbContext = new DatabaseContext()) + using var dbContext = new DatabaseContext(); + + User u = client.GetUser(dbContext); + + UserBankAccount bankAccount = u.BankAccount; + + if (bankAccount.Balance < 0) { - User u = client.GetUser(dbContext); - NAPI.Util.ConsoleOutput("get user"); - u.BankAccount.Balance += paycheck.Amount; - u.Wage = 0; - - u.PaydayTimer = 60; - - - NAPI.Util.ConsoleOutput("set sachen"); - - var rentals = dbContext.HouseRentals - .Include(hR => hR.House) - .ThenInclude(h => h.BankAccount) - .Where(hR => hR.UserId == u.Id); - - - NAPI.Util.ConsoleOutput("get rentals"); - - dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Id == 2).First().BankAccount.Balance += (int)(paycheck.HealthInsurance * 0.1); - - if (rentals.Any()) + if (bankAccount.Balance >= -2500) { - NAPI.Util.ConsoleOutput("hat rentals"); - foreach (var rental in rentals) + putInJail = 5; + } + else + { + putInJail = 10; + } + } + + u.BankAccount.Balance += paycheck.Amount; + u.Wage = 0; + + u.PaydayTimer = 60; + + var rentals = dbContext.HouseRentals + .Include(hR => hR.House) + .ThenInclude(h => h.BankAccount) + .Where(hR => hR.UserId == u.Id); + + dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Id == 2).First().BankAccount.Balance += (int)(paycheck.HealthInsurance * 0.1); + + if (rentals.Any()) + { + foreach (var rental in rentals) + { + if (rental?.House?.BankAccount != null) { - if (rental?.House?.BankAccount != null) - { - rental.House.BankAccount.Balance += (int)(rental.House.RentalFee * 0.7); - } + rental.House.BankAccount.Balance += (int)(rental.House.RentalFee * 0.7); } } - - dbContext.SaveChanges(); } if (paycheck.Amount > 0) ChatService.SendMessage(client, "~g~[PAYDAY]~s~ Dein Stundenumsatz beträgt + $~g~" + paycheck.Amount + "~s~."); else ChatService.SendMessage(client, "~g~[PAYDAY]~s~ Dein Stundenumsatz beträgt - $~r~" + paycheck.Amount + "~s~."); + if (putInJail != 0 && minusJail) + { + u.JailTime = putInJail * 60; + ChatService.SendMessage(client, "Du hattest beim PayDay einen negativen Betrag auf deinem Bank-Konto, dafür wirst du eingesperrt."); + ChatService.SendMessage(client, "Achte darauf, nicht in einen negativen Geldbetrag zu besitzen."); + } + + dbContext.SaveChanges(); + + if(putInJail != 0 && minusJail) + { + Jail.Check_PutBehindBars(client, false); + } } public static void Timer_Elapsed() diff --git a/ReallifeGamemode.Server/Wanted/Jail.cs b/ReallifeGamemode.Server/Wanted/Jail.cs index 77dcba58..b96eb264 100644 --- a/ReallifeGamemode.Server/Wanted/Jail.cs +++ b/ReallifeGamemode.Server/Wanted/Jail.cs @@ -19,7 +19,7 @@ namespace ReallifeGamemode.Server.Wanted private static Dictionary Jailtime { get; set; } = new Dictionary(); //time in seconds - public static void Check_PutBehindBars(Player client) + public static void Check_PutBehindBars(Player client, bool announceHq = true) { User user = client.GetUser(); if (user.JailTime > 0) @@ -51,16 +51,16 @@ namespace ReallifeGamemode.Server.Wanted } if (user.Wanteds <= 0) return; - foreach (var copPlayer in NAPI.Pools.GetAllPlayers()) + using (var dbContext = new DatabaseContext()) { - if (!copPlayer.IsLoggedIn()) continue; - User cop = copPlayer.GetUser(); - if (cop?.FactionId == 1 || cop?.FactionId == 3) + foreach (var copPlayer in NAPI.Pools.GetAllPlayers()) { - int jailTime = user.Wanteds * 54; - if (cop.GetData("duty") && copPlayer.Position.DistanceTo2D(client.Position) <= 200 && (!copPlayer.HasData("isDead") || copPlayer.GetData("isDead") != true)) + if (!copPlayer.IsLoggedIn()) continue; + User cop = copPlayer.GetUser(); + if (cop?.FactionId == 1 || cop?.FactionId == 3) { - using (var dbContext = new DatabaseContext()) + int jailTime = user.Wanteds * 54; + if (cop.GetData("duty") && copPlayer.Position.DistanceTo2D(client.Position) <= 200 && (!copPlayer.HasData("isDead") || copPlayer.GetData("isDead") != true)) { if (!client.HasData("isDead") || client.GetData("isDead") == false) { @@ -71,61 +71,67 @@ namespace ReallifeGamemode.Server.Wanted Jailtime[user.Id] = jailTime; // 54 sec for each wanted star -> in total 45min for 50 Wanteds client.GetUser(dbContext).Wanteds = 0; - dbContext.SaveChanges(); - } - client.SetData("isDead", false); - client.RemoveAllWeapons(); - client.SetSharedData("blipColor", 0); - Random rnd = new Random(); - int rndInt = rnd.Next(1, 3); - if (rndInt == 1) - NAPI.Player.SpawnPlayer(client, new Vector3(458.9842, -997.2126, 24.91485)); //send client to jail - if (rndInt == 2) - NAPI.Player.SpawnPlayer(client, new Vector3(459.696, -994.3766, 24.91486)); //send client to jail - if (rndInt == 3) - NAPI.Player.SpawnPlayer(client, new Vector3(458.3372, -1001.258, 24.91485)); //send client to jail + client.SetData("isDead", false); + client.RemoveAllWeapons(); + client.SetSharedData("blipColor", 0); + Random rnd = new Random(); + int rndInt = rnd.Next(1, 3); + if (rndInt == 1) + NAPI.Player.SpawnPlayer(client, new Vector3(458.9842, -997.2126, 24.91485)); //send client to jail + if (rndInt == 2) + NAPI.Player.SpawnPlayer(client, new Vector3(459.696, -994.3766, 24.91486)); //send client to jail + if (rndInt == 3) + NAPI.Player.SpawnPlayer(client, new Vector3(458.3372, -1001.258, 24.91485)); //send client to jail - client.TriggerEvent("onPlayerRevived"); - MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == client.Name); - Medic.RemoveTaskFromList(task); - client.Health = 100; + client.TriggerEvent("onPlayerRevived"); + MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == client.Name); + Medic.RemoveTaskFromList(task); + client.Health = 100; - int timeMinutes = 0; + int timeMinutes = 0; - if (((int)(client.GetUser().JailTime / 60)) <= 1 && client.GetUser().JailTime != 0) - { - timeMinutes = 1; + if (((int)(client.GetUser().JailTime / 60)) <= 1 && client.GetUser().JailTime != 0) + { + timeMinutes = 1; + } + else + { + timeMinutes = (int)(client.GetUser().JailTime / 60); + } + + client.TriggerEvent("jailTime", JsonConvert.SerializeObject(timeMinutes)); + ChatService.SendMessage(client, "!{#FF614A}* Du bist nun im Gefängnis für " + timeMinutes + " Minute/n."); + + if (announceHq) + { + ChatService.BroadcastFaction("!{#8181E9}HQ: " + user.Name + " wurde ins Gefängnis geliefert.", new List() { 1, 3 }); + } + + switch (user.FactionId) + { + case null: + client.SetSharedData("blipColor", 0); + break; + case 8: + client.SetSharedData("blipColor", 83); + break; + case 7: + client.SetSharedData("blipColor", 52); + break; + case 4: + client.SetSharedData("blipColor", 5); + break; + + } } else { - timeMinutes = (int)(client.GetUser().JailTime / 60); + ChatService.BroadcastFaction("!{#8181E9}HQ: Der Verdächtigte " + user.Name + " wurde soeben ins Krankenhaus eingeliefert.", new System.Collections.Generic.List() { 1, 3 }); } - - client.TriggerEvent("jailTime", JsonConvert.SerializeObject(timeMinutes)); - ChatService.SendMessage(client, "!{#FF614A}* Du bist nun im Gefängnis für " + timeMinutes + " Minute/n."); - ChatService.BroadcastFaction("!{#8181E9}HQ: " + user.Name + " wurde ins Gefängnis geliefert.", new List() { 1, 3 }); - switch (user.FactionId) - { - case null: - client.SetSharedData("blipColor", 0); - break; - case 8: - client.SetSharedData("blipColor", 83); - break; - case 7: - client.SetSharedData("blipColor", 52); - break; - case 4: - client.SetSharedData("blipColor", 5); - break; - - } - } - else - { - ChatService.BroadcastFaction("!{#8181E9}HQ: Der Verdächtigte " + user.Name + " wurde soeben ins Krankenhaus eingeliefert.", new System.Collections.Generic.List() { 1, 3 }); } } + + dbContext.SaveChanges(); } }