From d1cee2badef476443797d8f1820e43d74685ba49 Mon Sep 17 00:00:00 2001 From: Ovahlord <18347559+ovahlord@users.noreply.github.com> Date: Sun, 16 Aug 2026 16:56:32 +0200 Subject: [PATCH] Core/Creatures: correct behavior for enabling swimming for creatures on ocean floors --- .../game/Entities/Creature/Creature.cpp | 22 ++++++++++++------- src/server/game/Entities/Creature/Creature.h | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index ef662a3b70..a0a9b3a2f3 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -2931,9 +2931,13 @@ void Creature::InitializeMovementCapabilities() SetDisableGravity(IsFloating()); SetControlled(IsSessile(), UNIT_STATE_ROOT); - // If an amphibious creatures was swimming while engaged, disable swimming again - if (IsAmphibious() && !_staticFlags.HasFlag(CREATURE_STATIC_FLAG_CAN_SWIM)) - RemoveUnitFlag(UNIT_FLAG_CAN_SWIM); + if (IsSwimPrevented()) + { + SetUnitFlag2(UNIT_FLAG2_AI_WILL_ONLY_SWIM_IF_TARGET_SWIMS); + SetSwim(false); + } + else + RemoveUnitFlag2(UNIT_FLAG2_AI_WILL_ONLY_SWIM_IF_TARGET_SWIMS); UpdateMovementCapabilities(); } @@ -2950,12 +2954,14 @@ void Creature::UpdateMovementCapabilities() if (!isInAir) RemoveUnitMovementFlag(MOVEMENTFLAG_FALLING); - // Some Amphibious creatures toggle swimming while engaged - if (IsAmphibious() && !HasUnitFlag(UNIT_FLAG_CANT_SWIM) && !HasUnitFlag(UNIT_FLAG_CAN_SWIM) && IsEngaged()) - if (!CanOnlySwimIfTargetSwims() || (GetVictim() && !GetVictim()->IsOnOceanFloor())) - SetUnitFlag(UNIT_FLAG_CAN_SWIM); + if (HasUnitFlag2(UNIT_FLAG2_AI_WILL_ONLY_SWIM_IF_TARGET_SWIMS)) + if (GetVictim() && GetVictim()->IsInWater() && !GetVictim()->IsOnOceanFloor()) + RemoveUnitFlag2(UNIT_FLAG2_AI_WILL_ONLY_SWIM_IF_TARGET_SWIMS); - SetSwim(IsInWater() && CanSwim()); + if (IsInWater() && CanSwim()) + SetSwim(true); + else if (!IsInWater()) // We do not want to disable swimming again when a creature is in water - may to lead some nasty bugs + SetSwim(false); } CreatureMovementData const& Creature::GetMovementTemplate() const diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 5015b0080d..8a6e6162a5 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -154,10 +154,10 @@ class TC_GAME_API Creature : public Unit, public GridObject, public Ma bool IsSwimDisabled() const { return _staticFlags.HasFlag(CREATURE_STATIC_FLAG_3_CANT_SWIM); } // Returns true if CREATURE_STATIC_FLAG_4_AI_WILL_ONLY_SWIM_IF_TARGET_SWIMS is set which prevents 'Amphibious' creatures from swimming when engaged until the victim is no longer on the ocean floor - bool CanOnlySwimIfTargetSwims() const { return _staticFlags.HasFlag(CREATURE_STATIC_FLAG_4_AI_WILL_ONLY_SWIM_IF_TARGET_SWIMS); } + bool IsSwimPrevented() const { return _staticFlags.HasFlag(CREATURE_STATIC_FLAG_4_AI_WILL_ONLY_SWIM_IF_TARGET_SWIMS); } bool CanSwim() const override; - bool CanEnterWater() const override { return (CanSwim() || IsAmphibious()); } + bool CanEnterWater() const override { return (CanSwim() || IsAmphibious()); }; bool CanFly() const override { return (IsFlying() || HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY)); } MovementGeneratorType GetDefaultMovementType() const override;