From 96982ddc441c671192033d6383ffed877bf86fe6 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 10 Apr 2024 16:12:06 +0800 Subject: [PATCH] 1 --- server/gameserver/room.cc | 40 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 15b09f52..6ca50c77 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -190,25 +190,31 @@ void Room::Init() if (a8::TIMER_EXEC_EVENT == event) { if (!IsGameOver() && !GetVictoryTeam()) { for (size_t i = 0; i < 2; ++i) { - Team* team = GetMobaTeamA(); - if (i == 1) { - team = GetMobaTeamB(); - } - auto tuple = GetMapMeta()->GetMobaRoomMeta()->moba_towers.at(i); - team->TraverseMembers + const auto side = i + 1; + auto& tuple = GetMapMeta()->GetMobaRoomMeta()->moba_towers.at(i); + TraverseTeams ( - [&tuple] (Human* hum) -> bool + [&tuple, side] (Team* team) -> bool { - float distance = hum->GetPos().Distance2D2(std::get<0>(tuple)); - if (distance < std::get<1>(tuple)) { - if (!hum->dead && !hum->poisoning && !hum->downed) { - if (hum->GetHP() + 1 < hum->GetMaxHP()) { - hum->AddHp(hum->GetMaxHP() * - hum->room->GetMapMeta()->GetMobaRoomMeta()->tower_recover_hp_rate()); - hum->TryAddBuff(hum, kRecoverHpEffectBuffId); - } - } - } + team->TraverseMembers + ( + [&tuple, side] (Human* hum) -> bool + { + if (hum->side != side) { + return false; + } + float distance = hum->GetPos().Distance2D2(std::get<0>(tuple)); + if (distance < std::get<1>(tuple)) { + if (!hum->dead && !hum->poisoning && !hum->downed) { + if (hum->GetHP() + 1 < hum->GetMaxHP()) { + hum->AddHp(hum->GetMaxHP() * + hum->room->GetMapMeta()->GetMobaRoomMeta()->tower_recover_hp_rate()); + hum->TryAddBuff(hum, kRecoverHpEffectBuffId); + } + } + } + return true; + }); return true; }); }