aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/AI
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-01-08 22:23:12 +0100
committerShauren <shauren.trinity@gmail.com>2024-01-08 22:23:12 +0100
commit605e5f94c0d71cad8e83fa5a07eaec4e6bed9cc3 (patch)
tree5cad677458a22ef0dd187fa86d1cd574282384dd /src/server/game/AI
parenteeb4407f077bf567361becdbe5083c2790f00313 (diff)
Core/Creatures: Moved autoattack handling from scripts to game
Diffstat (limited to 'src/server/game/AI')
-rw-r--r--src/server/game/AI/CoreAI/CombatAI.cpp9
-rw-r--r--src/server/game/AI/CoreAI/GuardAI.cpp5
-rw-r--r--src/server/game/AI/CoreAI/PassiveAI.cpp4
-rw-r--r--src/server/game/AI/CoreAI/PetAI.cpp9
-rw-r--r--src/server/game/AI/CoreAI/ReactorAI.cpp5
-rw-r--r--src/server/game/AI/CoreAI/UnitAI.cpp35
-rw-r--r--src/server/game/AI/CoreAI/UnitAI.h1
-rw-r--r--src/server/game/AI/PlayerAI/PlayerAI.cpp2
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedCreature.cpp9
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp5
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp5
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.cpp10
12 files changed, 11 insertions, 88 deletions
diff --git a/src/server/game/AI/CoreAI/CombatAI.cpp b/src/server/game/AI/CoreAI/CombatAI.cpp
index 16c161dbd7a..b20cf471b0c 100644
--- a/src/server/game/AI/CoreAI/CombatAI.cpp
+++ b/src/server/game/AI/CoreAI/CombatAI.cpp
@@ -43,10 +43,7 @@ int32 AggressorAI::Permissible(Creature const* creature)
void AggressorAI::UpdateAI(uint32 /*diff*/)
{
- if (!UpdateVictim())
- return;
-
- DoMeleeAttackIfReady();
+ UpdateVictim();
}
/////////////////
@@ -107,8 +104,6 @@ void CombatAI::UpdateAI(uint32 diff)
if (AISpellInfoType const* info = GetAISpellInfo(spellId, me->GetMap()->GetDifficultyID()))
_events.ScheduleEvent(spellId, info->cooldown, info->cooldown * 2);
}
- else
- DoMeleeAttackIfReady();
}
void CombatAI::SpellInterrupted(uint32 spellId, uint32 unTimeMs)
@@ -202,6 +197,7 @@ TurretAI::TurretAI(Creature* creature, uint32 scriptId) : CreatureAI(creature, s
_minimumRange = spellInfo ? spellInfo->GetMinRange(false) : 0;
creature->m_CombatDistance = spellInfo ? spellInfo->GetMaxRange(false) : 0;
creature->m_SightDistance = creature->m_CombatDistance;
+ creature->SetCanMelee(false);
}
bool TurretAI::CanAIAttack(Unit const* who) const
@@ -235,6 +231,7 @@ VehicleAI::VehicleAI(Creature* creature, uint32 scriptId) : CreatureAI(creature,
LoadConditions();
_dismiss = false;
_dismissTimer = VEHICLE_DISMISS_TIME;
+ me->SetCanMelee(false);
}
// NOTE: VehicleAI::UpdateAI runs even while the vehicle is mounted
diff --git a/src/server/game/AI/CoreAI/GuardAI.cpp b/src/server/game/AI/CoreAI/GuardAI.cpp
index 5d6b62e83a9..21511c1f2c0 100644
--- a/src/server/game/AI/CoreAI/GuardAI.cpp
+++ b/src/server/game/AI/CoreAI/GuardAI.cpp
@@ -31,10 +31,7 @@ int32 GuardAI::Permissible(Creature const* creature)
void GuardAI::UpdateAI(uint32 /*diff*/)
{
- if (!UpdateVictim())
- return;
-
- DoMeleeAttackIfReady();
+ UpdateVictim();
}
bool GuardAI::CanSeeAlways(WorldObject const* obj)
diff --git a/src/server/game/AI/CoreAI/PassiveAI.cpp b/src/server/game/AI/CoreAI/PassiveAI.cpp
index 8bae96a6092..82904e5f52f 100644
--- a/src/server/game/AI/CoreAI/PassiveAI.cpp
+++ b/src/server/game/AI/CoreAI/PassiveAI.cpp
@@ -22,6 +22,7 @@
PassiveAI::PassiveAI(Creature* c, uint32 scriptId) : CreatureAI(c, scriptId)
{
me->SetReactState(REACT_PASSIVE);
+ me->SetCanMelee(false);
}
PossessedAI::PossessedAI(Creature* c, uint32 scriptId) : CreatureAI(c, scriptId)
@@ -32,6 +33,7 @@ PossessedAI::PossessedAI(Creature* c, uint32 scriptId) : CreatureAI(c, scriptId)
NullCreatureAI::NullCreatureAI(Creature* c, uint32 scriptId) : CreatureAI(c, scriptId)
{
me->SetReactState(REACT_PASSIVE);
+ me->SetCanMelee(false);
}
int32 NullCreatureAI::Permissible(Creature const* creature)
@@ -62,8 +64,6 @@ void PossessedAI::UpdateAI(uint32 /*diff*/)
{
if (!me->IsValidAttackTarget(me->GetVictim()))
me->AttackStop();
- else
- DoMeleeAttackIfReady();
}
}
diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp
index 42666d2a1e2..16e9356f646 100644
--- a/src/server/game/AI/CoreAI/PetAI.cpp
+++ b/src/server/game/AI/CoreAI/PetAI.cpp
@@ -80,15 +80,6 @@ void PetAI::UpdateAI(uint32 diff)
StopAttack();
return;
}
-
- // Check before attacking to prevent pets from leaving stay position
- if (me->GetCharmInfo()->HasCommandState(COMMAND_STAY))
- {
- if (me->GetCharmInfo()->IsCommandAttack() || (me->GetCharmInfo()->IsAtStay() && me->IsWithinMeleeRange(me->GetVictim())))
- DoMeleeAttackIfReady();
- }
- else
- DoMeleeAttackIfReady();
}
else
{
diff --git a/src/server/game/AI/CoreAI/ReactorAI.cpp b/src/server/game/AI/CoreAI/ReactorAI.cpp
index 8b15bed1908..a22876a067b 100644
--- a/src/server/game/AI/CoreAI/ReactorAI.cpp
+++ b/src/server/game/AI/CoreAI/ReactorAI.cpp
@@ -28,8 +28,5 @@ int32 ReactorAI::Permissible(Creature const* creature)
void ReactorAI::UpdateAI(uint32 /*diff*/)
{
- if (!UpdateVictim())
- return;
-
- DoMeleeAttackIfReady();
+ UpdateVictim();
}
diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp
index c8d2f61e77b..1470ca07bd9 100644
--- a/src/server/game/AI/CoreAI/UnitAI.cpp
+++ b/src/server/game/AI/CoreAI/UnitAI.cpp
@@ -58,41 +58,6 @@ void UnitAI::AttackStartCaster(Unit* victim, float dist)
me->GetMotionMaster()->MoveChase(victim, dist);
}
-void UnitAI::DoMeleeAttackIfReady()
-{
- if (me->IsCreature() && !me->ToCreature()->CanMelee())
- return;
-
- if (me->HasUnitState(UNIT_STATE_CASTING))
- {
- Spell* channeledSpell = me->GetCurrentSpell(CURRENT_CHANNELED_SPELL);
- if (!channeledSpell || !channeledSpell->GetSpellInfo()->HasAttribute(SPELL_ATTR5_ALLOW_ACTIONS_DURING_CHANNEL))
- return;
- }
-
- Unit* victim = me->GetVictim();
-
- if (!me->IsWithinMeleeRange(victim))
- return;
-
- // Check that the victim is in front of the unit
- if (!me->HasInArc(2 * float(M_PI) / 3, victim))
- return;
-
- //Make sure our attack is ready and we aren't currently casting before checking distance
- if (me->isAttackReady())
- {
- me->AttackerStateUpdate(victim);
- me->resetAttackTimer();
- }
-
- if (me->haveOffhandWeapon() && me->isAttackReady(OFF_ATTACK))
- {
- me->AttackerStateUpdate(victim, OFF_ATTACK);
- me->resetAttackTimer(OFF_ATTACK);
- }
-}
-
bool UnitAI::DoSpellAttackIfReady(uint32 spellId)
{
if (me->HasUnitState(UNIT_STATE_CASTING) || !me->isAttackReady())
diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h
index fed0cae7203..1ae52ff00a7 100644
--- a/src/server/game/AI/CoreAI/UnitAI.h
+++ b/src/server/game/AI/CoreAI/UnitAI.h
@@ -160,7 +160,6 @@ class TC_GAME_API UnitAI
SpellCastResult DoCastVictim(uint32 spellId, CastSpellExtraArgs const& args = {});
SpellCastResult DoCastAOE(uint32 spellId, CastSpellExtraArgs const& args = {}) { return DoCast(nullptr, spellId, args); }
- void DoMeleeAttackIfReady();
bool DoSpellAttackIfReady(uint32 spellId);
static std::unordered_map<std::pair<uint32, Difficulty>, AISpellInfoType> AISpellInfo;
diff --git a/src/server/game/AI/PlayerAI/PlayerAI.cpp b/src/server/game/AI/PlayerAI/PlayerAI.cpp
index 2f104c40eac..bfa4ea84f96 100644
--- a/src/server/game/AI/PlayerAI/PlayerAI.cpp
+++ b/src/server/game/AI/PlayerAI/PlayerAI.cpp
@@ -591,8 +591,6 @@ void PlayerAI::DoAutoAttackIfReady()
{
if (IsRangedAttacker())
DoRangedAttackIfReady();
- else
- DoMeleeAttackIfReady();
}
void PlayerAI::CancelAllShapeshifts()
diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
index 00c15509f5a..82c8dac896f 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
+++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
@@ -149,10 +149,7 @@ void ScriptedAI::AttackStart(Unit* who)
void ScriptedAI::UpdateAI(uint32 /*diff*/)
{
// Check if we have a current target
- if (!UpdateVictim())
- return;
-
- DoMeleeAttackIfReady();
+ UpdateVictim();
}
void ScriptedAI::DoStartMovement(Unit* victim, float distance, float angle)
@@ -629,8 +626,6 @@ void BossAI::UpdateAI(uint32 diff)
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
}
-
- DoMeleeAttackIfReady();
}
bool BossAI::CanAIAttack(Unit const* target) const
@@ -716,6 +711,4 @@ void WorldBossAI::UpdateAI(uint32 diff)
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
}
-
- DoMeleeAttackIfReady();
}
diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp
index ca6290d1379..19d11c4b957 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp
+++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp
@@ -248,10 +248,7 @@ void EscortAI::UpdateAI(uint32 diff)
void EscortAI::UpdateEscortAI(uint32 /*diff*/)
{
- if (!UpdateVictim())
- return;
-
- DoMeleeAttackIfReady();
+ UpdateVictim();
}
void EscortAI::AddWaypoint(uint32 id, float x, float y, float z, bool run)
diff --git a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp
index f12b7aaf9b6..c0a5aa3350a 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp
+++ b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp
@@ -147,10 +147,7 @@ void FollowerAI::UpdateAI(uint32 uiDiff)
void FollowerAI::UpdateFollowerAI(uint32 /*uiDiff*/)
{
- if (!UpdateVictim())
- return;
-
- DoMeleeAttackIfReady();
+ UpdateVictim();
}
void FollowerAI::StartFollow(Player* player, uint32 factionForFollower, uint32 quest)
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp
index 370e2d1a9f8..9177443d57f 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.cpp
+++ b/src/server/game/AI/SmartScripts/SmartAI.cpp
@@ -283,21 +283,13 @@ void SmartAI::UpdateAI(uint32 diff)
CheckConditions(diff);
- bool hasVictim = UpdateVictim();
+ UpdateVictim();
GetScript()->OnUpdate(diff);
UpdatePath(diff);
UpdateFollow(diff);
UpdateDespawn(diff);
-
- if (!IsAIControlled())
- return;
-
- if (!hasVictim)
- return;
-
- DoMeleeAttackIfReady();
}
bool SmartAI::IsEscortInvokerInRange()