Skip to content

Commit

Permalink
feat(Core/Entities): add OnPlayerCanGiveLevel script hook (#21666)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentVanclef authored Mar 10, 2025
1 parent 4cdb315 commit ffe03f6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions src/server/game/Scripting/ScriptDefines/PlayerScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
11 changes: 11 additions & 0 deletions src/server/game/Scripting/ScriptDefines/PlayerScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -782,6 +783,16 @@ class PlayerScript : public ScriptObject
* @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
1 change: 1 addition & 0 deletions src/server/game/Scripting/ScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ class ScriptMgr
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);
Expand Down

0 comments on commit ffe03f6

Please sign in to comment.