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
Returns a new instance of FeatTotaler.
4 5 6 7 8 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 4 def initialize(entity) @entity = entity @levels = entity.levels @total_level = levels.inject(0) { |sum, x| sum + x.rank } 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 39 def choice_granted choices = [] @levels.each do |level| clazz = PfrpgClasses::Heroclass.by_name(level.classname) (1..level.rank).each do |l| clazz.bonuses_for_level(l)[:choices].each do |choice| if (choice_is_feat(choice)) #TODO : this wont support another object choice.npc_id = entity.character_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
29 30 31 32 33 34 35 36 37 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 29 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
14 15 16 17 18 19 20 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 14 def level_granted i = (1..@total_level).inject(0) do |sum, x| choices = PfrpgTables::Tables::LevelTable.for_level(x)[:choices] sum + (choices.select { |c| choice_is_feat(c) }).size end return i end |
#race_granted ⇒ Object
22 23 24 25 26 27 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 22 def race_granted i = entity.race.bonus_choices.inject(0) do |sum, x| sum + 1 if choice_is_feat(x) end return i end |
#total ⇒ Object
10 11 12 |
# File 'lib/pfrpg_core/feat_totaler.rb', line 10 def total return level_granted + race_granted + feature_granted + choice_granted end |