From b2c88bb6a750840d659939396e625079a39b9ed3 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Thu, 24 Mar 2022 00:09:18 -0700 Subject: [PATCH] working query --- dGame/UserManager.cpp | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 1535364c..d1e49cbb 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -6,6 +6,7 @@ #include "Database.h" #include "Game.h" +#include "dLogger.h" #include "User.h" #include #include "Character.h" @@ -572,28 +573,26 @@ uint32_t GetShirtColorId(uint32_t color) { auto colorId = std::find(shirtColorVector.begin(), shirtColorVector.end(), color); return color = std::distance(shirtColorVector.begin(), colorId); } - +// the correct query +/** + * select obj.id, obj.name, obj._internalnotes, icc.color1, icc.decal from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == "character create shirt"; + */ uint32_t FindCharShirtID(uint32_t shirtColor, uint32_t shirtStyle) { - - shirtStyle--; // to start at 0 instead of 1 - uint32_t stylesCount = 34; - uint32_t colorId = GetShirtColorId(shirtColor); - - uint32_t startID = 4049; // item ID of the shirt with color 0 (red) and style 0 (plain) - - // For some reason, if the shirt style is 34 - 39, - // The ID is different than the original... Was this because - // these shirts were added later? - if (shirtStyle >= 34) { - startID = 5730; // item ID of the shirt with color 0 (red) and style 34 (butterflies) - shirtStyle -= stylesCount; //change style from range 35-40 to range 0-5 - stylesCount = 6; + try { + std::string shirtQuery = "select obj.id from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == \"character create shirt\" AND icc.color1 == "; + shirtQuery += std::to_string(shirtColor); + shirtQuery += " AND icc.decal == "; + shirtQuery = shirtQuery + std::to_string(shirtStyle); + auto tableData = CDClientDatabase::ExecuteQuery(shirtQuery); + auto shirtLOT = tableData.getIntField(0, -1); + tableData.finalize(); + return shirtLOT; + } + catch (const std::exception&){ + Game::logger->Log("Character Create", "Failed to use query! Using backup..."); + // in case of no shirt found in CDServer, return problematic red vest. + return 4069; } - - // Get the final ID of the shirt - uint32_t shirtID = startID + (colorId * stylesCount) + shirtStyle; - - return shirtID; } uint32_t FindCharPantsID(uint32_t pantsColor) {