This commit is contained in:
aozhiwei 2022-12-25 14:09:03 +08:00
parent 947ba92d2e
commit 671be7a7f2
3 changed files with 37 additions and 27 deletions

View File

@ -30,7 +30,7 @@ namespace mt
} }
} }
int AirDrop::RandDrop() int AirDrop::RandDrop() const
{ {
if (HasDrop()) { if (HasDrop()) {
int total_weight = std::get<1>(_drop[_drop.size() - 1]); int total_weight = std::get<1>(_drop[_drop.size() - 1]);
@ -44,4 +44,15 @@ namespace mt
return 0; return 0;
} }
void AirDrop::Traverse(std::function<void (const AirDrop*, bool&)> cb)
{
bool stop = false;
for (auto& itr : raw_list) {
cb(itr, stop);
if (stop) {
break;
}
}
}
} }

View File

@ -11,10 +11,12 @@ namespace mt
"id") "id")
public: public:
bool HasDrop() { return !_drop.empty();}; bool HasDrop() const { return !_drop.empty();};
void Init1(); void Init1();
int RandDrop(); int RandDrop() const;
static void Traverse(std::function<void (const AirDrop*, bool&)> cb);
private: private:
std::vector<std::tuple<int, int>> _drop; std::vector<std::tuple<int, int>> _drop;

View File

@ -1721,30 +1721,27 @@ void Room::CombineTeam()
void Room::InitAirDrop() void Room::InitAirDrop()
{ {
// 111 mt::AirDrop::Traverse
#if 0 (
{ [this] (const mt::AirDrop* air_drop_meta, bool& stop)
std::list<const mt::AirDrop>& air_drops = MetaMgr::Instance()->GetAirDrops(); {
for (auto& air_drop : air_drops) { if (air_drop_meta->id() >= 1 && air_drop_meta->id() <= 6) {
if (air_drop.pb->id() >= 1 && air_drop.pb->id() <= 6) { xtimer.SetTimeoutEx
xtimer.SetTimeoutEx (SERVER_FRAME_RATE * air_drop_meta->time(),
(SERVER_FRAME_RATE * air_drop.pb->time(), [this, air_drop_meta] (int event, const a8::Args* args) mutable
[this, air_drop] (int event, const a8::Args* args) mutable {
{ if (a8::TIMER_EXEC_EVENT == event) {
if (a8::TIMER_EXEC_EVENT == event) { if (!IsGameOver()) {
if (!IsGameOver()) { AirDrop(
AirDrop( air_drop_meta->appear_time(),
air_drop.pb->appear_time(), air_drop_meta->RandDrop(),
air_drop.RandDrop(), air_drop_meta->id());
air_drop.pb->id()); }
} }
} },
}, &xtimer_attacher_);
&xtimer_attacher_); }
} });
}
}
#endif
} }
void Room::AirDrop(int appear_time, int box_id, int airdrop_id) void Room::AirDrop(int appear_time, int box_id, int airdrop_id)