feat: add sorting feature and related conf (#174)

* feat: add sorting feature and related conf

* fix: optimize sort feature

* Update src/transmog_scripts.cpp
This commit is contained in:
Stefano Borzì
2024-09-07 12:17:06 +02:00
committed by GitHub
parent abac101878
commit 3b7bac8723
3 changed files with 59 additions and 33 deletions

View File

@@ -72,6 +72,11 @@
# Transmogrification.EnablePortable
# Description: Enables / Disables the portable transmogrification NPC.
# Default: 1
#
# Transmogrification.EnableSortByQualityAndName
# Description: Enables / Disables the sorting of the items by quality and then by names
# Default: 1
#
Transmogrification.Enable = 1
Transmogrification.UseCollectionSystem = 1
@@ -90,6 +95,8 @@ Transmogrification.NotAllowed = ""
Transmogrification.EnablePortable = 1
Transmogrification.EnableSortByQualityAndName = 1
#
# COPPER COST
#
@@ -220,6 +227,7 @@ Transmogrification.TokenAmount = 1
# Description: Ignore stat count > 0 requirement for source items
# Default: 0
Transmogrification.AllowPoor = 0
Transmogrification.AllowCommon = 0
Transmogrification.AllowUncommon = 1

View File

@@ -472,7 +472,11 @@ bool Transmogrification::AddCollectedAppearance(uint32 accountId, uint32 itemId)
if (std::find(collectionCache[accountId].begin(), collectionCache[accountId].end(), itemId) == collectionCache[accountId].end())
{
collectionCache[accountId].push_back(itemId);
if (!sConfigMgr->GetOption<bool>("Transmogrification.EnableSortByQualityAndName", true)) {
std::sort(collectionCache[accountId].begin(), collectionCache[accountId].end());
}
return true;
}
return false;

View File

@@ -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<Item*> GetValidTransmogs (Player* player, Item* target, bool hasSearch, std::string searchTerm)
{
std::vector<Item*> allowedItems;
@@ -415,6 +424,11 @@ std::vector<Item*> GetValidTransmogs (Player* player, Item* target, bool hasSear
}
}
}
if (sConfigMgr->GetOption<bool>("Transmogrification.EnableSortByQualityAndName", true)) {
sort(allowedItems.begin(), allowedItems.end(), CmpTmog);
}
return allowedItems;
}