Class: Adventure::Challenge
- Inherits:
-
Object
- Object
- Adventure::Challenge
- Defined in:
- lib/adventure/challenge.rb
Overview
Represents an ingame challenge and/or check.
Instance Attribute Summary collapse
-
#dc ⇒ Object
readonly
Returns the value of attribute dc.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#skill ⇒ Object
readonly
Returns the value of attribute skill.
Instance Method Summary collapse
-
#button ⇒ String
The query to show as an action / option to the player.
-
#initialize(dc, skill, **opts) ⇒ Challenge
constructor
Create a new instance of Challenge.
-
#roll(roll) ⇒ Boolean
Roll for the Challenge and save success or failure to the object.
-
#success? ⇒ Boolean?
Whether or not the Challenge was succeeded, or
nilif untried. -
#text(inline: false) ⇒ String
Either the Challenge's challenge text if unrolled, or result text if rolled.
-
#to_i ⇒ Integer
The Challenge's Difficulty Class (DC).
-
#to_s ⇒ String
Either the Challenge's challenge inline text if unrolled, or inline result text if rolled.
-
#unrolled? ⇒ Boolean
Whether or not the Challenge is unrolled.
Constructor Details
#initialize(dc, skill, **opts) ⇒ Challenge
Create a new instance of Challenge
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/adventure/challenge.rb', line 19 def initialize(dc, skill, **opts) @name = opts.key?(:name) ? opts[:name].strip : UUID.new.generate @dc = dc.to_i @skill = skill.strip @success = nil raise StandardError, 'All minimal texts must be set.' unless opts.key?(:challenge_text) && opts.key?(:challenge_inline) && opts.key?(:challenge_button) && opts.key?(:success_text) && opts.key?(:success_inline) && opts.key?(:failure_text) && opts.key?(:failure_inline) @challenge_text = opts[:challenge_text].strip @challenge_inline = opts[:challenge_inline].strip @challenge_button = opts[:challenge_button].strip @success_text = opts[:success_text].strip @success_inline = opts[:success_inline].strip @failure_text = opts[:failure_text].strip @failure_inline = opts[:failure_inline].strip end |
Instance Attribute Details
#dc ⇒ Object (readonly)
Returns the value of attribute dc.
13 14 15 |
# File 'lib/adventure/challenge.rb', line 13 def dc @dc end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/adventure/challenge.rb', line 10 def name @name end |
#skill ⇒ Object (readonly)
Returns the value of attribute skill.
16 17 18 |
# File 'lib/adventure/challenge.rb', line 16 def skill @skill end |
Instance Method Details
#button ⇒ String
The query to show as an action / option to the player.
62 63 64 |
# File 'lib/adventure/challenge.rb', line 62 def @challenge_button end |
#roll(roll) ⇒ Boolean
Roll for the Adventure::Challenge and save success or failure to the object.
91 92 93 94 |
# File 'lib/adventure/challenge.rb', line 91 def roll(roll) @success = roll >= @dc @success end |
#success? ⇒ Boolean?
Whether or not the Adventure::Challenge was succeeded, or nil if untried.
76 77 78 |
# File 'lib/adventure/challenge.rb', line 76 def success? @success end |
#text(inline: false) ⇒ String
Either the Adventure::Challenge's challenge text if unrolled, or result text if rolled.
49 50 51 52 53 54 55 56 57 |
# File 'lib/adventure/challenge.rb', line 49 def text(inline: false) if @success.nil? inline ? @challenge_inline : @challenge_text elsif @success inline ? @success_inline : @success_text else inline ? @failure_inline : @failure_text end end |
#to_i ⇒ Integer
The Adventure::Challenge's Difficulty Class (DC).
69 70 71 |
# File 'lib/adventure/challenge.rb', line 69 def to_i @dc end |
#to_s ⇒ String
Either the Adventure::Challenge's challenge inline text if unrolled, or inline result text if rolled.
An alias for #text with true as parameter.
41 42 43 |
# File 'lib/adventure/challenge.rb', line 41 def to_s text inline: true end |
#unrolled? ⇒ Boolean
Whether or not the Adventure::Challenge is unrolled.
83 84 85 |
# File 'lib/adventure/challenge.rb', line 83 def unrolled? @success.nil? end |