Removed User.GetFaction()

This commit is contained in:
hydrant
2019-03-10 13:02:03 +01:00
parent f732f053a8
commit ed069fd1d7
8 changed files with 39 additions and 43 deletions

View File

@@ -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();

View File

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

View File

@@ -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.");

View File

@@ -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);
}
}
}

View File

@@ -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<CharacterCloth> clothes = context.CharacterClothes.ToList().FindAll(u => u.UserId == user.Id && u.Duty == true);
List<CharacterCloth> clothes = context.CharacterClothes.Where(u => u.UserId == user.Id && u.Duty == true).ToList();
foreach(var cloth in clothes)
{

View File

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

View File

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