From 6092bea2ba4466bc939fc4ae75d13fcdea9d1dda Mon Sep 17 00:00:00 2001 From: azw Date: Tue, 7 Nov 2023 05:53:32 +0000 Subject: [PATCH] 1 --- server/gameserver/buff/callfunc.cc | 36 +++++++++++++++++++++--------- server/gameserver/buff/callfunc.h | 1 + 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/server/gameserver/buff/callfunc.cc b/server/gameserver/buff/callfunc.cc index 19b1329d..e933b8e6 100644 --- a/server/gameserver/buff/callfunc.cc +++ b/server/gameserver/buff/callfunc.cc @@ -187,6 +187,9 @@ void CallFuncBuff::Activate() void CallFuncBuff::Deactivate() { + if (deactivate_cb_) { + deactivate_cb_(); + } switch ((BuffCallFunc_e)meta->_int_buff_param1) { case BuffCallFunc_e::kAddMinorMode: { @@ -1043,10 +1046,11 @@ void CallFuncBuff::RangeHoldBuff() std::set hit_humans; owner->room->TraverseAliveHumanList ( - [this, range] (Human* hum) + [this, range, &hit_humans] (Human* hum) mutable { if (Collision::CheckCC(owner, owner->GetRadius(), hum, range)) { + hit_humans.insert(hum); } return true; }); @@ -1070,7 +1074,7 @@ void CallFuncBuff::RangeHoldBuff() } } }; - owner->room->xtimer.SetIntervalWpEx + auto check_timer = owner->room->xtimer.SetIntervalWpEx ( SERVER_FRAME_RATE, [this, context, on_enter, on_stay, on_leave, check_cb] @@ -1081,20 +1085,32 @@ void CallFuncBuff::RangeHoldBuff() } }, &owner->xtimer_attacher); + auto clear_func = + [this, context, check_timer] () mutable + { + owner->room->xtimer.Delete(check_timer); + for (auto& pair : context->in_human_infos) { + for (int buff_uniid : pair.second.buff_uniids) { + if (pair.second.c.Get()) { + pair.second.c.Get()->RemoveBuffByUniId(buff_uniid); + } + } + } + context->in_human_infos.clear(); + }; { event_handlers_.push_back(owner->GetTrigger()->AddListener ( kDieEvent, - [this, context] (const a8::Args& args) mutable + [this, clear_func] (const a8::Args& args) mutable { - for (auto& pair : context->in_human_infos) { - for (int buff_uniid : pair.second.buff_uniids) { - if (pair.second.c.Get()) { - pair.second.c.Get()->RemoveBuffByUniId(buff_uniid); - } - } - } + clear_func(); } )); + deactivate_cb_ = + [this, clear_func] () mutable + { + clear_func(); + }; } } diff --git a/server/gameserver/buff/callfunc.h b/server/gameserver/buff/callfunc.h index f090fde9..d4fa7666 100644 --- a/server/gameserver/buff/callfunc.h +++ b/server/gameserver/buff/callfunc.h @@ -66,4 +66,5 @@ class CallFuncBuff : public Buff float hold_param2_ = 0.0; Weapon* hold_weapon_ = nullptr; + std::function deactivate_cb_ = nullptr; };