aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-03-13 20:22:47 +0100
committerShauren <shauren.trinity@gmail.com>2023-03-13 20:22:47 +0100
commitd26d38075cdb56dcef77f05276a360e717cc5032 (patch)
treef35aa8fa9e9a3b1bef09f38d3709f1fbf44eaddd /src
parenteb93afffc08a45354e1b896adf38d1f8e8b352ac (diff)
Core/Creatures: Allow disabling melee attacks for all creatures, not just the ones using SAI
Diffstat (limited to 'src')
-rw-r--r--src/server/game/AI/CoreAI/UnitAI.cpp2
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.cpp9
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.h7
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp5
-rw-r--r--src/server/game/Entities/Creature/Creature.h2
-rw-r--r--src/server/game/Entities/Creature/CreatureData.h2
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp10
7 files changed, 18 insertions, 19 deletions
diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp
index b503441b976..81077ab5565 100644
--- a/src/server/game/AI/CoreAI/UnitAI.cpp
+++ b/src/server/game/AI/CoreAI/UnitAI.cpp
@@ -60,7 +60,7 @@ void UnitAI::AttackStartCaster(Unit* victim, float dist)
void UnitAI::DoMeleeAttackIfReady()
{
- if (me->HasUnitState(UNIT_STATE_CASTING))
+ if (me->HasUnitState(UNIT_STATE_CASTING) || (me->IsCreature() && !me->ToCreature()->CanMelee()))
return;
Unit* victim = me->GetVictim();
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp
index 56c6b98c208..1e0e0b9dec0 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.cpp
+++ b/src/server/game/AI/SmartScripts/SmartAI.cpp
@@ -33,7 +33,7 @@
SmartAI::SmartAI(Creature* creature, uint32 scriptId) : CreatureAI(creature, scriptId), _charmed(false), _followCreditType(0), _followArrivedTimer(0), _followCredit(0), _followArrivedEntry(0), _followDistance(0.f), _followAngle(0.f),
_escortState(SMART_ESCORT_NONE), _escortNPCFlags(0), _escortInvokerCheckTimer(1000), _currentWaypointNode(0), _waypointReached(false), _waypointPauseTimer(0), _waypointPauseForced(false), _repeatWaypointPath(false),
- _OOCReached(false), _waypointPathEnded(false), _run(true), _evadeDisabled(false), _canAutoAttack(true), _canCombatMove(true), _invincibilityHPLevel(0), _despawnTime(0), _despawnState(0), _vehicleConditionsTimer(0),
+ _OOCReached(false), _waypointPathEnded(false), _run(true), _evadeDisabled(false), _canCombatMove(true), _invincibilityHPLevel(0), _despawnTime(0), _despawnState(0), _vehicleConditionsTimer(0),
_gossipReturn(false), _escortQuestId(0)
{
_vehicleConditions = sConditionMgr->HasConditionsForNotGroupedEntry(CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, creature->GetEntry());
@@ -309,8 +309,7 @@ void SmartAI::UpdateAI(uint32 diff)
if (!hasVictim)
return;
- if (_canAutoAttack)
- DoMeleeAttackIfReady();
+ DoMeleeAttackIfReady();
}
bool SmartAI::IsEscortInvokerInRange()
@@ -594,11 +593,11 @@ void SmartAI::AttackStart(Unit* who)
if (!IsAIControlled())
{
if (who)
- me->Attack(who, _canAutoAttack);
+ me->Attack(who, true);
return;
}
- if (who && me->Attack(who, _canAutoAttack))
+ if (who && me->Attack(who, true))
{
me->GetMotionMaster()->Clear(MOTION_PRIORITY_NORMAL);
me->PauseMovement();
diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h
index b5f07778d32..82e2a53be3c 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.h
+++ b/src/server/game/AI/SmartScripts/SmartAI.h
@@ -68,12 +68,8 @@ class TC_GAME_API SmartAI : public CreatureAI
{
_escortState &= ~escortState;
}
- void SetAutoAttack(bool on)
- {
- _canAutoAttack = on;
- }
void SetCombatMove(bool on, bool stopMoving = false);
- bool CanCombatMove()
+ bool CanCombatMove() const
{
return _canCombatMove;
}
@@ -268,7 +264,6 @@ class TC_GAME_API SmartAI : public CreatureAI
bool _run;
bool _evadeDisabled;
- bool _canAutoAttack;
bool _canCombatMove;
uint32 _invincibilityHPLevel;
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp
index 5454b012212..2d8ebcc7783 100644
--- a/src/server/game/AI/SmartScripts/SmartScript.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScript.cpp
@@ -743,10 +743,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
case SMART_ACTION_AUTO_ATTACK:
{
- if (!IsSmart())
- break;
-
- ENSURE_AI(SmartAI, me->AI())->SetAutoAttack(e.action.autoAttack.attack != 0);
+ me->SetCanMelee(e.action.autoAttack.attack != 0);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_AUTO_ATTACK: Creature: {} bool on = {}",
me->GetGUID().ToString(), e.action.autoAttack.attack);
break;
diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h
index 403ed25d0ac..449c83ae9ad 100644
--- a/src/server/game/Entities/Creature/Creature.h
+++ b/src/server/game/Entities/Creature/Creature.h
@@ -184,6 +184,8 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
SpellSchoolMask GetMeleeDamageSchoolMask(WeaponAttackType /*attackType*/ = BASE_ATTACK) const override { return m_meleeDamageSchoolMask; }
void SetMeleeDamageSchool(SpellSchools school) { m_meleeDamageSchoolMask = SpellSchoolMask(1 << school); }
+ bool CanMelee() const { return !_staticFlags.HasFlag(CREATURE_STATIC_FLAG_NO_MELEE); }
+ void SetCanMelee(bool canMelee) { _staticFlags.ApplyFlag(CREATURE_STATIC_FLAG_NO_MELEE, !canMelee); }
bool HasSpell(uint32 spellID) const override;
diff --git a/src/server/game/Entities/Creature/CreatureData.h b/src/server/game/Entities/Creature/CreatureData.h
index da173c7b6db..e460ac1ce6d 100644
--- a/src/server/game/Entities/Creature/CreatureData.h
+++ b/src/server/game/Entities/Creature/CreatureData.h
@@ -55,7 +55,7 @@ enum CreatureStaticFlags
CREATURE_STATIC_FLAG_COMBAT_PING = 0x00020000,
CREATURE_STATIC_FLAG_AQUATIC = 0x00040000, // aka Water Only, creature_template_movement.Ground = 0
CREATURE_STATIC_FLAG_AMPHIBIOUS = 0x00080000, // creature_template_movement.Swim = 1
- CREATURE_STATIC_FLAG_NO_MELEE_FLEE = 0x00100000, // Prevents melee(does not prevent chasing, does not make creature passive). Not sure what 'Flee' means but another flag is named NO_MELEE_APPROACH
+ CREATURE_STATIC_FLAG_NO_MELEE = 0x00100000, // "No Melee (Flee)" Prevents melee(does not prevent chasing, does not make creature passive). Not sure what 'Flee' means but another flag is named NO_MELEE_APPROACH
CREATURE_STATIC_FLAG_VISIBLE_TO_GHOSTS = 0x00200000, // CREATURE_TYPE_FLAG_VISIBLE_TO_GHOSTS
CREATURE_STATIC_FLAG_PVP_ENABLING = 0x00400000, // Old UNIT_FLAG_PVP_ENABLING, now UNIT_BYTES_2_OFFSET_PVP_FLAG from UNIT_FIELD_BYTES_2
CREATURE_STATIC_FLAG_DO_NOT_PLAY_WOUND_ANIM = 0x00800000, // CREATURE_TYPE_FLAG_DO_NOT_PLAY_WOUND_ANIM
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 2228324d965..f6976fe1c00 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -5550,8 +5550,14 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
Creature* creature = ToCreature();
// creatures cannot attack while evading
- if (creature && creature->IsInEvadeMode())
- return false;
+ if (creature)
+ {
+ if (creature->IsInEvadeMode())
+ return false;
+
+ if (!creature->CanMelee())
+ meleeAttack = false;
+ }
// nobody can attack GM in GM-mode
if (victim->GetTypeId() == TYPEID_PLAYER)