Feat: Add new UnitEvent for Creature and Player (#341)

This commit is contained in:
iThorgrim
2025-11-08 14:02:00 +01:00
committed by GitHub
parent 5d59a43d49
commit 1ac94f18a3
7 changed files with 866 additions and 221 deletions

View File

@@ -1216,7 +1216,24 @@ public:
sALE->OnPlayerAuraApply(unit->ToPlayer(), aura);
if (unit->IsCreature())
{
sALE->OnCreatureAuraApply(unit->ToCreature(), aura);
sALE->OnAllCreatureAuraApply(unit->ToCreature(), aura);
}
}
void OnAuraRemove(Unit* unit, AuraApplication* aurApp, AuraRemoveMode mode) override
{
if (!unit || !aurApp->GetBase()) return;
if (unit->IsPlayer())
sALE->OnPlayerAuraRemove(unit->ToPlayer(), aurApp->GetBase(), mode);
if (unit->IsCreature())
{
sALE->OnCreatureAuraRemove(unit->ToCreature(), aurApp->GetBase(), mode);
sALE->OnAllCreatureAuraRemove(unit->ToCreature(), aurApp->GetBase(), mode);
}
}
void OnHeal(Unit* healer, Unit* receiver, uint32& gain) override
@@ -1227,7 +1244,10 @@ public:
sALE->OnPlayerHeal(healer->ToPlayer(), receiver, gain);
if (healer->IsCreature())
{
sALE->OnCreatureHeal(healer->ToCreature(), receiver, gain);
sALE->OnAllCreatureHeal(healer->ToCreature(), receiver, gain);
}
}
void OnDamage(Unit* attacker, Unit* receiver, uint32& damage) override
@@ -1238,7 +1258,79 @@ public:
sALE->OnPlayerDamage(attacker->ToPlayer(), receiver, damage);
if (attacker->IsCreature())
{
sALE->OnCreatureDamage(attacker->ToCreature(), receiver, damage);
sALE->OnAllCreatureDamage(attacker->ToCreature(), receiver, damage);
}
}
void ModifyPeriodicDamageAurasTick(Unit* target, Unit* attacker, uint32& damage, SpellInfo const* spellInfo) override
{
if (!target || !attacker) return;
if (attacker->IsPlayer())
sALE->OnPlayerModifyPeriodicDamageAurasTick(attacker->ToPlayer(), target, damage, spellInfo);
if (attacker->IsCreature())
{
sALE->OnCreatureModifyPeriodicDamageAurasTick(attacker->ToCreature(), target, damage, spellInfo);
sALE->OnAllCreatureModifyPeriodicDamageAurasTick(attacker->ToCreature(), target, damage, spellInfo);
}
}
void ModifyMeleeDamage(Unit* target, Unit* attacker, uint32& damage) override
{
if (!target || !attacker) return;
if (attacker->IsPlayer())
sALE->OnPlayerModifyMeleeDamage(attacker->ToPlayer(), target, damage);
if (attacker->IsCreature())
{
sALE->OnCreatureModifyMeleeDamage(attacker->ToCreature(), target, damage);
sALE->OnAllCreatureModifyMeleeDamage(attacker->ToCreature(), target, damage);
}
}
void ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& damage, SpellInfo const* spellInfo) override
{
if (!target || !attacker) return;
if (attacker->IsPlayer())
sALE->OnPlayerModifySpellDamageTaken(attacker->ToPlayer(), target, damage, spellInfo);
if (attacker->IsCreature())
{
sALE->OnCreatureModifySpellDamageTaken(attacker->ToCreature(), target, damage, spellInfo);
sALE->OnAllCreatureModifySpellDamageTaken(attacker->ToCreature(), target, damage, spellInfo);
}
}
void ModifyHealReceived(Unit* target, Unit* healer, uint32& heal, SpellInfo const* spellInfo) override
{
if (!target || !healer) return;
if (healer->IsPlayer())
sALE->OnPlayerModifyHealReceived(healer->ToPlayer(), target, heal, spellInfo);
if (healer->IsCreature())
{
sALE->OnCreatureModifyHealReceived(healer->ToCreature(), target, heal, spellInfo);
sALE->OnAllCreatureModifyHealReceived(healer->ToCreature(), target, heal, spellInfo);
}
}
uint32 DealDamage(Unit* AttackerUnit, Unit* pVictim, uint32 damage, DamageEffectType damagetype) override
{
if (!AttackerUnit || !pVictim) return damage;
if (AttackerUnit->IsPlayer())
return sALE->OnPlayerDealDamage(AttackerUnit->ToPlayer(), pVictim, damage, damagetype);
if (AttackerUnit->IsCreature())
return sALE->OnCreatureDealDamage(AttackerUnit->ToCreature(), pVictim, damage, damagetype);
return damage;
}
};

