Horizon Official Technical Documentation
Horizon::Zone::Traits::TemporaryChanges Class Reference

#include <Attribute.hpp>

+ Collaboration diagram for Horizon::Zone::Traits::TemporaryChanges:

Classes

struct  s_temporary_change
 

Public Member Functions

 TemporaryChanges (Attribute *attr)
 
void add_change (s_attribute_change_values change, uint64_t duration, std::string source)
 
void remove_change (std::string source)
 
void apply (bool notify=true)
 
void update (uint64_t delta)
 

Private Attributes

std::vector< s_temporary_change_changes
 
Attribute_attr
 

Constructor & Destructor Documentation

◆ TemporaryChanges()

Horizon::Zone::Traits::TemporaryChanges::TemporaryChanges ( Attribute attr)
inline
183: _attr(attr) {}
Attribute * _attr
Definition: Attribute.hpp:203

Member Function Documentation

◆ add_change()

void TemporaryChanges::add_change ( s_attribute_change_values  change,
uint64_t  duration,
std::string  source 
)
102{
103 _changes.push_back({ change, duration, source });
104}
std::vector< s_temporary_change > _changes
Definition: Attribute.hpp:202

Referenced by Horizon::Zone::Traits::Attribute::add_temporary_change().

+ Here is the caller graph for this function:

◆ apply()

void TemporaryChanges::apply ( bool  notify = true)
112{
113 for (auto &change : _changes)
114 {
115 if (change.change.get_base() > 0)
116 _attr->add_base(change.change.get_base(), notify);
117 else
118 _attr->sub_base(change.change.get_base(), notify);
119
120 if (change.change.get_equip() > 0)
121 _attr->add_equip(change.change.get_equip(), notify);
122 else
123 _attr->sub_equip(change.change.get_equip(), notify);
124
125 if (change.change.get_status() > 0)
126 _attr->add_status(change.change.get_status(), notify);
127 else
128 _attr->sub_status(change.change.get_status(), notify);
129 }
130}
virtual void sub_equip(int32_t val, bool notify=true)
Definition: Attribute.cpp:256
virtual void sub_status(int32_t val, bool notify=true)
Definition: Attribute.cpp:264
virtual void add_base(int32_t val, bool notify=true)
Definition: Attribute.cpp:244
virtual void sub_base(int32_t val, bool notify=true)
Definition: Attribute.cpp:248
virtual void add_equip(int32_t val, bool notify=true)
Definition: Attribute.cpp:252
virtual void add_status(int32_t val, bool notify=true)
Definition: Attribute.cpp:260

Referenced by Horizon::Zone::Traits::Attribute::apply().

+ Here is the caller graph for this function:

◆ remove_change()

void TemporaryChanges::remove_change ( std::string  source)
107{
108 _changes.erase(std::remove_if(_changes.begin(), _changes.end(), [source](s_temporary_change const &change) { return change.source == source; }), _changes.end());
109}

Referenced by Horizon::Zone::Traits::Attribute::remove_temporary_change().

+ Here is the caller graph for this function:

◆ update()

void TemporaryChanges::update ( uint64_t  delta)
133{
134 for (auto &change : _changes)
135 {
136 if (std::chrono::duration_cast<std::chrono::milliseconds>(change.start_time.time_since_epoch() + std::chrono::milliseconds(change.duration)).count() < delta)
137 {
138 remove_change(change.source);
139 _attr->recalculate(true);
140 continue;
141 }
142 }
143}
void recalculate(bool flag)
Definition: Attribute.hpp:410
void remove_change(std::string source)
Definition: Attribute.cpp:106

Referenced by Horizon::Zone::Traits::Attribute::update().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _attr

Attribute* Horizon::Zone::Traits::TemporaryChanges::_attr
private

◆ _changes

std::vector<s_temporary_change> Horizon::Zone::Traits::TemporaryChanges::_changes
private

The documentation for this class was generated from the following files: