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

Inherits:
Object
  • Object
show all
Defined in:
lib/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: {})

    the 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



13
14
15
16
17
18
# File 'lib/gemstone/bounty/task.rb', line 13

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 missing methods by returning the corresponding requirement if it exists.

Parameters:

  • symbol (Symbol)

    the method name that was called

  • args (Array)

    additional arguments (not used)

  • blk (Proc)

    block (not used)

Returns:

  • (Object)

    the value of the requirement or raises NoMethodError if not found

Raises:

  • (NoMethodError)

    if the requirement does not exist



254
255
256
257
258
259
260
# File 'lib/gemstone/bounty/task.rb', line 254

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.



20
21
22
# File 'lib/gemstone/bounty/task.rb', line 20

def description
  @description
end

#requirementsObject

Returns the value of attribute requirements.



20
21
22
# File 'lib/gemstone/bounty/task.rb', line 20

def requirements
  @requirements
end

#townObject

Returns the value of attribute town.



20
21
22
# File 'lib/gemstone/bounty/task.rb', line 20

def town
  @town
end

#typeObject

Returns the value of attribute type.



20
21
22
# File 'lib/gemstone/bounty/task.rb', line 20

def type
  @type
end

Instance Method Details

#any?Boolean

Checks if there are any tasks.

Returns:

  • (Boolean)

    true if there are tasks, false otherwise



188
189
190
# File 'lib/gemstone/bounty/task.rb', line 188

def any?
  !none?
end

#assigned?Boolean

Checks if the task type ends with “assignment”.

Returns:

  • (Boolean)

    true if the task is assigned, false otherwise



212
213
214
# File 'lib/gemstone/bounty/task.rb', line 212

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

#assist?Boolean

Checks if the task is an assist task (alias for help?).

Returns:

  • (Boolean)

    true if the task is an assist task, false otherwise



236
237
238
# File 'lib/gemstone/bounty/task.rb', line 236

def assist?
  help?
end

#bandit?Boolean

Checks if the task type starts with “bandit”.

Returns:

  • (Boolean)

    true if the task is a bandit task, false otherwise



68
69
70
# File 'lib/gemstone/bounty/task.rb', line 68

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

#countnil

Returns the number of tasks (not implemented).

Returns:

  • (nil)

    always returns nil



35
# File 'lib/gemstone/bounty/task.rb', line 35

def count; number; end

#creatureSymbol?

Returns the creature requirement for the task.

Returns:

  • (Symbol, nil)

    the creature required for the task or nil if not specified



40
41
42
# File 'lib/gemstone/bounty/task.rb', line 40

def creature
  requirements[:creature]
end

#creature?Boolean

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

Returns:

  • (Boolean)

    true if the task is creature-related, false otherwise



75
76
77
78
79
# File 'lib/gemstone/bounty/task.rb', line 75

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

#critterSymbol?

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

Returns:

  • (Symbol, nil)

    the creature required for the task or nil if not specified



47
48
49
# File 'lib/gemstone/bounty/task.rb', line 47

def critter
  requirements[:creature]
end

#critter?Boolean

Checks if a creature is required for the task.

Returns:

  • (Boolean)

    true if a creature is required, false otherwise



54
55
56
# File 'lib/gemstone/bounty/task.rb', line 54

def critter?
  !!requirements[:creature]
end

#cull?Boolean

Checks if the task type starts with “cull”.

Returns:

  • (Boolean)

    true if the task is a cull task, false otherwise



84
85
86
# File 'lib/gemstone/bounty/task.rb', line 84

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

#dangerous?Boolean

Checks if the task type starts with “dangerous”.

Returns:

  • (Boolean)

    true if the task is dangerous, false otherwise



91
92
93
# File 'lib/gemstone/bounty/task.rb', line 91

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

#done?Boolean

Checks if the task is done based on its type.

Returns:

  • (Boolean)

    true if the task is done, false otherwise



165
166
167
168
169
# File 'lib/gemstone/bounty/task.rb', line 165

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

#escort?Boolean

Checks if the task type starts with “escort”.

Returns:

  • (Boolean)

    true if the task is an escort task, false otherwise



98
99
100
# File 'lib/gemstone/bounty/task.rb', line 98

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

