From 3a13c07d59dfd3fe6a801e592407bfbc3d9ae9c8 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 3 Apr 2023 19:39:35 +0800 Subject: [PATCH] 1 --- server/gameserver/creature.cc | 100 ++++++++++++++++++---------------- server/gameserver/creature.h | 3 +- server/gameserver/hero.cc | 4 +- server/gameserver/shot.cc | 2 +- 4 files changed, 58 insertions(+), 51 deletions(-) diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index 777f06e5..546824d9 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -3013,65 +3013,73 @@ void CreatuRemoveSurplusObstacle(int thing_id, int num) } #endif -std::shared_ptr> Creature::CalcReporterList(const mt::Equip* weapon_meta, +std::shared_ptr> Creature::CalcReporterList(bool is_trace_bullet, + const mt::Equip* weapon_meta, const mt::Equip* bullet_meta) { std::shared_ptr> p; + bool need_gen = false; switch (bullet_meta->_inventory_slot()) { case IS_RPG: { - float nearest_distance = FLT_MAX; - Creature* nearest_hum = nullptr; - TraverseCreatures - ( - [this, &nearest_distance, &nearest_hum] (Creature* c, bool& stop) mutable - { - if (!c->IsHuman()) { - return; - } - if (a8::HasBitFlag(c->status, CS_Disable)) { - return; - } - if (c->dead) { - return; - } - 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) { - nearest_distance = distance; - 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>(); - p->insert(nearest_hum->GetUniId()); - } + need_gen = true; } break; default: { + if (IsEntityType(ET_Hero) && is_trace_bullet) { + need_gen = true; + } } break; } + if (need_gen) { + float nearest_distance = FLT_MAX; + Creature* nearest_hum = nullptr; + TraverseCreatures + ( + [this, &nearest_distance, &nearest_hum] (Creature* c, bool& stop) mutable + { + if (!c->IsHuman()) { + return; + } + if (a8::HasBitFlag(c->status, CS_Disable)) { + return; + } + if (c->dead) { + return; + } + 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) { + nearest_distance = distance; + 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>(); + p->insert(nearest_hum->GetUniId()); + } + } return p; } diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index 1374b7b2..6964fbaf 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -342,7 +342,8 @@ class Creature : public MoveableEntity float GetSkillRaycastDistance(); virtual void NetInitOk(); bool IsNearGas(); - std::shared_ptr> CalcReporterList(const mt::Equip* weapon_meta, + std::shared_ptr> CalcReporterList(bool is_trace_bullet, + const mt::Equip* weapon_meta, const mt::Equip* bullet_meta); protected: diff --git a/server/gameserver/hero.cc b/server/gameserver/hero.cc index 5f83293e..33a6f85b 100644 --- a/server/gameserver/hero.cc +++ b/server/gameserver/hero.cc @@ -111,9 +111,7 @@ void Hero::Update(int delta_time) } } #ifdef DEBUG - if (!room->stop_world) { - agent_->Exec(); - } + agent_->Exec(); #else agent_->Exec(); #endif diff --git a/server/gameserver/shot.cc b/server/gameserver/shot.cc index cbebe1a1..786301ab 100644 --- a/server/gameserver/shot.cc +++ b/server/gameserver/shot.cc @@ -529,7 +529,6 @@ void InternalShot(Creature* c, bullet_info.bullet_num = bulletNum; bullet_info.weapon_lv = weapon_lv; bullet_info.weapon_buff_id = weapon_buff_id; - bullet_info.reporter_list = c->CalcReporterList(weapon_meta, bullet_meta); #if 0 if (skill_meta && (skill_meta->GetMagicId() == MAGIC_20101_HL || @@ -538,6 +537,7 @@ void InternalShot(Creature* c, bullet_info.trace_target_uniid = c->GetSkillTargetId(); } #endif + bullet_info.reporter_list = c->CalcReporterList(trace_target_uniid, weapon_meta, bullet_meta); if (weapon_meta->double_gun() && bulletIdx > (int)(bulletNum / 2)) { bullet_info.hand = 1;