Core/Creature: Implement aggro grace period

Port From (https://github.com/TrinityCore/TrinityCore/commit/26d1337461114506ca57e2265d3dc5e96fd08f82)
This commit is contained in:
Hondacrx
2025-05-25 10:39:42 -04:00
parent de59110fe8
commit 1ea98d4f51
4 changed files with 43 additions and 1 deletions
+1 -1
View File
@@ -102,7 +102,7 @@ namespace Game.AI
if (me.IsEngaged())
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);
}
@@ -69,6 +69,8 @@ namespace Game.Entities
bool triggerJustAppeared;
bool m_respawnCompatibilityMode;
bool _aggroGracePeriodExpired;
public uint[] m_spells = new uint[SharedConst.MaxCreatureSpells];
// Timers
+15
View File
@@ -638,6 +638,16 @@ namespace Game.Entities
// Creatures with CREATURE_STATIC_FLAG_2_FORCE_PARTY_MEMBERS_INTO_COMBAT periodically force party members into combat
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)
@@ -1080,6 +1090,8 @@ namespace Game.Entities
{
base.AtEngage(target);
_aggroGracePeriodExpired = true;
GetThreatManager().ResetUpdateTimer();
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); }
public bool IsAggroGracePeriodExpired() { return _aggroGracePeriodExpired; }
public void OverrideSparringHealthPct(List<float> healthPct)
{
_sparringHealthPct = healthPct.SelectRandom();
@@ -2148,6 +2162,7 @@ namespace Game.Entities
ai.Reset();
triggerJustAppeared = true;
_aggroGracePeriodExpired = false;
uint poolid = GetCreatureData() != null ? GetCreatureData().poolId : 0;
if (poolid != 0)
+25
View File
@@ -360,6 +360,31 @@ namespace Game.Maps
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>
{
ServerPacket Data;