View File

@@ -231,6 +231,12 @@ namespace Hooks
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_ON_AURA_REMOVE = 67, // (event, player, aura, remove_mode)
PLAYER_EVENT_ON_MODIFY_PERIODIC_DAMAGE_AURAS_TICK = 68, // (event, player, target, damage, spellInfo) - Can return new damage amount
PLAYER_EVENT_ON_MODIFY_MELEE_DAMAGE = 69, // (event, player, target, damage) - Can return new damage amount
PLAYER_EVENT_ON_MODIFY_SPELL_DAMAGE_TAKEN = 70, // (event, player, target, damage, spellInfo) - Can return new damage amount
PLAYER_EVENT_ON_MODIFY_HEAL_RECEIVED = 71, // (event, player, target, heal, spellInfo) - Can return new heal amount
PLAYER_EVENT_ON_DEAL_DAMAGE = 72, // (event, player, target, damage, damagetype) - Can return new damage amount
PLAYER_EVENT_COUNT
};
@@ -320,6 +326,12 @@ namespace Hooks
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_ON_AURA_REMOVE = 41, // (event, creature, aura, remove_mode)
CREATURE_EVENT_ON_MODIFY_PERIODIC_DAMAGE_AURAS_TICK = 42, // (event, creature, target, damage, spellInfo) - Can return new damage amount
CREATURE_EVENT_ON_MODIFY_MELEE_DAMAGE = 43, // (event, creature, target, damage) - Can return new damage amount
CREATURE_EVENT_ON_MODIFY_SPELL_DAMAGE_TAKEN = 44, // (event, creature, target, damage, spellInfo) - Can return new damage amount
CREATURE_EVENT_ON_MODIFY_HEAL_RECEIVED = 45, // (event, creature, target, heal, spellInfo) - Can return new heal amount
CREATURE_EVENT_ON_DEAL_DAMAGE = 46, // (event, creature, target, damage, damagetype) - Can return new damage amount
CREATURE_EVENT_COUNT
};
@@ -403,6 +415,15 @@ namespace Hooks
ALL_CREATURE_EVENT_ON_REMOVE = 2, // (event, creature)
ALL_CREATURE_EVENT_ON_SELECT_LEVEL = 3, // (event, creature_template, creature)
ALL_CREATURE_EVENT_ON_BEFORE_SELECT_LEVEL = 4, // (event, creature_template, creature, level) - Can return the new level
ALL_CREATURE_EVENT_ON_AURA_APPLY = 5, // (event, creature, aura)
ALL_CREATURE_EVENT_ON_HEAL = 6, // (event, creature, target, gain) - Can return new heal amount
ALL_CREATURE_EVENT_ON_DAMAGE = 7, // (event, creature, target, damage) - Can return new damage amount
ALL_CREATURE_EVENT_ON_AURA_REMOVE = 8, // (event, creature, aura, remove_mode)
ALL_CREATURE_EVENT_ON_MODIFY_PERIODIC_DAMAGE_AURAS_TICK = 9, // (event, creature, target, damage, spellInfo) - Can return new damage amount
ALL_CREATURE_EVENT_ON_MODIFY_MELEE_DAMAGE = 10, // (event, creature, target, damage) - Can return new damage amount
ALL_CREATURE_EVENT_ON_MODIFY_SPELL_DAMAGE_TAKEN = 11, // (event, creature, target, damage, spellInfo) - Can return new damage amount
ALL_CREATURE_EVENT_ON_MODIFY_HEAL_RECEIVED = 12, // (event, creature, target, heal, spellInfo) - Can return new heal amount
ALL_CREATURE_EVENT_ON_DEAL_DAMAGE = 13, // (event, creature, target, damage, damagetype) - Can return new damage amount
ALL_CREATURE_EVENT_COUNT
};
};

