add house commands
This commit is contained in:
@@ -858,12 +858,12 @@ namespace ReallifeGamemode.Server.Commands
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
using(var dbContext = new DatabaseContext())
|
using (var dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
User user = target.GetUser(dbContext);
|
User user = target.GetUser(dbContext);
|
||||||
bool duty = user.GetData<bool>("duty");
|
bool duty = user.GetData<bool>("duty");
|
||||||
CharacterCloth cloth = dbContext.CharacterClothes.Where(c => c.UserId == user.Id && c.SlotId == component && c.SlotType == 0 && c.Duty == duty).FirstOrDefault();
|
CharacterCloth cloth = dbContext.CharacterClothes.Where(c => c.UserId == user.Id && c.SlotId == component && c.SlotType == 0 && c.Duty == duty).FirstOrDefault();
|
||||||
if(cloth == null)
|
if (cloth == null)
|
||||||
{
|
{
|
||||||
cloth = new CharacterCloth()
|
cloth = new CharacterCloth()
|
||||||
{
|
{
|
||||||
@@ -902,7 +902,7 @@ namespace ReallifeGamemode.Server.Commands
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(component == -1)
|
if (component == -1)
|
||||||
{
|
{
|
||||||
target.ClearAccessory(slot);
|
target.ClearAccessory(slot);
|
||||||
return;
|
return;
|
||||||
@@ -1083,7 +1083,7 @@ namespace ReallifeGamemode.Server.Commands
|
|||||||
uHash = NAPI.Util.GetHashKey($"weapon_{hash}");
|
uHash = NAPI.Util.GetHashKey($"weapon_{hash}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!WeaponManager.IsValidHash(uHash))
|
if (!WeaponManager.IsValidHash(uHash))
|
||||||
{
|
{
|
||||||
ChatService.ErrorMessage(player, "Diese Waffe existiert nicht");
|
ChatService.ErrorMessage(player, "Diese Waffe existiert nicht");
|
||||||
return;
|
return;
|
||||||
@@ -1704,7 +1704,7 @@ namespace ReallifeGamemode.Server.Commands
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!int.TryParse(option1, out int jobId))
|
if (!int.TryParse(option1, out int jobId))
|
||||||
{
|
{
|
||||||
ChatService.ErrorMessage(player, "Du musst eine gültige Zahl als JobID angeben");
|
ChatService.ErrorMessage(player, "Du musst eine gültige Zahl als JobID angeben");
|
||||||
return;
|
return;
|
||||||
@@ -2431,6 +2431,128 @@ namespace ReallifeGamemode.Server.Commands
|
|||||||
DoorManager.ReloadDoors();
|
DoorManager.ReloadDoors();
|
||||||
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)]
|
||||||
|
public void CmdAdminHouse(Client player, string option1, string option2 = null)
|
||||||
|
{
|
||||||
|
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
|
||||||
|
{
|
||||||
|
ChatService.NotAuthorized(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
option1 = option1.ToLower();
|
||||||
|
|
||||||
|
if (option1 == "add")
|
||||||
|
{
|
||||||
|
House nearHouse = HouseManager.GetNearHouse(player.Position);
|
||||||
|
if (nearHouse != null)
|
||||||
|
{
|
||||||
|
ChatService.ErrorMessage(player, "In der Nähe ist schon ein Haus");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
House house = new House()
|
||||||
|
{
|
||||||
|
Price = 0,
|
||||||
|
Type = "Haus",
|
||||||
|
X = player.Position.X,
|
||||||
|
Y = player.Position.Y,
|
||||||
|
Z = player.Position.Z
|
||||||
|
};
|
||||||
|
|
||||||
|
dbContext.Houses.Add(house);
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
|
HouseManager.LoadHouse(house);
|
||||||
|
|
||||||
|
player.SendNotification("Das Haus wurde erstellt");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (option1 == "remove")
|
||||||
|
{
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
House nearHouse = HouseManager.GetNearHouse(player.Position, dbContext);
|
||||||
|
if (nearHouse == null)
|
||||||
|
{
|
||||||
|
ChatService.ErrorMessage(player, "In deiner Nähe befindet sich kein Haus");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbContext.Houses.Remove(nearHouse);
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
|
HouseManager.RemoveHouse(nearHouse);
|
||||||
|
|
||||||
|
player.SendNotification("Das Haus wurde gelöscht");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (option1 == "price")
|
||||||
|
{
|
||||||
|
if (!int.TryParse(option2, out int price))
|
||||||
|
{
|
||||||
|
ChatService.ErrorMessage(player, "~m~Benutzung: ~s~/house price [Price]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
House nearHouse = HouseManager.GetNearHouse(player.Position, dbContext);
|
||||||
|
if (nearHouse == null)
|
||||||
|
{
|
||||||
|
ChatService.ErrorMessage(player, "In deiner Nähe befindet sich kein Haus");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nearHouse.Price = price;
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
|
HouseManager.RemoveHouse(nearHouse);
|
||||||
|
HouseManager.LoadHouse(nearHouse);
|
||||||
|
|
||||||
|
player.SendNotification("Der Hauspreis wurde gesetzt");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (option1 == "type")
|
||||||
|
{
|
||||||
|
if(option2 == null)
|
||||||
|
{
|
||||||
|
ChatService.ErrorMessage(player, "~m~Benutzung: ~s~/house type [Type]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
House nearHouse = HouseManager.GetNearHouse(player.Position, dbContext);
|
||||||
|
if (nearHouse == null)
|
||||||
|
{
|
||||||
|
ChatService.ErrorMessage(player, "In deiner Nähe befindet sich kein Haus");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nearHouse.Type = option2;
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
|
HouseManager.RemoveHouse(nearHouse);
|
||||||
|
HouseManager.LoadHouse(nearHouse);
|
||||||
|
|
||||||
|
player.SendNotification("Der Haustyp wurde gesetzt");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.SendChatMessage("~m~Benutzung: ~s~/house [add / remove / price / type]");
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ALevel1338
|
#region ALevel1338
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ namespace ReallifeGamemode.Server
|
|||||||
ATMManager.InitATMs();
|
ATMManager.InitATMs();
|
||||||
CityHallManager.LoadCityHall();
|
CityHallManager.LoadCityHall();
|
||||||
JobManager.LoadJobs();
|
JobManager.LoadJobs();
|
||||||
|
HouseManager.LoadHouses();
|
||||||
|
|
||||||
|
|
||||||
TempBlip tempBlip = new TempBlip()
|
TempBlip tempBlip = new TempBlip()
|
||||||
|
|||||||
84
ReallifeGamemode.Server/Managers/HouseManager.cs
Normal file
84
ReallifeGamemode.Server/Managers/HouseManager.cs
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
using GTANetworkAPI;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using ReallifeGamemode.Server.Entities;
|
||||||
|
using ReallifeGamemode.Server.Extensions;
|
||||||
|
using ReallifeGamemode.Server.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ReallifeGamemode.Server.Managers
|
||||||
|
{
|
||||||
|
class HouseManager
|
||||||
|
{
|
||||||
|
private static readonly Dictionary<int, NetHandle> houseMarkers = new Dictionary<int, NetHandle>();
|
||||||
|
private static readonly Dictionary<int, NetHandle> houseLabels = new Dictionary<int, NetHandle>();
|
||||||
|
|
||||||
|
public static void LoadHouses()
|
||||||
|
{
|
||||||
|
using(var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
foreach (House house in dbContext.Houses.Include(h => h.User))
|
||||||
|
{
|
||||||
|
LoadHouse(house);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
houseMarkers[house.Id].Entity<Marker>().Delete();
|
||||||
|
houseLabels[house.Id].Entity<TextLabel>().Delete();
|
||||||
|
|
||||||
|
houseMarkers.Remove(house.Id);
|
||||||
|
houseLabels.Remove(house.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user