Class: PfrpgCore::SavingThrows

Inherits:
Object
  • Object
show all
Defined in:
lib/pfrpg_core/saving_throws.rb

Instance Method Summary collapse

Constructor Details

#initialize(saves, bonuses, attributes) ⇒ SavingThrows

Returns a new instance of SavingThrows.



4
5
6
7
8
9
10
11
12
# File 'lib/pfrpg_core/saving_throws.rb', line 4

def initialize(saves, bonuses, attributes)
  @attributes = attributes
  @will = saves[:will]
  @will_bonus = NullObject.maybe(bonuses.get('will')).to_i
  @fortitude = saves[:fort]
  @fort_bonus = NullObject.maybe(bonuses.get('fort')).to_i
  @reflex = saves[:ref]
  @ref_bonus = NullObject.maybe(bonuses.get('ref')).to_i
end

Instance Method Details

#as_json(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pfrpg_core/saving_throws.rb', line 26

def as_json(options={})
  {
      :con_modifier => @attributes.con_mod,
      :wis_modifier => @attributes.wis_mod,
      :dex_modifier => @attributes.dex_mod,
      :base_ref     => @reflex,
      :base_fort    => @fortitude,
      :base_will    => @will,
      :bonus_ref    => @ref_bonus,
      :bonus_will   => @will_bonus,
      :bonus_fort   => @fort_bonus,
      :fortitude    => fortitude,
      :reflex       => reflex,
      :will         => will
  }
end

#fortitudeObject



14
15
16
# File 'lib/pfrpg_core/saving_throws.rb', line 14

def fortitude
  @attributes.con_mod + @fortitude + @fort_bonus
end

#reflexObject



18
19
20
# File 'lib/pfrpg_core/saving_throws.rb', line 18

def reflex
  @attributes.dex_mod + @reflex + @ref_bonus
end

#willObject



22
23
24
# File 'lib/pfrpg_core/saving_throws.rb', line 22

def will
  @attributes.wis_mod + @will + @will_bonus
end