View File

@@ -424,6 +424,12 @@ public:
void OnCreatureAuraApply(Creature* me, Aura* aura);
void OnCreatureHeal(Creature* me, Unit* target, uint32& gain);
void OnCreatureDamage(Creature* me, Unit* target, uint32& gain);
void OnCreatureAuraRemove(Creature* me, Aura* aura, AuraRemoveMode mode);
void OnCreatureModifyPeriodicDamageAurasTick(Creature* me, Unit* target, uint32& damage, SpellInfo const* spellInfo);
void OnCreatureModifyMeleeDamage(Creature* me, Unit* target, uint32& damage);
void OnCreatureModifySpellDamageTaken(Creature* me, Unit* target, int32& damage, SpellInfo const* spellInfo);
void OnCreatureModifyHealReceived(Creature* me, Unit* target, uint32& heal, SpellInfo const* spellInfo);
uint32 OnCreatureDealDamage(Creature* me, Unit* pVictim, uint32 damage, DamageEffectType damagetype);
/* GameObject */
void OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget);
@@ -498,8 +504,14 @@ public:
bool CanPlayerResurrect(Player* player);
void OnPlayerQuestAccept(Player* player, Quest const* quest);
void OnPlayerAuraApply(Player* player, Aura* aura);
void OnPlayerAuraRemove(Player* player, Aura* aura, AuraRemoveMode mode);
void OnPlayerHeal(Player* player, Unit* target, uint32& gain);
void OnPlayerDamage(Player* player, Unit* target, uint32& gain);
void OnPlayerDamage(Player* player, Unit* target, uint32& damage);
void OnPlayerModifyPeriodicDamageAurasTick(Player* player, Unit* target, uint32& damage, SpellInfo const* spellInfo);
void OnPlayerModifyMeleeDamage(Player* player, Unit* target, uint32& damage);
void OnPlayerModifySpellDamageTaken(Player* player, Unit* target, int32& damage, SpellInfo const* spellInfo);
void OnPlayerModifyHealReceived(Player* player, Unit* target, uint32& heal, SpellInfo const* spellInfo);
uint32 OnPlayerDealDamage(Player* player, Unit* pVictim, uint32 damage, DamageEffectType damagetype);
/* Vehicle */
void OnInstall(Vehicle* vehicle);
@@ -595,6 +607,15 @@ public:
void OnAllCreatureRemoveFromWorld(Creature* creature);
void OnAllCreatureSelectLevel(const CreatureTemplate* cinfo, Creature* creature);
void OnAllCreatureBeforeSelectLevel(const CreatureTemplate* cinfo, Creature* creature, uint8& level);
void OnAllCreatureAuraApply(Creature* me, Aura* aura);
void OnAllCreatureHeal(Creature* me, Unit* target, uint32& gain);
void OnAllCreatureDamage(Creature* me, Unit* target, uint32& gain);
void OnAllCreatureAuraRemove(Creature* me, Aura* aura, AuraRemoveMode mode);
void OnAllCreatureModifyPeriodicDamageAurasTick(Creature* me, Unit* target, uint32& damage, SpellInfo const* spellInfo);
void OnAllCreatureModifyMeleeDamage(Creature* me, Unit* target, uint32& damage);
void OnAllCreatureModifySpellDamageTaken(Creature* me, Unit* target, int32& damage, SpellInfo const* spellInfo);
void OnAllCreatureModifyHealReceived(Creature* me, Unit* target, uint32& heal, SpellInfo const* spellInfo);
uint32 OnAllCreatureDealDamage(Creature* me, Unit* pVictim, uint32 damage, DamageEffectType damagetype);
};
template<> Unit* ALE::CHECKOBJ<Unit>(lua_State* L, int narg, bool error);
template<> Object* ALE::CHECKOBJ<Object>(lua_State* L, int narg, bool error);

