[Pathing] Improvements to handling tight corridors pathing, clipping detection and recovery (#2826)

This commit is contained in:
Chris Miles 2023-02-06 17:24:03 -06:00 committed by GitHub
parent 823e73336d
commit 404f7cada8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 12 deletions

View File

@ -317,6 +317,7 @@ RULE_BOOL(Map, FixPathingZOnSendTo, false, "Try to repair Z coordinates in the S
RULE_BOOL(Map, FixZWhenPathing, true, "Automatically fix NPC Z coordinates when moving/pathing/engaged (Far less CPU intensive than its predecessor)")
RULE_REAL(Map, DistanceCanTravelBeforeAdjustment, 10.0, "Distance a mob can path before FixZ is called, depends on FixZWhenPathing")
RULE_BOOL(Map, MobZVisualDebug, false, "Displays spell effects determining whether or not NPC is hitting Best Z calcs (blue for hit, red for miss)")
RULE_BOOL(Map, MobPathingVisualDebug, false, "Displays nodes in pathing points in realtime to help with visual debugging")
RULE_REAL(Map, FixPathingZMaxDeltaSendTo, 20, "At runtime in SendTo: maximum change in Z to allow the BestZ code to apply")
RULE_INT(Map, FindBestZHeightAdjust, 1, "Adds this to the current Z before seeking the best Z position")
RULE_CATEGORY_END()

View File

@ -29,6 +29,7 @@ void command_loc(Client *c, const Seperator *sep)
glm::vec3 hit;
auto best_z = zone->zonemap->FindBestZ(tarloc, &hit);
auto fixed_z = c->GetFixedZ(c->GetPosition());
if (best_z != BEST_Z_INVALID) {
c->Message(
@ -39,6 +40,14 @@ void command_loc(Client *c, const Seperator *sep)
best_z
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"Fixed Z for {} | {:.2f}",
c->GetTargetDescription(target, TargetDescriptionType::UCSelf),
fixed_z
).c_str()
);
} else {
c->Message(Chat::White, "Could not find Best Z.");
}

View File

@ -1451,6 +1451,8 @@ public:
void SetManualFollow(bool flag) { m_manual_follow = flag; }
bool GetManualFollow() const { return m_manual_follow; }
void DrawDebugCoordinateNode(std::string node_name, const glm::vec4 vec);
protected:
void CommonDamage(Mob* other, int64 &damage, const uint16 spell_id, const EQ::skills::SkillType attack_skill, bool &avoidable, const int8 buffslot, const bool iBuffTic, eSpecialAttacks specal = eSpecialAttacks::None);
static uint16 GetProcID(uint16 spell_id, uint8 effect_index);

View File

@ -1053,6 +1053,13 @@ void MobMovementManager::FillCommandStruct(
position_update->delta_z = FloatToEQ13(delta_z);
position_update->delta_heading = FloatToEQ10(delta_heading);
position_update->animation = (mob->IsBot() ? (int) ((float) anim / 1.785714f) : anim);
if (RuleB(Map, MobPathingVisualDebug)) {
mob->DrawDebugCoordinateNode(
fmt::format("{} position update", mob->GetCleanName()),
mob->GetPosition()
);
}
}
/**

View File

@ -7002,3 +7002,17 @@ void Mob::SetHP(int64 hp)
current_hp = hp;
}
void Mob::DrawDebugCoordinateNode(std::string node_name, const glm::vec4 vec)
{
NPC* node = nullptr;
for (const auto& n : entity_list.GetNPCList()) {
if (n.second->GetCleanName() == node_name) {
node = n.second;
break;
}
}
if (!node) {
node = NPC::SpawnNodeNPC(node_name, "", GetPosition());
}
}

View File

@ -771,17 +771,15 @@ float Mob::GetFixedZ(const glm::vec3 &destination, int32 z_find_offset) {
float new_z = destination.z;
if (zone->HasMap()) {
if (flymode == GravityBehavior::Flying)
if (flymode == GravityBehavior::Flying) {
return new_z;
}
if (zone->HasWaterMap() && zone->watermap->InLiquid(glm::vec3(m_Position)))
if (zone->HasWaterMap() && zone->watermap->InLiquid(glm::vec3(m_Position))) {
return new_z;
}
/*
* Any more than 5 in the offset makes NPC's hop/snap to ceiling in small corridors
*/
new_z = FindDestGroundZ(destination, z_find_offset);
new_z = FindDestGroundZ(destination, (-GetZOffset() / 2));
if (new_z != BEST_Z_INVALID) {
new_z += GetZOffset();
@ -790,6 +788,20 @@ 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 [{}]",
@ -833,6 +845,10 @@ void Mob::FixZ(int32 z_find_offset /*= 5*/, bool fix_client_z /*= false*/) {
}
m_Position.z = new_z;
if (RuleB(Map, MobPathingVisualDebug)) {
DrawDebugCoordinateNode(fmt::format("{} new fixed z node", GetCleanName()), GetPosition());
}
}
else {
if (RuleB(Map, MobZVisualDebug)) {
@ -928,6 +944,7 @@ float Mob::GetZOffset() const {
case RACE_RABBIT_668:
offset = 5.0f;
break;
case RACE_WURM_158:
case RACE_BLIND_DREAMER_669:
offset = 7.0f;
break;