Class: PfrpgReaders::MiscReader
- Inherits:
-
Object
- Object
- PfrpgReaders::MiscReader
- Includes:
- FeatureDuplicator
- Defined in:
- lib/pfrpg_readers/misc_reader.rb
Defined Under Namespace
Classes: PrettyClassFeature, PrettyFeat, PrettyLevel
Instance Attribute Summary collapse
-
#alignment ⇒ Object
readonly
Returns the value of attribute alignment.
-
#class_features ⇒ Object
readonly
Returns the value of attribute class_features.
-
#feats ⇒ Object
readonly
Returns the value of attribute feats.
-
#hit_points ⇒ Object
readonly
Returns the value of attribute hit_points.
-
#initiative ⇒ Object
readonly
Returns the value of attribute initiative.
-
#languages ⇒ Object
readonly
Returns the value of attribute languages.
-
#levels ⇒ Object
readonly
Returns the value of attribute levels.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#speed ⇒ Object
readonly
Returns the value of attribute speed.
-
#total_level ⇒ Object
readonly
Returns the value of attribute total_level.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #calc_speed(speed_type, base) ⇒ Object
- #gen_class_features ⇒ Object
- #gen_feats ⇒ Object
- #gen_hit_points ⇒ Object
- #gen_initiative ⇒ Object
- #gen_levels ⇒ Object
- #gen_speed ⇒ Object
- #gen_total_level ⇒ Object
-
#initialize(character) ⇒ MiscReader
constructor
A new instance of MiscReader.
- #level_string ⇒ Object
- #parse_speed_bonuses(speed_bonuses) ⇒ Object
Methods included from FeatureDuplicator
#dupe_words, #filter_duplicates, #parse_number, #smallest
Constructor Details
#initialize(character) ⇒ MiscReader
Returns a new instance of MiscReader.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 6 def initialize(character) @character = character @initiative = gen_initiative @speed = gen_speed @feats = gen_feats @class_features = gen_class_features @levels = gen_levels @total_level = gen_total_level @hit_points = gen_hit_points @alignment = character.alignment @size = character.racial_size end |
Instance Attribute Details
#alignment ⇒ Object (readonly)
Returns the value of attribute alignment.
4 5 6 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 4 def alignment @alignment end |
#class_features ⇒ Object (readonly)
Returns the value of attribute class_features.
4 5 6 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 4 def class_features @class_features end |
#feats ⇒ Object (readonly)
Returns the value of attribute feats.
4 5 6 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 4 def feats @feats end |
#hit_points ⇒ Object (readonly)
Returns the value of attribute hit_points.
4 5 6 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 4 def hit_points @hit_points end |
#initiative ⇒ Object (readonly)
Returns the value of attribute initiative.
4 5 6 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 4 def initiative @initiative end |
#languages ⇒ Object (readonly)
Returns the value of attribute languages.
4 5 6 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 4 def languages @languages end |
#levels ⇒ Object (readonly)
Returns the value of attribute levels.
4 5 6 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 4 def levels @levels end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 4 def size @size end |
#speed ⇒ Object (readonly)
Returns the value of attribute speed.
4 5 6 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 4 def speed @speed end |
#total_level ⇒ Object (readonly)
Returns the value of attribute total_level.
4 5 6 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 4 def total_level @total_level end |
Instance Method Details
#as_json(options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 19 def as_json(={}) { :initiative => @initiative, :alignment => @alignment, :speed => @speed, :hit_points => @hit_points, :feats => @feats, :class_features => @class_features, :levels => @levels, :total_level => @total_level, :size => @size, :level_string => level_string, :temporary => @character.temp_values } end |
#calc_speed(speed_type, base) ⇒ Object
76 77 78 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 76 def calc_speed(speed_type, base) base + @character.get_bonus("#{speed_type}_speed") end |
#gen_class_features ⇒ Object
91 92 93 94 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 91 def gen_class_features features = @character.class_features.map { |x| PrettyClassFeature.new(x) } filter_duplicates(features) end |
#gen_feats ⇒ Object
87 88 89 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 87 def gen_feats @character.total_feats.map { |x| PrettyFeat.new(x) } end |
#gen_hit_points ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 44 def gen_hit_points hp = @character.hit_points # TODO : potentially move off this method when multiple hp affect stats exist if (@feats.find { |x| x.name == 'Toughness' }) hp += 3 if (total_level > 3) hp += total_level - 3 end end return hp end |
#gen_initiative ⇒ Object
80 81 82 83 84 85 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 80 def gen_initiative initiative = 0 initiative += @character.dex_mod initiative += @character.get_bonus("initiative").to_i return initiative end |
#gen_levels ⇒ Object
96 97 98 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 96 def gen_levels @character.latest_levels.map { |x| PrettyLevel.new(x, @character) } end |
#gen_speed ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 64 def gen_speed base_speed = NullObject.maybe(@character.race).speed || 0 base_speed += parse_speed_bonuses(@character.get_bonus("speed")) base_speed -= @character.armor_speed_penalty speeds = {} ['land','fly','climb','swim'].each do |type| speeds["#{type}_speed"] = calc_speed(type, base_speed) end speeds['speed'] = speeds['land_speed'] return speeds end |
#gen_total_level ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 56 def gen_total_level if @character.respond_to? 'get_last_level' return 0 if @character.levels.empty? return @character.get_last_level.number end @character.latest_levels.inject(0) {|sum, x| sum = sum + x.class_number } end |
#level_string ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 35 def level_string str = "#{alignment} :" @levels.each do |l| str += "#{l.name}/#{l.level}" str += "*" if l.favored end str end |
#parse_speed_bonuses(speed_bonuses) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/pfrpg_readers/misc_reader.rb', line 100 def parse_speed_bonuses(speed_bonuses) speed_bonus = 0 speed_bonuses.each do |s| speed_bonus += s.to_i if MathHelper.is_number(s) end speed_bonus end |