Merge develop into feature/inventory-system

This commit is contained in:
VegaZ
2018-11-26 17:53:25 +01:00
66 changed files with 4533 additions and 1302 deletions

13
Server/Events/Chat.cs Normal file
View File

@@ -0,0 +1,13 @@
using GTANetworkAPI;
namespace reallife_gamemode.Server.Events
{
public class Chat : Script
{
[ServerEvent(Event.ChatMessage)]
public void ChatEvent(Client player, string message)
{
NAPI.Player.GetPlayersInRadiusOfPlayer(10, player).ForEach(p => p.SendChatMessage($"{player.Name} sagt: {message}"));
}
}
}

View File

@@ -27,10 +27,7 @@ namespace reallife_gamemode.Server.Events
"datgame_",
"xSprite",
"xPrike",
"balboistderbeste",
"xNccPlay",
"Marvino01"
};
@@ -76,7 +73,7 @@ namespace reallife_gamemode.Server.Events
if (bannedUser.Applied == bannedUser.UntilDateTime)
{
player.SendChatMessage("!{#FF4040}Du wurdest permanent gebannt! [" + bannedUser.Reason + "]");
//player.Kick();
player.Kick();
}
else
{
@@ -86,14 +83,14 @@ namespace reallife_gamemode.Server.Events
if(timeStamp > unixTimestamp)
{
player.SendChatMessage("Du bist noch bis zum !{#FF4040}" + dt.AddSeconds(timeStamp).ToLocalTime() + " Uhr ~s~gebannt. [" + bannedUser.Reason + "]");
player.Kick();
}
else
{
player.GetUser().BanId = null;
user.BanId = null;
loginUser.SaveChanges();
player.TriggerEvent("showLogin");
}
//player.Kick();
}
}
}
else player.TriggerEvent("showLogin");

View File

@@ -1,8 +1,15 @@
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.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)
@@ -14,6 +21,81 @@ 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)
{
@@ -31,36 +113,78 @@ namespace reallife_gamemode.Server.Events
}
player.TriggerEvent("fetchPlayerList", JsonConvert.SerializeObject(ListPlayers));
}
[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 (NAPI.Player.IsPlayerInAnyVehicle(player))
if (player.IsInVehicle && player.VehicleSeat == -1)
{
bool engineStatus = NAPI.Vehicle.GetVehicleEngineStatus(player.Vehicle);
if (engineStatus == false)
{
player.Vehicle.EngineStatus = true;
}
else
{
player.Vehicle.EngineStatus = false;
}
player.Vehicle.EngineStatus = !player.Vehicle.EngineStatus;
}
}
[RemoteEvent("keyPress:X")]
public void KeyPressX(Client player)
{
if (NAPI.Player.IsPlayerInAnyVehicle(player))
if (player.IsInVehicle)
{
if (player.Seatbelt == false)
{
player.Seatbelt = true;
}
else
{
player.Seatbelt = false;
}
player.Seatbelt = !player.Seatbelt;
}
}
}
}
}

View File

