From f984be398fe809912e3bcb1d42b07ed29efd1f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefano=20Borz=C3=AC?= Date: Wed, 13 Mar 2024 16:59:48 +0100 Subject: [PATCH] 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 --- conf/transmog.conf.dist | 8 +++- src/Transmogrification.cpp | 80 ++++++++++++++++++++++---------------- src/Transmogrification.h | 13 ++++--- src/cs_transmog.cpp | 15 ++++++- 4 files changed, 76 insertions(+), 40 deletions(-) diff --git a/conf/transmog.conf.dist b/conf/transmog.conf.dist index 1c3bb05..af64e81 100644 --- a/conf/transmog.conf.dist +++ b/conf/transmog.conf.dist @@ -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 = "" # ################################################################################################### diff --git a/src/Transmogrification.cpp b/src/Transmogrification.cpp index 43ed980..6556578 100644 --- a/src/Transmogrification.cpp +++ b/src/Transmogrification.cpp @@ -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(itr).value()); } + + stringMembershipIds = sConfigMgr->GetOption("Transmogrification.MembershipLevelsPet", ""); + for (auto& itr : Acore::Tokenize(stringMembershipIds, ',', false)) { + MembershipIdsPet.push_back(Acore::StringTo(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(); + + 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(); - 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(); - } + 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 diff --git a/src/Transmogrification.h b/src/Transmogrification.h index e22a71d..883151e 100644 --- a/src/Transmogrification.h +++ b/src/Transmogrification.h @@ -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 MembershipIds; std::vector MembershipIdsLegendary; - bool isPlusWhiteGreyEligible(ObjectGuid::LowType playerGuid) const; - bool isPlusLegendaryEligible(ObjectGuid::LowType playerGuid) const; - uint32 getPlayerMembershipLevel(ObjectGuid::LowType playerGuid) const; + std::vector 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() diff --git a/src/cs_transmog.cpp b/src/cs_transmog.cpp index c233367..bb8d8fa 100644 --- a/src/cs_transmog.cpp +++ b/src/cs_transmog.cpp @@ -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; }; };