diff --git a/README.md b/README.md index 715c73469f..da84ed8603 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/src/ElunaLuaEngine_SC.cpp b/src/ElunaLuaEngine_SC.cpp index 343de8b752..05744e51f6 100644 --- a/src/ElunaLuaEngine_SC.cpp +++ b/src/ElunaLuaEngine_SC.cpp @@ -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 diff --git a/src/LuaEngine/CreatureMethods.h b/src/LuaEngine/CreatureMethods.h index ce8bb1b881..bc5ecdb0e1 100644 --- a/src/LuaEngine/CreatureMethods.h +++ b/src/LuaEngine/CreatureMethods.h @@ -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. @@ -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(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(L, 2); + creature->SetUInt32Value(UNIT_FIELD_FLAGS_2, flags); + return 0; + } #if defined(TRINITY) || defined(AZEROTHCORE) /** diff --git a/src/LuaEngine/GlobalMethods.h b/src/LuaEngine/GlobalMethods.h index 0bd2735c23..8545f737b9 100644 --- a/src/LuaEngine/GlobalMethods.h +++ b/src/LuaEngine/GlobalMethods.h @@ -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) * }; * * diff --git a/src/LuaEngine/Hooks.h b/src/LuaEngine/Hooks.h index 11b61fd060..6166ce3ddf 100644 --- a/src/LuaEngine/Hooks.h +++ b/src/LuaEngine/Hooks.h @@ -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 }; diff --git a/src/LuaEngine/LuaEngine.h b/src/LuaEngine/LuaEngine.h index f9d300dd15..62c880e705 100644 --- a/src/LuaEngine/LuaEngine.h +++ b/src/LuaEngine/LuaEngine.h @@ -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 diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index 8374986748..7e3b6b9ebc 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -813,6 +813,8 @@ ElunaRegister 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 }, @@ -838,6 +840,8 @@ ElunaRegister CreatureMethods[] = { "SetLootMode", &LuaCreature::SetLootMode }, #endif { "SetNPCFlags", &LuaCreature::SetNPCFlags }, + { "SetUnitFlags", &LuaCreature::SetUnitFlags }, + { "SetUnitFlagsTwo", &LuaCreature::SetUnitFlagsTwo }, #if defined(TRINITY) || AZEROTHCORE { "SetReactState", &LuaCreature::SetReactState }, #endif diff --git a/src/LuaEngine/PlayerHooks.cpp b/src/LuaEngine/PlayerHooks.cpp index bd9bca2355..4e7acfdb22 100644 --- a/src/LuaEngine/PlayerHooks.cpp +++ b/src/LuaEngine/PlayerHooks.cpp @@ -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); +}