This commit is contained in:
aozhiwei 2023-11-04 20:01:31 +08:00
parent b9a99c15ba
commit d33fa74d75
2 changed files with 53 additions and 96 deletions

View File

@ -7,115 +7,80 @@
#include "mt/Equip.h"
#include "mt/Buff.h"
struct AttrAbsPtr
{
struct AttrAbs* data;
AttrAbsPtr(AttrAbs* data) { this->data = data; };
};
struct AttrAbs
{
list_head entry;
int attr_id;
float value;
std::shared_ptr<AttrAbsPtr> ptr;
std::shared_ptr<AttrAbs> holder;
AttrAbs(int attr_id, float value)
{
this->attr_id = attr_id;
this->value = value;
INIT_LIST_HEAD(&entry);
ptr = std::make_shared<AttrAbsPtr>(this);
}
};
struct AttrRatePtr
{
struct AttrRate* data;
AttrRatePtr(AttrRate* data) { this->data = data; };
};
struct AttrRate
{
list_head entry;
int attr_id;
float value;
std::shared_ptr<AttrRatePtr> ptr;
std::shared_ptr<AttrRate> holder;
AttrRate(int attr_id, float value)
{
this->attr_id = attr_id;
this->value = value;
INIT_LIST_HEAD(&entry);
ptr = std::make_shared<AttrRatePtr>(this);
}
};
struct AttrAdditionPtr
{
struct AttrAddition* data;
AttrAdditionPtr(AttrAddition* data) { this->data = data; };
};
struct AttrAddition
{
list_head entry;
int attr_id;
float value;
std::shared_ptr<AttrAdditionPtr> ptr;
std::shared_ptr<AttrAddition> holder;
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
{
list_head entry;
int attr_id;
float value;
std::shared_ptr<AttrRuducePtr> ptr;
std::shared_ptr<AttrRuduce> holder;
AttrRuduce(int attr_id, float value)
{
this->attr_id = attr_id;
this->value = value;
INIT_LIST_HEAD(&entry);
ptr = std::make_shared<AttrRuducePtr>(this);
}
};
struct AttrDirectPtr
{
struct AttrDirect* data;
AttrDirectPtr(AttrDirect* data) { this->data = data; };
};
struct AttrDirect
{
list_head entry;
int attr_id;
float value;
std::shared_ptr<AttrDirectPtr> ptr;
std::shared_ptr<AttrDirect> holder;
AttrDirect(int attr_id, float value)
{
this->attr_id = attr_id;
this->value = value;
INIT_LIST_HEAD(&entry);
ptr = std::make_shared<AttrDirectPtr>(this);
}
};
@ -164,9 +129,8 @@ void Ability::Clear()
AttrAbs* e = list_first_entry(&std::get<1>(tuple),
AttrAbs,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
for (auto& tuple : attr_rate_) {
@ -175,9 +139,8 @@ void Ability::Clear()
AttrRate* e = list_first_entry(&std::get<1>(tuple),
AttrRate,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
@ -187,9 +150,8 @@ void Ability::Clear()
AttrAddition* e = list_first_entry(&std::get<1>(tuple),
AttrAddition,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
for (auto& tuple : attr_dec_) {
@ -198,9 +160,8 @@ void Ability::Clear()
AttrRuduce* e = list_first_entry(&std::get<1>(tuple),
AttrRuduce,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
@ -210,9 +171,8 @@ void Ability::Clear()
AttrAddition* e = list_first_entry(&std::get<1>(tuple),
AttrAddition,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
for (auto& tuple : vattr_dec_) {
@ -221,9 +181,8 @@ void Ability::Clear()
AttrRuduce* e = list_first_entry(&std::get<1>(tuple),
AttrRuduce,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
for (auto& tuple : attr_direct_) {
@ -232,9 +191,8 @@ void Ability::Clear()
AttrDirect* e = list_first_entry(&std::get<1>(tuple),
AttrDirect,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
@ -283,10 +241,11 @@ bool Ability::CanImmune(const std::set<int>& tags)
AttrAbsHandle Ability::AddAttrAbs(int attr_id, float value)
{
if (IsValidHumanAttr(attr_id)) {
auto p = new AttrAbs(attr_id, value);
auto p = std::make_shared<AttrAbs>(attr_id, value);
p->holder = p;
list_add_tail(&p->entry, &std::get<1>(attr_abs_[attr_id]));
RecalcAttrAbs(attr_id);
return p->ptr;
return p;
}
return AttrAbsHandle();
}
@ -295,19 +254,20 @@ 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;
list_del_init(&p->entry);
RecalcAttrAbs(p->attr_id);
p->holder = nullptr;
}
}
AttrRateHandle Ability::AddAttrRate(int attr_id, float value)
{
if (IsValidHumanAttr(attr_id)) {
auto p = new AttrRate(attr_id, value);
auto p = std::make_shared<AttrRate>(attr_id, value);
p->holder = p;
list_add_tail(&p->entry, &std::get<1>(attr_rate_[attr_id]));
RecalcAttrRate(attr_id);
return p->ptr;
return p;
}
return AttrRateHandle();
}
@ -316,9 +276,9 @@ void Ability::RemoveAttrRate(AttrRateHandle handle)
{
if (!handle.expired()) {
auto p = handle.lock();
list_del_init(&p->data->entry);
RecalcAttrRate(p->data->attr_id);
delete p->data;
list_del_init(&p->entry);
RecalcAttrRate(p->attr_id);
p->holder = nullptr;
}
}
@ -374,14 +334,15 @@ AttrAdditionHandle Ability::AddAttrAddition(int attr_id, float rate)
{
if (IsValidHumanAttr(attr_id) ||
IsValidHumanVirtualAttr(attr_id)) {
auto p = new AttrAddition(attr_id, rate);
auto p = std::make_shared<AttrAddition>(attr_id, rate);
p->holder = p;
if (IsValidHumanAttr(attr_id)) {
list_add_tail(&p->entry, &std::get<1>(attr_add_[attr_id]));
} else {
list_add_tail(&p->entry, &std::get<1>(vattr_add_[attr_id - kHVAT_Begin]));
}
RecalcAttrAddition(attr_id);
return p->ptr;
return p;
}
return AttrAdditionHandle();
}
@ -390,9 +351,9 @@ void Ability::RemoveAttrAddition(AttrAdditionHandle handle)
{
if (!handle.expired()) {
auto p = handle.lock();
list_del_init(&p->data->entry);
RecalcAttrAddition(p->data->attr_id);
delete p->data;
list_del_init(&p->entry);
RecalcAttrAddition(p->attr_id);
p->holder = nullptr;
}
}
@ -400,14 +361,15 @@ AttrRuduceHandle Ability::AddAttrRuduce(int attr_id, float rate)
{
if (IsValidHumanAttr(attr_id) ||
IsValidHumanVirtualAttr(attr_id)) {
auto p = new AttrRuduce(attr_id, rate);
auto p = std::make_shared<AttrRuduce>(attr_id, rate);
p->holder = p;
if (IsValidHumanAttr(attr_id)) {
list_add_tail(&p->entry, &std::get<1>(attr_dec_[attr_id]));
} else {
list_add_tail(&p->entry, &std::get<1>(vattr_dec_[attr_id - kHVAT_Begin]));
}
RecalcAttrRuduce(attr_id);
return p->ptr;
return p;
}
return AttrRuduceHandle();
}
@ -416,9 +378,9 @@ void Ability::RemoveAttrRuduce(AttrRuduceHandle handle)
{
if (!handle.expired()) {
auto p = handle.lock();
list_del_init(&p->data->entry);
RecalcAttrRuduce(p->data->attr_id);
delete p->data;
list_del_init(&p->entry);
RecalcAttrRuduce(p->attr_id);
p->holder = nullptr;
}
}
@ -571,9 +533,8 @@ void Ability::GMClearBaseAttr(int type)
AttrAbs* e = list_first_entry(&std::get<1>(tuple),
AttrAbs,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
for (auto& tuple : attr_rate_) {
@ -582,9 +543,8 @@ void Ability::GMClearBaseAttr(int type)
AttrRate* e = list_first_entry(&std::get<1>(tuple),
AttrRate,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
}
@ -682,9 +642,8 @@ void Ability::GMClearGrowAttr(int type)
AttrAddition* e = list_first_entry(&std::get<1>(tuple),
AttrAddition,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
for (auto& tuple : attr_dec_) {
@ -693,9 +652,8 @@ void Ability::GMClearGrowAttr(int type)
AttrRuduce* e = list_first_entry(&std::get<1>(tuple),
AttrRuduce,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
@ -705,9 +663,8 @@ void Ability::GMClearGrowAttr(int type)
AttrAddition* e = list_first_entry(&std::get<1>(tuple),
AttrAddition,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
for (auto& tuple : vattr_dec_) {
@ -716,9 +673,8 @@ void Ability::GMClearGrowAttr(int type)
AttrRuduce* e = list_first_entry(&std::get<1>(tuple),
AttrRuduce,
entry);
e->ptr->data = nullptr;
list_del_init(&e->entry);
delete e;
e->holder = nullptr;
}
}
}
@ -951,10 +907,11 @@ int Ability::GetSwitchTimes(int type)
AttrDirectHandle Ability::AddAttrDirect(int attr_id, float value)
{
if (IsValidHumanAttr(attr_id)) {
auto p = new AttrDirect(attr_id, value);
auto p = std::make_shared<AttrDirect>(attr_id, value);
p->holder = p;
list_add_tail(&p->entry, &std::get<1>(attr_direct_[attr_id]));
RecalcAttrDirect(attr_id);
return p->ptr;
return p;
}
return AttrDirectHandle();
}
@ -963,9 +920,9 @@ void Ability::RemoveAttrDirect(AttrDirectHandle handle)
{
if (!handle.expired()) {
auto p = handle.lock();
list_del_init(&p->data->entry);
RecalcAttrDirect(p->data->attr_id);
delete p->data;
list_del_init(&p->entry);
RecalcAttrDirect(p->attr_id);
p->holder = nullptr;
}
}

View File

@ -98,11 +98,11 @@ class IBullet
virtual bool NoAdjustPos() = 0;
};
typedef std::weak_ptr<struct AttrAdditionPtr> AttrAdditionHandle;
typedef std::weak_ptr<struct AttrRuducePtr> AttrRuduceHandle;
typedef std::weak_ptr<struct AttrAbsPtr> AttrAbsHandle;
typedef std::weak_ptr<struct AttrRatePtr> AttrRateHandle;
typedef std::weak_ptr<struct AttrDirectPtr> AttrDirectHandle;
typedef std::weak_ptr<struct AttrAddition> AttrAdditionHandle;
typedef std::weak_ptr<struct AttrRuduce> AttrRuduceHandle;
typedef std::weak_ptr<struct AttrAbs> AttrAbsHandle;
typedef std::weak_ptr<struct AttrRate> AttrRateHandle;
typedef std::weak_ptr<struct AttrDirect> AttrDirectHandle;
namespace a8
{