#gem?Boolean

Checks if the task type starts with “gem”.

Returns:

  • (Boolean)

    true if the task is a gem task, false otherwise



105
106
107
# File 'lib/gemstone/bounty/task.rb', line 105

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

#group?Boolean

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

Returns:

  • (Boolean)

    true if the task is a group task, false otherwise



243
244
245
# File 'lib/gemstone/bounty/task.rb', line 243

def group?
  help?
end

#guard?Boolean

Checks if the task type is one of the guard-related types.

Returns:

  • (Boolean)

    true if the task is a guard task, false otherwise



202
203
204
205
206
207
# File 'lib/gemstone/bounty/task.rb', line 202

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

#heirloom?Boolean

Checks if the task type starts with “heirloom”.

Returns:

  • (Boolean)

    true if the task is an heirloom task, false otherwise



112
113
114
# File 'lib/gemstone/bounty/task.rb', line 112

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

#heirloom_found?Boolean

Checks if the task type is “heirloom_found”.

Returns:

  • (Boolean)

    true if the task is an heirloom found task, false otherwise



156
157
158
159
160
# File 'lib/gemstone/bounty/task.rb', line 156

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

#help?Boolean

Checks if the description indicates a help task.

Returns:

  • (Boolean)

    true if the task is a help task, false otherwise



229
230
231
# File 'lib/gemstone/bounty/task.rb', line 229

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

#herb?Boolean

Checks if the task type starts with “herb”.

Returns:

  • (Boolean)

    true if the task is a herb task, false otherwise



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

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

#kindSymbol

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

Returns:

  • (Symbol)

    the type of the task



30
# File 'lib/gemstone/bounty/task.rb', line 30

def kind; type; end

#locationString

Returns the area requirement or the town associated with the task.

Returns:

  • (String)

    the area or town for the task



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

def location
  requirements[:area] || town
end

#loot_heirloom?Boolean

Checks if the task is a loot action for an heirloom.

Returns:

  • (Boolean)

    true if the task is a loot for an heirloom, false otherwise



148
149
150
151
# File 'lib/gemstone/bounty/task.rb', line 148

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

#none?Boolean

Checks if there are no tasks.

Returns:

  • (Boolean)

    true if there are no tasks, false otherwise



195
196
197
# File 'lib/gemstone/bounty/task.rb', line 195

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

#ready?Boolean

Checks if the task is ready based on its type.

Returns:

  • (Boolean)

    true if the task is ready, false otherwise



219
220
221
222
223
224
# File 'lib/gemstone/bounty/task.rb', line 219

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 starts with “rescue”.

Returns:

  • (Boolean)

    true if the task is a rescue task, false otherwise



126
127
128
# File 'lib/gemstone/bounty/task.rb', line 126

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

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

Checks if the method is missing and if it corresponds to a requirement.

Parameters:

  • symbol (Symbol)

    the method name

  • include_private (Boolean) (defaults to: false)

    whether to include private methods

Returns:

  • (Boolean)

    true if the method is a requirement, false otherwise



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

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

#search_heirloom?Boolean

Checks if the task is a search action for an heirloom.

Returns:

  • (Boolean)

    true if the task is a search for an heirloom, false otherwise



140
141
142
143
# File 'lib/gemstone/bounty/task.rb', line 140

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

#skin?Boolean

Checks if the task type starts with “skin”.

Returns:

  • (Boolean)

    true if the task is a skin task, false otherwise



133
134
135
# File 'lib/gemstone/bounty/task.rb', line 133

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

#spawned?Boolean

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

Returns:

  • (Boolean)

    true if the task is spawned, false otherwise



174
175
176
177
178
# File 'lib/gemstone/bounty/task.rb', line 174

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

#taskSymbol

Returns the type of the task.

Returns:

  • (Symbol)

    the type of the task



25
# File 'lib/gemstone/bounty/task.rb', line 25

def task; type; end

#triggered?Boolean

Checks if the task has been triggered (alias for spawned?).

Returns:

  • (Boolean)

    true if the task is triggered, false otherwise



183
# File 'lib/gemstone/bounty/task.rb', line 183

def triggered?; spawned?; end