View File

@@ -76,3 +76,202 @@ void ALE::OnAllCreatureBeforeSelectLevel(const CreatureTemplate* cinfo, Creature
CleanUpStack(3);
}
void ALE::OnAllCreatureAuraApply(Creature* me, Aura* aura)
{
START_HOOK(ALL_CREATURE_EVENT_ON_AURA_APPLY);
Push(me);
Push(aura);
CallAllFunctions(AllCreatureEventBindings, key);
}
void ALE::OnAllCreatureAuraRemove(Creature* me, Aura* aura, AuraRemoveMode mode)
{
START_HOOK(ALL_CREATURE_EVENT_ON_AURA_REMOVE);
Push(me);
Push(aura);
Push(mode);
CallAllFunctions(AllCreatureEventBindings, key);
}
void ALE::OnAllCreatureHeal(Creature* me, Unit* target, uint32& gain)
{
START_HOOK(ALL_CREATURE_EVENT_ON_HEAL);
Push(me);
Push(target);
Push(gain);
int gainIndex = lua_gettop(L);
int n = SetupStack(AllCreatureEventBindings, 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 ALE::OnAllCreatureDamage(Creature* me, Unit* target, uint32& damage)
{
START_HOOK(ALL_CREATURE_EVENT_ON_DAMAGE);
Push(me);
Push(target);
Push(damage);
int damageIndex = lua_gettop(L);
int n = SetupStack(AllCreatureEventBindings, 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);
}
void ALE::OnAllCreatureModifyPeriodicDamageAurasTick(Creature* me, Unit* target, uint32& damage, SpellInfo const* spellInfo)
{
START_HOOK(ALL_CREATURE_EVENT_ON_MODIFY_PERIODIC_DAMAGE_AURAS_TICK);
Push(me);
Push(target);
Push(damage);
Push(spellInfo);
int damageIndex = lua_gettop(L) - 1;
int n = SetupStack(AllCreatureEventBindings, key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 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(4);
}
void ALE::OnAllCreatureModifyMeleeDamage(Creature* me, Unit* target, uint32& damage)
{
START_HOOK(ALL_CREATURE_EVENT_ON_MODIFY_MELEE_DAMAGE);
Push(me);
Push(target);
Push(damage);
int damageIndex = lua_gettop(L);
int n = SetupStack(AllCreatureEventBindings, 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);
}
void ALE::OnAllCreatureModifySpellDamageTaken(Creature* me, Unit* target, int32& damage, SpellInfo const* spellInfo)
{
START_HOOK(ALL_CREATURE_EVENT_ON_MODIFY_SPELL_DAMAGE_TAKEN);
Push(me);
Push(target);
Push(damage);
Push(spellInfo);
int damageIndex = lua_gettop(L) - 1;
int n = SetupStack(AllCreatureEventBindings, key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 1);
if (lua_isnumber(L, r))
{
damage = CHECKVAL<int32>(L, r);
// Update the stack for subsequent calls.
ReplaceArgument(damage, damageIndex);
}
lua_pop(L, 1);
}
CleanUpStack(4);
}
void ALE::OnAllCreatureModifyHealReceived(Creature* me, Unit* target, uint32& heal, SpellInfo const* spellInfo)
{
START_HOOK(ALL_CREATURE_EVENT_ON_MODIFY_HEAL_RECEIVED);
Push(me);
Push(target);
Push(heal);
Push(spellInfo);
int healIndex = lua_gettop(L) - 1;
int n = SetupStack(AllCreatureEventBindings, key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 1);
if (lua_isnumber(L, r))
{
heal = CHECKVAL<uint32>(L, r);
// Update the stack for subsequent calls.
ReplaceArgument(heal, healIndex);
}
lua_pop(L, 1);
}
CleanUpStack(4);
}
uint32 ALE::OnAllCreatureDealDamage(Creature* me, Unit* target, uint32 damage, DamageEffectType damagetype)
{
START_HOOK_WITH_RETVAL(ALL_CREATURE_EVENT_ON_DEAL_DAMAGE, damage);
uint32 result = damage;
Push(me);
Push(target);
Push(damage);
Push(damagetype);
int damageIndex = lua_gettop(L) - 1;
int n = SetupStack(AllCreatureEventBindings, key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 1);
if (lua_isnumber(L, r))
{
result = CHECKVAL<uint32>(L, r);
// Update the stack for subsequent calls.
ReplaceArgument(result, damageIndex);
}
lua_pop(L, 1);
}
CleanUpStack(4);
return result;
}

