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 instance.

Parameters:

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

    options for the task

Options Hash (options):

  • :description (String) — default: nil

    the description of the task

  • :type (String) — default: nil

    the type of the task

  • :requirements (Hash) — default: nil

    the requirements for the task

  • :town (String) — default: nil

    the town associated with the task



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

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.

Parameters:

  • symbol (Symbol)

    the method name being called

  • args (Array)

    arguments passed to the method

Returns:

  • (Object)

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



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

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.



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

def description
  @description
end

#requirementsObject

Returns the value of attribute requirements.



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

def requirements
  @requirements
end

#townObject

Returns the value of attribute town.



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

def town
  @town
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#any?Boolean

Checks if there are any tasks.

Returns:

  • (Boolean)

    true if there are tasks, false otherwise



163
164
165
# File 'documented/gemstone/bounty/task.rb', line 163

def any?
  !none?
end

#assigned?Boolean

Checks if the task is assigned.

Returns:

  • (Boolean)

    true if the task type ends with "assignment", false otherwise



184
185
186
# File 'documented/gemstone/bounty/task.rb', line 184

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

#assist?Boolean

Checks if the task is an assist task.

Returns:

  • (Boolean)

    true if the task is a help task, false otherwise



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

def assist?
  help?
end

#bandit?Boolean

Checks if the task type is a bandit type.

Returns:

  • (Boolean)

    true if the task type starts with "bandit", false otherwise



59
60
61
# File 'documented/gemstone/bounty/task.rb', line 59

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

#countInteger

Returns the number associated with the task.

Returns:

  • (Integer)

    the number associated with the task



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

def count; number; end

#creatureString?

Returns the creature requirement for the task.

Returns:

  • (String, nil)

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



35
36
37
# File 'documented/gemstone/bounty/task.rb', line 35

def creature
  requirements[:creature]
end

#creature?Boolean

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

Returns:

  • (Boolean)

    true if the task type is a creature type, false otherwise



65
66
67
68
69
# File 'documented/gemstone/bounty/task.rb', line 65

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

#critterString?

Returns the creature requirement for the task.

Returns:

  • (String, nil)

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



41
42
43
# File 'documented/gemstone/bounty/task.rb', line 41

def critter
  requirements[:creature]
end

#critter?Boolean

Checks if there is a creature requirement for the task.

Returns:

  • (Boolean)

    true if a creature is required, false otherwise



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

def critter?
  !!requirements[:creature]
end

#cull?Boolean

Checks if the task type is a cull type.

Returns:

  • (Boolean)

    true if the task type starts with "cull", false otherwise



73
74
75
# File 'documented/gemstone/bounty/task.rb', line 73

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

#dangerous?Boolean

Checks if the task type is a dangerous type.

Returns:

  • (Boolean)

    true if the task type starts with "dangerous", false otherwise



79
80
81
# File 'documented/gemstone/bounty/task.rb', line 79

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

#done?Boolean

Checks if the task is marked as done.

Returns:

  • (Boolean)

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



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

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

#escort?Boolean

Checks if the task type is an escort type.

Returns:

  • (Boolean)

    true if the task type starts with "escort", false otherwise



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

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

#gem?Boolean

Checks if the task type is a gem type.

Returns:

  • (Boolean)

    true if the task type starts with "gem", false otherwise



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

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

#group?Boolean

Checks if the task is a group task.

Returns:

  • (Boolean)

    true if the task is a help task, false otherwise



211
212
213
# File 'documented/gemstone/bounty/task.rb', line 211

def group?
  help?
end

#guard?Boolean

Checks if the task type is a guard type.

Returns:

  • (Boolean)

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



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

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

#heirloom?Boolean

Checks if the task type is an heirloom type.

Returns:

  • (Boolean)

    true if the task type starts with "heirloom", false otherwise



97
98
99
# File 'documented/gemstone/bounty/task.rb', line 97

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

#heirloom_found?Boolean

Checks if the task type indicates that an heirloom has been found.

Returns:

  • (Boolean)

    true if the task type is heirloom_found, false otherwise



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

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

#help?Boolean

Checks if the task description indicates a help task.

Returns:

  • (Boolean)

    true if the description starts with "You have been tasked to help", false otherwise



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

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

#herb?Boolean

Checks if the task type is an herb type.

Returns:

  • (Boolean)

    true if the task type starts with "herb", false otherwise



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

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

#kindString

Returns the type of the task.

Returns:

  • (String)

    the type of the task



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

def kind; type; end

#locationString

Returns the location requirement for the task.

Returns:

  • (String)

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



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

def location
  requirements[:area] || town
end

#loot_heirloom?Boolean

Checks if the task is to loot an heirloom.

Returns:

  • (Boolean)

    true if the task type is heirloom and action is "loot", false otherwise



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

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

#none?Boolean

Checks if there are no tasks.

Returns:

  • (Boolean)

    true if the task type is none or nil, false otherwise



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

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

#ready?Boolean

Checks if the task is ready to be executed.

Returns:

  • (Boolean)

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



190
191
192
193
194
195
# File 'documented/gemstone/bounty/task.rb', line 190

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 type.

Returns:

  • (Boolean)

    true if the task type starts with "rescue", false otherwise



109
110
111
# File 'documented/gemstone/bounty/task.rb', line 109

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.

Parameters:

  • symbol (Symbol)

    the method name being checked

  • include_private (Boolean) (defaults to: false)

    whether to include private methods in the check

Returns:

  • (Boolean)

    true if the method exists in requirements, false otherwise



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

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

#search_heirloom?Boolean

Checks if the task is to search for an heirloom.

Returns:

  • (Boolean)

    true if the task type is heirloom and action is "search", false otherwise



121
122
123
124
# File 'documented/gemstone/bounty/task.rb', line 121

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

#skin?Boolean

Checks if the task type is a skin type.

Returns:

  • (Boolean)

    true if the task type starts with "skin", false otherwise



115
116
117
# File 'documented/gemstone/bounty/task.rb', line 115

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

#spawned?Boolean

Checks if the task has spawned.

Returns:

  • (Boolean)

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



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

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

#taskString

Returns the type of the task.

Returns:

  • (String)

    the type of the task



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

def task; type; end

#triggered?Boolean

Checks if the task has been triggered.

Returns:

  • (Boolean)

    true if the task has spawned, false otherwise



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

def triggered?; spawned?; end