Added a new convenience stat setter.

This commit is contained in:
Relintai 2020-05-02 01:54:12 +02:00
parent e033d5a988
commit 760254b7b1
2 changed files with 14 additions and 0 deletions

View File

@ -1932,6 +1932,16 @@ void Entity::stat_mod_percent(const int stat_id, const float value) {
stat_recalculate(stat_id);
}
void Entity::stat_mod(const int stat_id, const float base, const float bonus, const float percent) {
ERR_FAIL_INDEX(stat_id, ESS::get_instance()->stat_get_count());
_stats.write[stat_id].base += base;
_stats.write[stat_id].bonus += bonus;
_stats.write[stat_id].percent += percent;
stat_recalculate(stat_id);
}
float Entity::stat_gets_current(const int stat_id) const {
ERR_FAIL_INDEX_V(stat_id, ESS::get_instance()->stat_get_count(), 0);
@ -6904,6 +6914,8 @@ void Entity::_bind_methods() {
ClassDB::bind_method(D_METHOD("stat_set_percent", "stat_id", "value"), &Entity::stat_set_percent);
ClassDB::bind_method(D_METHOD("stat_mod_percent", "stat_id", "value"), &Entity::stat_mod_percent);
ClassDB::bind_method(D_METHOD("stat_mod", "stat_id", "base", "bonus", "percent"), &Entity::stat_mod);
ClassDB::bind_method(D_METHOD("stat_gets_current", "stat_id"), &Entity::stat_gets_current);
ClassDB::bind_method(D_METHOD("stat_sets_current", "stat_id", "value"), &Entity::stat_sets_current);

View File

@ -383,6 +383,8 @@ public:
void stat_set_percent(const int stat_id, const float value);
void stat_mod_percent(const int stat_id, const float value);
void stat_mod(const int stat_id, const float base, const float bonus, const float percent);
float stat_gets_current(const int stat_id) const;
void stat_sets_current(const int stat_id, const float value);