Skip to content

Commit

Permalink
feat: add sorting feature and related conf
Browse files Browse the repository at this point in the history
  • Loading branch information
Helias committed Sep 4, 2024
1 parent abac101 commit 06190b1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 34 deletions.
13 changes: 13 additions & 0 deletions conf/transmog.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@
# 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.AcoreWorldName
# Description: it is required for the sorting feature
# Default: 'acore_world'
#

Transmogrification.Enable = 1
Transmogrification.UseCollectionSystem = 1
Expand All @@ -90,6 +99,9 @@ Transmogrification.NotAllowed = ""

Transmogrification.EnablePortable = 1

Transmogrification.EnableSortByQualityAndName = 1
Transmogrification.AcoreWorldName = "acore_world"

#
# COPPER COST
#
Expand Down Expand Up @@ -220,6 +232,7 @@ Transmogrification.TokenAmount = 1
# Description: Ignore stat count > 0 requirement for source items
# Default: 0


Transmogrification.AllowPoor = 0
Transmogrification.AllowCommon = 0
Transmogrification.AllowUncommon = 1
Expand Down
32 changes: 18 additions & 14 deletions src/Transmogrification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
std::sort(collectionCache[accountId].begin(), collectionCache[accountId].end());

if (!sConfigMgr->GetOption<bool>("Transmogrification.EnableSortByQualityAndName", true)) {
std::sort(collectionCache[accountId].begin(), collectionCache[accountId].end());
}

