Core/Combat: Allow PvE combat references to become suppressed, just like PvP ones

Port From (https://github.com/TrinityCore/TrinityCore/commit/9bfc29f4aff01cd7f366faffcda0a84071970d6a)
This commit is contained in:
hondacrx
2022-09-07 13:23:53 -04:00
parent df33c48826
commit a5cfd149b7
2 changed files with 58 additions and 43 deletions
+56 -41
View File
@@ -83,10 +83,18 @@ namespace Game.Combat
}
}
public bool HasPvECombat()
{
foreach (var (_, refe) in _pveRefs)
if (!refe.IsSuppressedFor(_owner))
return true;
return false;
}
public bool HasPvECombatWithPlayers()
{
foreach (var reference in _pveRefs)
if (reference.Value.GetOther(_owner).IsPlayer())
if (!reference.Value.IsSuppressedFor(_owner) && reference.Value.GetOther(_owner).IsPlayer())
return true;
return false;
@@ -103,8 +111,9 @@ namespace Game.Combat
public Unit GetAnyTarget()
{
if (!_pveRefs.Empty())
return _pveRefs.First().Value.GetOther(_owner);
foreach (var pair in _pveRefs)
if (!pair.Value.IsSuppressedFor(_owner))
return pair.Value.GetOther(_owner);
foreach (var pair in _pvpRefs)
if (!pair.Value.IsSuppressedFor(_owner))
@@ -113,17 +122,23 @@ namespace Game.Combat
return null;
}
public bool SetInCombatWith(Unit who, bool suppressPvpSecond = false)
public bool SetInCombatWith(Unit who, bool addSecondUnitSuppressed = false)
{
// Are we already in combat? If yes, refresh pvp combat
var pvpRefe = _pvpRefs.LookupByKey(who.GetGUID());
if (pvpRefe != null)
var existingPvpRef = _pvpRefs.LookupByKey(who.GetGUID());
if (existingPvpRef != null)
{
pvpRefe.Refresh();
existingPvpRef.RefreshTimer();
existingPvpRef.Refresh();
return true;
}
else if (_pveRefs.ContainsKey(who.GetGUID()))
var existingPveRef = _pveRefs.LookupByKey(who.GetGUID());
if (existingPveRef != null)
{
existingPveRef.Refresh();
return true;
}
// Otherwise, check validity...
if (!CanBeginCombat(_owner, who))
@@ -132,15 +147,13 @@ namespace Game.Combat
// ...then create new reference
CombatReference refe;
if (_owner.IsControlledByPlayer() && who.IsControlledByPlayer())
{
PvPCombatReference refPvp = new PvPCombatReference(_owner, who);
if (suppressPvpSecond)
refPvp.SuppressFor(who);
refe = refPvp;
}
refe = new PvPCombatReference(_owner, who);
else
refe = new CombatReference(_owner, who);
if (addSecondUnitSuppressed)
refe.Suppress(who);
// ...and insert it into both managers
PutReference(who.GetGUID(), refe);
who.GetCombatManager().PutReference(_owner.GetGUID(), refe);
@@ -324,13 +337,10 @@ namespace Game.Combat
return true;
}
Unit GetOwner() { return _owner; }
public Unit GetOwner() { return _owner; }
public bool HasCombat() { return HasPvECombat() || HasPvPCombat(); }
public bool HasPvECombat() { return !_pveRefs.Empty(); }
public Dictionary<ObjectGuid, CombatReference> GetPvECombatRefs() { return _pveRefs; }
public Dictionary<ObjectGuid, PvPCombatReference> GetPvPCombatRefs() { return _pvpRefs; }
@@ -347,6 +357,9 @@ namespace Game.Combat
public Unit first;
public Unit second;
public bool _isPvP;
bool _suppressFirst;
bool _suppressSecond;
public CombatReference(Unit a, Unit b, bool pvp = false)
{
@@ -386,31 +399,8 @@ namespace Game.Combat
}
}
public Unit GetOther(Unit me) { return (first == me) ? second : first; }
}
public class PvPCombatReference : CombatReference
{
public static uint PVP_COMBAT_TIMEOUT = 5 * Time.InMilliseconds;
uint _combatTimer = PVP_COMBAT_TIMEOUT;
bool _suppressFirst = false;
bool _suppressSecond = false;
public PvPCombatReference(Unit first, Unit second) : base(first, second, true) { }
public bool Update(uint tdiff)
{
if (_combatTimer <= tdiff)
return false;
_combatTimer -= tdiff;
return true;
}
public void Refresh()
{
_combatTimer = PVP_COMBAT_TIMEOUT;
bool needFirstAI = false, needSecondAI = false;
if (_suppressFirst)
{
@@ -451,5 +441,30 @@ namespace Game.Combat
else
_suppressSecond = true;
}
public Unit GetOther(Unit me) { return (first == me) ? second : first; }
}
public class PvPCombatReference : CombatReference
{
public static uint PVP_COMBAT_TIMEOUT = 5 * Time.InMilliseconds;
uint _combatTimer = PVP_COMBAT_TIMEOUT;
public PvPCombatReference(Unit first, Unit second) : base(first, second, true) { }
public bool Update(uint tdiff)
{
if (_combatTimer <= tdiff)
return false;
_combatTimer -= tdiff;
return true;
}
public void RefreshTimer()
{
_combatTimer = PVP_COMBAT_TIMEOUT;
}
}
}
+2 -2
View File
@@ -95,10 +95,10 @@ namespace Game.Entities
public bool IsPetInCombat() { return HasUnitFlag(UnitFlags.PetInCombat); }
public void SetInCombatWith(Unit enemy, bool suppressPvpTargetCombat = false)
public void SetInCombatWith(Unit enemy, bool addSecondUnitSuppressed = false)
{
if (enemy != null)
m_combatManager.SetInCombatWith(enemy, suppressPvpTargetCombat);
m_combatManager.SetInCombatWith(enemy, addSecondUnitSuppressed);
}
public void EngageWithTarget(Unit enemy)