using System.Collections.Generic; using System.Linq; using GTANetworkAPI; using Newtonsoft.Json; using reallife_gamemode.Server.Classes; using reallife_gamemode.Server.Entities; using reallife_gamemode.Server.Extensions; using reallife_gamemode.Server.Factions.Medic; using reallife_gamemode.Server.Inventory; using reallife_gamemode.Server.Managers; using reallife_gamemode.Server.Models; 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.IsLoggedIn()) return; 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); } GroundItem.PickUpGroundItem(player); } [RemoteEvent("keyPress:LEFT_ARROW")] public void KeyPressLeftArrow(Client player) { if (!player.IsLoggedIn()) return; List nearbyPlayers = NAPI.Player.GetPlayersInRadiusOfPlayer(3, player); if (nearbyPlayers.Count > 1) { List nearbyPlayerList = new List(); foreach (Client nearPlayer in nearbyPlayers) { if (nearPlayer.Name != player.Name) { nearbyPlayerList.Add(nearPlayer.Name); } else { continue; } } player.TriggerEvent("showPlayerInteraction", JsonConvert.SerializeObject(nearbyPlayerList)); } } [RemoteEvent("keyPress:RIGHT_ARROW")] public void KeyPressRightArrow(Client player) { if (!player.IsLoggedIn()) return; User user = player.GetUser(); player.SendChatMessage("RIGHT_ARROW TRIGGER"); switch (user.FactionId) { //LSFD case 2: player.SendChatMessage("RIGHT_ARROW TRIGGER - FACTION:~g~" + user.FactionId); player.TriggerEvent("showFactionInteraction", user.FactionId, user.GetFaction().Name, user.FactionLeader, Medic.ReviveTasks.Count.ToString(), Medic.HealTasks.Count.ToString(), Medic.FireTasks.Count.ToString()); break; } } [RemoteEvent("keyPress:E")] public void KeyPressE(Client player) { if (!player.IsLoggedIn()) return; 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 { int medicCount = 0; foreach(Client c in NAPI.Pools.GetAllPlayers()) { if((c.GetUser()?.GetFaction().Id ?? 0) == 2) { medicCount++; } } NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", medicCount); } switch (factionId) { //LSPD case 1: nameTagColor = new Color(28, 134, 238); break; } player.NametagColor = nameTagColor; using (var context = new DatabaseContext()) { List 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) { if (!player.IsLoggedIn()) return; InventoryManager.GetUserItems(player); } [RemoteEvent("keyPress:J")] public void KeyPressJ(Client player) { if (!player.IsLoggedIn()) return; List players = NAPI.Pools.GetAllPlayers(); List ListPlayers = new List(); foreach(Client listPlayer in players) { var lPlayer = new ListPlayer { Id = listPlayer.Handle.Value, Name = listPlayer.Name, Ping = listPlayer.Ping }; ListPlayers.Add(lPlayer); } player.TriggerEvent("fetchPlayerList", JsonConvert.SerializeObject(ListPlayers)); } [RemoteEvent("keyPress:K")] public void KeyPressK(Client player) { if (!player.IsLoggedIn()) return; 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 hats = new List(); List tops = new List(); List legs = new List(); List shoes = new List(); using (var context = new DatabaseContext()) { List 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) { if (!player.IsLoggedIn()) return; DoorManager.ChangeDoorState(player); } [RemoteEvent("keyPress:N")] public void KeyPressN(Client player) { if (!player.IsLoggedIn()) return; } [RemoteEvent("keyPress:X")] public void KeyPressX(Client player) { if (!player.IsLoggedIn()) return; if (player.IsInVehicle && player.VehicleSeat == -1) { ServerVehicle veh = player.Vehicle.GetServerVehicle(); if(veh != null) { if(veh is FactionVehicle fV && fV.FactionId != player.GetUser()?.FactionId && (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN3) ?? false)) { return; } else if(veh is ShopVehicle) { return; } } player.TriggerEvent("ToggleVehicleMenu"); } } } }