Combat/Threat rewrite - prep & refactor
Port From (https://github.com/TrinityCore/TrinityCore/commit/8be23fcbbdf26e8169defd761e61765f301bebe0)
This commit is contained in:
@@ -125,7 +125,7 @@ namespace Game.Entities
|
||||
|
||||
public virtual void SetCanDualWield(bool value) { m_canDualWield = value; }
|
||||
|
||||
void SendClearThreatList()
|
||||
public void SendClearThreatList()
|
||||
{
|
||||
ThreatClear packet = new ThreatClear();
|
||||
packet.UnitGUID = GetGUID();
|
||||
@@ -158,13 +158,6 @@ namespace Game.Entities
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteThreatList()
|
||||
{
|
||||
if (CanHaveThreatList(true) && !threatManager.IsThreatListEmpty())
|
||||
SendClearThreatList();
|
||||
threatManager.ClearReferences();
|
||||
}
|
||||
|
||||
public void TauntApply(Unit taunter)
|
||||
{
|
||||
Cypher.Assert(IsTypeId(TypeId.Unit));
|
||||
@@ -325,12 +318,6 @@ namespace Game.Entities
|
||||
}
|
||||
public void RemoveHatedBy(HostileReference pHostileReference) { } //nothing to do yet
|
||||
|
||||
public void AddThreat(Unit victim, float fThreat, SpellSchoolMask schoolMask = SpellSchoolMask.Normal, SpellInfo threatSpell = null)
|
||||
{
|
||||
// Only mobs can manage threat lists
|
||||
if (CanHaveThreatList() && !HasUnitState(UnitState.Evade))
|
||||
threatManager.AddThreat(victim, fThreat, schoolMask, threatSpell);
|
||||
}
|
||||
public float ApplyTotalThreatModifier(float fThreat, SpellSchoolMask schoolMask = SpellSchoolMask.Normal)
|
||||
{
|
||||
if (!HasAuraType(AuraType.ModThreat) || fThreat < 0)
|
||||
@@ -360,6 +347,17 @@ namespace Game.Entities
|
||||
return m_deathState;
|
||||
}
|
||||
|
||||
public bool IsEngaged() { return IsInCombat(); }
|
||||
public bool IsEngagedBy(Unit who) { return IsInCombatWith(who); }
|
||||
public void EngageWithTarget(Unit who)
|
||||
{
|
||||
SetInCombatWith(who);
|
||||
who.SetInCombatWith(this);
|
||||
GetThreatManager().AddThreat(who, 0.0f);
|
||||
}
|
||||
public bool IsThreatened() { return CanHaveThreatList() && !GetThreatManager().IsThreatListEmpty(); }
|
||||
public bool IsThreatenedBy(Unit who) { return who != null && CanHaveThreatList() && GetThreatManager().IsThreatenedBy(who); }
|
||||
|
||||
public bool IsInCombat() { return HasUnitFlag(UnitFlags.InCombat); }
|
||||
public bool IsPetInCombat() { return HasUnitFlag(UnitFlags.PetInCombat); }
|
||||
|
||||
@@ -444,7 +442,7 @@ namespace Game.Entities
|
||||
if (creature != null && !IsPet())
|
||||
{
|
||||
// should not let player enter combat by right clicking target - doesn't helps
|
||||
AddThreat(victim, 0.0f);
|
||||
GetThreatManager().AddThreat(victim, 0.0f);
|
||||
SetInCombatWith(victim);
|
||||
|
||||
if (victim.IsTypeId(TypeId.Player))
|
||||
@@ -453,7 +451,7 @@ namespace Game.Entities
|
||||
Unit owner = victim.GetOwner();
|
||||
if (owner != null)
|
||||
{
|
||||
AddThreat(owner, 0.0f);
|
||||
GetThreatManager().AddThreat(owner, 0.0f);
|
||||
SetInCombatWith(owner);
|
||||
if (owner.GetTypeId() == TypeId.Player)
|
||||
owner.SetInCombatWith(this);
|
||||
@@ -553,6 +551,9 @@ namespace Game.Entities
|
||||
}
|
||||
public Unit GetAttackerForHelper()
|
||||
{
|
||||
if (!IsEngaged())
|
||||
return null;
|
||||
|
||||
Unit victim = GetVictim();
|
||||
if (victim != null)
|
||||
if ((!IsPet() && GetPlayerMovingMe() == null) || IsInCombatWith(victim) || victim.IsInCombatWith(this))
|
||||
@@ -1143,7 +1144,7 @@ namespace Game.Entities
|
||||
if (damagetype != DamageEffectType.DOT && damage > 0 && !victim.GetOwnerGUID().IsPlayer() && (spellProto == null || !spellProto.HasAura(AuraType.DamageShield)))
|
||||
victim.ToCreature().SetLastDamagedTime(GameTime.GetGameTime() + SharedConst.MaxAggroResetTime);
|
||||
|
||||
victim.AddThreat(this, damage, damageSchoolMask, spellProto);
|
||||
victim.GetThreatManager().AddThreat(this, damage, spellProto);
|
||||
}
|
||||
else // victim is a player
|
||||
{
|
||||
@@ -1338,11 +1339,12 @@ namespace Game.Entities
|
||||
SetInCombatWith(target);
|
||||
target.SetInCombatWith(this);
|
||||
}
|
||||
Unit who = target.GetCharmerOrOwnerOrSelf();
|
||||
if (who.IsTypeId(TypeId.Player))
|
||||
SetContestedPvP(who.ToPlayer());
|
||||
|
||||
Player me = GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
Unit who = target.GetCharmerOrOwnerOrSelf();
|
||||
if (me != null && who.IsTypeId(TypeId.Player))
|
||||
me.SetContestedPvP(who.ToPlayer());
|
||||
|
||||
if (me != null && who.IsPvP() && (!who.IsTypeId(TypeId.Player) || me.duel == null || me.duel.opponent != who))
|
||||
{
|
||||
me.UpdatePvP(true);
|
||||
@@ -1403,7 +1405,7 @@ namespace Game.Entities
|
||||
creature.GetAI().EnterCombat(enemy);
|
||||
|
||||
if (creature.GetFormation() != null)
|
||||
creature.GetFormation().MemberAttackStart(creature, enemy);
|
||||
creature.GetFormation().MemberEngagingTarget(creature, enemy);
|
||||
}
|
||||
|
||||
if (IsPet())
|
||||
@@ -1595,7 +1597,7 @@ namespace Game.Entities
|
||||
|
||||
if (!creature.IsPet())
|
||||
{
|
||||
creature.DeleteThreatList();
|
||||
creature.GetThreatManager().ClearAllThreat();
|
||||
|
||||
// must be after setDeathState which resets dynamic flags
|
||||
if (!creature.loot.IsLooted())
|
||||
@@ -1709,29 +1711,6 @@ namespace Game.Entities
|
||||
|
||||
public virtual uint GetBlockPercent() { return 30; }
|
||||
|
||||
public void SetContestedPvP(Player attackedPlayer = null)
|
||||
{
|
||||
Player player = GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
|
||||
if (player == null || (attackedPlayer != null && (attackedPlayer == player || (player.duel != null && player.duel.opponent == attackedPlayer))))
|
||||
return;
|
||||
|
||||
player.SetContestedPvPTimer(30000);
|
||||
if (!player.HasUnitState(UnitState.AttackPlayer))
|
||||
{
|
||||
player.AddUnitState(UnitState.AttackPlayer);
|
||||
player.AddPlayerFlag(PlayerFlags.ContestedPVP);
|
||||
// call MoveInLineOfSight for nearby contested guards
|
||||
UpdateObjectVisibility();
|
||||
}
|
||||
if (!HasUnitState(UnitState.AttackPlayer))
|
||||
{
|
||||
AddUnitState(UnitState.AttackPlayer);
|
||||
// call MoveInLineOfSight for nearby contested guards
|
||||
UpdateObjectVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateReactives(uint p_time)
|
||||
{
|
||||
for (ReactiveType reactive = 0; reactive < ReactiveType.Max; ++reactive)
|
||||
|
||||
@@ -313,7 +313,7 @@ namespace Game.Entities
|
||||
|
||||
CastStop();
|
||||
CombatStop(); // @todo CombatStop(true) may cause crash (interrupt spells)
|
||||
DeleteThreatList();
|
||||
GetThreatManager().ClearAllThreat();
|
||||
|
||||
Player playerCharmer = charmer.ToPlayer();
|
||||
|
||||
@@ -456,7 +456,7 @@ namespace Game.Entities
|
||||
CastStop();
|
||||
CombatStop(); // @todo CombatStop(true) may cause crash (interrupt spells)
|
||||
GetHostileRefManager().DeleteReferences();
|
||||
DeleteThreatList();
|
||||
GetThreatManager().ClearAllThreat();
|
||||
|
||||
if (_oldFactionId != 0)
|
||||
{
|
||||
|
||||
@@ -1508,14 +1508,19 @@ namespace Game.Entities
|
||||
}
|
||||
|
||||
public void EnergizeBySpell(Unit victim, uint spellId, int damage, PowerType powerType)
|
||||
{
|
||||
SpellInfo info = Global.SpellMgr.GetSpellInfo(spellId, GetMap().GetDifficultyID());
|
||||
if (info != null)
|
||||
EnergizeBySpell(victim, info, damage, powerType);
|
||||
}
|
||||
|
||||
void EnergizeBySpell(Unit victim, SpellInfo spellInfo, int damage, PowerType powerType)
|
||||
{
|
||||
int gain = victim.ModifyPower(powerType, damage);
|
||||
int overEnergize = damage - gain;
|
||||
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId, GetMap().GetDifficultyID());
|
||||
victim.GetHostileRefManager().ThreatAssist(this, damage * 0.5f, spellInfo);
|
||||
|
||||
SendEnergizeSpellLog(victim, spellId, damage, overEnergize, powerType);
|
||||
victim.GetThreatManager().ForwardThreatForAssistingMe(this, damage / 2, spellInfo, true);
|
||||
SendEnergizeSpellLog(victim, spellInfo.Id, damage, overEnergize, powerType);
|
||||
}
|
||||
|
||||
public void ApplySpellImmune(uint spellId, SpellImmunity op, SpellSchoolMask type, bool apply)
|
||||
|
||||
@@ -491,7 +491,7 @@ namespace Game.Entities
|
||||
|
||||
m_Events.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map.RemoveAllObjectsInRemoveList
|
||||
CombatStop();
|
||||
DeleteThreatList();
|
||||
GetThreatManager().ClearAllThreat();
|
||||
GetHostileRefManager().DeleteReferences();
|
||||
}
|
||||
public override void CleanupsBeforeDelete(bool finalCleanup = true)
|
||||
@@ -1609,7 +1609,7 @@ namespace Game.Entities
|
||||
if (s != DeathState.Alive && s != DeathState.JustRespawned)
|
||||
{
|
||||
CombatStop();
|
||||
DeleteThreatList();
|
||||
GetThreatManager().ClearAllThreat();
|
||||
GetHostileRefManager().DeleteReferences();
|
||||
|
||||
if (IsNonMeleeSpellCast(false))
|
||||
|
||||
Reference in New Issue
Block a user