Add duty System and Duty Cloth

This commit is contained in:
VegaZ
2018-11-14 19:00:31 +01:00
parent f02ad2b93d
commit b4df50215d
17 changed files with 371 additions and 45 deletions

View File

@@ -239,27 +239,7 @@ namespace reallife_gamemode.Server.Commands
[Command("duty", "~m~Benutzung: ~s~/duty")]
public void CmdFactionDuty(Client player)
{
if (player.GetUser()?.FactionId == null)
{
ChatService.NotAuthorized(player);
return;
}
if(player.GetData("duty") != true)
{
player.SetData("duty", true);
player.SendNotification("Du bist nun ~g~im Dienst.");
if(player.GetUser().FactionId == 2)
{
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", true);
}
}
else
{
player.SetData("duty", false);
player.SendNotification("Du bist nun ~r~außer Dienst.");
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", false);
}
}
#endregion
}

View File

@@ -0,0 +1,25 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
/**
* @overview Life of German Reallife - Entities CharacterCloth CharacterCloth.cs
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Entities
{
public class CharacterCloth
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("User")]
public int UserId { get; set; }
public User User { get; set; }
public int ComponentId { get; set; }
public int? Drawable { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
/**
* @overview Life of German Reallife - Entities CharacterProp CharacterProp.cs
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Entities
{
public class CharacterProp
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("User")]
public int UserId { get; set; }
public User User { get; set; }
public int PropId { get; set; }
public int? Drawable { get; set; }
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
/**
* @overview Life of German Reallife - Entities DutyCloth DutyCloth.cs
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Entities
{
public class DutyCloth
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("Faction")]
public int FactionId { get; set; }
public Faction Faction { get; set; }
public int ComponentId { get; set; }
public int Drawable { get; set; }
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
/**
* @overview Life of German Reallife - Entities DutyProp DutyProp.cs
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Entities
{
public class DutyProp
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("Faction")]
public int FactionId { get; set; }
public Faction Faction { get; set; }
public int PropId { get; set; }
public int Drawable { get; set; }
}
}

View File

@@ -4,7 +4,9 @@ using System.Text;
using GTANetworkAPI;
using Newtonsoft.Json;
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)
@@ -27,7 +29,46 @@ namespace reallife_gamemode.Server.Events
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;
}
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);
}
}
}
}
[RemoteEvent("keyPress:I")]
public void KeyPressI(Client player)
{
@@ -45,6 +86,46 @@ 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)
{
int[] hats;
int[] tops;
int[] legs;
int[] shoes;
if(user.GetCharacter().Gender == false) //Wenn männlich
{
hats = new int[] { -1, 5, 12, 39, 46, 123, 124, 125};
tops = new int[] { -1, 55, 26};
legs = new int[] { -1, 24, 28 };
shoes = new int[] { -1, 24, 25};
}
else
{
hats = new int[] { -1, 12, 38, 45, 122, 123, 124 };
tops = new int[] { -1, 48, 43 };
legs = new int[] { -1, 34, 37, 102 };
shoes = new int[] { -1, 24, 25 };
}
player.TriggerEvent("showDutyClothMenu", hats, tops, legs, shoes);
}
}
}
[RemoteEvent("keyPress:L")]
public void KeyPressL(Client player)
{
DoorManager.ChangeDoorState(player);
}
[RemoteEvent("keyPress:N")]
public void KeyPressN(Client player)
{
@@ -60,6 +141,6 @@ namespace reallife_gamemode.Server.Events
{
player.Seatbelt = !player.Seatbelt;
}
}
}
}
}

View File

@@ -42,6 +42,21 @@ namespace reallife_gamemode.Server.Extensions
}
}
public static Character GetCharacter(this User user, DatabaseContext context = null)
{
if (context == null)
{
using (context = new DatabaseContext())
{
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
}
}
else
{
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
}
}
/// <summary>
/// Gibt zurück, ob ein Client eingeloggt ist
/// </summary>

View File

@@ -17,8 +17,7 @@ namespace reallife_gamemode.Server.Managers
{
public class DoorManager : Script
{
[RemoteEvent("ChangeDoorState")]
public void ChangeDoorState(Client player)
public static void ChangeDoorState(Client player)
{
List<Door> NearDoors = new List<Door>();
var user = player.GetUser();

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Text;
using GTANetworkAPI;
using reallife_gamemode.Server.Entities;
namespace reallife_gamemode.Server.Managers
{
public class PositionManager : Script
{
public static List<DutyPoint> DutyPoints = new List<DutyPoint>();
public static List<ColShape> DutyColShapes = new List<ColShape>();
[ServerEvent(Event.ResourceStart)]
public void OnResourceStart()
{
DutyPoint dutyPointLSPD = new DutyPoint()
{
Position = new Vector3(458.24, -990.86, 30.68),
FactionId = 1
};
DutyPoints.Add(dutyPointLSPD);
foreach (DutyPoint d in DutyPoints)
{
NAPI.Marker.CreateMarker(1, new Vector3(d.Position.X, d.Position.Y, d.Position.Z - 2), new Vector3(d.Position.X, d.Position.Y, d.Position.Z + 1),
new Vector3(0,0,0), 3, new Color(255, 255, 255, 50), false, 0);
NAPI.TextLabel.CreateTextLabel("Stempeluhr - Dr\u00fccke ~y~E\n~s~Dienstkleidung - Dr\u00fccke ~y~K", d.Position, 7, 1, 0, new Color(255, 255, 255), false, 0);
}
}
}
public class DutyPoint
{
public Vector3 Position { get; set; }
public int FactionId { get; set; }
}
}

View File

@@ -19,7 +19,7 @@ namespace reallife_gamemode.Server.Managers
{
if(c.IsInVehicle)
{
c.TriggerEvent("showTuningInfo");
c.TriggerEvent("showTuningInfo", c.GetData("duty"));
}
};

40
Server/Util/Converter.cs Normal file
View File

@@ -0,0 +1,40 @@
using GTANetworkAPI;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace reallife_gamemode.Server.Util
{
public class Converter
{
public static Color HexToColor(string hexColor)
{
//Remove # if present
if (hexColor.IndexOf('#') != -1)
hexColor = hexColor.Replace("#", "");
int red = 0;
int green = 0;
int blue = 0;
if (hexColor.Length == 6)
{
//#RRGGBB
red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
}
else if (hexColor.Length == 3)
{
//#RGB
red = int.Parse(hexColor[0].ToString() + hexColor[0].ToString(), NumberStyles.AllowHexSpecifier);
green = int.Parse(hexColor[1].ToString() + hexColor[1].ToString(), NumberStyles.AllowHexSpecifier);
blue = int.Parse(hexColor[2].ToString() + hexColor[2].ToString(), NumberStyles.AllowHexSpecifier);
}
Color returnColor = new Color(red, green, blue);
return returnColor;
}
}
}