diff --git a/sql/migrations/20211210084942_world.sql b/sql/migrations/20211210084942_world.sql
new file mode 100644
index 000000000..b314648d4
--- /dev/null
+++ b/sql/migrations/20211210084942_world.sql
@@ -0,0 +1,38 @@
+DROP PROCEDURE IF EXISTS add_migration;
+delimiter ??
+CREATE PROCEDURE `add_migration`()
+BEGIN
+DECLARE v INT DEFAULT 1;
+SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20211210084942');
+IF v=0 THEN
+INSERT INTO `migrations` VALUES ('20211210084942');
+-- Add your query below.
+
+
+-- Assign NoAggro flag to creatures using ReactorAI.
+UPDATE `creature_template` SET `ai_name`='', `flags_extra` = `flags_extra` | 2 WHERE `ai_name`='ReactorAI';
+
+-- Assign NoAggro flag to Hurley Blackbreath and his cronies.
+UPDATE `creature_template` SET `flags_extra` = `flags_extra` | 2 WHERE `entry` IN (9537, 9541);
+
+-- Update existing script to make Hurley Blackbreath aggressive.
+DELETE FROM `creature_movement_scripts` WHERE `id`=953704;
+INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (953704, 0, 20, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Hurley Blackbreath - Move Idle');
+INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (953704, 1, 34, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Hurley Blackbreath - Set Home Position');
+INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (953704, 1, 4, 46, 256, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Hurley Blackbreath - Remove Immune To Player Flag');
+INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (953704, 1, 59, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Hurley Blackbreath - Set React State to Aggressive');
+INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (953704, 1, 68, 9541, 2, 9541, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Hurley Blackbreath - Start Script on Cronies');
+
+-- Update existing script to make Blackbreath Cronies aggressive.
+DELETE FROM `generic_scripts` WHERE `id`=9541;
+INSERT INTO `generic_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (9541, 0, 34, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Blackbreath Crony - Set Home Position');
+INSERT INTO `generic_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (9541, 0, 4, 46, 256, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Blackbreath Crony - Remove Immune To Player Flag');
+INSERT INTO `generic_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (9541, 0, 59, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Blackbreath Crony - Set React State to Aggressive');
+
+
+-- End of migration.
+END IF;
+END??
+delimiter ;
+CALL add_migration();
+DROP PROCEDURE IF EXISTS add_migration;
diff --git a/src/game/AI/AggressorAI.cpp b/src/game/AI/AggressorAI.cpp
deleted file mode 100644
index 3306f8b79..000000000
--- a/src/game/AI/AggressorAI.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2005-2011 MaNGOS
- * Copyright (C) 2009-2011 MaNGOSZero
- * Copyright (C) 2011-2016 Nostalrius
- * Copyright (C) 2016-2017 Elysium Project
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "AggressorAI.h"
-#include "Creature.h"
-#include "Map.h"
-
-int AggressorAI::Permissible(Creature const* creature)
-{
- // have some hostile factions, it will be selected by IsHostileTo check at MoveInLineOfSight
- if (!creature->HasExtraFlag(CREATURE_FLAG_EXTRA_NO_AGGRO) && !creature->IsNeutralToAll())
- return PERMIT_BASE_PROACTIVE;
-
- return PERMIT_BASE_NO;
-}
-
-void AggressorAI::MoveInLineOfSight(Unit* u)
-{
- // Check this now to prevent calling expensive functions (IsInAccessablePlaceFor / IsWithinLOSInMap)
- if (m_creature->GetVictim() && !m_creature->GetMap()->IsDungeon())
- return;
-
- if (!m_creature->IsWithinDistInMap(u, m_creature->GetAttackDistance(u), true, false))
- return;
-
- if (m_creature->CanInitiateAttack() && u->IsTargetable(true, false) && m_creature->IsHostileTo(u) &&
- m_creature->IsWithinLOSInMap(u) && u->IsInAccessablePlaceFor(m_creature))
- {
- if (!m_creature->GetVictim())
- AttackStart(u);
- else if (m_creature->GetMap()->IsDungeon())
- {
- m_creature->AddThreat(u);
- u->SetInCombatWith(m_creature);
- }
- }
-}
-
-
-void AggressorAI::UpdateAI(uint32 const uiDiff)
-{
- if (!m_creature->SelectHostileTarget() || !m_creature->GetVictim())
- return;
-
- if (!m_CreatureSpells.empty())
- UpdateSpellsList(uiDiff);
-
- DoMeleeAttackIfReady();
-}
-
-void AggressorAI::AttackStart(Unit* u)
-{
- if (!u)
- return;
-
- if (m_creature->Attack(u, true))
- {
- m_creature->AddThreat(u);
- m_creature->SetInCombatWith(u);
- u->SetInCombatWith(m_creature);
-
- if (m_bCombatMovement)
- m_creature->GetMotionMaster()->MoveChase(u);
- }
-}
diff --git a/src/game/AI/AggressorAI.h b/src/game/AI/AggressorAI.h
deleted file mode 100644
index 9131affd5..000000000
--- a/src/game/AI/AggressorAI.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2005-2011 MaNGOS
- * Copyright (C) 2009-2011 MaNGOSZero
- * Copyright (C) 2011-2016 Nostalrius
- * Copyright (C) 2016-2017 Elysium Project
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef MANGOS_AGGRESSORAI_H
-#define MANGOS_AGGRESSORAI_H
-
-#include "CreatureAI.h"
-
-class AggressorAI : public CreatureAI
-{
- public:
-
- explicit AggressorAI(Creature* c) : CreatureAI(c) {}
-
- void MoveInLineOfSight(Unit*) override;
- void AttackStart(Unit*) override;
- void UpdateAI(uint32 const) override;
-
- static int Permissible(Creature const*);
-};
-
-#endif
diff --git a/src/game/AI/BasicAI.cpp b/src/game/AI/BasicAI.cpp
new file mode 100644
index 000000000..114e51ca5
--- /dev/null
+++ b/src/game/AI/BasicAI.cpp
@@ -0,0 +1,110 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "BasicAI.h"
+#include "Creature.h"
+#include "GuardMgr.h"
+
+BasicAI::BasicAI(Creature* c) : CreatureAI(c), m_bCanSummonGuards(c->CanSummonGuards())
+{}
+
+int BasicAI::Permissible(Creature const* creature)
+{
+ return PERMIT_BASE_NORMAL;
+}
+
+bool BasicAI::IsProximityAggroAllowedFor(Unit* pTarget) const
+{
+ if (!m_creature->GetVictim())
+ return true;
+
+ // Allow this case for summoning guards against player we are in combat with.
+ if (m_creature->GetVictim() == pTarget)
+ return true;
+
+ if (m_creature->GetMap()->IsDungeon())
+ return true;
+
+ if (Player* pNearPlayer = pTarget->ToPlayer())
+ {
+ if (Player* pVictimPlayer = m_creature->GetVictim()->ToPlayer())
+ {
+ if (pNearPlayer->GetGroup() &&
+ pNearPlayer->GetGroup() == pVictimPlayer->GetGroup())
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void BasicAI::MoveInLineOfSight(Unit* pWho)
+{
+ // Check this now to prevent calling expensive functions (IsInAccessablePlaceFor / IsWithinLOSInMap)
+ if (!IsProximityAggroAllowedFor(pWho))
+ return;
+
+ bool const canInitiateAttack = pWho != m_creature->GetVictim() && m_creature->CanInitiateAttack();
+ bool const canSummonGuard = pWho->IsPlayer() && CanSummonGuards();
+
+ if (!canInitiateAttack && !canSummonGuard)
+ return;
+
+ if (!m_creature->CanFly() && m_creature->GetDistanceZ(pWho) > CREATURE_Z_ATTACK_RANGE)
+ return;
+
+ float const maxDistance = canInitiateAttack ? m_creature->GetAttackDistance(pWho) : m_creature->GetDetectionRange();
+
+ if (m_creature->IsWithinDistInMap(pWho, maxDistance, true, false) &&
+ pWho->IsTargetableBy(m_creature) && m_creature->IsHostileTo(pWho) &&
+ m_creature->IsWithinLOSInMap(pWho) && pWho->IsInAccessablePlaceFor(m_creature))
+ {
+ if (canInitiateAttack)
+ m_creature->EnterCombatWithTarget(pWho);
+ else if (canSummonGuard)
+ SummonGuard(pWho);
+ }
+}
+
+void BasicAI::JustRespawned()
+{
+ if (m_creature->CanSummonGuards())
+ m_bCanSummonGuards = true;
+
+ CreatureAI::JustRespawned();
+}
+
+void BasicAI::SummonedCreatureDespawn(Creature* pSummon)
+{
+ if (m_creature->CanSummonGuards() && pSummon->IsGuard())
+ m_bCanSummonGuards = true;
+}
+
+void BasicAI::UpdateAI(uint32 const uiDiff)
+{
+ if (!m_creature->SelectHostileTarget() || !m_creature->GetVictim())
+ return;
+
+ if (!m_CreatureSpells.empty())
+ UpdateSpellsList(uiDiff);
+
+ DoMeleeAttackIfReady();
+}
+
+void BasicAI::SummonGuard(Unit* pEnemy)
+{
+ m_bCanSummonGuards = !sGuardMgr.SummonGuard(m_creature, pEnemy);
+}
diff --git a/src/game/AI/ReactorAI.h b/src/game/AI/BasicAI.h
similarity index 68%
rename from src/game/AI/ReactorAI.h
rename to src/game/AI/BasicAI.h
index 490d829a9..45fdac8f1 100644
--- a/src/game/AI/ReactorAI.h
+++ b/src/game/AI/BasicAI.h
@@ -1,9 +1,4 @@
/*
- * Copyright (C) 2005-2011 MaNGOS
- * Copyright (C) 2009-2011 MaNGOSZero
- * Copyright (C) 2011-2016 Nostalrius
- * Copyright (C) 2016-2017 Elysium Project
- *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -19,28 +14,29 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef MANGOS_REACTORAI_H
-#define MANGOS_REACTORAI_H
+#ifndef MANGOS_AGGRESSORAI_H
+#define MANGOS_AGGRESSORAI_H
#include "CreatureAI.h"
-class Creature;
-
-class ReactorAI : public CreatureAI
+class BasicAI : public CreatureAI
{
public:
- explicit ReactorAI(Creature* c);
+ explicit BasicAI(Creature* c);
void MoveInLineOfSight(Unit*) override;
- void AttackStart(Unit*) override;
+ bool IsProximityAggroAllowedFor(Unit*) const;
void UpdateAI(uint32 const) override;
- void JustRespawned() override;
+ // Used for civillians that can summon guards.
+ void JustRespawned() override;
+ virtual void SummonedCreatureDespawn(Creature* /*pSummon*/) override;
bool CanSummonGuards() const { return m_bCanSummonGuards; }
+ void SummonGuard(Unit* /*pEnemy*/);
static int Permissible(Creature const*);
- private:
+ protected:
bool m_bCanSummonGuards;
};
diff --git a/src/game/AI/CreatureAI.cpp b/src/game/AI/CreatureAI.cpp
index ae2fa8b38..1e0ec6a5c 100644
--- a/src/game/AI/CreatureAI.cpp
+++ b/src/game/AI/CreatureAI.cpp
@@ -53,6 +53,22 @@ void CreatureAI::AttackedBy(Unit* attacker)
AttackStart(attacker);
}
+void CreatureAI::AttackStart(Unit* pVictim)
+{
+ if (!pVictim || m_creature->HasReactState(REACT_PASSIVE))
+ return;
+
+ if (m_creature->Attack(pVictim, m_bMeleeAttack))
+ {
+ m_creature->AddThreat(pVictim);
+ m_creature->SetInCombatWith(pVictim);
+ pVictim->SetInCombatWith(m_creature);
+
+ if (m_bCombatMovement)
+ m_creature->GetMotionMaster()->MoveChase(pVictim);
+ }
+}
+
CanCastResult CreatureAI::CanCastSpell(Unit* pTarget, SpellEntry const* pSpell, bool isTriggered)
{
if (!pTarget)
@@ -310,56 +326,6 @@ void CreatureAI::ClearTargetIcon()
}
}
-void CreatureAI::SetGazeOn(Unit* target)
-{
- if (m_creature->CanAttack(target))
- {
- AttackStart(target);
- m_creature->SetReactState(REACT_PASSIVE);
- }
-}
-
-bool CreatureAI::UpdateVictimWithGaze()
-{
- if (!m_creature->IsInCombat())
- return false;
-
- if (m_creature->HasReactState(REACT_PASSIVE))
- {
- if (m_creature->GetVictim())
- return true;
- m_creature->SetReactState(REACT_AGGRESSIVE);
- }
-
- if (m_creature->SelectHostileTarget())
- if (Unit* victim = m_creature->GetVictim())
- AttackStart(victim);
- return m_creature->GetVictim();
-}
-
-bool CreatureAI::UpdateVictim()
-{
- if (!m_creature->IsInCombat())
- return false;
-
- if (!m_creature->HasReactState(REACT_PASSIVE))
- {
- if (m_creature->SelectHostileTarget())
- if (Unit* victim = m_creature->GetVictim())
- AttackStart(victim);
- return m_creature->GetVictim();
- }
-
- if (m_creature->GetThreatManager().isThreatListEmpty())
- {
- EnterEvadeMode();
- return false;
- }
-
- return true;
-}
-
-
void CreatureAI::DoCast(Unit* victim, uint32 spellId, bool triggered)
{
if (!victim || (m_creature->IsNonMeleeSpellCasted(false) && !triggered))
@@ -381,25 +347,6 @@ bool CreatureAI::DoMeleeAttackIfReady()
return m_bMeleeAttack ? m_creature->UpdateMeleeAttackingState() : false;
}
-struct EnterEvadeModeHelper
-{
- explicit EnterEvadeModeHelper(Unit* _source) : source(_source) {}
- void operator()(Unit* unit) const
- {
- if (unit->IsCreature() && unit->ToCreature()->IsTotem())
- ((Totem*)unit)->UnSummon();
- else
- {
- unit->GetMotionMaster()->Clear(false);
- // for a controlled unit this will result in a follow move
- unit->GetMotionMaster()->MoveTargetedHome();
- unit->DeleteThreatList();
- unit->CombatStop(true);
- }
- }
- Unit* source;
-};
-
void CreatureAI::SetMeleeAttack(bool enabled)
{
if (m_bMeleeAttack == enabled)
@@ -444,6 +391,25 @@ void CreatureAI::SetCombatMovement(bool enabled)
}
}
+struct EnterEvadeModeHelper
+{
+ explicit EnterEvadeModeHelper(Unit* _source) : source(_source) {}
+ void operator()(Unit* unit) const
+ {
+ if (unit->IsCreature() && unit->ToCreature()->IsTotem())
+ ((Totem*)unit)->UnSummon();
+ else
+ {
+ unit->GetMotionMaster()->Clear(false);
+ // for a controlled unit this will result in a follow move
+ unit->GetMotionMaster()->MoveTargetedHome();
+ unit->DeleteThreatList();
+ unit->CombatStop(true);
+ }
+ }
+ Unit* source;
+};
+
void CreatureAI::OnCombatStop()
{
// Reset back to default spells template. This also resets timers.
diff --git a/src/game/AI/CreatureAI.h b/src/game/AI/CreatureAI.h
index 4604bd7d3..2cc7d1617 100644
--- a/src/game/AI/CreatureAI.h
+++ b/src/game/AI/CreatureAI.h
@@ -66,17 +66,13 @@ class CreatureAI
explicit CreatureAI(Creature* creature);
virtual ~CreatureAI();
- virtual void OnRemoveFromWorld() {}
-
- virtual uint32 GetData(uint32 /*type*/) { return 0; }
-
- virtual void InformGuid(ObjectGuid const /*guid*/, uint32 /*type*/=0) {}
- virtual void DoAction(uint32 const /*type*/=0) {}
- virtual void DoAction(Unit* /*pUnit*/, uint32 /*type*/) {}
///== Information about AI ========================
+
virtual void GetAIInformation(ChatHandler& /*reader*/) {}
+ virtual uint32 GetData(uint32 /*type*/) { return 0; }
+
///== Reactions At =================================
// Called when an unit moves within visibility distance
@@ -154,11 +150,20 @@ class CreatureAI
virtual void OwnerAttackedBy(Unit* /*attacker*/) {}
virtual void OwnerAttacked(Unit* /*target*/) {}
+ // Called by another script
+ virtual void OnScriptEventHappened(uint32 /*uiEvent*/ = 0, uint32 /*uiData*/ = 0, WorldObject* /*pInvoker*/ = nullptr) {};
+
+ // Called before being removed from the map
+ virtual void OnRemoveFromWorld() {}
+
+ // called when the corpse of this creature gets removed
+ virtual void CorpseRemoved(uint32& /*respawnDelay*/) {}
+
///== Triggered Actions Requested ==================
// Called when creature attack expected (if creature can and no have current victim)
// Note: for reaction at hostile action must be called AttackedBy function.
- virtual void AttackStart(Unit*) {}
+ virtual void AttackStart(Unit*);
// Called at World update tick
virtual void UpdateAI(uint32 const /*diff*/) {}
@@ -166,14 +171,14 @@ class CreatureAI
// Like UpdateAI, but only when the creature is a dead corpse
virtual void UpdateAI_corpse(uint32 const /*uiDiff*/) {}
- // Called by another script
- virtual void OnScriptEventHappened(uint32 /*uiEvent*/, uint32 /*uiData*/, WorldObject* /*pInvoker*/) {};
+ // Triggers an alert when a Unit moves near stealth detection range.
+ virtual void TriggerAlert(Unit const* who);
+ // Will auto attack if the swing timer is ready.
+ bool DoMeleeAttackIfReady();
+
///== State checks =================================
- // called when the corpse of this creature gets removed
- virtual void CorpseRemoved(uint32& /*respawnDelay*/) {}
-
// Is corpse looting allowed ?
virtual bool CanBeLooted() const { return true; }
@@ -186,27 +191,18 @@ class CreatureAI
// Does the creature melee attack.
bool IsMeleeAttackEnabled() const { return m_bMeleeAttack; }
- // Triggers an alert when a Unit moves near stealth detection range.
- virtual void TriggerAlert(Unit const* who);
-
- // TrinityCore
- void DoCast(Unit* victim, uint32 spellId, bool triggered = false);
- void DoCastAOE(uint32 spellId, bool triggered = false);
- bool UpdateVictim();
- bool UpdateVictimWithGaze();
- void SetGazeOn(Unit* target);
-
///== Helper functions =============================
- // Will auto attack if the swing timer is ready.
- bool DoMeleeAttackIfReady();
-
// Attempts to cast a spell and returns the result.
CanCastResult DoCastSpellIfCan(Unit* pTarget, uint32 uiSpell, uint32 uiCastFlags = 0, ObjectGuid uiOriginalCasterGUID = ObjectGuid());
// Helper functions for cast spell
virtual CanCastResult CanCastSpell(Unit* pTarget, SpellEntry const* pSpell, bool isTriggered);
+ // TrinityCore
+ void DoCast(Unit* victim, uint32 spellId, bool triggered = false);
+ void DoCastAOE(uint32 spellId, bool triggered = false);
+
// Clears any group/raid icons this creature may have
void ClearTargetIcon();
@@ -221,7 +217,7 @@ class CreatureAI
// Enables or disables melee attacks.
void SetMeleeAttack(bool enabled);
- // Enables or disabled combat movement.
+ // Enables or disables combat movement.
void SetCombatMovement(bool enabled);
// Pointer to controlled by AI creature
@@ -257,10 +253,8 @@ enum Permitions
{
PERMIT_BASE_NO = -1,
PERMIT_BASE_IDLE = 1,
- PERMIT_BASE_REACTIVE = 100,
- PERMIT_BASE_PROACTIVE = 200,
- PERMIT_BASE_FACTION_SPECIFIC = 400,
- PERMIT_BASE_SPECIAL = 800
+ PERMIT_BASE_NORMAL = 100,
+ PERMIT_BASE_SPECIAL = 200
};
typedef FactoryHolder CreatureAICreator;
diff --git a/src/game/AI/CreatureAIRegistry.cpp b/src/game/AI/CreatureAIRegistry.cpp
index 0ae7f4622..0b739e77d 100644
--- a/src/game/AI/CreatureAIRegistry.cpp
+++ b/src/game/AI/CreatureAIRegistry.cpp
@@ -20,8 +20,7 @@
*/
#include "NullCreatureAI.h"
-#include "ReactorAI.h"
-#include "AggressorAI.h"
+#include "BasicAI.h"
#include "CritterAI.h"
#include "GuardAI.h"
#include "GuardEventAI.h"
@@ -40,8 +39,7 @@ namespace AIRegistry
void Initialize()
{
(new CreatureAIFactory("NullAI"))->RegisterSelf();
- (new CreatureAIFactory("AggressorAI"))->RegisterSelf();
- (new CreatureAIFactory("ReactorAI"))->RegisterSelf();
+ (new CreatureAIFactory("BasicAI"))->RegisterSelf();
(new CreatureAIFactory("CritterAI"))->RegisterSelf();
(new CreatureAIFactory("GuardAI"))->RegisterSelf();
(new CreatureAIFactory("PetAI"))->RegisterSelf();
diff --git a/src/game/AI/CreatureEventAI.cpp b/src/game/AI/CreatureEventAI.cpp
index 1795b235b..ff9717873 100644
--- a/src/game/AI/CreatureEventAI.cpp
+++ b/src/game/AI/CreatureEventAI.cpp
@@ -59,7 +59,7 @@ void CreatureEventAI::GetAIInformation(ChatHandler& reader)
reader.PSendSysMessage(LANG_NPC_EVENTAI_PHASE, (uint32)m_Phase);
}
-CreatureEventAI::CreatureEventAI(Creature* c) : CreatureAI(c)
+CreatureEventAI::CreatureEventAI(Creature* c) : BasicAI(c)
{
// Need make copy for filter unneeded steps and safe in case table reload
CreatureEventAI_Event_Map::const_iterator creatureEventsItr = sEventAIMgr.GetCreatureEventAIMap().find(m_creature->GetEntry());
@@ -101,9 +101,6 @@ CreatureEventAI::CreatureEventAI(Creature* c) : CreatureAI(c)
m_bEmptyList = m_CreatureEventAIList.empty();
m_Phase = 0;
- m_AttackDistance = 0.0f;
- m_AttackAngle = 0.0f;
- m_bCanSummonGuards = c->CanSummonGuards();
m_InvinceabilityHpLevel = 0;
//Handle Spawned Events
@@ -445,9 +442,7 @@ void CreatureEventAI::JustRespawned()
{
Reset();
- CreatureAI::JustRespawned();
-
- m_bCanSummonGuards = m_creature->CanSummonGuards();
+ BasicAI::JustRespawned();
if (m_bEmptyList)
return;
@@ -499,7 +494,7 @@ void CreatureEventAI::JustReachedHome()
void CreatureEventAI::EnterEvadeMode()
{
- CreatureAI::EnterEvadeMode();
+ BasicAI::EnterEvadeMode();
if (m_bEmptyList)
return;
@@ -514,7 +509,7 @@ void CreatureEventAI::EnterEvadeMode()
void CreatureEventAI::OnCombatStop()
{
- CreatureAI::OnCombatStop();
+ BasicAI::OnCombatStop();
if (m_bEmptyList)
return;
@@ -583,7 +578,9 @@ void CreatureEventAI::SummonedCreatureJustDied(Creature* pUnit)
void CreatureEventAI::SummonedCreatureDespawn(Creature* pUnit)
{
- if (m_bEmptyList || !pUnit)
+ BasicAI::SummonedCreatureDespawn(pUnit);
+
+ if (m_bEmptyList)
return;
for (auto& i : m_CreatureEventAIList)
@@ -625,70 +622,13 @@ void CreatureEventAI::EnterCombat(Unit* enemy)
m_EventDiff = 0;
}
-void CreatureEventAI::AttackStart(Unit* who)
-{
- if (!who)
- return;
-
- if (m_creature->Attack(who, m_bMeleeAttack))
- {
- m_creature->AddThreat(who);
- m_creature->SetInCombatWith(who);
- who->SetInCombatWith(m_creature);
-
- if (m_bCombatMovement)
- m_creature->GetMotionMaster()->MoveChase(who, m_AttackDistance, m_AttackAngle);
- }
-}
-
void CreatureEventAI::MoveInLineOfSight(Unit* pWho)
{
- if (!pWho)
- return;
+ // Check for OOC LOS Event
+ if (!m_creature->GetVictim() && !m_bEmptyList)
+ UpdateEventsOn_MoveInLineOfSight(pWho);
- //Check for OOC LOS Event
- if (!m_creature->GetVictim())
- {
- if (!m_bEmptyList)
- UpdateEventsOn_MoveInLineOfSight(pWho);
-
- if (m_bCanSummonGuards && pWho->IsPlayer() && m_creature->IsWithinDistInMap(pWho, m_creature->GetDetectionRange()) &&
- m_creature->IsHostileTo(pWho) && pWho->IsTargetable(true, false) && m_creature->IsWithinLOSInMap(pWho))
- {
- m_bCanSummonGuards = !sGuardMgr.SummonGuard(m_creature, static_cast(pWho));
- }
- }
-
- if (m_creature->HasExtraFlag(CREATURE_FLAG_EXTRA_NO_AGGRO) || m_creature->IsNeutralToAll())
- return;
-
- // Check this now to prevent calling expensive functions (IsInAccessablePlaceFor / IsWithinLOSInMap)
- if (m_creature->GetVictim() && !m_creature->GetMap()->IsDungeon())
- return;
-
- if (!m_creature->CanFly() && m_creature->GetDistanceZ(pWho) > CREATURE_Z_ATTACK_RANGE)
- return;
-
- if (m_creature->CanInitiateAttack() && pWho->IsTargetable(true, false))
- {
- float attackRadius = m_creature->GetAttackDistance(pWho);
- if (m_creature->IsWithinDistInMap(pWho, attackRadius, true, false) && m_creature->IsHostileTo(pWho))
- {
- if (!m_creature->GetVictim())
- {
- if (m_creature->IsWithinLOSInMap(pWho) && pWho->IsInAccessablePlaceFor(m_creature))
- AttackStart(pWho);
- }
- else if (m_creature->GetMap()->IsDungeon())
- {
- if (m_creature->IsWithinLOSInMap(pWho) && pWho->IsInAccessablePlaceFor(m_creature))
- {
- m_creature->AddThreat(pWho);
- pWho->SetInCombatWith(m_creature);
- }
- }
- }
- }
+ BasicAI::MoveInLineOfSight(pWho);
}
void CreatureEventAI::UpdateEventsOn_MoveInLineOfSight(Unit* pWho)
diff --git a/src/game/AI/CreatureEventAI.h b/src/game/AI/CreatureEventAI.h
index 647e25cd8..46db3b12d 100644
--- a/src/game/AI/CreatureEventAI.h
+++ b/src/game/AI/CreatureEventAI.h
@@ -23,7 +23,7 @@
#define MANGOS_CREATURE_EAI_H
#include "Common.h"
-#include "CreatureAI.h"
+#include "BasicAI.h"
#include "ScriptMgr.h"
class Unit;
@@ -289,7 +289,7 @@ struct CreatureEventAIHolder
bool UpdateRepeatTimer(Creature* creature, uint32 repeatMin, uint32 repeatMax);
};
-class CreatureEventAI : public CreatureAI
+class CreatureEventAI : public BasicAI
{
public:
explicit CreatureEventAI(Creature* c);
@@ -309,7 +309,6 @@ class CreatureEventAI : public CreatureAI
void JustDied(Unit* killer) override;
void KilledUnit(Unit* victim) override;
void JustSummoned(Creature* pUnit) override;
- void AttackStart(Unit* who) override;
void MoveInLineOfSight(Unit* who) override;
void SpellHit(SpellCaster* pCaster, SpellEntry const* pSpell) override;
void MovementInform(uint32 type, uint32 id) override;
@@ -337,10 +336,7 @@ class CreatureEventAI : public CreatureAI
//Variables used by Events themselves
typedef std::vector CreatureEventAIList;
CreatureEventAIList m_CreatureEventAIList; //Holder for events (stores enabled, time, and eventid)
- float m_AttackDistance; // Distance to attack from
- float m_AttackAngle; // Angle of attack
uint32 m_InvinceabilityHpLevel; // Minimal health level allowed at damage apply
- bool m_bCanSummonGuards;
void UpdateEventsOn_UpdateAI(uint32 const diff, bool Combat);
void UpdateEventsOn_MoveInLineOfSight(Unit* pWho);
diff --git a/src/game/AI/GameObjectAI.h b/src/game/AI/GameObjectAI.h
index bee737e16..54473ce4f 100644
--- a/src/game/AI/GameObjectAI.h
+++ b/src/game/AI/GameObjectAI.h
@@ -17,7 +17,6 @@ class GameObjectAI
virtual void UpdateAI(uint32 const /*uiDiff*/) {}
virtual void SetData(uint32 /*id*/, uint32 /*value*/) {}
- virtual void InformGuid(ObjectGuid guid) {}
virtual bool OnUse(Unit* /*user*/) { return false; }
// Called when the gameobject summon successfully a creature
diff --git a/src/game/AI/GuardAI.cpp b/src/game/AI/GuardAI.cpp
index b3d03ef3f..c5c47f038 100644
--- a/src/game/AI/GuardAI.cpp
+++ b/src/game/AI/GuardAI.cpp
@@ -97,18 +97,3 @@ void GuardAI::UpdateAI(uint32 const uiDiff)
DoMeleeAttackIfReady();
}
-void GuardAI::AttackStart(Unit* pWho)
-{
- if (!pWho)
- return;
-
- if (m_creature->Attack(pWho, m_bMeleeAttack))
- {
- m_creature->AddThreat(pWho);
- m_creature->SetInCombatWith(pWho);
- pWho->SetInCombatWith(m_creature);
-
- if (m_bCombatMovement)
- m_creature->GetMotionMaster()->MoveChase(pWho);
- }
-}
diff --git a/src/game/AI/GuardAI.h b/src/game/AI/GuardAI.h
index 8496c835d..644303ffd 100644
--- a/src/game/AI/GuardAI.h
+++ b/src/game/AI/GuardAI.h
@@ -32,7 +32,6 @@ class GuardAI : public CreatureAI
explicit GuardAI(Creature* c);
void MoveInLineOfSight(Unit*) override;
- void AttackStart(Unit*) override;
void EnterCombat(Unit*) override;
void UpdateAI(uint32 const) override;
static int Permissible(Creature const*);
diff --git a/src/game/AI/GuardEventAI.cpp b/src/game/AI/GuardEventAI.cpp
index c6e3837bb..b10c126bc 100644
--- a/src/game/AI/GuardEventAI.cpp
+++ b/src/game/AI/GuardEventAI.cpp
@@ -47,9 +47,6 @@ bool GuardEventAI::IsAttackingPlayerOrFriendly(Unit const* pWho) const
void GuardEventAI::MoveInLineOfSight(Unit* pWho)
{
- if (!pWho)
- return;
-
if (m_creature->GetVictim())
return;
diff --git a/src/game/AI/PetEventAI.cpp b/src/game/AI/PetEventAI.cpp
index f45dd8f90..36ed21c3e 100644
--- a/src/game/AI/PetEventAI.cpp
+++ b/src/game/AI/PetEventAI.cpp
@@ -33,9 +33,6 @@ int PetEventAI::Permissible(Creature const* creature)
void PetEventAI::MoveInLineOfSight(Unit* pWho)
{
- if (!pWho)
- return;
-
if (m_creature->GetVictim())
return;
@@ -43,9 +40,6 @@ void PetEventAI::MoveInLineOfSight(Unit* pWho)
if (!m_bEmptyList)
UpdateEventsOn_MoveInLineOfSight(pWho);
- if (!m_creature->HasReactState(REACT_AGGRESSIVE))
- return;
-
if (m_creature->GetCharmInfo() && m_creature->GetCharmInfo()->IsReturning())
return;
@@ -59,7 +53,7 @@ void PetEventAI::MoveInLineOfSight(Unit* pWho)
return;
#endif
- if (m_creature->CanInitiateAttack() && pWho->IsTargetable(true, m_creature->IsCharmerOrOwnerPlayerOrPlayerItself()))
+ if (m_creature->CanInitiateAttack() && pWho->IsTargetableBy(m_creature))
{
float const attackRadius = m_creature->GetAttackDistance(pWho);
if (m_creature->IsWithinDistInMap(pWho, attackRadius, true, false) && m_creature->IsHostileTo(pWho) &&
diff --git a/src/game/AI/ReactorAI.cpp b/src/game/AI/ReactorAI.cpp
deleted file mode 100644
index 0642e99a7..000000000
--- a/src/game/AI/ReactorAI.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2005-2011 MaNGOS
- * Copyright (C) 2009-2011 MaNGOSZero
- * Copyright (C) 2011-2016 Nostalrius
- * Copyright (C) 2016-2017 Elysium Project
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ReactorAI.h"
-#include "Creature.h"
-#include "Player.h"
-#include "GuardMgr.h"
-
-ReactorAI::ReactorAI(Creature* c) : CreatureAI(c), m_bCanSummonGuards(c->CanSummonGuards())
-{}
-
-int ReactorAI::Permissible(Creature const* creature)
-{
- if (creature->HasExtraFlag(CREATURE_FLAG_EXTRA_NO_AGGRO) || creature->IsNeutralToAll())
- return PERMIT_BASE_REACTIVE;
-
- return PERMIT_BASE_NO;
-}
-
-void ReactorAI::JustRespawned()
-{
- m_bCanSummonGuards = m_creature->CanSummonGuards();
-}
-
-void ReactorAI::MoveInLineOfSight(Unit* pWho)
-{
- if (!CanSummonGuards() || m_creature->IsInCombat())
- return;
-
- if (!pWho->IsPlayer())
- return;
-
- if (!m_creature->IsWithinDistInMap(pWho, m_creature->GetDetectionRange()))
- return;
-
- if (m_creature->IsHostileTo(pWho) && pWho->IsTargetable(true, false) && m_creature->IsWithinLOSInMap(pWho))
- m_bCanSummonGuards = !sGuardMgr.SummonGuard(m_creature, static_cast(pWho));
-}
-
-void ReactorAI::AttackStart(Unit* p)
-{
- if (!p)
- return;
-
- if (m_creature->Attack(p, true))
- {
- DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Tag unit GUID: %u (TypeId: %u) as a victim", p->GetGUIDLow(), p->GetTypeId());
-
- m_creature->AddThreat(p);
-
- m_creature->SetInCombatWith(p);
- p->SetInCombatWith(m_creature);
-
- if (m_bCombatMovement)
- m_creature->GetMotionMaster()->MoveChase(p);
- }
-}
-
-void ReactorAI::UpdateAI(uint32 const uiDiff)
-{
- if (!m_creature->SelectHostileTarget() || !m_creature->GetVictim())
- return;
-
- if (!m_CreatureSpells.empty())
- UpdateSpellsList(uiDiff);
-
- DoMeleeAttackIfReady();
-}
diff --git a/src/game/AI/ScriptedAI.cpp b/src/game/AI/ScriptedAI.cpp
index 28ef6b7aa..bb01828d0 100644
--- a/src/game/AI/ScriptedAI.cpp
+++ b/src/game/AI/ScriptedAI.cpp
@@ -10,7 +10,7 @@
#include "ScriptedAI.h"
#include "GridSearchers.h"
-ScriptedAI::ScriptedAI(Creature* pCreature) : CreatureAI(pCreature),
+ScriptedAI::ScriptedAI(Creature* pCreature) : BasicAI(pCreature),
me(pCreature),
m_uiEvadeCheckCooldown(2500),
m_uiHomeArea(m_creature->GetAreaId())
@@ -24,44 +24,6 @@ ScriptedAI::ScriptedAI(Creature* pCreature) : CreatureAI(pCreature),
}
}
-void ScriptedAI::MoveInLineOfSight(Unit* pWho)
-{
- if (!m_creature->IsWithinDistInMap(pWho, m_creature->GetAttackDistance(pWho), true, false))
- return;
-
- if (m_creature->CanInitiateAttack() && pWho->IsTargetable(true, m_creature->IsCharmerOrOwnerPlayerOrPlayerItself()) && m_creature->IsHostileTo(pWho))
- {
- if (pWho->IsInAccessablePlaceFor(m_creature) && m_creature->IsWithinLOSInMap(pWho))
- {
- if (!m_creature->GetVictim())
- AttackStart(pWho);
- else if (m_creature->GetMap()->IsDungeon())
- {
- pWho->SetInCombatWith(m_creature);
- m_creature->AddThreat(pWho);
- }
- }
- }
-}
-
-void ScriptedAI::AttackStart(Unit* pWho)
-{
- if (!pWho)
- return;
-
- if (m_creature->Attack(pWho, true))
- {
- m_creature->AddThreat(pWho);
- m_creature->SetInCombatWith(pWho);
- pWho->SetInCombatWith(m_creature);
-
- if (m_bCombatMovement)
- m_creature->GetMotionMaster()->MoveChase(pWho);
- }
- else
- DEBUG_UNIT(m_creature, DEBUG_AI, "AttackStart %s impossible.", pWho->GetName());
-}
-
void ScriptedAI::EnterCombat(Unit* pEnemy)
{
if (!pEnemy)
@@ -74,17 +36,6 @@ void ScriptedAI::Aggro(Unit* pEnemy)
{
}
-void ScriptedAI::UpdateAI(uint32 const uiDiff)
-{
- //Check if we have a current target
- m_creature->SelectHostileTarget();
-
- if (!m_CreatureSpells.empty() && m_creature->IsInCombat())
- UpdateSpellsList(uiDiff);
-
- DoMeleeAttackIfReady();
-}
-
void ScriptedAI::EnterEvadeMode()
{
m_creature->ClearComboPointHolders();
diff --git a/src/game/AI/ScriptedAI.h b/src/game/AI/ScriptedAI.h
index f46abbbb6..2555c5b9f 100644
--- a/src/game/AI/ScriptedAI.h
+++ b/src/game/AI/ScriptedAI.h
@@ -5,7 +5,7 @@
#ifndef SC_CREATURE_H
#define SC_CREATURE_H
-#include "CreatureAI.h"
+#include "BasicAI.h"
#define CAST_AI(a,b) (dynamic_cast(b))
@@ -15,7 +15,7 @@ enum SCEquip
EQUIP_UNEQUIP = 0
};
-struct ScriptedAI : CreatureAI
+struct ScriptedAI : BasicAI
{
explicit ScriptedAI(Creature* pCreature);
~ScriptedAI() override {}
@@ -24,12 +24,6 @@ struct ScriptedAI : CreatureAI
//CreatureAI Functions
//*************
- // Called when an unit moves within visibility distance
- void MoveInLineOfSight(Unit*) override;
-
- // Called at each attack of m_creature by any victim
- void AttackStart(Unit*) override;
-
// Called for reaction at enter to combat if not in combat yet (enemy can be nullptr)
void EnterCombat(Unit*) override;
@@ -39,9 +33,6 @@ struct ScriptedAI : CreatureAI
// Called when the creature leaves combat
void OnCombatStop() override {}
- // Called at World update tick
- void UpdateAI(uint32 const) override;
-
// Called when creature is spawned or respawned (for reseting variables)
void JustRespawned() override;
diff --git a/src/game/AI/ScriptedEscortAI.cpp b/src/game/AI/ScriptedEscortAI.cpp
index bcd094aa9..389df62b9 100644
--- a/src/game/AI/ScriptedEscortAI.cpp
+++ b/src/game/AI/ScriptedEscortAI.cpp
@@ -55,25 +55,6 @@ void npc_escortAI::setCurrentWP (uint32 idx)
m_currentWaypointIdx = idx;
}
-void npc_escortAI::AttackStart(Unit* pWho)
-{
- if (!pWho)
- return;
-
- if (m_creature->Attack(pWho, true))
- {
- //if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == POINT_MOTION_TYPE)
- // m_creature->GetMotionMaster()->MovementExpired();
-
- m_creature->AddThreat(pWho);
- m_creature->SetInCombatWith(pWho);
- pWho->SetInCombatWith(m_creature);
-
- if (IsCombatMovementEnabled())
- m_creature->GetMotionMaster()->MoveChase(pWho);
- }
-}
-
void npc_escortAI::EnterCombat(Unit* pEnemy)
{
if (!pEnemy)
@@ -142,34 +123,10 @@ bool npc_escortAI::AssistPlayerInCombat(Unit* pWho)
void npc_escortAI::MoveInLineOfSight(Unit* pWho)
{
- if (pWho->IsTargetable(true, false) && pWho->IsInAccessablePlaceFor(m_creature))
- {
- if (HasEscortState(STATE_ESCORT_ESCORTING) && AssistPlayerInCombat(pWho))
- return;
+ if (HasEscortState(STATE_ESCORT_ESCORTING) && AssistPlayerInCombat(pWho))
+ return;
- if (!m_creature->CanInitiateAttack())
- return;
- // if (!m_creature->canFly() && m_creature->GetDistanceZ(pWho) > CREATURE_Z_ATTACK_RANGE)
- // return;
-
- if (m_creature->IsHostileTo(pWho))
- {
- float fAttackRadius = m_creature->GetAttackDistance(pWho);
- if (m_creature->IsWithinDistInMap(pWho, fAttackRadius, true, false) && m_creature->IsWithinLOSInMap(pWho))
- {
- if (!m_creature->GetVictim())
- {
- //pWho->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
- AttackStart(pWho);
- }
- else
- {
- pWho->SetInCombatWith(m_creature);
- m_creature->AddThreat(pWho);
- }
- }
- }
- }
+ BasicAI::MoveInLineOfSight(pWho);
}
void npc_escortAI::JustDied(Unit* /*pKiller*/)
diff --git a/src/game/AI/ScriptedEscortAI.h b/src/game/AI/ScriptedEscortAI.h
index 34a47f5eb..4ac0bd7ae 100644
--- a/src/game/AI/ScriptedEscortAI.h
+++ b/src/game/AI/ScriptedEscortAI.h
@@ -49,7 +49,6 @@ struct npc_escortAI : ScriptedAI
void ResetCreature() override {}
// CreatureAI functions
- void AttackStart(Unit*) override;
void EnterCombat(Unit*) override;
diff --git a/src/game/AI/ScriptedFollowerAI.cpp b/src/game/AI/ScriptedFollowerAI.cpp
index a4ed988eb..e57f21cdb 100644
--- a/src/game/AI/ScriptedFollowerAI.cpp
+++ b/src/game/AI/ScriptedFollowerAI.cpp
@@ -29,22 +29,6 @@ FollowerAI::FollowerAI(Creature* pCreature) : ScriptedAI(pCreature),
m_uiFollowDistance(0.0f)
{}
-void FollowerAI::AttackStart(Unit* pWho)
-{
- if (!pWho)
- return;
-
- if (m_creature->Attack(pWho, true))
- {
- m_creature->AddThreat(pWho);
- m_creature->SetInCombatWith(pWho);
- pWho->SetInCombatWith(m_creature);
-
- if (IsCombatMovementEnabled())
- m_creature->GetMotionMaster()->MoveChase(pWho);
- }
-}
-
//This part provides assistance to a player that are attacked by pWho, even if out of normal aggro range
//It will cause m_creature to attack pWho that are attacking _any_ player (which has been confirmed may happen also on offi)
//The flag (type_flag) is unconfirmed, but used here for further research and is a good candidate.
@@ -54,7 +38,7 @@ bool FollowerAI::AssistPlayerInCombat(Unit* pWho)
return false;
//experimental (unknown) flag not present
- if (m_creature->CanAssistPlayers())
+ if (!m_creature->CanAssistPlayers())
return false;
if (m_creature->HasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_FEIGN_DEATH))
@@ -90,7 +74,7 @@ bool FollowerAI::AssistPlayerInCombat(Unit* pWho)
void FollowerAI::MoveInLineOfSight(Unit* pWho)
{
- if (pWho->IsTargetable(true, m_creature->IsCharmerOrOwnerPlayerOrPlayerItself()) && pWho->IsInAccessablePlaceFor(m_creature))
+ if (pWho->IsTargetableBy(m_creature) && pWho->IsInAccessablePlaceFor(m_creature))
{
// AssistPlayerInCombat can start, so return if true
if (HasFollowState(STATE_FOLLOW_INPROGRESS) && AssistPlayerInCombat(pWho))
@@ -107,16 +91,7 @@ void FollowerAI::MoveInLineOfSight(Unit* pWho)
float fAttackRadius = m_creature->GetAttackDistance(pWho);
if (m_creature->IsWithinDistInMap(pWho, fAttackRadius, true, false) && m_creature->IsWithinLOSInMap(pWho))
{
- if (!m_creature->GetVictim())
- {
- pWho->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
- AttackStart(pWho);
- }
- else if (m_creature->GetMap()->IsDungeon())
- {
- pWho->SetInCombatWith(m_creature);
- m_creature->AddThreat(pWho);
- }
+ m_creature->EnterCombatWithTarget(pWho);
}
}
}
diff --git a/src/game/AI/ScriptedFollowerAI.h b/src/game/AI/ScriptedFollowerAI.h
index e2f813898..5bfa75a70 100644
--- a/src/game/AI/ScriptedFollowerAI.h
+++ b/src/game/AI/ScriptedFollowerAI.h
@@ -31,8 +31,6 @@ class FollowerAI : public ScriptedAI
void MovementInform(uint32 uiMotionType, uint32 uiPointId) override;
- void AttackStart(Unit*) override;
-
void MoveInLineOfSight(Unit*) override;
void EnterEvadeMode() override;
diff --git a/src/game/AI/ScriptedPetAI.cpp b/src/game/AI/ScriptedPetAI.cpp
index cb257a98f..f6c96447c 100644
--- a/src/game/AI/ScriptedPetAI.cpp
+++ b/src/game/AI/ScriptedPetAI.cpp
@@ -98,7 +98,7 @@ void ScriptedPetAI::UpdateAI(uint32 const uiDiff)
if (Unit* const pTarget = m_creature->GetVictim()) // in combat
{
- if (!pTarget->IsTargetable(true, m_creature->IsCharmerOrOwnerPlayerOrPlayerItself()))
+ if (!pTarget->IsTargetableBy(m_creature))
{
// target no longer valid for pet, so either attack stops or new target are selected
// doesn't normally reach this, because of how petAi is designed in Mangos. CombatStop
@@ -137,7 +137,7 @@ void ScriptedPetAI::UpdateAI(uint32 const uiDiff)
// Main target is CC-ed, so pick another attacker.
for (const auto pAttacker : pOwner->GetAttackers())
{
- if (pAttacker->IsInMap(m_creature) && pAttacker->IsTargetable(true, m_creature->IsCharmerOrOwnerPlayerOrPlayerItself()) && !pAttacker->HasAuraPetShouldAvoidBreaking())
+ if (pAttacker->IsInMap(m_creature) && pAttacker->IsTargetableBy(m_creature) && !pAttacker->HasAuraPetShouldAvoidBreaking())
{
AttackStart(pAttacker);
return;
diff --git a/src/game/AI/TotemAI.cpp b/src/game/AI/TotemAI.cpp
index 7caf89e0d..c6df9d426 100644
--- a/src/game/AI/TotemAI.cpp
+++ b/src/game/AI/TotemAI.cpp
@@ -32,7 +32,7 @@
int TotemAI::Permissible(Creature const* creature)
{
if (creature->IsTotem())
- return PERMIT_BASE_PROACTIVE;
+ return PERMIT_BASE_SPECIAL;
return PERMIT_BASE_NO;
}
diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt
index 2b1d07a55..03f695dcf 100644
--- a/src/game/CMakeLists.txt
+++ b/src/game/CMakeLists.txt
@@ -47,7 +47,7 @@ set (game_SRCS
Weather.cpp
World.cpp
WorldSession.cpp
- AI/AggressorAI.cpp
+ AI/BasicAI.cpp
AI/CreatureAI.cpp
AI/CreatureAIRegistry.cpp
AI/CreatureAISelector.cpp
@@ -61,7 +61,6 @@ set (game_SRCS
AI/PetAI.cpp
AI/PetEventAI.cpp
AI/PlayerAI.cpp
- AI/ReactorAI.cpp
AI/ScriptedAI.cpp
AI/ScriptedEscortAI.cpp
AI/ScriptedFollowerAI.cpp
@@ -250,7 +249,7 @@ set (game_SRCS
Weather.h
World.h
WorldSession.h
- AI/AggressorAI.h
+ AI/BasicAI.h
AI/CreatureAI.h
AI/CreatureAIImpl.h
AI/CreatureAIRegistry.h
@@ -265,7 +264,6 @@ set (game_SRCS
AI/PetAI.h
AI/PetEventAI.h
AI/PlayerAI.h
- AI/ReactorAI.h
AI/ScriptedAI.h
AI/ScriptedEscortAI.h
AI/ScriptedFollowerAI.h
diff --git a/src/game/Chat/Chat.cpp b/src/game/Chat/Chat.cpp
index e93380991..041211bac 100644
--- a/src/game/Chat/Chat.cpp
+++ b/src/game/Chat/Chat.cpp
@@ -651,6 +651,7 @@ ChatCommand * ChatHandler::getCommandTable()
{ "movetype", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcSetMoveTypeCommand, "", nullptr },
{ "wanderdistance", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcSetWanderDistCommand, "", nullptr },
{ "respawntime", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcSetSpawnTimeCommand, "", nullptr },
+ { "reactstate", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcSetReactStateCommand, "", nullptr },
{ nullptr, 0, false, nullptr, "", nullptr }
};
diff --git a/src/game/Chat/Chat.h b/src/game/Chat/Chat.h
index 9cf404d64..7c59451e3 100644
--- a/src/game/Chat/Chat.h
+++ b/src/game/Chat/Chat.h
@@ -708,6 +708,7 @@ class ChatHandler
bool HandleNpcSetWanderDistCommand(char* args);
bool HandleNpcSetSpawnTimeCommand(char* args);
bool HandleNpcSpawnSpawnTimeCommand(char* args);
+ bool HandleNpcSetReactStateCommand(char* args);
bool HandleNpcTameCommand(char* args);
bool HandleNpcTextEmoteCommand(char* args);
bool HandleNpcUnFollowCommand(char* args);
diff --git a/src/game/Commands/CreatureCommands.cpp b/src/game/Commands/CreatureCommands.cpp
index c11bf1f69..ce4f2a727 100644
--- a/src/game/Commands/CreatureCommands.cpp
+++ b/src/game/Commands/CreatureCommands.cpp
@@ -162,6 +162,7 @@ bool ChatHandler::HandleNpcAIInfoCommand(char* /*args*/)
strAI.empty() ? " - " : strAI.c_str(),
cstrAIClass ? cstrAIClass : " - ",
strScript.empty() ? " - " : strScript.c_str());
+ PSendSysMessage("React State: %s", ReactStateToString(pTarget->GetReactState()));
PSendSysMessage(LANG_NPC_AI_MOVE, GetOnOffStr(pTarget->AI()->IsCombatMovementEnabled()));
PSendSysMessage(LANG_NPC_AI_ATTACK, GetOnOffStr(pTarget->AI()->IsMeleeAttackEnabled()));
MovementGeneratorType moveType = pTarget->GetMotionMaster()->GetCurrentMovementGeneratorType();
@@ -374,7 +375,7 @@ bool ChatHandler::HandleNpcTameCommand(char* /*args*/)
if (!creatureTarget || creatureTarget->IsPet())
{
- PSendSysMessage(LANG_SELECT_CREATURE);
+ SendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
@@ -545,7 +546,7 @@ bool ChatHandler::HandleNpcSpawnSpawnTimeCommand(char* args)
Creature* pCreature = GetSelectedCreature();
if (!pCreature)
{
- PSendSysMessage(LANG_SELECT_CREATURE);
+ SendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
@@ -575,7 +576,7 @@ bool ChatHandler::HandleNpcSetSpawnTimeCommand(char* args)
Creature* pCreature = GetSelectedCreature();
if (!pCreature)
{
- PSendSysMessage(LANG_SELECT_CREATURE);
+ SendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
@@ -586,6 +587,33 @@ bool ChatHandler::HandleNpcSetSpawnTimeCommand(char* args)
return true;
}
+bool ChatHandler::HandleNpcSetReactStateCommand(char* args)
+{
+ Creature* pCreature = GetSelectedCreature();
+ if (!pCreature)
+ {
+ SendSysMessage(LANG_SELECT_CREATURE);
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ uint32 reactState;
+ if (!ExtractUInt32(&args, reactState))
+ return false;
+
+ if (reactState > REACT_AGGRESSIVE)
+ {
+ SendSysMessage("Invalid react state.");
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ pCreature->SetReactState((ReactStates)reactState);
+ PSendSysMessage("React state of %s updated to %u.", pCreature->GetName(), reactState);
+
+ return true;
+}
+
bool ChatHandler::HandleNpcEvadeCommand(char* /*args*/)
{
Creature* pTarget = GetSelectedCreature();
@@ -1186,7 +1214,7 @@ bool ChatHandler::HandleNpcFollowCommand(char* /*args*/)
if (!creature)
{
- PSendSysMessage(LANG_SELECT_CREATURE);
+ SendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
@@ -1205,7 +1233,7 @@ bool ChatHandler::HandleNpcUnFollowCommand(char* /*args*/)
if (!pCreature)
{
- PSendSysMessage(LANG_SELECT_CREATURE);
+ SendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
@@ -1242,7 +1270,7 @@ bool ChatHandler::HandleNpcAllowMovementCommand(char* args)
if (!pCreature)
{
- PSendSysMessage(LANG_SELECT_CREATURE);
+ SendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
@@ -1267,7 +1295,7 @@ bool ChatHandler::HandleNpcAllowAttackCommand(char* args)
if (!pCreature)
{
- PSendSysMessage(LANG_SELECT_CREATURE);
+ SendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
diff --git a/src/game/Group/CreatureLinkingMgr.cpp b/src/game/Group/CreatureLinkingMgr.cpp
index aa281710c..7ab0be735 100644
--- a/src/game/Group/CreatureLinkingMgr.cpp
+++ b/src/game/Group/CreatureLinkingMgr.cpp
@@ -464,26 +464,21 @@ void CreatureLinkingHolder::DoCreatureLinkingEvent(CreatureLinkingEvent eventTyp
{
switch (eventType)
{
- case LINKING_EVENT_AGGRO:
- if (pMaster->IsControlledByPlayer())
- return;
-
- if (pMaster->IsInCombat())
- pMaster->SetInCombatWith(pEnemy);
- else
- pMaster->AI()->AttackStart(pEnemy);
- break;
- case LINKING_EVENT_EVADE:
- if (!pMaster->IsAlive())
- pMaster->Respawn();
- break;
- case LINKING_EVENT_RESPAWN:
- if (pMaster->IsAlive())
- SetFollowing(pSource, pMaster);
- break;
- case LINKING_EVENT_DIE: // Nothing linked for this case
- case LINKING_EVENT_DESPAWN: // Nothing linked for this case
- break;
+ case LINKING_EVENT_AGGRO:
+ if (pMaster->IsControlledByPlayer())
+ return;
+ pMaster->EnterCombatWithTarget(pEnemy);
+ case LINKING_EVENT_EVADE:
+ if (!pMaster->IsAlive())
+ pMaster->Respawn();
+ break;
+ case LINKING_EVENT_RESPAWN:
+ if (pMaster->IsAlive())
+ SetFollowing(pSource, pMaster);
+ break;
+ case LINKING_EVENT_DIE: // Nothing linked for this case
+ case LINKING_EVENT_DESPAWN: // Nothing linked for this case
+ break;
}
}
}
diff --git a/src/game/GuardMgr.cpp b/src/game/GuardMgr.cpp
index 281ba5ea9..dbe3cf80f 100644
--- a/src/game/GuardMgr.cpp
+++ b/src/game/GuardMgr.cpp
@@ -401,7 +401,24 @@ uint32 GuardMgr::GetTextId(uint32 factionTemplateId, uint32 areaId, uint32 displ
return TEXT_NONE;
}
-bool GuardMgr::SummonGuard(Creature* pCivilian, Player* pEnemy)
+Team GuardMgr::GetTeam(Creature* pCivilian, Unit* pEnemy)
+{
+ if (Player* pPlayer = pEnemy->GetCharmerOrOwnerPlayerOrPlayerItself())
+ {
+ // Civilian must be opposite team of player.
+ switch (pPlayer->GetTeam())
+ {
+ case HORDE:
+ return ALLIANCE;
+ case ALLIANCE:
+ return HORDE;
+ }
+ }
+
+ return pCivilian->GetTeam();
+}
+
+bool GuardMgr::SummonGuard(Creature* pCivilian, Unit* pEnemy)
{
if (!pCivilian || !pEnemy)
return false;
@@ -427,7 +444,7 @@ bool GuardMgr::SummonGuard(Creature* pCivilian, Player* pEnemy)
if (uint32 textId = GetTextId(pCivilian->GetFactionTemplateId(), areaId, pCivilian->GetDisplayId()))
DoScriptText(textId, pCivilian, pEnemy, CHAT_TYPE_SAY);
- if (uint32 creatureId = pEnemy->GetTeamId() == TEAM_ALLIANCE ? guardInfo.creatureIdHorde : guardInfo.creatureIdAlliance)
+ if (uint32 creatureId = guardInfo.GetCreatureIdForTeam(GetTeam(pCivilian, pEnemy)))
{
float x, y, z;
pCivilian->GetNearPoint(pCivilian, x, y, z, 0, 5, 0);
diff --git a/src/game/GuardMgr.h b/src/game/GuardMgr.h
index d683c984c..aa5c46a66 100644
--- a/src/game/GuardMgr.h
+++ b/src/game/GuardMgr.h
@@ -25,8 +25,8 @@
#define GUARD_POST_MAX_CHARGES 10
+class Unit;
class Creature;
-class Player;
struct AreaGuardInfo
{
@@ -35,6 +35,18 @@ struct AreaGuardInfo
uint32 const creatureIdHorde;
uint32 cooldown;
uint32 charges;
+
+ uint32 GetCreatureIdForTeam(Team team) const
+ {
+ switch (team)
+ {
+ case HORDE:
+ return creatureIdHorde;
+ case ALLIANCE:
+ return creatureIdAlliance;
+ }
+ return 0;
+ }
};
class GuardMgr
@@ -44,7 +56,8 @@ class GuardMgr
~GuardMgr() {}
void Update(uint32 diff);
uint32 GetTextId(uint32 factionTemplateId, uint32 areaId, uint32 displayId) const;
- bool SummonGuard(Creature* pCivilian, Player* pEnemy);
+ Team GetTeam(Creature* pCivilian, Unit* pEnemy);
+ bool SummonGuard(Creature* pCivilian, Unit* pEnemy);
private:
std::unordered_map m_mAreaGuardInfo;
uint32 m_uiRechargeTimer;
diff --git a/src/game/HardcodedEvents.cpp b/src/game/HardcodedEvents.cpp
index c3c406073..fbebf86dd 100644
--- a/src/game/HardcodedEvents.cpp
+++ b/src/game/HardcodedEvents.cpp
@@ -986,7 +986,7 @@ void ScourgeInvasionEvent::HandleActiveZone(uint32 attackTimeVar, uint32 zoneId,
sLog.outBasic("[Scourge Invasion Event] %d victories", sObjectMgr.GetSavedVariable(VARIABLE_SI_ATTACK_COUNT));
if (pMouth)
- pMouth->AI()->DoAction(EVENT_MOUTH_OF_KELTHUZAD_ZONE_STOP);
+ pMouth->AI()->OnScriptEventHappened(EVENT_MOUTH_OF_KELTHUZAD_ZONE_STOP);
else
sLog.outError("ScourgeInvasionEvent::HandleActiveZone ObjectGuid %d not found.", zone->mouthGuid);
}
@@ -1197,7 +1197,7 @@ bool ScourgeInvasionEvent::SummonMouth(Map* pMap, InvasionZone* zone, Position p
if (Creature* pMouth = pMap->SummonCreature(NPC_MOUTH_OF_KELTHUZAD, position.x, position.y, position.z, position.o, TEMPSUMMON_DEAD_DESPAWN, 0, true))
{
- pMouth->AI()->DoAction(EVENT_MOUTH_OF_KELTHUZAD_ZONE_START);
+ pMouth->AI()->OnScriptEventHappened(EVENT_MOUTH_OF_KELTHUZAD_ZONE_START);
zone->mouthGuid = pMouth->GetObjectGuid();
}
else
diff --git a/src/game/Maps/GridNotifiers.h b/src/game/Maps/GridNotifiers.h
index 93755690a..884c9aee0 100644
--- a/src/game/Maps/GridNotifiers.h
+++ b/src/game/Maps/GridNotifiers.h
@@ -1532,7 +1532,7 @@ namespace MaNGOS
if (!u->IsWithinDistInMap(m_me, std::min(m_me->GetAttackDistance(u), m_dist), true, false))
return false;
- if (!u->IsTargetable(true, m_me->IsCharmerOrOwnerPlayerOrPlayerItself()))
+ if (!u->IsTargetableBy(m_me))
return false;
if (m_ignoreCivilians && u->IsCreature() && static_cast(u)->IsCivilian())
diff --git a/src/game/Maps/ScriptCommands.cpp b/src/game/Maps/ScriptCommands.cpp
index 91111c000..4f5410485 100644
--- a/src/game/Maps/ScriptCommands.cpp
+++ b/src/game/Maps/ScriptCommands.cpp
@@ -934,7 +934,7 @@ bool Map::ScriptCommand_AttackStart(ScriptInfo const& script, WorldObject* sourc
if (!pAttacker->IsAlive())
return ShouldAbortScript(script);
- if (!pAttacker->IsValidAttackTarget(pTarget) || !pAttacker->IsInMap(pTarget))
+ if (!pAttacker->IsValidAttackTarget(pTarget))
{
sLog.outError("SCRIPT_COMMAND_ATTACK_START (script id %u) for an invalid attack target, skipping.", script.id);
return ShouldAbortScript(script);
@@ -2067,27 +2067,13 @@ bool Map::ScriptCommand_AssistUnit(ScriptInfo const& script, WorldObject* source
return ShouldAbortScript(script);
}
- if (!pSource->IsInMap(pTarget))
- return ShouldAbortScript(script);
-
Unit* pAttacker = pTarget->GetAttackerForHelper();
if (!pAttacker)
return false;
- if (Unit* pVictim = pSource->GetVictim())
- {
- if (pVictim == pAttacker)
- return false;
-
- if (pSource->IsValidAttackTarget(pAttacker) && pSource->IsWithinDistInMap(pAttacker, 40.0f))
- pSource->AddThreat(pAttacker);
- }
- else
- {
- if (pSource->AI() && pSource->IsValidAttackTarget(pAttacker) && pSource->IsWithinDistInMap(pAttacker, 40.0f))
- pSource->AI()->AttackStart(pAttacker);
- }
+ if (pSource->IsValidAttackTarget(pAttacker) && pSource->IsWithinDistInMap(pAttacker, 40.0f))
+ pSource->EnterCombatWithTarget(pAttacker);
return false;
}
@@ -2150,7 +2136,7 @@ bool Map::ScriptCommand_AddThreat(ScriptInfo const& script, WorldObject* source,
return ShouldAbortScript(script);
}
- if (pSource->IsValidAttackTarget(pTarget) && pSource->IsInMap(pTarget))
+ if (pSource->IsValidAttackTarget(pTarget))
pSource->AddThreat(pTarget);
return false;
diff --git a/src/game/Objects/Creature.cpp b/src/game/Objects/Creature.cpp
index 39cd54305..75deecc89 100644
--- a/src/game/Objects/Creature.cpp
+++ b/src/game/Objects/Creature.cpp
@@ -201,7 +201,7 @@ Creature::Creature(CreatureSubtype subtype) :
m_defaultMovementType(IDLE_MOTION_TYPE), m_equipmentId(0), m_creatureStateFlags(CSTATE_REGEN_HEALTH | CSTATE_REGEN_MANA),
m_AI_locked(false), m_temporaryFactionFlags(TEMPFACTION_NONE),
m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), m_originalEntry(0), m_creatureGroup(nullptr),
- m_combatStartX(0.0f), m_combatStartY(0.0f), m_combatStartZ(0.0f), m_reactState(REACT_PASSIVE),
+ m_combatStartX(0.0f), m_combatStartY(0.0f), m_combatStartZ(0.0f), m_reactState(REACT_DEFENSIVE),
m_lastLeashExtensionTime(nullptr), m_playerDamageTaken(0), m_nonPlayerDamageTaken(0), m_creatureInfo(nullptr),
m_detectionDistance(20.0f), m_callForHelpDist(5.0f), m_leashDistance(0.0f), m_mountId(0),
m_reputationId(-1), m_gossipMenuId(0), m_castingTargetGuid(0)
@@ -515,6 +515,8 @@ bool Creature::UpdateEntry(uint32 Entry, CreatureData const* data /*=nullptr*/,
else
SetPvP(false);
+ InitializeReactState();
+
for (int i = 0; i < CREATURE_MAX_SPELLS; ++i)
m_spells[i] = GetCreatureInfo()->spells[i];
@@ -548,6 +550,16 @@ bool Creature::UpdateEntry(uint32 Entry, CreatureData const* data /*=nullptr*/,
return true;
}
+void Creature::InitializeReactState()
+{
+ if (IsTotem() || IsTrigger() || !CanHaveTarget() || GetCreatureType() == CREATURE_TYPE_CRITTER)
+ SetReactState(REACT_PASSIVE);
+ else if (HasExtraFlag(CREATURE_FLAG_EXTRA_NO_AGGRO))
+ SetReactState(REACT_DEFENSIVE);
+ else
+ SetReactState(REACT_AGGRESSIVE);
+}
+
float Creature::GetScaleForDisplayId(uint32 displayId)
{
if (CreatureDisplayInfoEntry const* displayEntry = sCreatureDisplayInfoStore.LookupEntry(displayId))
@@ -1122,7 +1134,6 @@ bool Creature::Create(uint32 guidlow, CreatureCreatePos& cPos, CreatureInfo cons
}
LoadCreatureAddon();
- InitializeReactState();
SetWalk(!HasExtraFlag(CREATURE_FLAG_EXTRA_ALWAYS_RUN), true);
return true;
}
@@ -2196,16 +2207,10 @@ void Creature::CallForHelp(float fRadius)
bool Creature::CanAssistTo(Unit const* u, Unit const* enemy, bool checkfaction /*= true*/) const
{
- if (!IsAlive())
- return false;
-
if (HasExtraFlag(CREATURE_FLAG_EXTRA_NO_ASSIST))
return false;
- if (HasExtraFlag(CREATURE_FLAG_EXTRA_NO_AGGRO))
- return false;
-
- if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SPAWNING | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_IMMUNE_TO_NPC))
+ if (!CanInitiateAttack())
return false;
// skip fighting creature
@@ -2235,6 +2240,9 @@ bool Creature::CanAssistTo(Unit const* u, Unit const* enemy, bool checkfaction /
return false;
}
+ if (!enemy->IsTargetableBy(this))
+ return false;
+
// skip non hostile to caster enemy creatures
if (!IsHostileTo(enemy))
return false;
@@ -2246,15 +2254,21 @@ bool Creature::CanAssistTo(Unit const* u, Unit const* enemy, bool checkfaction /
return true;
}
-bool Creature::CanInitiateAttack()
+bool Creature::CanInitiateAttack() const
{
+ if (!IsAlive())
+ return false;
+
if (HasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_PENDING_STUNNED | UNIT_STAT_FEIGN_DEATH))
return false;
if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SPAWNING | UNIT_FLAG_NOT_SELECTABLE))
return false;
- if (IsPassiveToHostile())
+ if (!HasReactState(REACT_AGGRESSIVE))
+ return false;
+
+ if (IsNeutralToAll())
return false;
if (IsTempPacified())
@@ -2544,18 +2558,8 @@ void Creature::SetInCombatWithZone(bool initialPulse)
if (!initialPulse && pPlayer->IsInCombat())
continue;
- if (pPlayer->IsAlive() && !IsFriendlyTo(pPlayer))
- {
- if (IsInCombat())
- {
- pPlayer->SetInCombatWith(this);
- AddThreat(pPlayer);
- }
- else if (AI())
- {
- AI()->AttackStart(pPlayer);
- }
- }
+ if (IsValidAttackTarget(pPlayer))
+ EnterCombatWithTarget(pPlayer);
}
}
}
@@ -3287,8 +3291,8 @@ void Creature::OnEnterCombat(Unit* pWho, bool notInCombat)
pPlayer->SendFactionAtWar(GetReputationId(), true);
}
- if (pWho->IsPlayer() && CanSummonGuards())
- sGuardMgr.SummonGuard(this, static_cast(pWho));
+ if (CanSummonGuards())
+ sGuardMgr.SummonGuard(this, pWho);
if (IsPet())
if (Creature* pOwner = GetOwnerCreature())
@@ -3641,9 +3645,7 @@ bool Creature::_IsTargetAcceptable(Unit const* target) const
ASSERT(target);
// if the target cannot be attacked, the target is not acceptable
- if (IsFriendlyTo(target)
- || !target->IsTargetable(true, IsCharmerOrOwnerPlayerOrPlayerItself())
- || target->HasUnitState(UNIT_STAT_FEIGN_DEATH))
+ if (IsFriendlyTo(target) || !target->IsTargetableBy(this))
return false;
Unit* myVictim = GetAttackerForHelper();
@@ -3704,6 +3706,17 @@ void Creature::ResetCombatTime(bool combat)
m_combatResetCount = 0;
}
+void Creature::EnterCombatWithTarget(Unit* pVictim)
+{
+ if (!GetVictim() && AI())
+ AI()->AttackStart(pVictim);
+ else
+ {
+ AddThreat(pVictim);
+ pVictim->SetInCombatWith(this);
+ }
+}
+
bool Creature::canStartAttack(Unit const* who, bool force) const
{
if (IsCivilian())
diff --git a/src/game/Objects/Creature.h b/src/game/Objects/Creature.h
index 3d2fe86b3..8d805a2a6 100644
--- a/src/game/Objects/Creature.h
+++ b/src/game/Objects/Creature.h
@@ -160,13 +160,7 @@ class Creature : public Unit
void SetReactState(ReactStates st) { m_reactState = st; }
ReactStates GetReactState() const { return m_reactState; }
bool HasReactState(ReactStates state) const { return (m_reactState == state); }
- void InitializeReactState()
- {
- if (IsTotem() || IsTrigger() || GetCreatureType() == CREATURE_TYPE_CRITTER)
- SetReactState(REACT_PASSIVE);
- else
- SetReactState(REACT_AGGRESSIVE);
- }
+ void InitializeReactState();
bool IsTrainerOf(Player* player, bool msg) const;
bool CanInteractWithBattleMaster(Player* player, bool msg) const;
@@ -322,7 +316,7 @@ class Creature : public Unit
}
bool HasSearchedAssistance() const { return HasCreatureState(CSTATE_ALREADY_SEARCH_ASSIST); }
bool CanAssistTo(Unit const* u, Unit const* enemy, bool checkfaction = true) const;
- bool CanInitiateAttack();
+ bool CanInitiateAttack() const;
bool CanHaveTarget() const { return !HasExtraFlag(CREATURE_FLAG_EXTRA_NO_TARGET); }
uint32 GetDefaultMount() { return m_mountId; }
@@ -365,6 +359,7 @@ class Creature : public Unit
void SendZoneUnderAttackMessage(Player* attacker);
void SetInCombatWithZone(bool initialPulse = true);
+ void EnterCombatWithTarget(Unit* pTarget);
bool canStartAttack(Unit const* who, bool force) const;
bool _IsTargetAcceptable(Unit const* target) const;
bool canCreatureAttack(Unit const* pVictim, bool force) const;
diff --git a/src/game/Objects/CreatureDefines.h b/src/game/Objects/CreatureDefines.h
index c05362075..c8ace5061 100644
--- a/src/game/Objects/CreatureDefines.h
+++ b/src/game/Objects/CreatureDefines.h
@@ -109,7 +109,7 @@ enum CreatureEliteType
enum CreatureFlagsExtra
{
CREATURE_FLAG_EXTRA_INSTANCE_BIND = 0x00000001, // 1 Killing this creature will bind players to the raid
- CREATURE_FLAG_EXTRA_NO_AGGRO = 0x00000002, // 2 Creature will not attack nearby hostile targets (ignore faction/reputation hostility)
+ CREATURE_FLAG_EXTRA_NO_AGGRO = 0x00000002, // 2 Creature is defensive does not attack nearby hostile targets
CREATURE_FLAG_EXTRA_NO_PARRY = 0x00000004, // 4 Creature can't parry
CREATURE_FLAG_EXTRA_SUMMON_GUARD = 0x00000008, // 8 Creature summons a guard if an opposite faction player gets near or attacks
CREATURE_FLAG_EXTRA_NO_BLOCK = 0x00000010, // 16 Creature can't block
@@ -125,7 +125,7 @@ enum CreatureFlagsExtra
CREATURE_FLAG_EXTRA_IMMUNE_AOE = 0x00004000, // 16384 Creature is immune to AoE
CREATURE_FLAG_EXTRA_CHASE_GEN_NO_BACKING = 0x00008000, // 32768 Creature does not move back when target is within bounding radius
CREATURE_FLAG_EXTRA_NO_ASSIST = 0x00010000, // 65536 Creature does not aggro when nearby creatures aggro
- CREATURE_FLAG_EXTRA_NO_TARGET = 0x00020000, // 131072 Creature does not acquire targets
+ CREATURE_FLAG_EXTRA_NO_TARGET = 0x00020000, // 131072 Creature is passive and does not acquire targets
CREATURE_FLAG_EXTRA_ONLY_VISIBLE_TO_FRIENDLY = 0x00040000, // 262144 Creature can only be seen by friendly units
CREATURE_FLAG_EXTRA_PVP = 0x00080000, // 524288 Creature has pvp unit flag set by default
CREATURE_FLAG_EXTRA_CAN_ASSIST = 0x00100000, // 1048576 CREATURE_TYPEFLAGS_CAN_ASSIST from TBC
diff --git a/src/game/Objects/Object.cpp b/src/game/Objects/Object.cpp
index 18961de6b..757d7577b 100644
--- a/src/game/Objects/Object.cpp
+++ b/src/game/Objects/Object.cpp
@@ -3500,7 +3500,7 @@ bool WorldObject::IsValidAttackTarget(Unit const* target, bool checkAlive) const
if (FindMap() != target->FindMap())
return false;
- if (!target->IsTargetable(true, IsCharmerOrOwnerPlayerOrPlayerItself(), false, checkAlive))
+ if (!target->IsTargetableBy(this, false, checkAlive))
return false;
Unit const* pThisUnit = ToUnit();
diff --git a/src/game/Objects/Player.h b/src/game/Objects/Player.h
index 747335b7d..c71687d09 100644
--- a/src/game/Objects/Player.h
+++ b/src/game/Objects/Player.h
@@ -2324,7 +2324,7 @@ class Player final: public Unit
bool m_DbSaveDisabled; // used for faction change
public:
static Team TeamForRace(uint8 race);
- Team GetTeam() const { return m_team; }
+ Team GetTeam() const final { return m_team; }
TeamId GetTeamId() const { return m_team == ALLIANCE ? TEAM_ALLIANCE : TEAM_HORDE; }
static uint32 GetFactionForRace(uint8 race);
void SetFactionForRace(uint8 race);
diff --git a/src/game/Objects/Unit.cpp b/src/game/Objects/Unit.cpp
index 1a59c7329..1a83ec8ca 100644
--- a/src/game/Objects/Unit.cpp
+++ b/src/game/Objects/Unit.cpp
@@ -796,7 +796,7 @@ uint32 Unit::DealDamage(Unit* pVictim, uint32 damage, CleanDamage const* cleanDa
if (damagetype != DOT)
{
- if (!GetVictim())
+ if (!GetVictim() && IsPlayer())
{
// if not have main target then attack state with target (including AI call)
//start melee attacks only after melee hit
@@ -4565,9 +4565,6 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
if (IsPlayer() && IsMounted())
return false;
- if (IsCreature() && !((Creature*)this)->CanHaveTarget())
- return false;
-
// nobody can attack GM in GM-mode
if (victim->IsPlayer())
{
@@ -4942,6 +4939,24 @@ void Unit::RestoreFaction()
}
}
+Team Unit::GetTeam() const
+{
+ if (FactionTemplateEntry const* pFactionTemplate = getFactionTemplateEntry())
+ {
+ if (FactionEntry const* pFaction = sObjectMgr.GetFactionEntry(pFactionTemplate->faction))
+ {
+ switch (pFaction->team)
+ {
+ case HORDE:
+ return HORDE;
+ case ALLIANCE:
+ return ALLIANCE;
+ }
+ }
+ }
+ return TEAM_NONE;
+}
+
bool Unit::CanAttack(Unit const* target, bool force) const
{
ASSERT(target);
@@ -4966,7 +4981,7 @@ bool Unit::CanAttack(Unit const* target, bool force) const
else if (!IsHostileTo(target))
return false;
- if (!target->IsTargetable(true, IsCharmerOrOwnerPlayerOrPlayerItself()) || target->HasUnitState(UNIT_STAT_FEIGN_DEATH))
+ if (!target->IsTargetableBy(this))
return false;
// shaman totem quests: spell 8898, shaman can detect elementals but elementals cannot see shaman
@@ -5832,7 +5847,7 @@ void Unit::ClearInCombat()
static_cast(this)->pvpInfo.inPvPCombat = false;
}
-bool Unit::IsTargetable(bool forAttack, bool isAttackerPlayer, bool forAoE, bool checkAlive) const
+bool Unit::IsTargetableBy(WorldObject const* pAttacker, bool forAoE, bool checkAlive) const
{
if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE))
return false;
@@ -5846,26 +5861,45 @@ bool Unit::IsTargetable(bool forAttack, bool isAttackerPlayer, bool forAoE, bool
return false;
}
- if (forAttack)
+ if (pAttacker)
{
- if (!forAoE && !CanBeDetected())
- return false;
-
- if (!isAttackerPlayer && !forAoE && HasUnitState(UNIT_STAT_FEIGN_DEATH))
- return false;
-
- // check flags
if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SPAWNING | UNIT_FLAG_TAXI_FLIGHT | UNIT_FLAG_NOT_ATTACKABLE_1 | UNIT_FLAG_NON_ATTACKABLE_2))
return false;
- if (isAttackerPlayer && HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER))
- return false;
-
- if (!isAttackerPlayer && HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
- return false;
-
if (IsTaxiFlying())
return false;
+
+ if (!forAoE && !CanBeDetected())
+ return false;
+
+ if (pAttacker->IsCharmerOrOwnerPlayerOrPlayerItself())
+ {
+ if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER))
+ return false;
+ }
+ else // non player attacker
+ {
+ if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
+ return false;
+
+ if (!forAoE && HasUnitState(UNIT_STAT_FEIGN_DEATH))
+ return false;
+ }
+
+ // attacker flags prevent attacking victim too
+ if (pAttacker->IsUnit())
+ {
+ if (IsCharmerOrOwnerPlayerOrPlayerItself())
+ {
+ if (pAttacker->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER))
+ return false;
+ }
+ else // non player victim
+ {
+ if (pAttacker->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
+ return false;
+ }
+ }
}
return IsInWorld();
@@ -7109,6 +7143,7 @@ void Unit::TauntApply(Unit* taunter)
if (target && target == taunter)
return;
+
// Nostalrius : Correction bug sheep/fear
if (!HasAuraType(SPELL_AURA_MOD_FEAR) && !HasAuraType(SPELL_AURA_MOD_CONFUSE))
{
@@ -7244,7 +7279,7 @@ bool Unit::SelectHostileTarget()
{
for (const auto& itr : m_attackers)
{
- if (itr->IsInMap(this) && itr->IsTargetable(true, IsCharmerOrOwnerPlayerOrPlayerItself()))
+ if (itr->IsInMap(this) && itr->IsTargetableBy(this))
return false;
}
}
diff --git a/src/game/Objects/Unit.h b/src/game/Objects/Unit.h
index 14461e737..c7479f1f5 100644
--- a/src/game/Objects/Unit.h
+++ b/src/game/Objects/Unit.h
@@ -1020,7 +1020,7 @@ class Unit : public SpellCaster
void AddExtraAttackOnUpdate() { m_doExtraAttacks = true; };
bool CanAttack(Unit const* target, bool force = false) const;
- bool IsTargetable(bool forAttack, bool isAttackerPlayer, bool forAoE = false, bool checkAlive = true) const;
+ bool IsTargetableBy(WorldObject const* pAttacker, bool forAoE = false, bool checkAlive = true) const;
bool CanReachWithMeleeAutoAttack(Unit const* pVictim, float flat_mod = 0.0f) const;
bool CanReachWithMeleeAutoAttackAtPosition(Unit const* pVictim, float x, float y, float z, float flat_mod = 0.0f) const;
@@ -1169,6 +1169,7 @@ class Unit : public SpellCaster
uint32 GetFactionTemplateId() const final { return GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE); }
void SetFactionTemplateId(uint32 faction) { SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, faction); }
void RestoreFaction();
+ virtual Team GetTeam() const;
bool IsHostileTo(WorldObject const* target) const override;
bool IsHostileToPlayers() const;
@@ -1182,7 +1183,6 @@ class Unit : public SpellCaster
void SetPvP(bool state);
bool IsPvPContested() const;
void SetPvPContested(bool state);
- bool IsPassiveToHostile() const { return HasFlag(UNIT_FIELD_FLAGS, (UNIT_FLAG_IMMUNE_TO_PLAYER | UNIT_FLAG_IMMUNE_TO_NPC)); }
void SetTargetGuid(ObjectGuid targetGuid) { SetGuidValue(UNIT_FIELD_TARGET, targetGuid); }
ObjectGuid const& GetTargetGuid() const { return GetGuidValue(UNIT_FIELD_TARGET); }
diff --git a/src/game/Objects/UnitDefines.h b/src/game/Objects/UnitDefines.h
index ddfbaf376..b1a2de68e 100644
--- a/src/game/Objects/UnitDefines.h
+++ b/src/game/Objects/UnitDefines.h
@@ -474,6 +474,20 @@ enum ReactStates
REACT_AGGRESSIVE = 2
};
+inline char const* ReactStateToString(uint32 reactState)
+{
+ switch (reactState)
+ {
+ case REACT_PASSIVE:
+ return "Passive";
+ case REACT_DEFENSIVE:
+ return "Defensive";
+ case REACT_AGGRESSIVE:
+ return "Aggressive";
+ }
+ return "UNKNOWN";
+}
+
enum CommandStates
{
COMMAND_STAY = 0,
diff --git a/src/game/Spells/Spell.cpp b/src/game/Spells/Spell.cpp
index 3c4b94ef7..5245147c1 100644
--- a/src/game/Spells/Spell.cpp
+++ b/src/game/Spells/Spell.cpp
@@ -2559,7 +2559,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
// remove not targetable units if spell has no script targets
for (UnitList::iterator itr = targetUnitMap.begin(); itr != targetUnitMap.end();)
{
- if (!(*itr)->IsTargetable(true, m_caster->IsCharmerOrOwnerPlayerOrPlayerItself(), true, false) || !m_spellInfo->CanTargetAliveState((*itr)->IsAlive()))
+ if (!(*itr)->IsTargetableBy(m_caster, true, false) || !m_spellInfo->CanTargetAliveState((*itr)->IsAlive()))
targetUnitMap.erase(itr++);
else
++itr;
@@ -7093,7 +7093,7 @@ SpellCastResult Spell::CheckPetCast(Unit* target)
if (_target) //for target dead/target not valid
{
- if (!_target->IsTargetable(true, m_casterUnit->IsCharmerOrOwnerPlayerOrPlayerItself()))
+ if (!_target->IsTargetableBy(m_spellInfo->IsPositiveSpell() ? nullptr : m_casterUnit))
return SPELL_FAILED_BAD_TARGETS; // guessed error
// SPELL_EFFECT_DISPEL -> Positive or negative depending on the target
@@ -8410,7 +8410,6 @@ public:
SpellTargets i_TargetType;
SpellCaster* i_originalCaster;
SpellCaster* i_castingObject;
- bool i_playerControlled;
float i_centerX;
float i_centerY;
@@ -8430,7 +8429,6 @@ public:
{
if (!i_originalCaster)
i_originalCaster = i_spell.GetAffectiveCasterObject();
- i_playerControlled = i_originalCaster ? i_originalCaster->IsControlledByPlayer() : false;
switch (i_push_type)
{
@@ -8488,7 +8486,7 @@ public:
if (i_TargetType != SPELL_TARGETS_ALL)
{
bool const forAttack = i_TargetType == SPELL_TARGETS_HOSTILE || i_TargetType == SPELL_TARGETS_NOT_FRIENDLY || i_TargetType == SPELL_TARGETS_AOE_DAMAGE;
- if (!unit->IsTargetable(forAttack, i_playerControlled, true, false) || !i_spell.m_spellInfo->CanTargetAliveState(unit->IsAlive()))
+ if (!unit->IsTargetableBy(forAttack ? i_originalCaster : nullptr, true, false) || !i_spell.m_spellInfo->CanTargetAliveState(unit->IsAlive()))
continue;
}
diff --git a/src/scripts/eastern_kingdoms/burning_steppes/blackwing_lair/boss_chromaggus.cpp b/src/scripts/eastern_kingdoms/burning_steppes/blackwing_lair/boss_chromaggus.cpp
index 7231c9622..40b17608d 100644
--- a/src/scripts/eastern_kingdoms/burning_steppes/blackwing_lair/boss_chromaggus.cpp
+++ b/src/scripts/eastern_kingdoms/burning_steppes/blackwing_lair/boss_chromaggus.cpp
@@ -160,7 +160,7 @@ struct boss_chromaggusAI : public ScriptedAI
return;
if (m_bEngagedOnce && pUnit->IsPlayer() && m_creature->GetDistance2d(pUnit) < 55.0f && m_creature->IsWithinLOSInMap(pUnit)
- && pUnit->IsTargetable(true, false) && pUnit->IsInAccessablePlaceFor(m_creature))
+ && pUnit->IsTargetableBy(m_creature) && pUnit->IsInAccessablePlaceFor(m_creature))
AttackStart(pUnit);
}
diff --git a/src/scripts/eastern_kingdoms/burning_steppes/blackwing_lair/boss_vaelastrasz.cpp b/src/scripts/eastern_kingdoms/burning_steppes/blackwing_lair/boss_vaelastrasz.cpp
index 6ba561fd5..9901f30d7 100644
--- a/src/scripts/eastern_kingdoms/burning_steppes/blackwing_lair/boss_vaelastrasz.cpp
+++ b/src/scripts/eastern_kingdoms/burning_steppes/blackwing_lair/boss_vaelastrasz.cpp
@@ -565,7 +565,7 @@ struct npc_death_talon_CaptainAI : public ScriptedAI
return;
if (pUnit->IsPlayer() && m_creature->GetDistance2d(pUnit) < 29.0f && m_creature->IsWithinLOSInMap(pUnit)
- && pUnit->IsTargetable(true, false) && pUnit->IsInAccessablePlaceFor(m_creature))
+ && pUnit->IsTargetableBy(m_creature) && pUnit->IsInAccessablePlaceFor(m_creature))
AttackStart(pUnit);
}
diff --git a/src/scripts/eastern_kingdoms/burning_steppes/molten_core/molten_core.cpp b/src/scripts/eastern_kingdoms/burning_steppes/molten_core/molten_core.cpp
index ebb00538e..41d8aa613 100644
--- a/src/scripts/eastern_kingdoms/burning_steppes/molten_core/molten_core.cpp
+++ b/src/scripts/eastern_kingdoms/burning_steppes/molten_core/molten_core.cpp
@@ -194,7 +194,7 @@ struct mob_ancient_core_houndAI : public ScriptedAI
{
if (!m_creature->IsInCombat())
{
- if (pWho->IsPlayer() && m_creature->IsWithinDistInMap(pWho, 20.0f) && pWho->IsTargetable(true, false))
+ if (pWho->IsPlayer() && m_creature->IsWithinDistInMap(pWho, 20.0f) && pWho->IsTargetableBy(m_creature))
{
// allow Soothe Animal to lower aggro range
if (m_creature->HasAuraType(SPELL_AURA_MOD_DETECT_RANGE) && !m_creature->IsWithinDistInMap(pWho, 10.0f))
diff --git a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_four_horsemen.cpp b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_four_horsemen.cpp
index 5b5f70009..b1e984461 100644
--- a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_four_horsemen.cpp
+++ b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_four_horsemen.cpp
@@ -168,7 +168,7 @@ struct boss_four_horsemen_shared : public ScriptedAI
if (!pPlayer->IsVisibleForOrDetect(m_creature, m_creature, true, false, &alert))
return;
- if (m_creature->CanInitiateAttack() && pPlayer->IsTargetable(true, false) && m_creature->IsHostileTo(pPlayer))
+ if (m_creature->CanInitiateAttack() && pPlayer->IsTargetableBy(m_creature) && m_creature->IsHostileTo(pPlayer))
{
if (pPlayer->IsInAccessablePlaceFor(m_creature) && m_creature->IsWithinLOSInMap(pPlayer))
{
@@ -197,7 +197,7 @@ struct boss_four_horsemen_shared : public ScriptedAI
if (!m_creature->IsWithinDistInMap(pWho, 75.0f))
return;
- if (m_creature->CanInitiateAttack() && pWho->IsTargetable(true, false) && m_creature->IsHostileTo(pWho))
+ if (m_creature->CanInitiateAttack() && pWho->IsTargetableBy(m_creature) && m_creature->IsHostileTo(pWho))
{
if (pWho->IsInAccessablePlaceFor(m_creature) && m_creature->IsWithinLOSInMap(pWho))
{
diff --git a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_heigan.cpp b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_heigan.cpp
index 48635134d..332b92481 100644
--- a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_heigan.cpp
+++ b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_heigan.cpp
@@ -167,7 +167,7 @@ struct boss_heiganAI : public ScriptedAI
{
if (pWho->GetPositionX() > 2825.0f)
return;
- if (m_creature->CanInitiateAttack() && pWho->IsTargetable(true, false) && m_creature->IsHostileTo(pWho))
+ if (m_creature->CanInitiateAttack() && pWho->IsTargetableBy(m_creature) && m_creature->IsHostileTo(pWho))
{
if (pWho->IsInAccessablePlaceFor(m_creature) && m_creature->IsWithinLOSInMap(pWho))
{
diff --git a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_loatheb.cpp b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_loatheb.cpp
index adc549718..e0046fa91 100644
--- a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_loatheb.cpp
+++ b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_loatheb.cpp
@@ -84,7 +84,7 @@ struct mob_rottingMaggotAI : public ScriptedAI
if (!m_creature->IsWithinDistInMap(pWho, 1.5f))
return;
- if (m_creature->CanInitiateAttack() && pWho->IsTargetable(true, false) && m_creature->IsHostileTo(pWho))
+ if (m_creature->CanInitiateAttack() && pWho->IsTargetableBy(m_creature) && m_creature->IsHostileTo(pWho))
{
if (pWho->IsInAccessablePlaceFor(m_creature) && m_creature->IsWithinLOSInMap(pWho))
{
@@ -160,7 +160,7 @@ struct mob_eyeStalkAI : public ScriptedAI
if (!m_creature->IsWithinDistInMap(pWho, 19.0f))
return;
- if (m_creature->CanInitiateAttack() && pWho->IsTargetable(true, false) && m_creature->IsHostileTo(pWho))
+ if (m_creature->CanInitiateAttack() && pWho->IsTargetableBy(m_creature) && m_creature->IsHostileTo(pWho))
{
if (pWho->IsInAccessablePlaceFor(m_creature) && m_creature->IsWithinLOSInMap(pWho))
{
diff --git a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_maexxna.cpp b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_maexxna.cpp
index e7af46d41..994ba73fd 100644
--- a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_maexxna.cpp
+++ b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_maexxna.cpp
@@ -207,7 +207,7 @@ struct boss_maexxnaAI : public ScriptedAI
if (!m_creature->IsWithinDistInMap(pWho, 40.0f))
return;
- if (m_creature->CanInitiateAttack() && pWho->IsTargetable(true, false) && m_creature->IsHostileTo(pWho))
+ if (m_creature->CanInitiateAttack() && pWho->IsTargetableBy(m_creature) && m_creature->IsHostileTo(pWho))
{
if (pWho->IsInAccessablePlaceFor(m_creature) && m_creature->IsWithinLOSInMap(pWho))
{
diff --git a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_patchwerk.cpp b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_patchwerk.cpp
index 0152e2bd5..0db889dcc 100644
--- a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_patchwerk.cpp
+++ b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_patchwerk.cpp
@@ -226,7 +226,7 @@ struct boss_patchwerkAI : public ScriptedAI
{
for (const auto itr : m_creature->GetAttackers())
{
- if (itr->IsInMap(m_creature) && itr->IsTargetable(true, false))
+ if (itr->IsInMap(m_creature) && itr->IsTargetableBy(m_creature))
return false;
}
}
diff --git a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_razuvious.cpp b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_razuvious.cpp
index 0cee3e0c6..17cbc077b 100644
--- a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_razuvious.cpp
+++ b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_razuvious.cpp
@@ -142,7 +142,7 @@ struct boss_razuviousAI : public ScriptedAI
if (!m_creature->IsWithinDistInMap(pWho, 33.0f))
return;
- if (m_creature->CanInitiateAttack() && pWho->IsTargetable(true, false) && m_creature->IsHostileTo(pWho))
+ if (m_creature->CanInitiateAttack() && pWho->IsTargetableBy(m_creature) && m_creature->IsHostileTo(pWho))
{
if (pWho->IsInAccessablePlaceFor(m_creature) && m_creature->IsWithinLOSInMap(pWho))
{
diff --git a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_sapphiron.cpp b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_sapphiron.cpp
index 47854ada7..f66f098d9 100644
--- a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_sapphiron.cpp
+++ b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_sapphiron.cpp
@@ -280,7 +280,7 @@ struct boss_sapphironAI : public ScriptedAI
if (!pPlayer->IsVisibleForOrDetect(m_creature, m_creature, true, false, &alert))
continue;
- if (!pPlayer->IsTargetable(true, false) || !m_creature->IsHostileTo(pPlayer))
+ if (!pPlayer->IsTargetableBy(m_creature) || !m_creature->IsHostileTo(pPlayer))
continue;
if (phase == PHASE_SKELETON)
diff --git a/src/scripts/eastern_kingdoms/eastern_plaguelands/stratholme/instance_stratholme.cpp b/src/scripts/eastern_kingdoms/eastern_plaguelands/stratholme/instance_stratholme.cpp
index 6ff26235a..2859b9140 100644
--- a/src/scripts/eastern_kingdoms/eastern_plaguelands/stratholme/instance_stratholme.cpp
+++ b/src/scripts/eastern_kingdoms/eastern_plaguelands/stratholme/instance_stratholme.cpp
@@ -744,7 +744,7 @@ struct instance_stratholme : public ScriptedInstance
{
if (Player* pPlayer = player.getSource())
{
- if (pPlayer->IsTargetable(true, false) &&
+ if (pPlayer->IsTargetableBy(nullptr) &&
pPlayer->GetDistance3dToCenter(unforgivenTriggerSpot) < 10.0f)
{
SetData(TYPE_UNFORGIVEN, DONE);
diff --git a/src/scripts/eastern_kingdoms/uldaman/boss_archaedas.cpp b/src/scripts/eastern_kingdoms/uldaman/boss_archaedas.cpp
index fa9f5b792..a593937a9 100644
--- a/src/scripts/eastern_kingdoms/uldaman/boss_archaedas.cpp
+++ b/src/scripts/eastern_kingdoms/uldaman/boss_archaedas.cpp
@@ -150,7 +150,7 @@ struct boss_archaedasAI : public ScriptedAI
}
//Return since we have no target
- if (!UpdateVictim())
+ if (!m_creature->SelectHostileTarget() || !m_creature->GetVictim())
{
return;
}
@@ -386,7 +386,7 @@ struct mob_archaedas_minionsAI : public ScriptedAI
else if (bAwake) uiReconstruct_Timer -= uiDiff;
//Return since we have no target
- if (!UpdateVictim())
+ if (!m_creature->SelectHostileTarget() || !m_creature->GetVictim())
{
return;
}
diff --git a/src/scripts/kalimdor/durotar/durotar.cpp b/src/scripts/kalimdor/durotar/durotar.cpp
index 7f661cfda..9141d2be3 100644
--- a/src/scripts/kalimdor/durotar/durotar.cpp
+++ b/src/scripts/kalimdor/durotar/durotar.cpp
@@ -67,9 +67,9 @@ struct LazyPeonAI : public ScriptedAI
uint8 state;
ObjectGuid playerGuid;
- void DoAction(uint32 const state) override
+ void OnScriptEventHappened(uint32 uiEvent, uint32 /*uiData*/, WorldObject* /*pInvoker*/) override
{
- this->state = state;
+ this->state = uiEvent;
}
void Reset() override {}
diff --git a/src/scripts/kalimdor/dustwallow_marsh/onyxias_lair/boss_onyxia.cpp b/src/scripts/kalimdor/dustwallow_marsh/onyxias_lair/boss_onyxia.cpp
index d5009dc85..842acd69a 100644
--- a/src/scripts/kalimdor/dustwallow_marsh/onyxias_lair/boss_onyxia.cpp
+++ b/src/scripts/kalimdor/dustwallow_marsh/onyxias_lair/boss_onyxia.cpp
@@ -236,7 +236,7 @@ struct boss_onyxiaAI : public ScriptedAI
{
if (Player* pPlayer = itr.getSource())
{
- if (m_creature->IsWithinDistInMap(pPlayer, ONYXIA_AGGRO_RANGE) && pPlayer->IsTargetable(true, false))
+ if (m_creature->IsWithinDistInMap(pPlayer, ONYXIA_AGGRO_RANGE) && pPlayer->IsTargetableBy(m_creature))
{
pPlayer->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
m_creature->AI()->AttackStart(pPlayer);
diff --git a/src/scripts/kalimdor/feralas/dire_maul/instance_dire_maul.cpp b/src/scripts/kalimdor/feralas/dire_maul/instance_dire_maul.cpp
index a164cc4e1..8973e9ce5 100644
--- a/src/scripts/kalimdor/feralas/dire_maul/instance_dire_maul.cpp
+++ b/src/scripts/kalimdor/feralas/dire_maul/instance_dire_maul.cpp
@@ -2100,7 +2100,7 @@ struct npc_alzzins_minionAI : ScriptedAI
{
if (!m_creature->IsInCombat())
{
- if (pWho->IsPlayer() && pWho->IsTargetable(true, false) && m_creature->IsWithinDistInMap(pWho, 30.0f) && m_creature->IsWithinLOSInMap(pWho))
+ if (pWho->IsPlayer() && pWho->IsTargetableBy(m_creature) && m_creature->IsWithinDistInMap(pWho, 30.0f) && m_creature->IsWithinLOSInMap(pWho))
m_creature->AttackedBy(pWho);
}
}
@@ -2157,7 +2157,7 @@ struct boss_ferraAI : public ScriptedAI
if (!m_creature->IsInCombat())
{
if (pWho->IsPlayer() && m_creature->IsWithinDistInMap(pWho, 80.0f) && m_creature->IsWithinLOSInMap(pWho)
- && pWho->IsTargetable(true, false))
+ && pWho->IsTargetableBy(m_creature))
{
// don't aggro people through the floor, ever!
if ((m_creature->GetPositionZ() - pWho->GetPositionZ()) < 10.0f)
diff --git a/src/scripts/kalimdor/silithus/temple_of_ahnqiraj/boss_cthun.cpp b/src/scripts/kalimdor/silithus/temple_of_ahnqiraj/boss_cthun.cpp
index 8dfb639f9..4529e2c43 100644
--- a/src/scripts/kalimdor/silithus/temple_of_ahnqiraj/boss_cthun.cpp
+++ b/src/scripts/kalimdor/silithus/temple_of_ahnqiraj/boss_cthun.cpp
@@ -434,7 +434,7 @@ struct cthunTentacle : public ScriptedAI
Unit* caster = (*it)->GetCaster();
if (!caster) continue;
- if (caster->IsInMap(m_creature) && caster->IsTargetable(true, false) && m_creature->CanReachWithMeleeAutoAttack(caster))
+ if (caster->IsInMap(m_creature) && caster->IsTargetableBy(m_creature) && m_creature->CanReachWithMeleeAutoAttack(caster))
{
target = caster;
break;
diff --git a/src/scripts/kalimdor/silithus/temple_of_ahnqiraj/boss_twinemperors.cpp b/src/scripts/kalimdor/silithus/temple_of_ahnqiraj/boss_twinemperors.cpp
index 64a409fd8..eebea9292 100644
--- a/src/scripts/kalimdor/silithus/temple_of_ahnqiraj/boss_twinemperors.cpp
+++ b/src/scripts/kalimdor/silithus/temple_of_ahnqiraj/boss_twinemperors.cpp
@@ -247,7 +247,7 @@ struct boss_twinemperorsAI : public ScriptedAI
if (!who || m_creature->GetVictim() || m_creature->IsInCombat())
return;
- if (who->IsTargetable(true, false) && who->IsInAccessablePlaceFor(m_creature) && m_creature->IsHostileTo(who))
+ if (who->IsTargetableBy(m_creature) && who->IsInAccessablePlaceFor(m_creature) && m_creature->IsHostileTo(who))
{
float attackRadius = m_creature->GetAttackDistance(who);
if (attackRadius < PULL_RANGE)
diff --git a/src/scripts/kalimdor/tanaris/zulfarrak/zulfarrak.cpp b/src/scripts/kalimdor/tanaris/zulfarrak/zulfarrak.cpp
index db5e70175..464aa54c9 100644
--- a/src/scripts/kalimdor/tanaris/zulfarrak/zulfarrak.cpp
+++ b/src/scripts/kalimdor/tanaris/zulfarrak/zulfarrak.cpp
@@ -111,7 +111,7 @@ struct npc_sergeant_blyAI : public ScriptedAI
//weegli doesn't fight - he goes & blows up the door
if (Creature* weegli = pInstance->instance->GetCreature(pInstance->GetData64(ENTRY_WEEGLI)))
{
- weegli->AI()->DoAction();
+ weegli->AI()->OnScriptEventHappened();
DoScriptText(SAY_WEEGLI, weegli);
}
@@ -147,7 +147,7 @@ struct npc_sergeant_blyAI : public ScriptedAI
DoMeleeAttackIfReady();
}
- void DoAction(uint32 const param) override
+ void OnScriptEventHappened(uint32 /*uiEvent*/ = 0, uint32 /*uiData*/ = 0, WorldObject* /*pInvoker*/ = 0) override
{
postGossipStep = 1;
Text_Timer = 0;
@@ -169,7 +169,7 @@ bool OnGossipSelect_npc_sergeant_bly(Player* pPlayer, Creature* pCreature, uint3
if (npc_sergeant_blyAI* ai = dynamic_cast(pCreature->AI()))
{
ai->PlayerGUID = pPlayer->GetGUID();
- ai->DoAction(0);
+ ai->OnScriptEventHappened();
}
}
return true;
@@ -433,9 +433,9 @@ struct npc_weegli_blastfuseAI : public ScriptedAI
}
}
- void DoAction(uint32 const param) override
+ void OnScriptEventHappened(uint32 /*uiEvent*/ = 0, uint32 /*uiData*/ = 0, WorldObject* /*pInvoker*/ = 0) override
{
- sLog.outString("DoAction de npc_weegli_blastfuse : Destruction porte");
+ sLog.outString("OnScriptEventHappened de npc_weegli_blastfuse : Destruction porte");
DestroyDoor();
}
@@ -482,7 +482,7 @@ bool OnGossipSelect_npc_weegli_blastfuse(Player* pPlayer, Creature* pCreature, u
{
pPlayer->CLOSE_GOSSIP_MENU();
//here we make him run to door, set the charge and run away off to nowhere
- pCreature->AI()->DoAction();
+ pCreature->AI()->OnScriptEventHappened();
}
return true;
}
diff --git a/src/scripts/world/scourge_invasion.cpp b/src/scripts/world/scourge_invasion.cpp
index 5d52827e4..54aa771fc 100644
--- a/src/scripts/world/scourge_invasion.cpp
+++ b/src/scripts/world/scourge_invasion.cpp
@@ -175,7 +175,7 @@ void SummonCultists(Unit* pShard)
float z = pGameObject->GetPositionZ() + 5.0f;
pShard->UpdateGroundPositionZ(x, y, z);
if (Creature* pCultist = pShard->SummonCreature(NPC_CULTIST_ENGINEER, x, y, z, angle - M_PI, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, IN_MILLISECONDS * HOUR, true, 1000))
- pCultist->AI()->DoAction(pShard, NPC_CULTIST_ENGINEER);
+ pCultist->AI()->OnScriptEventHappened(NPC_CULTIST_ENGINEER, 0, pShard);
}
}
}
@@ -303,9 +303,9 @@ struct MouthAI : public ScriptedAI
void Reset() override {}
- void DoAction(uint32 const action) override
+ void OnScriptEventHappened(uint32 uiEvent, uint32 /*uiData*/, WorldObject* /*pInvoker*/) override
{
- switch (action)
+ switch (uiEvent)
{
case EVENT_MOUTH_OF_KELTHUZAD_ZONE_START:
{
@@ -845,17 +845,6 @@ struct npc_cultist_engineer : public ScriptedAI
pGameObject->Delete();
}
- void DoAction(Unit* pUnit, uint32 action) override
- {
- if (action == NPC_CULTIST_ENGINEER)
- {
- m_creature->SetCorpseDelay(10); // Corpse despawns 10 seconds after a Shadow of Doom spawns.
- m_creature->CastSpell(m_creature, SPELL_CREATE_SUMMONER_SHIELD, true);
- m_creature->CastSpell(m_creature, SPELL_MINION_SPAWN_IN, true);
- m_events.ScheduleEvent(EVENT_CULTIST_CHANNELING, 1000);
- }
- }
-
void UpdateAI(uint32 const diff) override
{
m_events.Update(diff);
@@ -888,16 +877,22 @@ struct npc_cultist_engineer : public ScriptedAI
// Player summons a Shadow of Doom for 1 hour.
if (Creature* pShadow = pPlayer->SummonCreature(NPC_SHADOW_OF_DOOM, m_creature->GetPositionX(), m_creature->GetPositionY(), m_creature->GetPositionZ(), m_creature->GetOrientation(), TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, HOUR * IN_MILLISECONDS, true, 5000))
{
- pShadow->AI()->InformGuid(pPlayer->GetObjectGuid(), 0);
pShadow->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER);
pShadow->SetFacingToObject(pPlayer);
- pShadow->AI()->DoAction(pPlayer, NPC_SHADOW_OF_DOOM);
+ pShadow->AI()->OnScriptEventHappened(NPC_SHADOW_OF_DOOM, 0, pPlayer);
pPlayer->DestroyItemCount(ITEM_NECROTIC_RUNE, 8, true);
}
pPlayer->SendSpellGo(pPlayer, SPELL_SUMMON_BOSS);
m_creature->CastSpell(m_creature, SPELL_QUIET_SUICIDE, true);
}
}
+ else if (uiEvent == NPC_CULTIST_ENGINEER)
+ {
+ m_creature->SetCorpseDelay(10); // Corpse despawns 10 seconds after a Shadow of Doom spawns.
+ m_creature->CastSpell(m_creature, SPELL_CREATE_SUMMONER_SHIELD, true);
+ m_creature->CastSpell(m_creature, SPELL_MINION_SPAWN_IN, true);
+ m_events.ScheduleEvent(EVENT_CULTIST_CHANNELING, 1000);
+ }
}
};
@@ -919,7 +914,6 @@ struct ScourgeMinion : public ScriptedAI
}
EventMap m_events;
- ObjectGuid m_summonerGuid;
void Reset()
{
@@ -935,24 +929,19 @@ struct ScourgeMinion : public ScriptedAI
}
}
- void InformGuid(ObjectGuid const guid, uint32 type) override
+ void OnScriptEventHappened(uint32 uiEvent, uint32 /*uiData*/, WorldObject* pInvoker) override
{
- m_summonerGuid = guid;
- }
-
- void DoAction(Unit* pUnit, uint32 action) override
- {
- if (!pUnit)
+ if (!pInvoker)
return;
- if (action == NPC_SHADOW_OF_DOOM)
+ if (uiEvent == NPC_SHADOW_OF_DOOM)
{
m_events.ScheduleEvent(EVENT_DOOM_START_ATTACK, 5000); // Remove Flag (immune to Players) after 5 seconds.
// Pickup random emote like here: https://youtu.be/evOs9aJa2Jw?t=229
- m_creature->MonsterSay(PickRandomValue(BCT_SHADOW_OF_DOOM_TEXT_0, BCT_SHADOW_OF_DOOM_TEXT_1, BCT_SHADOW_OF_DOOM_TEXT_2, BCT_SHADOW_OF_DOOM_TEXT_3), LANG_UNIVERSAL, pUnit);
+ m_creature->MonsterSay(PickRandomValue(BCT_SHADOW_OF_DOOM_TEXT_0, BCT_SHADOW_OF_DOOM_TEXT_1, BCT_SHADOW_OF_DOOM_TEXT_2, BCT_SHADOW_OF_DOOM_TEXT_3), LANG_UNIVERSAL, pInvoker->ToUnit());
m_creature->CastSpell(m_creature, SPELL_SPAWN_SMOKE, true);
}
- if (action == NPC_FLAMESHOCKER)
+ if (uiEvent == NPC_FLAMESHOCKER)
m_events.ScheduleEvent(EVENT_MINION_FLAMESHOCKERS_DESPAWN, 60000);
}
@@ -1000,15 +989,20 @@ struct ScourgeMinion : public ScriptedAI
case EVENT_DOOM_START_ATTACK:
{
m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER);
- // Shadow of Doom seems to attack the Summoner here.
- if (Player* pPlayer = m_creature->GetMap()->GetPlayer(m_summonerGuid))
+
+ if (TemporarySummon* pMe = dynamic_cast(m_creature))
{
- if (pPlayer->IsWithinLOSInMap(m_creature))
+ // Shadow of Doom seems to attack the Summoner here.
+ if (Player* pPlayer = ToPlayer(pMe->GetSummoner()))
{
- m_creature->SetInCombatWith(pPlayer);
- m_creature->SetDetectionDistance(2.0f);
+ if (pPlayer->IsWithinLOSInMap(m_creature))
+ {
+ m_creature->SetInCombatWith(pPlayer);
+ m_creature->SetDetectionDistance(2.0f);
+ }
}
}
+
break;
}
case EVENT_DOOM_MINDFLAY:
@@ -1329,7 +1323,7 @@ struct PallidHorrorAI : public ScriptedAI
{
m_flameshockers.insert(pFlameshocker->GetObjectGuid());
pFlameshocker->CastSpell(pFlameshocker, SPELL_MINION_SPAWN_IN, true);
- pFlameshocker->AI()->DoAction(pFlameshocker, NPC_FLAMESHOCKER);
+ pFlameshocker->AI()->OnScriptEventHappened(NPC_FLAMESHOCKER, 0, pFlameshocker);
}
}
}
diff --git a/src/scripts/world/world_event_wareffort.cpp b/src/scripts/world/world_event_wareffort.cpp
index ee5c78981..63c3c7aa1 100644
--- a/src/scripts/world/world_event_wareffort.cpp
+++ b/src/scripts/world/world_event_wareffort.cpp
@@ -912,7 +912,7 @@ struct npc_infantrymanAI : ScriptedAI
void MoveInLineOfSight(Unit *pWho) override
{
- if (m_creature->CanInitiateAttack() && pWho->IsTargetable(true, false) && m_creature->IsHostileTo(pWho))
+ if (m_creature->CanInitiateAttack() && pWho->IsTargetableBy(m_creature) && m_creature->IsHostileTo(pWho))
{
if (pWho->IsInAccessablePlaceFor(m_creature) && m_creature->IsWithinLOSInMap(pWho))
{
@@ -1388,7 +1388,7 @@ struct npc_aqwar_saurfangAI : ScriptedAI
void MoveInLineOfSight(Unit *pWho) override
{
- if (m_creature->CanInitiateAttack() && pWho->IsTargetable(true, false) && m_creature->IsHostileTo(pWho))
+ if (m_creature->CanInitiateAttack() && pWho->IsTargetableBy(m_creature) && m_creature->IsHostileTo(pWho))
{
if (pWho->IsInAccessablePlaceFor(m_creature) && m_creature->IsWithinLOSInMap(pWho))
{