199 lines
8.0 KiB
C#
199 lines
8.0 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;
|
|
|
|
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())
|
|
{
|
|
if (player.GetUser().GetCharacter().Gender == false)
|
|
{
|
|
var combination = context.MaleCombinations.FirstOrDefault(c => c.Top == componentVariation);
|
|
player.SetClothes(11, componentVariation, 0);
|
|
if (combination != null)
|
|
{
|
|
player.SetClothes(3, combination.Torso, 0);
|
|
player.SetClothes(8, combination.Undershirt, 0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var combination = context.FemaleCombinations.FirstOrDefault(c => c.Top == componentVariation);
|
|
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 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.MaleCombinations.FirstOrDefault(c => c.Top == clothId[1]).Torso
|
|
};
|
|
CharacterCloth newUndershirt = new CharacterCloth
|
|
{
|
|
UserId = user.Id,
|
|
|
|
Duty = true,
|
|
|
|
SlotType = 0,
|
|
SlotId = 8,
|
|
ClothId = context.MaleCombinations.FirstOrDefault(c => c.Top == clothId[1]).Undershirt
|
|
};
|
|
context.CharacterClothes.Add(newTorso);
|
|
context.CharacterClothes.Add(newUndershirt);
|
|
}
|
|
else
|
|
{
|
|
CharacterCloth newTorso = new CharacterCloth
|
|
{
|
|
UserId = user.Id,
|
|
|
|
Duty = true,
|
|
|
|
SlotType = 0,
|
|
SlotId = 3,
|
|
ClothId = context.FemaleCombinations.FirstOrDefault(c => c.Top == clothId[1]).Torso
|
|
};
|
|
CharacterCloth newUndershirt = new CharacterCloth
|
|
{
|
|
UserId = user.Id,
|
|
|
|
Duty = true,
|
|
|
|
SlotType = 0,
|
|
SlotId = 8,
|
|
ClothId = context.FemaleCombinations.FirstOrDefault(c => c.Top == clothId[1]).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);
|
|
if (user.GetCharacter().Gender == false)
|
|
{
|
|
torso.ClothId = context.MaleCombinations.FirstOrDefault(c => c.Top == clothId[1]).Torso;
|
|
undershirt.ClothId = context.MaleCombinations.FirstOrDefault(c => c.Top == clothId[1]).Undershirt;
|
|
}
|
|
else
|
|
{
|
|
torso.ClothId = context.FemaleCombinations.FirstOrDefault(c => c.Top == clothId[1]).Torso;
|
|
undershirt.ClothId = context.FemaleCombinations.FirstOrDefault(c => c.Top == clothId[1]).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);
|
|
|
|
foreach(var cloth in charClothes)
|
|
{
|
|
if(cloth.SlotType == 0)
|
|
{
|
|
if (cloth.ClothId == -1)
|
|
{
|
|
player.ClearAccessory(cloth.SlotId);
|
|
}
|
|
else
|
|
{
|
|
player.SetAccessories(cloth.SlotId, cloth.ClothId, 0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
player.SetClothes(cloth.SlotId, cloth.ClothId, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |