added editorconfig and formatted code
This commit is contained in:
@@ -10,96 +10,96 @@ using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Managers
|
||||
{
|
||||
class HouseManager
|
||||
class HouseManager
|
||||
{
|
||||
private static readonly Dictionary<int, NetHandle> houseMarkers = new Dictionary<int, NetHandle>();
|
||||
private static readonly Dictionary<int, NetHandle> houseLabels = new Dictionary<int, NetHandle>();
|
||||
private static readonly Dictionary<int, NetHandle> houseColShapes = new Dictionary<int, NetHandle>();
|
||||
|
||||
public static void LoadHouses()
|
||||
{
|
||||
private static readonly Dictionary<int, NetHandle> houseMarkers = new Dictionary<int, NetHandle>();
|
||||
private static readonly Dictionary<int, NetHandle> houseLabels = new Dictionary<int, NetHandle>();
|
||||
private static readonly Dictionary<int, NetHandle> houseColShapes = new Dictionary<int, NetHandle>();
|
||||
|
||||
public static void LoadHouses()
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach (House house in dbContext.Houses.Include(h => h.Owner))
|
||||
{
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach (House house in dbContext.Houses.Include(h => h.Owner))
|
||||
{
|
||||
LoadHouse(house, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async static void ReloadAllHouses()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach(House house in await dbContext.Houses.Include(h => h.Owner).ToListAsync())
|
||||
{
|
||||
RemoveHouse(house);
|
||||
LoadHouse(house, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static House GetNearHouse(Vector3 position, DatabaseContext dbContext = null)
|
||||
{
|
||||
if(dbContext == null)
|
||||
{
|
||||
using (dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Houses.Where(h => h.Position.DistanceTo(position) <= 5f).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return dbContext.Houses.Where(h => h.Position.DistanceTo(position) <= 5f).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddHouse(string type, int price, Vector3 position)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
var house = new House()
|
||||
{
|
||||
Price = price,
|
||||
Type = type,
|
||||
X = position.X,
|
||||
Y = position.Y,
|
||||
Z = position.Z
|
||||
};
|
||||
|
||||
dbContext.Houses.Add(house);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
LoadHouse(house);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadHouse(House house, bool loadUser = true)
|
||||
{
|
||||
if (loadUser) house = house.Refresh();
|
||||
|
||||
houseMarkers[house.Id] = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, house.Position.Subtract(new Vector3(0, 0, 1.7)), new Vector3(), new Vector3(), 1.6f, new Color(255, 255, 255));
|
||||
string text = $"~g~Zum Verkauf\n~s~{house.Type}\nPreis: ~y~{house.Price.ToMoneyString()}";
|
||||
if(house.User != null)
|
||||
{
|
||||
text = $"{house.Type}\n~s~Besitzer: ~y~{house.User.Name}";
|
||||
}
|
||||
houseLabels[house.Id] = NAPI.TextLabel.CreateTextLabel(text, house.Position, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
}
|
||||
|
||||
public static void RemoveHouse(House house)
|
||||
{
|
||||
if (houseMarkers.ContainsKey(house.Id))
|
||||
{
|
||||
houseMarkers[house.Id].Entity<Marker>().Delete();
|
||||
houseMarkers.Remove(house.Id);
|
||||
}
|
||||
|
||||
if(houseLabels.ContainsKey(house.Id))
|
||||
{
|
||||
houseLabels[house.Id].Entity<TextLabel>().Delete();
|
||||
houseLabels.Remove(house.Id);
|
||||
}
|
||||
LoadHouse(house, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async static void ReloadAllHouses()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach (House house in await dbContext.Houses.Include(h => h.Owner).ToListAsync())
|
||||
{
|
||||
RemoveHouse(house);
|
||||
LoadHouse(house, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static House GetNearHouse(Vector3 position, DatabaseContext dbContext = null)
|
||||
{
|
||||
if (dbContext == null)
|
||||
{
|
||||
using (dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Houses.Where(h => h.Position.DistanceTo(position) <= 5f).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return dbContext.Houses.Where(h => h.Position.DistanceTo(position) <= 5f).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddHouse(string type, int price, Vector3 position)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
var house = new House()
|
||||
{
|
||||
Price = price,
|
||||
Type = type,
|
||||
X = position.X,
|
||||
Y = position.Y,
|
||||
Z = position.Z
|
||||
};
|
||||
|
||||
dbContext.Houses.Add(house);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
LoadHouse(house);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadHouse(House house, bool loadUser = true)
|
||||
{
|
||||
if (loadUser) house = house.Refresh();
|
||||
|
||||
houseMarkers[house.Id] = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, house.Position.Subtract(new Vector3(0, 0, 1.7)), new Vector3(), new Vector3(), 1.6f, new Color(255, 255, 255));
|
||||
string text = $"~g~Zum Verkauf\n~s~{house.Type}\nPreis: ~y~{house.Price.ToMoneyString()}";
|
||||
if (house.User != null)
|
||||
{
|
||||
text = $"{house.Type}\n~s~Besitzer: ~y~{house.User.Name}";
|
||||
}
|
||||
houseLabels[house.Id] = NAPI.TextLabel.CreateTextLabel(text, house.Position, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
}
|
||||
|
||||
public static void RemoveHouse(House house)
|
||||
{
|
||||
if (houseMarkers.ContainsKey(house.Id))
|
||||
{
|
||||
houseMarkers[house.Id].Entity<Marker>().Delete();
|
||||
houseMarkers.Remove(house.Id);
|
||||
}
|
||||
|
||||
if (houseLabels.ContainsKey(house.Id))
|
||||
{
|
||||
houseLabels[house.Id].Entity<TextLabel>().Delete();
|
||||
houseLabels.Remove(house.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user