Skip to content

Commit

Permalink
feature: add GetUnitFlags(), GetUnitFlagsTwo(), SetUnitFlags(flags), …
Browse files Browse the repository at this point in the history
…SetUnitFlagsTwo(flags), PlayerEvent OnApplyAura/OnRemoveAura (#137)
  • Loading branch information
New-HavenWotLK authored May 21, 2023
1 parent 8bcec88 commit 92818c6
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Eluna API for AC:
- Added `RegisterPlayerEvent` `54` (`PLAYER_EVENT_ON_COMPLETE_QUEST`): https://github.com/azerothcore/mod-eluna/pull/90
- Added `RegisterPlayerEvent` `55` (`PLAYER_EVENT_ON_CAN_GROUP_INVITE`): https://github.com/azerothcore/mod-eluna/pull/100
- Added `RegisterPlayerEvent` `56` (`PLAYER_EVENT_ON_GROUP_ROLL_REWARD_ITEM`): https://github.com/azerothcore/mod-eluna/pull/119
- Added `RegisterPlayerEvent` `57` (`PLAYER_EVENT_ON_APPLY_AURA`): https://github.com/azerothcore/mod-eluna/pull/137
- Added `RegisterPlayerEvent` `58` (`PLAYER_EVENT_ON_REMOVE_AURA`): https://github.com/azerothcore/mod-eluna/pull/137
- Added `Player:GetMailCount()`: https://github.com/azerothcore/mod-eluna/pull/76
- Added `Player:GetXP()`: https://github.com/azerothcore/mod-eluna/pull/77
- Added `Player:GetAchievementCriteriaProgress()`: https://github.com/azerothcore/mod-eluna/pull/78
Expand All @@ -106,6 +108,10 @@ Eluna API for AC:
- Added `Unit:ModifyThreatPct()`: https://github.com/azerothcore/mod-eluna/pull/25
- Added `Unit:GetAttackers()`: https://github.com/azerothcore/mod-eluna/pull/116
- Added `Unit:GetThreatList()`: https://github.com/azerothcore/mod-eluna/pull/117
- Added `Unit:GetUnitFlags()`: https://github.com/azerothcore/mod-eluna/pull/137
- Added `Unit:GetUnitFlagsTwo()`: https://github.com/azerothcore/mod-eluna/pull/137
- Added `Unit:SetUnitFlags(flags)`: https://github.com/azerothcore/mod-eluna/pull/137
- Added `Unit:SetUnitFlagsTwo(flags)`: https://github.com/azerothcore/mod-eluna/pull/137

### GameObject
- Added `GameObject:AddLoot()` to add loot at runtime to an **empty** container: https://github.com/azerothcore/mod-eluna/pull/52
Expand Down
10 changes: 10 additions & 0 deletions src/ElunaLuaEngine_SC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,16 @@ class Eluna_PlayerScript : public PlayerScript
{
return sEluna->OnCanGroupInvite(player, memberName);
}

void OnApplyAura(Player* player, Aura* aura, bool isNewAura)
{
return sEluna->OnApplyAura(player, aura, isNewAura);
}

void OnRemoveAura(Player* player, Aura* aura, bool isExpired)
{
return sEluna->OnRemoveAura(player, aura, isExpired);
}
};

class Eluna_ServerScript : public ServerScript
Expand Down
48 changes: 48 additions & 0 deletions src/LuaEngine/CreatureMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,30 @@ 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, among other things.
*
* @return [UnitFlags] unitFlags
*/
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 [UnitFlags2] unitFlags2
*/
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 Down Expand Up @@ -982,6 +1006,30 @@ auto const& threatlist = creature->GetThreatMgr().GetThreatList();
creature->SetUInt32Value(UNIT_NPC_FLAGS, flags);
return 0;
}

/**
* Sets the [Creature]'s Unit flags to `flags`.
*
* @param [UnitFlags] flags
*/
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 [UnitFlags2] flags
*/
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
2 changes: 2 additions & 0 deletions src/LuaEngine/GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ namespace LuaGlobalFunctions
* 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)
* };
* </pre>
*
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
2 changes: 2 additions & 0 deletions src/LuaEngine/LuaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ class ELUNA_GAME_API Eluna
bool OnCanJoinLfg(Player* player, uint8 roles, lfg::LfgDungeonSet& dungeons, const std::string& comment);
bool OnCanGroupInvite(Player* player, std::string& memberName);
void OnGroupRollRewardItem(Player* player, Item* item, uint32 count, RollVote voteType, Roll* roll);
void OnApplyAura(Player* player, Aura* aura, bool isNewAura);
void OnRemoveAura(Player* player, Aura* aura, bool isExpired);

#ifndef CLASSIC
#ifndef TBC
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);
}

0 comments on commit 92818c6

Please sign in to comment.