Olib 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 901479e6bec498eac64a1efcd4614d52e7f7e4a5
4
- data.tar.gz: 0cbde613e5bf68f9a6a53be5bcb7e3a22a48a53e
3
+ metadata.gz: 32dd85c76004987a26b1485416f9ea279ff9a18b
4
+ data.tar.gz: 3bd045223d339ccd81a67d842253821f694665fb
5
5
  SHA512:
6
- metadata.gz: ef96e09e9b39f404f240d7a33f0c7445f240441386360d2f6801f7d2b24fc379bc588b39e4321f9d83521623597c88e00da12c83eed13db3b9ffcb2f2dea651e
7
- data.tar.gz: 742745addc4ab4a8539f0e05a2e3bd58df57a27ffa8535e4cbfa917c8e205096411b9eb6eee6edd57180bb5058f58034cc78a9a9176b8240663ec5ad513b5b4a
6
+ metadata.gz: 15e3b6ca1d57404720b818b69b9275b5240711f11d83bd6252432866fc6f4be3e390ad3eef42447fc378013f80dd4d7aafc1d06b9105b657bb42a26b81d06fed
7
+ data.tar.gz: 77a1f64d339a3f50fcdfba866c566e54deeb2f8b7f865bbbb29b68051a606c90e17f89e47f7c82756f420a4b4849aa5639b004ee176ccdb0a43c86ae1db93a48
@@ -1,17 +1,18 @@
1
- lib = File.expand_path("../lib/", __FILE__)
2
- $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
3
-
4
- Gem::Specification.new do |s|
5
- s.name = 'Olib'
6
- s.version = '0.0.8'
7
- s.date = '2014-09-12'
8
- s.summary = "Useful Lich extensions for Gemstone IV"
9
- s.description = "Useful Lich extensions for Gemstone IV including hostile creature management, group management, syntactically pleasing movement, locker management, etc"
10
- s.authors = ["Ondreian Shamsiel"]
11
- s.email = 'ondreian.shamsiel@gmail.com'
12
- s.homepage = 'https://github.com/ondreian/Olib'
13
- s.files = %w[Olib.gemspec] + Dir['*.md', 'lib/**/*.rb']
14
- #s.require_paths = %w[lib]
15
- # s.add_runtime_dependency 'shoes'
16
- s.license = 'MIT'
1
+ lib = File.expand_path("../lib/", __FILE__)
2
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
3
+ require "Olib/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "Olib"
7
+ s.version = Olib::VERSION
8
+ s.date = "2014-09-12"
9
+ s.summary = "Useful Lich extensions for Gemstone IV"
10
+ s.description = "Useful Lich extensions for Gemstone IV including hostile creature management, group management, syntactically pleasing movement, locker management, etc"
11
+ s.authors = ["Ondreian Shamsiel"]
12
+ s.email = "ondreian.shamsiel@gmail.com"
13
+ s.homepage = "https://github.com/ondreian/Olib"
14
+ s.files = %w[Olib.gemspec] + Dir["*.md", "lib/**/*.rb"]
15
+ #s.require_paths = %w[lib]
16
+ # s.add_runtime_dependency "shoes"
17
+ s.license = "MIT"
17
18
  end
