From 9f923958e4720c68ee1d6673b96cf4b83cfb70cf Mon Sep 17 00:00:00 2001 From: hydrant Date: Mon, 2 Sep 2019 21:00:55 +0200 Subject: [PATCH] House Blips --- .../Managers/HouseManager.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ReallifeGamemode.Server/Managers/HouseManager.cs b/ReallifeGamemode.Server/Managers/HouseManager.cs index 10c25393..279a43d5 100644 --- a/ReallifeGamemode.Server/Managers/HouseManager.cs +++ b/ReallifeGamemode.Server/Managers/HouseManager.cs @@ -17,6 +17,9 @@ namespace ReallifeGamemode.Server.Managers private static readonly Dictionary houseMarkers = new Dictionary(); private static readonly Dictionary houseLabels = new Dictionary(); private static readonly Dictionary houseColShapes = new Dictionary(); + private static readonly Dictionary houseBlips = new Dictionary(); + + private static readonly Dictionary> playerInColShape = new Dictionary>(); public static async void LoadHouses() { @@ -96,14 +99,22 @@ namespace ReallifeGamemode.Server.Managers { if (loadUser) house = house.Refresh(); + playerInColShape[house.Id] = new List(); + 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 == 0 ? "~r~Nicht verkäuflich" : house.Price.ToMoneyString())}"; + + byte houseColor = 11; if (house.OwnerId != null) { text = $"{house.Type}\n~s~Besitzer: ~y~{house.Owner.Name}\n~s~Mietpreis: ~g~{house.RentalFee.ToMoneyString()}"; + houseColor = 4; } + + houseBlips[house.Id] = NAPI.Blip.CreateBlip(40, house.Position, 1.0f, houseColor, "Haus"); houseLabels[house.Id] = NAPI.TextLabel.CreateTextLabel(text, house.Position, 10f, 1f, 0, new Color(255, 255, 255)); + if (house.Price != 0) { houseColShapes[house.Id] = NAPI.ColShape.CreateCylinderColShape(house.Position.Subtract(new Vector3(0, 0, 2)), 2.0f, 5f); @@ -115,6 +126,14 @@ namespace ReallifeGamemode.Server.Managers private static void HouseManager_OnEntityExitColShape(ColShape colShape, Client client) { + if (!client.IsLoggedIn() || client.IsInVehicle) return; + if (!houseColShapes.ContainsValue(colShape.Handle)) + { + return; + } + int houseId = houseColShapes.Where(p => p.Value.Value == colShape.Handle.Value).FirstOrDefault().Key; + playerInColShape[houseId].Remove(client); + client.TriggerEvent("SERVER:CloseHouseMenu"); } @@ -126,6 +145,7 @@ namespace ReallifeGamemode.Server.Managers return; } int houseId = houseColShapes.Where(p => p.Value.Value == colShape.Handle.Value).FirstOrDefault().Key; + playerInColShape[houseId].Add(client); House house = GetHouseById(houseId); User user = client.GetUser(); @@ -178,6 +198,17 @@ namespace ReallifeGamemode.Server.Managers houseColShapes[house.Id].Entity().Delete(); houseColShapes.Remove(house.Id); } + + if (houseBlips.ContainsKey(house.Id)) + { + houseBlips[house.Id].Entity().Delete(); + houseBlips.Remove(house.Id); + } + + foreach (Client client in playerInColShape[house.Id]) + { + client.TriggerEvent("SERVER:CloseHouseMenu"); + } } [RemoteEvent("CLIENT:House_BuyHouse")]