Core: Combat/threat system rewrite

Port From (https://github.com/TrinityCore/TrinityCore/commit/34c7810fe507eca1b8b9389630db5d5d26d92e77)
This commit is contained in:
hondacrx
2021-05-18 12:25:40 -04:00
parent 891c3b6478
commit 9851142796
37 changed files with 3454 additions and 3345 deletions
+7 -38
View File
@@ -76,21 +76,13 @@ namespace Scripts.Pets
continue;
}
// else compare best fit unit with current unit
var triggers = unit.GetThreatManager().GetThreatList();
foreach (var reference in triggers)
float threat = unit.GetThreatManager().GetThreat(owner);
// Check if best fit hostile unit hs lower threat than this current unit
if (highestThreat < threat)
{
// Try to find threat referenced to owner
if (reference.GetTarget() == owner)
{
// Check if best fit hostile unit hs lower threat than this current unit
if (highestThreat < reference.GetThreat())
{
// If so, update best fit unit
highestThreat = reference.GetThreat();
highestThreatUnit = unit;
break;
}
}
// If so, update best fit unit
highestThreat = threat;
highestThreatUnit = unit;
}
// In case no unit with threat was found so far, always check for nearest unit (only for players)
if (unit.IsTypeId(TypeId.Player))
@@ -112,30 +104,7 @@ namespace Scripts.Pets
bool IsInThreatList(Unit target)
{
Unit owner = me.GetCharmerOrOwner();
List<Unit> targets = new List<Unit>();
var u_check = new AnyUnfriendlyUnitInObjectRangeCheck(me, me, 30.0f);
var searcher = new UnitListSearcher(me, targets, u_check);
Cell.VisitAllObjects(me, searcher, 40.0f);
foreach (var unit in targets)
{
if (unit == target)
{
// Consider only units without CC
if (!unit.HasBreakableByDamageCrowdControlAura(unit))
{
var triggers = unit.GetThreatManager().GetThreatList();
foreach (var reference in triggers)
{
// Try to find threat referenced to owner
if (reference.GetTarget() == owner)
return true;
}
}
}
}
return false;
return owner && target.IsThreatenedBy(owner);
}
public override void InitializeAI()
+1 -1
View File
@@ -2179,7 +2179,7 @@ namespace Scripts.Spells.Generic
if (mana != 0)
{
mana /= 10;
caster.EnergizeBySpell(caster, GetId(), mana, PowerType.Mana);
caster.EnergizeBySpell(caster, GetSpellInfo(), mana, PowerType.Mana);
}
}
+3 -8
View File
@@ -33,6 +33,7 @@ namespace Scripts.Spells.Hunter
public const uint ExhilarationR2 = 231546;
public const uint Lonewolf = 155228;
public const uint MastersCallTriggered = 62305;
public const uint Misdirection = 34477;
public const uint MisdirectionProc = 35079;
public const uint PetLastStandTriggered = 53479;
public const uint PetHeartOfThePhoenixTriggered = 54114;
@@ -205,12 +206,7 @@ namespace Scripts.Spells.Hunter
return;
if (!GetTarget().HasAura(SpellIds.MisdirectionProc))
GetTarget().ResetRedirectThreat();
}
bool CheckProc(ProcEventInfo eventInfo)
{
return GetTarget().GetRedirectThreatTarget();
GetTarget().GetThreatManager().UnregisterRedirectThreat(SpellIds.Misdirection);
}
void HandleProc(AuraEffect aurEff, ProcEventInfo eventInfo)
@@ -222,7 +218,6 @@ namespace Scripts.Spells.Hunter
public override void Register()
{
AfterEffectRemove.Add(new EffectApplyHandler(OnRemove, 1, AuraType.Dummy, AuraEffectHandleModes.Real));
DoCheckProc.Add(new CheckProcHandler(CheckProc));
OnEffectProc.Add(new EffectProcHandler(HandleProc, 1, AuraType.Dummy));
}
}
@@ -233,7 +228,7 @@ namespace Scripts.Spells.Hunter
{
void OnRemove(AuraEffect aurEff, AuraEffectHandleModes mode)
{
GetTarget().ResetRedirectThreat();
GetTarget().GetThreatManager().UnregisterRedirectThreat(SpellIds.Misdirection);
}
public override void Register()
+10 -4
View File
@@ -1550,18 +1550,24 @@ namespace Scripts.World.NpcSpecial
_scheduler.Schedule(TimeSpan.FromSeconds(1), task =>
{
long now = GameTime.GetGameTime();
foreach (var pair in _damageTimes.ToList())
var pveRefs = me.GetCombatManager().GetPvECombatRefs();
foreach (var pair in _damageTimes)
{
// If unit has not dealt damage to training dummy for 5 seconds, Remove him from combat
if (pair.Value < now - 5)
{
Unit unit = Global.ObjAccessor.GetUnit(me, pair.Key);
if (unit)
unit.GetHostileRefManager().DeleteReference(me);
var refe = pveRefs.LookupByKey(pair.Key);
if (refe != null)
refe.EndCombat();
_damageTimes.Remove(pair.Key);
}
}
foreach (var pair in pveRefs)
if (!_damageTimes.ContainsKey(pair.Key))
_damageTimes[pair.Key] = now;
task.Repeat();
});
}