53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using GTANetworkAPI;
|
|
using reallife_gamemode.Model;
|
|
using reallife_gamemode.Server.Entities;
|
|
using reallife_gamemode.Server.Extensions;
|
|
using reallife_gamemode.Server.Util;
|
|
/**
|
|
* @overview Life of German Reallife - Managers BankManager (BankManager.cs)
|
|
* @author VegaZ
|
|
* @copyright (c) 2008 - 2018 Life of German
|
|
*/
|
|
|
|
namespace reallife_gamemode.Server.Managers
|
|
{
|
|
public class DoorManager : Script
|
|
{
|
|
[RemoteEvent("ChangeDoorState")]
|
|
public void ChangeDoorState(Client player)
|
|
{
|
|
List<Door> NearDoors = new List<Door>();
|
|
var user = player.GetUser();
|
|
|
|
using (var saveDoor = new DatabaseContext())
|
|
{
|
|
NearDoors = saveDoor.Doors.ToList().FindAll(d => new Vector3(d.X, d.Y, d.Z).DistanceTo(player.Position) <= d.Radius);
|
|
foreach (Door d in NearDoors)
|
|
{
|
|
Door currentDoor = saveDoor.Doors.FirstOrDefault(c => c.Id == d.Id);
|
|
|
|
if(!user.IsAdmin(AdminLevel.ADMIN) && (d.FactionId != user.FactionId || d.FactionId == null))
|
|
{
|
|
string lockState = "~r~Du hast kein Recht diese T\u00fcr " + (d.Locked == true ? "auf" : "ab") + "zuschlie\u00dfen!";
|
|
player.SendNotification(lockState, false);
|
|
continue;
|
|
}
|
|
|
|
currentDoor.Locked = !currentDoor.Locked;
|
|
|
|
string notStr = d.Name + " " + (d.Locked == false ? "auf" : "ab") + "geschlossen";
|
|
|
|
player.SendNotification(notStr, false);
|
|
|
|
NAPI.Pools.GetAllPlayers().ForEach(p => p.TriggerEvent("changeDoorState", d.Model, d.X, d.Y, d.Z, (currentDoor.Locked ? 1 : 0), 0.0f, 0.0f, 0.0f));
|
|
}
|
|
saveDoor.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|