From 0240c1299aa748360b66394ae8213a05bec6ac26 Mon Sep 17 00:00:00 2001 From: Helias Date: Thu, 5 Sep 2024 23:50:43 +0200 Subject: [PATCH] fix: optimize sort feature --- conf/transmog.conf.dist | 5 ----- src/transmog_scripts.cpp | 24 +++++++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/conf/transmog.conf.dist b/conf/transmog.conf.dist index d1297ef0..9aaa6be1 100644 --- a/conf/transmog.conf.dist +++ b/conf/transmog.conf.dist @@ -77,10 +77,6 @@ # Description: Enables / Disables the sorting of the items by quality and then by names # Default: 1 # -# Transmogrification.AcoreWorldName -# Description: it is required for the sorting feature -# Default: 'acore_world' -# Transmogrification.Enable = 1 Transmogrification.UseCollectionSystem = 1 @@ -100,7 +96,6 @@ Transmogrification.NotAllowed = "" Transmogrification.EnablePortable = 1 Transmogrification.EnableSortByQualityAndName = 1 -Transmogrification.AcoreWorldName = "acore_world" # # COPPER COST diff --git a/src/transmog_scripts.cpp b/src/transmog_scripts.cpp index 971b0d18..51acd803 100644 --- a/src/transmog_scripts.cpp +++ b/src/transmog_scripts.cpp @@ -374,6 +374,15 @@ bool ValidForTransmog (Player* player, Item* target, Item* source, bool hasSearc return true; } +bool CmpTmog (Item* i1, Item* i2) +{ + const ItemTemplate* i1t = i1->GetTemplate(); + const ItemTemplate* i2t = i2->GetTemplate(); + const int q1 = 7-i1t->Quality; + const int q2 = 7-i2t->Quality; + return std::tie(q1, i1t->Name1) < std::tie(q2, i2t->Name1); +} + std::vector GetValidTransmogs (Player* player, Item* target, bool hasSearch, std::string searchTerm) { std::vector allowedItems; @@ -415,6 +424,11 @@ std::vector GetValidTransmogs (Player* player, Item* target, bool hasSear } } } + + if (sConfigMgr->GetOption("Transmogrification.EnableSortByQualityAndName", true)) { + sort(allowedItems.begin(), allowedItems.end(), CmpTmog); + } + return allowedItems; } @@ -1202,15 +1216,7 @@ class WS_Transmogrification : public WorldScript LOG_INFO("module", "Loading transmog appearance collection cache...."); uint32 collectedAppearanceCount = 0; - - std::string query = "SELECT account_id, item_template_id FROM custom_unlocked_appearances"; - - if (sConfigMgr->GetOption("Transmogrification.EnableSortByQualityAndName", true)) { - const std::string acore_world_name = sConfigMgr->GetOption("Transmogrification.AcoreWorldName", "acore_world"); - query = "SELECT custom_unlocked_appearances.account_id, custom_unlocked_appearances.item_template_id, " + acore_world_name + ".item_template.name, " + acore_world_name + ".item_template.Quality FROM custom_unlocked_appearances INNER JOIN " + acore_world_name + ".item_template ON custom_unlocked_appearances.item_template_id=" + acore_world_name + ".item_template.entry ORDER BY " + acore_world_name + ".item_template.Quality DESC, " + acore_world_name + ".item_template.name ASC;"; - } - - QueryResult result = CharacterDatabase.Query(query); + QueryResult result = CharacterDatabase.Query("SELECT account_id, item_template_id FROM custom_unlocked_appearances"); if (result) {