From c486e02d108f5e016faee8b5b263268f9f35135a Mon Sep 17 00:00:00 2001 From: Patman64 Date: Fri, 16 Jan 2015 17:11:27 -0500 Subject: [PATCH] Move ElunaCreatureAI into a separate file. --- ElunaCreatureAI.h | 212 ++++++++++++++++++++++++++++++++++++++++++++++ HookMgr.cpp | 201 +------------------------------------------ 2 files changed, 213 insertions(+), 200 deletions(-) create mode 100644 ElunaCreatureAI.h diff --git a/ElunaCreatureAI.h b/ElunaCreatureAI.h new file mode 100644 index 0000000..76b294e --- /dev/null +++ b/ElunaCreatureAI.h @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2010 - 2015 Eluna Lua Engine + * 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 diff --git a/HookMgr.cpp b/HookMgr.cpp index 59bd72a..4d0cfc0 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -10,6 +10,7 @@ #include "ElunaEventMgr.h" #include "ElunaIncludes.h" #include "ElunaTemplate.h" +#include "ElunaCreatureAI.h" extern "C" { @@ -18,13 +19,6 @@ extern "C" #include "lauxlib.h" }; -#ifndef TRINITY -class AggressorAI; -typedef AggressorAI ScriptedAI; -#else -struct ScriptedAI; -#endif - using namespace HookMgr; /* @@ -2202,199 +2196,6 @@ bool Eluna::OwnerAttacked(Creature* me, Unit* target) } #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 bool Eluna::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget) {