diff options
| author | ModoX <moardox@gmail.com> | 2023-11-05 21:14:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-05 21:14:24 +0100 |
| commit | caa4cfb5695deabd0bb9059f01435f3c8027aff7 (patch) | |
| tree | 9ead131b50cfd9aa5c8a4b00392d242f5b431a97 /src/server/scripts/EasternKingdoms | |
| parent | f4e4e62aea79ff478dbc0f2bb2c5ab7f412a8a66 (diff) | |
Core/AI: Move ArcherAI to individual creature script (#29383)
Diffstat (limited to 'src/server/scripts/EasternKingdoms')
| -rw-r--r-- | src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp b/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp index 95a4271be0c..c3414c6fabb 100644 --- a/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp +++ b/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp @@ -23,6 +23,7 @@ #include "GameObject.h" #include "GameObjectAI.h" #include "Log.h" +#include "Map.h" #include "MotionMaster.h" #include "MoveSplineInit.h" #include "ObjectAccessor.h" @@ -31,6 +32,7 @@ #include "Player.h" #include "ScriptedCreature.h" #include "ScriptedGossip.h" +#include "SpellMgr.h" #include "SpellScript.h" #include "SpellInfo.h" #include "TemporarySummon.h" @@ -1136,6 +1138,59 @@ class spell_chapter1_runeforging_credit : public SpellScript } }; +// 29102 - Hearthglen Crusader +// 29103 - Tirisfal Crusader +struct npc_hearthglen_crusader : public ScriptedAI +{ + npc_hearthglen_crusader(Creature* creature) : ScriptedAI(creature), _minimumRange(0) + { + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(creature->m_spells[0], creature->GetMap()->GetDifficultyID()); + if (!spellInfo) + return; + + _minimumRange = spellInfo->GetMinRange(false); + + if (!_minimumRange) + _minimumRange = MELEE_RANGE; + creature->m_CombatDistance = spellInfo->GetMaxRange(false); + creature->m_SightDistance = creature->m_CombatDistance; + } + + void AttackStart(Unit* who) override + { + if (!who) + return; + + if (me->IsWithinCombatRange(who, _minimumRange)) + { + if (me->Attack(who, true) && !who->IsFlying()) + me->GetMotionMaster()->MoveChase(who); + } + else + { + if (me->Attack(who, false) && !who->IsFlying()) + me->GetMotionMaster()->MoveChase(who, me->m_CombatDistance); + } + + if (who->IsFlying()) + me->GetMotionMaster()->MoveIdle(); + } + + void UpdateAI(uint32 /*diff*/) override + { + if (!UpdateVictim()) + return; + + if (!me->IsWithinCombatRange(me->GetVictim(), _minimumRange)) + DoSpellAttackIfReady(me->m_spells[0]); + else + DoMeleeAttackIfReady(); + } + +private: + float _minimumRange; +}; + void AddSC_the_scarlet_enclave_c1() { new npc_unworthy_initiate(); @@ -1153,4 +1208,5 @@ void AddSC_the_scarlet_enclave_c1() RegisterCreatureAI(npc_scarlet_ghoul); RegisterSpellScript(spell_gift_of_the_harvester); RegisterSpellScript(spell_chapter1_runeforging_credit); + RegisterCreatureAI(npc_hearthglen_crusader); } |
