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,57 +1,62 @@
1
- # a collection for managing all of the creatures in a room
2
- module Olib
3
- class Creatures
4
-
5
- def Creatures.first
6
- all.first
7
- end
8
-
9
- def Creatures.all
10
- GameObj.npcs
11
- .map { |creature| Olib::Creature.new(creature) }
12
- .select { |creature| !creature.dead? }
13
- .select { |creature| !creature.ignorable? }
14
- .select { |creature| !creature.tags.include?('animate') }
15
- .select { |creature| !creature.gone? } || []
16
- end
17
-
18
- def Creatures.each(&block)
19
- all.each(&block)
20
- end
21
-
22
- def Creatures.[](exp)
23
- regexp = exp.class == String ? /#{exp}/ : exp
24
-
25
- all.select { |creature| creature.name =~ regexp || creature.id == exp }
26
- end
27
-
28
- def Creatures.filter(&block);
29
- all.select(&block)
30
- end
31
-
32
- def Creatures.bandits; all.select { |creature| creature.is?('bandit') } ;end;
33
- def Creatures.ignoreable; all.select { |creature| creature.is?('ignoreable') } ;end;
34
- def Creatures.flying; all.select { |creature| creature.is?('flying') } ;end;
35
- def Creatures.living; all.select { |creature| creature.is?('living') } ;end;
36
- def Creatures.antimagic; all.select { |creature| creature.is?('antimagic') } ;end;
37
- def Creatures.undead; all.select { |creature| creature.is?('undead') } ;end;
38
-
39
- def Creatures.grimswarm; all.select { |creature| creature.is?('grimswarm') } ;end;
40
- def Creatures.invasion; all.select { |creature| creature.is?('invasion') } ;end;
41
- def Creatures.escortees; GameObj.npcs.map {|creature| Creature.new(creature) }.select {|creature| creature.is?('escortee') } ;end;
42
-
43
- def Creatures.stunned; all.select(&:stunned?) ;end;
44
- def Creatures.active; all.select(&:active?) ;end;
45
- def Creatures.dead; all.select(&:dead?) ;end;
46
- def Creatures.prone; all.select(&:prone?) ;end;
47
-
48
- def Creatures.ambushed?
49
- last_line = $_SERVERBUFFER_.reverse.find { |line| line =~ /<pushStream id='room'\/>|An? .*? fearfully exclaims, "It's an ambush!"|#{Olib::Dictionary.bandit_traps.values.join('|')}/ }
50
- echo "detected ambush..." if !last_line.nil? && last_line !~ /pushStream id='room'/
51
-
52
- !last_line.nil? && last_line !~ /pushStream id='room'/
53
- end
54
-
55
-
56
- end
1
+ # a collection for managing all of the creatures in a room
2
+ module Olib
3
+ class Creatures
4
+ def Creatures.first
5
+ all.first
6
+ end
7
+
8
+ def Creatures.all
9
+ GameObj.npcs
10
+ .map { |creature| Creature.new(creature) }
11
+ .select { |creature| !creature.dead? }
12
+ .select { |creature| !creature.ignorable? }
13
+ .select { |creature| !creature.tags.include?('animate') }
14
+ .select { |creature| !creature.gone? } || []
15
+ end
16
+
17
+ def Creatures.each(&block)
18
+ all.each(&block)
19
+ end
20
+
21
+ def Creatures.[](exp)
22
+ regexp = exp.class == String ? /#{exp}/ : exp
23
+
24
+ filter { |creature| creature.name =~ regexp || creature.id == exp }
25
+ end
26
+
27
+ def Creatures.filter(&block);
28
+ all.select(&block)
29
+ end
30
+
31
+ def Creatures.bandits; filter { |creature| creature.is?('bandit') } ;end;
32
+ def Creatures.ignoreable; filter { |creature| creature.is?('ignoreable') };end;
33
+ def Creatures.flying; filter { |creature| creature.is?('flying') } ;end;
34
+ def Creatures.living; filter { |creature| creature.is?('living') } ;end;
35
+ def Creatures.antimagic; filter { |creature| creature.is?('antimagic') } ;end;
36
+ def Creatures.undead; filter { |creature| creature.is?('undead') } ;end;
37
+
38
+ def Creatures.grimswarm; filter { |creature| creature.is?('grimswarm') } ;end;
39
+ def Creatures.invasion; filter { |creature| creature.is?('invasion') } ;end;
40
+
41
+ def Creatures.escortees
42
+ GameObj.npcs
43
+ .map {|creature| Creature.new(creature) }
44
+ .select {|creature| creature.is?('escortee') }
45
+ end
46
+
47
+ def Creatures.stunned; all.select(&:stunned?) ;end;
48
+ def Creatures.active; all.select(&:active?) ;end;
49
+ def Creatures.dead; all.select(&:dead?) ;end;
50
+ def Creatures.prone; all.select(&:prone?) ;end;
51
+
52
+ def Creatures.ambushed?
53
+ last_line = $_SERVERBUFFER_.reverse.find { |line| line =~ /<pushStream id='room'\/>|An? .*? fearfully exclaims, "It's an ambush!"|#{Olib::Dictionary.bandit_traps.values.join('|')}/ }
54
+ echo "detected ambush..." if !last_line.nil? && last_line !~ /pushStream id='room'/
55
+
56
+ !last_line.nil? && last_line !~ /pushStream id='room'/
57
+ end
58
+ end
59
+ end
60
+
61
+ class Creatures < Olib::Creatures
57
62
  end
@@ -1,149 +1,201 @@
1
- # for defining containers ala lootsack and using them across scripts
2
-
3
- require 'Olib/core/extender'
4
-
5
- class String
6
- def to_class
7
- Kernel.const_get self
8
- rescue NameError
9
- nil
10
- end
11
-
12
- def is_a_defined_class?
13
- true if self.to_class
14
- rescue NameError
15
- false
16
- end
17
- end
18
-
19
- module Olib
20
- class Container < Gameobj_Extender
21
- attr_accessor :ref
22
-
23
- def initialize(id=nil)
24
- # extract the class name to attempt to lookup the item by your settings
25
- # ex: class Lootsack
26
- # ex: class Gemsack
27
- name = if self.class.name.include?("::") then self.class.name.downcase.split('::').last.strip else self.class.name.downcase end
28
- candidates = Olib.Inventory[Vars[name]]
29
- raise Olib::Errors::DoesntExist.new("#{name} could not be initialized are you sure you:\n ;var set #{name}=<something>") if candidates.empty? && id.nil?
30
-
31
- @ref = GameObj[id] || candidates.first
32
-
33
- unless GameObj[@ref.id].contents
34
- tops = [
35
- 'table'
36
- ]
37
-
38
- action = tops.include?(@ref.noun) ? "look on ##{@ref.id}" : "look in ##{@ref.id}"
39
-
40
- fput action
41
- end
42
-
43
- super @ref
44
-
45
- end
46
-
47
- def contents
48
- GameObj[@ref.id].contents.map{ |item| Item.new(item) }
49
- end
50
-
51
- def where(conditions)
52
- contents.select { |item|
53
- !conditions.keys.map { |key|
54
- if conditions[key].class == Array
55
- item.props[key].class == Array && !conditions[key].map { |ele| item.props[key].include? ele }.include?(false)
56
- else
57
- item.props[key] == conditions[key]
58
- end
59
- }.include?(false)
60
- }
61
- end
62
-
63
- def find_by_tags(*tags)
64
- contents.select { |item|
65
- !tags.map {|tag| item.is?(tag) }.include? false
66
- }
67
- end
68
-
69
-
70
- def [](query)
71
- return contents.select do |item|
72
- item if (item.type =~ query || item.noun =~ query || item.name =~ query)
73
- end
74
- end
75
-
76
- def
77
-
78
- def __verbs__
79
- @verbs = 'open close analyze inspect weigh'.split(' ').map(&:to_sym)
80
- singleton = (class << self; self end)
81
- @verbs.each do |verb|
82
- singleton.send :define_method, verb do
83
- fput "#{verb.to_s} ##{@id}"
84
- self
85
- end
86
- end
87
- end
88
-
89
- def gems
90
- find_by_tags('gem')
91
- end
92
-
93
- def magic_items
94
- find_by_tags('magic')
95
- end
96
-
97
- def jewelry
98
- find_by_tags('jewelry')
99
- end
100
-
101
- def skins
102
- find_by_tags('skin')
103
- end
104
-
105
- def boxes
106
- find_by_tags('boxes')
107
- end
108
-
109
- def scrolls
110
- find_by_tags('scroll')
111
- end
112
-
113
- def full?
114
- is? 'full'
115
- end
116
-
117
- def add(item)
118
- result = Olib.do "_drag ##{item.id} ##{@id}", /#{[Olib::Dictionary.put[:success], Olib::Dictionary.put[:failure].values].flatten.join('|')}/
119
- tag 'full' if result =~ /won't fit in the/
120
- self
121
- end
122
- end
123
-
124
- class Lootsack < Container
125
-
126
- end
127
-
128
- def Olib.Lootsack
129
- return @@lootsack if @@lootsack
130
- @@lootsack = Lootsack.new
131
- @@lootsack
132
- end
133
-
134
- end
135
-
136
- module Containers
137
- @@containers = {}
138
-
139
- def Containers.define(name)
140
- @@containers[name] = Object.const_set(name.capitalize, Class.new(Olib::Container)).new
141
- @@containers[name]
142
- end
143
-
144
- def Containers.method_missing(name)
145
- return @@containers[name] if @@containers[name]
146
- return Containers.define(name)
147
- end
148
-
1
+ # for defining containers ala lootsack and using them across scripts
2
+
3
+ require 'Olib/core/extender'
4
+
5
+ class String
6
+ def to_class
7
+ Kernel.const_get self
8
+ rescue NameError
9
+ nil
10
+ end
11
+
12
+ def is_a_defined_class?
13
+ true if self.to_class
14
+ rescue NameError
15
+ false
16
+ end
17
+ end
18
+
19
+ module Olib
20
+ class Container < Gameobj_Extender
21
+ attr_accessor :ref, :nested, :containers, :ontop
22
+
23
+ def initialize(id=nil)
24
+ # extract the class name to attempt to lookup the item by your settings
25
+ # ex: class Lootsack
26
+ # ex: class Gemsack
27
+ name = if self.class.name.include?("::") then self.class.name.downcase.split('::').last.strip else self.class.name.downcase end
28
+ candidates = Olib.Inventory[Vars[name]]
29
+ raise Olib::Errors::DoesntExist.new("#{name} could not be initialized are you sure you:\n ;var set #{name}=<something>") if candidates.empty? && id.nil?
30
+
31
+ @ref = GameObj[id] || candidates.first
32
+ @ontop = Array.new
33
+
34
+ unless GameObj[@ref.id].contents
35
+ tops = [
36
+ 'table'
37
+ ]
38
+
39
+ action = tops.include?(@ref.noun) ? "look on ##{@ref.id}" : "look in ##{@ref.id}"
40
+
41
+ fput action
42
+ end
43
+
44
+ super @ref
45
+
46
+ end
47
+
48
+ def contents
49
+ [
50
+ @ontop,
51
+ GameObj[@ref.id].contents.map { |item| Item.new(item) }
52
+ ].flatten
53
+ end
54
+
55
+ def where(conditions)
56
+ contents.select { |item|
57
+ !conditions.keys.map { |key|
58
+ if conditions[key].class == Array
59
+ item.props[key].class == Array && !conditions[key].map { |ele| item.props[key].include? ele }.include?(false)
60
+ else
61
+ item.props[key] == conditions[key]
62
+ end
63
+ }.include?(false)
64
+ }
65
+ end
66
+
67
+ def find_by_tags(*tags)
68
+ contents.select { |item|
69
+ !tags.map {|tag| item.is?(tag) }.include? false
70
+ }
71
+ end
72
+
73
+
74
+ def [](query)
75
+ return contents.select do |item|
76
+ item if (item.type =~ query || item.noun =~ query || item.name =~ query)
77
+ end
78
+ end
79
+
80
+ def
81
+
82
+ def __verbs__
83
+ @verbs = 'open close analyze inspect weigh'.split(' ').map(&:to_sym)
84
+ singleton = (class << self; self end)
85
+ @verbs.each do |verb|
86
+ singleton.send :define_method, verb do
87
+ fput "#{verb.to_s} ##{@id}"
88
+ self
89
+ end
90
+ end
91
+ end
92
+
93
+ def at
94
+ Olib.wrap_stream("look at ##{@id}") { |line|
95
+ if line =~ /You see nothing unusual|prompt time|You gaze through (.*?) and see...|written/
96
+ raise Olib::Errors::Mundane
97
+ end
98
+
99
+ if line =~ /Looking at the (.*?), you see (?<nested>.*)/
100
+ @nested = true
101
+
102
+ @containers = line
103
+ .match(/Looking at the (.*?), you see (?<nested>.*)/)[:nested]
104
+ .scan(/<a exist="(?<id>.*?)" noun="(?<noun>.*?)">(?<name>.*?)<\/a>/)
105
+ .map {|matches| Container.new GameObj.new *matches }
106
+ raise Olib::Errors::Mundane
107
+ end
108
+
109
+ }
110
+ self
111
+ end
112
+
113
+ def look
114
+ self
115
+ end
116
+
117
+ def on
118
+ return self unless @id
119
+ Olib.wrap_stream("look on ##{@id}") { |line|
120
+ raise Olib::Errors::Mundane if line =~ /There is nothing on there|prompt time/
121
+ if line =~ /On the (.*?) you see/
122
+ @ontop << line.match(Dictionary.contents)[:items]
123
+ .scan(Dictionary.tag)
124
+ .map {|matches| Item.new GameObj.new *matches }
125
+ raise Olib::Errors::Mundane
126
+ end
127
+ next
128
+ }
129
+ self
130
+ end
131
+
132
+ def in
133
+ fput "look in ##{@id}"
134
+ self
135
+ end
136
+
137
+ def nested?
138
+ @nested
139
+ end
140
+
141
+ def gems
142
+ find_by_tags('gem')
143
+ end
144
+
145
+ def magic_items
146
+ find_by_tags('magic')
147
+ end
148
+
149
+ def jewelry
150
+ find_by_tags('jewelry')
151
+ end
152
+
153
+ def skins
154
+ find_by_tags('skin')
155
+ end
156
+
157
+ def boxes
158
+ find_by_tags('boxes')
159
+ end
160
+
161
+ def scrolls
162
+ find_by_tags('scroll')
163
+ end
164
+
165
+ def full?
166
+ is? 'full'
167
+ end
168
+
169
+ def add(item)
170
+ result = Olib.do "_drag ##{item.id} ##{@id}", /#{[Olib::Dictionary.put[:success], Olib::Dictionary.put[:failure].values].flatten.join('|')}/
171
+ tag 'full' if result =~ /won't fit in the/
172
+ self
173
+ end
174
+ end
175
+
176
+ class Lootsack < Container
177
+
178
+ end
179
+
180
+ def Olib.Lootsack
181
+ return @@lootsack if @@lootsack
182
+ @@lootsack = Lootsack.new
183
+ @@lootsack
184
+ end
185
+
186
+ end
187
+
188
+ module Containers
189
+ @@containers = {}
190
+
191
+ def Containers.define(name)
192
+ @@containers[name] = Object.const_set(name.capitalize, Class.new(Olib::Container)).new
193
+ @@containers[name]
194
+ end
195
+
196
+ def Containers.method_missing(name)
197
+ return @@containers[name] if @@containers[name]
198
+ return Containers.define(name)
199
+ end
200
+
149
201
  end