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.
@@ -1,10 +1,10 @@
1
- module Olib
2
- class Jewelry < Item
3
- attr_accessor :heirloom
4
- def heirloom?
5
- result = Library.do "look ##{@id}", /^You see nothing unusual|#{Gemstone_Regex.item[:heirloom]}/
6
- @heirloom = result =~ Gemstone_Regex.item[:heirloom] ? true : false
7
- @heirloom
8
- end
9
- end
1
+ module Olib
2
+ class Jewelry < Item
3
+ attr_accessor :heirloom
4
+ def heirloom?
5
+ result = Library.do "look ##{@id}", /^You see nothing unusual|#{Gemstone_Regex.item[:heirloom]}/
6
+ @heirloom = result =~ Gemstone_Regex.item[:heirloom] ? true : false
7
+ @heirloom
8
+ end
9
+ end
10
10
  end
@@ -1,72 +1,72 @@
1
- module Olib
2
- class Scroll < Item
3
- @@whitelist = [
4
- 101, 102, 103, 107, 116, 120,
5
- 202, 211, 215, 219,
6
- 303, 307, 310, 313, 315,
7
- 401, 406, 414, 425, 430,
8
- 503, 507, 508, 509, 511, 513, 520,
9
- 601, 602, 606, 613, 617, 618, 625, 640,
10
- 712, 716,
11
- 905, 911, 913, 920,
12
- 1109, 1119, 1125, 1130,
13
- 1201, 1204,
14
- 1601, 1603, 1606, 1610, 1611, 1612, 1616,
15
- 1712, 1718
16
- ]
17
- attr_accessor :spells, :worthy, :whitelist
18
-
19
- def Scroll.whitelist
20
- @@whitelist
21
- end
22
-
23
- def Scroll.add_to_whitelist(*args)
24
- @@whitelist + args
25
- end
26
-
27
- def Scroll.remove_from_whitelist(*args)
28
- @@whitelist = @@whitelist - args
29
- end
30
-
31
- def initialize(item)
32
- super item
33
- @spells = []
34
- return self
35
- end
36
-
37
- def worthy?
38
- @worthy = false
39
- read unless @spells.length > 0
40
- @spells.each do |spell| @worthy = true if Scroll.whitelist.include? spell[:n] end
41
- @worthy
42
- end
43
-
44
- def sell
45
- unless self.worthy?
46
- result = dothistimeout "get ##{@id}", 1, /^You remove/
47
- fput "sell ##{@id}" if result
48
- end
49
- end
50
-
51
- def read
52
- dothistimeout "read ##{@id}", 5, /It takes you a moment to focus/
53
- result = matchtimeout(5, 'On the')
54
- if result
55
- begin
56
- Timeout::timeout(0.1) do
57
- while(get =~ /\(([0-9]+)\) ([a-zA-Z'\s]+)/)
58
- spell = {}
59
- spell[:n] = $1.to_i
60
- spell[:name] = $2.to_s
61
- @spells.push spell
62
- end
63
- end
64
- rescue Timeout::Error
65
- # Silent
66
- end
67
- end
68
- self
69
- end
70
-
71
- end
1
+ module Olib
2
+ class Scroll < Item
3
+ @@whitelist = [
4
+ 101, 102, 103, 107, 116, 120,
5
+ 202, 211, 215, 219,
6
+ 303, 307, 310, 313, 315,
7
+ 401, 406, 414, 425, 430,
8
+ 503, 507, 508, 509, 511, 513, 520,
9
+ 601, 602, 606, 613, 617, 618, 625, 640,
10
+ 712, 716,
11
+ 905, 911, 913, 920,
12
+ 1109, 1119, 1125, 1130,
13
+ 1201, 1204,
14
+ 1601, 1603, 1606, 1610, 1611, 1612, 1616,
15
+ 1712, 1718
16
+ ]
17
+ attr_accessor :spells, :worthy, :whitelist
18
+
19
+ def Scroll.whitelist
20
+ @@whitelist
21
+ end
22
+
23
+ def Scroll.add_to_whitelist(*args)
24
+ @@whitelist + args
25
+ end
26
+
27
+ def Scroll.remove_from_whitelist(*args)
28
+ @@whitelist = @@whitelist - args
29
+ end
30
+
31
+ def initialize(item)
32
+ super item
33
+ @spells = []
34
+ return self
35
+ end
36
+
37
+ def worthy?
38
+ @worthy = false
39
+ read unless @spells.length > 0
40
+ @spells.each do |spell| @worthy = true if Scroll.whitelist.include? spell[:n] end
41
+ @worthy
42
+ end
43
+
44
+ def sell
45
+ unless self.worthy?
46
+ result = dothistimeout "get ##{@id}", 1, /^You remove/
47
+ fput "sell ##{@id}" if result
48
+ end
49
+ end
50
+
51
+ def read
52
+ dothistimeout "read ##{@id}", 5, /It takes you a moment to focus/
53
+ result = matchtimeout(5, 'On the')
54
+ if result
55
+ begin
56
+ Timeout::timeout(0.1) do
57
+ while(get =~ /\(([0-9]+)\) ([a-zA-Z'\s]+)/)
58
+ spell = {}
59
+ spell[:n] = $1.to_i
60
+ spell[:name] = $2.to_s
61
+ @spells.push spell
62
+ end
63
+ end
64
+ rescue Timeout::Error
65
+ # Silent
66
+ end
67
+ end
68
+ self
69
+ end
70
+
71
+ end
72
72
  end
@@ -1,4 +1,4 @@
1
- module Olib
2
- class Uncommon < Item
3
- end
1
+ module Olib
2
+ class Uncommon < Item
3
+ end
4
4
  end
@@ -1,4 +1,4 @@
1
- module Olib
2
- class Unknown < Item
3
- end
1
+ module Olib
2
+ class Unknown < Item
3
+ end
4
4
  end
@@ -1,4 +1,4 @@
1
- module Olib
2
- class Wand < Item
3
- end
1
+ module Olib
2
+ class Wand < Item
3
+ end
4
4
  end
@@ -1,177 +1,177 @@
1
- module Olib
2
- module Shop
3
-
4
- @@containers = []
5
-
6
- def Shop.items
7
- Shop.containers.map { |container| container.contents }.flatten
8
- end
9
-
10
- def Shop.containers
11
- #fput "look"
12
- @@containers = [
13
- GameObj.loot,
14
- GameObj.room_desc
15
- ]
16
- .flatten
17
- .compact
18
- .select { |container| !(container.name =~ /^([A-z][a-z]+ disk$)/)}
19
- .map { |container| Shop::Container.new(container) }
20
-
21
- @@containers
22
-
23
- end
24
-
25
- def Shop.cache
26
- @@containers
27
- end
28
-
29
- class Container < Olib::Gameobj_Extender
30
- attr_accessor :show, :nested, :containers, :id, :cache, :props
31
-
32
- def to_s
33
- info = {}
34
- info[:name] = @name
35
- info[:noun] = @noun
36
- info[:props] = @props
37
- info[:cache] = @cache
38
- info.to_s
39
- end
40
-
41
- def initialize(obj)
42
- @cache = Hash.new
43
- @props = Hash.new
44
- super(obj)
45
- end
46
-
47
- def action(verb)
48
- "#{verb} ##{@id}"
49
- end
50
-
51
- def look
52
- self
53
- end
54
-
55
- # detect nested containers
56
- def at
57
-
58
- Olib.wrap_stream(action 'look at') { |line|
59
-
60
- raise Olib::Errors::Mundane if line =~ /You see nothing unusual/
61
-
62
- if line =~ /Looking at the (.*?), you see (?<nested>.*)/
63
- @nested = true
64
-
65
- @containers = line.match(/Looking at the (.*?), you see (?<nested>.*)/)[:nested].scan(/<a exist="(?<id>.*?)" noun="(?<noun>.*?)">(?<name>.*?)<\/a>/).map {|matches|
66
- Container.new GameObj.new *matches
67
- }
68
- raise Olib::Errors::Prempt
69
- end
70
-
71
- }
72
-
73
- self
74
- end
75
-
76
- def nested?
77
- @nested || false
78
- end
79
-
80
- def in
81
- return self unless @id
82
- Olib.wrap_stream(action 'look in') { |line|
83
- raise Olib::Errors::Mundane if line=~ /^There is nothing in there|^That is closed|filled with a variety of garbage|Total items:/
84
- raise Olib::Errors::Prempt if line =~ /^In the (.*?) you see/
85
- }
86
- self
87
- end
88
-
89
- def on
90
- return self unless @id
91
- Olib.wrap_stream(action 'look on') { |line|
92
- raise Olib::Errors::Mundane if line =~ /^There is nothing on there/
93
- raise Olib::Errors::Prempt if line =~ /^On the (.*?) you see/
94
- }
95
- self
96
- end
97
-
98
- def contents
99
- look.in.on unless GameObj[@id].contents
100
- GameObj[@id].contents.map {|i| Item.new(i).define('container', @id) }
101
- end
102
-
103
- def containers
104
- @containers
105
- end
106
- end
107
-
108
- class Playershop
109
- @@noncontainers = [ "wall", "ceiling", "permit", "floor", "helmet", "snowshoes",
110
- "candelabrum", "flowerpot", "Hearthstone", "bear", "candelabra",
111
- "sculpture", "anvil", "tapestry", "portrait", "Wehnimer", "spiderweb",
112
- "rug", "fountain", "longsword", "ship", "panel", "painting", "armor",
113
- "flowers", "head", "plate", "vase", "pillows", "mask", "skeleton", "fan",
114
- "flag", "statue", "mat", "plaque", "mandolin", "plant", "sign" ]
115
-
116
- def Playershop.containers
117
- Shop.containers.reject { |container|
118
- @@noncontainers.include? container.noun
119
- }
120
- end
121
-
122
- def Playershop.balance
123
- balance = 0
124
- Olib.wrap_stream('shop withdraw') { |line|
125
- next if line =~ /^Usage: SHOP WITHDRAW <amount>/
126
- raise Olib::Errors::Prempt if line =~ /^You must be in your shop to do that.$/
127
-
128
- if line =~ /Your shop's bank account is currently ([\d]+)/
129
- balance = $1.to_i
130
- raise Olib::Errors::Prempt
131
- end
132
-
133
- }
134
- return balance
135
- end
136
-
137
- def Playershop.where(conditions)
138
- Playershop.items.select { |item|
139
- !conditions.keys.map { |key|
140
- if conditions[key].class == Array
141
- item.props[key].class == Array && !conditions[key].map { |ele| item.props[key].include? ele }.include?(false)
142
- else
143
- item.props[key] == conditions[key]
144
- end
145
- }.include?(false)
146
- }
147
- end
148
-
149
- def Playershop.find_by_tags(*tags)
150
-
151
- Playershop.items.select { |item|
152
- !tags.map {|tag| item.is?(tag) }.include? false
153
- }
154
- end
155
-
156
- def Playershop.sign
157
- Shop.containers.select { |container|
158
- container.noun == 'sign'
159
- }[0]
160
- end
161
-
162
- def Playershop.items
163
- Playershop.containers.map { |container|
164
- container.contents
165
- }.flatten
166
- end
167
- end
168
- end
169
-
170
- def Olib.Playershop
171
- Olib::Shop::Playershop
172
- end
173
-
174
- def Olib.Shop
175
- Olib::Shop
176
- end
1
+ module Olib
2
+ module Shop
3
+
4
+ @@containers = []
5
+
6
+ def Shop.items
7
+ Shop.containers.map { |container| container.contents }.flatten
8
+ end
9
+
10
+ def Shop.containers
11
+ #fput "look"
12
+ @@containers = [
13
+ GameObj.loot,
14
+ GameObj.room_desc
15
+ ]
16
+ .flatten
17
+ .compact
18
+ .select { |container| !(container.name =~ /^([A-z][a-z]+ disk$)/)}
19
+ .map { |container| Shop::Container.new(container) }
20
+
21
+ @@containers
22
+
23
+ end
24
+
25
+ def Shop.cache
26
+ @@containers
27
+ end
28
+
29
+ class Container < Olib::Gameobj_Extender
30
+ attr_accessor :show, :nested, :containers, :id, :cache, :props
31
+
32
+ def to_s
33
+ info = {}
34
+ info[:name] = @name
35
+ info[:noun] = @noun
36
+ info[:props] = @props
37
+ info[:cache] = @cache
38
+ info.to_s
39
+ end
40
+
41
+ def initialize(obj)
42
+ @cache = Hash.new
43
+ @props = Hash.new
44
+ super(obj)
45
+ end
46
+
47
+ def action(verb)
48
+ "#{verb} ##{@id}"
49
+ end
50
+
51
+ def look
52
+ self
53
+ end
54
+
55
+ # detect nested containers
56
+ def at
57
+
58
+ Olib.wrap_stream(action 'look at') { |line|
59
+
60
+ raise Olib::Errors::Mundane if line =~ /You see nothing unusual/
61
+
62
+ if line =~ /Looking at the (.*?), you see (?<nested>.*)/
63
+ @nested = true
64
+
65
+ @containers = line.match(/Looking at the (.*?), you see (?<nested>.*)/)[:nested].scan(/<a exist="(?<id>.*?)" noun="(?<noun>.*?)">(?<name>.*?)<\/a>/).map {|matches|
66
+ Container.new GameObj.new *matches
67
+ }
68
+ raise Olib::Errors::Prempt
69
+ end
70
+
71
+ }
72
+
73
+ self
74
+ end
75
+
76
+ def nested?
77
+ @nested || false
78
+ end
79
+
80
+ def in
81
+ return self unless @id
82
+ Olib.wrap_stream(action 'look in') { |line|
83
+ raise Olib::Errors::Mundane if line=~ /^There is nothing in there|^That is closed|filled with a variety of garbage|Total items:/
84
+ raise Olib::Errors::Prempt if line =~ /^In the (.*?) you see/
85
+ }
86
+ self
87
+ end
88
+
89
+ def on
90
+ return self unless @id
91
+ Olib.wrap_stream(action 'look on') { |line|
92
+ raise Olib::Errors::Mundane if line =~ /^There is nothing on there/
93
+ raise Olib::Errors::Prempt if line =~ /^On the (.*?) you see/
94
+ }
95
+ self
96
+ end
97
+
98
+ def contents
99
+ look.in.on unless GameObj[@id].contents
100
+ GameObj[@id].contents.map {|i| Item.new(i).define('container', @id) }
101
+ end
102
+
103
+ def containers
104
+ @containers
105
+ end
106
+ end
107
+
108
+ class Playershop
109
+ @@noncontainers = [ "wall", "ceiling", "permit", "floor", "helmet", "snowshoes",
110
+ "candelabrum", "flowerpot", "Hearthstone", "bear", "candelabra",
111
+ "sculpture", "anvil", "tapestry", "portrait", "Wehnimer", "spiderweb",
112
+ "rug", "fountain", "longsword", "ship", "panel", "painting", "armor",
113
+ "flowers", "head", "plate", "vase", "pillows", "mask", "skeleton", "fan",
114
+ "flag", "statue", "mat", "plaque", "mandolin", "plant", "sign" ]
115
+
116
+ def Playershop.containers
117
+ Shop.containers.reject { |container|
118
+ @@noncontainers.include? container.noun
119
+ }
120
+ end
121
+
122
+ def Playershop.balance
123
+ balance = 0
124
+ Olib.wrap_stream('shop withdraw') { |line|
125
+ next if line =~ /^Usage: SHOP WITHDRAW <amount>/
126
+ raise Olib::Errors::Prempt if line =~ /^You must be in your shop to do that.$/
127
+
128
+ if line =~ /Your shop's bank account is currently ([\d]+)/
129
+ balance = $1.to_i
130
+ raise Olib::Errors::Prempt
131
+ end
132
+
133
+ }
134
+ return balance
135
+ end
136
+
137
+ def Playershop.where(conditions)
138
+ Playershop.items.select { |item|
139
+ !conditions.keys.map { |key|
140
+ if conditions[key].class == Array
141
+ item.props[key].class == Array && !conditions[key].map { |ele| item.props[key].include? ele }.include?(false)
142
+ else
143
+ item.props[key] == conditions[key]
144
+ end
145
+ }.include?(false)
146
+ }
147
+ end
148
+
149
+ def Playershop.find_by_tags(*tags)
150
+
151
+ Playershop.items.select { |item|
152
+ !tags.map {|tag| item.is?(tag) }.include? false
153
+ }
154
+ end
155
+
156
+ def Playershop.sign
157
+ Shop.containers.select { |container|
158
+ container.noun == 'sign'
159
+ }[0]
160
+ end
161
+
162
+ def Playershop.items
163
+ Playershop.containers.map { |container|
164
+ container.contents
165
+ }.flatten
166
+ end
167
+ end
168
+ end
169
+
170
+ def Olib.Playershop
171
+ Olib::Shop::Playershop
172
+ end
173
+
174
+ def Olib.Shop
175
+ Olib::Shop
176
+ end
177
177
  end