From e298dc846d4c7611d02fccea3da22b6b1e412f0c Mon Sep 17 00:00:00 2001 From: VegaZ Date: Thu, 28 May 2020 16:45:10 +0200 Subject: [PATCH] Changes to character\n*Fixed duty cloth changer when already duty\n*Changed basic character creation to add default values for cloth and props to database --- .../Events/UpdateCharacterCloth.cs | 55 ++++++++----- .../Managers/CharacterCreator.cs | 81 +++++++++++++++++++ 2 files changed, 117 insertions(+), 19 deletions(-) diff --git a/ReallifeGamemode.Server/Events/UpdateCharacterCloth.cs b/ReallifeGamemode.Server/Events/UpdateCharacterCloth.cs index 0b5035b0..431bf24b 100644 --- a/ReallifeGamemode.Server/Events/UpdateCharacterCloth.cs +++ b/ReallifeGamemode.Server/Events/UpdateCharacterCloth.cs @@ -53,14 +53,15 @@ namespace ReallifeGamemode.Server.Events [RemoteEvent("saveCharacterCloth")] public void SaveDutyCloth(Player client, string JSlotType, string JSlotId, string JClothId) { + User user; using (var context = new DatabaseContext()) { int[] slotType = JsonConvert.DeserializeObject(JSlotType); int[] slotId = JsonConvert.DeserializeObject(JSlotId); int[] clothId = JsonConvert.DeserializeObject(JClothId); - User user = client.GetUser(context); - + user = client.GetUser(context); + var character = user.GetCharacter(context); var charClothes = context.CharacterClothes.FirstOrDefault(c => c.UserId == user.Id && c.Duty); @@ -133,34 +134,50 @@ namespace ReallifeGamemode.Server.Events } context.SaveChanges(); } - LoadCharacterDefaults(client); + if (user.GetData("duty") == false) + { + LoadCharacterDefaults(client); + } } [RemoteEvent("defaultCharacterCloth")] public static void LoadCharacterDefaults(Player player) { - User user = player.GetUser(); - using (var context = new DatabaseContext()) + if (player.GetUser().GetData("duty") == false) { - List charClothes = context.CharacterClothes.Where(c => c.UserId == user.Id && c.Duty == false).ToList(); - NAPI.Player.ClearPlayerAccessory(player, 0); - NAPI.Player.ClearPlayerAccessory(player, 1); - NAPI.Player.ClearPlayerAccessory(player, 2); - NAPI.Player.ClearPlayerAccessory(player, 6); - NAPI.Player.ClearPlayerAccessory(player, 7); - - foreach (var cloth in charClothes) + User user = player.GetUser(); + using (var context = new DatabaseContext()) { - if (cloth.SlotType == 1) + List charClothes = context.CharacterClothes.Where(c => c.UserId == user.Id && c.Duty == false).ToList(); + NAPI.Player.ClearPlayerAccessory(player, 0); + NAPI.Player.ClearPlayerAccessory(player, 1); + NAPI.Player.ClearPlayerAccessory(player, 2); + NAPI.Player.ClearPlayerAccessory(player, 6); + NAPI.Player.ClearPlayerAccessory(player, 7); + + foreach (var cloth in charClothes) { - NAPI.Player.SetPlayerAccessory(player, cloth.SlotId, cloth.ClothId, 0); - } - else - { - NAPI.Player.SetPlayerClothes(player, cloth.SlotId, cloth.ClothId, cloth.Texture); + if (cloth.SlotType == 1) + { + if(cloth.ClothId != -1) + { + NAPI.Player.SetPlayerAccessory(player, cloth.SlotId, cloth.ClothId, 0); + } + } + else + { + if (cloth.ClothId != -1) + { + NAPI.Player.SetPlayerClothes(player, cloth.SlotId, cloth.ClothId, cloth.Texture); + } + } } } } + else + { + return; + } } [RemoteEvent("SERVER:BuyCharacterClothes")] diff --git a/ReallifeGamemode.Server/Managers/CharacterCreator.cs b/ReallifeGamemode.Server/Managers/CharacterCreator.cs index 871c35f7..b0c0e5fe 100644 --- a/ReallifeGamemode.Server/Managers/CharacterCreator.cs +++ b/ReallifeGamemode.Server/Managers/CharacterCreator.cs @@ -155,6 +155,87 @@ namespace ReallifeGamemode.Server.Managers var user = saveCharacter.Users.SingleOrDefault(u => u.Id == userId); user.CharacterId = character.Id; + + for (var x = 1; x <= 11; x++) + { + var s = 0; + if (x == 10) s = -1; + if (x == 2) continue; + var createClothes = new Database.Entities.CharacterCloth() + { + UserId = userId, + Duty = false, + SlotType = 0, + SlotId = x, + ClothId = s, + Texture = 0 + }; + saveCharacter.CharacterClothes.Add(createClothes); + } + for (var x = 0; x <= 7; x++) + { + var y = 0; + if (x == 0 || x == 1 || x == 2 || x == 6 || x == 7) + { + if (gender == false) + { + switch (x) + { + case 0: + y = 8; + break; + case 1: + y = 6; + break; + case 2: + y = -1; + break; + case 6: + y = -1; + break; + case 7: + y = -1; + break; + }; + } + else + { + switch (x) + { + case 0: + y = 57; + break; + case 1: + y = 5; + break; + case 2: + y = -1; + break; + case 6: + y = -1; + break; + case 7: + y = -1; + break; + }; + } + var createClothes = new Database.Entities.CharacterCloth() + { + UserId = userId, + Duty = false, + SlotType = 1, + SlotId = x, + ClothId = y, + Texture = 0 + }; + saveCharacter.CharacterClothes.Add(createClothes); + } + else + { + continue; + } + } + saveCharacter.SaveChanges(); } //HeadOverlay makeupHo = new HeadOverlay()