refactor: Improve Transmog Plus code (#161)

* refactor: Improve Transmog Plus code

* Update Transmogrification.h
This commit is contained in:
Andrew
2024-08-16 10:37:00 -03:00
committed by GitHub
parent a571805e9c
commit e994a149f2
3 changed files with 40 additions and 66 deletions

View File

@@ -1011,12 +1011,12 @@ bool Transmogrification::IsAllowedQuality(uint32 quality, ObjectGuid const &play
{ {
switch (quality) switch (quality)
{ {
case ITEM_QUALITY_POOR: return AllowPoor || isPlusWhiteGreyEligible(playerGuid); case ITEM_QUALITY_POOR: return AllowPoor || IsPlusFeatureEligible(playerGuid, PLUS_FEATURE_GREY_ITEMS);
case ITEM_QUALITY_NORMAL: return AllowCommon || isPlusWhiteGreyEligible(playerGuid); case ITEM_QUALITY_NORMAL: return AllowCommon || IsPlusFeatureEligible(playerGuid, PLUS_FEATURE_GREY_ITEMS);
case ITEM_QUALITY_UNCOMMON: return AllowUncommon; case ITEM_QUALITY_UNCOMMON: return AllowUncommon;
case ITEM_QUALITY_RARE: return AllowRare; case ITEM_QUALITY_RARE: return AllowRare;
case ITEM_QUALITY_EPIC: return AllowEpic; 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_ARTIFACT: return AllowArtifact;
case ITEM_QUALITY_HEIRLOOM: return AllowHeirloom; case ITEM_QUALITY_HEIRLOOM: return AllowHeirloom;
default: return false; default: return false;
@@ -1134,19 +1134,24 @@ void Transmogrification::LoadConfig(bool reload)
/* TransmogPlus */ /* TransmogPlus */
IsTransmogPlusEnabled = sConfigMgr->GetOption<bool>("Transmogrification.EnablePlus", false); IsTransmogPlusEnabled = sConfigMgr->GetOption<bool>("Transmogrification.EnablePlus", false);
plusDataMap.clear();
std::string stringMembershipIds = sConfigMgr->GetOption<std::string>("Transmogrification.MembershipLevels", ""); std::string stringMembershipIds = sConfigMgr->GetOption<std::string>("Transmogrification.MembershipLevels", "");
for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) { for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false))
MembershipIds.push_back(Acore::StringTo<uint32>(itr).value()); {
plusDataMap[PLUS_FEATURE_GREY_ITEMS].push_back(Acore::StringTo<uint32>(itr).value());
} }
stringMembershipIds = sConfigMgr->GetOption<std::string>("Transmogrification.MembershipLevelsLegendary", ""); stringMembershipIds = sConfigMgr->GetOption<std::string>("Transmogrification.MembershipLevelsLegendary", "");
for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) { for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false))
MembershipIdsLegendary.push_back(Acore::StringTo<uint32>(itr).value()); {
plusDataMap[PLUS_FEATURE_LEGENDARY_ITEMS].push_back(Acore::StringTo<uint32>(itr).value());
} }
stringMembershipIds = sConfigMgr->GetOption<std::string>("Transmogrification.MembershipLevelsPet", ""); stringMembershipIds = sConfigMgr->GetOption<std::string>("Transmogrification.MembershipLevelsPet", "");
for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) { for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false))
MembershipIdsPet.push_back(Acore::StringTo<uint32>(itr).value()); {
plusDataMap[PLUS_FEATURE_PET].push_back(Acore::StringTo<uint32>(itr).value());
} }
PetSpellId = sConfigMgr->GetOption<uint32>("Transmogrification.PetSpellId", 2000100); PetSpellId = sConfigMgr->GetOption<uint32>("Transmogrification.PetSpellId", 2000100);
@@ -1168,7 +1173,8 @@ void Transmogrification::DeleteFakeFromDB(ObjectGuid::LowType itemLowGuid, Chara
CharacterDatabase.Execute("DELETE FROM custom_transmogrification WHERE GUID = {}", itemGUID.GetCounter()); 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); CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(playerGuid);
if (!playerData) if (!playerData)
return 0; return 0;
@@ -1182,59 +1188,24 @@ uint32 Transmogrification::getPlayerMembershipLevel(ObjectGuid const & playerGui
return 0; return 0;
} }
bool Transmogrification::isPlusWhiteGreyEligible(ObjectGuid const &playerGuid) const { bool Transmogrification::IsPlusFeatureEligible(ObjectGuid const &playerGuid, uint32 feature) const
{
if (!IsTransmogPlusEnabled) if (!IsTransmogPlusEnabled)
return false; return false;
if (MembershipIds.size() == 0) auto it = plusDataMap.find(feature);
if (it == plusDataMap.end() || it->second.empty())
return false; return false;
const auto membershipLevel = getPlayerMembershipLevel(playerGuid); const auto membershipLevel = getPlayerMembershipLevel(playerGuid);
if (membershipLevel == 0)
if (!membershipLevel)
return false; return false;
for (const auto& itr : MembershipIds) const auto& membershipLevels = it->second;
for (const auto& level : membershipLevels)
{ {
if (itr == membershipLevel) if (level == membershipLevel)
return true;
}
return false;
}
bool Transmogrification::isPlusLegendaryEligible(ObjectGuid const & playerGuid) const {
if (!IsTransmogPlusEnabled)
return false;
if (MembershipIdsLegendary.size() == 0)
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)
return false;
for (const auto& itr : MembershipIdsPet)
{
if (itr == membershipLevel)
return true; return true;
} }

View File

@@ -87,6 +87,13 @@ const uint32 AllArmorTiers[4] =
ITEM_SUBCLASS_ARMOR_CLOTH ITEM_SUBCLASS_ARMOR_CLOTH
}; };
enum PlusFeatures
{
PLUS_FEATURE_GREY_ITEMS,
PLUS_FEATURE_LEGENDARY_ITEMS,
PLUS_FEATURE_PET
};
class Transmogrification class Transmogrification
{ {
public: public:
@@ -97,6 +104,8 @@ public:
typedef std::unordered_map<ObjectGuid, transmog2Data> transmogMap; typedef std::unordered_map<ObjectGuid, transmog2Data> transmogMap;
typedef std::unordered_map<uint32, std::vector<uint32>> collectionCacheMap; typedef std::unordered_map<uint32, std::vector<uint32>> collectionCacheMap;
typedef std::unordered_map<uint32, std::string> searchStringMap; typedef std::unordered_map<uint32, std::string> searchStringMap;
typedef std::unordered_map<uint32, std::vector<uint32>> transmogPlusData;
transmogPlusData plusDataMap;
transmogMap entryMap; // entryMap[pGUID][iGUID] = entry transmogMap entryMap; // entryMap[pGUID][iGUID] = entry
transmogData dataMap; // dataMap[iGUID] = pGUID transmogData dataMap; // dataMap[iGUID] = pGUID
collectionCacheMap collectionCache; collectionCacheMap collectionCache;
@@ -250,14 +259,9 @@ public:
// Transmog Plus // Transmog Plus
bool IsTransmogPlusEnabled; bool IsTransmogPlusEnabled;
std::vector<uint32> MembershipIds; [[nodiscard]] bool IsPlusFeatureEligible(ObjectGuid const& playerGuid, uint32 feature) const;
std::vector<uint32> MembershipIdsLegendary;
std::vector<uint32> MembershipIdsPet;
uint32 getPlayerMembershipLevel(ObjectGuid const & playerGuid) 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() #define sTransmogrification Transmogrification::instance()

View File

@@ -307,16 +307,15 @@ public:
if (Player* player = PlayerIdentifier::FromSelf(handler)->GetConnectedPlayer()) if (Player* player = PlayerIdentifier::FromSelf(handler)->GetConnectedPlayer())
{ {
if (sTransmogrification->IsTransmogPlusEnabled) { if (sTransmogrification->IsTransmogPlusEnabled)
if (sTransmogrification->isTransmogPlusPetEligible(player->GetGUID())) { if (sTransmogrification->IsPlusFeatureEligible(player->GetGUID(), PLUS_FEATURE_PET))
{
player->CastSpell((Unit*)nullptr, sTransmogrification->PetSpellId, true); player->CastSpell((Unit*)nullptr, sTransmogrification->PetSpellId, true);
return true; return true;
} }
}
if (player->GetSession()->GetSecurity() < SEC_MODERATOR) { if (player->GetSession()->GetSecurity() < SEC_MODERATOR)
return true; return true;
}
player->CastSpell((Unit*)nullptr, sTransmogrification->PetSpellId, true); player->CastSpell((Unit*)nullptr, sTransmogrification->PetSpellId, true);
} }