Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/ElunaLuaEngine_SC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,21 @@ class Eluna_PlayerScript : public PlayerScript
{
sEluna->OnCreatureKilledByPet(player, killed);
}

bool CanPlayerUpdateSkill(Player* player, uint32 skill_id) override
{
return sEluna->OnCanPlayerUpdateSkill(player, skill_id);
}

void OnBeforePlayerUpdateSkill(Player* player, uint32 skill_id, uint32& value, uint32 max, uint32 step) override
{
sEluna->OnBeforePlayerUpdateSkill(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);
}
};

class Eluna_ServerScript : public ServerScript
Expand Down
3 changes: 3 additions & 0 deletions src/LuaEngine/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ namespace Hooks
PLAYER_EVENT_ON_GROUP_ROLL_REWARD_ITEM = 56, // (event, player, item, count, voteType, roll)
PLAYER_EVENT_ON_BG_DESERTION = 57, // (event, player, type)
PLAYER_EVENT_ON_PET_KILL = 58, // (event, player, killer)
PLAYER_EVENT_ON_CAN_UPDATE_SKILL = 59, // (event, player, skill_id) -- Can return true or false
PLAYER_EVENT_ON_BEFORE_UPDATE_SKILL = 60, // (event, player, skill_id, value, max, step) -- Can return new amount
PLAYER_EVENT_ON_UPDATE_SKILL = 61, // (event, player, skill_id, value, max, step, new_value)

PLAYER_EVENT_COUNT
};
Expand Down
3 changes: 3 additions & 0 deletions src/LuaEngine/LuaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ class ELUNA_GAME_API Eluna
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 OnCanPlayerUpdateSkill(Player* player, uint32 skill_id);
void OnBeforePlayerUpdateSkill(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);

/* Vehicle */
void OnInstall(Vehicle* vehicle);
Expand Down
47 changes: 47 additions & 0 deletions src/LuaEngine/hooks/PlayerHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,50 @@ void Eluna::OnCreatureKilledByPet(Player* player, Creature* killed)
Push(killed);
CallAllFunctions(PlayerEventBindings, key);
}

bool Eluna::OnCanPlayerUpdateSkill(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::OnBeforePlayerUpdateSkill(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);
}
Loading