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 +4 -4
- data/Olib.gemspec +17 -16
- data/README.md +23 -21
- data/TODOS.md +3 -3
- data/lib/Olib.rb +88 -50
- data/lib/Olib/area.rb +51 -0
- data/lib/Olib/bounty.rb +171 -128
- data/lib/Olib/character/char.rb +113 -118
- data/lib/Olib/character/group.rb +68 -67
- data/lib/Olib/character/inventory.rb +79 -79
- data/lib/Olib/character/mind.rb +70 -0
- data/lib/Olib/combat/creature.rb +255 -249
- data/lib/Olib/combat/creatures.rb +61 -56
- data/lib/Olib/core/container.rb +200 -148
- data/lib/Olib/core/errors.rb +91 -91
- data/lib/Olib/core/extender.rb +27 -19
- data/lib/Olib/core/item.rb +549 -549
- data/lib/Olib/core/utils.rb +220 -220
- data/lib/Olib/dictionary/dictionary.rb +165 -157
- data/lib/Olib/events/emitter.rb +7 -0
- data/lib/Olib/go2.rb +151 -0
- data/lib/Olib/npcs.rb +5 -0
- data/lib/Olib/objects/box.rb +3 -3
- data/lib/Olib/objects/clothing.rb +3 -3
- data/lib/Olib/objects/herb.rb +3 -3
- data/lib/Olib/objects/jar.rb +100 -100
- data/lib/Olib/objects/jewel.rb +34 -34
- data/lib/Olib/objects/jewelry.rb +9 -9
- data/lib/Olib/objects/scroll.rb +71 -71
- data/lib/Olib/objects/uncommon.rb +3 -3
- data/lib/Olib/objects/unknown.rb +3 -3
- data/lib/Olib/objects/wand.rb +3 -3
- data/lib/Olib/shops.rb +176 -176
- data/lib/Olib/utils/cli.rb +80 -80
- data/lib/Olib/utils/help_menu.rb +166 -166
- data/lib/Olib/utils/monsterbold.rb +4 -4
- data/lib/Olib/utils/vbulletin.rb +100 -100
- data/lib/Olib/version.rb +3 -0
- metadata +11 -7
- data/lib/Olib/transport.rb +0 -117
- data/lib/Olib/utils/utils.rb +0 -148
@@ -1,57 +1,62 @@
|
|
1
|
-
# a collection for managing all of the creatures in a room
|
2
|
-
module Olib
|
3
|
-
class Creatures
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
.
|
12
|
-
.select { |creature| !creature.
|
13
|
-
.select { |creature| !creature.
|
14
|
-
.select { |creature| !creature.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def Creatures.
|
33
|
-
def Creatures.
|
34
|
-
def Creatures.
|
35
|
-
def Creatures.
|
36
|
-
def Creatures.
|
37
|
-
|
38
|
-
|
39
|
-
def Creatures.
|
40
|
-
|
41
|
-
def Creatures.escortees
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def Creatures.
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
data/lib/Olib/core/container.rb
CHANGED
@@ -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
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
def
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
def
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
def
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|