Core/Creatures: Implemented CREATURE_STATIC_FLAG_4_NO_MELEE_APPROACH and fixed CREATURE_STATIC_FLAG_NO_MELEE_FLEE implementation (should cause fleeing from melee range)

Port From (https://github.com/TrinityCore/TrinityCore/commit/a748fddfa47216e1f516303e3bca9b5a86823748)
This commit is contained in:
hondacrx
2024-02-24 15:18:07 -05:00
parent dab3a891a7
commit 9d1589afd4
10 changed files with 93 additions and 34 deletions
+42 -3
View File
@@ -2602,6 +2602,47 @@ namespace Game.Entities
Global.WorldMgr.SendGlobalMessage(packet, null, (enemy_team == Team.Alliance ? Team.Horde : Team.Alliance));
}
public void SetCanMelee(bool canMelee, bool fleeFromMelee = false)
{
bool wasFleeingFromMelee = HasFlag(CreatureStaticFlags.NoMeleeFlee);
_staticFlags.ApplyFlag(CreatureStaticFlags.NoMeleeFlee, !canMelee && fleeFromMelee);
_staticFlags.ApplyFlag(CreatureStaticFlags4.NoMeleeApproach, !canMelee && !fleeFromMelee);
if (wasFleeingFromMelee == HasFlag(CreatureStaticFlags.NoMeleeFlee))
return;
Unit victim = GetVictim();
if (victim == null)
return;
var currentMovement = GetMotionMaster().GetCurrentMovementGenerator();
if (currentMovement == null)
return;
var canChangeMovement = new Func<bool>(() =>
{
if (wasFleeingFromMelee)
return currentMovement.GetMovementGeneratorType() == MovementGeneratorType.Fleeing && !HasUnitFlag(UnitFlags.Fleeing);
return currentMovement.GetMovementGeneratorType() == MovementGeneratorType.Chase;
})();
if (!canChangeMovement)
return;
GetMotionMaster().Remove(currentMovement);
StartDefaultCombatMovement(victim);
}
public void StartDefaultCombatMovement(Unit victim, float? range = null, float? angle = null)
{
if (!HasFlag(CreatureStaticFlags.NoMeleeFlee) || IsSummon())
GetMotionMaster().MoveChase(victim, range.GetValueOrDefault(0), angle.GetValueOrDefault(0));
else
GetMotionMaster().MoveFleeing(victim);
}
public override bool HasSpell(uint spellId)
{
return m_spells.Contains(spellId);
@@ -3376,9 +3417,7 @@ 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 bool CanMelee() { return !_staticFlags.HasFlag(CreatureStaticFlags.NoMeleeFlee) && !_staticFlags.HasFlag(CreatureStaticFlags4.NoMeleeApproach); }
public bool CanIgnoreLineOfSightWhenCastingOnMe() { return _staticFlags.HasFlag(CreatureStaticFlags4.IgnoreLosWhenCastingOnMe); }
+5 -2
View File
@@ -1391,14 +1391,17 @@ namespace Game.Entities
if (caster == null)
caster = GetAttackerForHelper();
GetMotionMaster().MoveFleeing(caster, TimeSpan.FromMilliseconds(fearAuras.Empty() ? WorldConfig.GetIntValue(WorldCfg.CreatureFamilyFleeDelay) : 0)); // caster == NULL processed in MoveFleeing
SetUnitFlag(UnitFlags.Fleeing);
}
else
{
RemoveUnitFlag(UnitFlags.Fleeing);
if (IsAlive())
{
GetMotionMaster().Remove(MovementGeneratorType.Fleeing);
if (GetVictim() != null)
SetTarget(GetVictim().GetGUID());
Unit victim = GetVictim();
if (victim != null)
SetTarget(victim.GetGUID());
if (!IsPlayer() && !IsInCombat())
GetMotionMaster().MoveTargetedHome();
}