Class: PfrpgCore::FeatTotaler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#entityObject (readonly)

Returns the value of attribute entity.



3
4
5
# File 'lib/pfrpg_core/feat_totaler.rb', line 3

def entity
  @entity
end

#levelsObject (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_grantedObject



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_grantedObject



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_grantedObject



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_grantedObject



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

#totalObject



9
10
11
# File 'lib/pfrpg_core/feat_totaler.rb', line 9

def total
  return level_granted + race_granted + feature_granted + choice_granted
end