From 7bc0d150687a65a5aa272a737990ca3df3bda4eb Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 5 Jul 2019 11:29:20 +0800 Subject: [PATCH] 1 --- server/gameserver/room.cc | 58 +++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index b09092b..d2ed457 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -795,15 +795,15 @@ void Room::UpdateGas() NotifyWxVoip(); RoomMgr::Instance()->ActiveRoom(room_uuid); battle_start_frameno_ = frame_no; - xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * MetaMgr::Instance()->game_duration, - a8::XParams() - .SetSender(this), - [] (const a8::XParams& param) - { - Room* room = (Room*)param.sender.GetUserData(); - room->BattleReport(); - }, - &xtimer_attacher.timer_list_); + battle_report_timer_ = xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * MetaMgr::Instance()->game_duration, + a8::XParams() + .SetSender(this), + [] (const a8::XParams& param) + { + Room* room = (Room*)param.sender.GetUserData(); + room->BattleReport(); + }, + &xtimer_attacher.timer_list_); } } break; @@ -991,5 +991,45 @@ void Room::NotifyWxVoip() void Room::BattleReport() { + battle_report_timer_ = nullptr; + std::vector human_list; + human_list.reserve(human_hash_.size()); + for (auto& pair : human_hash_) { + human_list.push_back(pair.second); + } + std::sort(human_list.begin(), human_list.end(), + [] (Human* a, Human* b) -> bool + { + if (a->stats.kills > b->stats.kills) { + return true; + } + if (a->stats.dead_times < b->stats.dead_times) { + return true; + } + if (a->stats.damage_amount_out > b->stats.damage_amount_out) { + return true; + } + return false; + }); + cs::SMGameOver msg; + msg.set_room_uuid(a8::XValue(room_uuid).GetString()); + int rank = 1; + for (Human* hum : human_list) { + auto p = msg.add_player_stats(); + p->set_rank(rank++); + p->set_player_id(hum->entity_uniid); + p->set_player_avatar_url(hum->avatar_url); + p->set_account_id(hum->account_id); + p->set_kills(hum->stats.kills); + p->set_dead_times(hum->stats.dead_times); + } + for (Human* hum : human_list) { + if (hum->entity_subtype == EST_Player) { + hum->SendNotifyMsg(msg); + } + } + game_over = true; + game_over_frameno = frame_no; + RoomMgr::Instance()->AddOverRoom(room_uuid); }