From 5692eec91eb3d00df70827f7c43fc221cc068965 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 27 May 2019 18:28:27 +0200 Subject: [PATCH] Now cooldowns are updated. --- entities/entity.cpp | 18 ++++++++++++++++++ utility/category_cooldown.cpp | 14 ++++++++++++++ utility/category_cooldown.h | 2 ++ utility/cooldown.cpp | 14 ++++++++++++++ utility/cooldown.h | 2 ++ 5 files changed, 50 insertions(+) diff --git a/entities/entity.cpp b/entities/entity.cpp index b5ba55d..231d9d7 100644 --- a/entities/entity.cpp +++ b/entities/entity.cpp @@ -2357,6 +2357,24 @@ void Entity::registers() { } void Entity::update(float delta) { + for (int i = 0; i < _s_cooldowns->size(); ++i) { + Ref cd = _s_cooldowns->get(i); + + if (cd->update(delta)) { + removes_cooldown(cd->get_spell_id()); + --i; + } + } + + for (int i = 0; i < _s_category_cooldowns->size(); ++i) { + Ref cd = _s_category_cooldowns->get(i); + + if (cd->update(delta)) { + removes_category_cooldown(cd->get_category_id()); + --i; + } + } + update_auras(delta); if (_s_spell_cast_info.is_valid() && _s_spell_cast_info->get_is_casting()) { diff --git a/utility/category_cooldown.cpp b/utility/category_cooldown.cpp index 59923f5..9964b4b 100644 --- a/utility/category_cooldown.cpp +++ b/utility/category_cooldown.cpp @@ -21,6 +21,18 @@ void CategoryCooldown::set_remaining(int value) _remaining = value; } +bool CategoryCooldown::update(float delta) { + _remaining -= delta; + + if (_remaining <= 0) { + _remaining = 0; + + return true; + } + + return false; +} + void CategoryCooldown::_bind_methods() { ClassDB::bind_method(D_METHOD("get_category_id"), &CategoryCooldown::get_category_id); @@ -30,4 +42,6 @@ void CategoryCooldown::_bind_methods() { ClassDB::bind_method(D_METHOD("get_remaining"), &CategoryCooldown::get_remaining); ClassDB::bind_method(D_METHOD("set_remaining", "value"), &CategoryCooldown::set_remaining); ADD_PROPERTY(PropertyInfo(Variant::INT, "remaining"), "set_remaining", "get_remaining"); + + ClassDB::bind_method(D_METHOD("update", "delta"), &CategoryCooldown::update); } diff --git a/utility/category_cooldown.h b/utility/category_cooldown.h index 50d31b9..af689fe 100644 --- a/utility/category_cooldown.h +++ b/utility/category_cooldown.h @@ -12,6 +12,8 @@ public: int get_remaining(); void set_remaining(int value); + + bool update(float delta); protected: static void _bind_methods(); diff --git a/utility/cooldown.cpp b/utility/cooldown.cpp index eb1fc39..9553f05 100644 --- a/utility/cooldown.cpp +++ b/utility/cooldown.cpp @@ -21,6 +21,18 @@ void Cooldown::set_remaining(int value) _remaining = value; } +bool Cooldown::update(float delta) { + _remaining -= delta; + + if (_remaining <= 0) { + _remaining = 0; + + return true; + } + + return false; +} + void Cooldown::_bind_methods() { ClassDB::bind_method(D_METHOD("get_spell_id"), &Cooldown::get_spell_id); @@ -30,4 +42,6 @@ void Cooldown::_bind_methods() { ClassDB::bind_method(D_METHOD("get_remaining"), &Cooldown::get_remaining); ClassDB::bind_method(D_METHOD("set_remaining", "value"), &Cooldown::set_remaining); ADD_PROPERTY(PropertyInfo(Variant::INT, "remaining"), "set_remaining", "get_remaining"); + + ClassDB::bind_method(D_METHOD("update", "delta"), &Cooldown::update); } diff --git a/utility/cooldown.h b/utility/cooldown.h index 4276417..1c98c9c 100644 --- a/utility/cooldown.h +++ b/utility/cooldown.h @@ -12,6 +12,8 @@ public: int get_remaining(); void set_remaining(int value); + + bool update(float delta); protected: static void _bind_methods();