add house entity
This commit is contained in:
@@ -55,6 +55,8 @@ namespace ReallifeGamemode.Server.Entities
|
||||
public int? BanId { get; set; }
|
||||
public Ban Ban { get; set; }
|
||||
|
||||
public int? BusinessId { get; set; }
|
||||
|
||||
public int? FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
|
||||
@@ -67,6 +69,9 @@ namespace ReallifeGamemode.Server.Entities
|
||||
|
||||
public GroupRank GroupRank { get; set; }
|
||||
|
||||
public House House { get; set; }
|
||||
public int? HouseId { get; set; }
|
||||
|
||||
public int? JobId { get; set; }
|
||||
|
||||
public int Wanteds
|
||||
@@ -79,80 +84,6 @@ namespace ReallifeGamemode.Server.Entities
|
||||
}
|
||||
}
|
||||
|
||||
public FactionRank GetFactionRank()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
FactionRank toReturn = dbContext.FactionRanks.FirstOrDefault(fR => fR.Id == FactionRankId);
|
||||
if (toReturn == null)
|
||||
{
|
||||
toReturn = dbContext.FactionRanks.OrderBy(f => f.Order).FirstOrDefault(f => f.FactionId == FactionId);
|
||||
}
|
||||
|
||||
if (toReturn == null)
|
||||
{
|
||||
toReturn = new FactionRank
|
||||
{
|
||||
RankName = "Rang-Fehler"
|
||||
};
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
||||
public int? BusinessId { get; set; }
|
||||
|
||||
public void BanPlayer(Client admin, string reason, int mins)
|
||||
{
|
||||
using (var banUserContext = new DatabaseContext())
|
||||
{
|
||||
int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
Ban banUser;
|
||||
|
||||
if (mins == 0)
|
||||
{
|
||||
ChatService.Broadcast("!{#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 };
|
||||
|
||||
this.Client?.Kick();
|
||||
|
||||
mins--;
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatService.Broadcast("!{#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 };
|
||||
this.Client?.Kick();
|
||||
}
|
||||
|
||||
banUserContext.Bans.Add(banUser);
|
||||
banUserContext.SaveChanges();
|
||||
|
||||
var targetUser = banUserContext.Users.FirstOrDefault(u => u.Name == this.Name);
|
||||
targetUser.BanId = banUser.Id;
|
||||
banUserContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public void UnbanPlayer()
|
||||
{
|
||||
using (var unbanUser = new DatabaseContext())
|
||||
{
|
||||
var targetUser = unbanUser.Users.FirstOrDefault(u => u.Id == this.Id);
|
||||
targetUser.BanId = null;
|
||||
unbanUser.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public List<UserItem> GetItems()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.UserItems.ToList().FindAll(u => u.UserId == this.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
||||
|
||||
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||
@@ -176,34 +107,6 @@ namespace ReallifeGamemode.Server.Entities
|
||||
get => NAPI.Pools.GetAllPlayers().Where(c => c.Name.ToLower() == this.Name.ToLower()).FirstOrDefault();
|
||||
}
|
||||
|
||||
internal T GetData<T>(string key, T nullValue)
|
||||
{
|
||||
key += "data_";
|
||||
if (!Client.HasData(key)) return nullValue;
|
||||
return JsonConvert.DeserializeObject<T>(Client.GetData(key));
|
||||
}
|
||||
|
||||
internal T GetData<T>(string key) => GetData<T>(key, default);
|
||||
|
||||
internal void SetData(string key, object value)
|
||||
{
|
||||
key += "data_";
|
||||
Client.SetData(key, JsonConvert.SerializeObject(value));
|
||||
}
|
||||
|
||||
internal void GiveWanteds(Client cop, int amount, string reason)
|
||||
{
|
||||
if (this.Wanteds + amount > 40)
|
||||
{
|
||||
ChatService.ErrorMessage(cop, "Die Wanteds dürfen ein Limit von 40 nicht überschreiten");
|
||||
return;
|
||||
}
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User user = dbContext.Users.Where(u => u.Id == this.Id).FirstOrDefault();
|
||||
user.Wanteds += amount;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user