From 671be7a7f2cf23cd407370a3670f6677e7d859ee Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 25 Dec 2022 14:09:03 +0800 Subject: [PATCH] 1 --- server/gameserver/mt/AirDrop.cc | 13 +++++++++- server/gameserver/mt/AirDrop.h | 6 +++-- server/gameserver/room.cc | 45 +++++++++++++++------------------ 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/server/gameserver/mt/AirDrop.cc b/server/gameserver/mt/AirDrop.cc index 09f59778..d249aede 100644 --- a/server/gameserver/mt/AirDrop.cc +++ b/server/gameserver/mt/AirDrop.cc @@ -30,7 +30,7 @@ namespace mt } } - int AirDrop::RandDrop() + int AirDrop::RandDrop() const { if (HasDrop()) { int total_weight = std::get<1>(_drop[_drop.size() - 1]); @@ -44,4 +44,15 @@ namespace mt return 0; } + void AirDrop::Traverse(std::function cb) + { + bool stop = false; + for (auto& itr : raw_list) { + cb(itr, stop); + if (stop) { + break; + } + } + } + } diff --git a/server/gameserver/mt/AirDrop.h b/server/gameserver/mt/AirDrop.h index 8fd73390..0e6006b9 100644 --- a/server/gameserver/mt/AirDrop.h +++ b/server/gameserver/mt/AirDrop.h @@ -11,10 +11,12 @@ namespace mt "id") public: - bool HasDrop() { return !_drop.empty();}; + bool HasDrop() const { return !_drop.empty();}; void Init1(); - int RandDrop(); + int RandDrop() const; + + static void Traverse(std::function cb); private: std::vector> _drop; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 56d082f7..bc4fa1f5 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -1721,30 +1721,27 @@ void Room::CombineTeam() void Room::InitAirDrop() { - // 111 - #if 0 - { - std::list& air_drops = MetaMgr::Instance()->GetAirDrops(); - for (auto& air_drop : air_drops) { - if (air_drop.pb->id() >= 1 && air_drop.pb->id() <= 6) { - xtimer.SetTimeoutEx - (SERVER_FRAME_RATE * air_drop.pb->time(), - [this, air_drop] (int event, const a8::Args* args) mutable - { - if (a8::TIMER_EXEC_EVENT == event) { - if (!IsGameOver()) { - AirDrop( - air_drop.pb->appear_time(), - air_drop.RandDrop(), - air_drop.pb->id()); - } - } - }, - &xtimer_attacher_); - } - } - } - #endif + mt::AirDrop::Traverse + ( + [this] (const mt::AirDrop* air_drop_meta, bool& stop) + { + if (air_drop_meta->id() >= 1 && air_drop_meta->id() <= 6) { + xtimer.SetTimeoutEx + (SERVER_FRAME_RATE * air_drop_meta->time(), + [this, air_drop_meta] (int event, const a8::Args* args) mutable + { + if (a8::TIMER_EXEC_EVENT == event) { + if (!IsGameOver()) { + AirDrop( + air_drop_meta->appear_time(), + air_drop_meta->RandDrop(), + air_drop_meta->id()); + } + } + }, + &xtimer_attacher_); + } + }); } void Room::AirDrop(int appear_time, int box_id, int airdrop_id)