Skip to content

Commit

Permalink
fix(SoloCraft): Limit XP modification to instances only (#49)
Browse files Browse the repository at this point in the history
## 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<ObjectGuid, bool>` 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.
  • Loading branch information
Hotschmoe committed Aug 21, 2024
1 parent de2eda4 commit 2b8193e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Solocraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Chat.h"
#include <math.h>
#include <unordered_map>
#include "ObjectGuid.h"

bool SoloCraftEnable = 1;
bool SoloCraftAnnounceModule = 1;
Expand Down Expand Up @@ -309,6 +310,9 @@ class SolocraftConfig : public WorldScript

class SolocraftAnnounce : public PlayerScript
{
private:
std::map<ObjectGuid, bool> playerInInstanceMap;

public:
SolocraftAnnounce() : PlayerScript("SolocraftAnnounce") {}

Expand All @@ -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);
Expand Down

0 comments on commit 2b8193e

Please sign in to comment.