mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
feat(LuaEngine/PlayerHooks): add skill-based player events (#238)
Co-authored-by: 55Honey <71938210+55Honey@users.noreply.github.com>
This commit is contained in:
@@ -813,6 +813,21 @@ public:
|
|||||||
sEluna->OnCreatureKilledByPet(player, killed);
|
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
|
bool OnPlayerCanResurrect(Player* player) override
|
||||||
{
|
{
|
||||||
return sEluna->CanPlayerResurrect(player);
|
return sEluna->CanPlayerResurrect(player);
|
||||||
|
|||||||
@@ -223,6 +223,9 @@ namespace Hooks
|
|||||||
PLAYER_EVENT_ON_BG_DESERTION = 57, // (event, player, type)
|
PLAYER_EVENT_ON_BG_DESERTION = 57, // (event, player, type)
|
||||||
PLAYER_EVENT_ON_PET_KILL = 58, // (event, player, killer)
|
PLAYER_EVENT_ON_PET_KILL = 58, // (event, player, killer)
|
||||||
PLAYER_EVENT_ON_CAN_RESURRECT = 59, // (event, player)
|
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
|
PLAYER_EVENT_COUNT
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -453,6 +453,9 @@ public:
|
|||||||
void OnGroupRollRewardItem(Player* player, Item* item, uint32 count, RollVote voteType, Roll* roll);
|
void OnGroupRollRewardItem(Player* player, Item* item, uint32 count, RollVote voteType, Roll* roll);
|
||||||
void OnBattlegroundDesertion(Player* player, const BattlegroundDesertionType type);
|
void OnBattlegroundDesertion(Player* player, const BattlegroundDesertionType type);
|
||||||
void OnCreatureKilledByPet(Player* player, Creature* killed);
|
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);
|
bool CanPlayerResurrect(Player* player);
|
||||||
|
|
||||||
/* Vehicle */
|
/* Vehicle */
|
||||||
|
|||||||
@@ -707,10 +707,57 @@ void Eluna::OnCreatureKilledByPet(Player* player, Creature* killed)
|
|||||||
CallAllFunctions(PlayerEventBindings, key);
|
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)
|
bool Eluna::CanPlayerResurrect(Player* player)
|
||||||
{
|
{
|
||||||
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_CAN_RESURRECT, true);
|
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_CAN_RESURRECT, true);
|
||||||
Push(player);
|
Push(player);
|
||||||
return CallAllFunctionsBool(PlayerEventBindings, key);
|
return CallAllFunctionsBool(PlayerEventBindings, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user