Class: Adventure::Being

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(name, **opts) ⇒ Being

Create a new instance of Being.

Parameters:

  • name (String)

    The being's name.

  • opts (Hash)

    A list of parameters.

Options Hash (**opts):

  • :name (String)

    Being's name.

  • :source (String)

    Being's source text, when applicable.

  • :align (String)

    Being's alignment.

  • :cr (Float)

    Being's Challenge Rating.

  • :levels (Hash)

    Being's Hash of levels by, when applicable, class, or Integer of total level.

  • :size (String)

    Being's size.

  • :type (String)

    Being's type.

  • :swarm (Boolean)

    Whether or not this is a swarm of beings.

  • :speed (Hash)

    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.

  • :senses (Array<String>)

    Being's Array of senses, empty by default.

  • :languages (Array<String>)

    Being's Array of known languages.

  • :rand_abilities (Boolean)

    Whether or not to roll random ability stats -- if set, the initializer ignores any plainly given ability stat.

  • :ability_preferences (Array<Symbol>)

    An array of prioritary abilities, from most importante (index = 0) to least (last index).

  • :ability_min (Integer)

    The minimum value an ability can be, used only when randomly generating ability scores.

  • :ability_max (Integer)

    The maximum value an ability can be, used only when randomly generating ability scores.

  • :str (Integer)

    Being's Strength score, defaults to 10, it unset.

  • :dex (Integer)

    Being's Dexterity score, defaults to 10, it unset.

  • :con (Integer)

    Being's Constitution score, defaults to 10, it unset.

  • :int (Integer)

    Being's Intelligence score, defaults to 10, it unset.

  • :wis (Integer)

    Being's Wisdom score, defaults to 10, it unset.

  • :cha (Integer)

    Being's Charisma score, defaults to 10, it unset.

  • :saves (Array<Symbol>)

    Being's Saving Throw proficiencies, as an Array of Symbol's for each proficient save.

  • :skills (Array<Symbol>)

    Being's Skill proficiencies, as an Array of Symbol's for each proficient skill.

  • :skills_expertise (Array<Symbol>)

    Being's Skill expertises, as an Array of Symbol's for each proficient skill.

  • :ac (Integer)

    Being's Armor Class.

  • :ac_desc (String)

    Being's AC description, if any.

  • :hp (Integer)

    Being's total/maximum Hit Points.

  • :hp_formula (String)

    Being's HP dice formula.

  • :dmg_vulnerabilities (Array<String>)

    Being's Array of Damage Vulnerabilities, if any -- empty by default.

  • :dmg_resistances (Array<String>)

    Being's Array of Damage Resistances, if any -- empty by default.

  • :dmg_immunities (Array<String>)

    Being's Array of Damage Immunities, if any -- empty by default.

  • :condition_immunities (Array<String>)

    Being's Array of Condition Immunities, if any -- empty by default.

  • :spell_header (String)

    Being's Spellcasting block header -- nil if not applicable.

  • :spell_footer (String)

    Being's Spellcasting block footer -- nil if not applicable.

  • :spell_list (Array<Hash>)

    Being's Spellcasting array of spells -- empty by default.

  • :traits (Array<Hash>)

    Being's array of traits.

  • :actions_header (String)

    Being's Actions' header.

  • :actions_list (Array)

    Being's Array of Actions.

  • :bonus_actions_header (String)

    Being's Bonus Actions' header.

  • :bonus_actions_list (Array)

    Being's Array of Bonus Actions.

  • :reactions_header (String)

    Being's Reactions' header.

  • :reactions_list (Array)

    Being's Array of Reactions.

  • :legendary_actions_header (String)

    Being's Legendary Actions' header.

  • :legendary_actions_count (Integer)

    Being's number of Legendary Actions, as Integer.

  • :legendary_actions_list (Array)

    Being's Array of Legendary Actions.

  • :mythic_actions_header (String)

    Being's Mythic Actions' header.

  • :mythic_actions_list (Array)

    Being's Array of Mythic Actions.

  • :inventory (Array)

    Being's Inventory.

  • :purse (Purse)

    Being's Purse.

  • :description (String)

    Being's flavor description/informations.

  • :environment (Array)

    Being's Array of environments.



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

