mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-22 21:26:23 +00:00
fix(Core/AI): Improve creature leashing behavior. (#19751)
* Init. https: //github.com/vmangos/core/commit/7d2f1e2923734ea1b983eeaa0208cfd158d4af02 Co-Authored-By: ratkosrb <35845488+ratkosrb@users.noreply.github.com> * Hackfix for pets. * Whoops. * Correct evade uses. * Conflict. * Actually fix grace timer. * Add visibility distance check. Creatures should always fail combat checks in the open world if they're outside of visibility distance, might not be the case for worldbosses. --------- Co-authored-by: ratkosrb <35845488+ratkosrb@users.noreply.github.com>
This commit is contained in:
@@ -220,9 +220,6 @@ bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
|
||||
{
|
||||
if (Unit* victim = ObjectAccessor::GetUnit(*m_owner, m_victim))
|
||||
{
|
||||
// Initialize last damage timer if it doesn't exist
|
||||
m_owner->SetLastDamagedTime(GameTime::GetGameTime().count() + MAX_AGGRO_RESET_TIME);
|
||||
|
||||
while (!m_assistants.empty())
|
||||
{
|
||||
Creature* assistant = ObjectAccessor::GetCreature(*m_owner, *m_assistants.begin());
|
||||
@@ -233,9 +230,14 @@ bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
|
||||
assistant->SetNoCallAssistance(true);
|
||||
assistant->CombatStart(victim);
|
||||
if (assistant->IsAIEnabled)
|
||||
{
|
||||
assistant->AI()->AttackStart(victim);
|
||||
|
||||
assistant->SetLastDamagedTimePtr(m_owner->GetLastDamagedTimePtr());
|
||||
// When nearby mobs aggro from another mob's initial call for assistance
|
||||
// their leash timers become linked and attacking one will keep the rest from evading.
|
||||
if (assistant->GetVictim())
|
||||
assistant->SetLastLeashExtensionTimePtr(m_owner->GetLastLeashExtensionTimePtr());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,7 +274,7 @@ Creature::Creature(bool isWorldObject): Unit(isWorldObject), MovableMapObject(),
|
||||
m_transportCheckTimer(1000), lootPickPocketRestoreTime(0), m_combatPulseTime(0), m_combatPulseDelay(0), m_reactState(REACT_AGGRESSIVE), m_defaultMovementType(IDLE_MOTION_TYPE),
|
||||
m_spawnId(0), m_equipmentId(0), m_originalEquipmentId(0), m_AlreadyCallAssistance(false),
|
||||
m_AlreadySearchedAssistance(false), m_regenHealth(true), m_regenPower(true), m_AI_locked(false), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), m_originalEntry(0), m_moveInLineOfSightDisabled(false), m_moveInLineOfSightStrictlyDisabled(false),
|
||||
m_homePosition(), m_transportHomePosition(), m_creatureInfo(nullptr), m_creatureData(nullptr), m_detectionDistance(20.0f), m_waypointID(0), m_path_id(0), m_formation(nullptr), _lastDamagedTime(nullptr), m_cannotReachTimer(0),
|
||||
m_homePosition(), m_transportHomePosition(), m_creatureInfo(nullptr), m_creatureData(nullptr), m_detectionDistance(20.0f), m_waypointID(0), m_path_id(0), m_formation(nullptr), m_lastLeashExtensionTime(nullptr), m_cannotReachTimer(0),
|
||||
_isMissingSwimmingFlagOutOfCombat(false), m_assistanceTimer(0), _playerDamageReq(0), _damagedByPlayer(false), _isCombatMovementAllowed(true)
|
||||
{
|
||||
m_regenTimer = CREATURE_REGEN_INTERVAL;
|
||||
@@ -1961,8 +1963,6 @@ void Creature::setDeathState(DeathState state, bool despawn)
|
||||
|
||||
if (state == DeathState::JustDied)
|
||||
{
|
||||
_lastDamagedTime.reset();
|
||||
|
||||
m_corpseRemoveTime = GameTime::GetGameTime().count() + m_corpseDelay;
|
||||
m_respawnTime = GameTime::GetGameTime().count() + m_respawnDelay + m_corpseDelay;
|
||||
|
||||
@@ -2640,7 +2640,7 @@ bool Creature::CanCreatureAttack(Unit const* victim, bool skipDistCheck) const
|
||||
return false;
|
||||
|
||||
// cannot attack if is during 5 second grace period, unless being attacked
|
||||
if (m_respawnedTime && (GameTime::GetGameTime().count() - m_respawnedTime) < 5 && !GetLastDamagedTime())
|
||||
if (m_respawnedTime && (GameTime::GetGameTime().count() - m_respawnedTime) < 5 && !IsEngagedBy(victim))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -2656,9 +2656,15 @@ bool Creature::CanCreatureAttack(Unit const* victim, bool skipDistCheck) const
|
||||
if (GetMap()->IsDungeon())
|
||||
return true;
|
||||
|
||||
float visibility = std::max<float>(GetVisibilityRange(), victim->GetVisibilityRange());
|
||||
|
||||
// if outside visibility
|
||||
if (!IsWithinDist(victim, visibility))
|
||||
return false;
|
||||
|
||||
// pussywizard: don't check distance to home position if recently damaged (allow kiting away from spawnpoint!)
|
||||
// xinef: this should include taunt auras
|
||||
if (!isWorldBoss() && (GetLastDamagedTime() > GameTime::GetGameTime().count() || HasAuraType(SPELL_AURA_MOD_TAUNT)))
|
||||
if (!isWorldBoss() && (GetLastLeashExtensionTime() + 12 > GameTime::GetGameTime().count() || HasAuraType(SPELL_AURA_MOD_TAUNT)))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2666,10 +2672,13 @@ bool Creature::CanCreatureAttack(Unit const* victim, bool skipDistCheck) const
|
||||
return true;
|
||||
|
||||
// xinef: added size factor for huge npcs
|
||||
float dist = std::min<float>(GetMap()->GetVisibilityRange() + GetObjectSize() * 2, 150.0f);
|
||||
float dist = std::min<float>(GetDetectionRange() + GetObjectSize() * 2, 150.0f);
|
||||
|
||||
if (Unit* unit = GetCharmerOrOwner())
|
||||
{
|
||||
dist = std::min<float>(GetMap()->GetVisibilityRange() + GetObjectSize() * 2, 150.0f);
|
||||
return victim->IsWithinDist(unit, dist);
|
||||
}
|
||||
else
|
||||
{
|
||||
// to prevent creatures in air ignore attacks because distance is already too high...
|
||||
@@ -3666,35 +3675,31 @@ bool Creature::IsNotReachableAndNeedRegen() const
|
||||
return false;
|
||||
}
|
||||
|
||||
time_t Creature::GetLastDamagedTime() const
|
||||
std::shared_ptr<time_t> const& Creature::GetLastLeashExtensionTimePtr() const
|
||||
{
|
||||
if (!_lastDamagedTime)
|
||||
return time_t(0);
|
||||
|
||||
return *_lastDamagedTime;
|
||||
if (m_lastLeashExtensionTime == nullptr)
|
||||
m_lastLeashExtensionTime = std::make_shared<time_t>(time(nullptr));
|
||||
return m_lastLeashExtensionTime;
|
||||
}
|
||||
|
||||
std::shared_ptr<time_t> const& Creature::GetLastDamagedTimePtr() const
|
||||
void Creature::SetLastLeashExtensionTimePtr(std::shared_ptr<time_t> const& timer)
|
||||
{
|
||||
return _lastDamagedTime;
|
||||
m_lastLeashExtensionTime = timer;
|
||||
}
|
||||
|
||||
void Creature::SetLastDamagedTime(time_t val)
|
||||
void Creature::ClearLastLeashExtensionTimePtr()
|
||||
{
|
||||
if (val > 0)
|
||||
{
|
||||
if (_lastDamagedTime)
|
||||
*_lastDamagedTime = val;
|
||||
else
|
||||
_lastDamagedTime = std::make_shared<time_t>(val);
|
||||
}
|
||||
else
|
||||
_lastDamagedTime.reset();
|
||||
m_lastLeashExtensionTime.reset();
|
||||
}
|
||||
|
||||
void Creature::SetLastDamagedTimePtr(std::shared_ptr<time_t> const& val)
|
||||
time_t Creature::GetLastLeashExtensionTime() const
|
||||
{
|
||||
_lastDamagedTime = val;
|
||||
return *GetLastLeashExtensionTimePtr();
|
||||
}
|
||||
|
||||
void Creature::UpdateLeashExtensionTime()
|
||||
{
|
||||
(*GetLastLeashExtensionTimePtr()) = time(nullptr);
|
||||
}
|
||||
|
||||
bool Creature::CanPeriodicallyCallForAssistance() const
|
||||
|
||||
Reference in New Issue
Block a user