mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 02:25:38 +01:00
Core/Creatures: Allow disabling melee attacks for all creatures, not just the ones using SAI
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user