Skip to content

Commit

Permalink
refactor: Move handling of memberships to PlayerSettings() (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyeriah authored Sep 7, 2024
1 parent 3b7bac8 commit d291297
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
22 changes: 6 additions & 16 deletions src/Transmogrification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32>();

return 0;
}

bool Transmogrification::IsPlusFeatureEligible(ObjectGuid const &playerGuid, uint32 feature) const
{
if (!IsTransmogPlusEnabled)
Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/Transmogrification.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 12 additions & 9 deletions src/transmog_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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)
Expand All @@ -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<uint32>());

#ifdef PRESETS
if (sT->GetEnableSets())
sT->LoadPlayerSets(playerGUID);
Expand Down

0 comments on commit d291297

Please sign in to comment.