Core/Entities: Kick engagement logic upstairs to Unit (from ThreatManager), since all Units with AI need it (not just those with threat list).
Port From (https://github.com/TrinityCore/TrinityCore/commit/35e55f10899712435102764671241b94a2026599)
This commit is contained in:
@@ -277,11 +277,15 @@ namespace Game.Combat
|
||||
{
|
||||
_owner.AddUnitFlag(UnitFlags.InCombat);
|
||||
_owner.AtEnterCombat();
|
||||
if (!_owner.CanHaveThreatList() && !_owner.IsEngaged())
|
||||
_owner.AtEngage(GetAnyTarget());
|
||||
}
|
||||
else
|
||||
{
|
||||
_owner.RemoveUnitFlag(UnitFlags.InCombat);
|
||||
_owner.AtExitCombat();
|
||||
if (_owner.IsEngaged() && !(_owner.IsCreature() && _owner.ToCreature().IsAIEnabled()))
|
||||
_owner.AtDisengage();
|
||||
}
|
||||
|
||||
Unit master = _owner.GetCharmerOrOwner();
|
||||
|
||||
@@ -32,7 +32,6 @@ namespace Game.Combat
|
||||
|
||||
public Unit _owner;
|
||||
bool _ownerCanHaveThreatList;
|
||||
bool _ownerEngaged;
|
||||
|
||||
public bool NeedClientUpdate;
|
||||
uint _updateTimer;
|
||||
@@ -82,7 +81,7 @@ namespace Game.Combat
|
||||
|
||||
public void Update(uint tdiff)
|
||||
{
|
||||
if (!CanHaveThreatList() || !IsEngaged())
|
||||
if (!CanHaveThreatList() || IsThreatListEmpty())
|
||||
return;
|
||||
|
||||
if (_updateTimer <= tdiff)
|
||||
@@ -192,13 +191,6 @@ namespace Game.Combat
|
||||
}
|
||||
}
|
||||
|
||||
static void SaveCreatureHomePositionIfNeed(Creature c)
|
||||
{
|
||||
MovementGeneratorType movetype = c.GetMotionMaster().GetCurrentMovementGeneratorType();
|
||||
if (movetype == MovementGeneratorType.Waypoint || movetype == MovementGeneratorType.Point || (c.IsAIEnabled() && c.GetAI().IsEscorted()))
|
||||
c.SetHomePosition(c.GetPosition());
|
||||
}
|
||||
|
||||
public void AddThreat(Unit target, float amount, SpellInfo spell = null, bool ignoreModifiers = false, bool ignoreRedirects = false)
|
||||
{
|
||||
// step 1: we can shortcut if the spell has one of the NO_THREAT attrs set - nothing will happen
|
||||
@@ -317,20 +309,10 @@ namespace Game.Combat
|
||||
if (newRefe.IsOnline()) // ...and if the ref is online it also gets the threat it should have
|
||||
newRefe.AddThreat(amount);
|
||||
|
||||
if (!_ownerEngaged)
|
||||
if (!_owner.IsEngaged())
|
||||
{
|
||||
Creature cOwner = _owner.ToCreature(); // if we got here the owner can have a threat list, and must be a creature!
|
||||
_ownerEngaged = true;
|
||||
|
||||
_owner.AtEngage(target);
|
||||
UpdateVictim();
|
||||
SaveCreatureHomePositionIfNeed(cOwner);
|
||||
CreatureAI ownerAI = cOwner.GetAI();
|
||||
if (ownerAI != null)
|
||||
ownerAI.JustEngagedWith(target);
|
||||
|
||||
CreatureGroup formation = cOwner.GetFormation();
|
||||
if (formation != null)
|
||||
formation.MemberEngagingTarget(cOwner, target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,14 +389,17 @@ namespace Game.Combat
|
||||
|
||||
public void ClearAllThreat()
|
||||
{
|
||||
_ownerEngaged = false;
|
||||
if (_myThreatListEntries.Empty())
|
||||
return;
|
||||
|
||||
SendClearAllThreatToClients();
|
||||
do
|
||||
_myThreatListEntries.First().Value.UnregisterAndFree();
|
||||
while (!_myThreatListEntries.Empty());
|
||||
if (!_myThreatListEntries.Empty())
|
||||
{
|
||||
SendClearAllThreatToClients();
|
||||
do
|
||||
_myThreatListEntries.FirstOrDefault().Value.UnregisterAndFree();
|
||||
while (!_myThreatListEntries.Empty());
|
||||
}
|
||||
// note: i don't really like having this here
|
||||
// (maybe engage flag should be in creature ai? it's inherently an AI property...)
|
||||
if (_owner.IsEngaged())
|
||||
_owner.AtDisengage();
|
||||
}
|
||||
|
||||
public void FixateTarget(Unit target)
|
||||
@@ -783,8 +768,6 @@ namespace Game.Combat
|
||||
// identical to ThreatManager::CanHaveThreatList(GetOwner())
|
||||
public bool CanHaveThreatList() { return _ownerCanHaveThreatList; }
|
||||
|
||||
public bool IsEngaged() { return _ownerEngaged; }
|
||||
|
||||
public int GetThreatListSize() { return _sortedThreatList.Count; }
|
||||
|
||||
// fastest of the three threat list getters - gets the threat list in "arbitrary" order
|
||||
|
||||
Reference in New Issue
Block a user