Skip to content

Commit

Permalink
feat: enable specific quality item based on transmog plus subscription (
Browse files Browse the repository at this point in the history
  • Loading branch information
Helias committed Mar 5, 2024
1 parent cd89891 commit a784284
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
16 changes: 16 additions & 0 deletions conf/transmog.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,21 @@ Transmogrification.SetNpcText = 601084
Transmogrification.SetCostModifier = 3.0
Transmogrification.SetCopperCost = 0

#
# TRANSMOG PLUS
#
# Transmogrification.EnablePlus
# Description: Enables/Disables TransmogPlus.
# Default: 0
#
# Transmogrification.MembershipLevels
# Description: Membership levels ID from acore_cms_subscriptions.
# Example: Transmogrification.MembershipLevels = "1,2,3"
# Default: ""
#

Transmogrification.EnablePlus = 0
Transmogrification.MembershipLevels = ""

#
###################################################################################################
54 changes: 46 additions & 8 deletions src/Transmogrification.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Transmogrification.h"
#include "ItemTemplate.h"
#include "DatabaseEnv.h"
#include "Tokenize.h"

Transmogrification* Transmogrification::instance()
{
Expand Down Expand Up @@ -721,7 +722,7 @@ bool Transmogrification::SuitableForTransmogrification(Player* player, ItemTempl
if (IsAllowed(proto->ItemId))
return true;

if (!IsItemTransmogrifiable(proto))
if (!IsItemTransmogrifiable(proto, player->GetGUID().GetCounter()))
return false;

//[AZTH] Yehonal
Expand Down Expand Up @@ -781,10 +782,10 @@ bool Transmogrification::SuitableForTransmogrification(ObjectGuid guid, ItemTemp
if (IsAllowed(proto->ItemId))
return true;

if (!IsItemTransmogrifiable(proto))
auto playerGuid = guid.GetCounter();
if (!IsItemTransmogrifiable(proto, playerGuid))
return false;

auto playerGuid = guid.GetCounter();
CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(guid);
if (!playerData)
return false;
Expand Down Expand Up @@ -854,7 +855,7 @@ bool Transmogrification::SuitableForTransmogrification(ObjectGuid guid, ItemTemp
return true;
}

bool Transmogrification::IsItemTransmogrifiable(ItemTemplate const* proto) const
bool Transmogrification::IsItemTransmogrifiable(ItemTemplate const* proto, ObjectGuid::LowType playerGuid) const
{
if (!proto)
return false;
Expand All @@ -865,7 +866,7 @@ bool Transmogrification::IsItemTransmogrifiable(ItemTemplate const* proto) const
if (!AllowFishingPoles && proto->Class == ITEM_CLASS_WEAPON && proto->SubClass == ITEM_SUBCLASS_WEAPON_FISHING_POLE)
return false;

if (!IsAllowedQuality(proto->Quality)) // (proto->Quality == ITEM_QUALITY_LEGENDARY)
if (!IsAllowedQuality(proto->Quality, playerGuid)) // (proto->Quality == ITEM_QUALITY_LEGENDARY)
return false;

// If World Event is not active, prevent using event dependant items
Expand Down Expand Up @@ -918,12 +919,12 @@ bool Transmogrification::IsNotAllowed(uint32 entry) const
return NotAllowed.find(entry) != NotAllowed.end();
}

bool Transmogrification::IsAllowedQuality(uint32 quality) const
bool Transmogrification::IsAllowedQuality(uint32 quality, ObjectGuid::LowType playerGuid) const
{
switch (quality)
{
case ITEM_QUALITY_POOR: return AllowPoor;
case ITEM_QUALITY_NORMAL: return AllowCommon;
case ITEM_QUALITY_POOR: return AllowPoor || isPlusEligible(playerGuid);
case ITEM_QUALITY_NORMAL: return AllowCommon || isPlusEligible(playerGuid);
case ITEM_QUALITY_UNCOMMON: return AllowUncommon;
case ITEM_QUALITY_RARE: return AllowRare;
case ITEM_QUALITY_EPIC: return AllowEpic;
Expand Down Expand Up @@ -1039,6 +1040,12 @@ void Transmogrification::LoadConfig(bool reload)
{
TokenEntry = 49426;
}

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());
}
}

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

bool Transmogrification::isPlusEligible(ObjectGuid::LowType playerGuid) const {
if (!IsTransmogPlusEnabled) {
return false;
}

if (MembershipIds.size() == 0) {
return false;
}

QueryResult result = CharacterDatabase.Query("SELECT `account` FROM `characters` WHERE `guid` = {}", playerGuid);

This comment has been minimized.

Copy link
@Nyeriah

Nyeriah Mar 11, 2024

Member

unnecessary query, you already have this information available at runtime


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);

This comment has been minimized.

Copy link
@Nyeriah

Nyeriah Mar 11, 2024

Member

unnecessary nested query, very bad resource efficiency

This comment has been minimized.

Copy link
@Helias

Helias Mar 13, 2024

Author Member

I do not know how to optimize this, I've already optimized the previous query using sCharacterCache locally (sill testing), but about this query I do not know how to get the account name in another way


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

}
}

return false;
}

bool Transmogrification::GetEnableTransmogInfo() const
{
return EnableTransmogInfo;
Expand Down
9 changes: 7 additions & 2 deletions src/Transmogrification.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class Transmogrification

bool IsAllowed(uint32 entry) const;
bool IsNotAllowed(uint32 entry) const;
bool IsAllowedQuality(uint32 quality) const;
bool IsAllowedQuality(uint32 quality, ObjectGuid::LowType playerGuid) const;
bool IsRangedWeapon(uint32 Class, uint32 SubClass) const;
bool CanNeverTransmog(ItemTemplate const* itemTemplate);

Expand All @@ -184,7 +184,7 @@ class Transmogrification
bool CanTransmogrifyItemWithItem(Player* player, ItemTemplate const* destination, ItemTemplate const* source) const;
bool SuitableForTransmogrification(Player* player, ItemTemplate const* proto) const;
bool SuitableForTransmogrification(ObjectGuid guid, ItemTemplate const* proto) const;
bool IsItemTransmogrifiable(ItemTemplate const* proto) const;
bool IsItemTransmogrifiable(ItemTemplate const* proto, ObjectGuid::LowType playerGuid) const;
uint32 GetSpecialPrice(ItemTemplate const* proto) const;

void DeleteFakeFromDB(ObjectGuid::LowType itemLowGuid, CharacterDatabaseTransaction* trans = nullptr);
Expand All @@ -211,6 +211,11 @@ class Transmogrification
bool EnableRetroActiveAppearances() const;
bool EnableResetRetroActiveAppearances() const;
[[nodiscard]] bool IsEnabled() const;

// Transmog Plus
bool IsTransmogPlusEnabled;
std::vector<uint32> MembershipIds;
bool isPlusEligible(ObjectGuid::LowType playerGuid) const;
};
#define sTransmogrification Transmogrification::instance()

Expand Down

0 comments on commit a784284

Please sign in to comment.