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
@@ -166,6 +166,7 @@ void KillRewarder::_RewardXP(Player* player, float rate)
AddPct(xp, (*i)->GetAmount()); AddPct(xp, (*i)->GetAmount());
// 4.2.3. Give XP to player. // 4.2.3. Give XP to player.
sScriptMgr->OnGivePlayerXP(player, xp, _victim, PlayerXPSource::XPSOURCE_KILL);
player->GiveXP(xp, _victim, _groupRate); player->GiveXP(xp, _victim, _groupRate);
if (Pet* pet = player->GetPet()) if (Pet* pet = player->GetPet())
// 4.2.4. If player has pet, reward pet with XP (100% for single player, 50% for group case). // 4.2.4. If player has pet, reward pet with XP (100% for single player, 50% for group case).
+6 -3
View File
@@ -2372,8 +2372,6 @@ void Player::GiveXP(uint32 xp, Unit* victim, float group_rate, bool isLFGReward)
uint8 level = GetLevel(); uint8 level = GetLevel();
sScriptMgr->OnGivePlayerXP(this, xp, victim);
// Favored experience increase START // Favored experience increase START
uint32 zone = GetZoneId(); uint32 zone = GetZoneId();
float favored_exp_mult = 0; float favored_exp_mult = 0;
@@ -5730,6 +5728,7 @@ void Player::CheckAreaExploreAndOutdoor()
XP = uint32(sObjectMgr->GetBaseXP(areaEntry->area_level) * sWorld->getRate(RATE_XP_EXPLORE)); XP = uint32(sObjectMgr->GetBaseXP(areaEntry->area_level) * sWorld->getRate(RATE_XP_EXPLORE));
} }
sScriptMgr->OnGivePlayerXP(this, XP, nullptr, PlayerXPSource::XPSOURCE_EXPLORE);
GiveXP(XP, nullptr); GiveXP(XP, nullptr);
SendExplorationExperience(areaId, XP); 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 bg->UpdatePlayerScore(this, SCORE_BONUS_HONOR, honor, false); //false: prevent looping
// Xinef: Only for BG activities // Xinef: Only for BG activities
if (!uVictim) 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)) if (sWorld->getBoolConfig(CONFIG_PVP_TOKEN_ENABLE))
+10
View File
@@ -995,6 +995,16 @@ enum PlayerCommandStates
CHEAT_WATERWALK = 0x10 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 enum InstantFlightGossipAction
{ {
GOSSIP_ACTION_TOGGLE_INSTANT_FLIGHT = 500 GOSSIP_ACTION_TOGGLE_INSTANT_FLIGHT = 500
@@ -756,6 +756,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
} }
else else
{ {
sScriptMgr->OnGivePlayerXP(this, XP, nullptr, isLFGReward ? PlayerXPSource::XPSOURCE_QUEST_DF : PlayerXPSource::XPSOURCE_QUEST);
GiveXP(XP, nullptr, isLFGReward); GiveXP(XP, nullptr, isLFGReward);
} }
@@ -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) ExecuteScript<PlayerScript>([&](PlayerScript* script)
{ {
script->OnGiveXP(player, amount, victim); script->OnGiveXP(player, amount, victim, xpSource);
}); });
} }
+2 -2
View File
@@ -1035,7 +1035,7 @@ public:
virtual void OnBeforeLootMoney(Player* /*player*/, Loot* /*loot*/) {} virtual void OnBeforeLootMoney(Player* /*player*/, Loot* /*loot*/) {}
// Called when a player gains XP (before anything is given) // 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) // 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; } 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 OnPlayerTalentsReset(Player* player, bool noCost);
void OnPlayerMoneyChanged(Player* player, int32& amount); void OnPlayerMoneyChanged(Player* player, int32& amount);
void OnBeforeLootMoney(Player* player, Loot* loot); 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); bool OnPlayerReputationChange(Player* player, uint32 factionID, int32& standing, bool incremental);
void OnPlayerReputationRankChange(Player* player, uint32 factionID, ReputationRank newRank, ReputationRank oldRank, bool increased); void OnPlayerReputationRankChange(Player* player, uint32 factionID, ReputationRank newRank, ReputationRank oldRank, bool increased);
void OnPlayerLearnSpell(Player* player, uint32 spellID); void OnPlayerLearnSpell(Player* player, uint32 spellID);