Class: Adventure::Being
- Inherits:
-
Object
- Object
- Adventure::Being
- Defined in:
- lib/adventure/being.rb
Overview
Represents any ingame being.
By being, this means any creature, plant, fungus, NPC, Player, or thing that has a monster stat block.
This class implements basic D&D stat management functionalities, as well as battle capabilities.
Constant Summary collapse
- ABILITIES =
List of all valid abilities.
%i[str dex con int wis cha].freeze
- SKILLS =
List of all valid skills.
%i[acrobatics animal_handling arcana athletics deception history insight intimidation investigation medicine nature perception performance persuasion religion sleight_hand stealth survival].freeze
- SIZES =
%w[Fine Diminutive Tiny Small Medium Large Huge Gargantuan Colossal].freeze
- TYPES =
%w[Aberration Animal Beast Celestial Construct Dragon Elemental Fey Fiend Giant Humanoid Ooze Outsider Plant Undead Vermin].freeze
Instance Attribute Summary collapse
-
#ac ⇒ Object
readonly
Being's Armor Class.
-
#ac_desc ⇒ Object
readonly
Being's AC description, if any.
-
#actions_header ⇒ Object
readonly
Being's Actions' header.
-
#actions_list ⇒ Object
readonly
Being's Array of Actions.
-
#align ⇒ Object
readonly
Being's alignment.
-
#bonus_actions_header ⇒ Object
readonly
Being's Bonus Actions' header.
-
#bonus_actions_list ⇒ Object
readonly
Being's Array of Bonus Actions.
-
#cha ⇒ Object
readonly
Being's Charisma score.
-
#con ⇒ Object
readonly
Being's Constitution score.
-
#condition_immunities ⇒ Object
readonly
Being's Array of Condition Immunities, if any -- empty by default.
-
#cr ⇒ Object
readonly
Being's Challenge Rating.
-
#current_hp ⇒ Object
readonly
Being's current HP, initialized as the same as maximum HP.
-
#description ⇒ Object
readonly
Being's flavor description/informations.
-
#dex ⇒ Object
readonly
Being's Dexterity score.
-
#dmg_immunities ⇒ Object
readonly
Being's Array of Damage Immunities, if any -- empty by default.
-
#dmg_resistances ⇒ Object
readonly
Being's Array of Damage Resistances, if any -- empty by default.
-
#dmg_vulnerabilities ⇒ Object
readonly
Being's Array of Damage Vulnerabilities, if any -- empty by default.
-
#environment ⇒ Object
readonly
Being's Array of environments.
-
#hp ⇒ Object
readonly
Being's total/maximum Hit Points.
-
#hp_formula ⇒ Object
readonly
Being's HP dice formula.
-
#int ⇒ Object
readonly
Being's Intelligence score.
-
#inventory ⇒ Object
readonly
Being's list of Items.
-
#languages ⇒ Object
readonly
Being's Array of known languages.
-
#legendary_actions_count ⇒ Object
readonly
Being's number of Legendary Actions, as Integer.
-
#legendary_actions_header ⇒ Object
readonly
Being's Legendary Actions' header.
-
#legendary_actions_list ⇒ Object
readonly
Being's Array of Legendary Actions.
-
#levels ⇒ Object
readonly
Being's Hash of levels by, when applicable, class, or Integer of total level.
-
#mythic_actions_header ⇒ Object
readonly
Being's Mythic Actions' header.
-
#mythic_actions_list ⇒ Object
readonly
Being's Array of Mythic Actions.
-
#name ⇒ Object
readonly
Being's name.
-
#passive_perception ⇒ Object
readonly
Being's Passive Perception score.
-
#proficiency ⇒ Object
readonly
Being's Proficiency bonus.
-
#purse ⇒ Object
readonly
Being's Purse.
-
#reactions_header ⇒ Object
readonly
Being's Reactions' header.
-
#reactions_list ⇒ Object
readonly
Being's Array of Reactions.
-
#senses ⇒ Object
readonly
Being's Array of senses, empty by default.
-
#size ⇒ Object
readonly
Being's size.
-
#source ⇒ Object
readonly
Being's source text, when applicable.
-
#speed ⇒ Object
readonly
Being's Hash of speeds, with five elements representing walk, burrow, climb, fly, and swim speeds -- the ones that don't apply set to
nil. -
#spell_footer ⇒ Object
readonly
Being's Spellcasting block footer --
nilif not applicable. -
#spell_header ⇒ Object
readonly
Being's Spellcasting block header --
nilif not applicable. -
#spell_list ⇒ Object
readonly
Being's Spellcasting array of spells -- empty by default.
-
#str ⇒ Object
readonly
Being's Strength score.
-
#subtype ⇒ Object
readonly
Being's subtype, if any.
-
#swarm ⇒ Object
readonly
Whether or not this is a swarm of beings.
-
#traits ⇒ Object
readonly
Being's Array of Traits.
-
#type ⇒ Object
readonly
Being's type.
-
#wis ⇒ Object
readonly
Being's Wisdom score.
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Whether this Being is alive or not.
-
#damage(amount) ⇒ Integer
Deal some damage to this Being, modifying the current HP accordingly.
-
#dead? ⇒ Boolean
Whether this Being is dead or not.
-
#heal(amount) ⇒ Integer
Heal this Being by the given amount, modifying the current HP accordingly.
-
#initialize(name, **opts) ⇒ Being
constructor
Create a new instance of Being.
-
#modifier(value) ⇒ Integer
private
Get the modifier for the given attribute's value.
-
#proficiency_bonus(levels) ⇒ Integer
private
Calculate proficiency bonus according to Someone_Evil's formula.
-
#roll_for_abilities(**opts) ⇒ Object
private
Set ability scores randomly.
-
#roll_for_save(ability) ⇒ Integer
Roll for a Saving Throw for the given ability.
-
#roll_for_skill(skill) ⇒ Integer
Roll for the given Skill.
-
#save(ability) ⇒ Integer
Get the Saving Throw modifier for the given ability.
-
#skill(skill) ⇒ Integer
Get the Skill modifier for the given skill.
-
#to_a ⇒ Array
Get an Array of the being's abilities in the classical order: Strength, Dexterity, Constitution, Intelligence, Wisdom, and Charisma.
-
#to_h ⇒ Hash
Get a Hash of the being's abilities, indexed by each ability abbreviation.
-
#to_i ⇒ Integer
Get either the being's Challenge Rating or the sum of its levels.
-
#to_s ⇒ String
Get the being's name.
Constructor Details
#initialize(name, **opts) ⇒ Being
Create a new instance of Being.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/adventure/being.rb', line 172 def initialize(name, **opts) @name = name.strip @source = opts.key?(:source) ? opts[:source].strip : nil @align = opts.key?(:align) ? opts[:align].strip : 'Unaligned' if opts.key? :cr @cr = opts.key?(:cr) ? opts[:cr].to_f : 0.0 @levels = nil else @cr = nil @levels = opts.key?(:levels) ? opts[:levels].to_a : {} end @proficiency = if @levels.nil? proficiency_bonus(@cr.to_i) else proficiency_bonus(@levels) end @size = opts.key?(:size) ? opts[:size].strip.capitalize : nil @size = 'Medium' unless SIZES.include? @size @type = opts.key?(:type) ? opts[:type].strip.capitalize : nil @type = 'Humanoid' unless TYPES.include? @type @subtype = opts.key?(:subtype) ? opts[:subtype].strip.capitalize : '' @swarm = opts.key?(:swarm) ? (opts[:swarm] == true) : false @speed = if opts.key?(:speed) opts[:speed].to_h else { walk: 0, burrow: 0, climb: 0, fly: 0, swim: 0 } end @senses = opts.key?(:senses) ? opts[:senses].to_a : [] @senses.map! { |x| x.to_s } if opts.key? :rand_abilities prefs = opts.key?(:ability_preferences) ? opts[:ability_preferences].to_a : nil min = opts.key?(:ability_min) ? opts[:ability_min].to_i : 1 max = opts.key?(:ability_max) ? opts[:ability_max].to_i : 20 roll_for_abilities(prefs: prefs, min: min, max: max) else @str = opts.key?(:str) ? opts[:@str].to_i : 10 @dex = opts.key?(:dex) ? opts[:@dex].to_i : 10 @con = opts.key?(:con) ? opts[:@con].to_i : 10 @int = opts.key?(:int) ? opts[:@int].to_i : 10 @wis = opts.key?(:wis) ? opts[:@wis].to_i : 10 @cha = opts.key?(:cha) ? opts[:@cha].to_i : 10 end @languages = opts.key?(:languages) ? opts[:languages].to_a : [] @languages.map! { |x| x.to_s } @saves = if opts.key? :saves opts[:saves].to_a.uniq else [] end @saves.select! { |save| ABILITIES.include? save } @skills = if opts.key? :skills opts[:skills].to_a.uniq else [] end @skills.select! { |skill| SKILLS.include? skill } @skills_expertise = if opts.key? :skills_expertise opts[:skills_expertise].to_a.uniq else [] end @skills_expertise.select! { |skill| SKILLS.include? skill } @ac = opts.key?(:ac) ? opts[:ac].to_i : 0 @ac_desc = opts.key?(:ac_desc) ? opts[:ac_desc].strip : nil @hp = opts.key?(:hp) ? opts[:hp].to_i : 0 @current_hp = @hp @hp_formula = opts.key?(:hp_formula) ? opts[:hp_formula].strip : nil @dmg_vulnerabilities = opts.key?(:dmg_vulnerabilities) ? opts[:dmg_vulnerabilities].to_a : [] @dmg_resistances = opts.key?(:dmg_resistances) ? opts[:dmg_resistances].to_a : [] @dmg_immunities = opts.key?(:dmg_immunities) ? opts[:dmg_immunities].to_a : [] @condition_immunities = opts.key?(:condition_immunities) ? opts[:condition_immunities].to_a : [] @spell_header = opts.key?(:spell_header) ? opts[:spell_header].strip : '' @spell_footer = opts.key?(:spell_footer) ? opts[:spell_footer].strip : '' @spell_list = opts.key?(:spell_list) ? opts[:spell_list].to_a : [] @traits = opts.key?(:traits) ? opts[:traits].to_a : [] @actions_header = opts.key?(:actions_header) ? opts[:actions_header].strip : '' @actions_list = opts.key?(:actions_list) ? opts[:actions_list].to_a : [] @bonus_actions_header = opts.key?(:bonus_actions_header) ? opts[:bonus_actions_header].strip : '' @bonus_actions_list = opts.key?(:bonus_actions_list) ? opts[:bonus_actions_list].to_a : [] @reactions_header = opts.key?(:reactions_header) ? opts[:reactions_header].strip : '' @reactions_list = opts.key?(:reactions_list) ? opts[:reactions_list].to_a : [] @legendary_actions_header = opts.key?(:legendary_actions_header) ? opts[:legendary_actions_header].strip : '' @legendary_actions_count = opts.key?(:legendary_actions_count) ? opts[:legendary_actions_count].to_i : 0 @legendary_actions_list = opts.key?(:legendary_actions_list) ? opts[:legendary_actions_list].to_a : [] @mythic_actions_header = opts.key?(:mythic_actions_header) ? opts[:mythic_actions_header].strip : '' @mythic_actions_list = opts.key?(:mythic_actions_list) ? opts[:mythic_actions_list].to_a : [] @inventory = opts.key?(:inventory) ? opts[:inventory] : [] @inventory = Inventory.new unless @inventory.is_a? Inventory @purse = opts.key?(:purse) ? opts[:purse] : [] @purse = Purse.new unless @purse.is_a? Purse @description = opts.key?(:description) ? opts[:description].strip : '' @environment = opts.key?(:environment) ? opts[:environment].to_a : [] end |
Instance Attribute Details
#ac ⇒ Object (readonly)
Being's Armor Class.
61 62 63 |
# File 'lib/adventure/being.rb', line 61 def ac @ac end |
#ac_desc ⇒ Object (readonly)
Being's AC description, if any.
63 64 65 |
# File 'lib/adventure/being.rb', line 63 def ac_desc @ac_desc end |
#actions_header ⇒ Object (readonly)
Being's Actions' header.
87 88 89 |
# File 'lib/adventure/being.rb', line 87 def actions_header @actions_header end |
#actions_list ⇒ Object (readonly)
Being's Array of Actions.
89 90 91 |
# File 'lib/adventure/being.rb', line 89 def actions_list @actions_list end |
#align ⇒ Object (readonly)
Being's alignment.
25 26 27 |
# File 'lib/adventure/being.rb', line 25 def align @align end |
#bonus_actions_header ⇒ Object (readonly)
Being's Bonus Actions' header.
91 92 93 |
# File 'lib/adventure/being.rb', line 91 def bonus_actions_header @bonus_actions_header end |
#bonus_actions_list ⇒ Object (readonly)
Being's Array of Bonus Actions.
93 94 95 |
# File 'lib/adventure/being.rb', line 93 def bonus_actions_list @bonus_actions_list end |
#cha ⇒ Object (readonly)
Being's Charisma score.
57 58 59 |
# File 'lib/adventure/being.rb', line 57 def cha @cha end |
#con ⇒ Object (readonly)
Being's Constitution score.
51 52 53 |
# File 'lib/adventure/being.rb', line 51 def con @con end |
#condition_immunities ⇒ Object (readonly)
Being's Array of Condition Immunities, if any -- empty by default.
77 78 79 |
# File 'lib/adventure/being.rb', line 77 def condition_immunities @condition_immunities end |
#cr ⇒ Object (readonly)
Being's Challenge Rating.
27 28 29 |
# File 'lib/adventure/being.rb', line 27 def cr @cr end |
#current_hp ⇒ Object (readonly)
Being's current HP, initialized as the same as maximum HP.
67 68 69 |
# File 'lib/adventure/being.rb', line 67 def current_hp @current_hp end |
#description ⇒ Object (readonly)
Being's flavor description/informations.
113 114 115 |
# File 'lib/adventure/being.rb', line 113 def description @description end |
#dex ⇒ Object (readonly)
Being's Dexterity score.
49 50 51 |
# File 'lib/adventure/being.rb', line 49 def dex @dex end |
#dmg_immunities ⇒ Object (readonly)
Being's Array of Damage Immunities, if any -- empty by default.
75 76 77 |
# File 'lib/adventure/being.rb', line 75 def dmg_immunities @dmg_immunities end |
#dmg_resistances ⇒ Object (readonly)
Being's Array of Damage Resistances, if any -- empty by default.
73 74 75 |
# File 'lib/adventure/being.rb', line 73 def dmg_resistances @dmg_resistances end |
#dmg_vulnerabilities ⇒ Object (readonly)
Being's Array of Damage Vulnerabilities, if any -- empty by default.
71 72 73 |
# File 'lib/adventure/being.rb', line 71 def dmg_vulnerabilities @dmg_vulnerabilities end |
#environment ⇒ Object (readonly)
Being's Array of environments.
115 116 117 |
# File 'lib/adventure/being.rb', line 115 def environment @environment end |
#hp ⇒ Object (readonly)
Being's total/maximum Hit Points.
65 66 67 |
# File 'lib/adventure/being.rb', line 65 def hp @hp end |
#hp_formula ⇒ Object (readonly)
Being's HP dice formula.
69 70 71 |
# File 'lib/adventure/being.rb', line 69 def hp_formula @hp_formula end |
#int ⇒ Object (readonly)
Being's Intelligence score.
53 54 55 |
# File 'lib/adventure/being.rb', line 53 def int @int end |
#inventory ⇒ Object (readonly)
Being's list of Items.
109 110 111 |
# File 'lib/adventure/being.rb', line 109 def inventory @inventory end |
#languages ⇒ Object (readonly)
Being's Array of known languages.
45 46 47 |
# File 'lib/adventure/being.rb', line 45 def languages @languages end |
#legendary_actions_count ⇒ Object (readonly)
Being's number of Legendary Actions, as Integer.
101 102 103 |
# File 'lib/adventure/being.rb', line 101 def legendary_actions_count @legendary_actions_count end |
#legendary_actions_header ⇒ Object (readonly)
Being's Legendary Actions' header.
99 100 101 |
# File 'lib/adventure/being.rb', line 99 def legendary_actions_header @legendary_actions_header end |
#legendary_actions_list ⇒ Object (readonly)
Being's Array of Legendary Actions.
103 104 105 |
# File 'lib/adventure/being.rb', line 103 def legendary_actions_list @legendary_actions_list end |
#levels ⇒ Object (readonly)
Being's Hash of levels by, when applicable, class, or Integer of total level.
31 32 33 |
# File 'lib/adventure/being.rb', line 31 def levels @levels end |
#mythic_actions_header ⇒ Object (readonly)
Being's Mythic Actions' header.
105 106 107 |
# File 'lib/adventure/being.rb', line 105 def mythic_actions_header @mythic_actions_header end |
#mythic_actions_list ⇒ Object (readonly)
Being's Array of Mythic Actions.
107 108 109 |
# File 'lib/adventure/being.rb', line 107 def mythic_actions_list @mythic_actions_list end |
#name ⇒ Object (readonly)
Being's name.
21 22 23 |
# File 'lib/adventure/being.rb', line 21 def name @name end |
#passive_perception ⇒ Object (readonly)
Being's Passive Perception score.
59 60 61 |
# File 'lib/adventure/being.rb', line 59 def passive_perception @passive_perception end |
#proficiency ⇒ Object (readonly)
Being's Proficiency bonus.
29 30 31 |
# File 'lib/adventure/being.rb', line 29 def proficiency @proficiency end |
#purse ⇒ Object (readonly)
Being's Purse.
111 112 113 |
# File 'lib/adventure/being.rb', line 111 def purse @purse end |
#reactions_header ⇒ Object (readonly)
Being's Reactions' header.
95 96 97 |
# File 'lib/adventure/being.rb', line 95 def reactions_header @reactions_header end |
#reactions_list ⇒ Object (readonly)
Being's Array of Reactions.
97 98 99 |
# File 'lib/adventure/being.rb', line 97 def reactions_list @reactions_list end |
#senses ⇒ Object (readonly)
Being's Array of senses, empty by default.
43 44 45 |
# File 'lib/adventure/being.rb', line 43 def senses @senses end |
#size ⇒ Object (readonly)
Being's size.
33 34 35 |
# File 'lib/adventure/being.rb', line 33 def size @size end |
#source ⇒ Object (readonly)
Being's source text, when applicable.
23 24 25 |
# File 'lib/adventure/being.rb', line 23 def source @source end |
#speed ⇒ Object (readonly)
Being's Hash of speeds, with five elements representing walk, burrow, climb, fly, and swim speeds -- the ones that don't apply set to nil.
41 42 43 |
# File 'lib/adventure/being.rb', line 41 def speed @speed end |
#spell_footer ⇒ Object (readonly)
Being's Spellcasting block footer -- nil if not applicable.
81 82 83 |
# File 'lib/adventure/being.rb', line 81 def @spell_footer end |
#spell_header ⇒ Object (readonly)
Being's Spellcasting block header -- nil if not applicable.
79 80 81 |
# File 'lib/adventure/being.rb', line 79 def spell_header @spell_header end |
#spell_list ⇒ Object (readonly)
Being's Spellcasting array of spells -- empty by default.
83 84 85 |
# File 'lib/adventure/being.rb', line 83 def spell_list @spell_list end |
#str ⇒ Object (readonly)
Being's Strength score.
47 48 49 |
# File 'lib/adventure/being.rb', line 47 def str @str end |
#subtype ⇒ Object (readonly)
Being's subtype, if any.
37 38 39 |
# File 'lib/adventure/being.rb', line 37 def subtype @subtype end |
#swarm ⇒ Object (readonly)
Whether or not this is a swarm of beings.
39 40 41 |
# File 'lib/adventure/being.rb', line 39 def swarm @swarm end |
#traits ⇒ Object (readonly)
Being's Array of Traits.
85 86 87 |
# File 'lib/adventure/being.rb', line 85 def traits @traits end |
#type ⇒ Object (readonly)
Being's type.
35 36 37 |
# File 'lib/adventure/being.rb', line 35 def type @type end |
#wis ⇒ Object (readonly)
Being's Wisdom score.
55 56 57 |
# File 'lib/adventure/being.rb', line 55 def wis @wis end |
Instance Method Details
#alive? ⇒ Boolean
Whether this Being is alive or not.
Uses the current HP as parameter to define life status.
502 503 504 |
# File 'lib/adventure/being.rb', line 502 def alive? @current_hp.positive? end |
#damage(amount) ⇒ Integer
Deal some damage to this Being, modifying the current HP accordingly.
If the damage is greater than the current HP, the
latter is normalized to 0, instead.
463 464 465 466 467 468 |
# File 'lib/adventure/being.rb', line 463 def damage(amount) amount = amount.to_i.abs @current_hp -= amount @current_hp = [@current_hp, 0].max @current_hp end |
#dead? ⇒ Boolean
Whether this Being is dead or not.
Uses the current HP as parameter to define dead status.
492 493 494 |
# File 'lib/adventure/being.rb', line 492 def dead? @current_hp.zero? end |
#heal(amount) ⇒ Integer
Heal this Being by the given amount, modifying the current HP accordingly.
If the new current HP is greater than the maximun HP, the former is normalized to the maximun HP, instead.
479 480 481 482 483 484 |
# File 'lib/adventure/being.rb', line 479 def heal(amount) amount = amount.to_i.abs @current_hp += amount @current_hp = [@current_hp, @hp].min @current_hp end |
#modifier(value) ⇒ Integer (private)
Get the modifier for the given attribute's value.
Modifier = (Score - 10) / 2, rounded down.
580 581 582 |
# File 'lib/adventure/being.rb', line 580 def modifier(value) ((value.to_f - 10.0) / 2.0).floor end |
#proficiency_bonus(levels) ⇒ Integer (private)
Calculate proficiency bonus according to Someone_Evil's formula.
512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/adventure/being.rb', line 512 def proficiency_bonus(levels) total_level = if levels.is_a? Numeric levels.to_i elsif levels.is_a? Hash levels.values.sum else 0 end if total_level.positive? (1.0 + (total_level.to_f / 4.0)).ceil else 2 end end |
#roll_for_abilities(**opts) ⇒ Object (private)
Set ability scores randomly
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
# File 'lib/adventure/being.rb', line 533 def roll_for_abilities(**opts) # Get minimum value, or set it to `1`. min = opts.key?(:min) ? opts[:min].to_i - 10 : -9 # Get maximum value, or set it to `20`. max = opts.key?(:max) ? opts[:max].to_i - 10 : 10 # Set min and max as range range = Range.new min, max # Get preferences and parse their uniquiness, or shuffle de default list above. prefs = if opts.key? :prefs opts[:prefs].to_a.uniq else ABILITIES.shuffle end # Filter invalid abilities prefs.select! { |x| ABILITIES.include? x } # Add randomly any missing abilities, if applicable missing_abilities = ABILITIES - prefs prefs += missing_abilities.shuffle if missing_abilities.length.positive? # Roll scores scores = Array.new(6) scores.map! do 10 + rand(range) end # Order from biggest to lowest scores.sort!.reverse! # Assign scores to abilities prefs.each_with_index do |a, i| case a when :str then @str = scores[i] when :dex then @dex = scores[i] when :con then @con = scores[i] when :int then @int = scores[i] when :wis then @wis = scores[i] when :cha then @cha = scores[i] end end end |
#roll_for_save(ability) ⇒ Integer
Roll for a Saving Throw for the given ability.
348 349 350 351 352 353 |
# File 'lib/adventure/being.rb', line 348 def roll_for_save(ability) mod = save(ability) roll = rand(1..20) roll + mod end |
#roll_for_skill(skill) ⇒ Integer
Roll for the given Skill.
The possible skills are:
:acrobatics;:animal_handling;:arcana;:athletics;:deception;:history;:insight;:intimidation;:investigation;:medicine;:nature;:perception;:performance;:persuasion;:religion;:sleight_hand;:stealth; and:survival.
This method also accepts a String of the full name of the skill, as presented in the official character sheet.
448 449 450 451 452 453 |
# File 'lib/adventure/being.rb', line 448 def roll_for_skill(skill) mod = skill(skill) roll = rand(1..20) roll + mod end |
#save(ability) ⇒ Integer
Get the Saving Throw modifier for the given ability.
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/adventure/being.rb', line 321 def save(ability) # Raise error if ability is not valid. raise StandardError, 'Invalid ability.' unless ABILITIES.include?(ability.to_sym) # Parse ability to valid string ability = ability[0..2].downcase.to_swm # Check for Proficiency in the Saving Throw mod = @saves.include?(ability) ? @proficiency : 0 case ability when :str then modifier(@str) + mod when :dex then modifier(@dex) + mod when :con then modifier(@con) + mod when :int then modifier(@int) + mod when :wis then modifier(@wis) + mod when :cha then modifier(@cha) + mod else 0 end end |
#skill(skill) ⇒ Integer
Get the Skill modifier for the given skill.
The possible skills are:
:acrobatics;:animal_handling;:arcana;:athletics;:deception;:history;:insight;:intimidation;:investigation;:medicine;:nature;:perception;:performance;:persuasion;:religion;:sleight_hand;:stealth; and:survival.
This method also accepts a String of the full name of the skill, as presented in the official character sheet.
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/adventure/being.rb', line 386 def skill(skill) # Raise error if skill is not valid. raise StandardError, 'Invalid skill.' unless SKILLS.include?(skill.to_sym) # Parse skill to valid string skill.gsub!(' of', '').gsub!(/ /, '_').downcase! unless skill.is_a? Symbol # Check for Proficiency or Expertise in the skill mod = if @skills.include? skill.to_sym @proficiency elsif @skills_expertise.include? skill.to_sym @proficiency * 2 else 0 end case skill.to_sym when :athletics modifier(@str) + mod when :acrobatics, :sleight_hand, :stealth modifier(@dex) + mod when :arcana, :history, :investigation, :nature, :religion modifier(@int) + mod when :animal_handling, :insight, :medicine, :perception, :survival modifier(@wis) + mod when :deception, :intimidation, :performance, :persuasion modifier(@cha) + mod else 0 end end |
#to_a ⇒ Array
Get an Array of the being's abilities in the classical order: Strength, Dexterity, Constitution, Intelligence, Wisdom, and Charisma.
296 297 298 |
# File 'lib/adventure/being.rb', line 296 def to_a [@str, @dex, @con, @int, @wis, @cha] end |
#to_h ⇒ Hash
Get a Hash of the being's abilities, indexed by each ability abbreviation.
304 305 306 307 308 309 310 311 312 313 |
# File 'lib/adventure/being.rb', line 304 def to_h { str: @str, dex: @dex, con: @con, int: @int, wis: @wis, cha: @cha } end |
#to_i ⇒ Integer
Get either the being's Challenge Rating or the sum of its levels.
283 284 285 286 287 288 289 |
# File 'lib/adventure/being.rb', line 283 def to_i if @levels.nil? @cr else @levels.values.sum end end |
#to_s ⇒ String
Get the being's name.
275 276 277 |
# File 'lib/adventure/being.rb', line 275 def to_s @name end |