Class: Lich::Gemstone::Bounty::Task

Inherits:
Object
  • Object
show all
Defined in:
documented/gemstone/bounty/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Task

Initializes a new task with the given options.

Parameters:

  • options (Hash) (defaults to: {})

    A hash of options for the task.

Options Hash (options):

  • :description (String)

    The description of the task.

  • :type (Symbol)

    The type of the task.

  • :requirements (Hash)

    The requirements for the task.

  • :town (String)

    The town associated with the task.



16
17
18
19
20
21
# File 'documented/gemstone/bounty/task.rb', line 16

def initialize(options = {})
  @description    = options[:description]
  @type           = options[:type]
  @requirements   = options[:requirements] || {}
  @town           = options[:town] || @requirements[:town]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &blk) ⇒ Object

Handles calls to methods that are not defined.

Examples:

task.some_dynamic_method # => value or raises NoMethodError

Parameters:

  • symbol (Symbol)

    The method name that was called.

  • args (Array)

    The arguments passed to the method.

  • blk (Proc)

    An optional block.

Returns:

  • (Object)

    The value of the requirement if it exists, otherwise calls super.



286
287
288
289
290
291
292
# File 'documented/gemstone/bounty/task.rb', line 286

def method_missing(symbol, *args, &blk)
  if requirements&.keys&.include?(symbol)
    requirements[symbol]
  else
    super
  end
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



22
23
24
# File 'documented/gemstone/bounty/task.rb', line 22

def description
  @description
end

#requirementsObject

Returns the value of attribute requirements.



22
23
24
# File 'documented/gemstone/bounty/task.rb', line 22

def requirements
  @requirements
end

#townObject

Returns the value of attribute town.



22
23
24
# File 'documented/gemstone/bounty/task.rb', line 22

def town
  @town
end

#typeObject

Returns the value of attribute type.



22
23
24
# File 'documented/gemstone/bounty/task.rb', line 22

def type
  @type
end

Instance Method Details

#any?Boolean

Checks if there are any tasks.

Examples:

task.any? # => true

Returns:

  • (Boolean)

    True if there are tasks, false otherwise.



213
214
215
# File 'documented/gemstone/bounty/task.rb', line 213

def any?
  !none?
end

#assigned?Boolean

Checks if the task is assigned.

Examples:

task.assigned? # => false

Returns:

  • (Boolean)

    True if the task type ends with “assignment”, false otherwise.



240
241
242
# File 'documented/gemstone/bounty/task.rb', line 240

def assigned?
  type.to_s.end_with?("assignment")
end

#assist?Boolean

Checks if the task requires assistance (alias for help?).

Examples:

task.assist? # => true

Returns:

  • (Boolean)

    True if help is needed, false otherwise.



267
268
269
# File 'documented/gemstone/bounty/task.rb', line 267

def assist?
  help?
end

#bandit?Boolean

Checks if the task type is a bandit task.

Examples:

task.bandit? # => true

Returns:

  • (Boolean)

    True if the task type starts with “bandit”, false otherwise.



77
78
79
# File 'documented/gemstone/bounty/task.rb', line 77

def bandit?
  type.to_s.start_with?("bandit")
end

#countInteger

Returns the number associated with the task.

Examples:

task.count # => 5

Returns:

  • (Integer)

    The number associated with the task.



39
# File 'documented/gemstone/bounty/task.rb', line 39

def count; number; end

#creatureSymbol?

Returns the creature requirement for the task.

Examples:

task.creature # => :goblin

Returns:

  • (Symbol, nil)

    The creature required for the task, or nil if not specified.



45
46
47
# File 'documented/gemstone/bounty/task.rb', line 45

def creature
  requirements[:creature]
end

#creature?Boolean

Checks if the task type is one of the creature types.

Examples:

task.creature? # => true

Returns:

  • (Boolean)

    True if the task type is a creature type, false otherwise.



85
86
87
88
89
# File 'documented/gemstone/bounty/task.rb', line 85

def creature?
  [
    :creature_assignment, :cull, :dangerous, :dangerous_spawned, :rescue, :heirloom
  ].include?(type)
end

#critterSymbol?

Returns the creature requirement for the task (alias for creature).

Examples:

task.critter # => :goblin

Returns:

  • (Symbol, nil)

    The creature required for the task, or nil if not specified.



