Core/Creatures: Allow disabling melee attacks for all creatures, not just the ones using SAI

Port From (https://github.com/TrinityCore/TrinityCore/commit/d26d38075cdb56dcef77f05276a360e717cc5032)
This commit is contained in:
hondacrx
2023-03-14 04:34:51 -04:00
parent 40898d4b9f
commit d0b7bcb2fe
7 changed files with 21 additions and 18 deletions
+1 -1
View File
@@ -287,7 +287,7 @@ namespace Framework.Constants
CombatPing = 0x00020000,
Aquatic = 0x00040000, // Aka Water Only, CreatureTemplateMovement.Ground = 0
Amphibious = 0x00080000, // CreatureTemplateMovement.Swim = 1
NoMeleeFlee = 0x00100000, // Prevents Melee(Does Not Prevent Chasing, Does Not Make Creature Passive). Not Sure What 'Flee' Means But Another Flag Is Named NoMeleeApproach
NoMelee = 0x00100000, // Prevents Melee(Does Not Prevent Chasing, Does Not Make Creature Passive). Not Sure What 'Flee' Means But Another Flag Is Named NoMeleeApproach
VisibleToGhosts = 0x00200000, // CreatureTypeFlagVisibleToGhosts
PvpEnabling = 0x00400000, // Old UnitFlagPvpEnabling, Now UnitBytes2OffsetPvpFlag From UnitFieldBytes2
DoNotPlayWoundAnim = 0x00800000, // CreatureTypeFlagDoNotPlayWoundAnim
+1 -1
View File
@@ -54,7 +54,7 @@ namespace Game.AI
public void DoMeleeAttackIfReady()
{
if (me.HasUnitState(UnitState.Casting))
if (me.HasUnitState(UnitState.Casting) || (me.IsCreature() && !me.ToCreature().CanMelee()))
return;
Unit victim = me.GetVictim();
+4 -8
View File
@@ -44,7 +44,6 @@ namespace Game.AI
bool _run;
bool _evadeDisabled;
bool _canAutoAttack;
bool _canCombatMove;
uint _invincibilityHpLevel;
@@ -62,7 +61,6 @@ namespace Game.AI
{
_escortInvokerCheckTimer = 1000;
_run = true;
_canAutoAttack = true;
_canCombatMove = true;
_hasConditions = Global.ConditionMgr.HasConditionsForNotGroupedEntry(ConditionSourceType.CreatureTemplateVehicle, creature.GetEntry());
@@ -338,9 +336,8 @@ namespace Game.AI
if (!hasVictim)
return;
if (_canAutoAttack)
DoMeleeAttackIfReady();
DoMeleeAttackIfReady();
}
bool IsEscortInvokerInRange()
@@ -629,11 +626,11 @@ namespace Game.AI
if (!IsAIControlled())
{
if (who != null)
me.Attack(who, _canAutoAttack);
me.Attack(who, true);
return;
}
if (who != null && me.Attack(who, _canAutoAttack))
if (who != null && me.Attack(who, true))
{
me.GetMotionMaster().Clear(MovementGeneratorPriority.Normal);
me.PauseMovement();
@@ -1074,7 +1071,6 @@ namespace Game.AI
public bool HasEscortState(SmartEscortState escortState) { return (_escortState & escortState) != 0; }
public void AddEscortState(SmartEscortState escortState) { _escortState |= escortState; }
public void RemoveEscortState(SmartEscortState escortState) { _escortState &= ~escortState; }
public void SetAutoAttack(bool on) { _canAutoAttack = on; }
public bool CanCombatMove() { return _canCombatMove; }
+1 -4
View File
@@ -615,10 +615,7 @@ namespace Game.AI
}
case SmartActions.AutoAttack:
{
if (!IsSmart())
break;
((SmartAI)_me.GetAI()).SetAutoAttack(e.Action.autoAttack.attack != 0);
_me.SetCanMelee(e.Action.autoAttack.attack != 0);
Log.outDebug(LogFilter.ScriptsAi, "SmartScript.ProcessAction. SMART_ACTION_AUTO_ATTACK: Creature: {0} bool on = {1}",
_me.GetGUID().ToString(), e.Action.autoAttack.attack);
break;
@@ -3246,6 +3246,10 @@ namespace Game.Entities
public override SpellSchoolMask GetMeleeDamageSchoolMask(WeaponAttackType attackType = WeaponAttackType.BaseAttack) { return m_meleeDamageSchoolMask; }
public void SetMeleeDamageSchool(SpellSchools school) { m_meleeDamageSchoolMask = (SpellSchoolMask)(1 << (int)school); }
public bool CanMelee() { return !_staticFlags.HasFlag(CreatureStaticFlags.NoMelee); }
public void SetCanMelee(bool canMelee) { _staticFlags.ApplyFlag(CreatureStaticFlags.NoMelee, !canMelee); }
public sbyte GetOriginalEquipmentId() { return m_originalEquipmentId; }
public byte GetCurrentEquipmentId() { return m_equipmentId; }
public void SetCurrentEquipmentId(byte id) { m_equipmentId = id; }
+8 -2
View File
@@ -258,8 +258,14 @@ namespace Game.Entities
Creature creature = ToCreature();
// creatures cannot attack while evading
if (creature != null && creature.IsInEvadeMode())
return false;
if (creature != null)
{
if (creature.IsInEvadeMode())
return false;
if (!creature.CanMelee())
meleeAttack = false;
}
// nobody can attack GM in GM-mode
if (victim.IsTypeId(TypeId.Player))
+2 -2
View File
@@ -1295,9 +1295,9 @@ namespace Game.Scripting
return ScriptMap.Empty();
}
public List<TValue> GetStorage()
public ICollection<TValue> GetStorage()
{
return ScriptMap.Values.ToList();
return ScriptMap.Values;
}
public void Unload()