From 12104f57f321040d458f2feb63a74f67c910460d Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 4 Jun 2020 16:50:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=BA=E5=99=A8=E4=BA=BA?= =?UTF-8?q?=E8=A7=86=E9=87=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/android.ai.cc | 2 +- server/gameserver/room.cc | 136 +++++++++++++++++++++----------- server/gameserver/room.h | 2 + 3 files changed, 95 insertions(+), 45 deletions(-) diff --git a/server/gameserver/android.ai.cc b/server/gameserver/android.ai.cc index 0837f3c..912c5bf 100644 --- a/server/gameserver/android.ai.cc +++ b/server/gameserver/android.ai.cc @@ -208,7 +208,7 @@ void AndroidAI::UpdateLastNpc() hum->move_dir.Normalize(); hum->attack_dir = hum->move_dir; if (hum->curr_weapon->weapon_idx != 0) { - hum->curr_weapon->ammo = MetaMgr::Instance()->newbie_first_robot_ammo; + hum->curr_weapon->ammo = MetaMgr::Instance()->newbie_first_robot_ammo * 2; } } else if (hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 1.5) { int speed = std::max(1, (int)hum->GetSpeed()); diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 744cd3d..aade2bf 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -27,7 +27,7 @@ #include "perfmonitor.h" const int ROOM_MAX_PLAYER_NUM = 40; -const int SHUA_RANGE = 731; +const int SHUA_RANGE = 512; static long long RoomXGetTickCount(void* context) { @@ -1588,6 +1588,23 @@ void Room::SecondRandPoint() #ifdef DEBUG CheckPartObjects(); #endif + if (room_type_ == RT_NewBrid || room_type_ == RT_MidBrid) { + std::vector tmp_humans; + tmp_humans.reserve(ROOM_MAX_PLAYER_NUM); + for (auto& pair : human_hash_) { + if (pair.second->IsAndroid() && + a8::HasBitFlag(pair.second->status, HS_Disable) && + pair.second->team_uuid.empty() + ) { + tmp_humans.push_back(pair.second); + } + } + std::random_shuffle(tmp_humans.begin(), tmp_humans.end()); + for (size_t i = 0; i < accountid_hash_.size(); ++i) { + last_human_hash_[tmp_humans[i]->GetEntityUniId()] = tmp_humans[i]; + a8::SetBitFlag(tmp_humans[i]->status, HS_LastAndroid); + } + } } void Room::NotifyGameStart() @@ -2449,18 +2466,6 @@ void Room::NewBieRoomStart() }, &xtimer_attacher_.timer_list_); } - std::vector tmp_humans; - tmp_humans.reserve(ROOM_MAX_PLAYER_NUM); - for (auto& pair : human_hash_) { - if (pair.second->IsAndroid()) { - tmp_humans.push_back(pair.second); - } - } - std::random_shuffle(tmp_humans.begin(), tmp_humans.end()); - for (size_t i = 0; i < accountid_hash_.size(); ++i) { - last_human_hash_[tmp_humans[i]->GetEntityUniId()] = tmp_humans[i]; - a8::SetBitFlag(tmp_humans[i]->status, HS_LastAndroid); - } } Human* Room::GetOneCanEnableAndroid() @@ -2596,42 +2601,85 @@ void Room::SyncFrameData() void Room::CheckShowHand() { + if (show_handed_) { + return; + } if (room_type_ == RT_NewBrid || room_type_ == RT_MidBrid) { - if (alive_count_ <= (int)(accountid_hash_.size() + last_human_hash_.size())) { - std::vector players; - std::vector androids; + int real_player_num = accountid_hash_.size(); + if (room_type_ == RT_MidBrid) { for (auto& pair : accountid_hash_) { - players.push_back(pair.second); - } - for (auto& pair : last_human_hash_) { - androids.push_back(pair.second); - } - for (size_t i = 0; i < players.size(); ++i) { - if (i >= androids.size()) { - break; - } - Player* target = players[i]; - Human* hum = androids[i]; - { - a8::Vec2 pos = target->GetPos(); - a8::Vec2 dir = target->move_dir; - if (rand() % 100 < 80) { - dir.Rotate(a8::RandAngle() / 2.0f); - } else { - dir.Rotate(a8::RandAngle()); + Human* player = pair.second; + real_player_num = 0; + for (Human* hum : *player->team_members) { + if (!hum->real_dead) { + ++real_player_num; } - pos = pos + dir * SHUA_RANGE; - if (OverBorder(pos, hum->GetRadius())) { - pos.x = target->GetPos().x; - if (OverBorder(pos, hum->GetRadius())) { - pos = target->GetPos(); //!!! - } - } - hum->last_human_target = target; - hum->SetPos(pos); - EnableHuman(hum); } + break; } } + if (alive_count_ <= (int)(real_player_num + last_human_hash_.size())) { +#ifdef DEBUG + a8::UdpLog::Instance()->Debug + ( + "showHand %d %d %d %d", + { + alive_count_, + accountid_hash_.size(), + last_human_hash_.size(), + real_player_num + } + ); +#endif + xtimer.AddDeadLineTimerAndAttach + (1, + a8::XParams() + .SetSender(this), + [] (const a8::XParams& param) + { + Room* room = (Room*)param.sender.GetUserData(); + room->ShowHand(); + }, + &xtimer_attacher_.timer_list_); + show_handed_ = true; + } + } +} + +void Room::ShowHand() +{ + std::vector players; + std::vector androids; + for (auto& pair : accountid_hash_) { + players.push_back(pair.second); + } + for (auto& pair : last_human_hash_) { + androids.push_back(pair.second); + } + for (size_t i = 0; i < players.size(); ++i) { + if (i >= androids.size()) { + break; + } + Player* target = players[i]; + Human* hum = androids[i]; + { + a8::Vec2 pos = target->GetPos(); + a8::Vec2 dir = target->move_dir; + if (rand() % 100 < 80) { + dir.Rotate(a8::RandAngle() / 2.0f); + } else { + dir.Rotate(a8::RandAngle()); + } + pos = pos + dir * VIEW_RANGE; + if (OverBorder(pos, hum->GetRadius())) { + pos.x = target->GetPos().x; + if (OverBorder(pos, hum->GetRadius())) { + pos = target->GetPos(); //!!! + } + } + hum->last_human_target = target; + hum->SetPos(pos); + EnableHuman(hum); + } } } diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 02d75e7..c39d9c6 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -192,6 +192,7 @@ private: bool CanAddToScene(Human* hum); void SyncFrameData(); void CheckShowHand(); + void ShowHand(); #ifdef DEBUG void InitDebugInfo(); @@ -223,6 +224,7 @@ private: a8::XTimerAttacher xtimer_attacher_; size_t airdrop_times_ = 0; int newbie_born_point_uniid_ = 0; + bool show_handed_ = false; int current_teamid_ = 0; int current_uniid_ = FIXED_OBJECT_MAXID;