1
This commit is contained in:
parent
5073a6fc63
commit
6ce1e21da3
@ -97,6 +97,28 @@ struct AttrRuduce
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
AttrDirect(int attr_id, float value)
|
||||||
|
{
|
||||||
|
this->attr_id = attr_id;
|
||||||
|
this->value = value;
|
||||||
|
INIT_LIST_HEAD(&entry);
|
||||||
|
ptr = std::make_shared<AttrDirectPtr>(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Ability::Ability(CreatureWeakPtr owner)
|
Ability::Ability(CreatureWeakPtr owner)
|
||||||
{
|
{
|
||||||
for (auto& tuple : attr_abs_) {
|
for (auto& tuple : attr_abs_) {
|
||||||
@ -123,11 +145,14 @@ Ability::Ability(CreatureWeakPtr owner)
|
|||||||
std::get<0>(tuple) = 0.0f;
|
std::get<0>(tuple) = 0.0f;
|
||||||
INIT_LIST_HEAD(&std::get<1>(tuple));
|
INIT_LIST_HEAD(&std::get<1>(tuple));
|
||||||
}
|
}
|
||||||
|
for (auto& tuple : attr_direct_) {
|
||||||
|
std::get<0>(tuple) = 0.0f;
|
||||||
|
INIT_LIST_HEAD(&std::get<1>(tuple));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ability::Clear()
|
void Ability::Clear()
|
||||||
{
|
{
|
||||||
|
|
||||||
for (auto& tuple : attr_abs_) {
|
for (auto& tuple : attr_abs_) {
|
||||||
std::get<0>(tuple) = 0.0f;
|
std::get<0>(tuple) = 0.0f;
|
||||||
while (!list_empty(&std::get<1>(tuple))) {
|
while (!list_empty(&std::get<1>(tuple))) {
|
||||||
@ -196,6 +221,17 @@ void Ability::Clear()
|
|||||||
delete e;
|
delete e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (auto& tuple : attr_direct_) {
|
||||||
|
std::get<0>(tuple) = 0.0f;
|
||||||
|
while (!list_empty(&std::get<1>(tuple))) {
|
||||||
|
AttrDirect* e = list_first_entry(&std::get<1>(tuple),
|
||||||
|
AttrDirect,
|
||||||
|
entry);
|
||||||
|
e->ptr->data = nullptr;
|
||||||
|
list_del_init(&e->entry);
|
||||||
|
delete e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch_times_ = {};
|
switch_times_ = {};
|
||||||
immune_tags_.clear();
|
immune_tags_.clear();
|
||||||
@ -906,3 +942,48 @@ int Ability::GetSwitchTimes(int type)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AttrDirectHandle Ability::AddAttrDirect(int attr_id, float value)
|
||||||
|
{
|
||||||
|
if (IsValidHumanAttr(attr_id)) {
|
||||||
|
auto p = new AttrDirect(attr_id, value);
|
||||||
|
list_add_tail(&p->entry, &std::get<1>(attr_direct_[attr_id]));
|
||||||
|
RecalcAttrDirect(attr_id);
|
||||||
|
return p->ptr;
|
||||||
|
}
|
||||||
|
return AttrDirectHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float Ability::GetAttrDirect(int attr_id)
|
||||||
|
{
|
||||||
|
if (IsValidHumanAttr(attr_id)) {
|
||||||
|
return std::get<0>(attr_direct_[attr_id]);
|
||||||
|
} else {
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ability::RecalcAttrDirect(int attr_id)
|
||||||
|
{
|
||||||
|
list_head* head = &std::get<1>(attr_direct_[attr_id]);
|
||||||
|
list_head* pos = nullptr;
|
||||||
|
list_head* next = nullptr;
|
||||||
|
float new_val = 0.0f;
|
||||||
|
list_for_each_safe(pos, next, head) {
|
||||||
|
AttrDirect* e = list_entry(pos,
|
||||||
|
AttrDirect,
|
||||||
|
entry);
|
||||||
|
new_val = std::max(e->value, new_val);
|
||||||
|
}
|
||||||
|
std::get<0>(attr_direct_[attr_id]) = new_val;
|
||||||
|
}
|
||||||
|
@ -2,11 +2,6 @@
|
|||||||
#include "attrdefine.h"
|
#include "attrdefine.h"
|
||||||
#include "weakptr.h"
|
#include "weakptr.h"
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
class Ability
|
class Ability
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -34,6 +29,10 @@ class Ability
|
|||||||
float GetAttrAddition(int attr_id);
|
float GetAttrAddition(int attr_id);
|
||||||
float GetAttrRuduce(int attr_id);
|
float GetAttrRuduce(int attr_id);
|
||||||
|
|
||||||
|
AttrDirectHandle AddAttrDirect(int attr_id, float value);
|
||||||
|
void RemoveAttrDirect(AttrDirectHandle handle);
|
||||||
|
float GetAttrDirect(int attr_id);
|
||||||
|
|
||||||
void GMDelBaseAttr(int type, int attr_id, int idx);
|
void GMDelBaseAttr(int type, int attr_id, int idx);
|
||||||
void GMClearBaseAttr(int type);
|
void GMClearBaseAttr(int type);
|
||||||
void GMDelGrowAttr(int type, int attr_id, int idx);
|
void GMDelGrowAttr(int type, int attr_id, int idx);
|
||||||
@ -45,6 +44,7 @@ private:
|
|||||||
void RecalcAttrRate(int attr_id);
|
void RecalcAttrRate(int attr_id);
|
||||||
void RecalcAttrAddition(int attr_id);
|
void RecalcAttrAddition(int attr_id);
|
||||||
void RecalcAttrRuduce(int attr_id);
|
void RecalcAttrRuduce(int attr_id);
|
||||||
|
void RecalcAttrDirect(int attr_id);
|
||||||
private:
|
private:
|
||||||
CreatureWeakPtr owner_;
|
CreatureWeakPtr owner_;
|
||||||
std::array<std::tuple<float, list_head>, kHAT_End> attr_abs_ = {};
|
std::array<std::tuple<float, list_head>, kHAT_End> attr_abs_ = {};
|
||||||
@ -53,6 +53,7 @@ private:
|
|||||||
std::array<std::tuple<float, list_head>, kHAT_End> attr_dec_ = {};
|
std::array<std::tuple<float, list_head>, kHAT_End> attr_dec_ = {};
|
||||||
std::array<std::tuple<float, list_head>, kHVAT_End - kHVAT_Begin> vattr_add_ = {};
|
std::array<std::tuple<float, list_head>, kHVAT_End - kHVAT_Begin> vattr_add_ = {};
|
||||||
std::array<std::tuple<float, list_head>, kHVAT_End - kHVAT_Begin> vattr_dec_ = {};
|
std::array<std::tuple<float, list_head>, kHVAT_End - kHVAT_Begin> vattr_dec_ = {};
|
||||||
|
std::array<std::tuple<float, list_head>, kHAT_End> attr_direct_ = {};
|
||||||
std::array<int, kSwitchTimeEnd> switch_times_ = {};
|
std::array<int, kSwitchTimeEnd> switch_times_ = {};
|
||||||
std::map<int, int> immune_tags_;
|
std::map<int, int> immune_tags_;
|
||||||
|
|
||||||
|
@ -93,3 +93,9 @@ class IBullet
|
|||||||
virtual float GetHitRadius() = 0;
|
virtual float GetHitRadius() = 0;
|
||||||
virtual void ProcRequestBulletDmg(int shield_hit, int strength_wall_uniid, int target_uniid, const glm::vec3& pos) = 0;
|
virtual void ProcRequestBulletDmg(int shield_hit, int strength_wall_uniid, int target_uniid, const glm::vec3& pos) = 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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user