156{
158 {
159 if (change.duration && std::chrono::duration_cast<std::chrono::milliseconds>(change.start_time.time_since_epoch() + std::chrono::milliseconds(change.duration)).count() < delta)
160 {
162 continue;
163 }
164
165
166
167
168 if (std::chrono::duration_cast<std::chrono::milliseconds>(change.last_update.time_since_epoch() + std::chrono::milliseconds(change.interval)).count() < delta)
169 {
170 std::function<bool(int, int, int)> over_min = [](int attr, int change, int min) { return (attr - change) < min; };
171 std::function<bool(int, int, int)> over_max = [](int attr, int change, int max) { return (attr + change) > max; };
172
174 return;
175
176 change.change.update_with_live_attribute();
177
178 bool changed = false;
179 if (change.change.get_base() > 0) {
180 if (!over_max(
_attr->
get_base(), change.change.get_base(), change.change.get_max())) {
182 changed = true;
183 } else {
186 }
187 }
188 else if (change.change.get_base() < 0) {
189 if (!over_min(
_attr->
get_base(), change.change.get_base(), change.change.get_min())) {
191 changed = true;
192 } else {
195 }
196 }
197
198 if (change.change.get_equip() > 0) {
199 if (!over_max(
_attr->
get_equip(), change.change.get_equip(), change.change.get_max())) {
201 changed = true;
202 } else {
205 }
206 }
207 else if (change.change.get_equip() < 0) {
208 if (!over_min(
_attr->
get_equip(), change.change.get_equip(), change.change.get_min())) {
210 changed = true;
211 } else {
214 }
215 }
216
217 if (change.change.get_status() > 0) {
218 if (!over_max(
_attr->
get_status(), change.change.get_status(), change.change.get_max())) {
220 changed = true;
221 } else {
224 }
225 }
226 else if (change.change.get_status() < 0) {
227 if (!over_min(
_attr->
get_status(), change.change.get_status(), change.change.get_min())) {
229 changed = true;
230 } else {
233 }
234 }
235
236 if (changed)
237 change.change.client_notify_function(change.change);
238
239 change.last_update = std::chrono::high_resolution_clock::now();
240 }
241 }
242}
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 int32_t get_equip() const
Definition: Attribute.hpp:278
std::shared_ptr< Unit > unit()
Definition: Attribute.hpp:259
virtual void sub_base(int32_t val, bool notify=true)
Definition: Attribute.cpp:248
virtual int32_t get_status() const
Definition: Attribute.hpp:287
virtual void add_equip(int32_t val, bool notify=true)
Definition: Attribute.cpp:252
virtual int32_t get_base() const
Definition: Attribute.hpp:269
virtual void add_status(int32_t val, bool notify=true)
Definition: Attribute.cpp:260
void remove_change(std::string source)
Definition: Attribute.cpp:150