From bfc4d32c0494e1e78361bb0813be3755ecbe163a Mon Sep 17 00:00:00 2001 From: Gozzim <80704304+Gozzim@users.noreply.github.com> Date: Mon, 30 May 2022 23:31:41 +0200 Subject: [PATCH] chore: replace query with charCache & various fixes --- src/Transmogrification.cpp | 34 +++++++++++-------------------- src/Transmogrification.h | 2 +- src/cs_transmog.cpp | 41 ++++++++++++++------------------------ 3 files changed, 28 insertions(+), 49 deletions(-) diff --git a/src/Transmogrification.cpp b/src/Transmogrification.cpp index 0f2cb4c..fa30569 100644 --- a/src/Transmogrification.cpp +++ b/src/Transmogrification.cpp @@ -550,9 +550,9 @@ bool Transmogrification::SuitableForTransmogrification(Player* player, ItemTempl return true; } -bool Transmogrification::SuitableForTransmogrification(ObjectGuid::LowType playerGuid, ItemTemplate const* proto) const +bool Transmogrification::SuitableForTransmogrification(ObjectGuid guid, ItemTemplate const* proto) const { - if (!playerGuid || !proto) + if (!guid || !proto) return false; if (proto->Class != ITEM_CLASS_ARMOR && @@ -566,28 +566,18 @@ bool Transmogrification::SuitableForTransmogrification(ObjectGuid::LowType playe if (!CheckPureProtoRequirements(proto)) return false; - uint32 playerRaceMask; - uint32 playerClassMask; - TeamId playerTeamId; - uint8 playerLevel; - std::unordered_map playerSkillValues; - - if (QueryResult resultPlayer = CharacterDatabase.Query("SELECT `race`, `class`, `level` FROM `characters` WHERE `guid` = {}", playerGuid)) - { - Field* fields = resultPlayer->Fetch(); - uint8 playerRace = fields[0].Get(); - uint8 playerClass = fields[1].Get(); - playerLevel = fields[2].Get(); - playerRaceMask = 1 << (playerRace - 1); - playerClassMask = 1 << (playerClass - 1); - playerTeamId = Player::TeamIdForRace(playerRace); - } - else - { - LOG_ERROR("module", "Transmogification could not find player with guid {} in database.", playerGuid); + ObjectGuid::LowType playerGuid = guid.GetCounter(); + CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(guid); + if (!playerData) return false; - } + uint8 playerRace = playerData->Race; + uint8 playerLevel = playerData->Level; + uint32 playerRaceMask = 1 << (playerRace - 1); + uint32 playerClassMask = 1 << (playerData->Class - 1); + TeamId playerTeamId = Player::TeamIdForRace(playerRace); + + std::unordered_map playerSkillValues; if (QueryResult resultSkills = CharacterDatabase.Query("SELECT `skill`, `value` FROM `character_skills` WHERE `guid` = {}", playerGuid)) { do diff --git a/src/Transmogrification.h b/src/Transmogrification.h index 7cba8eb..813993d 100644 --- a/src/Transmogrification.h +++ b/src/Transmogrification.h @@ -158,7 +158,7 @@ public: TransmogAcoreStrings Transmogrify(Player* player, Item* itemTransmogrifier, uint8 slot, /*uint32 newEntry, */bool no_cost = false, bool hidden_transmog = false); bool CanTransmogrifyItemWithItem(Player* player, ItemTemplate const* destination, ItemTemplate const* source) const; bool SuitableForTransmogrification(Player* player, ItemTemplate const* proto) const; - bool SuitableForTransmogrification(ObjectGuid::LowType playerGuid, ItemTemplate const* proto) const; + bool SuitableForTransmogrification(ObjectGuid guid, ItemTemplate const* proto) const; bool CheckPureProtoRequirements(ItemTemplate const* proto) const; // bool CanBeTransmogrified(Item const* item); // bool CanTransmogrify(Item const* item); diff --git a/src/cs_transmog.cpp b/src/cs_transmog.cpp index 912716e..47fc0dc 100644 --- a/src/cs_transmog.cpp +++ b/src/cs_transmog.cpp @@ -129,7 +129,7 @@ public: } else { - suitableForTransmog = sTransmogrification->SuitableForTransmogrification(player->GetGUID().GetCounter(), itemTemplate); + suitableForTransmog = sTransmogrification->SuitableForTransmogrification(player->GetGUID(), itemTemplate); } if (!sTransmogrification->GetTrackUnusableItems() && !suitableForTransmog) @@ -146,18 +146,13 @@ public: return true; } - uint32 itemId = itemTemplate->ItemId; - uint32 accountId; - auto guid = player->GetGUID().GetCounter(); - if (QueryResult result = CharacterDatabase.Query("SELECT `account` FROM `characters` WHERE `guid` = {}", guid)) - { - Field* fields = result->Fetch(); - accountId = fields[0].Get(); - } - else - { + auto guid = player->GetGUID(); + CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(guid); + if (!playerData) return false; - } + + uint32 itemId = itemTemplate->ItemId; + uint32 accountId = playerData->AccountId; std::stringstream tempStream; tempStream << std::hex << ItemQualityColors[itemTemplate->Quality]; @@ -228,21 +223,15 @@ public: return false; } + auto guid = player->GetGUID(); + CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(guid); + if (!playerData) + return false; + bool added = false; uint32 error = 0; uint32 itemId; - uint32 accountId; - - auto guid = player->GetGUID().GetCounter(); - if (QueryResult result = CharacterDatabase.Query("SELECT `account` FROM `characters` WHERE `guid` = {}", guid)) - { - Field* fields = result->Fetch(); - accountId = fields[0].Get(); - } - else - { - return false; - } + uint32 accountId = playerData->AccountId; for (uint32 i = 0; i < MAX_ITEM_SET_ITEMS; ++i) { @@ -254,7 +243,7 @@ public: { if (!sTransmogrification->GetTrackUnusableItems() && ( (target && !sTransmogrification->SuitableForTransmogrification(target, itemTemplate)) || - !sTransmogrification->SuitableForTransmogrification(player->GetGUID().GetCounter(), itemTemplate) + !sTransmogrification->SuitableForTransmogrification(guid, itemTemplate) )) { error = LANG_CMD_TRANSMOG_ADD_UNSUITABLE; @@ -284,7 +273,7 @@ public: int locale = handler->GetSessionDbcLocale(); std::string setName = set->name[locale]; - std::string nameLink = handler->playerLink(target->GetName()); + std::string nameLink = handler->playerLink(player->GetName()); // Feedback of command execution to GM if (isNotConsole)