miete alle 7 tage nachricht angepasst
improvements in db und haussystem
This commit is contained in:
@@ -113,33 +113,35 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
|
||||
public House GetHouseById(int id, DatabaseContext dbContext)
|
||||
{
|
||||
return dbContext.Houses.Where(h => h.Id == id).Include(h => h.Owner).FirstOrDefault();
|
||||
return dbContext.Houses.Where(h => h.Id == id)
|
||||
.Include(h => h.Owner)
|
||||
.Include(h => h.Rentals)
|
||||
.ThenInclude(hR => hR.User)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
private void SendPlayerHouseData(IPlayer player, House house)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
using var dbContext = GetDbContext();
|
||||
User user = player.GetUser(dbContext);
|
||||
var userHouseStatus = -1;
|
||||
|
||||
if (house.OwnerId == null) userHouseStatus = 0;
|
||||
else if (house.OwnerId == user?.Id) userHouseStatus = 1;
|
||||
else if (house.Rentals.Where(h => h.UserId == user.Id).Any()) userHouseStatus = 2;
|
||||
|
||||
var rentals = house.Rentals;
|
||||
|
||||
var newHouse = new
|
||||
{
|
||||
User user = player.GetUser(dbContext);
|
||||
var userHouseStatus = -1;
|
||||
OwnerName = house.Owner?.Name,
|
||||
house.RentalFee,
|
||||
house.Price,
|
||||
house.Type,
|
||||
Rentals = rentals.Select(r => r.User.Name)
|
||||
};
|
||||
|
||||
if (house.OwnerId == null) userHouseStatus = 0;
|
||||
else if (house.OwnerId == user?.Id) userHouseStatus = 1;
|
||||
else if (dbContext.HouseRentals.Where(h => h.HouseId == house.Id && h.UserId == user.Id).Count() == 1) userHouseStatus = 2;
|
||||
|
||||
var rentals = dbContext.HouseRentals.Where(h => h.HouseId == house.Id).Include(h => h.User).Select(h => h.User.Name).ToList();
|
||||
|
||||
var newHouse = new
|
||||
{
|
||||
OwnerName = house.Owner?.Name,
|
||||
house.RentalFee,
|
||||
house.Price,
|
||||
house.Type,
|
||||
Rentals = rentals
|
||||
};
|
||||
|
||||
player.TriggerEvent("SetHouseData", newHouse.SerializeJson(), userHouseStatus);
|
||||
}
|
||||
player.TriggerEvent("SetHouseData", newHouse.SerializeJson(), userHouseStatus);
|
||||
}
|
||||
|
||||
public void RemoveHouse(House house)
|
||||
@@ -181,19 +183,17 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
|
||||
public void ReloadAllHouses()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
using var dbContext = GetDbContext();
|
||||
foreach (House house in dbContext.Houses.Include(h => h.Owner).ToList())
|
||||
{
|
||||
foreach (House house in dbContext.Houses.Include(h => h.Owner).ToList())
|
||||
{
|
||||
RemoveHouse(house);
|
||||
LoadHouse(house);
|
||||
}
|
||||
RemoveHouse(house);
|
||||
LoadHouse(house);
|
||||
}
|
||||
}
|
||||
|
||||
private void HouseManagerBuyHouseEvent(IPlayer player, params object[] args)
|
||||
{
|
||||
using var dbContext = new DatabaseContext();
|
||||
using var dbContext = GetDbContext();
|
||||
User user = player.GetUser(dbContext, bankAccount: true);
|
||||
|
||||
if (user.HouseId != null)
|
||||
@@ -243,8 +243,8 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
DateTime newPossibility = house.LastRentSetTime.AddDays(7);
|
||||
string dateStr = newPossibility.ToLongDateString();
|
||||
string timeStr = newPossibility.ToShortTimeString();
|
||||
player.SendNotification(
|
||||
$"~r~Die Miete wurde in den letzten 7 Tagen schon verändert. Die nächste Änderung kann am {dateStr} um {timeStr} Uhr geändert werden.");
|
||||
player.SendMessage(
|
||||
$"Die Miete wurde in den letzten 7 Tagen schon verändert. Die Miete kann am ~y~{dateStr} um {timeStr}~s~ Uhr wieder geändert werden.", ChatPrefix.Info);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
private void HouseManagerCancelUserRentalEvent(IPlayer player, params object[] args)
|
||||
{
|
||||
string userName = args[0] as string;
|
||||
using var dbContext = new DatabaseContext();
|
||||
using var dbContext = GetDbContext();
|
||||
User user = player.GetUser(dbContext);
|
||||
if (user.HouseId == null)
|
||||
{
|
||||
@@ -291,14 +291,14 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
|
||||
House house = GetHouseById(user.HouseId.Value, dbContext);
|
||||
|
||||
HouseRental rental = dbContext.HouseRentals.Where(h => h.HouseId == house.Id && h.UserId == target.Id).FirstOrDefault();
|
||||
HouseRental rental = house.Rentals.Where(h => h.UserId == target.Id).FirstOrDefault();
|
||||
if (rental == null)
|
||||
{
|
||||
player.SendNotification("~r~Der Spieler ist nicht in deinem Haus eingemietet");
|
||||
return;
|
||||
}
|
||||
|
||||
dbContext.HouseRentals.Remove(rental);
|
||||
house.Rentals.Remove(rental);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
target.NewPlayer?.SendNotification($"~y~{player.Name}~s~ hat deinen Mietvertrag ~g~gekündigt~s~.");
|
||||
@@ -309,7 +309,7 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
|
||||
private void HouseManagerRentInHouseEvent(IPlayer player, params object[] args)
|
||||
{
|
||||
using var dbContext = new DatabaseContext();
|
||||
using var dbContext = GetDbContext();
|
||||
User user = player.GetUser(dbContext);
|
||||
House house = GetNearHouse(player.Position, dbContext);
|
||||
|
||||
@@ -331,7 +331,7 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
UserId = user.Id
|
||||
};
|
||||
|
||||
dbContext.HouseRentals.Add(newRental);
|
||||
house.Rentals.Add(newRental);
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
@@ -353,7 +353,7 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
return;
|
||||
}
|
||||
|
||||
HouseRental rental = dbContext.HouseRentals.Where(h => h.HouseId == house.Id && h.UserId == user.Id).FirstOrDefault();
|
||||
HouseRental rental = house.Rentals.Where(h => h.UserId == user.Id).FirstOrDefault();
|
||||
|
||||
if (rental == null)
|
||||
{
|
||||
@@ -361,7 +361,7 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
return;
|
||||
}
|
||||
|
||||
dbContext.HouseRentals.Remove(rental);
|
||||
house.Rentals.Remove(rental);
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user