feat(Core/Movement): Improved pathfinding, collisions and movements (#4220)
Npc positioning Implemented slope check to avoid unwanted climbing for some kind of movements (backwards, repositioning etc.) Implemented backwards movement Re-implemented circle repositioning algorithm (smartest than retail, but with the same feeling) Fixed random position of summoned minions Improved pet following movement. Also, they attack NPC from behind now. Thanks to @Footman Swimming creatures Fixed max_z coordinate for swimming creatures. Now only part of their body is allowed to be out of the water level Fixed pathfinder for swimming creatures creating shortcuts for specific segments, now they swim underwater to reach the seashore instead of flying above the water level. Creatures with water InhabitType but no swimming flag now, when not in combat, will walk on water depth instead of swimming. Thanks @jackpoz for the original code UNIT_FLAG_SWIMMING in UpdateEnvironmentIfNeeded to show the swimming animation correctly when underwater Implemented HasEnoughWater check to avoid swimming creatures to go where the water level is too low but also to properly enable swimming animation only when a creature has enough water to swim. Walking creatures Extended the DetourNavMeshQuery adding area cost based on walkability (slope angle + source height) to find better paths at runtime instead of completely remove them from mmaps improve Z height in certain conditions (see #4205, #4203, #4247 ) Flying creatures Rewriting of the hover system Removed hacks and improved the UpdateEnvironmentIfNeeded. Now creatures can properly switch from flying to walk etc. Spells LOS on spell effect must be calculated on CollisionHeight and HitSpherePoint instead of position coords. Improved position for object/creature spawned via spells Improved checks for Fleeing movements (fear spells) Other improvements Implemented method to calculate the CollisionWidth from dbc (used by repositioning algorithm etc.) Improved raycast and collision checks Co-authored-by: Footman <p.alexej@freenet.de> Co-authored-by: Helias <stefanoborzi32@gmail.com> Co-authored-by: Francesco Borzì <borzifrancesco@gmail.com> Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
@@ -51,9 +51,6 @@ bool PetAI::_needToStop()
|
||||
if (!me->_CanDetectFeignDeathOf(me->GetVictim()))
|
||||
return true;
|
||||
|
||||
if (me->isTargetNotAcceptableByMMaps(me->GetVictim()->GetGUID(), sWorld->GetGameTime(), me->GetVictim()))
|
||||
return true;
|
||||
|
||||
return !me->CanCreatureAttack(me->GetVictim());
|
||||
}
|
||||
|
||||
@@ -338,6 +335,12 @@ void PetAI::UpdateAI(uint32 diff)
|
||||
for (TargetSpellList::const_iterator itr = targetSpellStore.begin(); itr != targetSpellStore.end(); ++itr)
|
||||
delete itr->second;
|
||||
}
|
||||
|
||||
|
||||
// Update speed as needed to prevent dropping too far behind and despawning
|
||||
me->UpdateSpeed(MOVE_RUN, true);
|
||||
me->UpdateSpeed(MOVE_WALK, true);
|
||||
me->UpdateSpeed(MOVE_FLIGHT, true);
|
||||
}
|
||||
|
||||
void PetAI::UpdateAllies()
|
||||
@@ -470,7 +473,7 @@ Unit* PetAI::SelectNextTarget(bool allowAutoSelect) const
|
||||
|
||||
// Check pet attackers first so we don't drag a bunch of targets to the owner
|
||||
if (Unit* myAttacker = me->getAttackerForHelper())
|
||||
if (!myAttacker->HasBreakableByDamageCrowdControlAura() && me->_CanDetectFeignDeathOf(myAttacker) && me->CanCreatureAttack(myAttacker) && !me->isTargetNotAcceptableByMMaps(myAttacker->GetGUID(), sWorld->GetGameTime(), myAttacker))
|
||||
if (!myAttacker->HasBreakableByDamageCrowdControlAura() && me->_CanDetectFeignDeathOf(myAttacker) && me->CanCreatureAttack(myAttacker))
|
||||
return myAttacker;
|
||||
|
||||
// Check pet's attackers first to prevent dragging mobs back to owner
|
||||
@@ -491,13 +494,13 @@ Unit* PetAI::SelectNextTarget(bool allowAutoSelect) const
|
||||
|
||||
// Check owner attackers
|
||||
if (Unit* ownerAttacker = owner->getAttackerForHelper())
|
||||
if (!ownerAttacker->HasBreakableByDamageCrowdControlAura() && me->_CanDetectFeignDeathOf(ownerAttacker) && me->CanCreatureAttack(ownerAttacker) && !me->isTargetNotAcceptableByMMaps(ownerAttacker->GetGUID(), sWorld->GetGameTime(), ownerAttacker))
|
||||
if (!ownerAttacker->HasBreakableByDamageCrowdControlAura() && me->_CanDetectFeignDeathOf(ownerAttacker) && me->CanCreatureAttack(ownerAttacker))
|
||||
return ownerAttacker;
|
||||
|
||||
// Check owner victim
|
||||
// 3.0.2 - Pets now start attacking their owners victim in defensive mode as soon as the hunter does
|
||||
if (Unit* ownerVictim = owner->GetVictim())
|
||||
if (me->_CanDetectFeignDeathOf(ownerVictim) && me->CanCreatureAttack(ownerVictim) && !me->isTargetNotAcceptableByMMaps(ownerVictim->GetGUID(), sWorld->GetGameTime(), ownerVictim))
|
||||
if (me->_CanDetectFeignDeathOf(ownerVictim) && me->CanCreatureAttack(ownerVictim))
|
||||
return ownerVictim;
|
||||
|
||||
// Neither pet or owner had a target and aggressive pets can pick any target
|
||||
@@ -601,7 +604,11 @@ void PetAI::DoAttack(Unit* target, bool chase)
|
||||
if (chase)
|
||||
{
|
||||
if (_canMeleeAttack())
|
||||
me->GetMotionMaster()->MoveChase(target, combatRange, float(M_PI));
|
||||
{
|
||||
float angle = combatRange == 0.f && target->GetTypeId() != TYPEID_PLAYER && !target->IsPet() ? float(M_PI) : 0.f;
|
||||
float tolerance = combatRange == 0.f ? float(M_PI_4) : float(M_PI * 2);
|
||||
me->GetMotionMaster()->MoveChase(target, ChaseRange(0.f, combatRange), ChaseAngle(angle, tolerance));
|
||||
}
|
||||
}
|
||||
else // (Stay && ((Aggressive || Defensive) && In Melee Range)))
|
||||
{
|
||||
|
||||
@@ -257,6 +257,40 @@ bool CreatureAI::_EnterEvadeMode()
|
||||
return true;
|
||||
}
|
||||
|
||||
void CreatureAI::MoveCircleChecks()
|
||||
{
|
||||
Unit *victim = me->GetVictim();
|
||||
|
||||
if (
|
||||
!victim ||
|
||||
!me->IsFreeToMove() || me->HasUnitMovementFlag(MOVEMENTFLAG_ROOT) ||
|
||||
!me->IsWithinMeleeRange(victim) || me == victim->GetVictim() ||
|
||||
(victim->GetTypeId() != TYPEID_PLAYER && !victim->IsPet()) // only player & pets to save CPU
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
me->GetMotionMaster()->MoveCircleTarget(me->GetVictim());
|
||||
}
|
||||
|
||||
void CreatureAI::MoveBackwardsChecks() {
|
||||
Unit *victim = me->GetVictim();
|
||||
|
||||
if (
|
||||
!victim ||
|
||||
!me->IsFreeToMove() || me->HasUnitMovementFlag(MOVEMENTFLAG_ROOT) ||
|
||||
(victim->GetTypeId() != TYPEID_PLAYER && !victim->IsPet())
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float moveDist = me->GetMeleeRange(victim) / 2;
|
||||
|
||||
me->GetMotionMaster()->MoveBackwards(victim, moveDist);
|
||||
}
|
||||
|
||||
Creature* CreatureAI::DoSummon(uint32 entry, const Position& pos, uint32 despawnTime, TempSummonType summonType)
|
||||
{
|
||||
return me->SummonCreature(entry, pos, summonType, despawnTime);
|
||||
|
||||
@@ -71,6 +71,9 @@ public:
|
||||
|
||||
~CreatureAI() override {}
|
||||
|
||||
void MoveCircleChecks();
|
||||
void MoveBackwardsChecks();
|
||||
|
||||
/// == Reactions At =================================
|
||||
|
||||
// Called if IsVisible(Unit* who) is true at each who move, reaction at visibility zone enter
|
||||
|
||||
Reference in New Issue
Block a user