class Bounty

Constants

HERBALIST_AREAS
NPCS
REGEX

this should be refactored to use CONST

Public Class Methods

ask_for_bounty() click to toggle source
# 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!() click to toggle source
# File lib/Olib/bounty.rb, line 165
def Bounty.cooldown!
  if Bounty.cooldown?
    Go2.origin
    wait_until { !Bounty.cooldown? }
  end
  Bounty
end
cooldown?() click to toggle source
# File lib/Olib/bounty.rb, line 161
def Bounty.cooldown?
  Spell[9003].active?
end
current() click to toggle source
# File lib/Olib/bounty.rb, line 114
def Bounty.current
  Bounty.parse(checkbounty)
end
dispatch(listener=nil) click to toggle source
# 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?() click to toggle source
# File lib/Olib/bounty.rb, line 110
def Bounty.done?
  succeeded?
end
fetch!() click to toggle source
# File lib/Olib/bounty.rb, line 78
def Bounty.fetch!
  checkbounty.strip
end
find_guard() click to toggle source
# 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
herbalist() click to toggle source
# File lib/Olib/bounty.rb, line 137
def Bounty.herbalist
  if Room.current.location =~ HERBALIST_AREAS
    Go2.herbalist
  else
    Go2.npchealer
  end
  self
end
listeners() click to toggle source
# File lib/Olib/bounty.rb, line 157
def Bounty.listeners
  @@listeners
end
match(bounty) click to toggle source
# 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) click to toggle source
# 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
npc() click to toggle source
# 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) click to toggle source
# File lib/Olib/bounty.rb, line 152
def Bounty.on(namespace, &block)
  @@listeners[namespace] = block
  Bounty
end
parse(str) click to toggle source
# 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
regex() click to toggle source

@brief provides an accessor to the raw regular expression dictionary for Bounty logic

@return Bounty Regex

# File lib/Olib/bounty.rb, line 50
def Bounty.regex
  REGEX
end
remove() click to toggle source
# 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) click to toggle source
# File lib/Olib/bounty.rb, line 54
def Bounty.singularize(thing)
  thing
    .gsub("teeth", "tooth")
end
task() click to toggle source
# File lib/Olib/bounty.rb, line 106
def Bounty.task
  Bounty.current
end
throw_missing_listener() click to toggle source
# 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
type() click to toggle source
# File lib/Olib/bounty.rb, line 102
def Bounty.type
  match(Bounty.fetch!).first
end
types() click to toggle source

convenience list to get all types of bounties

# File lib/Olib/bounty.rb, line 42
def Bounty.types
  REGEX.keys
end