From c56483e85d6552321ba0f9c2060fef29dd1dd112 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 30 Jun 2021 09:50:35 +0000 Subject: [PATCH] add coexist_num --- server/gameserver/creature.cc | 26 +++++++++++++++++++++---- server/gameserver/creature.h | 2 ++ server/tools/protobuild/metatable.proto | 1 + 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index cf0211c..8b99dcd 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -163,16 +163,27 @@ Buff* Creature::GetBuffById(int buff_id) return nullptr; } +int Creature::GetBuffNum(int buff_id) +{ + int num = 0; + for (Buff& buff : buff_list_) { + if (buff.meta->i->buff_id() == buff_id) { + ++num; + } + } + return num; +} + void Creature::AddBuff(Creature* caster, MetaData::Buff* buff_meta, int skill_lv, MetaData::Skill* buff_skill_meta) { - #if 0 - if (GetBuffById(buff_meta->i->buff_id())) { - return; + if (buff_meta->i->coexist_num() > 0){ + if (GetBuffNum(buff_meta->i->buff_id()) >= buff_meta->i->coexist_num()) { + return; + } } - #endif if (IsImmuneBuffEffect(buff_meta->i->buff_effect())) { return; } @@ -345,6 +356,13 @@ void Creature::RemoveBuffById(int buff_id) #endif } +void Creature::ClearBuffById(int buff_id) +{ + while (GetBuffById(buff_id)) { + RemoveBuffById(buff_id); + } +} + void Creature::SendDebugMsg(const std::string& debug_msg) { diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index ad636e5..764946e 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -93,6 +93,7 @@ class Creature : public MoveableEntity bool HasBuffEffect(int buff_effect_id); Buff* GetBuffByEffectId(int effect_id); Buff* GetBuffById(int buff_id); + int GetBuffNum(int buff_id); void AddBuff(Creature* caster, MetaData::Buff* buff_meta, int skill_lv, @@ -101,6 +102,7 @@ class Creature : public MoveableEntity void MustBeAddBuff(Creature* caster, int buff_id); void TryAddBuff(Creature* caster, int buff_id); void RemoveBuffById(int buff_id); + void ClearBuffById(int buff_id); void RecalcBuffAttr(); void RemoveBuffByEffectId(int buff_effect_id); void ClearBuffList(); diff --git a/server/tools/protobuild/metatable.proto b/server/tools/protobuild/metatable.proto index 36379e0..893bda3 100755 --- a/server/tools/protobuild/metatable.proto +++ b/server/tools/protobuild/metatable.proto @@ -247,6 +247,7 @@ message Buff optional int32 only_self = 15; optional int32 depend_effect = 16; optional string child_buff = 17; + optional int32 coexist_num = 18; } message Drop