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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
140
ReallifeGamemode.Server.Core/Managers/InteriorManager.cs
Normal file
140
ReallifeGamemode.Server.Core/Managers/InteriorManager.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ReallifeGamemode.Server.Common;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.Managers
|
||||
{
|
||||
class InteriorManager : Script
|
||||
{
|
||||
public static Dictionary<int, ITextLabel> _interiorEnterTextLabels = new Dictionary<int, ITextLabel>();
|
||||
public static Dictionary<int, ITextLabel> _interiorExitTextLabels = new Dictionary<int, ITextLabel>();
|
||||
public static Dictionary<int, IMarker> _interiorEnterMarkers = new Dictionary<int, IMarker>();
|
||||
public static Dictionary<int, IMarker> _interiorExitMarkers = new Dictionary<int, IMarker>();
|
||||
public static Dictionary<int, IColShape> _interiorEnterColShapes = new Dictionary<int, IColShape>();
|
||||
public static Dictionary<int, IColShape> _interiorExitColShapes = new Dictionary<int, IColShape>();
|
||||
|
||||
public InteriorManager()
|
||||
{
|
||||
LoadInteriors();
|
||||
|
||||
EventHandler.RegisterClientEvent("InteriorManager_UseTeleport", InteriorManagerUseTeleportEvent);
|
||||
}
|
||||
|
||||
public Interior GetInteriorByName(string name, DatabaseContext dbContext)
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Name.ToLower() == name.ToLower()).FirstOrDefault();
|
||||
}
|
||||
|
||||
public Interior GetInteriorById(int id, DatabaseContext dbContext)
|
||||
{
|
||||
return dbContext.Interiors.Where(i => i.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public void LoadInteriors()
|
||||
{
|
||||
using var dbContext = GetDbContext();
|
||||
foreach (Interior interior in dbContext.Interiors)
|
||||
{
|
||||
LoadInterior(interior);
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadInterior(Interior interior)
|
||||
{
|
||||
if (interior.EnterPosition != null)
|
||||
{
|
||||
_interiorEnterTextLabels[interior.Id] = Api.TextLabel.CreateTextLabel("~y~" + interior.Name + "\n~s~Eingang", interior.EnterPosition, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
_interiorEnterMarkers[interior.Id] = Api.Marker.CreateMarker(MarkerType.VerticalCylinder, interior.EnterPosition.Subtract(new Position(0, 0, 1.7)), new Position(), new Position(), 1.6f, Color.White);
|
||||
_interiorEnterColShapes[interior.Id] = Api.ColShape.CreateSphere(interior.EnterPosition, 1.5f);
|
||||
|
||||
_interiorEnterColShapes[interior.Id].OnEntityEnter += InteriorManagerPlayerEnterColshapeEvent;
|
||||
_interiorEnterColShapes[interior.Id].OnEntityExit += InteriorManagerPlayerExitColshapeEvent;
|
||||
}
|
||||
|
||||
if (interior.ExitPosition != null)
|
||||
{
|
||||
_interiorExitTextLabels[interior.Id] = Api.TextLabel.CreateTextLabel("~y~" + interior.Name + "\n~s~Ausgang", interior.ExitPosition, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
_interiorExitMarkers[interior.Id] = Api.Marker.CreateMarker(MarkerType.VerticalCylinder, interior.ExitPosition.Subtract(new Position(0, 0, 1.7)), new Position(), new Position(), 1.6f, Color.White);
|
||||
_interiorExitColShapes[interior.Id] = Api.ColShape.CreateSphere(interior.ExitPosition, 1.5f);
|
||||
|
||||
_interiorExitColShapes[interior.Id].OnEntityEnter += InteriorManagerPlayerEnterColshapeEvent;
|
||||
_interiorExitColShapes[interior.Id].OnEntityExit += InteriorManagerPlayerExitColshapeEvent;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteInterior(Interior interior)
|
||||
{
|
||||
ITextLabel enT = GetInteriorEnterTextLabel(interior);
|
||||
ITextLabel exT = GetInteriorExitTextLabel(interior);
|
||||
IMarker enM = GetInteriorEnterMarker(interior);
|
||||
IMarker exM = GetInteriorExitMarkers(interior);
|
||||
IColShape enC = GetInteriorEnterColShape(interior);
|
||||
IColShape exC = GetInteriorExitColShape(interior);
|
||||
|
||||
if (enT != null) enT.Remove();
|
||||
if (exT != null) exT.Remove();
|
||||
if (enM != null) enM.Remove();
|
||||
if (exM != null) exM.Remove();
|
||||
if (enC != null) enC.Remove();
|
||||
if (exC != null) exC.Remove();
|
||||
|
||||
_interiorEnterTextLabels.Remove(interior.Id);
|
||||
_interiorExitTextLabels.Remove(interior.Id);
|
||||
_interiorEnterMarkers.Remove(interior.Id);
|
||||
_interiorExitMarkers.Remove(interior.Id);
|
||||
_interiorEnterColShapes.Remove(interior.Id);
|
||||
_interiorExitColShapes.Remove(interior.Id);
|
||||
}
|
||||
|
||||
public ITextLabel GetInteriorEnterTextLabel(Interior interior) => _interiorEnterTextLabels[interior.Id];
|
||||
public ITextLabel GetInteriorExitTextLabel(Interior interior) => _interiorExitTextLabels[interior.Id];
|
||||
|
||||
public IMarker GetInteriorEnterMarker(Interior interior) => _interiorEnterMarkers[interior.Id];
|
||||
public IMarker GetInteriorExitMarkers(Interior interior) => _interiorExitMarkers[interior.Id];
|
||||
|
||||
public IColShape GetInteriorEnterColShape(Interior interior) => _interiorEnterColShapes[interior.Id];
|
||||
public IColShape GetInteriorExitColShape(Interior interior) => _interiorExitColShapes[interior.Id];
|
||||
|
||||
public int GetInteriorIdFromEnterColShape(IColShape handle) => _interiorEnterColShapes.FirstOrDefault(c => c.Value == handle).Key;
|
||||
public int GetInteriorIdFromExitColShape(IColShape handle) => _interiorExitColShapes.FirstOrDefault(c => c.Value == handle).Key;
|
||||
|
||||
public void InteriorManagerPlayerEnterColshapeEvent(IColShape colShape, IPlayer player)
|
||||
{
|
||||
using var dbContext = GetDbContext();
|
||||
|
||||
int enterId = GetInteriorIdFromEnterColShape(colShape);
|
||||
int exitId = GetInteriorIdFromExitColShape(colShape);
|
||||
if (enterId != 0)
|
||||
{
|
||||
Interior interior = GetInteriorById(enterId, dbContext);
|
||||
player.TriggerEvent("InteriorManager_ShowHelpText", interior.Name, interior.Id, 0);
|
||||
}
|
||||
else if (exitId != 0)
|
||||
{
|
||||
Interior interior = GetInteriorById(exitId, dbContext);
|
||||
player.TriggerEvent("InteriorManager_ShowHelpText", interior.Name, interior.Id, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void InteriorManagerPlayerExitColshapeEvent(IColShape colShape, IPlayer player)
|
||||
{
|
||||
if (GetInteriorIdFromEnterColShape(colShape) != 0 || GetInteriorIdFromExitColShape(colShape) != 0)
|
||||
{
|
||||
player.TriggerEvent("InteriorManager_ClearHelpText");
|
||||
}
|
||||
}
|
||||
|
||||
public void InteriorManagerUseTeleportEvent(IPlayer player, params object[] args)
|
||||
{
|
||||
var id = args[0].ToInt();
|
||||
var enterExit = args[1].ToInt();
|
||||
|
||||
Interior interior = GetInteriorById(id, GetDbContext());
|
||||
player.Position = enterExit == 0 ? interior.ExitPosition : interior.EnterPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user