Class: Bounty

Inherits:
Object
  • Object
show all
Defined in:
lib/Olib/bounty.rb

Constant Summary collapse

NPCS =
/Bramblefist|balding halfling alchemist|fur trader|guard|sergeant|Brindlestoat|Halfwhistle|tavernkeeper|Luthrek|Felinium|clerk|purser|taskmaster|gemcutter|jeweler|akrash|kris|Ghaerdish|Furryback|healer|dealer|Ragnoz|Maraene|Kelph|Areacne|Jhiseth|Gaedrein/i
HERBALIST_AREAS =
/illistim|vaalor|legendary rest|solhaven/i
REGEX =

this should be refactored to use CONST

OpenStruct.new(
  creature_problem: /"Hmm, I've got a task here from (?<town>.*?)\.  It appears they have a creature problem they\'d like you to solve/,
  report_to_guard:  /^You succeeded in your task and should report back to/,
  get_skin_bounty:  /The local furrier/,
  # You have located an antique silver bracer and should bring it back to the sentry just outside town.
  heirloom_found:   Regexp.union(
    /^You have located (?:a|an|some) (?<heirloom>.*?) and should bring it back to/),
  cooldown:         /^You are not currently assigned a task.  You will be eligible for new task assignment in about (?<minutes>.*?) minute(s)./,
  
  dangerous: /You have been tasked to hunt down and kill a particularly dangerous (?<creature>.*) that has established a territory (?:in|on) (?:the )?(?<area>.*?)(?: near| between| under|\.)/,
  succeeded: /^You have succeeded in your task and can return to the Adventurer's/,
  heirloom:  /^You have been tasked to recover (a|an|some) (?<heirloom>.*?) that an unfortunate citizen lost after being attacked by (a|an|some) (?<creature>.*?) (?:in|on|around|near|by) (?<area>.*?)(| near (?<realm>.*?))\./,


  get_rescue:      /"Hmm, I've got a task here from (?<town>.*?)\.  It appears that a local resident urgently needs our help in some matter/,
  get_bandits:     /"Hmm, I've got a task here from (?<town>.*?)\.  It appears they have a bandit problem they'd like you to solve./,
  get_heirloom:    /"Hmm, I've got a task here from (?<town>.*?)\.  It appears they need your help in tracking down some kind of lost heirloom/,
  get_herb_bounty: /local herbalist|local healer|local alchemist|local halfling alchemist/,
  get_gem_bounty:  /"Hmm, I've got a task here from (?<town>.*?)\.  The local gem dealer, (?<npc>[a-zA-Z ]+), has an order to fill and wants our help/,

  herb:   /requires (?:a |an |)(?<herb>.*?) found (?:in|on|around|near) (?<area>.*?)(| (near|between) (?<realm>.*?)).  These samples must be in pristine condition.  You have been tasked to retrieve (?<number>[\d]+)/,
  escort: /Go to the (.*?) and WAIT for (?:him|her|them) to meet you there.  You must guarantee (?:his|her|their) safety to (?<destination>.*?) as soon as/,
  gem:    /The gem dealer in (?<town>.*?), (?<npc>.*?), has received orders from multiple customers requesting (?:a|an|some) (?<gem>[a-zA-Z '-]+).  You have been tasked to retrieve (?<number>[0-9]+)/,
  cull:    /^You have been tasked to suppress (?<creature>(?!bandit).*) activity (?:in|on|around) (?<area>.*?)(| (near|between) (?<realm>.*?)).  You need to kill (?<number>[0-9]+)/,
  bandits: /^You have been tasked to suppress bandit activity (?:in|on|around|near) (?<area>.*?) (?:near|between|under) (?<realm>.*?).  You need to kill (?<number>[0-9]+)/,

  rescue:  /A local divinist has had visions of the child fleeing from (?:a|an) (?<creature>.*) (?:in|on) (?:the )?(?<area>.*?)(?: near| between| under|\.)/,
  failed:  /You have failed in your task/,
  none:    /You are not currently assigned a task/,
  skin:    /^You have been tasked to retrieve (?<number>\d+) (?<skin>.*?) of at least (?<quality>.*?) quality for (?<buyer>.*?) in (?<realm>.*?)\.\s+You can SKIN them off the corpse of (a|an|some) (?<creature>.*?) or/,
  
  help_bandits: /You have been tasked to help (?<partner>.*?) suppress bandit activity (?:in|on|around|near) (?<area>.*?) (?:near|between|under) (?<realm>.*?).  You need to kill (?<number>[0-9]+)/,
  help_creatures: /You have been tasked to help (?<partner>.*?) kill a dangerous creature by suppressing (?<creature>.*) activity (?:in|on|around|near) (?<area>.*?) (?:near|between|under) (?<realm>.*?) during the hunt.  You need to kill (?<number>[0-9]+)/,
  help_cull: /You have been tasked to help (?<partner>.*?) suppress (?<creature>.*) activity (?:in|on|around|near) (?<area>.*?) (?:near|between|under) (?<realm>.*?).  You need to kill (?<number>[0-9]+)/,
)

Class Method Summary collapse

Class Method Details

.ask_for_bounty(expedite: false) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/Olib/bounty.rb', line 136

def Bounty.ask_for_bounty(expedite: false)
  fput "unhide" if invisible?
  fput "unhide" if hidden?
  npc = self.find_npc
  previous_state = checkbounty
  if expedite
    fput "ask %s for expedite" % npc
  else
    fput "ask %s for bounty" % npc
  end
  ttl = Time.now + 2
  wait_while {checkbounty.eql?(previous_state) and Time.now < ttl}
end

.cooldown!Object



173
174
175
176
177
178
179
# File 'lib/Olib/bounty.rb', line 173

def Bounty.cooldown!
  if Bounty.cooldown?
    Go2.origin
    wait_while { Bounty.cooldown? }
  end
  Bounty
end

.cooldown?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/Olib/bounty.rb', line 169

def Bounty.cooldown?
  not XMLData.active_spells["Next Bounty"].nil?
end

.currentObject



117
118
119
# File 'lib/Olib/bounty.rb', line 117

def Bounty.current
  Bounty.parse(checkbounty)
end

.done?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/Olib/bounty.rb', line 113

def Bounty.done?
  succeeded?
end

.fetch!Object



81
82
83
# File 'lib/Olib/bounty.rb', line 81

def Bounty.fetch!
  checkbounty.strip
end

.find_guardObject



181
182
183
184
185
186
# File 'lib/Olib/bounty.rb', line 181

def Bounty.find_guard
  Go2.advguard
  if Bounty.npc.nil? then Go2.advguard2 end
  throw Errors::Fatal.new "could not find guard" if Bounty.npc.nil?  
  return Bounty
end

.find_npcObject

fix because of Dreaven’s MA army fucking with XML feed



126
127
128
129
130
131
132
133
134
# File 'lib/Olib/bounty.rb', line 126

def self.find_npc
  return "#%s" % self.npc.id if self.npc
  case XMLData.room_id
  when 15004001
    return "Halline"
  else
    self.npc_404!
  end
end

.herbalistObject



150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/Olib/bounty.rb', line 150

def Bounty.herbalist
  if Room.current.location =~ /hinterwilds/i
    Script.run("go2", "u7503253")
    return self
  end
  if Room.current.location =~ HERBALIST_AREAS
    Go2.herbalist
  else
    Go2.npchealer
  end
  self
end

.match(bounty) ⇒ Object



85
86
87
88
89
# File 'lib/Olib/bounty.rb', line 85

def Bounty.match(bounty)
  Bounty.regex.each_pair.find do |type, exp|
    exp.match bounty
  end
end

.method_missing(method) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/Olib/bounty.rb', line 91

def Bounty.method_missing(method)
  str = method.to_s

  if str.chars.last == "?"
    return Bounty.type == str.chars.take(str.length-1).join.to_sym
  end

  unless current[method].nil?
    current[method]
  else
    raise Exception.new "Bounty<#{Bounty.current.to_h}> does not respond to :#{method}"
  end
end

.npcObject



188
189
190
191
# File 'lib/Olib/bounty.rb', line 188

def Bounty.npc
  GameObj.npcs.find { |npc| npc.name =~ NPCS } or
  GameObj.room_desc.find { |npc| npc.name =~ NPCS }
end

.npc_404!Object

Raises:

  • (Exception)


121
122
123
# File 'lib/Olib/bounty.rb', line 121

def self.npc_404!
  raise Exception, "could not find Bounty.npc here" unless Bounty.npc
end

.parse(str) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/Olib/bounty.rb', line 62

def Bounty.parse(str)
  type, patt = Bounty.match str
  unless patt
    return OpenStruct.new
  else
    bounty = patt.match(str).to_struct
    bounty[:type] = type
    if bounty[:skin] 
      bounty[:skin] = Bounty.singularize(bounty[:skin]) 
    end

    if bounty[:creature]
      bounty[:tags] = Creature.tags(bounty.creature)
    end

    bounty
  end
end

.regexObject

Returns Bounty Regex.

Returns:

  • Bounty Regex



53
54
55
# File 'lib/Olib/bounty.rb', line 53

def Bounty.regex
  REGEX
end

.removeObject



163
164
165
166
167
# File 'lib/Olib/bounty.rb', line 163

def Bounty.remove
  Go2.advguild
  2.times do fput "ask ##{Bounty.npc.id} for remove" end
  Bounty
end

.singularize(thing) ⇒ Object



57
58
59
60
# File 'lib/Olib/bounty.rb', line 57

def Bounty.singularize(thing)
  thing
    .gsub("teeth", "tooth")
end

.taskObject



109
110
111
# File 'lib/Olib/bounty.rb', line 109

def Bounty.task
  Bounty.current
end

.typeObject



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

def Bounty.type
  match(Bounty.fetch!).first
end

.typesObject

convenience list to get all types of bounties



45
46
47
# File 'lib/Olib/bounty.rb', line 45

def Bounty.types
  REGEX.keys
end