ChargeAbility_Behavior.cpp
Go to the documentation of this file.
2 
3 using namespace iv;
4 
5 namespace comp
6 {
7 
8 ChargeAbility_Behavior::ChargeAbility_Behavior( iv::Instance * inst, Ability * m_ability, iv::Attr< int > * m_charges ) :
9  Ability_Behavior( inst, m_ability ),
10  cm( inst, this, "ChargeAbility_Behavior" ),
11  m_charges( m_charges ),
12  field_charges( inst )
13 {
14  this->cm.inherits( this->Ability_Behavior::cm );
15  this->cm.owns( this->field_charges.cm );
16 
17  this->field_charges.Assign_Attribute_RW( m_charges );
18  this->field_charges.OnChange(
19  [ this ]( bool real )
20  {
21  auto charges = this->field_charges.Get();
22  this->AbilityEnable( charges );
23  }
24  );
25 }
26 
28 {
29  int charges = this->field_charges.Get();
30  if( charges > 0 )
31  {
32  this->field_charges.Modify( charges - 1 );
33  this->ChargeAbilityActivated();
34  }
35 }
36 
37 }