2020-01-31 19:34:47 +01:00
/*
Copyright ( c ) 2019 - 2020 Péter Magyar
Permission is hereby granted , free of charge , to any person obtaining a copy
of this software and associated documentation files ( the " Software " ) , to deal
in the Software without restriction , including without limitation the rights
to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
copies of the Software , and to permit persons to whom the Software is
furnished to do so , subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software .
THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM ,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE .
*/
2019-04-20 14:02:55 +02:00
# include "stat.h"
2020-04-25 16:50:53 +02:00
# include "../../singletons/ess.h"
2019-10-15 18:34:19 +02:00
# include "../entity.h"
# include "stat_data_entry.h"
2020-04-09 12:32:05 +02:00
# include "core/version.h"
2019-10-16 13:35:57 +02:00
const String Stat : : MAIN_STAT_BINDING_STRING = " Agility,Strength,Stamina,Intellect,Spirit " ;
2019-04-20 14:02:55 +02:00
2019-08-13 23:58:42 +02:00
const String Stat : : MODIFIER_APPLY_TYPE_BINDING_STRING = " Standard,Only min modifier,Only Max modifier " ;
2019-04-20 14:02:55 +02:00
2020-04-25 16:50:53 +02:00
int Stat : : get_id ( ) {
2019-04-20 14:02:55 +02:00
return _id ;
}
2020-04-25 16:50:53 +02:00
void Stat : : set_id ( int id ) {
2019-04-20 14:02:55 +02:00
_id = id ;
}
2019-10-15 18:34:19 +02:00
Ref < StatDataEntry > Stat : : get_stat_data_entry ( ) {
return _stat_data_entry ;
}
void Stat : : set_stat_data_entry ( Ref < StatDataEntry > entry ) {
_stat_data_entry = entry ;
}
Entity * Stat : : get_owner ( ) {
return _owner ;
}
void Stat : : set_owner ( Entity * value ) {
_owner = value ;
}
void Stat : : set_owner_bind ( Node * value ) {
if ( ! value ) {
return ;
}
Entity * e = cast_to < Entity > ( value ) ;
if ( ! e ) {
return ;
}
_owner = e ;
}
2019-04-20 14:02:55 +02:00
Stat : : StatModifierApplyType Stat : : get_stat_modifier_type ( ) {
return _modifier_apply_type ;
}
void Stat : : set_stat_modifier_type ( Stat : : StatModifierApplyType value ) {
_modifier_apply_type = value ;
}
2019-10-15 14:57:59 +02:00
bool Stat : : get_public ( ) {
return _public ;
}
void Stat : : set_public ( bool value ) {
_public = value ;
}
2019-09-11 18:18:20 +02:00
bool Stat : : get_locked ( ) {
return _locked ;
}
void Stat : : set_locked ( bool value ) {
_locked = value ;
}
2019-04-20 14:02:55 +02:00
bool Stat : : get_dirty ( ) {
return _dirty ;
}
void Stat : : set_dirty ( bool value ) {
_dirty = value ;
}
2019-10-15 14:57:59 +02:00
bool Stat : : get_dirty_mods ( ) {
return _dirty_mods ;
2019-04-20 14:02:55 +02:00
}
2019-10-15 14:57:59 +02:00
void Stat : : set_dirty_mods ( bool value ) {
_dirty_mods = value ;
2019-04-20 14:02:55 +02:00
}
2019-10-15 14:57:59 +02:00
float Stat : : get_base ( ) {
return _base ;
2019-04-20 14:02:55 +02:00
}
2020-04-24 23:43:37 +02:00
void Stat : : set_base ( float value ) {
_base = value ;
}
2019-10-15 14:57:59 +02:00
float Stat : : get_bonus ( ) {
return _bonus ;
2019-04-20 14:02:55 +02:00
}
2020-04-24 23:43:37 +02:00
void Stat : : set_bonus ( float value ) {
_bonus = value ;
}
2019-10-15 14:57:59 +02:00
float Stat : : get_percent ( ) {
return _percent ;
2019-04-20 14:02:55 +02:00
}
2020-04-24 23:43:37 +02:00
void Stat : : set_percent ( float value ) {
_percent = value ;
}
2019-04-20 14:02:55 +02:00
float Stat : : gets_current ( ) {
return _s_current ;
}
void Stat : : sets_current ( float value ) {
2019-09-11 18:18:20 +02:00
if ( _locked ) {
return ;
}
2019-04-20 14:02:55 +02:00
_s_current = value ;
2019-10-15 14:57:59 +02:00
_dirty = true ;
2019-04-20 14:02:55 +02:00
}
float Stat : : gets_max ( ) {
return _s_max ;
}
void Stat : : sets_max ( float value ) {
_s_max = value ;
2019-10-15 14:57:59 +02:00
_dirty = true ;
2019-04-20 14:02:55 +02:00
}
float Stat : : getc_current ( ) {
return _c_current ;
}
void Stat : : setc_current ( float value ) {
2019-10-15 18:34:19 +02:00
ERR_FAIL_COND ( _owner = = NULL ) ;
2019-04-20 14:02:55 +02:00
_c_current = value ;
2019-10-15 18:34:19 +02:00
_owner - > onc_stat_changed ( Ref < Stat > ( this ) ) ;
2019-08-13 23:58:42 +02:00
emit_signal ( " c_changed " , Ref < Stat > ( this ) ) ;
2019-04-20 14:02:55 +02:00
}
float Stat : : getc_max ( ) {
return _c_max ;
}
void Stat : : setc_max ( float value ) {
2019-10-15 18:34:19 +02:00
ERR_FAIL_COND ( _owner = = NULL ) ;
2019-04-20 14:02:55 +02:00
_s_current = value ;
2019-10-15 18:34:19 +02:00
_owner - > onc_stat_changed ( Ref < Stat > ( this ) ) ;
2019-08-13 23:58:42 +02:00
emit_signal ( " c_changed " , Ref < Stat > ( this ) ) ;
2019-04-20 14:02:55 +02:00
}
2019-10-15 14:57:59 +02:00
void Stat : : setc_values ( int ccurrent , int cmax ) {
2019-10-15 18:34:19 +02:00
ERR_FAIL_COND ( _owner = = NULL ) ;
2019-10-15 14:57:59 +02:00
_c_current = ccurrent ;
_c_max = cmax ;
2019-10-15 18:34:19 +02:00
_owner - > onc_stat_changed ( Ref < Stat > ( this ) ) ;
2019-10-15 14:57:59 +02:00
emit_signal ( " c_changed " , Ref < Stat > ( this ) ) ;
2019-04-20 14:02:55 +02:00
}
2020-04-24 23:43:37 +02:00
Vector < Ref < StatModifier > > * Stat : : get_modifiers ( ) {
2019-10-15 14:57:59 +02:00
return & _modifiers ;
}
2019-04-20 14:02:55 +02:00
2019-10-15 14:57:59 +02:00
int Stat : : get_modifier_count ( ) {
return _modifiers . size ( ) ;
2019-04-20 14:02:55 +02:00
}
2019-10-15 14:57:59 +02:00
void Stat : : clear_modifiers ( ) {
_modifiers . clear ( ) ;
_dirty = true ;
_dirty_mods = true ;
}
Ref < StatModifier > Stat : : get_modifier ( int index ) {
return _modifiers . get ( index ) ;
2019-04-20 14:02:55 +02:00
}
2019-10-15 14:57:59 +02:00
Ref < StatModifier > Stat : : add_modifier ( int id , float base_mod , float bonus_mod , float percent_mod ) {
Ref < StatModifier > stat_modifier = Ref < StatModifier > ( memnew ( StatModifier ( id , base_mod , bonus_mod , percent_mod , this ) ) ) ;
2019-04-20 14:02:55 +02:00
2019-10-15 14:57:59 +02:00
_modifiers . push_back ( stat_modifier ) ;
_dirty = true ;
_dirty_mods = true ;
return stat_modifier ;
2019-04-20 14:02:55 +02:00
}
2019-10-15 18:34:19 +02:00
Ref < StatModifier > Stat : : get_or_add_modifier ( int id ) {
for ( int i = 0 ; i < _modifiers . size ( ) ; + + i ) {
if ( _modifiers . get ( i ) - > get_id ( ) = = id ) {
return _modifiers . get ( i ) ;
}
}
Ref < StatModifier > stat_modifier = Ref < StatModifier > ( memnew ( StatModifier ( id , 0 , 0 , 0 , this ) ) ) ;
_modifiers . push_back ( stat_modifier ) ;
return stat_modifier ;
}
2019-10-15 14:57:59 +02:00
void Stat : : remove_modifier ( int id ) {
2019-10-15 18:34:19 +02:00
for ( int i = 0 ; i < _modifiers . size ( ) ; + + i ) {
2019-10-15 14:57:59 +02:00
if ( _modifiers . get ( i ) - > get_id ( ) = = id ) {
Ref < StatModifier > modifier = _modifiers . get ( i ) ;
_modifiers . remove ( i ) ;
_dirty_mods = true ;
return ;
}
}
2019-04-20 14:02:55 +02:00
}
2019-10-15 18:34:19 +02:00
void Stat : : remove_modifier_index ( int index ) {
_modifiers . remove ( index ) ;
}
2019-10-15 14:57:59 +02:00
void Stat : : apply_modifiers ( ) {
2020-04-10 14:09:21 +02:00
# if VERSION_MAJOR < 4
2019-10-15 22:21:14 +02:00
ERR_FAIL_COND ( ! ObjectDB : : instance_validate ( _owner ) ) ;
2020-04-10 14:09:21 +02:00
# else
2020-04-09 12:32:05 +02:00
ERR_FAIL_COND ( _owner = = NULL ) ;
2020-04-10 14:09:21 +02:00
# endif
2019-10-15 18:34:19 +02:00
ERR_FAIL_COND ( ! _stat_data_entry . is_valid ( ) ) ;
2019-10-15 14:57:59 +02:00
reset_values ( ) ;
if ( _modifier_apply_type = = MODIFIER_APPLY_TYPE_STANDARD ) {
2019-10-15 20:23:13 +02:00
for ( int i = 0 ; i < _modifiers . size ( ) ; + + i ) {
2019-10-15 14:57:59 +02:00
Ref < StatModifier > mod = _modifiers . get ( i ) ;
2020-01-09 04:27:19 +01:00
2019-10-15 14:57:59 +02:00
_base + = mod - > get_base_mod ( ) ;
_bonus + = mod - > get_bonus_mod ( ) ;
_percent + = mod - > get_percent_mod ( ) ;
}
} else {
2019-10-15 20:23:13 +02:00
for ( int i = 0 ; i < _modifiers . size ( ) ; + + i ) {
2019-10-15 14:57:59 +02:00
Ref < StatModifier > modifier = _modifiers . get ( i ) ;
2019-10-15 20:23:13 +02:00
_base + = modifier - > get_base_mod ( ) ;
_bonus + = modifier - > get_bonus_mod ( ) ;
if ( modifier - > get_percent_mod ( ) > = 0 ) {
2019-10-15 14:57:59 +02:00
_percent + = modifier - > get_percent_mod ( ) ;
}
}
2019-10-15 20:23:13 +02:00
float p = 0 ;
for ( int i = 0 ; i < _modifiers . size ( ) ; + + i ) {
Ref < StatModifier > modifier = _modifiers . get ( i ) ;
if ( modifier - > get_percent_mod ( ) < p )
p = modifier - > get_percent_mod ( ) ;
}
_percent + = p ;
2019-10-15 14:57:59 +02:00
}
2019-10-15 18:34:19 +02:00
refresh_currmax ( ) ;
2019-10-15 14:57:59 +02:00
_dirty_mods = false ;
2019-04-20 14:02:55 +02:00
2019-10-15 18:34:19 +02:00
for ( int i = 0 ; i < _stat_data_entry - > get_mod_stat_count ( ) ; + + i ) {
2020-04-25 16:50:53 +02:00
Ref < Stat > stat = _owner - > get_stat ( _stat_data_entry - > get_mod_stat_id ( i ) ) ;
2019-10-15 18:34:19 +02:00
Ref < Curve > curve = _stat_data_entry - > get_mod_stat_curve ( i ) ;
2019-10-15 21:58:40 +02:00
float max_value = _stat_data_entry - > get_mod_stat_max_value ( i ) ;
2019-10-15 18:34:19 +02:00
ERR_FAIL_COND ( ! stat . is_valid ( ) ) ;
ERR_FAIL_COND ( ! curve . is_valid ( ) ) ;
Ref < StatModifier > sm = stat - > get_or_add_modifier ( - ( static_cast < int > ( _id ) + 1 ) ) ;
2019-10-15 21:58:40 +02:00
sm - > set_base_mod ( _s_current * curve - > interpolate ( _s_current / max_value ) ) ;
2019-10-15 18:34:19 +02:00
}
_owner - > ons_stat_changed ( Ref < Stat > ( this ) ) ;
2019-08-13 23:58:42 +02:00
emit_signal ( " s_changed " , Ref < Stat > ( this ) ) ;
2019-04-20 14:02:55 +02:00
}
void Stat : : reset_values ( ) {
_percent = 0 ;
2019-10-15 20:23:13 +02:00
_bonus = 0 ;
_base = 0 ;
2019-04-20 14:02:55 +02:00
_dirty = true ;
2019-10-15 14:57:59 +02:00
_dirty_mods = true ;
2019-04-20 14:02:55 +02:00
}
2019-10-15 14:57:59 +02:00
void Stat : : refresh_currmax ( ) {
2019-10-15 20:23:13 +02:00
//According to people on stack overflow this should be fine, because 0.0 has a unique representation
float diff = _s_max = = 0.0 ? 1.0 : _s_current / _s_max ;
2019-09-14 20:44:50 +02:00
2019-08-05 23:59:37 +02:00
_s_max = ( _base + _bonus ) * ( _percent / 100.0 ) ;
2019-04-20 14:02:55 +02:00
2019-08-05 23:59:37 +02:00
_s_current = _s_max * diff ;
2019-04-20 14:02:55 +02:00
_dirty = true ;
}
bool Stat : : iss_current_zero ( ) {
return ( fabs ( _s_current ) < .000001 ) ;
}
bool Stat : : isc_current_zero ( ) {
return ( fabs ( _c_current ) < .000001 ) ;
}
void Stat : : set_to_max ( ) {
2019-10-15 18:34:19 +02:00
ERR_FAIL_COND ( _owner = = NULL ) ;
2019-04-20 14:02:55 +02:00
_s_current = _s_max ;
2019-10-15 14:57:59 +02:00
_dirty = true ;
2019-04-20 14:02:55 +02:00
2019-10-15 18:34:19 +02:00
_owner - > ons_stat_changed ( Ref < Stat > ( this ) ) ;
2019-08-13 23:58:42 +02:00
emit_signal ( " s_changed " , Ref < Stat > ( this ) ) ;
2019-04-20 14:02:55 +02:00
}
2019-10-15 14:57:59 +02:00
void Stat : : modifier_changed ( Ref < StatModifier > modifier ) {
_dirty_mods = true ;
2019-04-20 14:02:55 +02:00
}
2019-09-13 09:26:53 +02:00
Dictionary Stat : : to_dict ( ) {
return call ( " _to_dict " ) ;
}
void Stat : : from_dict ( const Dictionary & dict ) {
call ( " _from_dict " , dict ) ;
}
Dictionary Stat : : _to_dict ( ) {
Dictionary dict ;
dict [ " id " ] = _id ;
dict [ " modifier_apply_type " ] = _modifier_apply_type ;
2019-10-15 14:57:59 +02:00
dict [ " public " ] = _public ;
2019-09-13 09:26:53 +02:00
dict [ " locked " ] = _locked ;
dict [ " dirty " ] = _dirty ;
2019-10-15 14:57:59 +02:00
dict [ " dirty_mods " ] = _dirty_mods ;
2019-09-13 09:26:53 +02:00
dict [ " base " ] = _base ;
dict [ " bonus " ] = _bonus ;
dict [ " percent " ] = _percent ;
dict [ " current " ] = _s_current ;
dict [ " max " ] = _s_max ;
Dictionary modifiers ;
2019-10-15 20:23:13 +02:00
for ( int i = 0 ; i < _modifiers . size ( ) ; + + i ) {
modifiers [ String : : num ( i ) ] = _modifiers . get ( i ) - > to_dict ( ) ;
2019-09-13 09:26:53 +02:00
}
dict [ " modifiers " ] = modifiers ;
return dict ;
}
void Stat : : _from_dict ( const Dictionary & dict ) {
ERR_FAIL_COND ( dict . empty ( ) ) ;
2019-09-14 20:44:50 +02:00
2020-04-25 16:50:53 +02:00
_id = dict . get ( " id " , 0 ) ;
2019-09-14 20:44:50 +02:00
_modifier_apply_type = ( StatModifierApplyType ) ( ( int ) dict . get ( " modifier_apply_type " , 0 ) ) ;
2019-10-15 14:57:59 +02:00
_public = dict . get ( " public " , false ) ;
2019-09-14 20:44:50 +02:00
_locked = dict . get ( " locked " , false ) ;
_dirty = dict . get ( " dirty " , false ) ;
2019-10-15 14:57:59 +02:00
_dirty_mods = dict . get ( " dirty_mods " , false ) ;
2019-09-14 20:44:50 +02:00
_base = dict . get ( " base " , 0 ) ;
_bonus = dict . get ( " bonus " , 0 ) ;
_percent = dict . get ( " percent " , 1 ) ;
_s_current = dict . get ( " current " , 0 ) ;
_s_max = dict . get ( " max " , 0 ) ;
_c_current = _s_current ;
_c_max = _s_max ;
_modifiers . clear ( ) ;
Dictionary modifiers = dict . get ( " modifiers " , Dictionary ( ) ) ;
for ( int i = 0 ; i < modifiers . size ( ) ; + + i ) {
Ref < StatModifier > sm ;
sm . instance ( ) ;
2019-10-15 18:34:19 +02:00
2019-10-15 20:23:13 +02:00
sm - > from_dict ( modifiers . get ( String : : num ( i ) , Dictionary ( ) ) ) ;
2019-10-15 14:57:59 +02:00
sm - > set_owner ( this ) ;
2019-09-14 20:44:50 +02:00
_modifiers . push_back ( sm ) ;
}
2019-10-25 21:58:29 +02:00
_dirty = true ;
_dirty_mods = true ;
2019-09-13 09:26:53 +02:00
}
Stat : : Stat ( ) {
2020-04-25 16:50:53 +02:00
_id = 0 ;
2019-10-15 18:34:19 +02:00
_owner = NULL ;
2019-09-13 09:26:53 +02:00
2019-10-04 22:55:09 +02:00
_modifier_apply_type = MODIFIER_APPLY_TYPE_STANDARD ;
2019-10-15 14:57:59 +02:00
_public = false ;
_dirty_mods = false ;
2019-09-13 09:26:53 +02:00
_locked = false ;
2019-10-04 22:55:09 +02:00
_dirty = true ;
2019-09-13 09:26:53 +02:00
2019-10-04 22:55:09 +02:00
_base = 0 ;
_bonus = 0 ;
2019-10-15 20:23:13 +02:00
_percent = 0 ;
2019-10-04 22:55:09 +02:00
_s_current = 0 ;
_s_max = 0 ;
_c_current = 0 ;
_c_max = 0 ;
2019-09-13 09:26:53 +02:00
}
2020-04-25 16:50:53 +02:00
Stat : : Stat ( int id , Entity * owner ) {
2019-09-13 09:26:53 +02:00
_id = id ;
2019-10-15 18:34:19 +02:00
_owner = owner ;
2019-09-13 09:26:53 +02:00
2019-10-04 22:55:09 +02:00
_modifier_apply_type = MODIFIER_APPLY_TYPE_STANDARD ;
2019-10-15 14:57:59 +02:00
_public = false ;
_dirty_mods = false ;
2019-09-13 09:26:53 +02:00
_locked = false ;
2019-10-04 22:55:09 +02:00
_dirty = true ;
2019-09-13 09:26:53 +02:00
2019-10-04 22:55:09 +02:00
_base = 0 ;
_bonus = 0 ;
2019-10-15 20:23:13 +02:00
_percent = 0 ;
2019-10-04 22:55:09 +02:00
_s_current = 0 ;
_s_max = 0 ;
_c_current = 0 ;
_c_max = 0 ;
2019-09-13 09:26:53 +02:00
}
2020-04-25 16:50:53 +02:00
Stat : : Stat ( int id , StatModifierApplyType modifier_apply_type , Entity * owner ) {
2019-09-13 09:26:53 +02:00
_id = id ;
2019-10-15 18:34:19 +02:00
_owner = owner ;
2019-09-13 09:26:53 +02:00
2019-10-04 22:55:09 +02:00
_modifier_apply_type = modifier_apply_type ;
2019-10-15 14:57:59 +02:00
_public = false ;
_dirty_mods = false ;
2019-09-13 09:26:53 +02:00
_locked = false ;
2019-10-04 22:55:09 +02:00
_dirty = true ;
2019-09-13 09:26:53 +02:00
2019-10-04 22:55:09 +02:00
_base = 0 ;
_bonus = 0 ;
2019-10-15 20:23:13 +02:00
_percent = 0 ;
2019-10-04 22:55:09 +02:00
_s_current = 0 ;
_s_max = 0 ;
_c_current = 0 ;
_c_max = 0 ;
2019-09-13 09:26:53 +02:00
}
Stat : : ~ Stat ( ) {
_modifiers . clear ( ) ;
2019-10-15 18:34:19 +02:00
_owner = NULL ;
_stat_data_entry . unref ( ) ;
2019-09-13 09:26:53 +02:00
}
2020-04-25 16:50:53 +02:00
void Stat : : _validate_property ( PropertyInfo & property ) const {
if ( property . name = = " id " ) {
property . hint_string = ESS : : get_instance ( ) - > stat_get_string ( ) ;
}
}
2019-04-20 14:02:55 +02:00
void Stat : : _bind_methods ( ) {
ADD_SIGNAL ( MethodInfo ( " s_changed " , PropertyInfo ( Variant : : OBJECT , " stat " , PROPERTY_HINT_RESOURCE_TYPE , " Stat " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " c_changed " , PropertyInfo ( Variant : : OBJECT , " stat " , PROPERTY_HINT_RESOURCE_TYPE , " Stat " ) ) ) ;
ClassDB : : bind_method ( D_METHOD ( " get_id " ) , & Stat : : get_id ) ;
ClassDB : : bind_method ( D_METHOD ( " set_id " , " id " ) , & Stat : : set_id ) ;
2020-04-25 16:50:53 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " id " , PROPERTY_HINT_ENUM , " " ) , " set_id " , " get_id " ) ;
2019-04-20 14:02:55 +02:00
2019-10-15 18:34:19 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_stat_data_entry " ) , & Stat : : get_stat_data_entry ) ;
ClassDB : : bind_method ( D_METHOD ( " set_stat_data_entry " , " value " ) , & Stat : : set_stat_data_entry ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " stat_data_entry " , PROPERTY_HINT_RESOURCE_TYPE , " StatDataEntry " ) , " set_stat_data_entry " , " get_stat_data_entry " ) ;
ClassDB : : bind_method ( D_METHOD ( " get_owner " ) , & Stat : : get_owner ) ;
ClassDB : : bind_method ( D_METHOD ( " set_owner " , " value " ) , & Stat : : set_owner_bind ) ;
2020-04-23 12:13:56 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " owner " , PROPERTY_HINT_RESOURCE_TYPE , " Entity " , 0 ) , " set_owner " , " get_owner " ) ;
2019-10-15 18:34:19 +02:00
2019-04-20 14:02:55 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_stat_modifier_type " ) , & Stat : : get_stat_modifier_type ) ;
ClassDB : : bind_method ( D_METHOD ( " set_stat_modifier_type " , " value " ) , & Stat : : set_stat_modifier_type ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " stat_type " , PROPERTY_HINT_ENUM , " Standard, Min Modifier, Max modifier " ) , " set_stat_modifier_type " , " get_stat_modifier_type " ) ;
2019-10-15 14:57:59 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_public " ) , & Stat : : get_public ) ;
ClassDB : : bind_method ( D_METHOD ( " set_public " , " value " ) , & Stat : : set_public ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " public " ) , " set_public " , " get_public " ) ;
2019-09-11 18:18:20 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_locked " ) , & Stat : : get_locked ) ;
ClassDB : : bind_method ( D_METHOD ( " set_locked " , " value " ) , & Stat : : set_locked ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " locked " ) , " set_locked " , " get_locked " ) ;
2019-04-20 14:02:55 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_dirty " ) , & Stat : : get_dirty ) ;
ClassDB : : bind_method ( D_METHOD ( " set_dirty " , " value " ) , & Stat : : set_dirty ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " is_dirty " ) , " set_dirty " , " get_dirty " ) ;
2019-10-15 14:57:59 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_dirty_mods " ) , & Stat : : get_dirty_mods ) ;
ClassDB : : bind_method ( D_METHOD ( " set_dirty_mods " , " value " ) , & Stat : : set_dirty_mods ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " dirty_mods " ) , " set_dirty_mods " , " get_dirty_mods " ) ;
ClassDB : : bind_method ( D_METHOD ( " get_base " ) , & Stat : : get_base ) ;
2020-04-24 23:43:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_base " ) , & Stat : : set_base ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " base " ) , " set_base " , " get_base " ) ;
2019-10-15 14:57:59 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_bonus " ) , & Stat : : get_bonus ) ;
2020-04-24 23:43:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_bonus " ) , & Stat : : set_bonus ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " bonus " ) , " set_bonus " , " get_bonus " ) ;
2019-10-15 14:57:59 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_percent " ) , & Stat : : get_percent ) ;
2020-04-24 23:43:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_percent " ) , & Stat : : set_percent ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " percent " ) , " set_percent " , " get_percent " ) ;
2019-10-15 14:57:59 +02:00
2019-04-20 14:02:55 +02:00
ClassDB : : bind_method ( D_METHOD ( " gets_current " ) , & Stat : : gets_current ) ;
ClassDB : : bind_method ( D_METHOD ( " sets_current " , " value " ) , & Stat : : sets_current ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " scurrent " ) , " sets_current " , " gets_current " ) ;
ClassDB : : bind_method ( D_METHOD ( " gets_max " ) , & Stat : : gets_max ) ;
ClassDB : : bind_method ( D_METHOD ( " sets_max " ) , & Stat : : sets_max ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " smax " ) , " sets_max " , " gets_max " ) ;
ClassDB : : bind_method ( D_METHOD ( " getc_max " ) , & Stat : : getc_max ) ;
ClassDB : : bind_method ( D_METHOD ( " setc_max " ) , & Stat : : setc_max ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " cmax " ) , " setc_max " , " getc_max " ) ;
2019-10-15 14:57:59 +02:00
ClassDB : : bind_method ( D_METHOD ( " getc_current " ) , & Stat : : getc_current ) ;
ClassDB : : bind_method ( D_METHOD ( " setc_current " , " value " ) , & Stat : : setc_current ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " ccurrent " ) , " setc_current " , " getc_current " ) ;
2019-04-20 14:02:55 +02:00
2019-10-15 14:57:59 +02:00
ClassDB : : bind_method ( D_METHOD ( " setc_values " , " ccurrent " , " cmax " ) , & Stat : : setc_values ) ;
2019-04-20 14:02:55 +02:00
2019-10-15 14:57:59 +02:00
ClassDB : : bind_method ( D_METHOD ( " add_modifier " , " id " , " base_mod " , " bonus_mod " , " percent_mod " ) , & Stat : : add_modifier ) ;
2019-10-15 18:34:19 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_or_add_modifier " , " id " ) , & Stat : : get_or_add_modifier ) ;
2019-10-15 14:57:59 +02:00
ClassDB : : bind_method ( D_METHOD ( " remove_modifier " , " id " ) , & Stat : : remove_modifier ) ;
2019-10-15 18:34:19 +02:00
ClassDB : : bind_method ( D_METHOD ( " remove_modifier_index " , " index " ) , & Stat : : remove_modifier_index ) ;
2019-10-15 14:57:59 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_modifier_count " ) , & Stat : : get_modifier_count ) ;
ClassDB : : bind_method ( D_METHOD ( " clear_modifiers " ) , & Stat : : clear_modifiers ) ;
ClassDB : : bind_method ( D_METHOD ( " get_modifier " , " index " ) , & Stat : : get_modifier ) ;
ClassDB : : bind_method ( D_METHOD ( " apply_modifiers " ) , & Stat : : apply_modifiers ) ;
2019-04-20 14:02:55 +02:00
ClassDB : : bind_method ( D_METHOD ( " reset_values " ) , & Stat : : reset_values ) ;
2019-10-15 14:57:59 +02:00
ClassDB : : bind_method ( D_METHOD ( " refresh_currmax " ) , & Stat : : refresh_currmax ) ;
2019-04-20 14:02:55 +02:00
ClassDB : : bind_method ( D_METHOD ( " iss_current_zero " ) , & Stat : : iss_current_zero ) ;
ClassDB : : bind_method ( D_METHOD ( " isc_current_zero " ) , & Stat : : isc_current_zero ) ;
ClassDB : : bind_method ( D_METHOD ( " set_to_max " ) , & Stat : : set_to_max ) ;
2019-10-15 14:57:59 +02:00
ClassDB : : bind_method ( D_METHOD ( " modifier_changed " , " modifier " ) , & Stat : : modifier_changed ) ;
2019-09-16 03:13:52 +02:00
2019-09-13 09:26:53 +02:00
//Serialization
BIND_VMETHOD ( MethodInfo ( " _from_dict " , PropertyInfo ( Variant : : DICTIONARY , " dict " ) ) ) ;
BIND_VMETHOD ( MethodInfo ( PropertyInfo ( Variant : : DICTIONARY , " dict " ) , " _to_dict " ) ) ;
ClassDB : : bind_method ( D_METHOD ( " from_dict " , " dict " ) , & Stat : : from_dict ) ;
ClassDB : : bind_method ( D_METHOD ( " to_dict " ) , & Stat : : to_dict ) ;
ClassDB : : bind_method ( D_METHOD ( " _from_dict " , " dict " ) , & Stat : : _from_dict ) ;
ClassDB : : bind_method ( D_METHOD ( " _to_dict " ) , & Stat : : _to_dict ) ;
2019-10-16 14:55:14 +02:00
BIND_ENUM_CONSTANT ( MODIFIER_APPLY_TYPE_STANDARD ) ;
BIND_ENUM_CONSTANT ( MODIFIER_APPLY_TYPE_ONLY_MIN_MODIFIER ) ;
BIND_ENUM_CONSTANT ( MODIFIER_APPLY_TYPE_ONLY_MAX_MODIFIER ) ;
2019-04-20 14:02:55 +02:00
}