diff --git a/ReallifeGamemode.Client/index.js b/ReallifeGamemode.Client/index.js index c70fe2cf..5c241a5e 100644 --- a/ReallifeGamemode.Client/index.js +++ b/ReallifeGamemode.Client/index.js @@ -12,7 +12,7 @@ let globalData = { }; mp.game.gameplay.enableMpDlcMaps(true); -mp.game.vehicle.defaultEngineBehaviour = true; +mp.game.vehicle.defaultEngineBehaviour = false; //ALPHABETISCH SORTIERT UND ZUSAMMENGEFÜGT diff --git a/ReallifeGamemode.Server/Commands/Admin.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs similarity index 99% rename from ReallifeGamemode.Server/Commands/Admin.cs rename to ReallifeGamemode.Server/Commands/AdminCommands.cs index f965971e..2f83833f 100644 --- a/ReallifeGamemode.Server/Commands/Admin.cs +++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs @@ -23,7 +23,7 @@ using ReallifeGamemode.Server.Models; namespace ReallifeGamemode.Server.Commands { - public class Admin : Script + public class AdminCommands : Script { #region Test [Command("eat", "~m~Benutzung: ~s~/eat [Item]")] @@ -1550,7 +1550,7 @@ namespace ReallifeGamemode.Server.Commands case "fvehicle": if (player.IsInVehicle) { - if (player.GetUser().GetFaction() == null) + if (player.GetUser().Faction == null) { player.SendChatMessage("~m~Du bist in keiner Fraktion! Invite dich erst mit ~y~/ainvite"); return; @@ -2118,7 +2118,7 @@ namespace ReallifeGamemode.Server.Commands using(var dbContext = new DatabaseContext()) { - Entities.User owner = business.GetOwner(dbContext); + User owner = business.GetOwner(dbContext); if(owner == null) { player.SendChatMessage("~r~[FEHLER]~s~ Dieses Business hat momentan keinen Besitzer."); @@ -2128,7 +2128,7 @@ namespace ReallifeGamemode.Server.Commands owner.BusinessId = null; business.GetBankAccount(dbContext).Balance = 0; - owner.GetClient()?.SendChatMessage("~b~[ADMIN]~s~ Dir wurde von ~y~" + player.Name + "~s~ dein Business entzogen."); + owner.Client?.SendChatMessage("~b~[ADMIN]~s~ Dir wurde von ~y~" + player.Name + "~s~ dein Business entzogen."); player.SendChatMessage("~b~[ADMIN]~s~ Du hast ~y~" + owner.Name + "~s~ sein Business ~o~" + business.Name + "~s~ entzogen."); dbContext.SaveChanges(); diff --git a/ReallifeGamemode.Server/Commands/Faction.cs b/ReallifeGamemode.Server/Commands/FactionCommands.cs similarity index 96% rename from ReallifeGamemode.Server/Commands/Faction.cs rename to ReallifeGamemode.Server/Commands/FactionCommands.cs index ceba64ce..ccb71d45 100644 --- a/ReallifeGamemode.Server/Commands/Faction.cs +++ b/ReallifeGamemode.Server/Commands/FactionCommands.cs @@ -15,14 +15,14 @@ using System.Text.RegularExpressions; namespace ReallifeGamemode.Server.Commands { - class Faction : Script + class FactionCommands : Script { #region Chat Commands [Command("f", "~m~Benutzung: ~s~/f [Nachricht]", GreedyArg = true)] public void CmdFactionF(Client player, string message) { - Entities.Faction f = player.GetUser()?.GetFaction(); + Faction f = player.GetUser()?.Faction; if (f == null || f.StateOwned) { ChatService.NotAuthorized(player); @@ -38,7 +38,7 @@ namespace ReallifeGamemode.Server.Commands [Command("r", "~m~Benutzung: ~s~/r [Nachricht]", GreedyArg = true)] public void CmdFactionR(Client player, string message) { - Entities.Faction f = player.GetUser()?.GetFaction(); + Entities.Faction f = player.GetUser()?.Faction; if (f == null || !f.StateOwned) { ChatService.NotAuthorized(player); @@ -54,7 +54,7 @@ namespace ReallifeGamemode.Server.Commands [Command("d", "~m~Benutzung: ~s~/d [Nachricht]", GreedyArg = true)] public void CmdFactionD(Client player, string message) { - Entities.Faction f = player.GetUser()?.GetFaction(); + Faction f = player.GetUser()?.Faction; if (f == null || !f.StateOwned) { ChatService.NotAuthorized(player); @@ -97,7 +97,7 @@ namespace ReallifeGamemode.Server.Commands target.SetData("accept_invite", player.Handle); player.SendChatMessage("!{02FCFF}Du hast dem Spieler " + target.Name + " eine Einladung in deine Fraktion gesendet."); - target.SendChatMessage("!{02FCFF}Du hast von " + player.Name + " eine Einladung in die Fraktion \"" + player.GetUser().GetFaction().Name + "\" erhalten."); + target.SendChatMessage("!{02FCFF}Du hast von " + player.Name + " eine Einladung in die Fraktion \"" + player.GetUser().Faction.Name + "\" erhalten."); target.SendChatMessage("!{02FCFF}Benutze '/accept invite', um die Einladung anzunehmen"); return; @@ -201,7 +201,7 @@ namespace ReallifeGamemode.Server.Commands message = Regex.Replace(message, "(~[a-zA-Z]~{1})|(!{(.*)})", ""); - string broadcastMsg = "~y~[" + player.GetUser().GetFaction().Name + "] " + player.Name + ": " + message; + string broadcastMsg = "~y~[" + player.GetUser().Faction.Name + "] " + player.Name + ": " + message; NAPI.Pools.GetAllPlayers().ForEach(p => { diff --git a/ReallifeGamemode.Server/Commands/User.cs b/ReallifeGamemode.Server/Commands/UserCommands.cs similarity index 86% rename from ReallifeGamemode.Server/Commands/User.cs rename to ReallifeGamemode.Server/Commands/UserCommands.cs index ed486cf9..778e54a7 100644 --- a/ReallifeGamemode.Server/Commands/User.cs +++ b/ReallifeGamemode.Server/Commands/UserCommands.cs @@ -7,7 +7,7 @@ using System.Linq; namespace ReallifeGamemode.Server.Commands { - class User : Script + class UserCommands : Script { [Command("accept", "~m~Benutzung: ~s~/accept [invite]")] public void CmdUserAccept(Client player, string option) @@ -38,14 +38,16 @@ namespace ReallifeGamemode.Server.Commands return; } - Entities.User u = leader.GetUser(dbContext); - Entities.User own = player.GetUser(dbContext); + User u = leader.GetUser(dbContext); + User own = player.GetUser(dbContext); own.FactionId = u.FactionId; own.FactionLeader = false; - own.FactionRankId = dbContext.FactionRanks. - OrderBy(x => x.Order) - .FirstOrDefault(r => r.FactionId == own.FactionId)?.Id ?? null; + own.FactionRankId = dbContext + .FactionRanks + .OrderBy(x => x.Order) + .Where(r => r.FactionId == own.FactionId) + .FirstOrDefault()?.Id ?? null; leader.SendChatMessage("!{02FCFF}" + player.Name + " hat die Einladung angenommen."); player.SendChatMessage("!{02FCFF}Du hast die Einladung angenommen."); diff --git a/ReallifeGamemode.Server/Entities/User.cs b/ReallifeGamemode.Server/Entities/User.cs index 2d8081e4..5af59229 100644 --- a/ReallifeGamemode.Server/Entities/User.cs +++ b/ReallifeGamemode.Server/Entities/User.cs @@ -53,31 +53,21 @@ namespace ReallifeGamemode.Server.Entities public Faction Faction { get; set; } public bool FactionLeader { get; set; } - + public int? FactionRankId { get; set; } - public FactionRank FactionRank { get;set; } - - public int? BusinessId { get; set; } - - public Faction GetFaction() - { - using(var context = new DatabaseContext()) - { - return context.Factions.FirstOrDefault(f => f.Id == FactionId); - } - } + public FactionRank FactionRank { get; set; } public FactionRank GetFactionRank() { - using (var context = new DatabaseContext()) + using (var dbContext = new DatabaseContext()) { - FactionRank toReturn = context.FactionRanks.FirstOrDefault(fR => fR.Id == FactionRankId); - if(toReturn == null) + FactionRank toReturn = dbContext.FactionRanks.FirstOrDefault(fR => fR.Id == FactionRankId); + if (toReturn == null) { - toReturn = context.FactionRanks.OrderBy(f => f.Order).FirstOrDefault(f => f.FactionId == FactionId); + toReturn = dbContext.FactionRanks.OrderBy(f => f.Order).FirstOrDefault(f => f.FactionId == FactionId); } - if(toReturn == null) + if (toReturn == null) { toReturn = new FactionRank { @@ -89,6 +79,8 @@ namespace ReallifeGamemode.Server.Entities } } + public int? BusinessId { get; set; } + public void BanPlayer(Client admin, string reason, int mins) { using (var banUserContext = new DatabaseContext()) @@ -101,7 +93,7 @@ namespace ReallifeGamemode.Server.Entities NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " permanent gebannt. [" + reason + "]"); banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp }; - GetClient()?.Kick(); + this.Client?.Kick(); mins--; } @@ -109,7 +101,7 @@ namespace ReallifeGamemode.Server.Entities { NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " für " + mins + " Minuten gebannt. [" + reason + "]"); banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp + mins * 60 }; - GetClient()?.Kick(); + this.Client?.Kick(); } banUserContext.Bans.Add(banUser); @@ -138,6 +130,7 @@ namespace ReallifeGamemode.Server.Entities return dbContext.UserItems.ToList().FindAll(u => u.UserId == this.Id); } } + public bool IsAdmin(AdminLevel level) => AdminLevel >= level; public IBankAccount GetBankAccount(DatabaseContext databaseContext = null) @@ -155,9 +148,10 @@ namespace ReallifeGamemode.Server.Entities } } - public Client GetClient() + [NotMapped] + public Client Client { - return NAPI.Player.GetPlayerFromName(Name); + get => NAPI.Player.GetPlayerFromName(this.Name); } } } diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index e1b45eff..2582a0b4 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -87,7 +87,7 @@ namespace ReallifeGamemode.Server.Events { //LSFD case 2: - player.TriggerEvent("showFactionInteraction", user.FactionId, player.GetData("duty"), user.GetFaction().Name, user.FactionLeader, Medic.ReviveTasks.Count.ToString(), Medic.HealTasks.Count.ToString(), Medic.FireTasks.Count.ToString()); + player.TriggerEvent("showFactionInteraction", user.FactionId, player.GetData("duty"), user.Faction.Name, user.FactionLeader, Medic.ReviveTasks.Count.ToString(), Medic.HealTasks.Count.ToString(), Medic.FireTasks.Count.ToString()); break; } } @@ -115,7 +115,7 @@ namespace ReallifeGamemode.Server.Events int medicCount = 0; foreach(Client c in NAPI.Pools.GetAllPlayers()) { - if((c.GetUser()?.GetFaction().Id ?? 0) == 2) + if((c.GetUser()?.Faction.Id ?? 0) == 2) { medicCount++; } @@ -132,7 +132,7 @@ namespace ReallifeGamemode.Server.Events player.NametagColor = nameTagColor; using (var context = new DatabaseContext()) { - List clothes = context.CharacterClothes.ToList().FindAll(u => u.UserId == user.Id && u.Duty == true); + List clothes = context.CharacterClothes.Where(u => u.UserId == user.Id && u.Duty == true).ToList(); foreach(var cloth in clothes) { diff --git a/ReallifeGamemode.Server/Inventory/Items/FoodItem.cs b/ReallifeGamemode.Server/Inventory/Items/FoodItem.cs index 8c0b84e8..3ec801b6 100644 --- a/ReallifeGamemode.Server/Inventory/Items/FoodItem.cs +++ b/ReallifeGamemode.Server/Inventory/Items/FoodItem.cs @@ -21,7 +21,7 @@ namespace ReallifeGamemode.Server.Inventory.Items public void Use(UserItem uItem) { - Client player = uItem.GetUser().GetClient(); + Client player = uItem.GetUser().Client; int amountToAdd = HpAmount; if(player.Health + amountToAdd > 100) diff --git a/ReallifeGamemode.Server/Services/ChatService.cs b/ReallifeGamemode.Server/Services/ChatService.cs index 0eae8c39..08c852e0 100644 --- a/ReallifeGamemode.Server/Services/ChatService.cs +++ b/ReallifeGamemode.Server/Services/ChatService.cs @@ -42,7 +42,7 @@ namespace ReallifeGamemode.Server.Services { foreach (Client c in NAPI.Pools.GetAllPlayers()) { - Faction f = c.GetUser()?.GetFaction(); + Faction f = c.GetUser()?.Faction; if (f != null) { if (factions.Find(fT => fT.Id == f.Id) != null)