mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Support for UnitEvent and pass to PlayerEvent or CreatureEvent (#313)
This commit is contained in:
@@ -1191,6 +1191,39 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Eluna_UnitScript : public UnitScript
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Eluna_UnitScript() : UnitScript("Eluna_UnitScript") { }
|
||||||
|
|
||||||
|
void OnAuraApply(Unit* unit, Aura* aura) override
|
||||||
|
{
|
||||||
|
if (unit->IsPlayer())
|
||||||
|
sEluna->OnPlayerAuraApply(unit->ToPlayer(), aura);
|
||||||
|
|
||||||
|
if (unit->IsCreature())
|
||||||
|
sEluna->OnCreatureAuraApply(unit->ToCreature(), aura);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnHeal(Unit* healer, Unit* receiver, uint32& gain) override
|
||||||
|
{
|
||||||
|
if (healer->IsPlayer())
|
||||||
|
sEluna->OnPlayerHeal(healer->ToPlayer(), receiver, gain);
|
||||||
|
|
||||||
|
if (healer->IsCreature())
|
||||||
|
sEluna->OnCreatureHeal(healer->ToCreature(), receiver, gain);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnDamage(Unit* attacker, Unit* receiver, uint32& damage) override
|
||||||
|
{
|
||||||
|
if (attacker->IsPlayer())
|
||||||
|
sEluna->OnPlayerDamage(attacker->ToPlayer(), receiver, damage);
|
||||||
|
|
||||||
|
if (attacker->IsCreature())
|
||||||
|
sEluna->OnCreatureDamage(attacker->ToCreature(), receiver, damage);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Group all custom scripts
|
// Group all custom scripts
|
||||||
void AddSC_ElunaLuaEngine()
|
void AddSC_ElunaLuaEngine()
|
||||||
{
|
{
|
||||||
@@ -1215,4 +1248,5 @@ void AddSC_ElunaLuaEngine()
|
|||||||
new Eluna_VehicleScript();
|
new Eluna_VehicleScript();
|
||||||
new Eluna_WorldObjectScript();
|
new Eluna_WorldObjectScript();
|
||||||
new Eluna_WorldScript();
|
new Eluna_WorldScript();
|
||||||
|
new Eluna_UnitScript();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,10 +226,13 @@ namespace Hooks
|
|||||||
PLAYER_EVENT_ON_BG_DESERTION = 57, // (event, player, type)
|
PLAYER_EVENT_ON_BG_DESERTION = 57, // (event, player, type)
|
||||||
PLAYER_EVENT_ON_PET_KILL = 58, // (event, player, killer)
|
PLAYER_EVENT_ON_PET_KILL = 58, // (event, player, killer)
|
||||||
PLAYER_EVENT_ON_CAN_RESURRECT = 59, // (event, player)
|
PLAYER_EVENT_ON_CAN_RESURRECT = 59, // (event, player)
|
||||||
PLAYER_EVENT_ON_CAN_UPDATE_SKILL = 60, // (event, player, skill_id) -- Can return true or false
|
PLAYER_EVENT_ON_CAN_UPDATE_SKILL = 60, // (event, player, skill_id) - Can return true or false
|
||||||
PLAYER_EVENT_ON_BEFORE_UPDATE_SKILL = 61, // (event, player, skill_id, value, max, step) -- Can return new amount
|
PLAYER_EVENT_ON_BEFORE_UPDATE_SKILL = 61, // (event, player, skill_id, value, max, step) -- Can return new amount
|
||||||
PLAYER_EVENT_ON_UPDATE_SKILL = 62, // (event, player, skill_id, value, max, step, new_value)
|
PLAYER_EVENT_ON_UPDATE_SKILL = 62, // (event, player, skill_id, value, max, step, new_value)
|
||||||
PLAYER_EVENT_ON_QUEST_ACCEPT = 63, // (event, player, quest)
|
PLAYER_EVENT_ON_QUEST_ACCEPT = 63, // (event, player, quest)
|
||||||
|
PLAYER_EVENT_ON_AURA_APPLY = 64, // (event, player, aura)
|
||||||
|
PLAYER_EVENT_ON_HEAL = 65, // (event, player, target, gain) - Can return new heal amount
|
||||||
|
PLAYER_EVENT_ON_DAMAGE = 66, // (event, player, target, damage) - Can return new damage amount
|
||||||
|
|
||||||
PLAYER_EVENT_COUNT
|
PLAYER_EVENT_COUNT
|
||||||
};
|
};
|
||||||
@@ -316,6 +319,9 @@ namespace Hooks
|
|||||||
CREATURE_EVENT_ON_DIALOG_STATUS = 35, // (event, player, creature)
|
CREATURE_EVENT_ON_DIALOG_STATUS = 35, // (event, player, creature)
|
||||||
CREATURE_EVENT_ON_ADD = 36, // (event, creature)
|
CREATURE_EVENT_ON_ADD = 36, // (event, creature)
|
||||||
CREATURE_EVENT_ON_REMOVE = 37, // (event, creature)
|
CREATURE_EVENT_ON_REMOVE = 37, // (event, creature)
|
||||||
|
CREATURE_EVENT_ON_AURA_APPLY = 38, // (event, creature, aura)
|
||||||
|
CREATURE_EVENT_ON_HEAL = 39, // (event, creature, target, gain) - Can return new heal amount
|
||||||
|
CREATURE_EVENT_ON_DAMAGE = 40, // (event, creature, target, damage) - Can return new damage amount
|
||||||
CREATURE_EVENT_COUNT
|
CREATURE_EVENT_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -418,6 +418,9 @@ public:
|
|||||||
bool OwnerAttackedBy(Creature* me, Unit* attacker);
|
bool OwnerAttackedBy(Creature* me, Unit* attacker);
|
||||||
bool OwnerAttacked(Creature* me, Unit* target);
|
bool OwnerAttacked(Creature* me, Unit* target);
|
||||||
void On_Reset(Creature* me);
|
void On_Reset(Creature* me);
|
||||||
|
void OnCreatureAuraApply(Creature* me, Aura* aura);
|
||||||
|
void OnCreatureHeal(Creature* me, Unit* target, uint32& gain);
|
||||||
|
void OnCreatureDamage(Creature* me, Unit* target, uint32& gain);
|
||||||
|
|
||||||
/* GameObject */
|
/* GameObject */
|
||||||
void OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget);
|
void OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget);
|
||||||
@@ -491,6 +494,9 @@ public:
|
|||||||
void OnPlayerUpdateSkill(Player* player, uint32 skill_id, uint32 value, uint32 max, uint32 step, uint32 new_value);
|
void OnPlayerUpdateSkill(Player* player, uint32 skill_id, uint32 value, uint32 max, uint32 step, uint32 new_value);
|
||||||
bool CanPlayerResurrect(Player* player);
|
bool CanPlayerResurrect(Player* player);
|
||||||
void OnPlayerQuestAccept(Player* player, Quest const* quest);
|
void OnPlayerQuestAccept(Player* player, Quest const* quest);
|
||||||
|
void OnPlayerAuraApply(Player* player, Aura* aura);
|
||||||
|
void OnPlayerHeal(Player* player, Unit* target, uint32& gain);
|
||||||
|
void OnPlayerDamage(Player* player, Unit* target, uint32& gain);
|
||||||
|
|
||||||
/* Vehicle */
|
/* Vehicle */
|
||||||
void OnInstall(Vehicle* vehicle);
|
void OnInstall(Vehicle* vehicle);
|
||||||
|
|||||||
@@ -327,3 +327,61 @@ bool Eluna::OwnerAttacked(Creature* me, Unit* target)
|
|||||||
Push(target);
|
Push(target);
|
||||||
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
return CallAllFunctionsBool(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Eluna::OnCreatureAuraApply(Creature* me, Aura* aura)
|
||||||
|
{
|
||||||
|
START_HOOK(CREATURE_EVENT_ON_AURA_APPLY, me);
|
||||||
|
Push(me);
|
||||||
|
Push(aura);
|
||||||
|
CallAllFunctions(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Eluna::OnCreatureHeal(Creature* me, Unit* target, uint32& gain)
|
||||||
|
{
|
||||||
|
START_HOOK(CREATURE_EVENT_ON_HEAL, me);
|
||||||
|
Push(me);
|
||||||
|
Push(target);
|
||||||
|
Push(gain);
|
||||||
|
|
||||||
|
int gainIndex = lua_gettop(L);
|
||||||
|
int n = SetupStack(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key, 3);
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
int r = CallOneFunction(n--, 3, 1);
|
||||||
|
if (lua_isnumber(L, r))
|
||||||
|
{
|
||||||
|
gain = CHECKVAL<uint32>(L, r);
|
||||||
|
// Update the stack for subsequent calls.
|
||||||
|
ReplaceArgument(gain, gainIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
CleanUpStack(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Eluna::OnCreatureDamage(Creature* me, Unit* target, uint32& damage)
|
||||||
|
{
|
||||||
|
START_HOOK(CREATURE_EVENT_ON_DAMAGE, me);
|
||||||
|
Push(me);
|
||||||
|
Push(target);
|
||||||
|
Push(damage);
|
||||||
|
|
||||||
|
int damageIndex = lua_gettop(L);
|
||||||
|
int n = SetupStack(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key, 3);
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
int r = CallOneFunction(n--, 3, 1);
|
||||||
|
if (lua_isnumber(L, r))
|
||||||
|
{
|
||||||
|
damage = CHECKVAL<uint32>(L, r);
|
||||||
|
// Update the stack for subsequent calls.
|
||||||
|
ReplaceArgument(damage, damageIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
CleanUpStack(3);
|
||||||
|
}
|
||||||
@@ -768,3 +768,61 @@ void Eluna::OnPlayerQuestAccept(Player* player, Quest const* quest)
|
|||||||
Push(quest);
|
Push(quest);
|
||||||
CallAllFunctions(PlayerEventBindings, key);
|
CallAllFunctions(PlayerEventBindings, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Eluna::OnPlayerAuraApply(Player* player, Aura* aura)
|
||||||
|
{
|
||||||
|
START_HOOK(PLAYER_EVENT_ON_AURA_APPLY);
|
||||||
|
Push(player);
|
||||||
|
Push(aura);
|
||||||
|
CallAllFunctions(PlayerEventBindings, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Eluna::OnPlayerHeal(Player* player, Unit* target, uint32& gain)
|
||||||
|
{
|
||||||
|
START_HOOK(PLAYER_EVENT_ON_HEAL);
|
||||||
|
Push(player);
|
||||||
|
Push(target);
|
||||||
|
Push(gain);
|
||||||
|
|
||||||
|
int gainIndex = lua_gettop(L);
|
||||||
|
int n = SetupStack(PlayerEventBindings, key, 3);
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
int r = CallOneFunction(n--, 3, 1);
|
||||||
|
if (lua_isnumber(L, r))
|
||||||
|
{
|
||||||
|
gain = CHECKVAL<uint32>(L, r);
|
||||||
|
// Update the stack for subsequent calls.
|
||||||
|
ReplaceArgument(gain, gainIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
CleanUpStack(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Eluna::OnPlayerDamage(Player* player, Unit* target, uint32& damage)
|
||||||
|
{
|
||||||
|
START_HOOK(PLAYER_EVENT_ON_DAMAGE);
|
||||||
|
Push(player);
|
||||||
|
Push(target);
|
||||||
|
Push(damage);
|
||||||
|
|
||||||
|
int damageIndex = lua_gettop(L);
|
||||||
|
int n = SetupStack(PlayerEventBindings, key, 3);
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
int r = CallOneFunction(n--, 3, 1);
|
||||||
|
if (lua_isnumber(L, r))
|
||||||
|
{
|
||||||
|
damage = CHECKVAL<uint32>(L, r);
|
||||||
|
// Update the stack for subsequent calls.
|
||||||
|
ReplaceArgument(damage, damageIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
CleanUpStack(3);
|
||||||
|
}
|
||||||
@@ -782,6 +782,9 @@ namespace LuaGlobalFunctions
|
|||||||
* PLAYER_EVENT_ON_BEFORE_UPDATE_SKILL = 61, // (event, player, skill_id, value, max, step) -- Can return new amount
|
* PLAYER_EVENT_ON_BEFORE_UPDATE_SKILL = 61, // (event, player, skill_id, value, max, step) -- Can return new amount
|
||||||
* PLAYER_EVENT_ON_UPDATE_SKILL = 62, // (event, player, skill_id, value, max, step, new_value)
|
* PLAYER_EVENT_ON_UPDATE_SKILL = 62, // (event, player, skill_id, value, max, step, new_value)
|
||||||
* PLAYER_EVENT_ON_QUEST_ACCEPT = 63, // (event, player, quest)
|
* PLAYER_EVENT_ON_QUEST_ACCEPT = 63, // (event, player, quest)
|
||||||
|
* PLAYER_EVENT_ON_AURA_APPLY = 64, // (event, player, aura)
|
||||||
|
* PLAYER_EVENT_ON_HEAL = 65, // (event, player, target, heal) - Can return new heal amount
|
||||||
|
* PLAYER_EVENT_ON_DAMAGE = 66, // (event, player, target, damage) - Can return new damage amount
|
||||||
* };
|
* };
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
@@ -1162,6 +1165,9 @@ namespace LuaGlobalFunctions
|
|||||||
* CREATURE_EVENT_ON_DIALOG_STATUS = 35, // (event, player, creature)
|
* CREATURE_EVENT_ON_DIALOG_STATUS = 35, // (event, player, creature)
|
||||||
* CREATURE_EVENT_ON_ADD = 36, // (event, creature)
|
* CREATURE_EVENT_ON_ADD = 36, // (event, creature)
|
||||||
* CREATURE_EVENT_ON_REMOVE = 37, // (event, creature)
|
* CREATURE_EVENT_ON_REMOVE = 37, // (event, creature)
|
||||||
|
* CREATURE_EVENT_ON_AURA_APPLY = 38, // (event, creature, aura)
|
||||||
|
* CREATURE_EVENT_ON_HEAL = 39, // (event, creature, target, heal) - Can return new heal amount
|
||||||
|
* CREATURE_EVENT_ON_DAMAGE = 40, // (event, creature, target, damage) - Can return new damage amount
|
||||||
* CREATURE_EVENT_COUNT
|
* CREATURE_EVENT_COUNT
|
||||||
* };
|
* };
|
||||||
* </pre>
|
* </pre>
|
||||||
|
|||||||
Reference in New Issue
Block a user