feat(Core/Hooks): Add parameter to detect XP origin for OnGiveXP hook. (#16109)

Added enum parameter to detect where XP originated from.
This commit is contained in:
AnchyDev
2023-05-06 11:39:36 +10:00
committed by GitHub
parent d7190451cf
commit 444793346d
6 changed files with 22 additions and 7 deletions

View File

@@ -166,6 +166,7 @@ void KillRewarder::_RewardXP(Player* player, float rate)
AddPct(xp, (*i)->GetAmount());
// 4.2.3. Give XP to player.
sScriptMgr->OnGivePlayerXP(player, xp, _victim, PlayerXPSource::XPSOURCE_KILL);
player->GiveXP(xp, _victim, _groupRate);
if (Pet* pet = player->GetPet())
// 4.2.4. If player has pet, reward pet with XP (100% for single player, 50% for group case).

View File

@@ -2372,8 +2372,6 @@ void Player::GiveXP(uint32 xp, Unit* victim, float group_rate, bool isLFGReward)
uint8 level = GetLevel();
sScriptMgr->OnGivePlayerXP(this, xp, victim);
// Favored experience increase START
uint32 zone = GetZoneId();
float favored_exp_mult = 0;
@@ -5730,6 +5728,7 @@ void Player::CheckAreaExploreAndOutdoor()
XP = uint32(sObjectMgr->GetBaseXP(areaEntry->area_level) * sWorld->getRate(RATE_XP_EXPLORE));
}
sScriptMgr->OnGivePlayerXP(this, XP, nullptr, PlayerXPSource::XPSOURCE_EXPLORE);
GiveXP(XP, nullptr);
SendExplorationExperience(areaId, XP);
}
@@ -6119,7 +6118,11 @@ bool Player::RewardHonor(Unit* uVictim, uint32 groupsize, int32 honor, bool awar
bg->UpdatePlayerScore(this, SCORE_BONUS_HONOR, honor, false); //false: prevent looping
// Xinef: Only for BG activities
if (!uVictim)
GiveXP(uint32(honor * (3 + GetLevel() * 0.30f)), nullptr);
{
uint32 xp = uint32(honor * (3 + GetLevel() * 0.30f));
sScriptMgr->OnGivePlayerXP(this, xp, nullptr, PlayerXPSource::XPSOURCE_BATTLEGROUND);
GiveXP(xp, nullptr);
}
}
if (sWorld->getBoolConfig(CONFIG_PVP_TOKEN_ENABLE))

View File

@@ -995,6 +995,16 @@ enum PlayerCommandStates
CHEAT_WATERWALK = 0x10
};
// Used for OnGiveXP PlayerScript hook
enum PlayerXPSource
{
XPSOURCE_KILL = 0,
XPSOURCE_QUEST = 1,
XPSOURCE_QUEST_DF = 2,
XPSOURCE_EXPLORE = 3,
XPSOURCE_BATTLEGROUND = 4
};
enum InstantFlightGossipAction
{
GOSSIP_ACTION_TOGGLE_INSTANT_FLIGHT = 500

View File

@@ -756,6 +756,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
}
else
{
sScriptMgr->OnGivePlayerXP(this, XP, nullptr, isLFGReward ? PlayerXPSource::XPSOURCE_QUEST_DF : PlayerXPSource::XPSOURCE_QUEST);
GiveXP(XP, nullptr, isLFGReward);
}

View File

@@ -154,11 +154,11 @@ void ScriptMgr::OnBeforeLootMoney(Player* player, Loot* loot)
});
}
void ScriptMgr::OnGivePlayerXP(Player* player, uint32& amount, Unit* victim)
void ScriptMgr::OnGivePlayerXP(Player* player, uint32& amount, Unit* victim, uint8 xpSource)
{
ExecuteScript<PlayerScript>([&](PlayerScript* script)
{
script->OnGiveXP(player, amount, victim);
script->OnGiveXP(player, amount, victim, xpSource);
});
}

View File

@@ -1035,7 +1035,7 @@ public:
virtual void OnBeforeLootMoney(Player* /*player*/, Loot* /*loot*/) {}
// Called when a player gains XP (before anything is given)
virtual void OnGiveXP(Player* /*player*/, uint32& /*amount*/, Unit* /*victim*/) { }
virtual void OnGiveXP(Player* /*player*/, uint32& /*amount*/, Unit* /*victim*/, uint8 /*xpSource*/) { }
// Called when a player's reputation changes (before it is actually changed)
virtual bool OnReputationChange(Player* /*player*/, uint32 /*factionID*/, int32& /*standing*/, bool /*incremental*/) { return true; }
@@ -2240,7 +2240,7 @@ public: /* PlayerScript */
void OnPlayerTalentsReset(Player* player, bool noCost);
void OnPlayerMoneyChanged(Player* player, int32& amount);
void OnBeforeLootMoney(Player* player, Loot* loot);
void OnGivePlayerXP(Player* player, uint32& amount, Unit* victim);
void OnGivePlayerXP(Player* player, uint32& amount, Unit* victim, uint8 xpSource);
bool OnPlayerReputationChange(Player* player, uint32 factionID, int32& standing, bool incremental);
void OnPlayerReputationRankChange(Player* player, uint32 factionID, ReputationRank newRank, ReputationRank oldRank, bool increased);
void OnPlayerLearnSpell(Player* player, uint32 spellID);