feat: transmog plus pet (#141)

* feat: transmog plus pet

* chore: update code style based on standard, restore sql values

* refactor: improve code quality, remove unnecessary sql query
This commit is contained in:
Stefano Borzì
2024-03-13 16:59:48 +01:00
committed by GitHub
parent c163d1dc50
commit f984be398f
4 changed files with 76 additions and 40 deletions

View File

@@ -270,13 +270,19 @@ Transmogrification.SetCopperCost = 0
#
# Transmogrification.MembershipLevelsLegendary
# Description: Membership levels ID from acore_cms_subscriptions that define the eligibility for legendary items
# Example: Transmogrification.MembershipLevels = "1,2,3"
# Example: Transmogrification.MembershipLevelsLegendary = "1,2,3"
# Default: ""
#
# Transmogrification.MembershipLevelsPet
# Description: Membership levels ID from acore_cms_subscriptions that define the eligibility for transmog pet
# Example: Transmogrification.MembershipLevelsPet = "1,2,3"
# Default: ""
#
Transmogrification.EnablePlus = 0
Transmogrification.MembershipLevels = ""
Transmogrification.MembershipLevelsLegendary = ""
Transmogrification.MembershipLevelsPet = ""
#
###################################################################################################

View File

@@ -722,7 +722,7 @@ bool Transmogrification::SuitableForTransmogrification(Player* player, ItemTempl
if (IsAllowed(proto->ItemId))
return true;
if (!IsItemTransmogrifiable(proto, player->GetGUID().GetCounter()))
if (!IsItemTransmogrifiable(proto, player->GetGUID()))
return false;
//[AZTH] Yehonal
@@ -782,10 +782,10 @@ bool Transmogrification::SuitableForTransmogrification(ObjectGuid guid, ItemTemp
if (IsAllowed(proto->ItemId))
return true;
auto playerGuid = guid.GetCounter();
if (!IsItemTransmogrifiable(proto, playerGuid))
if (!IsItemTransmogrifiable(proto, guid))
return false;
auto playerGuid = guid.GetCounter();
CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(guid);
if (!playerData)
return false;
@@ -855,7 +855,7 @@ bool Transmogrification::SuitableForTransmogrification(ObjectGuid guid, ItemTemp
return true;
}
bool Transmogrification::IsItemTransmogrifiable(ItemTemplate const* proto, ObjectGuid::LowType playerGuid) const
bool Transmogrification::IsItemTransmogrifiable(ItemTemplate const* proto, ObjectGuid const &playerGuid) const
{
if (!proto)
return false;
@@ -919,7 +919,7 @@ bool Transmogrification::IsNotAllowed(uint32 entry) const
return NotAllowed.find(entry) != NotAllowed.end();
}
bool Transmogrification::IsAllowedQuality(uint32 quality, ObjectGuid::LowType playerGuid) const
bool Transmogrification::IsAllowedQuality(uint32 quality, ObjectGuid const &playerGuid) const
{
switch (quality)
{
@@ -1053,6 +1053,11 @@ void Transmogrification::LoadConfig(bool reload)
for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) {
MembershipIdsLegendary.push_back(Acore::StringTo<uint32>(itr).value());
}
stringMembershipIds = sConfigMgr->GetOption<std::string>("Transmogrification.MembershipLevelsPet", "");
for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) {
MembershipIdsPet.push_back(Acore::StringTo<uint32>(itr).value());
}
}
void Transmogrification::DeleteFakeFromDB(ObjectGuid::LowType itemLowGuid, CharacterDatabaseTransaction* trans /*= nullptr*/)
@@ -1071,68 +1076,77 @@ void Transmogrification::DeleteFakeFromDB(ObjectGuid::LowType itemLowGuid, Chara
CharacterDatabase.Execute("DELETE FROM custom_transmogrification WHERE GUID = {}", itemGUID.GetCounter());
}
bool Transmogrification::isPlusWhiteGreyEligible(ObjectGuid::LowType playerGuid) const {
if (!IsTransmogPlusEnabled) {
return false;
}
uint32 Transmogrification::getPlayerMembershipLevel(ObjectGuid const & playerGuid) const {
CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(playerGuid);
if (!playerData)
return 0;
if (MembershipIds.size() == 0) {
uint32 accountId = playerData->AccountId;
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)
return (*resultAcc)[0].Get<uint32>();
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) {
if (membershipLevel == 0)
return false;
}
for (const auto& itr : MembershipIds)
{
if (itr == membershipLevel) {
if (itr == membershipLevel)
return true;
}
}
return false;
}
bool Transmogrification::isPlusLegendaryEligible(ObjectGuid::LowType playerGuid) const {
if (!IsTransmogPlusEnabled) {
bool Transmogrification::isPlusLegendaryEligible(ObjectGuid const & playerGuid) const {
if (!IsTransmogPlusEnabled)
return false;
}
if (MembershipIdsLegendary.size() == 0) {
if (MembershipIdsLegendary.size() == 0)
return false;
}
const auto membershipLevel = getPlayerMembershipLevel(playerGuid);
if (membershipLevel == 0) {
if (membershipLevel == 0)
return false;
}
for (const auto& itr : MembershipIdsLegendary)
{
if (itr == membershipLevel) {
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);
bool Transmogrification::isTransmogPlusPetEligible(ObjectGuid const & playerGuid) const {
if (MembershipIdsPet.size() == 0)
return false;
if (resultAcc) {
return (*resultAcc)[0].Get<uint32>();
}
const auto membershipLevel = getPlayerMembershipLevel(playerGuid);
if (membershipLevel == 0)
return false;
for (const auto& itr : MembershipIdsPet)
{
if (itr == membershipLevel)
return true;
}
return 0;
return false;
}
bool Transmogrification::GetEnableTransmogInfo() const

View File

@@ -161,7 +161,7 @@ public:
bool IsAllowed(uint32 entry) const;
bool IsNotAllowed(uint32 entry) const;
bool IsAllowedQuality(uint32 quality, ObjectGuid::LowType playerGuid) const;
bool IsAllowedQuality(uint32 quality, ObjectGuid const & playerGuid) const;
bool IsRangedWeapon(uint32 Class, uint32 SubClass) const;
bool CanNeverTransmog(ItemTemplate const* itemTemplate);
@@ -184,7 +184,7 @@ public:
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, ObjectGuid::LowType playerGuid) const;
bool IsItemTransmogrifiable(ItemTemplate const* proto, ObjectGuid const &playerGuid) const;
uint32 GetSpecialPrice(ItemTemplate const* proto) const;
void DeleteFakeFromDB(ObjectGuid::LowType itemLowGuid, CharacterDatabaseTransaction* trans = nullptr);
@@ -216,9 +216,12 @@ public:
bool IsTransmogPlusEnabled;
std::vector<uint32> MembershipIds;
std::vector<uint32> MembershipIdsLegendary;
bool isPlusWhiteGreyEligible(ObjectGuid::LowType playerGuid) const;
bool isPlusLegendaryEligible(ObjectGuid::LowType playerGuid) const;
uint32 getPlayerMembershipLevel(ObjectGuid::LowType playerGuid) const;
std::vector<uint32> MembershipIdsPet;
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()

View File

@@ -43,7 +43,7 @@ public:
{ "add", addCollectionTable },
{ "", HandleDisableTransMogVisual, SEC_PLAYER, Console::No },
{ "sync", HandleSyncTransMogCommand, SEC_PLAYER, Console::No },
{ "portable", HandleTransmogPortableCommand, SEC_MODERATOR, Console::No },
{ "portable", HandleTransmogPortableCommand, SEC_PLAYER, Console::No },
};
static ChatCommandTable commandTable =
@@ -304,8 +304,21 @@ public:
if (Player* player = PlayerIdentifier::FromSelf(handler)->GetConnectedPlayer())
{
if (sTransmogrification->IsTransmogPlusEnabled) {
if (sTransmogrification->isTransmogPlusPetEligible(player->GetGUID())) {
player->CastSpell((Unit*)nullptr, SPELL_SUMMON_ETHEREAL_WARPWEAVER, true);
return true;
}
}
if (player->GetSession()->GetSecurity() < SEC_MODERATOR) {
return true;
}
player->CastSpell((Unit*)nullptr, SPELL_SUMMON_ETHEREAL_WARPWEAVER, true);
}
return true;
};
};