Class: Olib::Bounty

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

Direct Known Subclasses

Bounty

Constant Summary collapse

@@listeners =
{}
@@re =
{}

Class Method Summary collapse

Class Method Details

.areaObject



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

def Bounty.area
  Bounty.current[:area]
end

.ask_for_bountyObject



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

def Bounty.ask_for_bounty
  fput "ask ##{Bounty.npc.id} for bounty"
  Bounty
end

.cooldown!Object



115
116
117
118
119
120
121
# File 'lib/Olib/bounty.rb', line 115

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

.cooldown?Boolean

Returns:

  • (Boolean)


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

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

.creatureObject



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

def Bounty.creature
  Bounty.current[:creature]
end

.currentObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/Olib/bounty.rb', line 75

def Bounty.current
  info = nil
  bounty_str = checkbounty.strip
  Bounty.regex.each do |type, exp|
    if data = exp.match(bounty_str) then
      info = data.names.length ? Hash[ data.names.map(&:to_sym).zip( data.captures ) ] : {}
      info[:type] = type
    end
  end
  return info || {}
end

.destinationObject



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

def Bounty.destination
  Bounty.current[:destiniation]
end

.dispatch(listener = nil) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/Olib/bounty.rb', line 137

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

.find_guardObject



155
156
157
158
159
160
161
162
# File 'lib/Olib/bounty.rb', line 155

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

.gemObject



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

def Bounty.gem
  Bounty.current[:gem]
end

.herbObject



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

def Bounty.herb
  Bounty.current[:herb]
end

.listenersObject



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

def Bounty.listeners
  @@listeners
end

.nObject



63
64
65
# File 'lib/Olib/bounty.rb', line 63

def Bounty.n
  Bounty.current[:number].to_i
end

.npcObject



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

def Bounty.npc
  GameObj.npcs.select { |npc| npc.name =~ /guard|taskmaster|gemcutter|jeweler|akrash|kris|healer|dealer/i }.first
end

.on(namespace, &block) ⇒ Object



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

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

.regexObject

Returns Bounty Regex.

Returns:

  • Bounty Regex



35
36
37
# File 'lib/Olib/bounty.rb', line 35

def Bounty.regex
  @@re
end

.removeObject



92
93
94
95
96
# File 'lib/Olib/bounty.rb', line 92

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

.taskObject



71
72
73
# File 'lib/Olib/bounty.rb', line 71

def Bounty.task
  Bounty.current
end

.throw_missing_listenerObject



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

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 Errors::Fatal.new msg
end

.to_sObject



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

def Bounty.to_s
  @@listeners.to_s
end

.townObject



39
40
41
# File 'lib/Olib/bounty.rb', line 39

def Bounty.town
  Bounty.current[:town]
end

.typeObject



67
68
69
# File 'lib/Olib/bounty.rb', line 67

def Bounty.type
  Bounty.current[:type]
end

.typesObject

convenience list to get all types of bounties



27
28
29
# File 'lib/Olib/bounty.rb', line 27

def Bounty.types
  @@re.keys
end