mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Move ElunaCreatureAI into a separate file.
This commit is contained in:
212
ElunaCreatureAI.h
Normal file
212
ElunaCreatureAI.h
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 - 2015 Eluna Lua Engine <http://emudevs.com/>
|
||||||
|
* This program is free software licensed under GPL version 3
|
||||||
|
* Please see the included DOCS/LICENSE.md for more information
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ELUNA_CREATURE_AI_H
|
||||||
|
#define _ELUNA_CREATURE_AI_H
|
||||||
|
|
||||||
|
#include "LuaEngine.h"
|
||||||
|
|
||||||
|
#ifndef TRINITY
|
||||||
|
class AggressorAI;
|
||||||
|
typedef AggressorAI ScriptedAI;
|
||||||
|
#else
|
||||||
|
struct ScriptedAI;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct ElunaCreatureAI : ScriptedAI
|
||||||
|
{
|
||||||
|
#ifndef TRINITY
|
||||||
|
#define me m_creature
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ElunaCreatureAI(Creature* creature) : ScriptedAI(creature)
|
||||||
|
{
|
||||||
|
JustRespawned();
|
||||||
|
}
|
||||||
|
~ElunaCreatureAI() { }
|
||||||
|
|
||||||
|
//Called at World update tick
|
||||||
|
#ifndef TRINITY
|
||||||
|
void UpdateAI(const uint32 diff) override
|
||||||
|
#else
|
||||||
|
void UpdateAI(uint32 diff) override
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
if (!sEluna->UpdateAI(me, diff))
|
||||||
|
{
|
||||||
|
#ifdef TRINITY
|
||||||
|
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
|
||||||
|
ScriptedAI::UpdateAI(diff);
|
||||||
|
#else
|
||||||
|
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE))
|
||||||
|
ScriptedAI::UpdateAI(diff);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//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
|
||||||
|
void EnterCombat(Unit* target) override
|
||||||
|
{
|
||||||
|
if (!sEluna->EnterCombat(me, target))
|
||||||
|
ScriptedAI::EnterCombat(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called at any Damage from any attacker (before damage apply)
|
||||||
|
void DamageTaken(Unit* attacker, uint32& damage) override
|
||||||
|
{
|
||||||
|
if (!sEluna->DamageTaken(me, attacker, damage))
|
||||||
|
ScriptedAI::DamageTaken(attacker, damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Called at creature death
|
||||||
|
void JustDied(Unit* killer) override
|
||||||
|
{
|
||||||
|
if (!sEluna->JustDied(me, killer))
|
||||||
|
ScriptedAI::JustDied(killer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Called at creature killing another unit
|
||||||
|
void KilledUnit(Unit* victim) override
|
||||||
|
{
|
||||||
|
if (!sEluna->KilledUnit(me, victim))
|
||||||
|
ScriptedAI::KilledUnit(victim);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the creature summon successfully other creature
|
||||||
|
void JustSummoned(Creature* summon) override
|
||||||
|
{
|
||||||
|
if (!sEluna->JustSummoned(me, summon))
|
||||||
|
ScriptedAI::JustSummoned(summon);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when a summoned creature is despawned
|
||||||
|
void SummonedCreatureDespawn(Creature* summon) override
|
||||||
|
{
|
||||||
|
if (!sEluna->SummonedCreatureDespawn(me, summon))
|
||||||
|
ScriptedAI::SummonedCreatureDespawn(summon);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Called at waypoint reached or PointMovement end
|
||||||
|
void MovementInform(uint32 type, uint32 id) override
|
||||||
|
{
|
||||||
|
if (!sEluna->MovementInform(me, type, id))
|
||||||
|
ScriptedAI::MovementInform(type, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called before EnterCombat even before the creature is in combat.
|
||||||
|
void AttackStart(Unit* target) override
|
||||||
|
{
|
||||||
|
if (!sEluna->AttackStart(me, target))
|
||||||
|
ScriptedAI::AttackStart(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called for reaction at stopping attack at no attackers or targets
|
||||||
|
void EnterEvadeMode() override
|
||||||
|
{
|
||||||
|
if (!sEluna->EnterEvadeMode(me))
|
||||||
|
ScriptedAI::EnterEvadeMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
|
||||||
|
void AttackedBy(Unit* attacker) override
|
||||||
|
{
|
||||||
|
if (!sEluna->AttackedBy(me, attacker))
|
||||||
|
ScriptedAI::AttackedBy(attacker);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when creature is spawned or respawned (for reseting variables)
|
||||||
|
void JustRespawned() override
|
||||||
|
{
|
||||||
|
if (!sEluna->JustRespawned(me))
|
||||||
|
ScriptedAI::JustRespawned();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called at reaching home after evade
|
||||||
|
void JustReachedHome() override
|
||||||
|
{
|
||||||
|
if (!sEluna->JustReachedHome(me))
|
||||||
|
ScriptedAI::JustReachedHome();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called at text emote receive from player
|
||||||
|
void ReceiveEmote(Player* player, uint32 emoteId) override
|
||||||
|
{
|
||||||
|
if (!sEluna->ReceiveEmote(me, player, emoteId))
|
||||||
|
ScriptedAI::ReceiveEmote(player, emoteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// called when the corpse of this creature gets removed
|
||||||
|
void CorpseRemoved(uint32& respawnDelay) override
|
||||||
|
{
|
||||||
|
if (!sEluna->CorpseRemoved(me, respawnDelay))
|
||||||
|
ScriptedAI::CorpseRemoved(respawnDelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef TRINITY
|
||||||
|
// Enables use of MoveInLineOfSight
|
||||||
|
bool IsVisible(Unit* who) const override
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void MoveInLineOfSight(Unit* who) override
|
||||||
|
{
|
||||||
|
if (!sEluna->MoveInLineOfSight(me, who))
|
||||||
|
ScriptedAI::MoveInLineOfSight(who);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when hit by a spell
|
||||||
|
void SpellHit(Unit* caster, SpellInfo const* spell) override
|
||||||
|
{
|
||||||
|
if (!sEluna->SpellHit(me, caster, spell))
|
||||||
|
ScriptedAI::SpellHit(caster, spell);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when spell hits a target
|
||||||
|
void SpellHitTarget(Unit* target, SpellInfo const* spell) override
|
||||||
|
{
|
||||||
|
if (!sEluna->SpellHitTarget(me, target, spell))
|
||||||
|
ScriptedAI::SpellHitTarget(target, spell);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TRINITY
|
||||||
|
|
||||||
|
// Called when the creature is summoned successfully by other creature
|
||||||
|
void IsSummonedBy(Unit* summoner) override
|
||||||
|
{
|
||||||
|
if (!sEluna->OnSummoned(me, summoner))
|
||||||
|
ScriptedAI::IsSummonedBy(summoner);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SummonedCreatureDies(Creature* summon, Unit* killer) override
|
||||||
|
{
|
||||||
|
if (!sEluna->SummonedCreatureDies(me, summon, killer))
|
||||||
|
ScriptedAI::SummonedCreatureDies(summon, killer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when owner takes damage
|
||||||
|
void OwnerAttackedBy(Unit* attacker) override
|
||||||
|
{
|
||||||
|
if (!sEluna->OwnerAttackedBy(me, attacker))
|
||||||
|
ScriptedAI::OwnerAttackedBy(attacker);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when owner attacks something
|
||||||
|
void OwnerAttacked(Unit* target) override
|
||||||
|
{
|
||||||
|
if (!sEluna->OwnerAttacked(me, target))
|
||||||
|
ScriptedAI::OwnerAttacked(target);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TRINITY
|
||||||
|
#undef me
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
201
HookMgr.cpp
201
HookMgr.cpp
@@ -10,6 +10,7 @@
|
|||||||
#include "ElunaEventMgr.h"
|
#include "ElunaEventMgr.h"
|
||||||
#include "ElunaIncludes.h"
|
#include "ElunaIncludes.h"
|
||||||
#include "ElunaTemplate.h"
|
#include "ElunaTemplate.h"
|
||||||
|
#include "ElunaCreatureAI.h"
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@@ -18,13 +19,6 @@ extern "C"
|
|||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef TRINITY
|
|
||||||
class AggressorAI;
|
|
||||||
typedef AggressorAI ScriptedAI;
|
|
||||||
#else
|
|
||||||
struct ScriptedAI;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace HookMgr;
|
using namespace HookMgr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2202,199 +2196,6 @@ bool Eluna::OwnerAttacked(Creature* me, Unit* target)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct ElunaCreatureAI : ScriptedAI
|
|
||||||
{
|
|
||||||
#ifndef TRINITY
|
|
||||||
#define me m_creature
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ElunaCreatureAI(Creature* creature) : ScriptedAI(creature)
|
|
||||||
{
|
|
||||||
JustRespawned();
|
|
||||||
}
|
|
||||||
~ElunaCreatureAI() { }
|
|
||||||
|
|
||||||
//Called at World update tick
|
|
||||||
#ifndef TRINITY
|
|
||||||
void UpdateAI(const uint32 diff) override
|
|
||||||
#else
|
|
||||||
void UpdateAI(uint32 diff) override
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
if (!sEluna->UpdateAI(me, diff))
|
|
||||||
{
|
|
||||||
#ifdef TRINITY
|
|
||||||
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
|
|
||||||
ScriptedAI::UpdateAI(diff);
|
|
||||||
#else
|
|
||||||
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE))
|
|
||||||
ScriptedAI::UpdateAI(diff);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//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
|
|
||||||
void EnterCombat(Unit* target) override
|
|
||||||
{
|
|
||||||
if (!sEluna->EnterCombat(me, target))
|
|
||||||
ScriptedAI::EnterCombat(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called at any Damage from any attacker (before damage apply)
|
|
||||||
void DamageTaken(Unit* attacker, uint32& damage) override
|
|
||||||
{
|
|
||||||
if (!sEluna->DamageTaken(me, attacker, damage))
|
|
||||||
ScriptedAI::DamageTaken(attacker, damage);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Called at creature death
|
|
||||||
void JustDied(Unit* killer) override
|
|
||||||
{
|
|
||||||
if (!sEluna->JustDied(me, killer))
|
|
||||||
ScriptedAI::JustDied(killer);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Called at creature killing another unit
|
|
||||||
void KilledUnit(Unit* victim) override
|
|
||||||
{
|
|
||||||
if (!sEluna->KilledUnit(me, victim))
|
|
||||||
ScriptedAI::KilledUnit(victim);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when the creature summon successfully other creature
|
|
||||||
void JustSummoned(Creature* summon) override
|
|
||||||
{
|
|
||||||
if (!sEluna->JustSummoned(me, summon))
|
|
||||||
ScriptedAI::JustSummoned(summon);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a summoned creature is despawned
|
|
||||||
void SummonedCreatureDespawn(Creature* summon) override
|
|
||||||
{
|
|
||||||
if (!sEluna->SummonedCreatureDespawn(me, summon))
|
|
||||||
ScriptedAI::SummonedCreatureDespawn(summon);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Called at waypoint reached or PointMovement end
|
|
||||||
void MovementInform(uint32 type, uint32 id) override
|
|
||||||
{
|
|
||||||
if (!sEluna->MovementInform(me, type, id))
|
|
||||||
ScriptedAI::MovementInform(type, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called before EnterCombat even before the creature is in combat.
|
|
||||||
void AttackStart(Unit* target) override
|
|
||||||
{
|
|
||||||
if (!sEluna->AttackStart(me, target))
|
|
||||||
ScriptedAI::AttackStart(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called for reaction at stopping attack at no attackers or targets
|
|
||||||
void EnterEvadeMode() override
|
|
||||||
{
|
|
||||||
if (!sEluna->EnterEvadeMode(me))
|
|
||||||
ScriptedAI::EnterEvadeMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
|
|
||||||
void AttackedBy(Unit* attacker) override
|
|
||||||
{
|
|
||||||
if (!sEluna->AttackedBy(me, attacker))
|
|
||||||
ScriptedAI::AttackedBy(attacker);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when creature is spawned or respawned (for reseting variables)
|
|
||||||
void JustRespawned() override
|
|
||||||
{
|
|
||||||
if (!sEluna->JustRespawned(me))
|
|
||||||
ScriptedAI::JustRespawned();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called at reaching home after evade
|
|
||||||
void JustReachedHome() override
|
|
||||||
{
|
|
||||||
if (!sEluna->JustReachedHome(me))
|
|
||||||
ScriptedAI::JustReachedHome();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called at text emote receive from player
|
|
||||||
void ReceiveEmote(Player* player, uint32 emoteId) override
|
|
||||||
{
|
|
||||||
if (!sEluna->ReceiveEmote(me, player, emoteId))
|
|
||||||
ScriptedAI::ReceiveEmote(player, emoteId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// called when the corpse of this creature gets removed
|
|
||||||
void CorpseRemoved(uint32& respawnDelay) override
|
|
||||||
{
|
|
||||||
if (!sEluna->CorpseRemoved(me, respawnDelay))
|
|
||||||
ScriptedAI::CorpseRemoved(respawnDelay);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef TRINITY
|
|
||||||
// Enables use of MoveInLineOfSight
|
|
||||||
bool IsVisible(Unit* who) const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void MoveInLineOfSight(Unit* who) override
|
|
||||||
{
|
|
||||||
if (!sEluna->MoveInLineOfSight(me, who))
|
|
||||||
ScriptedAI::MoveInLineOfSight(who);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when hit by a spell
|
|
||||||
void SpellHit(Unit* caster, SpellInfo const* spell) override
|
|
||||||
{
|
|
||||||
if (!sEluna->SpellHit(me, caster, spell))
|
|
||||||
ScriptedAI::SpellHit(caster, spell);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when spell hits a target
|
|
||||||
void SpellHitTarget(Unit* target, SpellInfo const* spell) override
|
|
||||||
{
|
|
||||||
if (!sEluna->SpellHitTarget(me, target, spell))
|
|
||||||
ScriptedAI::SpellHitTarget(target, spell);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef TRINITY
|
|
||||||
|
|
||||||
// Called when the creature is summoned successfully by other creature
|
|
||||||
void IsSummonedBy(Unit* summoner) override
|
|
||||||
{
|
|
||||||
if (!sEluna->OnSummoned(me, summoner))
|
|
||||||
ScriptedAI::IsSummonedBy(summoner);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SummonedCreatureDies(Creature* summon, Unit* killer) override
|
|
||||||
{
|
|
||||||
if (!sEluna->SummonedCreatureDies(me, summon, killer))
|
|
||||||
ScriptedAI::SummonedCreatureDies(summon, killer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when owner takes damage
|
|
||||||
void OwnerAttackedBy(Unit* attacker) override
|
|
||||||
{
|
|
||||||
if (!sEluna->OwnerAttackedBy(me, attacker))
|
|
||||||
ScriptedAI::OwnerAttackedBy(attacker);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when owner attacks something
|
|
||||||
void OwnerAttacked(Unit* target) override
|
|
||||||
{
|
|
||||||
if (!sEluna->OwnerAttacked(me, target))
|
|
||||||
ScriptedAI::OwnerAttacked(target);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef TRINITY
|
|
||||||
#undef me
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
// gameobject
|
// gameobject
|
||||||
bool Eluna::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget)
|
bool Eluna::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user