Make ReactorAI the default AI on mangos and allow overriding.

All AI event handlers (except OnReset) can now override the default AI
behavior on both mangos and Trinity by returning true.

For default behavior, return false or nothing.

Fixes #124.
This commit is contained in:
Patman64
2014-12-14 23:20:51 -05:00
parent 28788e0efe
commit 3f08b37fd0
3 changed files with 239 additions and 134 deletions

View File

@@ -44,7 +44,7 @@
#include "revision.h" #include "revision.h"
#else #else
#include "Config/Config.h" #include "Config/Config.h"
#include "ReactorAI.h" #include "AggressorAI.h"
#include "revision_nr.h" #include "revision_nr.h"
#include "BattleGroundMgr.h" #include "BattleGroundMgr.h"
#endif #endif

View File

@@ -19,8 +19,8 @@ extern "C"
}; };
#ifndef TRINITY #ifndef TRINITY
class ReactorAI; class AggressorAI;
typedef ReactorAI ScriptedAI; typedef AggressorAI ScriptedAI;
#else #else
struct ScriptedAI; struct ScriptedAI;
#endif #endif
@@ -1454,176 +1454,254 @@ void Eluna::OnRemoveFromWorld(Creature* creature)
ENDCALL(); ENDCALL();
} }
void Eluna::UpdateAI(Creature* me, const uint32 diff) bool Eluna::UpdateAI(Creature* me, const uint32 diff)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_AIUPDATE, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_AIUPDATE, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, diff); Eluna::Push(L, diff);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
//Called for reaction at enter to combat if not in combat yet (enemy can be NULL) //Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
//Called at creature aggro either by MoveInLOS or Attack Start //Called at creature aggro either by MoveInLOS or Attack Start
void Eluna::EnterCombat(Creature* me, Unit* target) bool Eluna::EnterCombat(Creature* me, Unit* target)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_ENTER_COMBAT, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_ENTER_COMBAT, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, target); Eluna::Push(L, target);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called at any Damage from any attacker (before damage apply) // Called at any Damage from any attacker (before damage apply)
void Eluna::DamageTaken(Creature* me, Unit* attacker, uint32& damage) bool Eluna::DamageTaken(Creature* me, Unit* attacker, uint32& damage)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_DAMAGE_TAKEN, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_DAMAGE_TAKEN, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, attacker); Eluna::Push(L, attacker);
Eluna::Push(L, damage); Eluna::Push(L, damage);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(2);
FOR_RETS(i) FOR_RETS(i)
{ {
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i);
if (lua_isnumber(L, i)) if (lua_isnumber(L, i))
damage = Eluna::CHECKVAL<uint32>(L, i, damage); damage = Eluna::CHECKVAL<uint32>(L, i, damage);
} }
ENDCALL(); ENDCALL();
return result;
} }
//Called at creature death //Called at creature death
void Eluna::JustDied(Creature* me, Unit* killer) bool Eluna::JustDied(Creature* me, Unit* killer)
{ {
On_Reset(me); On_Reset(me);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_DIED, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_DIED, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, killer); Eluna::Push(L, killer);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
//Called at creature killing another unit //Called at creature killing another unit
void Eluna::KilledUnit(Creature* me, Unit* victim) bool Eluna::KilledUnit(Creature* me, Unit* victim)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_TARGET_DIED, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_TARGET_DIED, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, victim); Eluna::Push(L, victim);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called when the creature summon successfully other creature // Called when the creature summon successfully other creature
void Eluna::JustSummoned(Creature* me, Creature* summon) bool Eluna::JustSummoned(Creature* me, Creature* summon)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, summon); Eluna::Push(L, summon);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called when a summoned creature is despawned // Called when a summoned creature is despawned
void Eluna::SummonedCreatureDespawn(Creature* me, Creature* summon) bool Eluna::SummonedCreatureDespawn(Creature* me, Creature* summon)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, summon); Eluna::Push(L, summon);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
//Called at waypoint reached or PointMovement end //Called at waypoint reached or PointMovement end
void Eluna::MovementInform(Creature* me, uint32 type, uint32 id) bool Eluna::MovementInform(Creature* me, uint32 type, uint32 id)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_WP, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_WP, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, type); Eluna::Push(L, type);
Eluna::Push(L, id); Eluna::Push(L, id);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called before EnterCombat even before the creature is in combat. // Called before EnterCombat even before the creature is in combat.
void Eluna::AttackStart(Creature* me, Unit* target) bool Eluna::AttackStart(Creature* me, Unit* target)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_PRE_COMBAT, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_PRE_COMBAT, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, target); Eluna::Push(L, target);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called for reaction at stopping attack at no attackers or targets // Called for reaction at stopping attack at no attackers or targets
void Eluna::EnterEvadeMode(Creature* me) bool Eluna::EnterEvadeMode(Creature* me)
{ {
On_Reset(me); On_Reset(me);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc) // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
void Eluna::AttackedBy(Creature* me, Unit* attacker) bool Eluna::AttackedBy(Creature* me, Unit* attacker)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_ATTACKED_AT, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_ATTACKED_AT, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, attacker); Eluna::Push(L, attacker);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called when creature is spawned or respawned (for reseting variables) // Called when creature is spawned or respawned (for reseting variables)
void Eluna::JustRespawned(Creature* me) bool Eluna::JustRespawned(Creature* me)
{ {
On_Reset(me); On_Reset(me);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPAWN, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPAWN, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called at reaching home after evade // Called at reaching home after evade
void Eluna::JustReachedHome(Creature* me) bool Eluna::JustReachedHome(Creature* me)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called at text emote receive from player // Called at text emote receive from player
void Eluna::ReceiveEmote(Creature* me, Player* player, uint32 emoteId) bool Eluna::ReceiveEmote(Creature* me, Player* player, uint32 emoteId)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_RECEIVE_EMOTE, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_RECEIVE_EMOTE, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, player); Eluna::Push(L, player);
Eluna::Push(L, emoteId); Eluna::Push(L, emoteId);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// called when the corpse of this creature gets removed // called when the corpse of this creature gets removed
void Eluna::CorpseRemoved(Creature* me, uint32& respawnDelay) bool Eluna::CorpseRemoved(Creature* me, uint32& respawnDelay)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_CORPSE_REMOVED, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_CORPSE_REMOVED, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, respawnDelay); Eluna::Push(L, respawnDelay);
ENTRY_EXECUTE(1); ENTRY_EXECUTE(2);
FOR_RETS(i) FOR_RETS(i)
{ {
if (lua_isboolean(L, i))
result = Eluna::CHECKVAL<bool>(L, i);
if (lua_isnumber(L, i)) if (lua_isnumber(L, i))
respawnDelay = Eluna::CHECKVAL<uint32>(L, i, respawnDelay); respawnDelay = Eluna::CHECKVAL<uint32>(L, i, respawnDelay);
} }
ENDCALL(); ENDCALL();
return result;
} }
void Eluna::MoveInLineOfSight(Creature* me, Unit* who) bool Eluna::MoveInLineOfSight(Creature* me, Unit* who)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_MOVE_IN_LOS, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_MOVE_IN_LOS, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, who); Eluna::Push(L, who);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called on creature initial spawn, respawn, death, evade (leave combat) // Called on creature initial spawn, respawn, death, evade (leave combat)
@@ -1636,57 +1714,82 @@ void Eluna::On_Reset(Creature* me) // Not an override, custom
} }
// Called when hit by a spell // Called when hit by a spell
void Eluna::SpellHit(Creature* me, Unit* caster, SpellInfo const* spell) bool Eluna::SpellHit(Creature* me, Unit* caster, SpellInfo const* spell)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_HIT_BY_SPELL, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_HIT_BY_SPELL, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, caster); Eluna::Push(L, caster);
Eluna::Push(L, spell->Id); // Pass spell object? Eluna::Push(L, spell->Id); // Pass spell object?
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called when spell hits a target // Called when spell hits a target
void Eluna::SpellHitTarget(Creature* me, Unit* target, SpellInfo const* spell) bool Eluna::SpellHitTarget(Creature* me, Unit* target, SpellInfo const* spell)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPELL_HIT_TARGET, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPELL_HIT_TARGET, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, target); Eluna::Push(L, target);
Eluna::Push(L, spell->Id); // Pass spell object? Eluna::Push(L, spell->Id); // Pass spell object?
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
#ifdef TRINITY #ifdef TRINITY
void Eluna::SummonedCreatureDies(Creature* me, Creature* summon, Unit* killer) bool Eluna::SummonedCreatureDies(Creature* me, Creature* summon, Unit* killer)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, summon); Eluna::Push(L, summon);
Eluna::Push(L, killer); Eluna::Push(L, killer);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called when owner takes damage // Called when owner takes damage
void Eluna::OwnerAttackedBy(Creature* me, Unit* attacker) bool Eluna::OwnerAttackedBy(Creature* me, Unit* attacker)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED_AT, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED_AT, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, attacker); Eluna::Push(L, attacker);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
// Called when owner attacks something // Called when owner attacks something
void Eluna::OwnerAttacked(Creature* me, Unit* target) bool Eluna::OwnerAttacked(Creature* me, Unit* target)
{ {
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED, return); bool result = false;
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED, return false);
Eluna::Push(L, me); Eluna::Push(L, me);
Eluna::Push(L, target); Eluna::Push(L, target);
ENTRY_EXECUTE(0); ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL(); ENDCALL();
return result;
} }
#endif #endif
@@ -1709,114 +1812,115 @@ struct ElunaCreatureAI : ScriptedAI
void UpdateAI(uint32 diff) override void UpdateAI(uint32 diff) override
#endif #endif
{ {
if (!sEluna->UpdateAI(me, diff))
{
#ifdef TRINITY #ifdef TRINITY
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC)) if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
ScriptedAI::UpdateAI(diff); ScriptedAI::UpdateAI(diff);
#else #else
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE)) if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE))
ScriptedAI::UpdateAI(diff); ScriptedAI::UpdateAI(diff);
#endif #endif
}
sEluna->UpdateAI(me, diff);
} }
//Called for reaction at enter to combat if not in combat yet (enemy can be NULL) //Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
//Called at creature aggro either by MoveInLOS or Attack Start //Called at creature aggro either by MoveInLOS or Attack Start
void EnterCombat(Unit* target) override void EnterCombat(Unit* target) override
{ {
ScriptedAI::EnterCombat(target); if (!sEluna->EnterCombat(me, target))
sEluna->EnterCombat(me, target); ScriptedAI::EnterCombat(target);
} }
// Called at any Damage from any attacker (before damage apply) // Called at any Damage from any attacker (before damage apply)
void DamageTaken(Unit* attacker, uint32& damage) override void DamageTaken(Unit* attacker, uint32& damage) override
{ {
ScriptedAI::DamageTaken(attacker, damage); if (!sEluna->DamageTaken(me, attacker, damage))
sEluna->DamageTaken(me, attacker, damage); ScriptedAI::DamageTaken(attacker, damage);
} }
//Called at creature death //Called at creature death
void JustDied(Unit* killer) override void JustDied(Unit* killer) override
{ {
ScriptedAI::JustDied(killer); if (!sEluna->JustDied(me, killer))
sEluna->JustDied(me, killer); ScriptedAI::JustDied(killer);
} }
//Called at creature killing another unit //Called at creature killing another unit
void KilledUnit(Unit* victim) override void KilledUnit(Unit* victim) override
{ {
ScriptedAI::KilledUnit(victim); if (!sEluna->KilledUnit(me, victim))
sEluna->KilledUnit(me, victim); ScriptedAI::KilledUnit(victim);
} }
// Called when the creature summon successfully other creature // Called when the creature summon successfully other creature
void JustSummoned(Creature* summon) override void JustSummoned(Creature* summon) override
{ {
ScriptedAI::JustSummoned(summon); if (!sEluna->JustSummoned(me, summon))
sEluna->JustSummoned(me, summon); ScriptedAI::JustSummoned(summon);
} }
// Called when a summoned creature is despawned // Called when a summoned creature is despawned
void SummonedCreatureDespawn(Creature* summon) override void SummonedCreatureDespawn(Creature* summon) override
{ {
ScriptedAI::SummonedCreatureDespawn(summon); if (!sEluna->SummonedCreatureDespawn(me, summon))
sEluna->SummonedCreatureDespawn(me, summon); ScriptedAI::SummonedCreatureDespawn(summon);
} }
//Called at waypoint reached or PointMovement end //Called at waypoint reached or PointMovement end
void MovementInform(uint32 type, uint32 id) override void MovementInform(uint32 type, uint32 id) override
{ {
ScriptedAI::MovementInform(type, id); if (!sEluna->MovementInform(me, type, id))
sEluna->MovementInform(me, type, id); ScriptedAI::MovementInform(type, id);
} }
// Called before EnterCombat even before the creature is in combat. // Called before EnterCombat even before the creature is in combat.
void AttackStart(Unit* target) override void AttackStart(Unit* target) override
{ {
ScriptedAI::AttackStart(target); if (!sEluna->AttackStart(me, target))
sEluna->AttackStart(me, target); ScriptedAI::AttackStart(target);
} }
// Called for reaction at stopping attack at no attackers or targets // Called for reaction at stopping attack at no attackers or targets
void EnterEvadeMode() override void EnterEvadeMode() override
{ {
ScriptedAI::EnterEvadeMode(); if (!sEluna->EnterEvadeMode(me))
sEluna->EnterEvadeMode(me); ScriptedAI::EnterEvadeMode();
} }
// Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc) // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
void AttackedBy(Unit* attacker) override void AttackedBy(Unit* attacker) override
{ {
ScriptedAI::AttackedBy(attacker); if (!sEluna->AttackedBy(me, attacker))
sEluna->AttackedBy(me, attacker); ScriptedAI::AttackedBy(attacker);
} }
// Called when creature is spawned or respawned (for reseting variables) // Called when creature is spawned or respawned (for reseting variables)
void JustRespawned() override void JustRespawned() override
{ {
ScriptedAI::JustRespawned(); if (!sEluna->JustRespawned(me))
sEluna->JustRespawned(me); ScriptedAI::JustRespawned();
} }
// Called at reaching home after evade // Called at reaching home after evade
void JustReachedHome() override void JustReachedHome() override
{ {
ScriptedAI::JustReachedHome(); if (!sEluna->JustReachedHome(me))
sEluna->JustReachedHome(me); ScriptedAI::JustReachedHome();
} }
// Called at text emote receive from player // Called at text emote receive from player
void ReceiveEmote(Player* player, uint32 emoteId) override void ReceiveEmote(Player* player, uint32 emoteId) override
{ {
ScriptedAI::ReceiveEmote(player, emoteId); if (!sEluna->ReceiveEmote(me, player, emoteId))
sEluna->ReceiveEmote(me, player, emoteId); ScriptedAI::ReceiveEmote(player, emoteId);
} }
// called when the corpse of this creature gets removed // called when the corpse of this creature gets removed
void CorpseRemoved(uint32& respawnDelay) override void CorpseRemoved(uint32& respawnDelay) override
{ {
ScriptedAI::CorpseRemoved(respawnDelay); if (!sEluna->CorpseRemoved(me, respawnDelay))
sEluna->CorpseRemoved(me, respawnDelay); ScriptedAI::CorpseRemoved(respawnDelay);
} }
#ifndef TRINITY #ifndef TRINITY
@@ -1829,22 +1933,22 @@ struct ElunaCreatureAI : ScriptedAI
void MoveInLineOfSight(Unit* who) override void MoveInLineOfSight(Unit* who) override
{ {
ScriptedAI::MoveInLineOfSight(who); if (!sEluna->MoveInLineOfSight(me, who))
sEluna->MoveInLineOfSight(me, who); ScriptedAI::MoveInLineOfSight(who);
} }
// Called when hit by a spell // Called when hit by a spell
void SpellHit(Unit* caster, SpellInfo const* spell) override void SpellHit(Unit* caster, SpellInfo const* spell) override
{ {
ScriptedAI::SpellHit(caster, spell); if (!sEluna->SpellHit(me, caster, spell))
sEluna->SpellHit(me, caster, spell); ScriptedAI::SpellHit(caster, spell);
} }
// Called when spell hits a target // Called when spell hits a target
void SpellHitTarget(Unit* target, SpellInfo const* spell) override void SpellHitTarget(Unit* target, SpellInfo const* spell) override
{ {
ScriptedAI::SpellHitTarget(target, spell); if (!sEluna->SpellHitTarget(me, target, spell))
sEluna->SpellHitTarget(me, target, spell); ScriptedAI::SpellHitTarget(target, spell);
} }
#ifdef TRINITY #ifdef TRINITY
@@ -1852,28 +1956,28 @@ struct ElunaCreatureAI : ScriptedAI
// Called when the creature is summoned successfully by other creature // Called when the creature is summoned successfully by other creature
void IsSummonedBy(Unit* summoner) override void IsSummonedBy(Unit* summoner) override
{ {
ScriptedAI::IsSummonedBy(summoner); if (!sEluna->OnSummoned(me, summoner))
sEluna->OnSummoned(me, summoner); ScriptedAI::IsSummonedBy(summoner);
} }
void SummonedCreatureDies(Creature* summon, Unit* killer) override void SummonedCreatureDies(Creature* summon, Unit* killer) override
{ {
ScriptedAI::SummonedCreatureDies(summon, killer); if (!sEluna->SummonedCreatureDies(me, summon, killer))
sEluna->SummonedCreatureDies(me, summon, killer); ScriptedAI::SummonedCreatureDies(summon, killer);
} }
// Called when owner takes damage // Called when owner takes damage
void OwnerAttackedBy(Unit* attacker) override void OwnerAttackedBy(Unit* attacker) override
{ {
ScriptedAI::OwnerAttackedBy(attacker); if (!sEluna->OwnerAttackedBy(me, attacker))
sEluna->OwnerAttackedBy(me, attacker); ScriptedAI::OwnerAttackedBy(attacker);
} }
// Called when owner attacks something // Called when owner attacks something
void OwnerAttacked(Unit* target) override void OwnerAttacked(Unit* target) override
{ {
ScriptedAI::OwnerAttacked(target); if (!sEluna->OwnerAttacked(me, target))
sEluna->OwnerAttacked(me, target); ScriptedAI::OwnerAttacked(target);
} }
#endif #endif

