diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index a90756c..d5e41a2 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -1316,3 +1316,20 @@ void Player::InternalAdOk() ad_timer_ = nullptr; } } + +void Player::PushJoinRoomMsg() +{ + { + cs::SMJoinedNotify notifymsg; + notifymsg.set_error_code(0); + room->FillSMJoinedNotify(this, notifymsg); + GGListener::Instance()->SendToClient(socket_handle, 0, notifymsg); + } + { + cs::SMMapInfo notifymsg; + notifymsg.set_map_id(room->GetMapMeta()->i->map_id()); + notifymsg.set_map_width(room->GetMapMeta()->i->map_width()); + notifymsg.set_map_height(room->GetMapMeta()->i->map_height()); + GGListener::Instance()->SendToClient(socket_handle, 0, notifymsg); + } +} diff --git a/server/gameserver/player.h b/server/gameserver/player.h index 85ceae6..691518a 100644 --- a/server/gameserver/player.h +++ b/server/gameserver/player.h @@ -86,6 +86,7 @@ class Player : public Human prepare_items); void ProcPrepareItems2(const ::google::protobuf::RepeatedPtrField< cs::MFPair >& prepare_items); + void PushJoinRoomMsg(); void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg); void _CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg); diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 3f8fff5..335937e 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -166,90 +166,21 @@ void Room::AddPlayer(Player* hum) hum->room = this; hum->join_frameno = GetFrameNo(); hum->Initialize(); - { - cs::SMJoinedNotify notifymsg; - notifymsg.set_error_code(0); - FillSMJoinedNotify(hum, notifymsg); - GGListener::Instance()->SendToClient(hum->socket_handle, 0, notifymsg); - } - { - cs::SMMapInfo notifymsg; - notifymsg.set_map_id(map_meta_->i->map_id()); - notifymsg.set_map_width(map_meta_->i->map_width()); - notifymsg.set_map_height(map_meta_->i->map_height()); - GGListener::Instance()->SendToClient(hum->socket_handle, 0, notifymsg); - } AddToEntityHash(hum); AddToMoveableHash(hum); AddToAccountHash(hum); AddToHumanHash(hum); AddToAliveHumanHash(hum); + MatchTeam(hum); + hum->PushJoinRoomMsg(); ++alive_count_; ++App::Instance()->perf.alive_count; - MatchTeam(hum); grid_service->AddHuman(hum); hum->FindLocation(); hum->RefreshView(); - if (room_type_ == RT_NewBrid) { - if (force_shua_android_times_ < 1) { - CreateAndroid(20 + rand() % 10); - ++force_shua_android_times_; - } - xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * (1 + rand() % 3), - a8::XParams() - .SetSender(hum), - [] (const a8::XParams& param) - { - Human* hum = (Human*)param.sender.GetUserData(); - hum->room->ShowAndroid(hum, 1 + rand() % 2); - }, - &hum->xtimer_attacher.timer_list_); - } - if (room_type_ == RT_NewBrid || room_type_ == RT_MidBrid) { - for (int buff_id : MetaMgr::Instance()->newbie_buff_list) { - MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(buff_id); - if (buff_meta) { - hum->AddBuff(buff_meta, 1); - } -#ifdef DEBUG - a8::UdpLog::Instance()->Debug("room_idx:%d 添加新手buff %s %s %d", - { - GetRoomIdx(), - hum->account_id, - hum->name, - buff_id - }); -#endif - } - } - while (human_hash_.size() > ROOM_MAX_PLAYER_NUM) { - RandRemoveAndroid(); - } + AddPlayerPostProc(hum); NotifyUiUpdate(); - #ifdef DEBUG - xtimer.AddRepeatTimerAndAttach - (SERVER_FRAME_RATE * 5, - a8::XParams() - .SetSender(hum), - [] (const a8::XParams& param) - { - Human* hum = (Human*)param.sender.GetUserData(); - std::string debugmsg = a8::Format("weapon_id:%d weapon_lv:%d atk:%f fire_rate:%f " - "volume:%d maxhp:%f curr_hp:%f", - { - hum->curr_weapon->weapon_id, - hum->curr_weapon->weapon_lv, - hum->curr_weapon->GetAttrValue(kHAT_Atk), - hum->curr_weapon->GetAttrValue(kHAT_FireRate), - hum->curr_weapon->GetAttrValue(kHAT_Volume), - hum->curr_weapon->GetAttrValue(kHAT_MaxHp), - hum->GetHP() - }); - hum->SendDebugMsg(debugmsg); - }, - &hum->xtimer_attacher.timer_list_); - #endif } int Room::AllocUniid() @@ -271,7 +202,6 @@ void Room::ShuaAndroid() MetaMgr::Instance()->refresh_robot_max_time); if (robot_num > 0 && refresh_time > 0) { CreateAndroid(robot_num); - NotifyUiUpdate(); xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * refresh_time, a8::XParams() .SetSender(this), @@ -354,6 +284,7 @@ void Room::CreateAndroid(int robot_num) hum->RefreshView(); } } + NotifyUiUpdate(); } Human* Room::FindEnemy(Human* hum) @@ -2429,3 +2360,53 @@ void Room::AddToAccountHash(Player* hum) { accountid_hash_[hum->account_id] = hum; } + +void Room::AddPlayerPostProc(Player* hum) +{ + if (room_type_ == RT_NewBrid) { + CreateAndroid(20 + rand() % 10); + xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * (1 + rand() % 3), + a8::XParams() + .SetSender(hum), + [] (const a8::XParams& param) + { + Human* hum = (Human*)param.sender.GetUserData(); + hum->room->ShowAndroid(hum, 1 + rand() % 2); + }, + &hum->xtimer_attacher.timer_list_); + } + if (room_type_ == RT_NewBrid || room_type_ == RT_MidBrid) { + for (int buff_id : MetaMgr::Instance()->newbie_buff_list) { + MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(buff_id); + if (buff_meta) { + hum->AddBuff(buff_meta, 1); + } + } + } + while (human_hash_.size() > ROOM_MAX_PLAYER_NUM) { + RandRemoveAndroid(); + } + #ifdef DEBUG + xtimer.AddRepeatTimerAndAttach + (SERVER_FRAME_RATE * 5, + a8::XParams() + .SetSender(hum), + [] (const a8::XParams& param) + { + Human* hum = (Human*)param.sender.GetUserData(); + std::string debugmsg = a8::Format("weapon_id:%d weapon_lv:%d atk:%f fire_rate:%f " + "volume:%d maxhp:%f curr_hp:%f", + { + hum->curr_weapon->weapon_id, + hum->curr_weapon->weapon_lv, + hum->curr_weapon->GetAttrValue(kHAT_Atk), + hum->curr_weapon->GetAttrValue(kHAT_FireRate), + hum->curr_weapon->GetAttrValue(kHAT_Volume), + hum->curr_weapon->GetAttrValue(kHAT_MaxHp), + hum->GetHP() + }); + hum->SendDebugMsg(debugmsg); + }, + &hum->xtimer_attacher.timer_list_); + #endif +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index d48fb72..4450378 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -168,6 +168,8 @@ private: void AddToMoveableHash(MoveableEntity* entity); void AddToAccountHash(Player* hum); + void AddPlayerPostProc(Player* hum); + #ifdef DEBUG void InitDebugInfo(); void UnInitDebugInfo(); @@ -193,7 +195,6 @@ private: long long game_over_frameno_ = 0; int elapsed_time_ = 0; int alive_count_ = 0; - int force_shua_android_times_ = 0; MetaData::AirLine* airline_ = nullptr; a8::XTimerAttacher xtimer_attacher_; size_t airdrop_times_ = 0;