From ddd77d25d23b8c7d168d11e6f2ba8c3f502dbeb6 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 22 Apr 2020 13:35:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E5=90=8E=E7=BB=84=E9=98=9F?= =?UTF-8?q?=E7=8E=A9=E5=AE=B6=E8=B7=B3=E5=88=B0=E7=BB=9F=E4=B8=80=E7=9A=84?= =?UTF-8?q?=E5=87=BA=E7=94=9F=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/room.cc | 111 ++++++++++++++++++++++++-------------- server/gameserver/room.h | 2 + 2 files changed, 72 insertions(+), 41 deletions(-) diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index c5e2b5f..bbec051 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -1635,23 +1635,7 @@ BornPoint* Room::AllocBornPoint(Human* hum) } } if (pre_point) { - switch (hum->entity_subtype) { - case EST_Player: - { - --pre_point->player_num; - } - break; - case EST_Android: - { - --pre_point->android_num; - } - break; - default: - { - - } - break; - } + DecBornPointHumanNum(pre_point, hum); } if (!free_point_list.empty()) { born_point = free_point_list[rand() % free_point_list.size()]; @@ -1667,22 +1651,7 @@ BornPoint* Room::AllocBornPoint(Human* hum) } } if (born_point) { - switch (hum->entity_subtype) { - case EST_Player: - { - ++born_point->player_num; - } - break; - case EST_Android: - { - ++born_point->android_num; - } - break; - default: - { - } - break; - } + DecBornPointHumanNum(born_point, hum); } return born_point; } @@ -1731,20 +1700,80 @@ void Room::CreateMapSpawnPoint(MetaData::MapTplThing& thing_tpl) born_point_hash_[AllocUniid()] = born_point; } +void Room::IncBornPointHumanNum(BornPoint* point, Human* hum) +{ + switch (hum->entity_subtype) { + case EST_Player: + { + ++point->player_num; + } + break; + case EST_Android: + { + ++point->android_num; + } + break; + default: + { + } + break; + } +} + +void Room::DecBornPointHumanNum(BornPoint* point, Human* hum) +{ + switch (hum->entity_subtype) { + case EST_Player: + { + --point->player_num; + } + break; + case EST_Android: + { + --point->android_num; + } + break; + default: + { + + } + break; + } +} + void Room::SecondRandPoint() { for (auto& pair : accountid_hash_) { Human* hum = pair.second; hum->born_point = AllocBornPoint(hum); - if (!hum->born_point) { - hum->SetX(DEFAULT_BORN_POINT_X + rand() % 100); - hum->SetY(DEFAULT_BORN_POINT_Y + rand() % 200); - } else { - hum->SetPos(hum->born_point->RandPoint()); + } + for (auto& pair : team_hash_) { + if (pair.second.size() < 2) { + continue; + } + Human* target = nullptr; + for (Human* hum : pair.second) { + if (!target) { + target = hum; + } else { + if (target->born_point) { + if (hum->born_point) { + DecBornPointHumanNum(hum->born_point, hum); + } + hum->born_point = target->born_point; + if (!hum->born_point) { + hum->SetX(DEFAULT_BORN_POINT_X + rand() % 100); + hum->SetY(DEFAULT_BORN_POINT_Y + rand() % 200); + } else { + IncBornPointHumanNum(hum->born_point, hum); + hum->SetPos(hum->born_point->RandPoint()); + } + hum->FindLocation(); + hum->RefreshView(); + grid_service.MoveHuman(hum); + } + } } - hum->FindLocation(); - hum->RefreshView(); - grid_service.MoveHuman(hum); } } diff --git a/server/gameserver/room.h b/server/gameserver/room.h index e0b307b..4c704cc 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -135,6 +135,8 @@ private: BornPoint* AllocBornPoint(Human* hum); void CreateMapObject(MetaData::MapTplThing& thing_tpl); void CreateMapSpawnPoint(MetaData::MapTplThing& thing_tpl); + void IncBornPointHumanNum(BornPoint* point, Human* hum); + void DecBornPointHumanNum(BornPoint* point, Human* hum); void SecondRandPoint(); void NotifyGameStart();