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

Feature: Added GetUnitFlags(), GetUnitFlagsTwo(), SetUnitFlags(flags), SetUnitFlagsTwo(flags), Added PlayerEvent OnApplyAura/OnRemoveAura #137

Merged
merged 14 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
50 changes: 50 additions & 0 deletions src/LuaEngine/CreatureMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,31 @@ auto const& threatlist = creature->GetThreatMgr().GetThreatList();
Eluna::Push(L, creature->GetUInt32Value(UNIT_NPC_FLAGS));
return 1;
}

/**
* Returns the [Creature]'s Unit flags.
*
* These are used to control whether the NPC is attackable or not as well as many other different things,
*
*
* @return [unit_flags] unitFlags
*/
New-HavenWotLK marked this conversation as resolved.
Show resolved Hide resolved
int GetUnitFlags(lua_State* L, Creature* creature)
{
Eluna::Push(L, creature->GetUInt32Value(UNIT_FIELD_FLAGS));
return 1;
}

/**
* Returns the [Creature]'s Unit flags 2.
*
* @return [unit_flags2] unitFlags2
*/
New-HavenWotLK marked this conversation as resolved.
Show resolved Hide resolved
int GetUnitFlagsTwo(lua_State* L, Creature* creature)
{
Eluna::Push(L, creature->GetUInt32Value(UNIT_FIELD_FLAGS_2));
return 1;
}

/**
* Returns the [Creature]'s Extra flags.
Expand All @@ -923,6 +948,7 @@ auto const& threatlist = creature->GetThreatMgr().GetThreatList();
*
* @return [ExtraFlags] extraFlags
*/

New-HavenWotLK marked this conversation as resolved.
Show resolved Hide resolved
int GetExtraFlags(lua_State* L, Creature* creature)
{
#if defined(TRINITY) || defined(AZEROTHCORE)
Expand Down Expand Up @@ -982,6 +1008,30 @@ auto const& threatlist = creature->GetThreatMgr().GetThreatList();
creature->SetUInt32Value(UNIT_NPC_FLAGS, flags);
return 0;
}

/**
* Sets the [Creature]'s UNIT flags to `flags`.
*
* @param [unit_flags] flags
*/
New-HavenWotLK marked this conversation as resolved.
Show resolved Hide resolved
int SetUnitFlags(lua_State* L, Creature* creature)
{
uint32 flags = Eluna::CHECKVAL<uint32>(L, 2);
creature->SetUInt32Value(UNIT_FIELD_FLAGS, flags);
return 0;
}

/**
* Sets the [Creature]'s UNIT flags2 to `flags`.
*
* @param [unit_flags2] flags
*/
New-HavenWotLK marked this conversation as resolved.
Show resolved Hide resolved
int SetUnitFlagsTwo(lua_State* L, Creature* creature)
{
uint32 flags = Eluna::CHECKVAL<uint32>(L, 2);
creature->SetUInt32Value(UNIT_FIELD_FLAGS_2, flags);
return 0;
}

#if defined(TRINITY) || defined(AZEROTHCORE)
/**
Expand Down
4 changes: 3 additions & 1 deletion src/LuaEngine/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ namespace Hooks
PLAYER_EVENT_ON_COMPLETE_QUEST = 54, // (event, player, quest)
PLAYER_EVENT_ON_CAN_GROUP_INVITE = 55, // (event, player, memberName) - Can return false to prevent inviting
PLAYER_EVENT_ON_GROUP_ROLL_REWARD_ITEM = 56, // (event, player, item, count, voteType, roll)

PLAYER_EVENT_ON_APPLY_AURA = 57, // (event, player, aura, isNewAura)
PLAYER_EVENT_ON_REMOVE_AURA = 58, // (event, player, aura, isExpired)

PLAYER_EVENT_COUNT
};

Expand Down
4 changes: 4 additions & 0 deletions src/LuaEngine/LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,8 @@ ElunaRegister<Creature> CreatureMethods[] =
{ "GetLootRecipient", &LuaCreature::GetLootRecipient },
{ "GetLootRecipientGroup", &LuaCreature::GetLootRecipientGroup },
{ "GetNPCFlags", &LuaCreature::GetNPCFlags },
{ "GetUnitFlags", &LuaCreature::GetUnitFlags },
{ "GetUnitFlagsTwo", &LuaCreature::GetUnitFlagsTwo },
{ "GetExtraFlags", &LuaCreature::GetExtraFlags },
#if defined(CLASSIC) || defined(TBC) || defined(WOTLK)
{ "GetShieldBlockValue", &LuaCreature::GetShieldBlockValue },
Expand All @@ -838,6 +840,8 @@ ElunaRegister<Creature> CreatureMethods[] =
{ "SetLootMode", &LuaCreature::SetLootMode },
#endif
{ "SetNPCFlags", &LuaCreature::SetNPCFlags },
{ "SetUnitFlags", &LuaCreature::SetUnitFlags },
{ "SetUnitFlagsTwo", &LuaCreature::SetUnitFlagsTwo },
#if defined(TRINITY) || AZEROTHCORE
{ "SetReactState", &LuaCreature::SetReactState },
#endif
Expand Down
18 changes: 18 additions & 0 deletions src/LuaEngine/PlayerHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,3 +690,21 @@ void Eluna::OnGroupRollRewardItem(Player* player, Item* item, uint32 count, Roll
Push(roll);
CallAllFunctions(PlayerEventBindings, key);
}

void Eluna::OnApplyAura(Player* player, Aura* aura, bool isNewAura)
{
START_HOOK(PLAYER_EVENT_ON_APPLY_AURA);
Push(player);
Push(aura);
Push(isNewAura);
CallAllFunctions(PlayerEventBindings, key);
}

void Eluna::OnRemoveAura(Player* player, Aura* aura, bool isExpired)
{
START_HOOK(PLAYER_EVENT_ON_REMOVE_AURA);
Push(player);
Push(aura);
Push(isExpired);
CallAllFunctions(PlayerEventBindings, key);
}