Class: PfrpgCore::FeatTotaler
- Inherits:
-
Object
- Object
- PfrpgCore::FeatTotaler
- Defined in:
- lib/pfrpg_core/feat_totaler.rb
Instance Attribute Summary collapse
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
-
#levels ⇒ Object
readonly
Returns the value of attribute levels.
Instance Method Summary collapse
- #choice_granted ⇒ Object
- #choice_is_feat(choice) ⇒ Object
- #feature_granted ⇒ Object
-
#initialize(entity) ⇒ FeatTotaler
constructor
A new instance of FeatTotaler.
- #level_granted ⇒ Object
- #race_granted ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(entity) ⇒ FeatTotaler
4 5 6 7 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 4 def initialize(entity) @entity = entity @levels = PfrpgCore::LevelParser.new(entity.level) end |
Instance Attribute Details
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
3 4 5 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 3 def entity @entity end |
#levels ⇒ Object (readonly)
Returns the value of attribute levels.
3 4 5 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 3 def levels @levels end |
Instance Method Details
#choice_granted ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 38 def choice_granted choices = [] lvls = @levels.parse lvls.keys.each do |hc| clazz = PfrpgClasses::Heroclass.by_name(hc) level = lvls[hc] (1..level).each do |l| clazz.bonuses_for_level(l)[:choices].each do |choice| if (choice_is_feat(choice)) choice.npc_id = entity.id choices << choice end end end end @choose_features = choices.flatten.size end |
#choice_is_feat(choice) ⇒ Object
56 57 58 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 56 def choice_is_feat(choice) choice.class.to_s['Feat'] != nil end |
#feature_granted ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 28 def feature_granted i = entity.class_features.inject(0) do |sum, x| if x.respond_to? 'granted_choice' choices = [x.granted_choice].flatten sum += (choices.select { |c| choice_is_feat(c) }).size end end return i || 0 end |
#level_granted ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 13 def level_granted i = (1..levels.total).inject(0) do |sum, x| choices = PfrpgTables::Tables::LevelTable.for_level(x)[:choices] sum = sum + (choices.select { |c| choice_is_feat(c) }).size end return i end |
#race_granted ⇒ Object
21 22 23 24 25 26 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 21 def race_granted i = entity.race.bonus_choices.inject(0) do |sum, x| sum = sum + 1 if choice_is_feat(x) end return i end |
#total ⇒ Object
9 10 11 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 9 def total return level_granted + race_granted + feature_granted + choice_granted end |