View File

@@ -336,6 +336,15 @@ void ALE::OnCreatureAuraApply(Creature* me, Aura* aura)
CallAllFunctions(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
}
void ALE::OnCreatureAuraRemove(Creature* me, Aura* aura, AuraRemoveMode mode)
{
START_HOOK(CREATURE_EVENT_ON_AURA_REMOVE, me);
Push(me);
Push(aura);
Push(mode);
CallAllFunctions(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key);
}
void ALE::OnCreatureHeal(Creature* me, Unit* target, uint32& gain)
{
START_HOOK(CREATURE_EVENT_ON_HEAL, me);
@@ -385,3 +394,135 @@ void ALE::OnCreatureDamage(Creature* me, Unit* target, uint32& damage)
CleanUpStack(3);
}
void ALE::OnCreatureModifyPeriodicDamageAurasTick(Creature* me, Unit* target, uint32& damage, SpellInfo const* spellInfo)
{
START_HOOK(CREATURE_EVENT_ON_MODIFY_PERIODIC_DAMAGE_AURAS_TICK, me);
Push(me);
Push(target);
Push(damage);
Push(spellInfo);
int damageIndex = lua_gettop(L) - 1;
int n = SetupStack(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 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(4);
}
void ALE::OnCreatureModifyMeleeDamage(Creature* me, Unit* target, uint32& damage)
{
START_HOOK(CREATURE_EVENT_ON_MODIFY_MELEE_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);
}
void ALE::OnCreatureModifySpellDamageTaken(Creature* me, Unit* target, int32& damage, SpellInfo const* spellInfo)
{
START_HOOK(CREATURE_EVENT_ON_MODIFY_SPELL_DAMAGE_TAKEN, me);
Push(me);
Push(target);
Push(damage);
Push(spellInfo);
int damageIndex = lua_gettop(L) - 1;
int n = SetupStack(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 1);
if (lua_isnumber(L, r))
{
damage = CHECKVAL<int32>(L, r);
// Update the stack for subsequent calls.
ReplaceArgument(damage, damageIndex);
}
lua_pop(L, 1);
}
CleanUpStack(4);
}
void ALE::OnCreatureModifyHealReceived(Creature* me, Unit* target, uint32& heal, SpellInfo const* spellInfo)
{
START_HOOK(CREATURE_EVENT_ON_MODIFY_HEAL_RECEIVED, me);
Push(me);
Push(target);
Push(heal);
Push(spellInfo);
int healIndex = lua_gettop(L) - 1;
int n = SetupStack(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 1);
if (lua_isnumber(L, r))
{
heal = CHECKVAL<uint32>(L, r);
// Update the stack for subsequent calls.
ReplaceArgument(heal, healIndex);
}
lua_pop(L, 1);
}
CleanUpStack(4);
}
uint32 ALE::OnCreatureDealDamage(Creature* me, Unit* target, uint32 damage, DamageEffectType damagetype)
{
START_HOOK_WITH_RETVAL(CREATURE_EVENT_ON_DEAL_DAMAGE, me, damage);
uint32 result = damage;
Push(me);
Push(target);
Push(damage);
Push(damagetype);
int damageIndex = lua_gettop(L) - 1;
int n = SetupStack(CreatureEventBindings, CreatureUniqueBindings, entry_key, unique_key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 1);
if (lua_isnumber(L, r))
{
result = CHECKVAL<uint32>(L, r);
// Update the stack for subsequent calls.
ReplaceArgument(result, damageIndex);
}
lua_pop(L, 1);
}
CleanUpStack(4);
return result;
}

View File