53
54
55
# File 'documented/gemstone/bounty/task.rb', line 53

def critter
  requirements[:creature]
end

#critter?Boolean

Checks if the task has a creature requirement.

Examples:

task.critter? # => true

Returns:

  • (Boolean)

    True if a creature is required, false otherwise.



61
62
63
# File 'documented/gemstone/bounty/task.rb', line 61

def critter?
  !!requirements[:creature]
end

#cull?Boolean

Checks if the task type is a cull task.

Examples:

task.cull? # => false

Returns:

  • (Boolean)

    True if the task type starts with “cull”, false otherwise.



95
96
97
# File 'documented/gemstone/bounty/task.rb', line 95

def cull?
  type.to_s.start_with?("cull")
end

#dangerous?Boolean

Checks if the task type is a dangerous task.

Examples:

task.dangerous? # => false

Returns:

  • (Boolean)

    True if the task type starts with “dangerous”, false otherwise.



103
104
105
# File 'documented/gemstone/bounty/task.rb', line 103

def dangerous?
  type.to_s.start_with?("dangerous")
end

#done?Boolean

Checks if the task is done.

Examples:

task.done? # => false

Returns:

  • (Boolean)

    True if the task type is one of the done types, false otherwise.



187
188
189
190
191
# File 'documented/gemstone/bounty/task.rb', line 187

def done?
  [
    :failed, :guard, :taskmaster, :heirloom_found
  ].include?(type)
end

#escort?Boolean

Checks if the task type is an escort task.

Examples:

task.escort? # => false

Returns:

  • (Boolean)

    True if the task type starts with “escort”, false otherwise.



111
112
113
# File 'documented/gemstone/bounty/task.rb', line 111

def escort?
  type.to_s.start_with?("escort")
end

#gem?Boolean

Checks if the task type is a gem task.

Examples:

task.gem? # => false

Returns:

  • (Boolean)

    True if the task type starts with “gem”, false otherwise.



119
120
121
# File 'documented/gemstone/bounty/task.rb', line 119

def gem?
  type.to_s.start_with?("gem")
end

#group?Boolean

Checks if the task is a group task (alias for help?).

Examples:

task.group? # => true

Returns:

  • (Boolean)

    True if help is needed, false otherwise.



275
276
277
# File 'documented/gemstone/bounty/task.rb', line 275

def group?
  help?
end

#guard?Boolean

Checks if the task type is a guard task.

Examples:

task.guard? # => false

Returns:

  • (Boolean)

    True if the task type is one of the guard types, false otherwise.



229
230
231
232
233
234
# File 'documented/gemstone/bounty/task.rb', line 229

def guard?
  [
    :guard,
    :bandit_assignment, :creature_assignment, :heirloom_assignment, :heirloom_found, :rescue_assignment
  ].include?(type)
end

#heirloom?Boolean

Checks if the task type is a heirloom task.

Examples:

task.heirloom? # => false

Returns:

  • (Boolean)

    True if the task type starts with “heirloom”, false otherwise.



127
128
129
# File 'documented/gemstone/bounty/task.rb', line 127

def heirloom?
  type.to_s.start_with?("heirloom")
end

#heirloom_found?Boolean

Checks if the task type is a found heirloom task.

Examples:

task.heirloom_found? # => false

Returns:

  • (Boolean)

    True if the task type is heirloom_found, false otherwise.



177
178
179
180
181
# File 'documented/gemstone/bounty/task.rb', line 177

def heirloom_found?
  [
    :heirloom_found
  ].include?(type)
end

#help?Boolean

Checks if the task description indicates help is needed.

Examples:

task.help? # => true

Returns:

  • (Boolean)

    True if the description starts with “You have been tasked to help”, false otherwise.



259
260
261
# File 'documented/gemstone/bounty/task.rb', line 259

def help?
  description.start_with?("You have been tasked to help")
end

#herb?Boolean

Checks if the task type is a herb task.

Examples:

task.herb? # => false

Returns:

  • (Boolean)

    True if the task type starts with “herb”, false otherwise.



135
136
137
# File 'documented/gemstone/bounty/task.rb', line 135

def herb?
  type.to_s.start_with?("herb")
end

#kindSymbol

Returns the type of the task (alias for task).

