From 0c9671ac5c3a5b07a6be843d8ec4820db46ea0ed Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 30 Jul 2024 19:48:35 +0800 Subject: [PATCH] 1 --- server/gameserver/boxdrop.cc | 9 +++++++-- server/gameserver/boxdrop.h | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/gameserver/boxdrop.cc b/server/gameserver/boxdrop.cc index ac5a8514..c32130b2 100644 --- a/server/gameserver/boxdrop.cc +++ b/server/gameserver/boxdrop.cc @@ -32,14 +32,14 @@ void BoxDrop::UnInit() void BoxDrop::OnHeroDeadDrop(Hero* hero) { - if (box_num_ > 0) { + if (GetRemainNum() > 0) { Drop(1, hero->GetPos().ToGlmVec3()); } } void BoxDrop::OnObstacleDeadDrop(Obstacle* ob) { - if (box_num_ > 0) { + if (GetRemainNum() > 0) { Drop(1, ob->GetPos().ToGlmVec3()); } } @@ -153,3 +153,8 @@ void BoxDrop::RequestReturnBoxNum() ); } } + +int BoxDrop::GetRemainNum() +{ + return std::max(0, alloc_box_num_ - used_num_); +} diff --git a/server/gameserver/boxdrop.h b/server/gameserver/boxdrop.h index 056ec446..9dee3435 100644 --- a/server/gameserver/boxdrop.h +++ b/server/gameserver/boxdrop.h @@ -20,11 +20,12 @@ class BoxDrop : public std::enable_shared_from_this void Drop(int num, const glm::vec3& center); void RequestAllocBoxNum(); + int GetRemainNum(); private: Room* room_ = nullptr; a8::XTimerWp get_box_num_timer_; - int box_num_ = 0; + int used_num_ = 0; int alloc_box_num_ = 0; bool returned_ = false; };