Class: Bounty

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

Constant Summary collapse

NPCS =
/guard|sergeant|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: /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/,
  heirloom_found:   /^You have located the 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:      /It appears that a local resident urgently needs our help in some matter/,
  get_bandits:     /It appears they have a bandit problem they'd like you to solve./,
  get_heirloom:    /It appears they need your help in tracking down some kind of lost heirloom/,
  get_herb_bounty: /local herbalist|local healer|local alchemist/,
  get_gem_bounty:  /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:    /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) (?<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) (?<area>.*?)(| near (?<realm>.*?)).  You need to kill (?<number>[0-9]+)/
)
@@listeners =
{}

Class Method Summary collapse

Class Method Details

.ask_for_bountyObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/Olib/bounty.rb', line 118

def Bounty.ask_for_bounty
  if invisible?
    fput "unhide"
  end

  if hidden?
    fput "unhide"
  end

  if Bounty.npc
    fput "ask ##{Bounty.npc.id} for bounty"
    Bounty
  else
    raise Exception.new "could not find Bounty.npc here"
  end
  # give the XML parser time to update
  sleep 0.2
end

.cooldown!Object



165
166
167
168
169
170
171
# File 'lib/Olib/bounty.rb', line 165

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

.cooldown?Boolean



161
162
163
# File 'lib/Olib/bounty.rb', line 161

def Bounty.cooldown?
  Spell[9003].active?
end

.currentObject



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

def Bounty.current
  Bounty.parse(checkbounty)
end

.dispatch(listener = nil) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/Olib/bounty.rb', line 187

def Bounty.dispatch(listener=nil)
  if listener
    if @@listeners[listener]
      @@listeners[listener].call
      return Bounty
    else 
      Bounty.throw_missing_listener
    end
  end

  if @@listeners[Bounty.type]
    @@listeners[Bounty.type].call
    return Bounty
  else
    Bounty.throw_missing_listener
  end
end

.done?Boolean



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

def Bounty.done?
  succeeded?
end

.fetch!Object



78
79
80
# File 'lib/Olib/bounty.rb', line 78

def Bounty.fetch!
  checkbounty.strip
end

.find_guardObject



205
206
207
208
209
210
211
212
# File 'lib/Olib/bounty.rb', line 205

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

.herbalistObject



137
138
139
140
141
142
143
144
# File 'lib/Olib/bounty.rb', line 137

def Bounty.herbalist
  if Room.current.location =~ HERBALIST_AREAS
    Go2.herbalist
  else
    Go2.npchealer
  end
  self
end

.listenersObject



157
158
159
# File 'lib/Olib/bounty.rb', line 157

def Bounty.listeners
  @@listeners
end

.match(bounty) ⇒ Object



82
83
84
85
86
# File 'lib/Olib/bounty.rb', line 82

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

.method_missing(method) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/Olib/bounty.rb', line 88

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



214
215
216
217
# File 'lib/Olib/bounty.rb', line 214

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

.on(namespace, &block) ⇒ Object



152
153
154
155
# File 'lib/Olib/bounty.rb', line 152

def Bounty.on(namespace, &block)
  @@listeners[namespace] = block
  Bounty
end

.parse(str) ⇒ Object



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

def Bounty.parse(str)
  type, patt = Bounty.match str
  unless patt
    raise Exception.new "could not match Bounty: #{str}\nplease notify Ondreian"
  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



50
51
52
# File 'lib/Olib/bounty.rb', line 50

def Bounty.regex
  REGEX
end

.removeObject



146
147
148
149
150
# File 'lib/Olib/bounty.rb', line 146

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

.singularize(thing) ⇒ Object



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

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

.taskObject



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

def Bounty.task
  Bounty.current
end

.throw_missing_listenerObject



173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/Olib/bounty.rb', line 173

def Bounty.throw_missing_listener
  msg = "\n"
  msg.concat "\nBounty.dispatch called for `:#{Bounty.type}` without a defined listener\n\n"
  msg.concat "define a listener with:\n"
  msg.concat " \n" 
  msg.concat "   Bounty.on(:#{Bounty.type}) {\n" 
  msg.concat "      # do something\n"
  msg.concat "   }\n"
  msg.concat " \n"
  msg.concat "or rescue this error (Olib::Errors::Fatal) gracefully\n"
  msg.concat " \n"
  raise Olib::Errors::Fatal.new msg
end

.typeObject



102
103
104
# File 'lib/Olib/bounty.rb', line 102

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

.typesObject

convenience list to get all types of bounties



42
43
44
# File 'lib/Olib/bounty.rb', line 42

def Bounty.types
  REGEX.keys
end