Class: Radventure::Action
- Inherits:
-
Object
- Object
- Radventure::Action
- Defined in:
- lib/radventure/action.rb
Overview
Represents an ingame possible action
Instance Attribute Summary collapse
-
#dc ⇒ Integer
readonly
The the skill’s Difficulty Class of the action.
-
#failure ⇒ String
readonly
The failure text of the action.
-
#name ⇒ String
readonly
The general name of the action.
-
#skill ⇒ String
readonly
The name of the skill to test of the action.
-
#status ⇒ Boolean?
readonly
The current status of the action of the action.
-
#success ⇒ String
readonly
The success text of the action.
Instance Method Summary collapse
-
#get_reward(index) ⇒ nil, ...
Retrieve a reward (and remove it) from the available rewards list.
-
#initialize(name, skill, dc, success, failure, success_cache = [], failure_cache = []) ⇒ Action
constructor
Action constructor.
-
#rewards ⇒ false, Array
Fetch rewards, if applicable.
-
#try(roll) ⇒ Boolean
Try to roll for this action.
Constructor Details
#initialize(name, skill, dc, success, failure, success_cache = [], failure_cache = []) ⇒ Action
Action constructor
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/radventure/action.rb', line 31 def initialize(name, skill, dc, success, failure, success_cache = [], failure_cache = []) @name = name.strip @skill = skill.strip @dc = dc.to_i @success = success.strip @failure = failure.strip @status = nil @success_cache = success_cache @failure_cache = failure_cache @cache = nil end |
Instance Attribute Details
#dc ⇒ Integer (readonly)
Returns The the skill’s Difficulty Class of the action.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/radventure/action.rb', line 18 class Action attr_reader :name, :skill, :success, :failure, :status # Action constructor # # @param name [String] The general name of the action # @param skill [String] The name of the skill to test of the action # @param dc [Integer] The skill's Difficulty Class of the action # @param success [String] The success text of the action # @param failure [String] The failure text of the action # @param success_cache [Array<Item, Money>] A list of items and money caches available when succeeded # @param failure_cache [Array<Item, Money>] A list of items and money caches available when failed # @return [Action] The Action object def initialize(name, skill, dc, success, failure, success_cache = [], failure_cache = []) @name = name.strip @skill = skill.strip @dc = dc.to_i @success = success.strip @failure = failure.strip @status = nil @success_cache = success_cache @failure_cache = failure_cache @cache = nil end # Try to roll for this action # # @param roll [Integer] The result of the roll # @return [Boolean] Whether the check succeeded or not def try(roll) if @status.nil? @status = roll.to_i >= @success @cache = if @status @success_cache else @failure_cache end end @status end # Fetch rewards, if applicable # # @return [false, Array] Returns `false` if the action was not tried, or an array, otherwise def rewards if @status.nil? false else @cache end end # Retrieve a reward (and remove it) from the available rewards list # # @return [nil, Item, Money] Returns the removed reward from the rewards list, or `nil` if no rewards match def get_reward(index) if @cache.nil? nil else @cache.delete_at index end end end |
#failure ⇒ String (readonly)
Returns The failure text of the action.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/radventure/action.rb', line 18 class Action attr_reader :name, :skill, :success, :failure, :status # Action constructor # # @param name [String] The general name of the action # @param skill [String] The name of the skill to test of the action # @param dc [Integer] The skill's Difficulty Class of the action # @param success [String] The success text of the action # @param failure [String] The failure text of the action # @param success_cache [Array<Item, Money>] A list of items and money caches available when succeeded # @param failure_cache [Array<Item, Money>] A list of items and money caches available when failed # @return [Action] The Action object def initialize(name, skill, dc, success, failure, success_cache = [], failure_cache = []) @name = name.strip @skill = skill.strip @dc = dc.to_i @success = success.strip @failure = failure.strip @status = nil @success_cache = success_cache @failure_cache = failure_cache @cache = nil end # Try to roll for this action # # @param roll [Integer] The result of the roll # @return [Boolean] Whether the check succeeded or not def try(roll) if @status.nil? @status = roll.to_i >= @success @cache = if @status @success_cache else @failure_cache end end @status end # Fetch rewards, if applicable # # @return [false, Array] Returns `false` if the action was not tried, or an array, otherwise def rewards if @status.nil? false else @cache end end # Retrieve a reward (and remove it) from the available rewards list # # @return [nil, Item, Money] Returns the removed reward from the rewards list, or `nil` if no rewards match def get_reward(index) if @cache.nil? nil else @cache.delete_at index end end end |
#name ⇒ String (readonly)
Returns The general name of the action.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/radventure/action.rb', line 18 class Action attr_reader :name, :skill, :success, :failure, :status # Action constructor # # @param name [String] The general name of the action # @param skill [String] The name of the skill to test of the action # @param dc [Integer] The skill's Difficulty Class of the action # @param success [String] The success text of the action # @param failure [String] The failure text of the action # @param success_cache [Array<Item, Money>] A list of items and money caches available when succeeded # @param failure_cache [Array<Item, Money>] A list of items and money caches available when failed # @return [Action] The Action object def initialize(name, skill, dc, success, failure, success_cache = [], failure_cache = []) @name = name.strip @skill = skill.strip @dc = dc.to_i @success = success.strip @failure = failure.strip @status = nil @success_cache = success_cache @failure_cache = failure_cache @cache = nil end # Try to roll for this action # # @param roll [Integer] The result of the roll # @return [Boolean] Whether the check succeeded or not def try(roll) if @status.nil? @status = roll.to_i >= @success @cache = if @status @success_cache else @failure_cache end end @status end # Fetch rewards, if applicable # # @return [false, Array] Returns `false` if the action was not tried, or an array, otherwise def rewards if @status.nil? false else @cache end end # Retrieve a reward (and remove it) from the available rewards list # # @return [nil, Item, Money] Returns the removed reward from the rewards list, or `nil` if no rewards match def get_reward(index) if @cache.nil? nil else @cache.delete_at index end end end |
#skill ⇒ String (readonly)
Returns The name of the skill to test of the action.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/radventure/action.rb', line 18 class Action attr_reader :name, :skill, :success, :failure, :status # Action constructor # # @param name [String] The general name of the action # @param skill [String] The name of the skill to test of the action # @param dc [Integer] The skill's Difficulty Class of the action # @param success [String] The success text of the action # @param failure [String] The failure text of the action # @param success_cache [Array<Item, Money>] A list of items and money caches available when succeeded # @param failure_cache [Array<Item, Money>] A list of items and money caches available when failed # @return [Action] The Action object def initialize(name, skill, dc, success, failure, success_cache = [], failure_cache = []) @name = name.strip @skill = skill.strip @dc = dc.to_i @success = success.strip @failure = failure.strip @status = nil @success_cache = success_cache @failure_cache = failure_cache @cache = nil end # Try to roll for this action # # @param roll [Integer] The result of the roll # @return [Boolean] Whether the check succeeded or not def try(roll) if @status.nil? @status = roll.to_i >= @success @cache = if @status @success_cache else @failure_cache end end @status end # Fetch rewards, if applicable # # @return [false, Array] Returns `false` if the action was not tried, or an array, otherwise def rewards if @status.nil? false else @cache end end # Retrieve a reward (and remove it) from the available rewards list # # @return [nil, Item, Money] Returns the removed reward from the rewards list, or `nil` if no rewards match def get_reward(index) if @cache.nil? nil else @cache.delete_at index end end end |
#status ⇒ Boolean? (readonly)
Returns The current status of the action of the action.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/radventure/action.rb', line 18 class Action attr_reader :name, :skill, :success, :failure, :status # Action constructor # # @param name [String] The general name of the action # @param skill [String] The name of the skill to test of the action # @param dc [Integer] The skill's Difficulty Class of the action # @param success [String] The success text of the action # @param failure [String] The failure text of the action # @param success_cache [Array<Item, Money>] A list of items and money caches available when succeeded # @param failure_cache [Array<Item, Money>] A list of items and money caches available when failed # @return [Action] The Action object def initialize(name, skill, dc, success, failure, success_cache = [], failure_cache = []) @name = name.strip @skill = skill.strip @dc = dc.to_i @success = success.strip @failure = failure.strip @status = nil @success_cache = success_cache @failure_cache = failure_cache @cache = nil end # Try to roll for this action # # @param roll [Integer] The result of the roll # @return [Boolean] Whether the check succeeded or not def try(roll) if @status.nil? @status = roll.to_i >= @success @cache = if @status @success_cache else @failure_cache end end @status end # Fetch rewards, if applicable # # @return [false, Array] Returns `false` if the action was not tried, or an array, otherwise def rewards if @status.nil? false else @cache end end # Retrieve a reward (and remove it) from the available rewards list # # @return [nil, Item, Money] Returns the removed reward from the rewards list, or `nil` if no rewards match def get_reward(index) if @cache.nil? nil else @cache.delete_at index end end end |
#success ⇒ String (readonly)
Returns The success text of the action.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/radventure/action.rb', line 18 class Action attr_reader :name, :skill, :success, :failure, :status # Action constructor # # @param name [String] The general name of the action # @param skill [String] The name of the skill to test of the action # @param dc [Integer] The skill's Difficulty Class of the action # @param success [String] The success text of the action # @param failure [String] The failure text of the action # @param success_cache [Array<Item, Money>] A list of items and money caches available when succeeded # @param failure_cache [Array<Item, Money>] A list of items and money caches available when failed # @return [Action] The Action object def initialize(name, skill, dc, success, failure, success_cache = [], failure_cache = []) @name = name.strip @skill = skill.strip @dc = dc.to_i @success = success.strip @failure = failure.strip @status = nil @success_cache = success_cache @failure_cache = failure_cache @cache = nil end # Try to roll for this action # # @param roll [Integer] The result of the roll # @return [Boolean] Whether the check succeeded or not def try(roll) if @status.nil? @status = roll.to_i >= @success @cache = if @status @success_cache else @failure_cache end end @status end # Fetch rewards, if applicable # # @return [false, Array] Returns `false` if the action was not tried, or an array, otherwise def rewards if @status.nil? false else @cache end end # Retrieve a reward (and remove it) from the available rewards list # # @return [nil, Item, Money] Returns the removed reward from the rewards list, or `nil` if no rewards match def get_reward(index) if @cache.nil? nil else @cache.delete_at index end end end |
Instance Method Details
#get_reward(index) ⇒ nil, ...
Retrieve a reward (and remove it) from the available rewards list
74 75 76 77 78 79 80 |
# File 'lib/radventure/action.rb', line 74 def get_reward(index) if @cache.nil? nil else @cache.delete_at index end end |
#rewards ⇒ false, Array
Fetch rewards, if applicable
63 64 65 66 67 68 69 |
# File 'lib/radventure/action.rb', line 63 def rewards if @status.nil? false else @cache end end |
#try(roll) ⇒ Boolean
Try to roll for this action
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/radventure/action.rb', line 47 def try(roll) if @status.nil? @status = roll.to_i >= @success @cache = if @status @success_cache else @failure_cache end end @status end |