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() public bool HasPvECombatWithPlayers()
{ {
foreach (var reference in _pveRefs) foreach (var reference in _pveRefs)
if (reference.Value.GetOther(_owner).IsPlayer()) if (!reference.Value.IsSuppressedFor(_owner) && reference.Value.GetOther(_owner).IsPlayer())
return true; return true;
return false; return false;
@@ -103,8 +111,9 @@ namespace Game.Combat
public Unit GetAnyTarget() public Unit GetAnyTarget()
{ {
if (!_pveRefs.Empty()) foreach (var pair in _pveRefs)
return _pveRefs.First().Value.GetOther(_owner); if (!pair.Value.IsSuppressedFor(_owner))
return pair.Value.GetOther(_owner);
foreach (var pair in _pvpRefs) foreach (var pair in _pvpRefs)
if (!pair.Value.IsSuppressedFor(_owner)) if (!pair.Value.IsSuppressedFor(_owner))
@@ -113,17 +122,23 @@ namespace Game.Combat
return null; 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 // Are we already in combat? If yes, refresh pvp combat
var pvpRefe = _pvpRefs.LookupByKey(who.GetGUID()); var existingPvpRef = _pvpRefs.LookupByKey(who.GetGUID());
if (pvpRefe != null) if (existingPvpRef != null)
{ {
pvpRefe.Refresh(); existingPvpRef.RefreshTimer();
existingPvpRef.Refresh();
return true; return true;
} }
else if (_pveRefs.ContainsKey(who.GetGUID()))
var existingPveRef = _pveRefs.LookupByKey(who.GetGUID());
if (existingPveRef != null)
{
existingPveRef.Refresh();
return true; return true;
}
// Otherwise, check validity... // Otherwise, check validity...
if (!CanBeginCombat(_owner, who)) if (!CanBeginCombat(_owner, who))
@@ -132,15 +147,13 @@ namespace Game.Combat
// ...then create new reference // ...then create new reference
CombatReference refe; CombatReference refe;
if (_owner.IsControlledByPlayer() && who.IsControlledByPlayer()) if (_owner.IsControlledByPlayer() && who.IsControlledByPlayer())
{ refe = new PvPCombatReference(_owner, who);
PvPCombatReference refPvp = new PvPCombatReference(_owner, who);
if (suppressPvpSecond)
refPvp.SuppressFor(who);
refe = refPvp;
}
else else
refe = new CombatReference(_owner, who); refe = new CombatReference(_owner, who);
if (addSecondUnitSuppressed)
refe.Suppress(who);
// ...and insert it into both managers // ...and insert it into both managers
PutReference(who.GetGUID(), refe); PutReference(who.GetGUID(), refe);
who.GetCombatManager().PutReference(_owner.GetGUID(), refe); who.GetCombatManager().PutReference(_owner.GetGUID(), refe);
@@ -324,13 +337,10 @@ namespace Game.Combat
return true; return true;
} }
public Unit GetOwner() { return _owner; }
Unit GetOwner() { return _owner; }
public bool HasCombat() { return HasPvECombat() || HasPvPCombat(); } public bool HasCombat() { return HasPvECombat() || HasPvPCombat(); }
public bool HasPvECombat() { return !_pveRefs.Empty(); }
public Dictionary<ObjectGuid, CombatReference> GetPvECombatRefs() { return _pveRefs; } public Dictionary<ObjectGuid, CombatReference> GetPvECombatRefs() { return _pveRefs; }
public Dictionary<ObjectGuid, PvPCombatReference> GetPvPCombatRefs() { return _pvpRefs; } public Dictionary<ObjectGuid, PvPCombatReference> GetPvPCombatRefs() { return _pvpRefs; }
@@ -347,6 +357,9 @@ namespace Game.Combat
public Unit first; public Unit first;
public Unit second; public Unit second;
public bool _isPvP; public bool _isPvP;
bool _suppressFirst;
bool _suppressSecond;
public CombatReference(Unit a, Unit b, bool pvp = false) 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() public void Refresh()
{ {
_combatTimer = PVP_COMBAT_TIMEOUT;
bool needFirstAI = false, needSecondAI = false; bool needFirstAI = false, needSecondAI = false;
if (_suppressFirst) if (_suppressFirst)
{ {
@@ -451,5 +441,30 @@ namespace Game.Combat
else else
_suppressSecond = true; _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 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) if (enemy != null)
m_combatManager.SetInCombatWith(enemy, suppressPvpTargetCombat); m_combatManager.SetInCombatWith(enemy, addSecondUnitSuppressed);
} }
public void EngageWithTarget(Unit enemy) public void EngageWithTarget(Unit enemy)