#acObject (readonly)

Being's Armor Class.



61
62
63
# File 'lib/adventure/being.rb', line 61

def ac
  @ac
end

#ac_descObject (readonly)

Being's AC description, if any.



63
64
65
# File 'lib/adventure/being.rb', line 63

def ac_desc
  @ac_desc
end

#actions_headerObject (readonly)

Being's Actions' header.



87
88
89
# File 'lib/adventure/being.rb', line 87

def actions_header
  @actions_header
end

#actions_listObject (readonly)

Being's Array of Actions.



89
90
91
# File 'lib/adventure/being.rb', line 89

def actions_list
  @actions_list
end

#alignObject (readonly)

Being's alignment.



25
26
27
# File 'lib/adventure/being.rb', line 25

def align
  @align
end

#bonus_actions_headerObject (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_listObject (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

#chaObject (readonly)

Being's Charisma score.



57
58
59
# File 'lib/adventure/being.rb', line 57

def cha
  @cha
end

#conObject (readonly)

Being's Constitution score.



51
52
53
# File 'lib/adventure/being.rb', line 51

def con
  @con
end

#condition_immunitiesObject (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

#crObject (readonly)

Being's Challenge Rating.



27
28
29
# File 'lib/adventure/being.rb', line 27

def cr
  @cr
end

#current_hpObject (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

#descriptionObject (readonly)

Being's flavor description/informations.



113
114
115
# File 'lib/adventure/being.rb', line 113

def description
  @description
end

#dexObject (readonly)

Being's Dexterity score.



49
50
51
# File 'lib/adventure/being.rb', line 49

def dex
  @dex
end

#dmg_immunitiesObject (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_resistancesObject (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_vulnerabilitiesObject (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

#environmentObject (readonly)

Being's Array of environments.



115
116
117
# File 'lib/adventure/being.rb', line 115

def environment
  @environment
end

#hpObject (readonly)

Being's total/maximum Hit Points.



65
66
67
# File 'lib/adventure/being.rb', line 65

def hp
  @hp
end

#hp_formulaObject (readonly)

Being's HP dice formula.



69
70
71
# File 'lib/adventure/being.rb', line 69

def hp_formula
  @hp_formula
end

#intObject (readonly)

Being's Intelligence score.



53
54
55
# File 'lib/adventure/being.rb', line 53

def int
  @int
end

#inventoryObject (readonly)

Being's list of Items.



109
110
111
# File 'lib/adventure/being.rb', line 109

def inventory
  @inventory
end

#languagesObject (readonly)

Being's Array of known languages.



45
46
47
# File 'lib/adventure/being.rb', line 45

def languages
  @languages
end

#legendary_actions_countObject (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_headerObject (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_listObject (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

#levelsObject (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_headerObject (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_listObject (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

#nameObject (readonly)

Being's name.



21
22
23
# File 'lib/adventure/being.rb', line 21

def name
  @name
end

#passive_perceptionObject (readonly)

Being's Passive Perception score.



59
60
61
# File 'lib/adventure/being.rb', line 59

def passive_perception
  @passive_perception
end

#proficiencyObject (readonly)

Being's Proficiency bonus.



29
30
31
# File 'lib/adventure/being.rb', line 29

def proficiency
  @proficiency
end

#purseObject (readonly)

Being's Purse.



111
112
113
# File 'lib/adventure/being.rb', line 111

def purse
  @purse
end

#reactions_headerObject (readonly)

Being's Reactions' header.



95
96
97
# File 'lib/adventure/being.rb', line 95

def reactions_header
  @reactions_header
end

#reactions_listObject (readonly)

Being's Array of Reactions.



97
98
99
# File 'lib/adventure/being.rb', line 97

def reactions_list
  @reactions_list
end

#sensesObject (readonly)

Being's Array of senses, empty by default.



43
44
45
# File 'lib/adventure/being.rb', line 43

def senses
  @senses
end

#sizeObject (readonly)

Being's size.



33
34
35
# File 'lib/adventure/being.rb', line 33

def size
  @size
end

#sourceObject (readonly)

Being's source text, when applicable.



23
24
25
# File 'lib/adventure/being.rb', line 23

def source
  @source
end

#speedObject (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

