Class: PfrpgCore::FeatureTotaler
- Inherits:
-
Object
- Object
- PfrpgCore::FeatureTotaler
- Defined in:
- lib/pfrpg_core/feature_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_is_feat(choice) ⇒ Object
- #feature_granted ⇒ Object
- #flatten_options(feature_choice) ⇒ Object
- #get_base_features ⇒ Object
- #get_choose_features ⇒ Object
-
#initialize(entity) ⇒ FeatureTotaler
constructor
A new instance of FeatureTotaler.
- #level_granted ⇒ Object
- #parse_features ⇒ Object
- #race_granted ⇒ Object
Constructor Details
#initialize(entity) ⇒ FeatureTotaler
Returns a new instance of FeatureTotaler.
4 5 6 7 8 9 10 |
# File 'lib/pfrpg_core/feature_totaler.rb', line 4 def initialize(entity) @entity = entity @levels = PfrpgCore::LevelParser.new(entity.level) @base_features = [] @choose_features = [] parse_features end |
Instance Attribute Details
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
3 4 5 |
# File 'lib/pfrpg_core/feature_totaler.rb', line 3 def entity @entity end |
#levels ⇒ Object (readonly)
Returns the value of attribute levels.
3 4 5 |
# File 'lib/pfrpg_core/feature_totaler.rb', line 3 def levels @levels end |
Instance Method Details
#choice_is_feat(choice) ⇒ Object
80 81 82 |
# File 'lib/pfrpg_core/feature_totaler.rb', line 80 def choice_is_feat(choice) choice.class.to_s['Feat'] != nil end |
#feature_granted ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/pfrpg_core/feature_totaler.rb', line 72 def feature_granted i = entity.class_features.inject(0) do |sum, x| choices = x.bonus_choices sum += (choices.select { |c| choice_is_feat(c) }).size end return i end |
#flatten_options(feature_choice) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pfrpg_core/feature_totaler.rb', line 44 def (feature_choice) ap "feature chioce:" ap feature_choice.choices[:options][0] if feature_choice.choices[:options][0].respond_to? 'name' = feature_choice.choices[:options].map { |x| x.name } ap "New options:" ap feature_choice.choices[:options] = end return feature_choice end |
#get_base_features ⇒ Object
12 13 14 |
# File 'lib/pfrpg_core/feature_totaler.rb', line 12 def get_base_features @base_features end |
#get_choose_features ⇒ Object
16 17 18 |
# File 'lib/pfrpg_core/feature_totaler.rb', line 16 def get_choose_features @choose_features end |
#level_granted ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/pfrpg_core/feature_totaler.rb', line 56 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 |
#parse_features ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pfrpg_core/feature_totaler.rb', line 20 def parse_features choices = [] lvls = levels.parse lvls.keys.each do |hc| clazz = PfrpgClasses::Heroclass.by_name(hc) level = lvls[hc] (1..level).each do |l| class_features = clazz.bonuses_for_level(l)[:granted_features] class_features.each do |x| ap "Creating granted feature:" ap "\t#{x} (#{hc})" @base_features << ClassFeature.granted_feature(x, hc) end 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 end |
#race_granted ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/pfrpg_core/feature_totaler.rb', line 64 def race_granted race = entity.race i = race.bonus_choices.inject(0) do |sum, x| sum = sum + 1 if choice_is_feat(x) end return i end |