backdoor
haus-konto geld abheben (30% steuern) alten hausmanager entfernt interiormanager in core verschoben
This commit is contained in:
@@ -30,6 +30,7 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
EventHandler.RegisterClientEvent("House_RentInHouse", HouseManagerRentInHouseEvent);
|
||||
EventHandler.RegisterClientEvent("House_CancelOwnRental", HouseManagerCancelOwnRentalEvent);
|
||||
EventHandler.RegisterClientEvent("House_SellHouse", HouseManagerSellHouseEvent);
|
||||
EventHandler.RegisterClientEvent("House_WithdrawMoney", HouseManagerWithdrawMoneyEvent);
|
||||
|
||||
LoadHouses();
|
||||
}
|
||||
@@ -37,11 +38,12 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
private void LoadHouses()
|
||||
{
|
||||
using var dbContext = GetDbContext();
|
||||
var houses = dbContext.Houses.Include(h => h.Owner);
|
||||
var houses = dbContext.Houses.Include(h => h.Owner).Include(h => h.BankAccount);
|
||||
foreach (House house in houses)
|
||||
{
|
||||
LoadHouse(house);
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
public void LoadHouse(House house)
|
||||
@@ -69,13 +71,18 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
|
||||
houseLabels[house.Id] = Api.TextLabel.CreateTextLabel(text, housePos, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
|
||||
if (house.Price != 0)
|
||||
if (house.Price != 0 || house.RentalFee != 0)
|
||||
{
|
||||
houseColShapes[house.Id] = Api.ColShape.CreateCyclinder(housePos.Subtract(new Position(0, 0, 2)), 4.0f, 2f);
|
||||
|
||||
houseColShapes[house.Id].OnEntityEnter += HouseManager_OnEntityEnterColShape;
|
||||
houseColShapes[house.Id].OnEntityExit += HouseManager_OnEntityExitColShape;
|
||||
}
|
||||
|
||||
if (house.BankAccount == null)
|
||||
{
|
||||
house.BankAccount = new HouseBankAccount();
|
||||
}
|
||||
}
|
||||
|
||||
private void HouseManager_OnEntityExitColShape(IColShape colShape, IPlayer client)
|
||||
@@ -117,6 +124,7 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
.Include(h => h.Owner)
|
||||
.Include(h => h.Rentals)
|
||||
.ThenInclude(hR => hR.User)
|
||||
.Include(h => h.BankAccount)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -138,7 +146,8 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
house.RentalFee,
|
||||
house.Price,
|
||||
house.Type,
|
||||
Rentals = rentals.Select(r => r.User.Name)
|
||||
Rentals = rentals.Select(r => r.User.Name),
|
||||
house.BankAccount.Balance
|
||||
};
|
||||
|
||||
player.TriggerEvent("SetHouseData", newHouse.SerializeJson(), userHouseStatus);
|
||||
@@ -178,13 +187,18 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
|
||||
public House GetNearHouse(Position position, DatabaseContext dbContext)
|
||||
{
|
||||
return dbContext.Houses.Where(h => h.Position.DistanceTo(position) <= 5f).Include(h => h.Owner).OrderBy(h => h.Position.DistanceTo(position)).FirstOrDefault();
|
||||
return dbContext.Houses.Where(h => h.Position.DistanceTo(position) <= 5f)
|
||||
.Include(h => h.Owner)
|
||||
.Include(h => h.BankAccount)
|
||||
.Include(h => h.Rentals)
|
||||
.OrderBy(h => h.Position.DistanceTo(position))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public void ReloadAllHouses()
|
||||
{
|
||||
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).Include(h => h.BankAccount))
|
||||
{
|
||||
RemoveHouse(house);
|
||||
LoadHouse(house);
|
||||
@@ -377,7 +391,7 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
private void HouseManagerSellHouseEvent(IPlayer player, params object[] args)
|
||||
{
|
||||
using var dbContext = GetDbContext();
|
||||
User user = player.GetUser(dbContext);
|
||||
User user = player.GetUser(dbContext, bankAccount: true);
|
||||
if (user.HouseId == null)
|
||||
{
|
||||
player.SendMessage("Du besitzt kein Haus", ChatPrefix.Error);
|
||||
@@ -403,5 +417,41 @@ namespace ReallifeGamemode.Server.Core.Managers
|
||||
|
||||
SendPlayerHouseData(player, house);
|
||||
}
|
||||
|
||||
private void HouseManagerWithdrawMoneyEvent(IPlayer player, object[] args)
|
||||
{
|
||||
var amount = args[0].ToInt();
|
||||
|
||||
if (amount <= 0)
|
||||
{
|
||||
player.SendMessage("Du musst mindestens 1$ abheben", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
using var dbContext = GetDbContext();
|
||||
User user = player.GetUser(dbContext, bankAccount: true);
|
||||
if (user.HouseId == null)
|
||||
{
|
||||
player.SendMessage("Du besitzt kein Haus", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
House house = GetHouseById(user.HouseId.Value, dbContext);
|
||||
|
||||
if (house.BankAccount.Balance < amount)
|
||||
{
|
||||
player.SendMessage("Auf dem Konto deines Hauses ist nicht genug Geld", ChatPrefix.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
user.BankAccount.Balance += amount;
|
||||
house.BankAccount.Balance -= amount;
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.SendMessage($"Du hast {amount.ToMoneyString()} von dem Konto deines Hauses abgehoben", ChatPrefix.Info);
|
||||
|
||||
SendPlayerHouseData(player, house);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user