diff --git a/src/Transmogrification.cpp b/src/Transmogrification.cpp index 6dd85097..48b6911d 100644 --- a/src/Transmogrification.cpp +++ b/src/Transmogrification.cpp @@ -1011,12 +1011,12 @@ bool Transmogrification::IsAllowedQuality(uint32 quality, ObjectGuid const &play { switch (quality) { - case ITEM_QUALITY_POOR: return AllowPoor || isPlusWhiteGreyEligible(playerGuid); - case ITEM_QUALITY_NORMAL: return AllowCommon || isPlusWhiteGreyEligible(playerGuid); + case ITEM_QUALITY_POOR: return AllowPoor || IsPlusFeatureEligible(playerGuid, PLUS_FEATURE_GREY_ITEMS); + case ITEM_QUALITY_NORMAL: return AllowCommon || IsPlusFeatureEligible(playerGuid, PLUS_FEATURE_GREY_ITEMS); case ITEM_QUALITY_UNCOMMON: return AllowUncommon; case ITEM_QUALITY_RARE: return AllowRare; case ITEM_QUALITY_EPIC: return AllowEpic; - case ITEM_QUALITY_LEGENDARY: return AllowLegendary || isPlusLegendaryEligible(playerGuid); + case ITEM_QUALITY_LEGENDARY: return AllowLegendary || IsPlusFeatureEligible(playerGuid, PLUS_FEATURE_LEGENDARY_ITEMS); case ITEM_QUALITY_ARTIFACT: return AllowArtifact; case ITEM_QUALITY_HEIRLOOM: return AllowHeirloom; default: return false; @@ -1134,19 +1134,24 @@ void Transmogrification::LoadConfig(bool reload) /* TransmogPlus */ IsTransmogPlusEnabled = sConfigMgr->GetOption("Transmogrification.EnablePlus", false); + plusDataMap.clear(); + std::string stringMembershipIds = sConfigMgr->GetOption("Transmogrification.MembershipLevels", ""); - for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) { - MembershipIds.push_back(Acore::StringTo(itr).value()); + for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) + { + plusDataMap[PLUS_FEATURE_GREY_ITEMS].push_back(Acore::StringTo(itr).value()); } stringMembershipIds = sConfigMgr->GetOption("Transmogrification.MembershipLevelsLegendary", ""); - for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) { - MembershipIdsLegendary.push_back(Acore::StringTo(itr).value()); + for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) + { + plusDataMap[PLUS_FEATURE_LEGENDARY_ITEMS].push_back(Acore::StringTo(itr).value()); } stringMembershipIds = sConfigMgr->GetOption("Transmogrification.MembershipLevelsPet", ""); - for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) { - MembershipIdsPet.push_back(Acore::StringTo(itr).value()); + for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) + { + plusDataMap[PLUS_FEATURE_PET].push_back(Acore::StringTo(itr).value()); } PetSpellId = sConfigMgr->GetOption("Transmogrification.PetSpellId", 2000100); @@ -1168,7 +1173,8 @@ void Transmogrification::DeleteFakeFromDB(ObjectGuid::LowType itemLowGuid, Chara CharacterDatabase.Execute("DELETE FROM custom_transmogrification WHERE GUID = {}", itemGUID.GetCounter()); } -uint32 Transmogrification::getPlayerMembershipLevel(ObjectGuid const & playerGuid) const { +uint32 Transmogrification::getPlayerMembershipLevel(ObjectGuid const & playerGuid) const +{ CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(playerGuid); if (!playerData) return 0; @@ -1182,59 +1188,24 @@ uint32 Transmogrification::getPlayerMembershipLevel(ObjectGuid const & playerGui return 0; } -bool Transmogrification::isPlusWhiteGreyEligible(ObjectGuid const &playerGuid) const { - if (!IsTransmogPlusEnabled) - return false; - - if (MembershipIds.size() == 0) - return false; - - const auto membershipLevel = getPlayerMembershipLevel(playerGuid); - if (membershipLevel == 0) - return false; - - for (const auto& itr : MembershipIds) - { - if (itr == membershipLevel) - return true; - } - - return false; -} - - -bool Transmogrification::isPlusLegendaryEligible(ObjectGuid const & playerGuid) const { +bool Transmogrification::IsPlusFeatureEligible(ObjectGuid const &playerGuid, uint32 feature) const +{ if (!IsTransmogPlusEnabled) return false; - if (MembershipIdsLegendary.size() == 0) + auto it = plusDataMap.find(feature); + if (it == plusDataMap.end() || it->second.empty()) return false; const auto membershipLevel = getPlayerMembershipLevel(playerGuid); - if (membershipLevel == 0) - return false; - for (const auto& itr : MembershipIdsLegendary) - { - if (itr == membershipLevel) - return true; - } - - return false; -} - - -bool Transmogrification::isTransmogPlusPetEligible(ObjectGuid const & playerGuid) const { - if (MembershipIdsPet.size() == 0) - return false; - - const auto membershipLevel = getPlayerMembershipLevel(playerGuid); - if (membershipLevel == 0) + if (!membershipLevel) return false; - for (const auto& itr : MembershipIdsPet) + const auto& membershipLevels = it->second; + for (const auto& level : membershipLevels) { - if (itr == membershipLevel) + if (level == membershipLevel) return true; } diff --git a/src/Transmogrification.h b/src/Transmogrification.h index 93c1911d..248728aa 100644 --- a/src/Transmogrification.h +++ b/src/Transmogrification.h @@ -87,6 +87,13 @@ const uint32 AllArmorTiers[4] = ITEM_SUBCLASS_ARMOR_CLOTH }; +enum PlusFeatures +{ + PLUS_FEATURE_GREY_ITEMS, + PLUS_FEATURE_LEGENDARY_ITEMS, + PLUS_FEATURE_PET +}; + class Transmogrification { public: @@ -97,6 +104,8 @@ class Transmogrification typedef std::unordered_map transmogMap; typedef std::unordered_map> collectionCacheMap; typedef std::unordered_map searchStringMap; + typedef std::unordered_map> transmogPlusData; + transmogPlusData plusDataMap; transmogMap entryMap; // entryMap[pGUID][iGUID] = entry transmogData dataMap; // dataMap[iGUID] = pGUID collectionCacheMap collectionCache; @@ -250,14 +259,9 @@ class Transmogrification // Transmog Plus bool IsTransmogPlusEnabled; - std::vector MembershipIds; - std::vector MembershipIdsLegendary; - std::vector MembershipIdsPet; - + [[nodiscard]] bool IsPlusFeatureEligible(ObjectGuid const& playerGuid, uint32 feature) const; uint32 getPlayerMembershipLevel(ObjectGuid const & playerGuid) const; - bool isPlusWhiteGreyEligible(ObjectGuid const & playerGuid) const; - bool isPlusLegendaryEligible(ObjectGuid const & playerGuid) const; - bool isTransmogPlusPetEligible(ObjectGuid const & playerGuid) const; + }; #define sTransmogrification Transmogrification::instance() diff --git a/src/cs_transmog.cpp b/src/cs_transmog.cpp index d35c9fda..233df9fc 100644 --- a/src/cs_transmog.cpp +++ b/src/cs_transmog.cpp @@ -307,16 +307,15 @@ class transmog_commandscript : public CommandScript if (Player* player = PlayerIdentifier::FromSelf(handler)->GetConnectedPlayer()) { - if (sTransmogrification->IsTransmogPlusEnabled) { - if (sTransmogrification->isTransmogPlusPetEligible(player->GetGUID())) { + if (sTransmogrification->IsTransmogPlusEnabled) + if (sTransmogrification->IsPlusFeatureEligible(player->GetGUID(), PLUS_FEATURE_PET)) + { player->CastSpell((Unit*)nullptr, sTransmogrification->PetSpellId, true); return true; } - } - if (player->GetSession()->GetSecurity() < SEC_MODERATOR) { + if (player->GetSession()->GetSecurity() < SEC_MODERATOR) return true; - } player->CastSpell((Unit*)nullptr, sTransmogrification->PetSpellId, true); }