Class: PfrpgReaders::PrettySkill
- Inherits:
-
Object
- Object
- PfrpgReaders::PrettySkill
- Includes:
- PfrpgCore::Filterable
- Defined in:
- lib/pfrpg_readers/skills_reader.rb
Instance Attribute Summary collapse
-
#ac_penalty ⇒ Object
readonly
Returns the value of attribute ac_penalty.
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#class_skill ⇒ Object
readonly
Returns the value of attribute class_skill.
-
#filter_str ⇒ Object
readonly
Returns the value of attribute filter_str.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#misc_bonus ⇒ Object
Returns the value of attribute misc_bonus.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stat_bonus ⇒ Object
readonly
Returns the value of attribute stat_bonus.
-
#total_bonus ⇒ Object
readonly
Returns the value of attribute total_bonus.
-
#trained_rank ⇒ Object
readonly
Returns the value of attribute trained_rank.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #calculate_ac_penalty(skill, character) ⇒ Object
- #calculate_attribute_bonus(skill, character) ⇒ Object
- #calculate_misc_bonus(skill, character) ⇒ Object
- #class_skill_bonuses(character) ⇒ Object
-
#initialize(skill, character, skill_filters) ⇒ PrettySkill
constructor
A new instance of PrettySkill.
- #is_class_skill?(skill, character) ⇒ Boolean
- #total_bonuses ⇒ Object
Constructor Details
#initialize(skill, character, skill_filters) ⇒ PrettySkill
Returns a new instance of PrettySkill.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 34 def initialize(skill, character, skill_filters) @class_skill = is_class_skill?(skill, character) @ac_penalty = calculate_ac_penalty(skill, character) @name = skill[:skill].description @trained_rank = skill[:char_skill]['trained_rank'] @stat_bonus = calculate_attribute_bonus(skill, character) @misc_bonus = calculate_misc_bonus(skill, character) @attribute = skill[:skill].attribute @total_bonus = total_bonuses @filters = skill_filters @filter_str = [] apply_filters end |
Instance Attribute Details
#ac_penalty ⇒ Object (readonly)
Returns the value of attribute ac_penalty.
30 31 32 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 30 def ac_penalty @ac_penalty end |
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
30 31 32 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 30 def attribute @attribute end |
#class_skill ⇒ Object (readonly)
Returns the value of attribute class_skill.
30 31 32 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 30 def class_skill @class_skill end |
#filter_str ⇒ Object (readonly)
Returns the value of attribute filter_str.
30 31 32 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 30 def filter_str @filter_str end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
30 31 32 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 30 def filters @filters end |
#misc_bonus ⇒ Object
Returns the value of attribute misc_bonus.
30 31 32 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 30 def misc_bonus @misc_bonus end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 30 def name @name end |
#stat_bonus ⇒ Object (readonly)
Returns the value of attribute stat_bonus.
30 31 32 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 30 def stat_bonus @stat_bonus end |
#total_bonus ⇒ Object (readonly)
Returns the value of attribute total_bonus.
30 31 32 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 30 def total_bonus @total_bonus end |
#trained_rank ⇒ Object (readonly)
Returns the value of attribute trained_rank.
30 31 32 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 30 def trained_rank @trained_rank end |
Instance Method Details
#as_json(options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 52 def as_json(={}) { :class_skill => @class_skill, :ac_penalty => @ac_penalty, :name => @name, :trained_rank => @trained_rank, :stat_bonus => @stat_bonus, :misc_bonus => @misc_bonus, :total_bonus => @total_bonus, :attribute => @attribute } end |
#calculate_ac_penalty(skill, character) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 85 def calculate_ac_penalty(skill, character) ac_penalty = 0 if skill[:skill].ac_penalty? ac_penalty = character.get_ac_penalty end ac_penalty end |
#calculate_attribute_bonus(skill, character) ⇒ Object
93 94 95 96 97 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 93 def calculate_attribute_bonus(skill, character) attribute = skill[:skill].attribute bonus = character.send("#{attribute}_mod") bonus ||= 0 end |
#calculate_misc_bonus(skill, character) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 105 def calculate_misc_bonus(skill, character) if skill[:skill].respond_to? "bonus_str" misc = character.get_bonus(skill[:skill].bonus_str).to_i else misc = character.get_bonus(skill[:skill].description).to_i end misc ||= 0 end |
#class_skill_bonuses(character) ⇒ Object
79 80 81 82 83 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 79 def class_skill_bonuses(character) bonuses = character.get_bonus("class_skill") bonuses ||= [] return bonuses end |
#is_class_skill?(skill, character) ⇒ Boolean
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 65 def is_class_skill?(skill, character) found = character.latest_levels.any? do |l| l.heroclass.skills.find { |x| x.to_s == skill[:skill].to_s } end found ||= class_skill_bonuses(character).find do |x| if x x.downcase == skill[:skill].description.downcase else false end end return (found != nil && found) end |
#total_bonuses ⇒ Object
99 100 101 102 103 |
# File 'lib/pfrpg_readers/skills_reader.rb', line 99 def total_bonuses total = @misc_bonus + @stat_bonus - @ac_penalty + @trained_rank total += 3 if (@class_skill && @trained_rank > 0) total end |