From a4f826ec22cb26da53ddf15b102ca0215b6ddbb5 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 17 Aug 2023 14:03:57 +0800 Subject: [PATCH] 1 --- server/gameserver/incubator.cc | 52 ++++++++++++++++++++++++++++++---- server/gameserver/incubator.h | 1 + 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/server/gameserver/incubator.cc b/server/gameserver/incubator.cc index 02a06db6..bb7b361b 100644 --- a/server/gameserver/incubator.cc +++ b/server/gameserver/incubator.cc @@ -206,6 +206,7 @@ void Incubator::RecycleAndroid(Human* hum) hum->RemoveBuffByEffectId(kBET_BeRecycle); hold_humans_.push_back(hum); room->DisableHuman(hum); + Rearrangement(); #ifdef DEBUG room->BroadcastDebugMsg(a8::Format("回收机器人 %d:%s:%d 添加到回收列表", {hum->GetUniId(), @@ -516,14 +517,11 @@ void Incubator::ShowHand() room->EnableHuman(hum); hum->MustBeAddBuff(hum, kTraceBuffId); a8::SetBitFlag(hum->status, CS_CrazeMode); - #if 0 a8::SetBitFlag(hum->status, CS_DisableAttackAndroid); - #endif } - #if 0 room->xtimer.SetIntervalEx ( - SERVER_FRAME_RATE, + SERVER_FRAME_RATE * 40, [room = room] (int event, const a8::Args* args) mutable { if (a8::TIMER_EXEC_EVENT == event) { @@ -540,7 +538,6 @@ void Incubator::ShowHand() } }, &room->xtimer_attacher_); - #endif hold_humans_.clear(); } @@ -556,3 +553,48 @@ void Incubator::Clear(int save_num) hold_humans_.erase(hold_humans_.begin()); } } + +void Incubator::Rearrangement() +{ + if (hold_humans_.size() < 6) { + return; + } + std::vector teams2; + std::vector teams3; + std::vector teams4; + { + std::map team_num_hash; + for (auto hum : hold_humans_) { + if (team_num_hash.find(hum->team_id) != team_num_hash.end()) { + ++team_num_hash[hum->team_id]; + } else { + team_num_hash[hum->team_id]; + } + } + for (auto& pair : team_num_hash) { + if (pair.second > 1) { + teams2.push_back(pair.first); + } + if (pair.second > 2) { + teams3.push_back(pair.first); + } + if (pair.second > 3) { + teams4.push_back(pair.first); + } + } + } + int team_id = 0; + if (!teams3.empty() || !teams4.empty()) { + if (a8::RandEx(1, 99) < 10 && !teams4.empty()) { + team_id = teams4.at(rand() % teams4.size()); + } else { + if (!teams3.empty()) { + team_id = teams3.at(rand() % teams3.size()); + } else if (!teams4.empty()) { + team_id = teams4.at(rand() % teams4.size()); + } + } + } else if (!teams2.empty()) { + team_id = teams2.at(rand() % teams2.size()); + } +} diff --git a/server/gameserver/incubator.h b/server/gameserver/incubator.h index dce12013..76faa197 100644 --- a/server/gameserver/incubator.h +++ b/server/gameserver/incubator.h @@ -26,6 +26,7 @@ private: void AutoAllocAndroid(); void OnEnterNewWave(int wave); void SpawnWaveMon(int wave); + void Rearrangement(); private: int wait_alloc_time_ = 0;