feature: add GetUnitFlags(), GetUnitFlagsTwo(), SetUnitFlags(flags), SetUnitFlagsTwo(flags), PlayerEvent OnApplyAura/OnRemoveAura (#137)

This commit is contained in:
Krisande
2023-05-21 14:05:59 +02:00
committed by GitHub
parent 8bcec886b9
commit 92818c6311
8 changed files with 93 additions and 1 deletions

View File

@@ -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` `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` `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` `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:GetMailCount()`: https://github.com/azerothcore/mod-eluna/pull/76
- Added `Player:GetXP()`: https://github.com/azerothcore/mod-eluna/pull/77 - Added `Player:GetXP()`: https://github.com/azerothcore/mod-eluna/pull/77
- Added `Player:GetAchievementCriteriaProgress()`: https://github.com/azerothcore/mod-eluna/pull/78 - 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:ModifyThreatPct()`: https://github.com/azerothcore/mod-eluna/pull/25
- Added `Unit:GetAttackers()`: https://github.com/azerothcore/mod-eluna/pull/116 - Added `Unit:GetAttackers()`: https://github.com/azerothcore/mod-eluna/pull/116
- Added `Unit:GetThreatList()`: https://github.com/azerothcore/mod-eluna/pull/117 - 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 ### GameObject
- Added `GameObject:AddLoot()` to add loot at runtime to an **empty** container: https://github.com/azerothcore/mod-eluna/pull/52 - Added `GameObject:AddLoot()` to add loot at runtime to an **empty** container: https://github.com/azerothcore/mod-eluna/pull/52

View File

@@ -801,6 +801,16 @@ public:
{ {
return sEluna->OnCanGroupInvite(player, memberName); 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 class Eluna_ServerScript : public ServerScript

View File

@@ -915,6 +915,30 @@ auto const& threatlist = creature->GetThreatMgr().GetThreatList();
return 1; 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. * Returns the [Creature]'s Extra flags.
* *
@@ -983,6 +1007,30 @@ auto const& threatlist = creature->GetThreatMgr().GetThreatList();
return 0; 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) #if defined(TRINITY) || defined(AZEROTHCORE)
/** /**
* Sets the [Creature]'s ReactState to `state`. * Sets the [Creature]'s ReactState to `state`.

View File

@@ -729,6 +729,8 @@ namespace LuaGlobalFunctions
* PLAYER_EVENT_ON_COMPLETE_QUEST = 54, // (event, player, quest) * 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_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_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> * </pre>
* *

View File

@@ -218,6 +218,8 @@ namespace Hooks
PLAYER_EVENT_ON_COMPLETE_QUEST = 54, // (event, player, quest) 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_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_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 PLAYER_EVENT_COUNT
}; };

View File

@@ -487,6 +487,8 @@ public:
bool OnCanJoinLfg(Player* player, uint8 roles, lfg::LfgDungeonSet& dungeons, const std::string& comment); bool OnCanJoinLfg(Player* player, uint8 roles, lfg::LfgDungeonSet& dungeons, const std::string& comment);
bool OnCanGroupInvite(Player* player, std::string& memberName); bool OnCanGroupInvite(Player* player, std::string& memberName);
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 OnApplyAura(Player* player, Aura* aura, bool isNewAura);
void OnRemoveAura(Player* player, Aura* aura, bool isExpired);
#ifndef CLASSIC #ifndef CLASSIC
#ifndef TBC #ifndef TBC

View File

@@ -813,6 +813,8 @@ ElunaRegister<Creature> CreatureMethods[] =
{ "GetLootRecipient", &LuaCreature::GetLootRecipient }, { "GetLootRecipient", &LuaCreature::GetLootRecipient },
{ "GetLootRecipientGroup", &LuaCreature::GetLootRecipientGroup }, { "GetLootRecipientGroup", &LuaCreature::GetLootRecipientGroup },
{ "GetNPCFlags", &LuaCreature::GetNPCFlags }, { "GetNPCFlags", &LuaCreature::GetNPCFlags },
{ "GetUnitFlags", &LuaCreature::GetUnitFlags },
{ "GetUnitFlagsTwo", &LuaCreature::GetUnitFlagsTwo },
{ "GetExtraFlags", &LuaCreature::GetExtraFlags }, { "GetExtraFlags", &LuaCreature::GetExtraFlags },
#if defined(CLASSIC) || defined(TBC) || defined(WOTLK) #if defined(CLASSIC) || defined(TBC) || defined(WOTLK)
{ "GetShieldBlockValue", &LuaCreature::GetShieldBlockValue }, { "GetShieldBlockValue", &LuaCreature::GetShieldBlockValue },
@@ -838,6 +840,8 @@ ElunaRegister<Creature> CreatureMethods[] =
{ "SetLootMode", &LuaCreature::SetLootMode }, { "SetLootMode", &LuaCreature::SetLootMode },
#endif #endif
{ "SetNPCFlags", &LuaCreature::SetNPCFlags }, { "SetNPCFlags", &LuaCreature::SetNPCFlags },
{ "SetUnitFlags", &LuaCreature::SetUnitFlags },
{ "SetUnitFlagsTwo", &LuaCreature::SetUnitFlagsTwo },
#if defined(TRINITY) || AZEROTHCORE #if defined(TRINITY) || AZEROTHCORE
{ "SetReactState", &LuaCreature::SetReactState }, { "SetReactState", &LuaCreature::SetReactState },
#endif #endif

View File

@@ -690,3 +690,21 @@ void Eluna::OnGroupRollRewardItem(Player* player, Item* item, uint32 count, Roll
Push(roll); Push(roll);
CallAllFunctions(PlayerEventBindings, key); 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);
}