From 1c94dc614852b1c7e12c656a1734f32a778146bc Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 25 Feb 2023 09:12:59 +0800 Subject: [PATCH] 1 --- server/gameserver/creature.cc | 10 +++++++++- server/gameserver/creature.h | 3 ++- server/gameserver/gungrasp.cc | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index 369d7840..af045f72 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -2733,13 +2733,14 @@ void Creature::ClearEnergyShield() true); } -int Creature::AddEffect(int effect_id) +std::weak_ptr Creature::AddEffect(int effect_id) { auto effect = std::make_shared(); effect->effect_uniid = ++buff_uniid_; effect->owner = this; effect->effect_id = effect_id; effect_hash_[effect->effect_uniid] = effect; + return effect; } void Creature::RemoveEffect(int effect_uniid) @@ -2747,6 +2748,13 @@ void Creature::RemoveEffect(int effect_uniid) effect_hash_.erase(effect_uniid); } +void Creature::RemoveEffect(std::weak_ptr effect) +{ + if (!effect.expired()) { + RemoveEffect(effect.lock()->effect_uniid); + } +} + void Creature::RemoveEffects(std::vector effect_uniids) { for (int effect_uniid : effect_uniids) { diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index 47cf3771..7c72785e 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -181,7 +181,8 @@ class Creature : public MoveableEntity void UpdatePoisoning(); Team* GetTeam() { return team_; } void SetTeam(Team* team) { team_ = team; } - int AddEffect(int effect_id); + std::weak_ptr AddEffect(int effect_id); + void RemoveEffect(std::weak_ptr effect); void RemoveEffect(int effect_uniid); void RemoveEffects(std::vector effect_uniids); void ClearEffect(); diff --git a/server/gameserver/gungrasp.cc b/server/gameserver/gungrasp.cc index 9afbbf66..850b30da 100644 --- a/server/gameserver/gungrasp.cc +++ b/server/gameserver/gungrasp.cc @@ -21,6 +21,7 @@ struct GraspBuff std::tuple buffs; std::function on_remove; a8::Attacher xtimer_attacher; + std::vector>> effect_list; void ProcSignet(GunGrasp* gun_grasp, int count, Creature* enemy) { @@ -88,6 +89,23 @@ private: } } + void ProcEffectList(Creature* target, const mt::GraspBuff* buff, int buff_time, int attr_num) + { + for (int effect_id : buff->_effect_list) { + effect_list.push_back(std::make_tuple(target->GetWeakPtrRef(), target->AddEffect(effect_id))); + } + } + + void ClearEffectList() + { + for (auto& tuple : effect_list) { + if (std::get<0>(tuple).Get()) { + std::get<0>(tuple).Get()->RemoveEffect(std::get<1>(tuple)); + } + } + effect_list.clear(); + } + }; GunGrasp::GunGrasp(Creature* owner)