Class: FifthedSim::Stat
- Inherits:
-
Object
- Object
- FifthedSim::Stat
- Defined in:
- lib/fifthed_sim/stat.rb
Defined Under Namespace
Classes: DefinitionProxy
Instance Attribute Summary collapse
-
#mod_bonus ⇒ Object
readonly
Returns the value of attribute mod_bonus.
-
#save_mod_bonus ⇒ Object
readonly
Returns the value of attribute save_mod_bonus.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ Stat
constructor
A new instance of Stat.
- #mod ⇒ Object
- #saving_throw ⇒ Object
Constructor Details
#initialize(hash) ⇒ Stat
Returns a new instance of Stat.
31 32 33 34 35 |
# File 'lib/fifthed_sim/stat.rb', line 31 def initialize(hash) @value = hash[:value] @mod_bonus = (hash[:mod_bonus] || 0) @save_mod_bonus = (hash[:save_mod_bonus] || 0) end |
Instance Attribute Details
#mod_bonus ⇒ Object (readonly)
Returns the value of attribute mod_bonus.
37 38 39 |
# File 'lib/fifthed_sim/stat.rb', line 37 def mod_bonus @mod_bonus end |
#save_mod_bonus ⇒ Object (readonly)
Returns the value of attribute save_mod_bonus.
37 38 39 |
# File 'lib/fifthed_sim/stat.rb', line 37 def save_mod_bonus @save_mod_bonus end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
37 38 39 |
# File 'lib/fifthed_sim/stat.rb', line 37 def value @value end |
Class Method Details
.define(&block) ⇒ Object
21 22 23 24 |
# File 'lib/fifthed_sim/stat.rb', line 21 def self.define(&block) h = DefinitionProxy.new(&block).hash self.new(h) end |
.from_value(h) ⇒ Object
26 27 28 29 |
# File 'lib/fifthed_sim/stat.rb', line 26 def self.from_value(h) raise ArgumentError, "#{h} not fixnum" unless h.is_a?(Fixnum) self.new({value: h, save_mod: 0, mod_bonus: 0}) end |
Instance Method Details
#mod ⇒ Object
41 42 43 |
# File 'lib/fifthed_sim/stat.rb', line 41 def mod ((@value - 10) / 2) + @mod_bonus end |
#saving_throw ⇒ Object
45 46 47 |
# File 'lib/fifthed_sim/stat.rb', line 45 def saving_throw 1.d(20) + mod + save_mod_bonus end |