feat(LuaEngine/PlayerHooks): add skill-based player events (#238)

Co-authored-by: 55Honey <71938210+55Honey@users.noreply.github.com>
This commit is contained in:
iThorgrim
2025-02-20 14:30:20 +01:00
committed by GitHub
parent ae6bb06b50
commit cbe1621b48
4 changed files with 69 additions and 1 deletions

View File

@@ -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);

View File

@@ -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
};

View File

@@ -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 */

View File

@@ -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<uint32>(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);
}