Class: PfrpgCore::Attributes
- Inherits:
-
Object
- Object
- PfrpgCore::Attributes
- Defined in:
- lib/pfrpg_core/attributes.rb
Instance Attribute Summary collapse
-
#max_dex ⇒ Object
Returns the value of attribute max_dex.
-
#raw_cha ⇒ Object
Returns the value of attribute raw_cha.
-
#raw_con ⇒ Object
Returns the value of attribute raw_con.
-
#raw_dex ⇒ Object
Returns the value of attribute raw_dex.
-
#raw_int ⇒ Object
Returns the value of attribute raw_int.
-
#raw_str ⇒ Object
Returns the value of attribute raw_str.
-
#raw_wis ⇒ Object
Returns the value of attribute raw_wis.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #cha_mod ⇒ Object
- #con_mod ⇒ Object
- #dex_mod ⇒ Object
- #get_modified(attribute) ⇒ Object
- #get_modifier(val) ⇒ Object
-
#initialize(attributes, bonuses = Bonuses.new) ⇒ Attributes
constructor
A new instance of Attributes.
- #int_mod ⇒ Object
- #modified_cha ⇒ Object (also: #charisma)
- #modified_con ⇒ Object (also: #constitution)
- #modified_dex ⇒ Object (also: #dexterity)
- #modified_int ⇒ Object (also: #intelligence)
- #modified_str ⇒ Object (also: #strength)
- #modified_wis ⇒ Object (also: #wisdom)
- #set_bonuses(bonuses) ⇒ Object
- #str_mod ⇒ Object
- #wis_mod ⇒ Object
Constructor Details
#initialize(attributes, bonuses = Bonuses.new) ⇒ Attributes
Returns a new instance of Attributes.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/pfrpg_core/attributes.rb', line 7 def initialize(attributes,bonuses=Bonuses.new) @raw_int = attributes[:raw_int] @raw_con = attributes[:raw_con] @raw_str = attributes[:raw_str] @raw_wis = attributes[:raw_wis] @raw_cha = attributes[:raw_cha] @raw_dex = attributes[:raw_dex] @max_dex = attributes[:max_dex] || 1000 @bonuses = bonuses end |
Instance Attribute Details
#max_dex ⇒ Object
Returns the value of attribute max_dex.
4 5 6 |
# File 'lib/pfrpg_core/attributes.rb', line 4 def max_dex @max_dex end |
#raw_cha ⇒ Object
Returns the value of attribute raw_cha.
4 5 6 |
# File 'lib/pfrpg_core/attributes.rb', line 4 def raw_cha @raw_cha end |
#raw_con ⇒ Object
Returns the value of attribute raw_con.
4 5 6 |
# File 'lib/pfrpg_core/attributes.rb', line 4 def raw_con @raw_con end |
#raw_dex ⇒ Object
Returns the value of attribute raw_dex.
4 5 6 |
# File 'lib/pfrpg_core/attributes.rb', line 4 def raw_dex @raw_dex end |
#raw_int ⇒ Object
Returns the value of attribute raw_int.
4 5 6 |
# File 'lib/pfrpg_core/attributes.rb', line 4 def raw_int @raw_int end |
#raw_str ⇒ Object
Returns the value of attribute raw_str.
4 5 6 |
# File 'lib/pfrpg_core/attributes.rb', line 4 def raw_str @raw_str end |
#raw_wis ⇒ Object
Returns the value of attribute raw_wis.
4 5 6 |
# File 'lib/pfrpg_core/attributes.rb', line 4 def raw_wis @raw_wis end |
Instance Method Details
#as_json(options = {}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/pfrpg_core/attributes.rb', line 85 def as_json(={}) { :values => { :strength => modified_str, :dexterity => modified_dex, :charisma => modified_cha, :wisdom => modified_wis, :constitution => modified_con, :intelligence => modified_int }, :modifier => { :strength => str_mod, :dexterity => dex_mod, :charisma => cha_mod, :wisdom => wis_mod, :constitution => con_mod, :intelligence => int_mod } } end |
#cha_mod ⇒ Object
62 63 64 |
# File 'lib/pfrpg_core/attributes.rb', line 62 def cha_mod get_modifier(modified_cha) end |
#con_mod ⇒ Object
54 55 56 |
# File 'lib/pfrpg_core/attributes.rb', line 54 def con_mod get_modifier(modified_con) end |
#dex_mod ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/pfrpg_core/attributes.rb', line 34 def dex_mod # TODO : feats let you overcome this dex = get_modifier(modified_dex) max = @max_dex dex = max if (dex > max) dex end |
#get_modified(attribute) ⇒ Object
74 75 76 77 78 |
# File 'lib/pfrpg_core/attributes.rb', line 74 def get_modified(attribute) base = self.send("raw_#{attribute}") || 0 base += NullObject.maybe(@bonuses.get(attribute)).to_i base end |
#get_modifier(val) ⇒ Object
80 81 82 |
# File 'lib/pfrpg_core/attributes.rb', line 80 def get_modifier(val) return ((val - 10) / 2.0).floor end |
#int_mod ⇒ Object
26 27 28 |
# File 'lib/pfrpg_core/attributes.rb', line 26 def int_mod get_modifier(modified_int) end |
#modified_cha ⇒ Object Also known as: charisma
58 59 60 |
# File 'lib/pfrpg_core/attributes.rb', line 58 def modified_cha get_modified('cha') end |
#modified_con ⇒ Object Also known as: constitution
50 51 52 |
# File 'lib/pfrpg_core/attributes.rb', line 50 def modified_con get_modified('con') end |
#modified_dex ⇒ Object Also known as: dexterity
30 31 32 |
# File 'lib/pfrpg_core/attributes.rb', line 30 def modified_dex get_modified('dex') end |
#modified_int ⇒ Object Also known as: intelligence
22 23 24 |
# File 'lib/pfrpg_core/attributes.rb', line 22 def modified_int get_modified('int') end |
#modified_str ⇒ Object Also known as: strength
42 43 44 |
# File 'lib/pfrpg_core/attributes.rb', line 42 def modified_str get_modified('str') end |
#modified_wis ⇒ Object Also known as: wisdom
66 67 68 |
# File 'lib/pfrpg_core/attributes.rb', line 66 def modified_wis get_modified('wis') end |
#set_bonuses(bonuses) ⇒ Object
18 19 20 |
# File 'lib/pfrpg_core/attributes.rb', line 18 def set_bonuses(bonuses) @bonuses = bonuses end |
#str_mod ⇒ Object
46 47 48 |
# File 'lib/pfrpg_core/attributes.rb', line 46 def str_mod get_modifier(modified_str) end |
#wis_mod ⇒ Object
70 71 72 |
# File 'lib/pfrpg_core/attributes.rb', line 70 def wis_mod get_modifier(modified_wis) end |