217 lines
9.1 KiB
C#
217 lines
9.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using GTANetworkAPI;
|
|
using Newtonsoft.Json;
|
|
using reallife_gamemode.Model;
|
|
using reallife_gamemode.Server.Entities;
|
|
using reallife_gamemode.Server.Extensions;
|
|
using reallife_gamemode.Server.Inventory.Interfaces;
|
|
using reallife_gamemode.Server.Managers;
|
|
using reallife_gamemode.Server.Saves;
|
|
using reallife_gamemode.Server.Services;
|
|
using reallife_gamemode.Server.Util;
|
|
/**
|
|
* @overview Life of German Reallife - Event Key (Key.cs)
|
|
* @author VegaZ
|
|
* @copyright (c) 2008 - 2018 Life of German
|
|
*/
|
|
|
|
namespace reallife_gamemode.Server.Events
|
|
{
|
|
public class Key : Script
|
|
{
|
|
[RemoteEvent("keyPress:NUM2")]
|
|
public void KeyPressNUM2(Client player)
|
|
{
|
|
if(player.GetData("editmode") == true && player.GetUser().IsAdmin(AdminLevel.HEADADMIN) == true)
|
|
{
|
|
TempBlip tempBlip = NAPI.Data.GetWorldData("blipTemplate");
|
|
SaveManager.OnSaveBlipData(player, tempBlip.Sprite.ToString(), tempBlip.Name, tempBlip.Scale.ToString(), tempBlip.Color.ToString(),
|
|
tempBlip.Transparency.ToString(), 200.ToString(), tempBlip.ShortRange.ToString(), 0.ToString(), 0.ToString());
|
|
player.SendNotification("~y~Blip~s~ erstellt!", false);
|
|
}
|
|
}
|
|
[RemoteEvent("keyPress:E")]
|
|
public void KeyPressE(Client player)
|
|
{
|
|
var user = player.GetUser();
|
|
if (user?.FactionId != null)
|
|
{
|
|
DutyPoint nearest = PositionManager.DutyPoints.Find(d => d.Position.DistanceTo(player.Position) <= 1.5);
|
|
if (nearest == null) return;
|
|
if (player.Position.DistanceTo(nearest.Position) <= 1.5 && nearest.FactionId == user.FactionId)
|
|
{
|
|
var nameTagColor = new Color(0, 0, 0);
|
|
var factionId = user.FactionId;
|
|
|
|
if (player.GetData("duty") == false)
|
|
{
|
|
player.SetData("duty", true);
|
|
player.SendNotification("Du bist nun ~g~im Dienst.");
|
|
if (player.GetUser().FactionId == 2) //Fire Department
|
|
{
|
|
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", true);
|
|
}
|
|
switch (factionId)
|
|
{
|
|
//LSPD
|
|
case 1:
|
|
nameTagColor = new Color(28, 134, 238);
|
|
break;
|
|
}
|
|
player.NametagColor = nameTagColor;
|
|
using (var context = new DatabaseContext())
|
|
{
|
|
List<CharacterCloth> clothes = context.CharacterClothes.ToList().FindAll(u => u.UserId == user.Id && u.Duty == true);
|
|
|
|
foreach(var cloth in clothes)
|
|
{
|
|
if(cloth.SlotType == 0)
|
|
{
|
|
player.SetClothes(cloth.SlotId, cloth.ClothId, 0);
|
|
}
|
|
else
|
|
{
|
|
if(cloth.ClothId != -1)
|
|
{
|
|
player.SetAccessories(cloth.SlotId, cloth.ClothId, 0);
|
|
}
|
|
else
|
|
{
|
|
player.ClearAccessory(cloth.SlotId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
player.SetData("duty", false);
|
|
player.SendNotification("Du bist nun ~r~außer Dienst.");
|
|
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", false);
|
|
player.NametagColor = new Color(255, 255, 255);
|
|
UpdateCharacterCloth.LoadCharacterDefaults(player);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
[RemoteEvent("keyPress:I")]
|
|
public void KeyPressI(Client player)
|
|
{
|
|
List<Client> players = NAPI.Pools.GetAllPlayers();
|
|
List<ListPlayer> ListPlayers = new List<ListPlayer>();
|
|
|
|
foreach(Client listPlayer in players)
|
|
{
|
|
var lPlayer = new ListPlayer();
|
|
lPlayer.Id = listPlayer.Handle.Value;
|
|
lPlayer.Name = listPlayer.Name;
|
|
lPlayer.Ping = listPlayer.Ping;
|
|
|
|
ListPlayers.Add(lPlayer);
|
|
}
|
|
player.TriggerEvent("fetchPlayerList", JsonConvert.SerializeObject(ListPlayers));
|
|
}
|
|
[RemoteEvent("keyPress:J")]
|
|
public void KeyPressJ(Client player)
|
|
{
|
|
var user = player.GetUser();
|
|
var inventoryWeight = 0;
|
|
|
|
using (var context = new DatabaseContext())
|
|
{
|
|
List<UserItem> userItems = context.UserItems.ToList().FindAll(i => i.UserId == user.Id);
|
|
string[][] items = new string[userItems.Count][];
|
|
foreach (var item in userItems)
|
|
{
|
|
IItem iItem = InventoryManager.GetItemById(item.ItemId);
|
|
var currentItemWeight = iItem.Gewicht * item.Amount;
|
|
inventoryWeight += currentItemWeight;
|
|
|
|
items[userItems.IndexOf(item)][0] = iItem.Name;
|
|
items[userItems.IndexOf(item)][1] = iItem.Description;
|
|
items[userItems.IndexOf(item)][2] = iItem.Gewicht.ToString();
|
|
items[userItems.IndexOf(item)][3] = item.Amount.ToString();
|
|
items[userItems.IndexOf(item)][4] = item.Slot.ToString();
|
|
}
|
|
player.TriggerEvent("showInventory", inventoryWeight, items);
|
|
}
|
|
}
|
|
[RemoteEvent("keyPress:K")]
|
|
public void KeyPressK(Client player)
|
|
{
|
|
var user = player.GetUser();
|
|
if (user?.FactionId != null)
|
|
{
|
|
DutyPoint nearest = PositionManager.DutyPoints.Find(d => d.Position.DistanceTo(player.Position) <= 1.5);
|
|
if (nearest == null) return;
|
|
if (player.Position.DistanceTo(nearest.Position) <= 1.5 && nearest.FactionId == user.FactionId)
|
|
{
|
|
List<string> hats = new List<string>();
|
|
List<string> tops = new List<string>();
|
|
List<string> legs = new List<string>();
|
|
List<string> shoes = new List<string>();
|
|
|
|
using (var context = new DatabaseContext())
|
|
{
|
|
List<DutyCloth> clothes = context.DutyClothes.ToList().FindAll(c => c.FactionId == user.FactionId && c.Gender == user.GetCharacter().Gender);
|
|
foreach(var cloth in clothes)
|
|
{
|
|
if(cloth.SlotType == 1)
|
|
{
|
|
if (cloth.ClothId != -1)
|
|
{
|
|
hats.Add(cloth.ClothId.ToString());
|
|
}
|
|
else
|
|
{
|
|
hats.Add("Keinen");
|
|
}
|
|
continue;
|
|
}
|
|
|
|
switch (cloth.SlotId)
|
|
{
|
|
case 11:
|
|
tops.Add(cloth.ClothId.ToString());
|
|
break;
|
|
case 4:
|
|
legs.Add(cloth.ClothId.ToString());
|
|
break;
|
|
case 6:
|
|
shoes.Add(cloth.ClothId.ToString());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
player.TriggerEvent("showDutyClothMenu", hats.ToArray(), tops.ToArray(), legs.ToArray(), shoes.ToArray());
|
|
}
|
|
}
|
|
|
|
}
|
|
[RemoteEvent("keyPress:L")]
|
|
public void KeyPressL(Client player)
|
|
{
|
|
DoorManager.ChangeDoorState(player);
|
|
}
|
|
[RemoteEvent("keyPress:N")]
|
|
public void KeyPressN(Client player)
|
|
{
|
|
if (player.IsInVehicle && player.VehicleSeat == -1)
|
|
{
|
|
player.Vehicle.EngineStatus = !player.Vehicle.EngineStatus;
|
|
}
|
|
}
|
|
[RemoteEvent("keyPress:X")]
|
|
public void KeyPressX(Client player)
|
|
{
|
|
if (player.IsInVehicle)
|
|
{
|
|
player.Seatbelt = !player.Seatbelt;
|
|
}
|
|
}
|
|
}
|
|
}
|