View File

@@ -227,27 +227,28 @@ public:
uint32 GetDialogStatus(Player* pPlayer, Creature* pCreature); uint32 GetDialogStatus(Player* pPlayer, Creature* pCreature);
void OnSummoned(Creature* creature, Unit* summoner); void OnSummoned(Creature* creature, Unit* summoner);
void UpdateAI(Creature* me, const uint32 diff); bool UpdateAI(Creature* me, const uint32 diff);
void EnterCombat(Creature* me, Unit* target); bool EnterCombat(Creature* me, Unit* target);
void DamageTaken(Creature* me, Unit* attacker, uint32& damage); void JustDied(Creature* me, Unit* killer); bool DamageTaken(Creature* me, Unit* attacker, uint32& damage);
void KilledUnit(Creature* me, Unit* victim); bool JustDied(Creature* me, Unit* killer);
void JustSummoned(Creature* me, Creature* summon); bool KilledUnit(Creature* me, Unit* victim);
void SummonedCreatureDespawn(Creature* me, Creature* summon); bool JustSummoned(Creature* me, Creature* summon);
void MovementInform(Creature* me, uint32 type, uint32 id); bool SummonedCreatureDespawn(Creature* me, Creature* summon);
void AttackStart(Creature* me, Unit* target); bool MovementInform(Creature* me, uint32 type, uint32 id);
void EnterEvadeMode(Creature* me); bool AttackStart(Creature* me, Unit* target);
void AttackedBy(Creature* me, Unit* attacker); bool EnterEvadeMode(Creature* me);
void JustRespawned(Creature* me); bool AttackedBy(Creature* me, Unit* attacker);
void JustReachedHome(Creature* me); bool JustRespawned(Creature* me);
void ReceiveEmote(Creature* me, Player* player, uint32 emoteId); bool JustReachedHome(Creature* me);
void CorpseRemoved(Creature* me, uint32& respawnDelay); bool ReceiveEmote(Creature* me, Player* player, uint32 emoteId);
void MoveInLineOfSight(Creature* me, Unit* who); bool CorpseRemoved(Creature* me, uint32& respawnDelay);
bool MoveInLineOfSight(Creature* me, Unit* who);
bool SpellHit(Creature* me, Unit* caster, SpellInfo const* spell);
bool SpellHitTarget(Creature* me, Unit* target, SpellInfo const* spell);
bool SummonedCreatureDies(Creature* me, Creature* summon, Unit* killer);
bool OwnerAttackedBy(Creature* me, Unit* attacker);
bool OwnerAttacked(Creature* me, Unit* target);
void On_Reset(Creature* me); void On_Reset(Creature* me);
void SpellHit(Creature* me, Unit* caster, SpellInfo const* spell);
void SpellHitTarget(Creature* me, Unit* target, SpellInfo const* spell);
void SummonedCreatureDies(Creature* me, Creature* summon, Unit* killer);
void OwnerAttackedBy(Creature* me, Unit* attacker);
void OwnerAttacked(Creature* me, Unit* target);
/* GameObject */ /* GameObject */
bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget); bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget);