From d9682382b99018edea54a1c8ecce28b82100fbaa Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 26 Mar 2023 18:31:29 +0800 Subject: [PATCH] 1 --- server/gameserver/ability.cc | 30 ++++++++++++++++++++++++------ server/gameserver/ability.h | 4 ++-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/server/gameserver/ability.cc b/server/gameserver/ability.cc index 13a2a88d..f8cb5e90 100644 --- a/server/gameserver/ability.cc +++ b/server/gameserver/ability.cc @@ -371,20 +371,38 @@ float Ability::GetFixedSped() AttrAdditionHandle Ability::AddAttr(int attr_id, float rate) { - + if (IsValidHumanAttr(attr_id)) { + auto p = std::make_shared(); + p->value = rate; + INIT_LIST_HEAD(&p->entry); + list_add_tail(&p->entry, &std::get<1>(attr_add_[attr_id])); + return p; + } + return nullptr; } -void Ability::RemoveAttrAddition(AttrAdditionHandle handler) +void Ability::RemoveAttrAddition(AttrAdditionHandle handle) { - + if (handle && !list_empty(&handle->entry)) { + list_del_init(&handle->entry); + } } AttrRuduceHandle Ability::DecAttr(int attr_id, float rate) { - + if (IsValidHumanAttr(attr_id)) { + auto p = std::make_shared(); + p->value = rate; + INIT_LIST_HEAD(&p->entry); + list_add_tail(&p->entry, &std::get<1>(attr_dec_[attr_id])); + return p; + } + return nullptr; } -void Ability::RemoveAttrRuduce(AttrRuduceHandle handler) +void Ability::RemoveAttrRuduce(AttrRuduceHandle handle) { - + if (handle && !list_empty(&handle->entry)) { + list_del_init(&handle->entry); + } } diff --git a/server/gameserver/ability.h b/server/gameserver/ability.h index 084ea6d4..92abd552 100644 --- a/server/gameserver/ability.h +++ b/server/gameserver/ability.h @@ -3,8 +3,8 @@ #include "attrdefine.h" #include "weakptr.h" -typedef std::weak_ptr AttrAdditionHandle; -typedef std::weak_ptr AttrRuduceHandle; +typedef std::shared_ptr AttrAdditionHandle; +typedef std::shared_ptr AttrRuduceHandle; class Room; class Human;