diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index b39440c6..b42efcee 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -399,10 +399,11 @@ void Room::AddPlayer(Player* hum, std::shared_ptr init_born_point, bo MatchTeam(hum); } hum->PushJoinRoomMsg(); - ++alive_count_; - alive_count_chged_frameno_ = GetFrameNo(); - ++PerfMonitor::Instance()->alive_count; - + if (!hum->IsOb()) { + ++alive_count_; + alive_count_chged_frameno_ = GetFrameNo(); + ++PerfMonitor::Instance()->alive_count; + } grid_service->AddCreature(hum); hum->FindLocation(); hum->RefreshView(); @@ -500,9 +501,11 @@ void Room::CreateAndroid(int robot_num, std::shared_ptr team) } else { MatchTeam(hum); } - ++alive_count_; - alive_count_chged_frameno_ = GetFrameNo(); - ++PerfMonitor::Instance()->alive_count; + if (!hum->IsOb()) { + ++alive_count_; + alive_count_chged_frameno_ = GetFrameNo(); + ++PerfMonitor::Instance()->alive_count; + } refreshed_robot_set_.insert(robot_meta->id()); if (!CanAddToScene(hum)) { a8::SetBitFlag(hum->status, CS_Disable); @@ -910,7 +913,7 @@ void Room::InternalRemoveObjectLater(Entity* entity, a8::Attacher& xtimer_attach void Room::OnHumanDie(Human* hum) { - { + if (!hum->IsOb()) { --alive_count_; alive_count_chged_frameno_ = GetFrameNo(); --PerfMonitor::Instance()->alive_count; @@ -1022,6 +1025,15 @@ void Room::TraverseTeams(std::function cb) } } +void Room::TraverseRawTeams(std::function cb) +{ + for (auto& pair : team_hash_) { + if (!cb(pair.second.get())) { + break; + } + } +} + int Room::GetTeamNum() { return team_hash_.size(); @@ -1172,20 +1184,40 @@ std::shared_ptr Room::NewViewTeam() return team; } -void Room::TraversePlayerList(std::function func) +void Room::TraversePlayerList(std::function cb) { for (auto& pair : accountid_hash_) { - if (pair.second) { - func(pair.second); + if (pair.second && !pair.second->IsOb()) { + cb(pair.second); } } } -void Room::TraverseHumanList(std::function func) +void Room::TraverseRawPlayerList(std::function cb) +{ + for (auto& pair : accountid_hash_) { + if (pair.second) { + cb(pair.second); + } + } +} + +void Room::TraverseHumanList(std::function cb) { for (auto& pair : human_hash_) { if (pair.second && !pair.second->IsOb()) { - if (!func(pair.second)) { + if (!cb(pair.second)) { + break; + } + } + } +} + +void Room::TraverseRawHumanList(std::function cb) +{ + for (auto& pair : human_hash_) { + if (pair.second) { + if (!cb(pair.second)) { break; } } @@ -2125,9 +2157,11 @@ void Room::RandRemoveAndroid() RemoveFromHuamnHash(hum); RemoveFromAliveHumanHash(hum); AddToRemovedRobotHash(hum); - --alive_count_; - alive_count_chged_frameno_ = GetFrameNo(); - --PerfMonitor::Instance()->alive_count; + if (!hum->IsOb()) { + --alive_count_; + alive_count_chged_frameno_ = GetFrameNo(); + --PerfMonitor::Instance()->alive_count; + } for (auto& pair : human_hash_) { pair.second->RemovePartObjects(hum); } @@ -2903,6 +2937,27 @@ void Room::OnBattleStart() e.Get()->OnBattleStart(this); } } + TraverseHumanList + ( + [this] (Human* ele_hum) -> bool + { + ++battle_human_count_; + return true; + }); + TraversePlayerList + ( + [this] (Player* ele_hum) -> bool + { + ++battle_player_count_; + return true; + }); + TraverseTeams + ( + [this] (Team* ele_team) -> bool + { + ++battle_team_count_; + return true; + }); battle_starting_ = false; } diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 0e659f93..527ef4f9 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -148,8 +148,10 @@ public: void FillSMJoinedNotify(Human* self_hum, cs::SMJoinedNotify& msg); - void TraversePlayerList(std::function func); - void TraverseHumanList(std::function func); + void TraversePlayerList(std::function cb); + void TraverseRawPlayerList(std::function cb); + void TraverseHumanList(std::function cb); + void TraverseRawHumanList(std::function cb); void TraverseAliveHumanList(std::function func); void TraverseEntityList(std::function func); void TraverseAlivePlayers(std::function func); @@ -201,6 +203,7 @@ public: int GetAliveTeamNum(); Team* GetAliveTeam(); void TraverseTeams(std::function cb); + void TraverseRawTeams(std::function cb); bool CanJoin(const std::string& accountid, RoomType_e self_roomm_type, RoomMode_e self_room_mode, @@ -370,7 +373,9 @@ private: int elapsed_time_ = 0; int alive_count_ = 0; long long alive_count_chged_frameno_ = 0; - int human_alive_count_ = 0; + int battle_human_count_ = 0; + int battle_player_count_ = 0; + int battle_team_count_ = 0; const mt::AirLine* airline_ = nullptr; int level0room_born_point_uniid_ = 0; int level1room_born_point_uniid_ = 0;