207 lines
6.4 KiB
C#
207 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using GTANetworkAPI;
|
|
using ReallifeGamemode.Database.Entities;
|
|
using ReallifeGamemode.Database.Models;
|
|
using ReallifeGamemode.Server.Extensions;
|
|
using ReallifeGamemode.Server.Factions.Medic;
|
|
using ReallifeGamemode.Server.Services;
|
|
using ReallifeGamemode.Services;
|
|
using System.Diagnostics;
|
|
using Newtonsoft.Json;
|
|
using ReallifeGamemode.Server.Managers;
|
|
|
|
namespace ReallifeGamemode.Server.Wanted
|
|
{
|
|
public class Jail : Script
|
|
{
|
|
private static Dictionary<int, int> Jailtime { get; set; } = new Dictionary<int, int>(); //time in seconds
|
|
|
|
|
|
public static void Check_PutBehindBars(User user)
|
|
{
|
|
Player player = user.Player;
|
|
PositionManager.cuffPoints.Remove(player);
|
|
if (user.JailTime > 0)
|
|
{
|
|
player.RemoveAllWeapons();
|
|
player.Health = 100;
|
|
player.Armor = 0;
|
|
Random rnd = new Random();
|
|
int rndInt = rnd.Next(1, 3);
|
|
if (rndInt == 1)
|
|
NAPI.Player.SpawnPlayer(player, new Vector3(458.9842, -997.2126, 24.91485)); //send client to jail
|
|
if (rndInt == 2)
|
|
NAPI.Player.SpawnPlayer(player, new Vector3(459.696, -994.3766, 24.91486)); //send client to jail
|
|
if (rndInt == 3)
|
|
NAPI.Player.SpawnPlayer(player, new Vector3(458.3372, -1001.258, 24.91485)); //send client to jail
|
|
Jailtime[user.Id] = user.JailTime; // 54 sec for each wanted star -> in total 45min for 50 Wanteds
|
|
int timeMinutes;
|
|
|
|
if ((user.JailTime / 60) <= 1 && user.JailTime != 0)
|
|
{
|
|
timeMinutes = 1;
|
|
}
|
|
else
|
|
{
|
|
timeMinutes = (user.JailTime / 60);
|
|
}
|
|
player.TriggerEvent("jailTime", timeMinutes);
|
|
return;
|
|
}
|
|
}
|
|
|
|
/*
|
|
public static void JailTimer()
|
|
{
|
|
System.Timers.Timer timer = new System.Timers.Timer(60000);
|
|
System.Timers.Timer brakeOut = new System.Timers.Timer(10000);
|
|
System.Timers.Timer jailIn = new System.Timers.Timer(2500);
|
|
timer.Start();
|
|
brakeOut.Start();
|
|
jailIn.Start();
|
|
//timer.Elapsed += Timer_Elapsed;
|
|
//brakeOut.Elapsed += BrakeOut_Elapsed;
|
|
//jailIn.Elapsed += JailIn_Elapsed;
|
|
}
|
|
*/
|
|
|
|
public static void JailIn_Elapsed()
|
|
{
|
|
using var dbContext = new DatabaseContext();
|
|
foreach (var player in NAPI.Pools.GetAllPlayers())
|
|
{
|
|
if (player.Position.DistanceTo(new Vector3(458.9842, -997.2126, 24.91485)) > 7)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
User user = player.GetUser();
|
|
|
|
if (user != null && user.Wanteds > 0 && !Jailtime.ContainsKey(user.Id))
|
|
{
|
|
foreach (var copPlayer in NAPI.Pools.GetAllPlayers().Where(u => u.IsLoggedIn() && u.IsDuty())
|
|
{
|
|
if (!copPlayer.HasData("isDead") || copPlayer.GetData<bool>("isDead") != true)
|
|
{
|
|
if (player.Position.DistanceTo(copPlayer.Position) < 5)
|
|
{
|
|
user.SetJailTime(false);
|
|
user.AnnouncePlayerJailedIn();
|
|
dbContext.SaveChanges();
|
|
Check_PutBehindBars(user);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void BrakeOut_Elapsed()
|
|
{
|
|
foreach (var player in NAPI.Pools.GetAllPlayers())
|
|
{
|
|
User user = player.GetUser();
|
|
|
|
if (user != null && player.Position.DistanceTo2D(new Vector3(458.9842, -997.2126, 24.91485)) > 7 && Jailtime.ContainsKey(user.Id))
|
|
{
|
|
using (var dbContext = new DatabaseContext())
|
|
{
|
|
user = player.GetUser(dbContext);
|
|
user.JailTime = 0;
|
|
user.GiveWanteds(null, 50, "Knast-Ausbruch");
|
|
player.TriggerEvent("jailTime", 0);
|
|
dbContext.SaveChanges();
|
|
Jailtime.Remove(user.Id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void JailOut_Elapsed()
|
|
{
|
|
using var dbContext = new DatabaseContext();
|
|
foreach (var player in NAPI.Pools.GetAllPlayers())
|
|
{
|
|
User user = player.GetUser(dbContext);
|
|
if (user != null && Jailtime.ContainsKey(user.Id))
|
|
{
|
|
if (user.JailTime <= 0)
|
|
{
|
|
Jailtime.Remove(user.Id);
|
|
player.Position = new Vector3(427.879, -984.65, 30.71);
|
|
player.TriggerEvent("jailTime", 0);
|
|
return;
|
|
}
|
|
if (user.JailTime > 0)
|
|
{
|
|
user.JailTime -= 60;
|
|
|
|
int timeMinutes = 0;
|
|
|
|
if (((int)(user.JailTime / 60)) == 0 && user.JailTime != 0)
|
|
{
|
|
timeMinutes = 1;
|
|
}
|
|
else
|
|
{
|
|
timeMinutes = (int)(user.JailTime / 60);
|
|
}
|
|
|
|
player.TriggerEvent("jailTime", timeMinutes);
|
|
player.Health = 100;
|
|
}
|
|
}
|
|
}
|
|
dbContext.SaveChanges();
|
|
}
|
|
|
|
[RemoteEvent("setPrisonerFree")]
|
|
public void Release_Jail(Player cop, string client)
|
|
{
|
|
Player player = PlayerService.GetPlayerByNameOrId(client);
|
|
if (player == null)
|
|
return;
|
|
|
|
User user = player.GetUser();
|
|
if (Jailtime.ContainsKey(user.Id))
|
|
{
|
|
Jailtime.Remove(user.Id);
|
|
using (var dbContext = new DatabaseContext())
|
|
{
|
|
player.GetUser(dbContext).JailTime = 0;
|
|
dbContext.SaveChanges();
|
|
}
|
|
player.Health = 100;
|
|
player.Position = new Vector3(427.879, -984.65, 30.71);
|
|
|
|
ChatService.HQMessage("!{#8181E9}HQ: Beamter " + cop.Name + " hat " + user.Name + " aus dem Knast entlassen.");
|
|
ChatService.SendMessage(player, "!{#8181E9}Der Beamte " + cop.Name + " hat dich aus dem Knast entlassen");
|
|
player.TriggerEvent("jailTime", 0);
|
|
}
|
|
}
|
|
|
|
public static void Release_Jail_Admin(Player admin, Player target)
|
|
{
|
|
using var dbContext = new DatabaseContext();
|
|
User user = target.GetUser(dbContext);
|
|
if (Jailtime.ContainsKey(user.Id))
|
|
{
|
|
Jailtime.Remove(user.Id);
|
|
|
|
user.JailTime = 0;
|
|
dbContext.SaveChanges();
|
|
|
|
target.Health = 100;
|
|
target.Position = new Vector3(427.879, -984.65, 30.71);
|
|
|
|
ChatService.HQMessage(" Admin " + admin.Name + " hat " + user.Name + " aus dem Knast entlassen.");
|
|
ChatService.SendMessage(target, "!{#8181E9}Admin " + admin.Name + " hat dich aus dem Knast entlassen");
|
|
ChatService.SendMessage(admin, "!{#8181E9}Du hast " + user.Name + " administrativ aus dem Knast entlassen");
|
|
target.TriggerEvent("jailTime", 0);
|
|
}
|
|
}
|
|
}
|
|
}
|