1
This commit is contained in:
parent
afde903551
commit
be32a8af4f
@ -421,6 +421,7 @@ AttrAdditionHandle Ability::AddAttr(int attr_id, float rate)
|
|||||||
if (IsValidHumanAttr(attr_id)) {
|
if (IsValidHumanAttr(attr_id)) {
|
||||||
auto p = new AttrAddition(attr_id, rate);
|
auto p = new AttrAddition(attr_id, rate);
|
||||||
list_add_tail(&p->entry, &std::get<1>(attr_add_[attr_id]));
|
list_add_tail(&p->entry, &std::get<1>(attr_add_[attr_id]));
|
||||||
|
RecalcAttrAddition(attr_id);
|
||||||
return p->ptr;
|
return p->ptr;
|
||||||
}
|
}
|
||||||
return AttrAdditionHandle();
|
return AttrAdditionHandle();
|
||||||
@ -431,6 +432,7 @@ void Ability::RemoveAttrAddition(AttrAdditionHandle handle)
|
|||||||
if (!handle.expired()) {
|
if (!handle.expired()) {
|
||||||
auto p = handle.lock();
|
auto p = handle.lock();
|
||||||
list_del_init(&p->data->entry);
|
list_del_init(&p->data->entry);
|
||||||
|
RecalcAttrAddition(p->data->attr_id);
|
||||||
delete p->data;
|
delete p->data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -440,6 +442,7 @@ AttrRuduceHandle Ability::DecAttr(int attr_id, float rate)
|
|||||||
if (IsValidHumanAttr(attr_id)) {
|
if (IsValidHumanAttr(attr_id)) {
|
||||||
auto p = new AttrRuduce(attr_id, rate);
|
auto p = new AttrRuduce(attr_id, rate);
|
||||||
list_add_tail(&p->entry, &std::get<1>(attr_dec_[attr_id]));
|
list_add_tail(&p->entry, &std::get<1>(attr_dec_[attr_id]));
|
||||||
|
RecalcAttrRuduce(attr_id);
|
||||||
return p->ptr;
|
return p->ptr;
|
||||||
}
|
}
|
||||||
return AttrRuduceHandle();
|
return AttrRuduceHandle();
|
||||||
@ -450,6 +453,43 @@ void Ability::RemoveAttrRuduce(AttrRuduceHandle handle)
|
|||||||
if (!handle.expired()) {
|
if (!handle.expired()) {
|
||||||
auto p = handle.lock();
|
auto p = handle.lock();
|
||||||
list_del_init(&p->data->entry);
|
list_del_init(&p->data->entry);
|
||||||
|
RecalcAttrRuduce(p->data->attr_id);
|
||||||
delete p->data;
|
delete p->data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Ability::RecalcAttrAddition(int attr_id)
|
||||||
|
{
|
||||||
|
if (!IsValidHumanAttr(attr_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
list_head* pos = nullptr;
|
||||||
|
list_head* next = nullptr;
|
||||||
|
list_head* head = &std::get<1>(attr_add_[attr_id]);
|
||||||
|
float new_val = 0.0f;
|
||||||
|
list_for_each_safe(pos, next, head) {
|
||||||
|
AttrAddition* e = list_entry(pos,
|
||||||
|
AttrAddition,
|
||||||
|
entry);
|
||||||
|
new_val += e->value;
|
||||||
|
}
|
||||||
|
std::get<0>(attr_add_[attr_id]) = new_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ability::RecalcAttrRuduce(int attr_id)
|
||||||
|
{
|
||||||
|
if (!IsValidHumanAttr(attr_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
list_head* pos = nullptr;
|
||||||
|
list_head* next = nullptr;
|
||||||
|
list_head* head = &std::get<1>(attr_dec_[attr_id]);
|
||||||
|
float new_val = 0.0f;
|
||||||
|
list_for_each_safe(pos, next, head) {
|
||||||
|
AttrRuduce* e = list_entry(pos,
|
||||||
|
AttrRuduce,
|
||||||
|
entry);
|
||||||
|
new_val += e->value;
|
||||||
|
}
|
||||||
|
std::get<0>(attr_dec_[attr_id]) = new_val;
|
||||||
|
}
|
||||||
|
@ -71,6 +71,8 @@ class Ability
|
|||||||
void RemoveAttrAddition(AttrAdditionHandle handler);
|
void RemoveAttrAddition(AttrAdditionHandle handler);
|
||||||
AttrRuduceHandle DecAttr(int attr_id, float rate);
|
AttrRuduceHandle DecAttr(int attr_id, float rate);
|
||||||
void RemoveAttrRuduce(AttrRuduceHandle handler);
|
void RemoveAttrRuduce(AttrRuduceHandle handler);
|
||||||
|
void RecalcAttrAddition(int attr_id);
|
||||||
|
void RecalcAttrRuduce(int attr_id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CreatureWeakPtr owner_;
|
CreatureWeakPtr owner_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user