aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorModoX <moardox@gmail.com>2023-11-05 21:14:24 +0100
committerGitHub <noreply@github.com>2023-11-05 21:14:24 +0100
commitcaa4cfb5695deabd0bb9059f01435f3c8027aff7 (patch)
tree9ead131b50cfd9aa5c8a4b00392d242f5b431a97
parentf4e4e62aea79ff478dbc0f2bb2c5ab7f412a8a66 (diff)
Core/AI: Move ArcherAI to individual creature script (#29383)
-rw-r--r--sql/updates/world/master/2023_11_05_00_world.sql2
-rw-r--r--src/server/game/AI/CoreAI/CombatAI.cpp49
-rw-r--r--src/server/game/AI/CoreAI/CombatAI.h13
-rw-r--r--src/server/game/AI/CreatureAIRegistry.cpp1
-rw-r--r--src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp56
5 files changed, 58 insertions, 63 deletions
diff --git a/sql/updates/world/master/2023_11_05_00_world.sql b/sql/updates/world/master/2023_11_05_00_world.sql
new file mode 100644
index 00000000000..62f75af9ef7
--- /dev/null
+++ b/sql/updates/world/master/2023_11_05_00_world.sql
@@ -0,0 +1,2 @@
+--
+UPDATE `creature_template` SET `AIName`='', `ScriptName`='npc_hearthglen_crusader' WHERE `entry` IN(29102, 29103);
diff --git a/src/server/game/AI/CoreAI/CombatAI.cpp b/src/server/game/AI/CoreAI/CombatAI.cpp
index efa8df549a2..16c161dbd7a 100644
--- a/src/server/game/AI/CoreAI/CombatAI.cpp
+++ b/src/server/game/AI/CoreAI/CombatAI.cpp
@@ -190,55 +190,6 @@ void CasterAI::UpdateAI(uint32 diff)
}
//////////////
-// ArcherAI
-//////////////
-
-ArcherAI::ArcherAI(Creature* creature, uint32 scriptId) : CreatureAI(creature, scriptId)
-{
- if (!creature->m_spells[0])
- TC_LOG_ERROR("scripts.ai", "ArcherAI set for creature with spell1 = 0. AI will do nothing ({})", creature->GetGUID().ToString());
-
- SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(creature->m_spells[0], creature->GetMap()->GetDifficultyID());
- _minimumRange = spellInfo ? spellInfo->GetMinRange(false) : 0;
-
- if (!_minimumRange)
- _minimumRange = MELEE_RANGE;
- creature->m_CombatDistance = spellInfo ? spellInfo->GetMaxRange(false) : 0;
- creature->m_SightDistance = creature->m_CombatDistance;
-}
-
-void ArcherAI::AttackStart(Unit* who)
-{
- 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 ArcherAI::UpdateAI(uint32 /*diff*/)
-{
- if (!UpdateVictim())
- return;
-
- if (!me->IsWithinCombatRange(me->GetVictim(), _minimumRange))
- DoSpellAttackIfReady(me->m_spells[0]);
- else
- DoMeleeAttackIfReady();
-}
-
-//////////////
// TurretAI
//////////////
diff --git a/src/server/game/AI/CoreAI/CombatAI.h b/src/server/game/AI/CoreAI/CombatAI.h
index bfcb1042670..cd861b52398 100644
--- a/src/server/game/AI/CoreAI/CombatAI.h
+++ b/src/server/game/AI/CoreAI/CombatAI.h
@@ -65,19 +65,6 @@ class TC_GAME_API CasterAI : public CombatAI
float _attackDistance;
};
-struct TC_GAME_API ArcherAI : public CreatureAI
-{
- public:
- explicit ArcherAI(Creature* creature, uint32 scriptId = {});
- void AttackStart(Unit* who) override;
- void UpdateAI(uint32 diff) override;
-
- static int32 Permissible(Creature const* /*creature*/) { return PERMIT_BASE_NO; }
-
- protected:
- float _minimumRange;
-};
-
struct TC_GAME_API TurretAI : public CreatureAI
{
public:
diff --git a/src/server/game/AI/CreatureAIRegistry.cpp b/src/server/game/AI/CreatureAIRegistry.cpp
index 462dc5ae9b0..7b85c3ce540 100644
--- a/src/server/game/AI/CreatureAIRegistry.cpp
+++ b/src/server/game/AI/CreatureAIRegistry.cpp
@@ -45,7 +45,6 @@ namespace AIRegistry
(new CreatureAIFactory<PetAI, false>("PetAI"))->RegisterSelf();
(new CreatureAIFactory<TotemAI, false>("TotemAI"))->RegisterSelf();
(new CreatureAIFactory<CombatAI>("CombatAI"))->RegisterSelf();
- (new CreatureAIFactory<ArcherAI>("ArcherAI"))->RegisterSelf();
(new CreatureAIFactory<TurretAI>("TurretAI"))->RegisterSelf();
(new CreatureAIFactory<VehicleAI>("VehicleAI"))->RegisterSelf();
(new CreatureAIFactory<SmartAI>("SmartAI"))->RegisterSelf();
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);
}