Skip to content

Commit

Permalink
feat: add transmog plus for legendary items + refactor (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
Helias authored Mar 6, 2024
1 parent a784284 commit c163d1d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 15 deletions.
6 changes: 6 additions & 0 deletions conf/transmog.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,15 @@ Transmogrification.SetCopperCost = 0
# Example: Transmogrification.MembershipLevels = "1,2,3"
# Default: ""
#
# Transmogrification.MembershipLevelsLegendary
# Description: Membership levels ID from acore_cms_subscriptions that define the eligibility for legendary items
# Example: Transmogrification.MembershipLevels = "1,2,3"
# Default: ""
#

Transmogrification.EnablePlus = 0
Transmogrification.MembershipLevels = ""
Transmogrification.MembershipLevelsLegendary = ""

#
###################################################################################################
68 changes: 54 additions & 14 deletions src/Transmogrification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,12 +923,12 @@ bool Transmogrification::IsAllowedQuality(uint32 quality, ObjectGuid::LowType pl
{
switch (quality)
{
case ITEM_QUALITY_POOR: return AllowPoor || isPlusEligible(playerGuid);
case ITEM_QUALITY_NORMAL: return AllowCommon || isPlusEligible(playerGuid);
case ITEM_QUALITY_POOR: return AllowPoor || isPlusWhiteGreyEligible(playerGuid);
case ITEM_QUALITY_NORMAL: return AllowCommon || isPlusWhiteGreyEligible(playerGuid);
case ITEM_QUALITY_UNCOMMON: return AllowUncommon;
case ITEM_QUALITY_RARE: return AllowRare;
case ITEM_QUALITY_EPIC: return AllowEpic;
case ITEM_QUALITY_LEGENDARY: return AllowLegendary;
case ITEM_QUALITY_LEGENDARY: return AllowLegendary || isPlusLegendaryEligible(playerGuid);
case ITEM_QUALITY_ARTIFACT: return AllowArtifact;
case ITEM_QUALITY_HEIRLOOM: return AllowHeirloom;
default: return false;
Expand Down Expand Up @@ -1041,11 +1041,18 @@ void Transmogrification::LoadConfig(bool reload)
TokenEntry = 49426;
}

/* TransmogPlus */
IsTransmogPlusEnabled = sConfigMgr->GetOption<bool>("Transmogrification.EnablePlus", false);

std::string stringMembershipIds = sConfigMgr->GetOption<std::string>("Transmogrification.MembershipLevels", "");
for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) {
MembershipIds.push_back(Acore::StringTo<uint32>(itr).value());
}

stringMembershipIds = sConfigMgr->GetOption<std::string>("Transmogrification.MembershipLevelsLegendary", "");
for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) {
MembershipIdsLegendary.push_back(Acore::StringTo<uint32>(itr).value());
}
}

void Transmogrification::DeleteFakeFromDB(ObjectGuid::LowType itemLowGuid, CharacterDatabaseTransaction* trans /*= nullptr*/)
Expand All @@ -1064,7 +1071,7 @@ void Transmogrification::DeleteFakeFromDB(ObjectGuid::LowType itemLowGuid, Chara
CharacterDatabase.Execute("DELETE FROM custom_transmogrification WHERE GUID = {}", itemGUID.GetCounter());
}

bool Transmogrification::isPlusEligible(ObjectGuid::LowType playerGuid) const {
bool Transmogrification::isPlusWhiteGreyEligible(ObjectGuid::LowType playerGuid) const {
if (!IsTransmogPlusEnabled) {
return false;
}
Expand All @@ -1073,26 +1080,59 @@ bool Transmogrification::isPlusEligible(ObjectGuid::LowType playerGuid) const {
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::LowType 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;
}

uint32 Transmogrification::getPlayerMembershipLevel(ObjectGuid::LowType playerGuid) const {
QueryResult result = CharacterDatabase.Query("SELECT `account` FROM `characters` WHERE `guid` = {}", playerGuid);

if (result) {

uint32 accountId = (*result)[0].Get<uint32>();
QueryResult resultAcc = LoginDatabase.Query("SELECT `membership_level` FROM `acore_cms_subscriptions` WHERE `account_name` COLLATE utf8mb4_general_ci = (SELECT `username` FROM `account` WHERE `id` = {})", accountId);

if (resultAcc) {
const uint32 membershipLevel = (*resultAcc)[0].Get<uint32>();
for (const auto& itr : MembershipIds)
{
if (itr == membershipLevel) {
return true;
}
}

return (*resultAcc)[0].Get<uint32>();
}
}

return false;
return 0;
}

bool Transmogrification::GetEnableTransmogInfo() const
Expand Down
5 changes: 4 additions & 1 deletion src/Transmogrification.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ class Transmogrification
// Transmog Plus
bool IsTransmogPlusEnabled;
std::vector<uint32> MembershipIds;
bool isPlusEligible(ObjectGuid::LowType playerGuid) const;
std::vector<uint32> MembershipIdsLegendary;
bool isPlusWhiteGreyEligible(ObjectGuid::LowType playerGuid) const;
bool isPlusLegendaryEligible(ObjectGuid::LowType playerGuid) const;
uint32 getPlayerMembershipLevel(ObjectGuid::LowType playerGuid) const;
};
#define sTransmogrification Transmogrification::instance()

Expand Down

0 comments on commit c163d1d

Please sign in to comment.