@@ -826,3 +826,144 @@ void ALE::OnPlayerDamage(Player* player, Unit* target, uint32& damage)
CleanUpStack(3);
}
void ALE::OnPlayerAuraRemove(Player* player, Aura* aura, AuraRemoveMode mode)
{
START_HOOK(PLAYER_EVENT_ON_AURA_REMOVE);
Push(player);
Push(aura);
Push(mode);
CallAllFunctions(PlayerEventBindings, key);
}
void ALE::OnPlayerModifyPeriodicDamageAurasTick(Player* player, Unit* target, uint32& damage, SpellInfo const* spellInfo)
{
START_HOOK(PLAYER_EVENT_ON_MODIFY_PERIODIC_DAMAGE_AURAS_TICK);
Push(player);
Push(target);
Push(damage);
Push(spellInfo);
int damageIndex = lua_gettop(L) - 1;
int n = SetupStack(PlayerEventBindings, key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 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(4);
}
void ALE::OnPlayerModifyMeleeDamage(Player* player, Unit* target, uint32& damage)
{
START_HOOK(PLAYER_EVENT_ON_MODIFY_MELEE_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);
}
void ALE::OnPlayerModifySpellDamageTaken(Player* player, Unit* target, int32& damage, SpellInfo const* spellInfo)
{
START_HOOK(PLAYER_EVENT_ON_MODIFY_SPELL_DAMAGE_TAKEN);
Push(player);
Push(target);
Push(damage);
Push(spellInfo);
int damageIndex = lua_gettop(L) - 1;
int n = SetupStack(PlayerEventBindings, key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 1);
if (lua_isnumber(L, r))
{
damage = CHECKVAL<int32>(L, r);
// Update the stack for subsequent calls.
ReplaceArgument(damage, damageIndex);
}
lua_pop(L, 1);
}
CleanUpStack(4);
}
void ALE::OnPlayerModifyHealReceived(Player* player, Unit* target, uint32& heal, SpellInfo const* spellInfo)
{
START_HOOK(PLAYER_EVENT_ON_MODIFY_HEAL_RECEIVED);
Push(player);
Push(target);
Push(heal);
Push(spellInfo);
int healIndex = lua_gettop(L) - 1;
int n = SetupStack(PlayerEventBindings, key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 1);
if (lua_isnumber(L, r))
{
heal = CHECKVAL<uint32>(L, r);
// Update the stack for subsequent calls.
ReplaceArgument(heal, healIndex);
}
lua_pop(L, 1);
}
CleanUpStack(4);
}
uint32 ALE::OnPlayerDealDamage(Player* player, Unit* target, uint32 damage, DamageEffectType damagetype)
{
START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_DEAL_DAMAGE, damage);
Push(player);
Push(target);
Push(damage);
Push(damagetype);
int damageIndex = lua_gettop(L) - 1;
int n = SetupStack(PlayerEventBindings, key, 4);
uint32 result = damage;
while (n > 0)
{
int r = CallOneFunction(n--, 4, 1);
if (lua_isnumber(L, r))
{
result = CHECKVAL<uint32>(L, r);
// Update the stack for subsequent calls.
ReplaceArgument(result, damageIndex);
}
lua_pop(L, 1);
}
CleanUpStack(4);
return result;
}

View File

