This commit is contained in:
aozhiwei 2023-04-02 14:34:04 +08:00
parent 996c9316f6
commit 76a4cd945e

View File

@ -3024,7 +3024,7 @@ std::shared_ptr<std::set<int>> Creature::CalcReporterList(const mt::Equip* weapo
Creature* nearest_hum = nullptr;
TraverseCreatures
(
[nearest_distance, nearest_hum] (Creature*c, bool& stop) mutable
[this, &nearest_distance, &nearest_hum] (Creature* c, bool& stop) mutable
{
if (!c->IsHuman()) {
return;
@ -3035,7 +3035,7 @@ std::shared_ptr<std::set<int>> Creature::CalcReporterList(const mt::Equip* weapo
if (c->dead) {
return;
}
float distance = std::fabs(c->GetPos().GetX() - c->GetPos().GetX()) + std::fabs(c->GetPos().GetZ() - c->GetPos().GetZ());
float distance = std::fabs(c->GetPos().GetX() - GetPos().GetX()) + std::fabs(c->GetPos().GetZ() - GetPos().GetZ());
if (c->IsPlayer()) {
if (c->AsHuman()->socket_handle) {
if (distance < nearest_distance) {
@ -3043,8 +3043,28 @@ std::shared_ptr<std::set<int>> Creature::CalcReporterList(const mt::Equip* weapo
nearest_hum = c;
}
}
} else if (c->AsHuman()->HasObserver()) {
c->AsHuman()->TraverseObservers
(
[this, &nearest_distance, &nearest_hum] (Human* hum, bool& stop) mutable
{
if (!hum->IsPlayer()) {
return;
}
if (hum->socket_handle) {
float distance = std::fabs(hum->GetPos().GetX() - GetPos().GetX()) + std::fabs(hum->GetPos().GetZ() - GetPos().GetZ());
if (distance < nearest_distance) {
nearest_distance = distance;
nearest_hum = hum;
}
}
});
}
});
if (nearest_hum) {
p = std::make_shared<std::set<int>>();
p->insert(nearest_hum->GetUniId());
}
}
break;
default: