Core/Creature: Implement aggro grace period
Port From (https://github.com/TrinityCore/TrinityCore/commit/26d1337461114506ca57e2265d3dc5e96fd08f82)
This commit is contained in:
@@ -102,7 +102,7 @@ namespace Game.AI
|
|||||||
if (me.IsEngaged())
|
if (me.IsEngaged())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (me.HasReactState(ReactStates.Aggressive) && me.CanStartAttack(who, false))
|
if (me.HasReactState(ReactStates.Aggressive) && me.CanStartAttack(who, false) && (me.IsAggroGracePeriodExpired() || me.GetMap().Instanceable()))
|
||||||
me.EngageWithTarget(who);
|
me.EngageWithTarget(who);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ namespace Game.Entities
|
|||||||
bool triggerJustAppeared;
|
bool triggerJustAppeared;
|
||||||
bool m_respawnCompatibilityMode;
|
bool m_respawnCompatibilityMode;
|
||||||
|
|
||||||
|
bool _aggroGracePeriodExpired;
|
||||||
|
|
||||||
public uint[] m_spells = new uint[SharedConst.MaxCreatureSpells];
|
public uint[] m_spells = new uint[SharedConst.MaxCreatureSpells];
|
||||||
|
|
||||||
// Timers
|
// Timers
|
||||||
|
|||||||
@@ -638,6 +638,16 @@ namespace Game.Entities
|
|||||||
|
|
||||||
// Creatures with CREATURE_STATIC_FLAG_2_FORCE_PARTY_MEMBERS_INTO_COMBAT periodically force party members into combat
|
// Creatures with CREATURE_STATIC_FLAG_2_FORCE_PARTY_MEMBERS_INTO_COMBAT periodically force party members into combat
|
||||||
ForcePartyMembersIntoCombat();
|
ForcePartyMembersIntoCombat();
|
||||||
|
|
||||||
|
// creatures should only attack surroundings initially after heartbeat has passed or until attacked
|
||||||
|
if (!_aggroGracePeriodExpired)
|
||||||
|
{
|
||||||
|
_aggroGracePeriodExpired = true;
|
||||||
|
|
||||||
|
// trigger MoveInLineOfSight
|
||||||
|
CreatureAggroGracePeriodExpiredNotifier notifier = new(this);
|
||||||
|
Cell.VisitAllObjects(this, notifier, GetVisibilityRange());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Regenerate(PowerType power)
|
public void Regenerate(PowerType power)
|
||||||
@@ -1080,6 +1090,8 @@ namespace Game.Entities
|
|||||||
{
|
{
|
||||||
base.AtEngage(target);
|
base.AtEngage(target);
|
||||||
|
|
||||||
|
_aggroGracePeriodExpired = true;
|
||||||
|
|
||||||
GetThreatManager().ResetUpdateTimer();
|
GetThreatManager().ResetUpdateTimer();
|
||||||
|
|
||||||
if (!HasFlag(CreatureStaticFlags2.AllowMountedCombat))
|
if (!HasFlag(CreatureStaticFlags2.AllowMountedCombat))
|
||||||
@@ -1680,6 +1692,8 @@ namespace Game.Entities
|
|||||||
|
|
||||||
void SetInteractSpellId(int interactSpellId) { SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.InteractSpellID), interactSpellId); }
|
void SetInteractSpellId(int interactSpellId) { SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.InteractSpellID), interactSpellId); }
|
||||||
|
|
||||||
|
public bool IsAggroGracePeriodExpired() { return _aggroGracePeriodExpired; }
|
||||||
|
|
||||||
public void OverrideSparringHealthPct(List<float> healthPct)
|
public void OverrideSparringHealthPct(List<float> healthPct)
|
||||||
{
|
{
|
||||||
_sparringHealthPct = healthPct.SelectRandom();
|
_sparringHealthPct = healthPct.SelectRandom();
|
||||||
@@ -2148,6 +2162,7 @@ namespace Game.Entities
|
|||||||
ai.Reset();
|
ai.Reset();
|
||||||
|
|
||||||
triggerJustAppeared = true;
|
triggerJustAppeared = true;
|
||||||
|
_aggroGracePeriodExpired = false;
|
||||||
|
|
||||||
uint poolid = GetCreatureData() != null ? GetCreatureData().poolId : 0;
|
uint poolid = GetCreatureData() != null ? GetCreatureData().poolId : 0;
|
||||||
if (poolid != 0)
|
if (poolid != 0)
|
||||||
|
|||||||
@@ -360,6 +360,31 @@ namespace Game.Maps
|
|||||||
bool isCreature;
|
bool isCreature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class CreatureAggroGracePeriodExpiredNotifier : Notifier
|
||||||
|
{
|
||||||
|
Creature i_creature;
|
||||||
|
|
||||||
|
public CreatureAggroGracePeriodExpiredNotifier(Creature c)
|
||||||
|
{
|
||||||
|
i_creature = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Visit(IList<Creature> objs)
|
||||||
|
{
|
||||||
|
foreach (var creature in objs)
|
||||||
|
{
|
||||||
|
CreatureUnitRelocationWorker(creature, i_creature);
|
||||||
|
CreatureUnitRelocationWorker(i_creature, creature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Visit(IList<Player> objs)
|
||||||
|
{
|
||||||
|
foreach (var player in objs)
|
||||||
|
CreatureUnitRelocationWorker(i_creature, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class PacketSenderRef : IDoWork<Player>
|
public class PacketSenderRef : IDoWork<Player>
|
||||||
{
|
{
|
||||||
ServerPacket Data;
|
ServerPacket Data;
|
||||||
|
|||||||
Reference in New Issue
Block a user