Being's Spellcasting block footer -- nil if not applicable.



81
82
83
# File 'lib/adventure/being.rb', line 81

def spell_footer
  @spell_footer
end

#spell_headerObject (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_listObject (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

#strObject (readonly)

Being's Strength score.



47
48
49
# File 'lib/adventure/being.rb', line 47

def str
  @str
end

#subtypeObject (readonly)

Being's subtype, if any.



37
38
39
# File 'lib/adventure/being.rb', line 37

def subtype
  @subtype
end

#swarmObject (readonly)

Whether or not this is a swarm of beings.



39
40
41
# File 'lib/adventure/being.rb', line 39

def swarm
  @swarm
end

#traitsObject (readonly)

Being's Array of Traits.



85
86
87
# File 'lib/adventure/being.rb', line 85

def traits
  @traits
end

#typeObject (readonly)

Being's type.



35
36
37
# File 'lib/adventure/being.rb', line 35

def type
  @type
end

#wisObject (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.

Returns:

  • (Boolean)

    true if current HP is greater than 0, false otherwise.



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.

Parameters:

  • amount (Integer)

    The amount of damage to be dealt, negative values are accepted, but are not counted as healing --- use #heal instead.

Returns:

  • (Integer)

    The new current HP.



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.

Returns:

  • (Boolean)

    true if current HP is 0, false otherwise.



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.

Parameters:

  • amount (Integer)

    The amount to heal the Being by, negative values are accepted, but are not counted as damage --- use #damage instead.

Returns:

  • (Integer)

    The new current HP.



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.

Parameters:

  • value (Numeric)

    A value to have its modifier calculated.

Returns:

  • (Integer)

    The corresponding modifier, according to the formula above.



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.

Parameters:

  • levels (Integer, Hash)

    Either the total level or a Hash of levels.

Returns:

  • (Integer)

    An Integer representing the corresponding Proficiency Bonus.



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

Parameters:

  • opts (Hash)

    A Hash of options to be used.

Options Hash (**opts):

  • :prefs (Array<Symbol>)

    An Array of Symbol's representing the order to prioritize abilities.

  • :min (Integer)

    The minimum value an ability can have, defaults to 1.

  • :max (Integer)

    The minimum value an ability can have, defaults to 20.



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.

Parameters:

  • ability (Symbol, String)

    The ability abbreviation as either a String or a Symbol.

Returns:

  • (Integer)

    The roll's result added to the corresponding save modifier.

Raises:

  • (StandardError)

    If the given ability is not a valid ability abbreviation.

See Also:



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.

Parameters:

  • skill (Symbol, String)

    The skill as either a String or a Symbol.

Returns:

  • (Integer)

    The roll's result added to the corresponding skill modifier, either plain, proficiency, or expertise.

Raises:

  • (StandardError)

    If the given skill is not a valid one.

See Also:



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.

Parameters:

  • ability (Symbol, String)

    The ability abbreviation as either a String or a Symbol.

Returns:

  • (Integer)

    The corresponding save modifier.

Raises:

  • (StandardError)

    If the given ability is not a valid ability abbreviation.

See Also:



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.

Parameters:

  • skill (Symbol, String)

    The skill as either a String or a Symbol.

Returns:

  • (Integer)

    The corresponding skill modifier.

Raises:

  • (StandardError)

    If the given skill is not a valid one.

See Also:



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_aArray

Get an Array of the being's abilities in the classical order: Strength, Dexterity, Constitution, Intelligence, Wisdom, and Charisma.

Returns:

  • (Array)

    An Array of the being's abilities: [STR, DEX, CON, INT, WIS, CHA].



296
297
298
# File 'lib/adventure/being.rb', line 296

def to_a
  [@str, @dex, @con, @int, @wis, @cha]
end

#to_hHash

Get a Hash of the being's abilities, indexed by each ability abbreviation.

Returns:

  • (Hash)

    A Hash of the being's abilities.



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_iInteger

Get either the being's Challenge Rating or the sum of its levels.

Returns:

  • (Integer)

    Either the being's CR 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_sString

Get the being's name.

Returns:

  • (String)

    The being's name.



275
276
277
# File 'lib/adventure/being.rb', line 275

def to_s
  @name
end