Feature/character creator

This commit is contained in:
VegaZ
2018-10-24 20:51:54 +02:00
parent 5d581ed66d
commit ae6801cedb
14 changed files with 1184 additions and 15 deletions

View File

@@ -1731,6 +1731,11 @@ namespace reallife_gamemode.Server.Commands
SaveManager.SaveAllOnSave();
}
[Command("creator")]
public void CmdAdminCreator(Client player)
{
player.TriggerEvent("toggleCreator");
}
/*
[Command("restart")]
public void CmdAdminRestart(Client player)

View File

@@ -0,0 +1,92 @@
using Newtonsoft.Json;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
using reallife_gamemode.Server.Extensions;
using reallife_gamemode.Server.Services;
using reallife_gamemode.Server.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
/**
* @overview Life of German Reallife - Entities Ban (Ban.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Entities
{
public class Character
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("User")]
public int UserId { get; set; }
public User User { get; set; }
public bool Gender { get; set; }
public byte Father { get; set; }
public byte Mother { get; set; }
public float Similarity { get; set; }
public float SkinSimilarity { get; set; }
public float NoseWidth { get; set; }
public float NoseBottomHeight { get; set; }
public float NoseTipLength { get; set; }
public float NoseBridgeDepth { get; set; }
public float NoseTipHeight { get; set; }
public float NoseBroken { get; set; }
public float BrowHeight { get; set; }
public float BrowDepth { get; set; }
public float CheekboneHeight { get; set; }
public float CheekboneWidth { get; set; }
public float CheekDepth { get; set; }
public float EyeSize { get; set; }
public float LipThickness { get; set; }
public float JawWidth { get; set; }
public float JawShape { get; set; }
public float ChinHeight { get; set; }
public float ChinDepth { get; set; }
public float ChinWidth { get; set; }
public float ChinIndent { get; set; }
public float NeckWidth { get; set; }
public byte Blemishes { get; set; }
public float BlemishesOpacity { get; set; }
public byte FacialHair { get; set; }
public float FacialHairOpacity { get; set; }
public byte Eyebrows { get; set; }
public float EyebrowsOpacity { get; set; }
public byte Ageing { get; set; }
public float AgeingOpacity { get; set; }
public byte Makeup { get; set; }
public float MakeupOpacity { get; set; }
public byte Blush { get; set; }
public float BlushOpacity { get; set; }
public byte Complexion { get; set; }
public float ComplexionOpacity { get; set; }
public byte SunDamage { get; set; }
public float SunDamageOpacity { get; set; }
public byte Lipstick { get; set; }
public float LipstickOpacity { get; set; }
public byte Freckles { get; set; }
public float FrecklesOpacity { get; set; }
public byte ChestHair { get; set; }
public float ChestHairOpacity { get; set; }
public byte Hair { get; set; }
public byte HairColor { get; set; }
public byte HairHighlightColor { get; set; }
public byte EyebrowColor { get; set; }
public byte BeardColor { get; set; }
public byte EyeColor { get; set; }
public byte BlushColor { get; set; }
public byte LipstickColor { get; set; }
public byte ChestHairColor { get; set; }
}
}

View File

@@ -42,10 +42,13 @@ namespace reallife_gamemode.Server.Entities
public float PositionY { get; set; }
public float PositionZ { get; set; }
[ForeignKey("Character")]
public int? CharacterId { get; set; }
public Character Character { get; set; }
[ForeignKey("Ban")]
public int? BanId { get; set; }
public Ban Ban { get; set; }
public int? FactionId { get; set; }
public Faction Faction { get; set; }

View File

@@ -5,6 +5,7 @@ using System.Text;
using GTANetworkAPI;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
using reallife_gamemode.Server.Managers;
using reallife_gamemode.Server.Util;
/**
@@ -19,7 +20,7 @@ namespace reallife_gamemode.Server.Events
{
[RemoteEvent("OnPlayerLogin")]
public void OnPlayerLogin(Client player, string password)
{
{
using (var loginUser = new Model.DatabaseContext())
{
var user = loginUser.Users.SingleOrDefault(b => b.Name == player.Name);
@@ -39,16 +40,17 @@ namespace reallife_gamemode.Server.Events
if (user.Password != NAPI.Util.GetHashSha256(password))
{
player.TriggerEvent("loginFail", "Passwort inkorrekt!");
}
}
else
{
player.TriggerEvent("loginSuccess");
NAPI.Player.SpawnPlayer(player, new Vector3(user.PositionX, user.PositionY, user.PositionZ), 0);
player.TriggerEvent("loginSuccess");
player.SetData("isLoggedIn", true);
player.SetData("spec", true);
player.SetData("duty", false);
var userBankAccount = loginUser.UserBankAccounts.SingleOrDefault(u => u.UserId == user.Id);
userBankAccount.Balance = userBankAccount.Balance;
if (user.Dead == true)
{
if (user.IsAdmin(AdminLevel.ADMIN) == true)
@@ -65,12 +67,7 @@ namespace reallife_gamemode.Server.Events
else
{
player.SetData("isDead", false);
}
var userBankAccount = loginUser.UserBankAccounts.SingleOrDefault(u => u.UserId == user.Id);
userBankAccount.Balance = userBankAccount.Balance;
player.TriggerEvent("draw", player.Name, player.Handle.Value);
}
if (user.Dead == true)
{
//player.TriggerEvent("startDeathTimer");
@@ -82,6 +79,21 @@ namespace reallife_gamemode.Server.Events
{
player.SetData("isDead", false);
}
if (user.CharacterId == null)
{
var currentPlayerCreatorDimension = (uint) NAPI.Data.GetWorldData("playerCreatorDimension");
currentPlayerCreatorDimension++;
NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension);
player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension");
player.Position = new Vector3(402.8664, -996.4108, -99.00027);
player.TriggerEvent("toggleCreator");
}
else
{
CharacterCreator.ApplyCharacter(player);
NAPI.Player.SpawnPlayer(player, new Vector3(user.PositionX, user.PositionY, user.PositionZ), 0);
player.TriggerEvent("draw", player.Name, player.Handle.Value);
}
}
}
}

View File

@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTANetworkAPI;
using Newtonsoft.Json;
using reallife_gamemode.Model;
/**
* @overview Life of German Reallife - Event Register (Register.cs)
@@ -41,11 +43,17 @@ namespace reallife_gamemode.Server.Events
dbContext.UserBankAccounts.Add(userBankAccount);
dbContext.SaveChanges();
player.TriggerEvent("registerSuccess");
NAPI.Player.SpawnPlayer(player, Main.DEFAULT_SPAWN_POSITION, Main.DEFAULT_SPAWN_HEADING);
player.TriggerEvent("registerSuccess");
player.SetData("isLoggedIn", true);
player.TriggerEvent("draw", player.Name, player.Handle.Value);
player.SetData("isDead", false);
var currentPlayerCreatorDimension = (uint) NAPI.Data.GetWorldData("playerCreatorDimension");
currentPlayerCreatorDimension++;
NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension);
player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension");
player.TriggerEvent("toggleCreator");
}
else if (player.SocialClubName == checkedUser.SocialClubName)
{
player.TriggerEvent("registerFail", "Dieser SocialClubAccount ist schon registriert!");

View File

@@ -1,5 +1,7 @@
using GTANetworkAPI;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
using System;

View File

@@ -31,5 +31,19 @@ namespace reallife_gamemode.Server.Extensions
return context.UserBankAccounts.FirstOrDefault(u => u.UserId == user.Id);
}
}
public static Character GetUserCharacter(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);
}
}
}
}

View File

@@ -0,0 +1,327 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTANetworkAPI;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Extensions;
namespace reallife_gamemode.Server.Managers
{
public class CharacterCreator : Script
{
public CharacterCreator()
{
}
[RemoteEvent("creatorSave")]
public void CreatorSave(Client player, bool gender, string parentData, string featureData, string appearanceData, string hairAndColorData)
{
var jParentData = JObject.Parse(parentData);
var jFeatureData = JArray.Parse(featureData);
var jAppearanceData = JArray.Parse(appearanceData);
var jHairAndColorData = JArray.Parse(hairAndColorData);
byte father = jParentData.Value<byte>("Father");
byte mother = jParentData.Value<byte>("Mother");
float similarity = jParentData.Value<float>("Similarity");
float skinSimilarity = jParentData.Value<float>("SkinSimilarity");
float noseWidth = jFeatureData.Value<float>(0);
float noseBottomHeight = jFeatureData.Value<float>(1);
float noseTipLength = jFeatureData.Value<float>(2);
float noseBridgeDepth = jFeatureData.Value<float>(3);
float noseTipHeight = jFeatureData.Value<float>(4);
float noseBroken = jFeatureData.Value<float>(5);
float browHeight = jFeatureData.Value<float>(6);
float browDepth = jFeatureData.Value<float>(7);
float cheekboneHeight = jFeatureData.Value<float>(8);
float cheekboneWidth = jFeatureData.Value<float>(9);
float cheekDepth = jFeatureData.Value<float>(10);
float eyeSize = jFeatureData.Value<float>(11);
float lipThickness = jFeatureData.Value<float>(12);
float jawWidth = jFeatureData.Value<float>(13);
float jawShape = jFeatureData.Value<float>(14);
float chinHeight = jFeatureData.Value<float>(15);
float chinDepth = jFeatureData.Value<float>(16);
float chinWidth = jFeatureData.Value<float>(17);
float chinIndent = jFeatureData.Value<float>(18);
float neckWidth = jFeatureData.Value<float>(19);
byte blemishes = jAppearanceData[0].Value<byte>("Value");
float blemishesOpacity = jAppearanceData[0].Value<byte>("Opacity");
byte facialHair = jAppearanceData[1].Value<byte>("Value");
float facialHairOpacity = jAppearanceData[1].Value<byte>("Opacity");
byte eyebrows = jAppearanceData[2].Value<byte>("Value");
float eyebrowsOpacity = jAppearanceData[2].Value<byte>("Opacity");
byte ageing = jAppearanceData[3].Value<byte>("Value");
float ageingOpacity = jAppearanceData[3].Value<byte>("Opacity");
byte makeup = jAppearanceData[4].Value<byte>("Value");
float makeupOpacity = jAppearanceData[4].Value<byte>("Opacity");
byte blush = jAppearanceData[5].Value<byte>("Value");
float blushOpacity = jAppearanceData[5].Value<byte>("Opacity");
byte complexion = jAppearanceData[6].Value<byte>("Value");
float complexionOpacity = jAppearanceData[6].Value<byte>("Opacity");
byte sunDamage = jAppearanceData[7].Value<byte>("Value");
float sunDamageOpacity = jAppearanceData[7].Value<byte>("Opacity");
byte lipstick = jAppearanceData[8].Value<byte>("Value");
float lipstickOpacity = jAppearanceData[8].Value<byte>("Opacity");
byte freckles = jAppearanceData[9].Value<byte>("Value");
float frecklesOpacity = jAppearanceData[9].Value<byte>("Opacity");
byte chestHair = jAppearanceData[10].Value<byte>("Value");
float chestHairOpacity = jAppearanceData[10].Value<byte>("Opacity");
byte hair = jHairAndColorData.Value<byte>(0);
byte hairColor = jHairAndColorData.Value<byte>(1);
byte hairHighlightColor = jHairAndColorData.Value<byte>(2);
byte eyebrowColor = jHairAndColorData.Value<byte>(3);
byte beardColor = jHairAndColorData.Value<byte>(4);
byte eyeColor = jHairAndColorData.Value<byte>(5);
byte blushColor = jHairAndColorData.Value<byte>(6);
byte lipstickColor = jHairAndColorData.Value<byte>(7);
byte chestHairColor = jHairAndColorData.Value<byte>(8);
using (var saveCharacter = new DatabaseContext())
{
var character = new Entities.Character
{
UserId = player.GetUser().Id,
Gender = gender,
Father = father,
Mother = mother,
Similarity = similarity,
SkinSimilarity = skinSimilarity,
NoseWidth = noseWidth,
NoseBottomHeight = noseBottomHeight,
NoseTipLength = noseTipLength,
NoseBridgeDepth = noseBridgeDepth,
NoseTipHeight = noseTipHeight,
NoseBroken = noseBroken,
BrowHeight = browHeight,
BrowDepth = browDepth,
CheekboneHeight = cheekboneHeight,
CheekboneWidth = cheekboneWidth,
CheekDepth = cheekDepth,
EyeSize = eyeSize,
LipThickness = lipThickness,
JawWidth = jawWidth,
JawShape = jawShape,
ChinHeight = chinHeight,
ChinDepth = chinDepth,
ChinWidth = chinWidth,
ChinIndent = chinIndent,
NeckWidth = neckWidth,
Blemishes = blemishes,
BlemishesOpacity = blemishesOpacity,
FacialHair = facialHair,
FacialHairOpacity = facialHairOpacity,
Eyebrows = eyebrows,
EyebrowsOpacity = eyebrowsOpacity,
Ageing = ageing,
AgeingOpacity = ageingOpacity,
Makeup = makeup,
MakeupOpacity = makeupOpacity,
Blush = blush,
BlushOpacity = blushOpacity,
Complexion = complexion,
ComplexionOpacity = complexionOpacity,
SunDamage = sunDamage,
SunDamageOpacity = sunDamageOpacity,
Lipstick = lipstick,
LipstickOpacity = lipstickOpacity,
Freckles = freckles,
FrecklesOpacity = frecklesOpacity,
ChestHair = chestHair,
ChestHairOpacity = chestHairOpacity,
Hair = hair,
HairColor = hairColor,
HairHighlightColor = hairHighlightColor,
EyebrowColor = eyebrowColor,
BeardColor = beardColor,
EyeColor = eyeColor,
BlushColor = blushColor,
LipstickColor = lipstickColor,
ChestHairColor = chestHairColor
};
saveCharacter.Characters.Add(character);
saveCharacter.SaveChanges();
var userId = player.GetUser().Id;
var user = saveCharacter.Users.SingleOrDefault(u => u.Id == userId);
user.CharacterId = character.Id;
saveCharacter.SaveChanges();
}
//HeadOverlay makeupHo = new HeadOverlay()
//{
// Index = 0,
// Opacity = 0.0f,
// Color = 0,
// SecondaryColor = 0
//};
//HeadOverlay blushHo = new HeadOverlay()
//{
// Index = 0,
// Opacity = 0.0f,
// Color = 0,
// SecondaryColor = 0
//};
//player.SetHeadOverlay(4, makeupHo);
//player.SetHeadOverlay(5, blushHo);
NAPI.Player.SpawnPlayer(player, Main.DEFAULT_SPAWN_POSITION, Main.DEFAULT_SPAWN_HEADING);
}
public static void ApplyCharacter(Client player)
{
var userId = player.GetUser().Id;
using (var loadCharacter = new DatabaseContext())
{
var character = loadCharacter.Characters.SingleOrDefault(c => c.UserId == userId);
//Männlich / Weiblich
if (character.Gender == false)
{
player.SetSkin(PedHash.FreemodeMale01);
}
else
{
player.SetSkin(PedHash.FreemodeFemale01);
}
//Gesichtszüge
float[] faceFeatures = new float[] { character.NoseWidth, character.NoseBottomHeight, character.NoseTipLength, character.NoseBridgeDepth, character.NoseTipHeight,
character.NoseBroken, character.BrowHeight, character.BrowDepth, character.CheekboneHeight, character.CheekboneWidth,
character.CheekboneWidth, character.CheekDepth, character.EyeSize, character.LipThickness, character.JawWidth,
character.JawShape, character.ChinHeight, character.ChinDepth, character.ChinWidth, character.ChinIndent, character.NeckWidth };
for (var i = 0; i < faceFeatures.Length; i++)
{
player.SetFaceFeature(i, faceFeatures[i]);
}
//Gesichtsmerkmale
HeadOverlay blemishes = new HeadOverlay()
{
Index = character.Blemishes,
Opacity = character.BlemishesOpacity,
Color = 255,
SecondaryColor = 255
};
HeadOverlay facialHair = new HeadOverlay()
{
Index = character.FacialHair,
Opacity = character.FacialHairOpacity,
Color = character.BeardColor,
SecondaryColor = 255
};
HeadOverlay eyebrows = new HeadOverlay()
{
Index = character.Eyebrows,
Opacity = character.EyebrowsOpacity,
Color = character.EyebrowColor,
SecondaryColor = 255
};
HeadOverlay ageing = new HeadOverlay()
{
Index = character.Ageing,
Opacity = character.AgeingOpacity,
Color = 255,
SecondaryColor = 255
};
HeadOverlay makeup = new HeadOverlay()
{
Index = character.Makeup,
Opacity = character.MakeupOpacity,
Color = 255,
SecondaryColor = 255
};
HeadOverlay blush = new HeadOverlay()
{
Index = character.Blush,
Opacity = character.BlushOpacity,
Color = character.BlushColor,
SecondaryColor = 255
};
HeadOverlay complexion = new HeadOverlay()
{
Index = character.Complexion,
Opacity = character.ComplexionOpacity,
Color = 255,
SecondaryColor = 255
};
HeadOverlay sunDamage = new HeadOverlay()
{
Index = character.SunDamage,
Opacity = character.SunDamageOpacity,
Color = 255,
SecondaryColor = 255
};
HeadOverlay lipstick = new HeadOverlay()
{
Index = character.Lipstick,
Opacity = character.LipstickOpacity,
Color = character.LipstickColor,
SecondaryColor = 255
};
HeadOverlay freckles = new HeadOverlay()
{
Index = character.Freckles,
Opacity = character.FrecklesOpacity,
Color = 255,
SecondaryColor = 255
};
HeadOverlay chestHair = new HeadOverlay()
{
Index = character.ChestHair,
Opacity = character.ChestHairOpacity,
Color = character.ChestHairColor,
SecondaryColor = 255
};
player.SetHeadOverlay(0, blemishes);
player.SetHeadOverlay(1, facialHair);
player.SetHeadOverlay(2, eyebrows);
player.SetHeadOverlay(3, ageing);
player.SetHeadOverlay(4, makeup);
player.SetHeadOverlay(5, blush);
player.SetHeadOverlay(6, complexion);
player.SetHeadOverlay(7, sunDamage);
player.SetHeadOverlay(8, lipstick);
player.SetHeadOverlay(9, freckles);
player.SetHeadOverlay(10, chestHair);
player.SetHeadOverlay(11, blemishes);
player.SetHeadOverlay(12, blemishes);
//Gesicht (Vererbung durch Mutter / Vater)
HeadBlend headBlend = new HeadBlend()
{
ShapeFirst = character.Mother,
ShapeSecond = character.Father,
ShapeThird = 0,
SkinFirst = character.Mother,
SkinSecond = character.Father,
SkinThird = 0,
ShapeMix = character.Similarity,
SkinMix = character.SkinSimilarity,
ThirdMix = 0.0f
};
NAPI.Player.SetPlayerHeadBlend(player, headBlend);
//Haare und Haarfarbe
player.SetClothes(2, character.Hair, 0);
NAPI.Player.SetPlayerHairColor(player, character.HairColor, character.HairHighlightColor);
//Augenfarbe
NAPI.Player.SetPlayerEyeColor(player, character.EyeColor);
}
}
}
}