diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index a00e65f661..d15d92533a 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -3011,26 +3011,33 @@ void Creature::UpdateMovementFlags() // Set the movement flags if the creature is in that mode. (Only fly if actually in air, only swim if in water, etc) float ground = GetFloorZ(); + bool isInAir = (G3D::fuzzyGt(GetPositionZ(), ground + (IsHovering() ? GetFloatValue(UNIT_FIELD_HOVERHEIGHT) : 0.0f) + GROUND_HEIGHT_TOLERANCE) || G3D::fuzzyLt(GetPositionZ(), ground - GROUND_HEIGHT_TOLERANCE)); // Can be underground too, prevent the falling - bool canHover = CanHover(); - bool isInAir = (G3D::fuzzyGt(GetPositionZ(), ground + (canHover ? GetFloatValue(UNIT_FIELD_HOVERHEIGHT) : 0.0f) + GROUND_HEIGHT_TOLERANCE) || G3D::fuzzyLt(GetPositionZ(), ground - GROUND_HEIGHT_TOLERANCE)); // Can be underground too, prevent the falling - + // Creature has a flight state enabled in db if (GetMovementTemplate().IsFlightAllowed() && isInAir && !IsFalling()) { - if (GetMovementTemplate().Flight == CreatureFlightMovementType::CanFly) - SetCanFly(true); - else - SetDisableGravity(true, false, false); + if (GetMovementTemplate().IsGravityDisabled()) + SetDisableGravity(true); - if (!HasAuraType(SPELL_AURA_HOVER)) - SetHover(false); + if (GetMovementTemplate().CanFly()) + SetCanFly(true); } else { + // @todo: this interferes with scripted flight movement so let's reevaluate if we want to stick with CREATURE_FLAG_EXTRA_NO_MOVE_FLAGS_UPDATE to avoid that or if we want to drop that all together. SetCanFly(false); - SetDisableGravity(false, false, false); - if ((IsAlive() && CanHover()) || HasAuraType(SPELL_AURA_HOVER)) - SetHover(true, false, false); + SetDisableGravity(false); + } + + // Creature has a special ground state enabled in db or has a movement hover aura applied + if (GetMovementTemplate().IsGroundAllowed()) + { + // Hovering always requires the creature to be alive to avoid visual issues + // @todo: sniffed spawn locations have applied hover offsets to the position z value so either substract them when parsing sniffs or skip the initial relocation from Unit::SetHover + if (IsAlive() && (GetMovementTemplate().IsHoverEnabled() || HasAuraType(SPELL_AURA_HOVER))) + SetHover(true); + else + SetHover(false); } if (!isInAir) diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index cdef4b17bf..7bea18a1b1 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -98,7 +98,7 @@ class TC_GAME_API Creature : public Unit, public GridObject, public Ma bool CanSwim() const override; bool CanEnterWater() const override; bool CanFly() const override { return GetMovementTemplate().IsFlightAllowed() || IsFlying(); } - bool CanHover() const { return GetMovementTemplate().Ground == CreatureGroundMovementType::Hover || IsHovering(); } + bool CanHover() const { return GetMovementTemplate().IsHoverEnabled() || IsHovering(); } bool SetDisableGravity(bool disable, bool packetOnly = false, bool updateAnimationTier = true) override; bool SetHover(bool enable, bool packetOnly = false, bool updateAnimationTier = true) override; diff --git a/src/server/game/Entities/Creature/CreatureData.h b/src/server/game/Entities/Creature/CreatureData.h index e886eb89b7..c39ced1b27 100644 --- a/src/server/game/Entities/Creature/CreatureData.h +++ b/src/server/game/Entities/Creature/CreatureData.h @@ -118,6 +118,9 @@ struct TC_GAME_API CreatureMovementData bool IsSwimAllowed() const { return Swim; } bool IsFlightAllowed() const { return Flight != CreatureFlightMovementType::None; } bool IsRooted() const { return Rooted; } + bool IsGravityDisabled() const { return Flight == CreatureFlightMovementType::DisableGravity; } + bool CanFly() const { return Flight == CreatureFlightMovementType::CanFly; } + bool IsHoverEnabled() const { return Ground == CreatureGroundMovementType::Hover; } CreatureRandomMovementType GetRandom() const { return Random; }