This commit is contained in:
aozhiwei 2023-02-03 17:38:00 +08:00
parent 3683a0a00d
commit dc269b189a
2 changed files with 16 additions and 11 deletions

View File

@ -1418,9 +1418,9 @@ void Creature::CheckSpecObject(int new_poly_flags)
if (!a8::SameBitFlag(poly_ext_flags_, new_poly_flags, i)) { if (!a8::SameBitFlag(poly_ext_flags_, new_poly_flags, i)) {
if ((1 << i) == SAMPLE_POLYFLAGS_SWIM) { if ((1 << i) == SAMPLE_POLYFLAGS_SWIM) {
if (a8::HasBitFlag(poly_ext_flags_, i)) { if (a8::HasBitFlag(poly_ext_flags_, i)) {
TryAddBuff(this, kInWater1BuffId);
} else {
RemoveBuffByEffectId(kBET_InWater); RemoveBuffByEffectId(kBET_InWater);
} else {
TryAddBuff(this, kInWater1BuffId);
} }
} }
} }

View File

@ -669,12 +669,12 @@ bool MapInstance::RaycastEx(const glm::vec3& start, const glm::vec3& end,
abort(); abort();
} }
if (flags) { if (flags) {
spec_polys.push_back(polys_[i]);
}
if (last_flags && last_flags != flags) { if (last_flags && last_flags != flags) {
is_same_flags = false; is_same_flags = false;
} }
last_flags = flags; last_flags = flags;
spec_polys.push_back(flags);
}
} }
if (is_same_flags) { if (is_same_flags) {
same_polys_flags = last_flags; same_polys_flags = last_flags;
@ -697,22 +697,27 @@ void MapInstance::CheckTerrain(Creature* c, int same_poly_flags, const std::vect
c->CheckSpecObject(0); c->CheckSpecObject(0);
} else { } else {
float pos[3]; float pos[3];
pos[0] = c->GetPos().x; pos[0] = c->GetPos().x * GetMapMeta()->scale();
pos[1] = c->GetPos().y; pos[1] = c->GetPos().y;
pos[2] = c->GetPos().z; pos[2] = c->GetPos().z * GetMapMeta()->scale();
float closest[3]; float closest[3];
bool found = false;
for (auto& poly_ref : spec_polys) { for (auto& poly_ref : spec_polys) {
dtStatus status = navmesh_query_->closestPointOnPolyBoundary(poly_ref, pos, closest); dtStatus status = navmesh_query_->closestPointOnPolyBoundary(poly_ref, pos, closest);
if (dtStatusSucceed(status) && if (dtStatusSucceed(status) &&
std::fabs(closest[0] - c->GetPos().x) <= 0.3f && std::fabs(closest[0] - c->GetPos().x * GetMapMeta()->scale()) <= 0.1f &&
std::fabs(closest[2] - c->GetPos().z) <= 0.3f) { std::fabs(closest[2] - c->GetPos().z * GetMapMeta()->scale()) <= 0.1f) {
unsigned short flags = 0; unsigned short flags = 0;
if (dtStatusSucceed(navmesh_->getPolyFlags(poly_ref, &flags))) { if (dtStatusSucceed(navmesh_->getPolyFlags(poly_ref, &flags))) {
c->CheckSpecObject(flags); c->CheckSpecObject(flags);
found = true;
break; break;
} }
} }
} }
if (!found) {
c->CheckSpecObject(0);
}
} }
} }
} }