Class: Olib::Bounty
- Inherits:
-
Object
- Object
- Olib::Bounty
- Defined in:
- lib/Olib/bounty.rb
Direct Known Subclasses
Constant Summary collapse
- @@listeners =
{}
- @@re =
{}
Class Method Summary collapse
- .area ⇒ Object
- .ask_for_bounty ⇒ Object
- .cooldown! ⇒ Object
- .cooldown? ⇒ Boolean
- .creature ⇒ Object
- .current ⇒ Object
- .destination ⇒ Object
- .dispatch(listener = nil) ⇒ Object
- .find_guard ⇒ Object
- .gem ⇒ Object
- .herb ⇒ Object
- .listeners ⇒ Object
- .n ⇒ Object
- .npc ⇒ Object
- .on(namespace, &block) ⇒ Object
-
.regex ⇒ Object
Bounty Regex.
- .remove ⇒ Object
- .task ⇒ Object
- .throw_missing_listener ⇒ Object
- .to_s ⇒ Object
- .town ⇒ Object
- .type ⇒ Object
-
.types ⇒ Object
convenience list to get all types of bounties.
Class Method Details
.area ⇒ Object
43 44 45 |
# File 'lib/Olib/bounty.rb', line 43 def Bounty.area Bounty.current[:area] end |
.ask_for_bounty ⇒ Object
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
111 112 113 |
# File 'lib/Olib/bounty.rb', line 111 def Bounty.cooldown? Spell[9003].active? end |
.creature ⇒ Object
55 56 57 |
# File 'lib/Olib/bounty.rb', line 55 def Bounty.creature Bounty.current[:creature] end |
.current ⇒ Object
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 |
.destination ⇒ Object
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_guard ⇒ Object
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 |
.herb ⇒ Object
59 60 61 |
# File 'lib/Olib/bounty.rb', line 59 def Bounty.herb Bounty.current[:herb] end |
.listeners ⇒ Object
107 108 109 |
# File 'lib/Olib/bounty.rb', line 107 def Bounty.listeners @@listeners end |
.n ⇒ Object
63 64 65 |
# File 'lib/Olib/bounty.rb', line 63 def Bounty.n Bounty.current[:number].to_i end |
.npc ⇒ Object
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 |
.regex ⇒ Object
Returns Bounty Regex.
35 36 37 |
# File 'lib/Olib/bounty.rb', line 35 def Bounty.regex @@re end |
.remove ⇒ Object
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 |
.throw_missing_listener ⇒ Object
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_s ⇒ Object
98 99 100 |
# File 'lib/Olib/bounty.rb', line 98 def Bounty.to_s @@listeners.to_s end |
.town ⇒ Object
39 40 41 |
# File 'lib/Olib/bounty.rb', line 39 def Bounty.town Bounty.current[:town] end |
.type ⇒ Object
67 68 69 |
# File 'lib/Olib/bounty.rb', line 67 def Bounty.type Bounty.current[:type] end |
.types ⇒ Object
convenience list to get all types of bounties
27 28 29 |
# File 'lib/Olib/bounty.rb', line 27 def Bounty.types @@re.keys end |