diff --git a/server/gameserver/ability.cc b/server/gameserver/ability.cc index 872174bc..30c63f80 100644 --- a/server/gameserver/ability.cc +++ b/server/gameserver/ability.cc @@ -473,42 +473,92 @@ float Ability::GetFixedSped() AttrAbsHandle Ability::AddAttrAbs(int attr_id, float value) { - + if (IsValidHumanAttr(attr_id)) { + auto p = new AttrAbs(attr_id, value); + list_add_tail(&p->entry, &std::get<1>(attr_abs_[attr_id])); + RecalcAttrAbs(attr_id); + return p->ptr; + } + return AttrAbsHandle(); } void Ability::RemoveAttrAbs(AttrAbsHandle handle) { - + if (!handle.expired()) { + auto p = handle.lock(); + list_del_init(&p->data->entry); + RecalcAttrAbs(p->data->attr_id); + delete p->data; + } } AttrRateHandle Ability::AddAttrRate(int attr_id, float value) { - + if (IsValidHumanAttr(attr_id)) { + auto p = new AttrRate(attr_id, value); + list_add_tail(&p->entry, &std::get<1>(attr_abs_[attr_id])); + RecalcAttrRate(attr_id); + return p->ptr; + } + return AttrRateHandle(); } void Ability::RemoveAttrRate(AttrAbsHandle handle) { - + if (!handle.expired()) { + auto p = handle.lock(); + list_del_init(&p->data->entry); + RecalcAttrRate(p->data->attr_id); + delete p->data; + } } void Ability::RecalcAttrAbs(int attr_id) { - + list_head* head = &std::get<1>(attr_abs_[attr_id]); + list_head* pos = nullptr; + list_head* next = nullptr; + float new_val = 0.0f; + list_for_each_safe(pos, next, head) { + AttrAbs* e = list_entry(pos, + AttrAbs, + entry); + new_val += e->value; + } + std::get<0>(attr_abs_[attr_id]) = new_val; } void Ability::RecalcAttrRate(int attr_id) { - + list_head* head = &std::get<1>(attr_rate_[attr_id]); + list_head* pos = nullptr; + list_head* next = nullptr; + float new_val = 0.0f; + list_for_each_safe(pos, next, head) { + AttrRate* e = list_entry(pos, + AttrRate, + entry); + new_val += e->value; + } + std::get<0>(attr_rate_[attr_id]) = new_val; } float Ability::GetAttrAbs(int attr_id) { - return 0.0f; + if (IsValidHumanAttr(attr_id)) { + return std::get<0>(attr_abs_[attr_id]); + } else { + return 0.0f; + } } float Ability::GetAttrRate(int attr_id) { - return 0.0f; + if (IsValidHumanAttr(attr_id)) { + return std::get<0>(attr_rate_[attr_id]); + } else { + return 0.0f; + } } AttrAdditionHandle Ability::AddAttr(int attr_id, float rate)