From 2b8193eca1dff04177b53c566817bc60e8b020df Mon Sep 17 00:00:00 2001 From: Isaac Strong Date: Wed, 21 Aug 2024 02:19:31 -0700 Subject: [PATCH] fix(SoloCraft): Limit XP modification to instances only (#49) ## Changes Proposed This PR addresses an issue in the SoloCraft module where XP modification was being applied to all players, regardless of whether they were in an instance or not. The changes include: 1. Implemented a system to track whether players are in instances or not. 2. Modified the XP calculation to only apply when players are in instances (dungeons or raids). 3. Fixed build errors related to the use of ObjectGuid. ## Implementation Details - Added a `std::map` to track players' instance status. - Implemented `OnMapChanged` to update players' instance status. - Modified `OnGiveXP` to check instance status before applying XP modifications. - Updated `OnLogout` to clean up instance tracking data. ## How to Test 1. Enable the SoloCraft module. 2. Enter a dungeon or raid and kill some mobs. Verify that XP is modified as expected. 3. Exit the instance and kill mobs in the open world. Verify that XP is not modified. 4. Re-enter an instance and confirm that XP modification resumes. ## Issues Addressed This PR fixes the issue where XP modification was being applied globally, even outside of instances. --- src/Solocraft.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Solocraft.cpp b/src/Solocraft.cpp index cc85459..59410f5 100644 --- a/src/Solocraft.cpp +++ b/src/Solocraft.cpp @@ -11,6 +11,7 @@ #include "Chat.h" #include #include +#include "ObjectGuid.h" bool SoloCraftEnable = 1; bool SoloCraftAnnounceModule = 1; @@ -309,6 +310,9 @@ class SolocraftConfig : public WorldScript class SolocraftAnnounce : public PlayerScript { +private: + std::map playerInInstanceMap; + public: SolocraftAnnounce() : PlayerScript("SolocraftAnnounce") {} @@ -328,11 +332,24 @@ class SolocraftAnnounce : public PlayerScript //Remove database entry as the player has logged out CharacterDatabase.Execute("DELETE FROM `custom_solocraft_character_stats` WHERE `GUID`={}", player->GetGUID().GetCounter()); } + playerInInstanceMap.erase(player->GetGUID()); + } + + void OnMapChanged(Player* player) override + { + if (player->GetMap()->IsDungeon() || player->GetMap()->IsRaid()) + { + playerInInstanceMap[player->GetGUID()] = true; + } + else + { + playerInInstanceMap[player->GetGUID()] = false; + } } - void OnGiveXP(Player* /*player*/, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override + void OnGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override { - if (SolocraftXPBalEnabled) + if (SolocraftXPBalEnabled && playerInInstanceMap[player->GetGUID()]) { // Decrease Experience based on number of players and difficulty of instance (0 to 100%) amount = uint32(amount * SoloCraftXPMod);