From 00f7a6bbdefa26d69ded8868e665fd5eb6b24446 Mon Sep 17 00:00:00 2001 From: UltraNix <80540499+UltraNix@users.noreply.github.com> Date: Sun, 21 Mar 2021 15:19:07 +0100 Subject: [PATCH] fix(Core/Maps): Include collision height in underwater status calculations. (#4855) --- src/server/game/Entities/Player/Player.cpp | 5 +++-- src/server/game/Maps/Map.cpp | 8 ++++---- src/server/game/Maps/Map.h | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 65dc9a906..51455e3a4 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -3041,7 +3041,7 @@ bool Player::IsInWater(bool allowAbove) const bool Player::IsUnderWater() const { return IsInWater() && - GetPositionZ() < (GetBaseMap()->GetWaterLevel(GetPositionX(), GetPositionY()) - 2); + GetPositionZ() < GetBaseMap()->GetWaterLevel(GetPositionX(), GetPositionY()) - GetCollisionHeight(); } bool Player::IsFalling() const @@ -24769,13 +24769,14 @@ void Player::UpdateUnderwaterState(Map* m, float x, float y, float z) // pussywizard: optimization if (GetExactDistSq(&m_last_underwaterstate_position) < 3.0f * 3.0f) return; + m_last_underwaterstate_position.Relocate(m_positionX, m_positionY, m_positionZ); if (!IsPositionValid()) // pussywizard: crashfix if calculated grid coords would be out of range 0-64 return; LiquidData liquid_status; - ZLiquidStatus res = m->getLiquidStatus(x, y, z, MAP_ALL_LIQUIDS, &liquid_status); + ZLiquidStatus res = m->getLiquidStatus(x, y, z, MAP_ALL_LIQUIDS, &liquid_status, GetCollisionHeight()); if (!res) { m_MirrorTimerFlags &= ~(UNDERWATER_INWATER | UNDERWATER_INLAVA | UNDERWATER_INSLIME | UNDERWARER_INDARKWATER); diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 98e95a6fb..a35ee2cec 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -1802,7 +1802,7 @@ uint8 GridMap::getTerrainType(float x, float y) const } // Get water state on map -inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData* data) +inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, float collisionHeight, LiquidData* data) { // Check water type (if no water return) if (!_liquidType && !_liquidFlags) @@ -1887,11 +1887,11 @@ inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 R // For speed check as int values float delta = liquid_level - z; - if (delta > 2.0f) // Under water + if (delta > collisionHeight) // Under water return LIQUID_MAP_UNDER_WATER; if (delta > 0.0f) // In water return LIQUID_MAP_IN_WATER; - if (delta > -0.1f) // Walk on water + if (delta > -0.1f) // Walk on water return LIQUID_MAP_WATER_WALK; // Above water return LIQUID_MAP_ABOVE_WATER; @@ -2218,7 +2218,7 @@ ZLiquidStatus Map::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidTyp if (GridMap* gmap = const_cast(this)->GetGrid(x, y)) { LiquidData map_data; - ZLiquidStatus map_result = gmap->getLiquidStatus(x, y, z, ReqLiquidType, &map_data); + ZLiquidStatus map_result = gmap->getLiquidStatus(x, y, z, ReqLiquidType, collisionHeight, &map_data); // Not override LIQUID_MAP_ABOVE_WATER with LIQUID_MAP_NO_WATER: if (map_result != LIQUID_MAP_NO_WATER && (map_data.level > ground_level)) { diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 130a20e11..bc3df54fa 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -208,7 +208,7 @@ public: [[nodiscard]] float getMinHeight(float x, float y) const; [[nodiscard]] float getLiquidLevel(float x, float y) const; [[nodiscard]] uint8 getTerrainType(float x, float y) const; - ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData* data = nullptr); + ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, float collisionHeight, LiquidData* data = nullptr); }; // GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push, N), also any gcc version not support it at some platform