1
This commit is contained in:
parent
d9682382b9
commit
afde903551
@ -7,16 +7,49 @@
|
|||||||
#include "mt/Equip.h"
|
#include "mt/Equip.h"
|
||||||
#include "mt/Buff.h"
|
#include "mt/Buff.h"
|
||||||
|
|
||||||
|
struct AttrAdditionPtr
|
||||||
|
{
|
||||||
|
struct AttrAddition* data;
|
||||||
|
AttrAdditionPtr(AttrAddition* data) { this->data = data; };
|
||||||
|
};
|
||||||
|
|
||||||
struct AttrAddition
|
struct AttrAddition
|
||||||
{
|
{
|
||||||
list_head entry;
|
list_head entry;
|
||||||
|
int attr_id;
|
||||||
float value;
|
float value;
|
||||||
|
std::shared_ptr<AttrAdditionPtr> ptr;
|
||||||
|
|
||||||
|
AttrAddition(int attr_id, float value)
|
||||||
|
{
|
||||||
|
this->attr_id = attr_id;
|
||||||
|
this->value = value;
|
||||||
|
INIT_LIST_HEAD(&entry);
|
||||||
|
ptr = std::make_shared<AttrAdditionPtr>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AttrRuducePtr
|
||||||
|
{
|
||||||
|
struct AttrRuduce* data;
|
||||||
|
AttrRuducePtr(AttrRuduce* data) { this->data = data; };
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AttrRuduce
|
struct AttrRuduce
|
||||||
{
|
{
|
||||||
list_head entry;
|
list_head entry;
|
||||||
|
int attr_id;
|
||||||
float value;
|
float value;
|
||||||
|
std::shared_ptr<AttrRuducePtr> ptr;
|
||||||
|
|
||||||
|
AttrRuduce(int attr_id, float value)
|
||||||
|
{
|
||||||
|
this->attr_id = attr_id;
|
||||||
|
this->value = value;
|
||||||
|
INIT_LIST_HEAD(&entry);
|
||||||
|
ptr = std::make_shared<AttrRuducePtr>(this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ability::Ability(CreatureWeakPtr owner)
|
Ability::Ability(CreatureWeakPtr owner)
|
||||||
@ -70,12 +103,26 @@ void Ability::Clear()
|
|||||||
buff_attr_rate_ = {};
|
buff_attr_rate_ = {};
|
||||||
buff_attr_flag_ = {};
|
buff_attr_flag_ = {};
|
||||||
for (auto& tuple : attr_add_) {
|
for (auto& tuple : attr_add_) {
|
||||||
std::get<0>(tuple) = .0f;
|
std::get<0>(tuple) = 0.0f;
|
||||||
INIT_LIST_HEAD(&std::get<1>(tuple));
|
while (!list_empty(&std::get<1>(tuple))) {
|
||||||
|
AttrAddition* e = list_first_entry(&std::get<1>(tuple),
|
||||||
|
AttrAddition,
|
||||||
|
entry);
|
||||||
|
e->ptr->data = nullptr;
|
||||||
|
list_del_init(&e->entry);
|
||||||
|
delete e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (auto& tuple : attr_dec_) {
|
for (auto& tuple : attr_dec_) {
|
||||||
std::get<0>(tuple) = .0f;
|
std::get<0>(tuple) = 0.0f;
|
||||||
INIT_LIST_HEAD(&std::get<1>(tuple));
|
while (!list_empty(&std::get<1>(tuple))) {
|
||||||
|
AttrRuduce* e = list_first_entry(&std::get<1>(tuple),
|
||||||
|
AttrRuduce,
|
||||||
|
entry);
|
||||||
|
e->ptr->data = nullptr;
|
||||||
|
list_del_init(&e->entry);
|
||||||
|
delete e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,37 +419,37 @@ float Ability::GetFixedSped()
|
|||||||
AttrAdditionHandle Ability::AddAttr(int attr_id, float rate)
|
AttrAdditionHandle Ability::AddAttr(int attr_id, float rate)
|
||||||
{
|
{
|
||||||
if (IsValidHumanAttr(attr_id)) {
|
if (IsValidHumanAttr(attr_id)) {
|
||||||
auto p = std::make_shared<AttrAddition>();
|
auto p = new AttrAddition(attr_id, rate);
|
||||||
p->value = rate;
|
|
||||||
INIT_LIST_HEAD(&p->entry);
|
|
||||||
list_add_tail(&p->entry, &std::get<1>(attr_add_[attr_id]));
|
list_add_tail(&p->entry, &std::get<1>(attr_add_[attr_id]));
|
||||||
return p;
|
return p->ptr;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return AttrAdditionHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ability::RemoveAttrAddition(AttrAdditionHandle handle)
|
void Ability::RemoveAttrAddition(AttrAdditionHandle handle)
|
||||||
{
|
{
|
||||||
if (handle && !list_empty(&handle->entry)) {
|
if (!handle.expired()) {
|
||||||
list_del_init(&handle->entry);
|
auto p = handle.lock();
|
||||||
|
list_del_init(&p->data->entry);
|
||||||
|
delete p->data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AttrRuduceHandle Ability::DecAttr(int attr_id, float rate)
|
AttrRuduceHandle Ability::DecAttr(int attr_id, float rate)
|
||||||
{
|
{
|
||||||
if (IsValidHumanAttr(attr_id)) {
|
if (IsValidHumanAttr(attr_id)) {
|
||||||
auto p = std::make_shared<AttrRuduce>();
|
auto p = new AttrRuduce(attr_id, rate);
|
||||||
p->value = rate;
|
|
||||||
INIT_LIST_HEAD(&p->entry);
|
|
||||||
list_add_tail(&p->entry, &std::get<1>(attr_dec_[attr_id]));
|
list_add_tail(&p->entry, &std::get<1>(attr_dec_[attr_id]));
|
||||||
return p;
|
return p->ptr;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return AttrRuduceHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ability::RemoveAttrRuduce(AttrRuduceHandle handle)
|
void Ability::RemoveAttrRuduce(AttrRuduceHandle handle)
|
||||||
{
|
{
|
||||||
if (handle && !list_empty(&handle->entry)) {
|
if (!handle.expired()) {
|
||||||
list_del_init(&handle->entry);
|
auto p = handle.lock();
|
||||||
|
list_del_init(&p->data->entry);
|
||||||
|
delete p->data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
#include "attrdefine.h"
|
#include "attrdefine.h"
|
||||||
#include "weakptr.h"
|
#include "weakptr.h"
|
||||||
|
|
||||||
typedef std::shared_ptr<struct AttrAddition> AttrAdditionHandle;
|
typedef std::weak_ptr<struct AttrAdditionPtr> AttrAdditionHandle;
|
||||||
typedef std::shared_ptr<struct AttrRuduce> AttrRuduceHandle;
|
typedef std::weak_ptr<struct AttrRuducePtr> AttrRuduceHandle;
|
||||||
|
|
||||||
class Room;
|
class Room;
|
||||||
class Human;
|
class Human;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user