From 1ac74c1fbdbfde44a35a8d5145064ec99d1379f1 Mon Sep 17 00:00:00 2001 From: Skjalf <47818697+Nyeriah@users.noreply.github.com> Date: Sat, 7 Sep 2024 07:52:59 -0300 Subject: [PATCH] refactor: Move handling of memberships to PlayerSettings() --- src/Transmogrification.cpp | 22 ++++++---------------- src/Transmogrification.h | 7 ++++--- src/transmog_scripts.cpp | 21 ++++++++++++--------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/Transmogrification.cpp b/src/Transmogrification.cpp index 5781480c..a9374d2f 100644 --- a/src/Transmogrification.cpp +++ b/src/Transmogrification.cpp @@ -1214,21 +1214,6 @@ void Transmogrification::DeleteFakeFromDB(ObjectGuid::LowType itemLowGuid, Chara CharacterDatabase.Execute("DELETE FROM custom_transmogrification WHERE GUID = {}", itemGUID.GetCounter()); } -uint32 Transmogrification::getPlayerMembershipLevel(ObjectGuid const & playerGuid) const -{ - CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(playerGuid); - if (!playerData) - return 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::IsPlusFeatureEligible(ObjectGuid const &playerGuid, uint32 feature) const { if (!IsTransmogPlusEnabled) @@ -1238,7 +1223,12 @@ bool Transmogrification::IsPlusFeatureEligible(ObjectGuid const &playerGuid, uin if (it == plusDataMap.end() || it->second.empty()) return false; - const auto membershipLevel = getPlayerMembershipLevel(playerGuid); + Player* player = ObjectAccessor::FindConnectedPlayer(playerGuid); + + if (!player) + return false; + + const auto membershipLevel = GetPlayerMembershipLevel(player); if (!membershipLevel) return false; diff --git a/src/Transmogrification.h b/src/Transmogrification.h index 0ee83577..8c910cce 100644 --- a/src/Transmogrification.h +++ b/src/Transmogrification.h @@ -27,8 +27,9 @@ struct ItemTemplate; enum TransmogSettings { - SETTING_HIDE_TRANSMOG = 0, - SETTING_RETROACTIVE_CHECK = 1 + SETTING_HIDE_TRANSMOG = 0, + SETTING_RETROACTIVE_CHECK = 1, + SETTING_TRANSMOG_MEMBERSHIP_LEVEL = 2 }; enum MixedWeaponSettings @@ -270,7 +271,7 @@ class Transmogrification // Transmog Plus bool IsTransmogPlusEnabled; [[nodiscard]] bool IsPlusFeatureEligible(ObjectGuid const& playerGuid, uint32 feature) const; - uint32 getPlayerMembershipLevel(ObjectGuid const & playerGuid) const; + [[nodiscard]] uint32 GetPlayerMembershipLevel(Player* player) const { return player->GetPlayerSetting("mod-transmog", SETTING_TRANSMOG_MEMBERSHIP_LEVEL).value; }; [[nodiscard]] bool IgnoreLevelRequirement(ObjectGuid const& playerGuid) const { return IgnoreReqLevel || IsPlusFeatureEligible(playerGuid, PLUS_FEATURE_SKIP_LEVEL_REQ); } uint32 PetSpellId; diff --git a/src/transmog_scripts.cpp b/src/transmog_scripts.cpp index 4ea413ce..ed3e9711 100644 --- a/src/transmog_scripts.cpp +++ b/src/transmog_scripts.cpp @@ -1120,13 +1120,11 @@ class PS_Transmogrification : public PlayerScript void OnLogin(Player* player) override { if (sT->EnableResetRetroActiveAppearances()) - { player->UpdatePlayerSetting("mod-transmog", SETTING_RETROACTIVE_CHECK, 0); - } + if (sT->EnableRetroActiveAppearances() && !(player->GetPlayerSetting("mod-transmog", SETTING_RETROACTIVE_CHECK).value)) - { CheckRetroActiveQuestAppearances(player); - } + ObjectGuid playerGUID = player->GetGUID(); sT->entryMap.erase(playerGUID); QueryResult result = CharacterDatabase.Query("SELECT GUID, FakeEntry FROM custom_transmogrification WHERE Owner = {}", player->GetGUID().GetCounter()); @@ -1141,11 +1139,6 @@ class PS_Transmogrification : public PlayerScript sT->dataMap[itemGUID] = playerGUID; sT->entryMap[playerGUID][itemGUID] = fakeEntry; } - else - { - //sLog->outError(LOG_FILTER_SQL, "Item entry (Entry: {}, itemGUID: {}, playerGUID: {}) does not exist, ignoring.", fakeEntry, GUID_LOPART(itemGUID), player->GetGUIDLow()); - // CharacterDatabase.Execute("DELETE FROM custom_transmogrification WHERE FakeEntry = {}", fakeEntry); - } } while (result->NextRow()); for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot) @@ -1155,6 +1148,16 @@ class PS_Transmogrification : public PlayerScript } } + uint32 accountId = 0; + + if (player->GetSession()) + accountId = player->GetSession()->GetAccountId(); + + 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) + player->UpdatePlayerSetting("mod-transmog", SETTING_TRANSMOG_MEMBERSHIP_LEVEL, (*resultAcc)[0].Get()); + #ifdef PRESETS if (sT->GetEnableSets()) sT->LoadPlayerSets(playerGUID);