feat(Core/Entities): add OnPlayerCanGiveLevel script hook (#21666)

This commit is contained in:
Vincent Vanclef
2025-03-10 08:44:33 +01:00
committed by GitHub
parent 4cdb315db1
commit ffe03f6e14
4 changed files with 20 additions and 0 deletions

View File

@@ -2476,6 +2476,9 @@ void Player::GiveLevel(uint8 level)
if (level == oldLevel)
return;
if (!sScriptMgr->OnPlayerCanGiveLevel(this, level))
return;
if (Guild* guild = GetGuild())
guild->UpdateMemberData(this, GUILD_MEMBER_DATA_LEVEL, level);

View File

@@ -915,6 +915,11 @@ bool ScriptMgr::OnPlayerCanResurrect(Player* player)
CALL_ENABLED_BOOLEAN_HOOKS(PlayerScript, PLAYERHOOK_CAN_RESURRECT, !script->OnPlayerCanResurrect(player));
}
bool ScriptMgr::OnPlayerCanGiveLevel(Player* player, uint8 newLevel)
{
CALL_ENABLED_BOOLEAN_HOOKS(PlayerScript, PLAYERHOOK_ON_CAN_GIVE_LEVEL, !script->OnPlayerCanGiveLevel(player, newLevel));
}
PlayerScript::PlayerScript(const char* name, std::vector<uint16> enabledHooks)
: ScriptObject(name, PLAYERHOOK_END)
{

View File

@@ -208,6 +208,7 @@ enum PlayerHook
PLAYERHOOK_ON_BEFORE_UPDATE_SKILL,
PLAYERHOOK_ON_UPDATE_SKILL,
PLAYERHOOK_CAN_RESURRECT,
PLAYERHOOK_ON_CAN_GIVE_LEVEL,
PLAYERHOOK_END
};
@@ -782,6 +783,16 @@ public:
* @return true if player is authorized to resurect
*/
virtual bool OnPlayerCanResurrect(Player* /*player*/) { return true; }
/**
* @brief This hook is called, to cancel the normal level up flow
*
* @param player Contains information about the Player
* @param newLevel The new level the player is about to be given
*
* @return true if player is allowed to gain the new level
*/
virtual bool OnPlayerCanGiveLevel(Player* /*player*/, uint8 /*newLevel*/) { return true; }
};
#endif

View File

@@ -463,6 +463,7 @@ public: /* PlayerScript */
void OnPlayerBeforeUpdateSkill(Player* player, uint32 skill_id, uint32& value, uint32 max, uint32 step);
void OnPlayerUpdateSkill(Player* player, uint32 skillId, uint32 value, uint32 max, uint32 step, uint32 newValue);
bool OnPlayerCanResurrect(Player* player);
bool OnPlayerCanGiveLevel(Player* player, uint8 newLevel);
// Anti cheat
void AnticheatSetCanFlybyServer(Player* player, bool apply);