diff --git a/src/ElunaLuaEngine_SC.cpp b/src/ElunaLuaEngine_SC.cpp index bc3e7d8..f11f47f 100644 --- a/src/ElunaLuaEngine_SC.cpp +++ b/src/ElunaLuaEngine_SC.cpp @@ -813,6 +813,21 @@ public: sEluna->OnCreatureKilledByPet(player, killed); } + bool OnPlayerCanUpdateSkill(Player* player, uint32 skill_id) override + { + return sEluna->OnPlayerCanUpdateSkill(player, skill_id); + } + + void OnPlayerBeforeUpdateSkill(Player* player, uint32 skill_id, uint32& value, uint32 max, uint32 step) override + { + sEluna->OnPlayerBeforeUpdateSkill(player, skill_id, value, max, step); + } + + void OnPlayerUpdateSkill(Player* player, uint32 skill_id, uint32 value, uint32 max, uint32 step, uint32 new_value) override + { + sEluna->OnPlayerUpdateSkill(player, skill_id, value, max, step, new_value); + } + bool OnPlayerCanResurrect(Player* player) override { return sEluna->CanPlayerResurrect(player); diff --git a/src/LuaEngine/Hooks.h b/src/LuaEngine/Hooks.h index 7d8599c..da72aad 100644 --- a/src/LuaEngine/Hooks.h +++ b/src/LuaEngine/Hooks.h @@ -223,6 +223,9 @@ namespace Hooks PLAYER_EVENT_ON_BG_DESERTION = 57, // (event, player, type) PLAYER_EVENT_ON_PET_KILL = 58, // (event, player, killer) PLAYER_EVENT_ON_CAN_RESURRECT = 59, // (event, player) + PLAYER_EVENT_ON_CAN_UPDATE_SKILL = 60, // (event, player, skill_id) -- Can return true or false + PLAYER_EVENT_ON_BEFORE_UPDATE_SKILL = 61, // (event, player, skill_id, value, max, step) -- Can return new amount + PLAYER_EVENT_ON_UPDATE_SKILL = 62, // (event, player, skill_id, value, max, step, new_value) PLAYER_EVENT_COUNT }; diff --git a/src/LuaEngine/LuaEngine.h b/src/LuaEngine/LuaEngine.h index e582992..999fb03 100644 --- a/src/LuaEngine/LuaEngine.h +++ b/src/LuaEngine/LuaEngine.h @@ -453,6 +453,9 @@ public: void OnGroupRollRewardItem(Player* player, Item* item, uint32 count, RollVote voteType, Roll* roll); void OnBattlegroundDesertion(Player* player, const BattlegroundDesertionType type); void OnCreatureKilledByPet(Player* player, Creature* killed); + bool OnPlayerCanUpdateSkill(Player* player, uint32 skill_id); + void OnPlayerBeforeUpdateSkill(Player* player, uint32 skill_id, uint32& value, uint32 max, uint32 step); + void OnPlayerUpdateSkill(Player* player, uint32 skill_id, uint32 value, uint32 max, uint32 step, uint32 new_value); bool CanPlayerResurrect(Player* player); /* Vehicle */ diff --git a/src/LuaEngine/hooks/PlayerHooks.cpp b/src/LuaEngine/hooks/PlayerHooks.cpp index f8ff479..08823dd 100644 --- a/src/LuaEngine/hooks/PlayerHooks.cpp +++ b/src/LuaEngine/hooks/PlayerHooks.cpp @@ -707,10 +707,57 @@ void Eluna::OnCreatureKilledByPet(Player* player, Creature* killed) CallAllFunctions(PlayerEventBindings, key); } +bool Eluna::OnPlayerCanUpdateSkill(Player* player, uint32 skill_id) +{ + START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_CAN_UPDATE_SKILL, true); + Push(player); + Push(skill_id); + return CallAllFunctionsBool(PlayerEventBindings, key); +} + +void Eluna::OnPlayerBeforeUpdateSkill(Player* player, uint32 skill_id, uint32& value, uint32 max, uint32 step) +{ + START_HOOK(PLAYER_EVENT_ON_BEFORE_UPDATE_SKILL); + Push(player); + Push(skill_id); + Push(value); + Push(max); + Push(step); + + int valueIndex = lua_gettop(L) -2; + int n = SetupStack(PlayerEventBindings, key, 5); + while (n > 0) + { + int r = CallOneFunction(n--, 5, 1); + if (lua_isnumber(L, r)) + { + value = CHECKVAL(L, r); + // Update the stack for subsequent calls. + ReplaceArgument(value, valueIndex); + } + + lua_pop(L, 1); + } + + CleanUpStack(5); +} + +void Eluna::OnPlayerUpdateSkill(Player* player, uint32 skill_id, uint32 value, uint32 max, uint32 step, uint32 new_value) +{ + START_HOOK(PLAYER_EVENT_ON_UPDATE_SKILL); + Push(player); + Push(skill_id); + Push(value); + Push(max); + Push(step); + Push(new_value); + CallAllFunctions(PlayerEventBindings, key); +} + + bool Eluna::CanPlayerResurrect(Player* player) { START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_CAN_RESURRECT, true); Push(player); return CallAllFunctionsBool(PlayerEventBindings, key); } -