data/README.md CHANGED
@@ -1,21 +1,23 @@
1
- ## Olib
2
-
3
- `gem install Olib`
4
-
5
- This offers a lot of syntatic sugar for scripting in GS
6
-
7
- examples:
8
-
9
- ``` ruby
10
- Creatures.magical.each { |creature|
11
- creature.kill
12
- }
13
- ```
14
-
15
- ``` ruby
16
- Group.members.each { |char|
17
- haste(char)
18
- }
19
- ```
20
-
21
- Pull requests and the like as welcome.
1
+ ## Olib [![Build Status](https://travis-ci.org/ondreian/Olib.svg?branch=master)](https://travis-ci.org/ondreian/Olib)
2
+
3
+ `gem install Olib`
4
+
5
+ This offers a lot of syntatic sugar for scripting in GS.
6
+
7
+ examples:
8
+
9
+ ``` ruby
10
+ Creatures.magical.each { |creature|
11
+ creature.kill
12
+ }
13
+ ```
14
+
15
+ ``` ruby
16
+ Group.members.each { |char|
17
+ haste(char)
18
+ }
19
+ ```
20
+
21
+ [WIP documentation](http://www.rubydoc.info/github/ondreian/Olib/Olib/)
22
+
23
+ Pull requests and the like as welcome.
data/TODOS.md CHANGED
@@ -1,4 +1,4 @@
1
- # TODOS
2
-
3
- + Add Documentation
1
+ # TODOS
2
+
3
+ + Add Documentation
4
4
  + Better tagging for items
@@ -1,51 +1,89 @@
1
- require 'net/http'
2
- require 'json'
3
-
4
- module Olib
5
-
6
- def Olib.update_notifier
7
- begin
8
- request = Net::HTTP::Get.new('/api/v1/gems/Olib.json', initheader = {'Content-Type' =>'application/json'})
9
- response = Net::HTTP.new('rubygems.org').start {|http| http.request(request) }
10
- if response.body =~ /error/
11
- # silence is golden
12
- exit
13
- else
14
- # check version
15
- if Gem.loaded_specs["Olib"].version < Gem::Version.new(JSON.parse(response.body)['version'])
16
- puts "<pushBold/>You need to update the Olib gem with a `gem install Olib`<popBold/>"
17
- end
18
- end
19
- rescue
20
- echo $!
21
- puts $!.backtrace[0..1]
22
- end
23
- end
24
-
25
- # load core first
26
- Dir[File.dirname(__FILE__) + '/Olib/core/**/*.rb'].each {|file|
27
- require file
28
- }
29
-
30
- # load things that depend on core extensions
31
- Dir[File.dirname(__FILE__) + '/Olib/**/*.rb'].each {|file|
32
- require file
33
- }
34
-
35
- # invoke update notifier immediately
36
- Olib.update_notifier
37
-
38
- def Olib.do(action, re)
39
- dothistimeout action, 5, re
40
- end
41
-
42
- def Olib.run(script, *args)
43
- start_script script, args
44
- wait_while { running? script }
45
- end
46
-
47
- Vars.Olib ||= Hash.new
48
-
49
-
50
-
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module Olib
5
+
6
+ def Olib.update_notifier
7
+ begin
8
+ response = JSON.parse Net::HTTP.get URI('https://rubygems.org/api/v1/gems/Olib.json')
9
+ # check version
10
+ if Gem.loaded_specs["Olib"].version < Gem::Version.new(response['version'])
11
+ puts "<pushBold/>You need to update the Olib gem with a `gem install Olib`<popBold/>"
12
+ end
13
+
14
+ rescue
15
+ echo $!
16
+ puts $!.backtrace[0..1]
17
+ end
18
+ end
19
+
20
+ def Olib.methodize(str)
21
+ str.downcase.strip.gsub(/-|\s+|'|"/, "_")
22
+ end
23
+
24
+ # load core first
25
+ Dir[File.dirname(__FILE__) + '/Olib/core/**/*.rb'].each {|file|
26
+ require file
27
+ }
28
+
29
+ # load things that depend on core extensions
30
+ Dir[File.dirname(__FILE__) + '/Olib/**/*.rb'].each {|file|
31
+ require file
32
+ }
33
+
34
+ # invoke update notifier immediately
35
+ Olib.update_notifier
36
+
37
+ def Olib.do(action, re)
38
+ dothistimeout action, 5, re
39
+ end
40
+
41
+ def Olib.run(script, *args)
42
+ start_script script, args
43
+ wait_while { running? script }
44
+ end
45
+
46
+ def Olib.install(g, v=nil)
47
+ if !which("gem") then
48
+ echo "Olib could not detect the `gem` executable in your $PATH"
49
+ echo "when you installed Ruby did you forget to click the `modify $PATH` box?"
50
+ raise Exception
51
+ end
52
+
53
+ begin
54
+ unless v.nil?
55
+ # make it a true instance of Gem::Version so we can compare
56
+ raise UpdateGemError if Gem.loaded_specs[g].version < Gem::Version.new(v)
57
+ gem g, v
58
+ end
59
+
60
+ Olib.reload g
61
+
62
+ ##
63
+ ## rescue missing gem and reload after install
64
+ ##
65
+ rescue LoadError
66
+ echo "installing #{g}..."
67
+ version = "--version '#{v}'" unless v.nil?
68
+ worked = system("gem install #{g} #{version} --no-ri --no-rdoc")
69
+ unless worked then raise "Could not install #{g} gem" end
70
+ Olib.reload g
71
+ echo "... installed #{g}!"
72
+
73
+ ##
74
+ ## rescue from too old of a gem version for a Ruby environment
75
+ ##
76
+ rescue UpdateGemError
77
+ echo "updating #{g}@#{Gem.loaded_specs[g].version} => #{v}..."
78
+ version = "--version '#{v}'" unless v.nil?
79
+ worked = system("gem install #{g} #{version} --no-ri --no-rdoc")
80
+ unless worked then raise "Could not install #{g} gem" end
81
+ Olib.reload g
82
+ echo "... updated #{g} to #{v}!"
83
+ end
84
+ end
85
+
86
+ Vars.Olib ||= Hash.new
87
+
88
+
51
89
  end
@@ -0,0 +1,51 @@
1
+ class Area < Olib::Container
2
+
3
+ def Area.current
4
+ Area.new
5
+ end
6
+
7
+ attr_accessor :room, :contents, :objects
8
+
9
+ def initialize
10
+ @contents = []
11
+ @room = Room.current
12
+ @objects = [ GameObj.loot, GameObj.room_desc ]
13
+ .flatten
14
+ .compact
15
+ .map { |thing| thing.id }
16
+ .uniq # sometimes objects exist in both loot & room_desc
17
+ .map { |id| Olib::Container.new id }
18
+ end
19
+
20
+ def contents
21
+ items = []
22
+ @objects
23
+ .reject { |container| container.name =~ /[A-Z][a-z]+ disk/ }
24
+ .each { |container|
25
+ check_container container
26
+ unless container.nested?
27
+ container.contents.each { |item|
28
+ item.container = container
29
+ items << item
30
+ }
31
+ else
32
+ container.containers.each do |nested|
33
+ check_container nested
34
+ nested.contents.each { |item|
35
+ item.container = container
36
+ items << item
37
+ }
38
+ end
39
+ end
40
+ }
41
+ items.compact
42
+ end
43
+
44
+ def check_container(container)
45
+ unless container.contents
46
+ container.look.at.on
47
+ end
48
+ end
49
+
50
+
51
+ end
@@ -1,129 +1,172 @@
1
- module Olib
2
- class Bounty
3
- @@procedures = {}
4
-
5
- @@re = {}
6
- @@re[:herb] = /requires (?:a|an|some) (?<herb>[a-zA-Z '-]+) found (?:in|on|around) (?<area>[a-zA-Z '-]+). These samples must be in pristine condition. You have been tasked to retrieve (?<number>[\d]+)/
7
- @@re[:escort] = /Go to the (.*?) and WAIT for (?:him|her|them) to meet you there. You must guarantee (?:his|her|their) safety to (?<destiniation>[a-zA-Z '-]+) as soon as/
8
- @@re[:gem] = /has received orders from multiple customers requesting (?:a|an|some) (?<gem>[a-zA-Z '-]+). You have been tasked to retrieve (?<number>[0-9]+)/
9
- @@re[:heirloom] = /You have been tasked to recover ([a-zA-Z '-]+) that an unfortunate citizen lost after being attacked by (a|an|some) (?<creature>[a-zA-Z '-]+) (in|on|around|near|by) (?<area>[a-zA-Z '-]+)./
10
- @@re[:heirloom_found] = /^You have located the heirloom and should bring it back to/
11
- @@re[:turn_in] = /You have succeeded in your task and can return to the Adventurer's Guild to receive your reward/
12
- @@re[:guard_turn_in] = /^You succeeded in your task and should report back to/
13
- @@re[:guard_bounty] = /Go report to ([a-zA-Z ]+) to find out more/
14
- @@re[:cull] = /^You have been tasked to suppress (?<creature>^((?!bandit).)*$) activity (?:in|on) (?:the )? (?<area>.*?)(?: near| between| under|\.) ([a-zA-Z' ]+). You need to kill (?<number>[0-9]+)/
15
- @@re[:bandits] = /^You have been tasked to suppress bandit activity (?:in |on )(?:the )(?<area>.*?)(?: near| between| under) ([a-zA-Z' ]+). You need to kill (?<number>[0-9]+)/
16
- @@re[: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|\.)/
17
- @@re[:get_skin_bounty] = /The local furrier/
18
- @@re[:get_herb_bounty] = /local herbalist|local healer|local alchemist/
19
- @@re[:get_gem_bounty] = /The local gem dealer, (?<npc>[a-zA-Z ]+), has an order to fill and wants our help/
20
- @@re[:creature_problem] = /It appears they have a creature problem they\'d like you to solve/
21
- @@re[:rescue] = /A local divinist has had visions of the child fleeing from (?:a|an) (?<creature>.*) (?:in|on) (?:the )?(?<area>.*?)(?: near| between| under|\.)/
22
- @@re[:failed_bounty] = /You have failed in your task/
23
- @@re[:no_bounty] = /You are not currently assigned a task/
24
-
25
- # convenience list to get all types of bounties
26
- def Bounty.types
27
- @@re.keys
28
- end
29
-
30
- def Bounty.town
31
- checkbounty.match(@@re[ Bounty.type ])[:town]
32
- end
33
-
34
- def Bounty.area
35
- checkbounty.match(@@re[ Bounty.type ])[:area]
36
- end
37
-
38
- def Bounty.destination
39
- checkbounty.match(@@re[ Bounty.type ])[:destiniation]
40
- end
41
-
42
- def Bounty.gem
43
- checkbounty.match(@@re[ Bounty.type ])[:gem]
44
- end
45
-
46
- def Bounty.creature
47
- checkbounty.match(@@re[ Bounty.type ])[:creature]
48
- end
49
-
50
- def Bounty.herb
51
- checkbounty.match(@@re[ Bounty.type ])[:herb]
52
- end
53
-
54
- def Bounty.n
55
- checkbounty.match(@@re[ Bounty.type ])[:number].to_i
56
- end
57
-
58
- def Bounty.type
59
- t = nil
60
- @@re.each do |type, exp|
61
- t= type if checkbounty =~ exp
62
- end
63
- return t
64
- end
65
-
66
- def Bounty.current
67
- Bounty.type
68
- end
69
-
70
- def Bounty.ask_for_bounty
71
- fput "ask ##{Bounty.npc.id} for bounty"
72
- end
73
-
74
- def Bounty.to_s
75
- @@procedures.to_s
76
- end
77
-
78
- def Bounty.define_procedure(namespace, &block)
79
- @@procedures[namespace] = block
80
- end
81
-
82
- def Bounty.procedures
83
- @@procedures
84
- end
85
-
86
- def Bounty.cooldown?
87
- Spell[9003].active?
88
- end
89
-
90
- def Bounty.throw_missing_procedure
91
- msg = "\n"
92
- msg.concat "\nBounty.exec called for #{Bounty.current} without a defined procedure\n\n"
93
- msg.concat "define a procedure with:\n"
94
- msg.concat " \n"
95
- msg.concat " Bounty.define_procedure(:#{Bounty.current}) {\n"
96
- msg.concat " # do something\n"
97
- msg.concat " }\n"
98
- msg.concat " \n"
99
- msg.concat "or rescue this error (Olib::Errors::Fatal) gracefully\n"
100
- msg.concat " \n"
101
- raise Errors::Fatal.new msg
102
- end
103
-
104
- def Bounty.exec(procedure=nil)
105
-
106
- if procedure
107
- if @@procedures[procedure]
108
- @@procedures[procedure].call
109
- return Bounty
110
- else
111
- Bounty.throw_missing_procedure
112
- end
113
- end
114
-
115
- if @@procedures[Bounty.current]
116
- @@procedures[Bounty.current].call
117
- return Bounty
118
- else
119
- Bounty.throw_missing_procedure
120
- end
121
-
122
- end
123
-
124
- def Bounty.npc
125
- GameObj.npcs.select { |npc| npc.name =~ /guard|taskmaster|gemcutter|jeweler|akrash|healer/i }.first
126
- end
127
-
128
- end
1
+ module Olib
2
+ class Bounty
3
+ @@listeners = {}
4
+ @@re = {}
5
+ @@re[:herb] = /requires (?:a|an|some) (?<herb>[a-zA-Z '-]+) found (?:in|on|around) (?<area>[a-zA-Z '-]+). These samples must be in pristine condition. You have been tasked to retrieve (?<number>[\d]+)/
6
+ @@re[:escort] = /Go to the (.*?) and WAIT for (?:him|her|them) to meet you there. You must guarantee (?:his|her|their) safety to (?<destiniation>[a-zA-Z '-]+) as soon as/
7
+ @@re[:gem] = /has received orders from multiple customers requesting (?:a|an|some) (?<gem>[a-zA-Z '-]+). You have been tasked to retrieve (?<number>[0-9]+)/
8
+ @@re[:heirloom] = /You have been tasked to recover ([a-zA-Z '-]+) that an unfortunate citizen lost after being attacked by (a|an|some) (?<creature>[a-zA-Z '-]+) (in|on|around|near|by) (?<area>[a-zA-Z '-]+)./
9
+ @@re[:heirloom_found] = /^You have located the heirloom and should bring it back to/
10
+ @@re[:succeeded] = /^You have succeeded in your task and can return to the Adventurer's/
11
+ @@re[:report_to_guard] = /^You succeeded in your task and should report back to/
12
+ @@re[:cull] = /^You have been tasked to suppress (?<creature>^((?!bandit).)*$) activity (?:in|on) (?:the )? (?<area>.*?)(?: near| between| under|\.) ([a-zA-Z' ]+). You need to kill (?<number>[0-9]+)/
13
+ @@re[:bandits] = /^You have been tasked to suppress bandit activity (?:in |on )(?:the )(?<area>.*?)(?: near| between| under) ([a-zA-Z' ]+). You need to kill (?<number>[0-9]+)/
14
+ @@re[: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|\.)/
15
+ @@re[:get_skin_bounty] = /The local furrier/
16
+ @@re[:get_rescue] = /It appears that a local resident urgently needs our help in some matter/
17
+ @@re[:get_bandits] = /It appears they have a bandit problem they'd like you to solve./
18
+ @@re[:get_heirloom] = /It appears they need your help in tracking down some kind of lost heirloom/
19
+ @@re[:get_herb_bounty] = /local herbalist|local healer|local alchemist/
20
+ @@re[:get_gem_bounty] = /The local gem dealer, (?<npc>[a-zA-Z ]+), has an order to fill and wants our help/
21
+ @@re[:creature_problem] = /It appears they have a creature problem they\'d like you to solve/
22
+ @@re[:rescue] = /A local divinist has had visions of the child fleeing from (?:a|an) (?<creature>.*) (?:in|on) (?:the )?(?<area>.*?)(?: near| between| under|\.)/
23
+ @@re[:failed] = /You have failed in your task/
24
+ @@re[:none] = /You are not currently assigned a task/
25
+
26
+ # convenience list to get all types of bounties
27
+ def Bounty.types
28
+ @@re.keys
29
+ end
30
+ ##
31
+ ## @brief provides an accessor to the raw regular expression dictionary for Bounty logic
32
+ ##
33
+ ## @return Bounty Regex
34
+ ##
35
+ def Bounty.regex
36
+ @@re
37
+ end
38
+
39
+ def Bounty.town
40
+ Bounty.current[:town]
41
+ end
42
+
43
+ def Bounty.area
44
+ Bounty.current[:area]
45
+ end
46
+
47
+ def Bounty.destination
48
+ Bounty.current[:destiniation]
49
+ end
50
+
51
+ def Bounty.gem
52
+ Bounty.current[:gem]
53
+ end
54
+
55
+ def Bounty.creature
56
+ Bounty.current[:creature]
57
+ end
58
+
59
+ def Bounty.herb
60
+ Bounty.current[:herb]
61
+ end
62
+
63
+ def Bounty.n
64
+ Bounty.current[:number].to_i
65
+ end
66
+
67
+ def Bounty.type
68
+ Bounty.current[:type]
69
+ end
70
+
71
+ def Bounty.task
72
+ Bounty.current
73
+ end
74
+
75
+ def Bounty.current
76
+ info = nil
77
+ bounty_str = checkbounty.strip
78
+ Bounty.regex.each do |type, exp|
79
+ if data = exp.match(bounty_str) then
80
+ info = data.names.length ? Hash[ data.names.map(&:to_sym).zip( data.captures ) ] : {}
81
+ info[:type] = type
82
+ end
83
+ end
84
+ return info || {}
85
+ end
86
+
87
+ def Bounty.ask_for_bounty
88
+ fput "ask ##{Bounty.npc.id} for bounty"
89
+ Bounty
90
+ end
91
+
92
+ def Bounty.remove
93
+ Go2.advguild
94
+ 2.times do fput "ask ##{Bounty.npc.id} for remove" end
95
+ Bounty
96
+ end
97
+
98
+ def Bounty.to_s
99
+ @@listeners.to_s
100
+ end
101
+
102
+ def Bounty.on(namespace, &block)
103
+ @@listeners[namespace] = block
104
+ Bounty
105
+ end
106
+
107
+ def Bounty.listeners
108
+ @@listeners
109
+ end
110
+
111
+ def Bounty.cooldown?
112
+ Spell[9003].active?
113
+ end
114
+
115
+ def Bounty.cooldown!
116
+ if Bounty.cooldown?
117
+ Go2.origin
118
+ wait_until { !Bounty.cooldown? }
119
+ end
120
+ Bounty
121
+ end
122
+
123
+ def Bounty.throw_missing_listener
124
+ msg = "\n"
125
+ msg.concat "\nBounty.dispatch called for `:#{Bounty.type}` without a defined listener\n\n"
126
+ msg.concat "define a listener with:\n"
127
+ msg.concat " \n"
128
+ msg.concat " Bounty.on(:#{Bounty.type}) {\n"
129
+ msg.concat " # do something\n"
130
+ msg.concat " }\n"
131
+ msg.concat " \n"
132
+ msg.concat "or rescue this error (Olib::Errors::Fatal) gracefully\n"
133
+ msg.concat " \n"
134
+ raise Errors::Fatal.new msg
135
+ end
136
+
137
+ def Bounty.dispatch(listener=nil)
138
+ if listener
139
+ if @@listeners[listener]
140
+ @@listeners[listener].call
141
+ return Bounty
142
+ else
143
+ Bounty.throw_missing_listener
144
+ end
145
+ end
146
+
147
+ if @@listeners[Bounty.type]
148
+ @@listeners[Bounty.type].call
149
+ return Bounty
150
+ else
151
+ Bounty.throw_missing_listener
152
+ end
153
+ end
154
+
155
+ def Bounty.find_guard
156
+ Go2.advguard
157
+ if Bounty.npc.nil? then Go2.advguard2 end
158
+ if Bounty.npc.nil? then
159
+ throw Olib::Errors::Fatal.new "could not find guard"
160
+ end
161
+ return Bounty
162
+ end
163
+
164
+ def Bounty.npc
165
+ GameObj.npcs.select { |npc| npc.name =~ /guard|taskmaster|gemcutter|jeweler|akrash|kris|healer|dealer/i }.first
166
+ end
167
+
168
+ end
169
+ end
170
+
171
+ class Bounty < Olib::Bounty
129
172
  end