working query

This commit is contained in:
EmosewaMC 2022-03-24 00:09:18 -07:00
parent a49f9dc586
commit b2c88bb6a7

View File

@ -6,6 +6,7 @@
#include "Database.h" #include "Database.h"
#include "Game.h" #include "Game.h"
#include "dLogger.h"
#include "User.h" #include "User.h"
#include <WorldPackets.h> #include <WorldPackets.h>
#include "Character.h" #include "Character.h"
@ -572,28 +573,26 @@ uint32_t GetShirtColorId(uint32_t color) {
auto colorId = std::find(shirtColorVector.begin(), shirtColorVector.end(), color); auto colorId = std::find(shirtColorVector.begin(), shirtColorVector.end(), color);
return color = std::distance(shirtColorVector.begin(), colorId); 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) { uint32_t FindCharShirtID(uint32_t shirtColor, uint32_t shirtStyle) {
try {
shirtStyle--; // to start at 0 instead of 1 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 == ";
uint32_t stylesCount = 34; shirtQuery += std::to_string(shirtColor);
uint32_t colorId = GetShirtColorId(shirtColor); shirtQuery += " AND icc.decal == ";
shirtQuery = shirtQuery + std::to_string(shirtStyle);
uint32_t startID = 4049; // item ID of the shirt with color 0 (red) and style 0 (plain) auto tableData = CDClientDatabase::ExecuteQuery(shirtQuery);
auto shirtLOT = tableData.getIntField(0, -1);
// For some reason, if the shirt style is 34 - 39, tableData.finalize();
// The ID is different than the original... Was this because return shirtLOT;
// these shirts were added later? }
if (shirtStyle >= 34) { catch (const std::exception&){
startID = 5730; // item ID of the shirt with color 0 (red) and style 34 (butterflies) Game::logger->Log("Character Create", "Failed to use query! Using backup...");
shirtStyle -= stylesCount; //change style from range 35-40 to range 0-5 // in case of no shirt found in CDServer, return problematic red vest.
stylesCount = 6; return 4069;
} }
// Get the final ID of the shirt
uint32_t shirtID = startID + (colorId * stylesCount) + shirtStyle;
return shirtID;
} }
uint32_t FindCharPantsID(uint32_t pantsColor) { uint32_t FindCharPantsID(uint32_t pantsColor) {