@@ -48,6 +48,11 @@ namespace reallife_gamemode.Server.Events
player.SetData("spec", true);
player.SetData("duty", false);
if(user.IsAdmin(AdminLevel.HEADADMIN) == true)
{
player.SetData("editmode", false);
}
var userBankAccount = loginUser.UserBankAccounts.SingleOrDefault(u => u.UserId == user.Id);
userBankAccount.Balance = userBankAccount.Balance;
@@ -66,8 +71,9 @@ namespace reallife_gamemode.Server.Events
else
{
CharacterCreator.ApplyCharacter(player);
UpdateCharacterCloth.LoadCharacterDefaults(player);
NAPI.Player.SpawnPlayer(player, new Vector3(user.PositionX, user.PositionY, user.PositionZ), 0);
player.TriggerEvent("draw", player.Name, player.Handle.Value);
player.TriggerEvent("draw", player.Name, player.Handle.Value);
}
if (user.Dead == true)
{

View File

@@ -0,0 +1,156 @@
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;
namespace reallife_gamemode.Server.Events
{
public class UpdateCharacterCloth : Script
{
[RemoteEvent("updateDutyProp")]
public void UpdateDutyProp(Client player, int componentId, int componentVariation)
{
if (componentId != -1)
{
player.SetAccessories(componentId, componentVariation, 0);
}
else
{
player.ClearAccessory(0);
}
}
[RemoteEvent("updateDutyCloth")]
public void UpdateDutyCloth(Client player, int componentId, int componentVariation)
{
if (componentId == 11)
{
//TODO Spezielle Duty Kleidung in Datenbank einpflegen (Ergibt bei Cop-Kleidung NULL)
using (var context = new DatabaseContext())
{
var character = player.GetUser().GetCharacter();
var combination = context.ClothCombinations.FirstOrDefault(c => c.Top == componentVariation && c.Gender == character.Gender);
player.SetClothes(11, componentVariation, 0);
if (combination != null)
{
player.SetClothes(3, combination.Torso, 0);
player.SetClothes(8, combination.Undershirt, 0);
}
}
}
else
{
player.SetClothes(componentId, componentVariation, 0);
}
}
[RemoteEvent("saveCharacterCloth")]
public void SaveDutyCloth(Client client, string JSlotType, string JSlotId, string JClothId)
{
using (var context = new DatabaseContext())
{
int[] slotType = JsonConvert.DeserializeObject<int[]>(JSlotType);
int[] slotId = JsonConvert.DeserializeObject<int[]>(JSlotId);
int[] clothId = JsonConvert.DeserializeObject<int[]>(JClothId);
User user = client.GetUser();
user = context.Users.FirstOrDefault(u => u.Id == user.Id);
var character = client.GetUser().GetCharacter();
var charClothes = context.CharacterClothes.FirstOrDefault(c => c.UserId == user.Id);
if (charClothes == null)
{
for (var x = 0; x < slotType.Length; x++)
{
CharacterCloth newCloth = new CharacterCloth
{
UserId = user.Id,
Duty = true,
SlotType = (byte)slotType[x],
SlotId = slotId[x],
ClothId = clothId[x]
};
context.CharacterClothes.Add(newCloth);
}
if (user.GetCharacter().Gender == false)
{
CharacterCloth newTorso = new CharacterCloth
{
UserId = user.Id,
Duty = true,
SlotType = 0,
SlotId = 3,
ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Torso
};
CharacterCloth newUndershirt = new CharacterCloth
{
UserId = user.Id,
Duty = true,
SlotType = 0,
SlotId = 8,
ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Undershirt
};
context.CharacterClothes.Add(newTorso);
context.CharacterClothes.Add(newUndershirt);
}
}
else
{
for (var x = 0; x < slotType.Length; x++)
{
var loopCloth = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == slotType[x] && u.SlotId == slotId[x]);
loopCloth.ClothId = clothId[x];
}
CharacterCloth torso = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == 0 && u.SlotId == 3);
CharacterCloth undershirt = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == 0 && u.SlotId == 8);
torso.ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Torso;
undershirt.ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Undershirt;
}
context.SaveChanges();
}
LoadCharacterDefaults(client);
}
[RemoteEvent("defaultCharacterCloth")]
public static void LoadCharacterDefaults(Client player)
{
User user = player.GetUser();
using (var context = new DatabaseContext())
{
List<CharacterCloth> charClothes = context.CharacterClothes.ToList().FindAll(c => c.UserId == user.Id && c.Duty == false);
player.ClearAccessory(0);
player.ClearAccessory(1);
player.ClearAccessory(2);
player.ClearAccessory(6);
player.ClearAccessory(7);
foreach (var cloth in charClothes)
{
if(cloth.SlotType == 1)
{
player.SetAccessories(cloth.SlotId, cloth.ClothId, 0);
}
else
{
player.SetClothes(cloth.SlotId, cloth.ClothId, 0);
}
}
}
}
}
}