From 1e50f19f7e1e520d801393b7ec6e1edd0aa80960 Mon Sep 17 00:00:00 2001 From: Chris Miles Date: Tue, 21 Feb 2023 10:24:25 -0600 Subject: [PATCH] [Pathing] Improvements to z-clipping, z-recovery and z-calculations (#2975) * zclip adjustments * Remove debug --- zone/mob.cpp | 1 + zone/mob.h | 2 ++ zone/mob_ai.cpp | 8 ++++++++ zone/waypoints.cpp | 28 +++++++++++++--------------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/zone/mob.cpp b/zone/mob.cpp index f961621ea..f190766e9 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -103,6 +103,7 @@ Mob::Mob( attack_dw_timer(2000), ranged_timer(2000), hp_regen_per_second_timer(1000), + m_z_clip_check_timer(1000), tic_timer(6000), mana_timer(2000), spellend_timer(0), diff --git a/zone/mob.h b/zone/mob.h index 5a3d4b735..797dc445d 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -1427,6 +1427,8 @@ protected: int _GetRunSpeed() const; int _GetFearSpeed() const; + Timer m_z_clip_check_timer; + virtual bool AI_EngagedCastCheck() { return(false); } virtual bool AI_PursueCastCheck() { return(false); } virtual bool AI_IdleCastCheck() { return(false); } diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index b78b5ecfe..07d6c2df4 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -1071,6 +1071,14 @@ void Mob::AI_Process() { } if (engaged) { + if (IsNPC() && m_z_clip_check_timer.Check()) { + auto t = GetTarget(); + if (t && DistanceNoZ(GetPosition(), t->GetPosition()) < 75 && std::abs(GetPosition().z - t->GetPosition().z) > 15 && !CheckLosFN(t)) { + GMMove(t->GetPosition().x, t->GetPosition().y, t->GetPosition().z, t->GetPosition().w); + FaceTarget(t); + } + } + if (!(m_PlayerState & static_cast(PlayerState::Aggressive))) SendAddPlayerState(PlayerState::Aggressive); diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index 5de0aa43a..7d5e3e02e 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -781,7 +781,19 @@ float Mob::GetFixedZ(const glm::vec3 &destination, int32 z_find_offset) { return new_z; } - new_z = FindDestGroundZ(destination, (-GetZOffset() / 2)); + new_z = FindDestGroundZ(destination, ((-GetZOffset() / 2) + z_find_offset)); + + if (RuleB(Map, MobPathingVisualDebug)) { + DrawDebugCoordinateNode( + fmt::format("{} search z node", GetCleanName()), + glm::vec4{ + m_Position.x, + m_Position.y, + ((-GetZOffset() / 2) + z_find_offset), + m_Position.w + } + ); + } if (new_z != BEST_Z_INVALID) { new_z += GetZOffset(); @@ -790,20 +802,6 @@ float Mob::GetFixedZ(const glm::vec3 &destination, int32 z_find_offset) { } } - // prevent ceiling clipping - // if client is close in distance (not counting Z) and we clipped up into a ceiling - // this helps us snap back down (or up) if it were to happen - // other fixes were put in place to prevent clipping into the ceiling to begin with - if (std::abs(new_z - m_Position.z) > 15) { - LogFixZ("TRIGGER clipping detection"); - auto t = GetTarget(); - if (t && DistanceNoZ(GetPosition(), t->GetPosition()) < 20) { - new_z = FindDestGroundZ(t->GetPosition(), -t->GetZOffset()); - new_z += GetZOffset(); - GMMove(t->GetPosition().x, t->GetPosition().y, new_z, t->GetPosition().w); - } - } - auto duration = timer.elapsed(); LogFixZ("[{}] returned [{}] at [{}] [{}] [{}] - Took [{}]",