@@ -787,6 +787,12 @@ namespace LuaGlobalFunctions
* 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
* PLAYER_EVENT_ON_AURA_REMOVE = 67, // (event, player, aura, remove_mode)
* PLAYER_EVENT_ON_MODIFY_PERIODIC_DAMAGE_AURAS_TICK = 68, // (event, player, target, damage, spellInfo) - Can return new damage amount
* PLAYER_EVENT_ON_MODIFY_MELEE_DAMAGE = 69, // (event, player, target, damage) - Can return new damage amount
* PLAYER_EVENT_ON_MODIFY_SPELL_DAMAGE_TAKEN = 70, // (event, player, target, damage, spellInfo) - Can return new damage amount
* PLAYER_EVENT_ON_MODIFY_HEAL_RECEIVED = 71, // (event, player, target, heal, spellInfo) - Can return new heal amount
* PLAYER_EVENT_ON_DEAL_DAMAGE = 72, // (event, player, target, damage, damagetype) - Can return new damage amount
* };
* </pre>
*
@@ -1170,6 +1176,12 @@ namespace LuaGlobalFunctions
* 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_ON_AURA_REMOVE = 41, // (event, creature, aura, remove_mode)
* CREATURE_EVENT_ON_MODIFY_PERIODIC_DAMAGE_AURAS_TICK = 42, // (event, creature, target, damage, spellInfo) - Can return new damage amount
* CREATURE_EVENT_ON_MODIFY_MELEE_DAMAGE = 43, // (event, creature, target, damage) - Can return new damage amount
* CREATURE_EVENT_ON_MODIFY_SPELL_DAMAGE_TAKEN = 44, // (event, creature, target, damage, spellInfo) - Can return new damage amount
* CREATURE_EVENT_ON_MODIFY_HEAL_RECEIVED = 45, // (event, creature, target, heal, spellInfo) - Can return new heal amount
* CREATURE_EVENT_ON_DEAL_DAMAGE = 46, // (event, creature, target, damage, damagetype) - Can return new damage amount
* CREATURE_EVENT_COUNT
* };
* </pre>
@@ -1232,6 +1244,15 @@ namespace LuaGlobalFunctions
* CREATURE_EVENT_ON_DIALOG_STATUS = 35, // (event, player, creature)
* CREATURE_EVENT_ON_ADD = 36, // (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_ON_AURA_REMOVE = 41, // (event, creature, aura, remove_mode)
* CREATURE_EVENT_ON_MODIFY_PERIODIC_DAMAGE_AURAS_TICK = 42, // (event, creature, target, damage, spellInfo) - Can return new damage amount
* CREATURE_EVENT_ON_MODIFY_MELEE_DAMAGE = 43, // (event, creature, target, damage) - Can return new damage amount
* CREATURE_EVENT_ON_MODIFY_SPELL_DAMAGE_TAKEN = 44, // (event, creature, target, damage, spellInfo) - Can return new damage amount
* CREATURE_EVENT_ON_MODIFY_HEAL_RECEIVED = 45, // (event, creature, target, heal, spellInfo) - Can return new heal amount
* CREATURE_EVENT_ON_DEAL_DAMAGE = 46, // (event, creature, target, damage, damagetype) - Can return new damage amount
* CREATURE_EVENT_COUNT
* };
* </pre>
@@ -1348,6 +1369,15 @@ namespace LuaGlobalFunctions
* ALL_CREATURE_EVENT_ON_REMOVE = 2, // (event, creature)
* ALL_CREATURE_EVENT_ON_SELECT_LEVEL = 3, // (event, creature_template, creature)
* ALL_CREATURE_EVENT_ON_BEFORE_SELECT_LEVEL = 4, // (event, creature_template, creature, level) - Can return the new level
* ALL_CREATURE_EVENT_ON_AURA_APPLY = 5, // (event, creature, aura)
* ALL_CREATURE_EVENT_ON_HEAL = 6, // (event, creature, target, gain) - Can return new heal amount
* ALL_CREATURE_EVENT_ON_DAMAGE = 7, // (event, creature, target, damage) - Can return new damage amount
* ALL_CREATURE_EVENT_ON_AURA_REMOVE = 8, // (event, creature, aura, remove_mode)
* ALL_CREATURE_EVENT_ON_MODIFY_PERIODIC_DAMAGE_AURAS_TICK = 9, // (event, creature, target, damage, spellInfo) - Can return new damage amount
* ALL_CREATURE_EVENT_ON_MODIFY_MELEE_DAMAGE = 10, // (event, creature, target, damage) - Can return new damage amount
* ALL_CREATURE_EVENT_ON_MODIFY_SPELL_DAMAGE_TAKEN = 11, // (event, creature, target, damage, spellInfo) - Can return new damage amount
* ALL_CREATURE_EVENT_ON_MODIFY_HEAL_RECEIVED = 12, // (event, creature, target, heal, spellInfo) - Can return new heal amount
* ALL_CREATURE_EVENT_ON_DEAL_DAMAGE = 13, // (event, creature, target, damage, damagetype) - Can return new damage amount
* ALL_CREATURE_EVENT_COUNT
* };
* </pre>