add house reload command

This commit is contained in:
hydrant
2019-06-27 19:33:05 +02:00
parent f2b1788939
commit c63c516757
3 changed files with 55 additions and 8 deletions

View File

@@ -2432,7 +2432,7 @@ namespace ReallifeGamemode.Server.Commands
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Die Türen wurden erfolgreich neugeladen."); ChatService.SendMessage(player, "~b~[ADMIN]~s~ Die Türen wurden erfolgreich neugeladen.");
} }
[Command("house", "~m~Benutzung: ~s~/house [add / remove / price / type]", GreedyArg = true)] [Command("house", "~m~Benutzung: ~s~/house [add / remove / price / type / reloadhouses]", GreedyArg = true)]
public void CmdAdminHouse(Client player, string option1, string option2 = null) public void CmdAdminHouse(Client player, string option1, string option2 = null)
{ {
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true) if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
@@ -2550,8 +2550,13 @@ namespace ReallifeGamemode.Server.Commands
return; return;
} }
else if(option1 == "reloadhouses")
{
HouseManager.ReloadAllHouses();
player.SendNotification("Alle Häuser wurden neu geladen");
}
player.SendChatMessage("~m~Benutzung: ~s~/house [add / remove / price / type]"); player.SendChatMessage("~m~Benutzung: ~s~/house [add / remove / price / type / reloadhouses]");
} }
#endregion #endregion

View File

@@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore;
using ReallifeGamemode.Server.Entities;
using ReallifeGamemode.Server.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ReallifeGamemode.Server.Extensions
{
static class HouseExtensions
{
public static House Refresh(this House house)
{
using(var dbContext = new DatabaseContext())
{
return dbContext.Houses.Where(h => h.Id == house.Id).Include(h => h.User).FirstOrDefault();
}
}
}
}

View File

@@ -14,6 +14,7 @@ namespace ReallifeGamemode.Server.Managers
{ {
private static readonly Dictionary<int, NetHandle> houseMarkers = new Dictionary<int, NetHandle>(); 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> houseLabels = new Dictionary<int, NetHandle>();
private static readonly Dictionary<int, NetHandle> houseColShapes = new Dictionary<int, NetHandle>();
public static void LoadHouses() public static void LoadHouses()
{ {
@@ -21,7 +22,19 @@ namespace ReallifeGamemode.Server.Managers
{ {
foreach (House house in dbContext.Houses.Include(h => h.User)) foreach (House house in dbContext.Houses.Include(h => h.User))
{ {
LoadHouse(house); LoadHouse(house, false);
}
}
}
public async static void ReloadAllHouses()
{
using (var dbContext = new DatabaseContext())
{
foreach(House house in await dbContext.Houses.Include(h => h.User).ToListAsync())
{
RemoveHouse(house);
LoadHouse(house, false);
} }
} }
} }
@@ -61,8 +74,10 @@ namespace ReallifeGamemode.Server.Managers
} }
} }
public static void LoadHouse(House 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)); 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()}"; string text = $"~g~Zum Verkauf\n~s~{house.Type}\nPreis: ~y~{house.Price.ToMoneyString()}";
if(house.User != null) if(house.User != null)
@@ -73,12 +88,18 @@ namespace ReallifeGamemode.Server.Managers
} }
public static void RemoveHouse(House house) public static void RemoveHouse(House house)
{
if (houseMarkers.ContainsKey(house.Id))
{ {
houseMarkers[house.Id].Entity<Marker>().Delete(); houseMarkers[house.Id].Entity<Marker>().Delete();
houseLabels[house.Id].Entity<TextLabel>().Delete();
houseMarkers.Remove(house.Id); houseMarkers.Remove(house.Id);
}
if(houseLabels.ContainsKey(house.Id))
{
houseLabels[house.Id].Entity<TextLabel>().Delete();
houseLabels.Remove(house.Id); houseLabels.Remove(house.Id);
} }
} }
} }
}