return true;
}
return false;
Expand Down Expand Up @@ -654,28 +658,28 @@ bool Transmogrification::CanTransmogrifyItemWithItem(Player* player, ItemTemplat
bool Transmogrification::IsSubclassMismatchAllowed(Player *player, const ItemTemplate *source, const ItemTemplate *target) const
{
if (IsAllowed(source->ItemId)) return true;

uint32 sourceType = source->InventoryType;
uint32 targetType = target->InventoryType;
uint32 sourceClass = source->Class;
uint32 targetClass = target->Class;
uint32 sourceSub = source->SubClass;
uint32 targetSub = target->SubClass;

if (targetClass == ITEM_CLASS_WEAPON)
{
if (IsRangedWeapon(sourceClass, sourceSub))
return true;

if (AllowMixedWeaponTypes == MIXED_WEAPONS_MODERN)
{
switch (targetSub)
{
case ITEM_SUBCLASS_WEAPON_AXE:
case ITEM_SUBCLASS_WEAPON_SWORD:
case ITEM_SUBCLASS_WEAPON_MACE:
if (sourceSub == ITEM_SUBCLASS_WEAPON_AXE ||
sourceSub == ITEM_SUBCLASS_WEAPON_SWORD ||
if (sourceSub == ITEM_SUBCLASS_WEAPON_AXE ||
sourceSub == ITEM_SUBCLASS_WEAPON_SWORD ||
sourceSub == ITEM_SUBCLASS_WEAPON_MACE )
return true;
break;
Expand All @@ -684,13 +688,13 @@ bool Transmogrification::IsSubclassMismatchAllowed(Player *player, const ItemTem
case ITEM_SUBCLASS_WEAPON_MACE2:
case ITEM_SUBCLASS_WEAPON_STAFF:
case ITEM_SUBCLASS_WEAPON_POLEARM:
if (sourceSub == ITEM_SUBCLASS_WEAPON_AXE2 ||
sourceSub == ITEM_SUBCLASS_WEAPON_SWORD2 ||
if (sourceSub == ITEM_SUBCLASS_WEAPON_AXE2 ||
sourceSub == ITEM_SUBCLASS_WEAPON_SWORD2 ||
sourceSub == ITEM_SUBCLASS_WEAPON_MACE2 ||
sourceSub == ITEM_SUBCLASS_WEAPON_STAFF ||
sourceSub == ITEM_SUBCLASS_WEAPON_POLEARM )
return true;
break;
break;
}
}
else if (AllowMixedWeaponTypes == MIXED_WEAPONS_LOOSE)
Expand All @@ -704,19 +708,19 @@ bool Transmogrification::IsSubclassMismatchAllowed(Player *player, const ItemTem
{
if (AllowMixedArmorTypes)
return true;
if (AllowLowerTiers && IsTieredArmorSubclass(targetSub) && TierAvailable(player, 0, sourceSub))
if (AllowLowerTiers && IsTieredArmorSubclass(targetSub) && TierAvailable(player, 0, sourceSub))
return true;
if (AllowMixedOffhandArmorTypes && IsValidOffhandArmor(targetSub, targetType) && IsValidOffhandArmor(sourceSub, sourceType))
return true;
if (sourceSub == ITEM_SUBCLASS_ARMOR_MISC)
return sourceType == targetType;
}

return false;
}

bool Transmogrification::IsInvTypeMismatchAllowed(const ItemTemplate *source, const ItemTemplate *target) const
{
{
uint32 sourceType = source->InventoryType;
uint32 targetType = target->InventoryType;
uint32 sourceClass = source->Class;
Expand All @@ -728,7 +732,7 @@ bool Transmogrification::IsInvTypeMismatchAllowed(const ItemTemplate *source, co
{
if (IsRangedWeapon(sourceClass, sourceSub))
return true;

// Main-hand to offhand restrictions - see https://wowpedia.fandom.com/wiki/Transmogrification
if (AllowMixedWeaponTypes == MIXED_WEAPONS_LOOSE)
return true;
Expand All @@ -751,7 +755,7 @@ bool Transmogrification::IsInvTypeMismatchAllowed(const ItemTemplate *source, co
if (targetType == INVTYPE_CHEST || targetType == INVTYPE_ROBE)
return sourceType == INVTYPE_CHEST || sourceType == INVTYPE_ROBE;
}

return false;
}

Expand Down
50 changes: 30 additions & 20 deletions src/transmog_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ bool ValidForTransmog (Player* player, Item* target, Item* source, bool hasSearc
if (!target || !source || !player) return false;
ItemTemplate const* targetTemplate = target->GetTemplate();
ItemTemplate const* sourceTemplate = source->GetTemplate();

if (!sT->CanTransmogrifyItemWithItem(player, targetTemplate, sourceTemplate))
return false;
if (sT->GetFakeEntry(target->GetGUID()) == source->GetEntry())
Expand All @@ -378,13 +378,13 @@ std::vector<Item*> GetValidTransmogs (Player* player, Item* target, bool hasSear
{
std::vector<Item*> allowedItems;
if (!target) return allowedItems;

if (sT->GetUseCollectionSystem())
{
uint32 accountId = player->GetSession()->GetAccountId();
if (sT->collectionCache.find(accountId) == sT->collectionCache.end())
return allowedItems;

for (uint32 itemId : sT->collectionCache[accountId])
{
if (!sObjectMgr->GetItemTemplate(itemId))
Expand Down Expand Up @@ -775,7 +775,7 @@ class npc_transmogrifier : public CreatureScript
LocaleConstant locale = session->GetSessionDbLocaleIndex();
Item* oldItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
bool hasSearchString;

uint16 pageNumber = 0;
uint32 startValue = 0;
uint32 endValue = MAX_OPTIONS - 4;
Expand All @@ -786,7 +786,7 @@ class npc_transmogrifier : public CreatureScript
startValue = (pageNumber * (MAX_OPTIONS - 2));
endValue = (pageNumber + 1) * (MAX_OPTIONS - 2) - 1;
}

if (oldItem)
{
uint32 price = GetTransmogPrice(oldItem->GetTemplate());
Expand All @@ -800,7 +800,7 @@ class npc_transmogrifier : public CreatureScript
hasSearchString = !(searchStringIterator == sT->searchStringByPlayer.end());
std::string searchDisplayValue(hasSearchString ? searchStringIterator->second : GetLocaleText(locale, "search"));
std::vector<Item*> allowedItems = GetValidTransmogs(player, oldItem, hasSearchString, searchDisplayValue);

if (allowedItems.size() > 0)
{
lastPage = false;
Expand Down Expand Up @@ -872,7 +872,7 @@ class npc_transmogrifier : public CreatureScript
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|t" + GetLocaleText(locale, "back"), EQUIPMENT_SLOT_END + 1, 0);
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
}

static std::vector<ItemTemplate const*> GetSpoofedVendorItems (Item* target)
{
std::vector<ItemTemplate const*> spoofedItems;
Expand Down Expand Up @@ -913,7 +913,7 @@ class npc_transmogrifier : public CreatureScript
return 0;
}
}

static void EncodeItemToPacket (WorldPacket& data, ItemTemplate const* proto, uint8& slot, uint32 price)
{
data << uint32(slot + 1);
Expand All @@ -926,7 +926,7 @@ class npc_transmogrifier : public CreatureScript
data << uint32(0);
slot++;
}

//The actual vendor options are handled in the player script below, OnBeforeBuyItemFromVendor
static void ShowTransmogItemsInFakeVendor (Player* player, Creature* creature, uint8 slot)
{
Expand All @@ -938,26 +938,26 @@ class npc_transmogrifier : public CreatureScript
return;
}
ItemTemplate const* targetTemplate = targetItem->GetTemplate();

std::vector<Item*> itemList = GetValidTransmogs(player, targetItem, false, "");
std::vector<ItemTemplate const*> spoofedItems = GetSpoofedVendorItems(targetItem);

uint32 itemCount = itemList.size();
uint32 spoofCount = spoofedItems.size();
uint32 totalItems = itemCount + spoofCount;
uint32 price = GetTransmogPrice(targetItem->GetTemplate());
WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + totalItems * 8 * 4);

WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + totalItems * 8 * 4);
data << uint64(creature->GetGUID().GetRawValue());

uint8 count = 0;
size_t count_pos = data.wpos();
data << uint8(count);

for (uint32 i = 0; i < spoofCount && count < MAX_VENDOR_ITEMS; ++i)
{
EncodeItemToPacket (
data, spoofedItems[i], count,
data, spoofedItems[i], count,
GetSpoofedItemPrice(spoofedItems[i]->ItemId, targetTemplate)
);
}
Expand All @@ -966,7 +966,7 @@ class npc_transmogrifier : public CreatureScript
ItemTemplate const* _proto = itemList[i]->GetTemplate();
if (_proto) EncodeItemToPacket(data, _proto, count, price);
}

data.put(count_pos, count);
player->GetSession()->SendPacket(&data);
}
Expand Down Expand Up @@ -1154,13 +1154,13 @@ class PS_Transmogrification : public PlayerScript
sT->dataMap.erase(it->first);
sT->entryMap.erase(pGUID);
sT->selectionCache.erase(pGUID);

#ifdef PRESETS
if (sT->GetEnableSets())
sT->UnloadPlayerSets(pGUID);
#endif
}

void OnBeforeBuyItemFromVendor(Player* player, ObjectGuid vendorguid, uint32 /*vendorslot*/, uint32& itemEntry, uint8 /*count*/, uint8 /*bag*/, uint8 /*slot*/) override
{
Creature* vendor = player->GetMap()->GetCreature(vendorguid);
Expand Down Expand Up @@ -1201,7 +1201,17 @@ class WS_Transmogrification : public WorldScript
{
LOG_INFO("module", "Loading transmog appearance collection cache....");
uint32 collectedAppearanceCount = 0;
QueryResult result = CharacterDatabase.Query("SELECT account_id, item_template_id FROM custom_unlocked_appearances");


std::string query = "SELECT account_id, item_template_id FROM custom_unlocked_appearances";

if (sConfigMgr->GetOption<bool>("Transmogrification.EnableSortByQualityAndName", true)) {
const std::string acore_world_name = sConfigMgr->GetOption<std::string>("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);

if (result)
{
do
Expand Down

0 comments on commit 06190b1

Please sign in to comment.