From 6e46e42ac30e4aec7f2d80ce8c797beda8f0e5a8 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 24 Feb 2023 20:20:45 +0800 Subject: [PATCH] 1 --- server/gameserver/creature.cc | 25 +++++++++++++++++++------ server/gameserver/creature.h | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index 2c0753c0..2e16f5bf 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -21,6 +21,7 @@ #include "mapinstance.h" #include "collision.h" #include "gungrasp.h" +#include "effect.h" #include "mt/Param.h" #include "mt/Hero.h" @@ -2718,25 +2719,37 @@ void Creature::ClearEnergyShield() int 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; } void Creature::RemoveEffect(int effect_uniid) { - + effect_hash_.erase(effect_uniid); } void Creature::RemoveEffects(std::vector effect_uniids) { - + for (int effect_uniid : effect_uniids) { + RemoveEffect(effect_uniid); + } } void Creature::ClearEffect() { - + effect_hash_.clear(); } -void Creature::TraverseEffect(std::function func) +void Creature::TraverseEffect(std::function cb) { - + for (auto& pair : effect_hash_) { + bool stop = false; + cb(pair.second.get(), stop); + if (stop) { + break; + } + } } diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index a21871fd..5a8ab310 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -364,7 +364,7 @@ private: std::array depend_effect_ = {}; std::array cond_buffs_ = {}; std::list> buff_list_; - std::list> effect_list_; + std::map> effect_hash_; std::list> slave_heros_; std::list> slave_things_; a8::XTimerWp auto_switch_weapon_timer_;