Examples:

task.kind # => :bandit

Returns:

  • (Symbol)

    The type of the task.



34
# File 'documented/gemstone/bounty/task.rb', line 34

def kind; type; end

#locationString

Returns the location requirement for the task.

Examples:

task.location # => "Forest"

Returns:

  • (String)

    The area required for the task, or the town if not specified.



69
70
71
# File 'documented/gemstone/bounty/task.rb', line 69

def location
  requirements[:area] || town
end

#loot_heirloom?Boolean

Checks if the task is a loot heirloom task.

Examples:

task.loot_heirloom? # => false

Returns:

  • (Boolean)

    True if the task type is heirloom and action is “loot”, false otherwise.



168
169
170
171
# File 'documented/gemstone/bounty/task.rb', line 168

def loot_heirloom?
  [:heirloom].include?(type) &&
    requirements[:action] == "loot"
end

#none?Boolean

Checks if there are no tasks.

Examples:

task.none? # => false

Returns:

  • (Boolean)

    True if there are no tasks, false otherwise.



221
222
223
# File 'documented/gemstone/bounty/task.rb', line 221

def none?
  [:none, nil].include?(type)
end

#ready?Boolean

Checks if the task is ready to be executed.

Examples:

task.ready? # => true

Returns:

  • (Boolean)

    True if the task type is one of the ready types, false otherwise.



248
249
250
251
252
253
# File 'documented/gemstone/bounty/task.rb', line 248

def ready?
  [
    :bandit_assignment, :escort_assignment,
    :bandit, :cull, :dangerous, :escort, :gem, :heirloom, :herb, :rescue, :skin
  ].include?(type)
end

#rescue?Boolean

Checks if the task type is a rescue task.

Examples:

task.rescue? # => false

Returns:

  • (Boolean)

    True if the task type starts with “rescue”, false otherwise.



143
144
145
# File 'documented/gemstone/bounty/task.rb', line 143

def rescue?
  type.to_s.start_with?("rescue")
end

#respond_to_missing?(symbol, include_private = false) ⇒ Boolean

Checks if the object responds to a missing method.

Examples:

task.respond_to_missing?(:some_dynamic_method) # => true or false

Parameters:

  • symbol (Symbol)

    The method name that was checked.

  • include_private (Boolean) (defaults to: false)

    Whether to include private methods.

Returns:

  • (Boolean)

    True if the method exists in requirements, false otherwise.



300
301
302
# File 'documented/gemstone/bounty/task.rb', line 300

def respond_to_missing?(symbol, include_private = false)
  requirements&.keys&.include?(symbol) || super
end

#search_heirloom?Boolean

Checks if the task is a search heirloom task.

Examples:

task.search_heirloom? # => false

Returns:

  • (Boolean)

    True if the task type is heirloom and action is “search”, false otherwise.



159
160
161
162
# File 'documented/gemstone/bounty/task.rb', line 159

def search_heirloom?
  [:heirloom].include?(type) &&
    requirements[:action] == "search"
end

#skin?Boolean

Checks if the task type is a skin task.

Examples:

task.skin? # => false

Returns:

  • (Boolean)

    True if the task type starts with “skin”, false otherwise.



151
152
153
# File 'documented/gemstone/bounty/task.rb', line 151

def skin?
  type.to_s.start_with?("skin")
end

#spawned?Boolean

Checks if the task has spawned.

Examples:

task.spawned? # => false

Returns:

  • (Boolean)

    True if the task type is one of the spawned types, false otherwise.



197
198
199
200
201
# File 'documented/gemstone/bounty/task.rb', line 197

def spawned?
  [
    :dangerous_spawned, :escort, :rescue_spawned
  ].include?(type)
end

#taskSymbol

Returns the type of the task.

Examples:

task = Lich::Gemstone::Bounty::Task.new(type: :bandit)
task.task # => :bandit

Returns:

  • (Symbol)

    The type of the task.



29
# File 'documented/gemstone/bounty/task.rb', line 29

def task; type; end

#triggered?Boolean

Checks if the task has been triggered (spawned).

Examples:

task.triggered? # => false

Returns:

  • (Boolean)

    True if the task has spawned, false otherwise.



207
# File 'documented/gemstone/bounty/task.rb', line 207

def triggered?; spawned?; end