Combat/Threat rewrite - prep & refactor

Port From (https://github.com/TrinityCore/TrinityCore/commit/8be23fcbbdf26e8169defd761e61765f301bebe0)
This commit is contained in:
hondacrx
2020-08-22 11:58:19 -04:00
parent 67bacbb731
commit 193ad3a48d
42 changed files with 533 additions and 421 deletions
+80 -34
View File
@@ -111,6 +111,85 @@ namespace Game.AI
source.PlayDirectSound(soundId);
}
/// <summary>
/// Add specified amount of threat directly to victim (ignores redirection effects) - also puts victim in combat and engages them if necessary
/// </summary>
/// <param name="victim"></param>
/// <param name="amount"></param>
/// <param name="who"></param>
public void AddThreat(Unit victim, float amount, Unit who = null)
{
if (!victim)
return;
if (!who)
who = me;
who.GetThreatManager().AddThreat(victim, amount, null, true, true);
}
/// <summary>
/// Adds/removes the specified percentage from the specified victim's threat (to who, or me if not specified)
/// </summary>
/// <param name="victim"></param>
/// <param name="pct"></param>
/// <param name="who"></param>
public void ModifyThreatByPercent(Unit victim, int pct, Unit who = null)
{
if (!victim)
return;
if (!who)
who = me;
who.GetThreatManager().ModifyThreatByPercent(victim, pct);
}
/// <summary>
/// Resets the victim's threat level to who (or me if not specified) to zero
/// </summary>
/// <param name="victim"></param>
/// <param name="who"></param>
void ResetThreat(Unit victim, Unit who)
{
if (!victim)
return;
if (!who)
who = me;
who.GetThreatManager().ResetThreat(victim);
}
/// <summary>
/// Resets the specified unit's threat list (me if not specified) - does not delete entries, just sets their threat to zero
/// </summary>
/// <param name="who"></param>
public void ResetThreatList(Unit who = null)
{
if (!who)
who = me;
who.GetThreatManager().ResetAllThreat();
}
/// <summary>
/// Returns the threat level of victim towards who (or me if not specified)
/// </summary>
/// <param name="victim"></param>
/// <param name="who"></param>
/// <returns></returns>
public float GetThreat(Unit victim, Unit who = null)
{
if (!victim)
return 0.0f;
if (!who)
who = me;
return who.GetThreatManager().GetThreat(victim);
}
//Spawns a creature relative to me
public Creature DoSpawnCreature(uint entry, float offsetX, float offsetY, float offsetZ, float angle, TempSummonType type, uint despawntime)
{
@@ -182,39 +261,6 @@ namespace Game.AI
return apSpell[RandomHelper.IRand(0, (int)(spellCount - 1))];
}
//Drops all threat to 0%. Does not remove players from the threat list
public void DoResetThreat()
{
if (!me.CanHaveThreatList() || me.GetThreatManager().IsThreatListEmpty())
{
Log.outError(LogFilter.Scripts, "DoResetThreat called for creature that either cannot have threat list or has empty threat list (me entry = {0})", me.GetEntry());
return;
}
var threatlist = me.GetThreatManager().GetThreatList();
foreach (var refe in threatlist)
{
Unit unit = Global.ObjAccessor.GetUnit(me, refe.GetUnitGuid());
if (unit != null && DoGetThreat(unit) != 0)
DoModifyThreatPercent(unit, -100);
}
}
public float DoGetThreat(Unit unit)
{
if (unit == null)
return 0.0f;
return me.GetThreatManager().GetThreat(unit);
}
public void DoModifyThreatPercent(Unit unit, int pct)
{
if (unit == null)
return;
me.GetThreatManager().ModifyThreatPercent(unit, pct);
}
void DoTeleportTo(float x, float y, float z, uint time = 0)
{
me.Relocate(x, y, z);
@@ -499,7 +545,7 @@ namespace Game.AI
public override void JustSummoned(Creature summon)
{
summons.Summon(summon);
if (me.IsInCombat())
if (me.IsEngaged())
DoZoneInCombat(summon);
}
+3 -21
View File
@@ -88,8 +88,7 @@ namespace Game.AI
}
else
{
who.SetInCombatWith(me);
me.AddThreat(who, 0.0f);
me.EngageWithTarget(who);
return true;
}
}
@@ -111,24 +110,7 @@ namespace Game.AI
{
float fAttackRadius = me.GetAttackDistance(who);
if (me.IsWithinDistInMap(who, fAttackRadius) && me.IsWithinLOSInMap(who))
{
if (!me.GetVictim())
{
// Clear distracted state on combat
if (me.HasUnitState(UnitState.Distracted))
{
me.ClearUnitState(UnitState.Distracted);
me.GetMotionMaster().Clear();
}
AttackStart(who);
}
else if (me.GetMap().IsDungeon())
{
who.SetInCombatWith(me);
me.AddThreat(who, 0.0f);
}
}
me.EngageWithTarget(who);
}
}
}
@@ -181,7 +163,7 @@ namespace Game.AI
public override void EnterEvadeMode(EvadeReason why = EvadeReason.Other)
{
me.RemoveAllAuras();
me.DeleteThreatList();
me.GetThreatManager().ClearAllThreat();
me.CombatStop(true);
me.SetLootRecipient(null);
@@ -49,9 +49,7 @@ namespace Game.AI
if (me.Attack(who, true))
{
me.AddThreat(who, 0.0f);
me.SetInCombatWith(who);
who.SetInCombatWith(me);
me.EngageWithTarget(who); // in case it doesn't have threat+combat yet
if (me.HasUnitState(UnitState.Follow))
me.ClearUnitState(UnitState.Follow);
@@ -84,18 +82,8 @@ namespace Game.AI
//too far away and no free sight?
if (me.IsWithinDistInMap(who, 100.0f) && me.IsWithinLOSInMap(who))
{
//already fighting someone?
if (!me.GetVictim())
{
AttackStart(who);
return true;
}
else
{
who.SetInCombatWith(me);
me.AddThreat(who, 0.0f);
return true;
}
me.EngageWithTarget(who);
return true;
}
return false;
@@ -128,10 +116,7 @@ namespace Game.AI
AttackStart(who);
}
else if (me.GetMap().IsDungeon())
{
who.SetInCombatWith(me);
me.AddThreat(who, 0.0f);
}
me.EngageWithTarget(who);
}
}
}
@@ -178,7 +163,7 @@ namespace Game.AI
public override void EnterEvadeMode(EvadeReason why)
{
me.RemoveAllAuras();
me.DeleteThreatList();
me.GetThreatManager().ClearAllThreat();
me.CombatStop(true);
me.SetLootRecipient(null);