-
Notifications
You must be signed in to change notification settings - Fork 8
/
wander.lic
294 lines (285 loc) · 11.2 KB
/
wander.lic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
=begin
Moves around by selecting the adjacent room that was visited least recently.
Stops in a room only if:
there is a live, targetable npc in the room
there are no characters in the room that aren't in your group
there is no disk in the room that belongs to someone not in your group
Use ;wander add and
;wander remove to set up boundaries to keep you in your hunting area.
Use ;wander delay <number> to set the movement delay
Use ;wander <npc1> <npc2> to stop only for specific npcs.
Use ;wander <pc> to stop for another specific character.
Use ;wander to stop for any targetable npcs.
author: Tillmen ([email protected])
game: Gemstone
tags: movement
version: 0.8
changelog:
0.8 (2015-04-29):
ignore pcs when wandering for loot
0.7 (2015-04-13):
share confluence variables with map database
0.6 (2015-04-11):
better wandering for the Elemental Confluence
0.5 (2015-04-09):
fix searching for people
0.4 (2015-04-05):
fix disk check
0.3 (2015-03-05):
added support for the Elemental Confluence
0.2 (2013-12-04):
added delay setting
allow adding/deleting multiple room ids at once
=end
CharSettings['boundary'] ||= Array.new
CharSettings['untargetable'] ||= Array.new
CharSettings['targetable'] ||= Array.new
CharSettings['delay'] ||= 1.0
$wander_rooms ||= Array.new
$mapdb_confluence_wander ||= Array.new
dirs = [ 'north', 'northeast', 'east', 'southeast', 'south', 'southwest', 'west', 'northwest' ]
reverse_dir = { 'north' => 'south', 'northeast' => 'southwest', 'east' => 'west', 'southeast' => 'northwest', 'south' => 'north', 'southwest' => 'northeast', 'west' => 'east', 'northwest' => 'southeast' }
# fixme: room numbers are for Prime only
hot_confluence_rooms = [23282, 23283, 23284, 23285, 23286, 23287, 23288, 23289, 23290, 23291, 23292, 23293, 23294, 23295, 23296, 23297, 23298, 23299, 23300, 23301, 23302, 23303, 23329, 23330, 23331, 23332, 23333, 23334]
cold_confluence_rooms = [23304, 23305, 23306, 23307, 23308, 23309, 23310, 23311, 23312, 23313, 23314, 23315, 23316, 23317, 23318, 23319, 23320, 23321, 23322, 23323, 23324, 23325, 23326, 23327, 23328]
wander = proc {
if (checkroom == '[Elemental Confluence]') and (XMLData.game == 'GSIV')
$mapdb_confluence_wayto ||= Hash.new
1.times {
start_room = Room.current
if $mapdb_confluence_wayto[start_room.id].nil?
redo if Room.current != start_room
$mapdb_confluence_wayto[start_room.id] = Hash.new
XMLData.room_exits.each { |d| $mapdb_confluence_wayto[start_room.id][d] = nil }
end
if ($mapdb_confluence_wayto[start_room.id].keys != XMLData.room_exits)
redo if Room.current != start_room
$mapdb_confluence_wayto = Hash.new
redo
end
dir = $mapdb_confluence_wayto[start_room.id].keys.find { |d| $mapdb_confluence_wayto[start_room.id][d].nil? }
if dir.nil?
dir = $mapdb_confluence_wayto[start_room.id].keys.find { |d| not $mapdb_confluence_wander.include?($mapdb_confluence_wayto[start_room.id][d]) }
end
if dir.nil?
next_id = $mapdb_confluence_wander.find { |i| $mapdb_confluence_wayto[start_room.id].values.include?(i) }
dir = $mapdb_confluence_wayto[start_room.id].keys.find { |d| $mapdb_confluence_wayto[start_room.id][d] == next_id }
end
if dir.nil?
dir = XMLData.room_exits[rand(XMLData.room_exits.length)]
end
r = move dir.dup
if r == false
# maze probably changed and XMLData.room_exits is wrong
status_tags
result = dothistimeout 'look', 5, /<compass>/
status_tags
options = result.scan(/<dir value=\"(.*?)\"/).flatten
move options[rand(options.length)]
else
end_room = Room.current
$mapdb_confluence_wander.delete(end_room.id)
$mapdb_confluence_wander.push(end_room.id)
$mapdb_confluence_wayto[start_room.id][dir] = end_room.id
if hot_confluence_rooms.include?(end_room.id)
if GameObj.loot.any? { |o| o.name == 'point of elemental tranquility' }
$mapdb_confluence_hot_tranquility = end_room.id
elsif $mapdb_confluence_hot_tranquility == end_room.id
$mapdb_confluence_hot_tranquility = nil
end
if GameObj.loot.any? { |o| o.name == 'gaping bottomless pit' }
$mapdb_confluence_hot_pit = end_room.id
elsif $mapdb_confluence_hot_pit == end_room.id
$mapdb_confluence_hot_pit = nil
end
else
if GameObj.loot.any? { |o| o.name == 'point of elemental tranquility' }
$mapdb_confluence_cold_tranquility = end_room.id
elsif $mapdb_confluence_cold_tranquility == end_room.id
$mapdb_confluence_cold_tranquility = nil
end
if GameObj.loot.any? { |o| o.name == 'gaping bottomless pit' }
$mapdb_confluence_cold_pit = end_room.id
elsif $mapdb_confluence_cold_pit == end_room.id
$mapdb_confluence_cold_pit = nil
end
end
end
}
elsif checkroom == '[Elemental Confluence]'
if $mapdb_confluence_last_dir.nil?
$mapdb_confluence_last_dir = XMLData.room_exits[rand(XMLData.room_exits.length)]
result = move $mapdb_confluence_last_dir
else
i = dirs.index(reverse_dir[$mapdb_confluence_last_dir])
8.times {
i += 1
i = i % 8
if XMLData.room_exits.include?(dirs[i])
$mapdb_confluence_last_dir = dirs[i]
break
end
}
result = move $mapdb_confluence_last_dir
end
waitrt?
if result == false
# maze probably changed and XMLData.room_exits is wrong
status_tags
result = dothistimeout 'look', 5, /<compass>/
status_tags
options = result.scan(/<dir value="(.*?)"/).flatten
$mapdb_confluence_last_dir = options[rand(options.length)]
move $mapdb_confluence_last_dir
end
else
room = Room.current
next_room_options = room.wayto.keys - CharSettings['boundary']
next_room_options.delete_if { |room_id| (room.timeto[room_id].class == Proc) and room.timeto[room_id].call.nil? }
# next_room_options.delete_if { |room_id| room.wayto[room_id] !~ /^(?:north|northeast|east|southeast|south|southwest|west|northwest|n|ne|e|se|s|sw|w|nw)$/ }
next_room = next_room_options.find_all { |r| not $wander_rooms.include?(r) }
if next_room.empty?
next_room = $wander_rooms.find { |r| next_room_options.include?(r) }
else
next_room = next_room[rand(next_room.length)]
end
$wander_rooms.delete(next_room)
$wander_rooms.push(next_room)
way = room.wayto[next_room]
wait_while { ($loot_grab_list.length.to_i > 0) or $loot_working }
if way.class == String
move(way)
else
way.call
end
end
}
if script.vars[1] =~ /help/i
output = "\n"
output.concat ";wander add adds the current room to the boundary list\n"
output.concat ";wander add <room id> adds the given room id to the boundary list\n"
output.concat ";wander rem deletes the current room to the boundary list\n"
output.concat ";wander rem <room id> deletes the given room id to the boundary list\n"
output.concat ";wander clear clears the boundary list and npc info\n"
output.concat ";wander delay <seconds> sets the delay before moving to the next room\n"
output.concat ";wander list shows saved boundaries and npc info\n"
output.concat ";wander <npc1> <npc2> wanders around, stopping only for the given npcs\n"
output.concat ";wander wanders around, stopping only for targetable npcs\n"
output.concat "\n"
respond output
elsif script.vars[1] =~ /^add$|^set$/i
if script.vars[2]
for var in script.vars[2..-1]
if var =~ /^[0-9]+$/
CharSettings['boundary'].push(var)
echo "room #{var} has been added to the boundary list"
else
echo "ignoring #{var}: not a room id"
end
end
elsif room = Room.current
CharSettings['boundary'].push(room.id.to_s)
echo "this room (#{room.id}) has been added to the boundary list"
else
echo 'error: current room is uknown'
end
elsif script.vars[1] =~ /^del(?:ete)?$|^rem(?:ove)?$/i
if script.vars[2]
for var in script.vars[2..-1]
if var =~ /^[0-9]+$/
if CharSettings['boundary'].delete(var)
echo "room #{var} has been removed from the boundary list"
else
echo "room #{var} was not found in the boundary list"
end
else
echo "ignoring #{var}: not a room id"
end
end
elsif room = Room.current
if CharSettings['boundary'].delete(room.id.to_s)
echo "this room (#{room.id}) has been removed from the boundary list"
else
echo "this room (#{room.id}) was not found in the boundary list"
end
else
echo 'current room is uknown'
end
elsif (script.vars[1] =~ /^delay$/i) and (script.vars[2] =~ /^[0-9\.]+$/)
CharSettings['delay'] = script.vars[2].to_f
echo "movement delay is now #{CharSettings['delay']}"
elsif script.vars[1] =~ /^list$/i
output = "\n"
if CharSettings['boundary'].empty?
output.concat " boundaries: none\n"
else
output.concat " boundaries:\n"
for boundary in CharSettings['boundary']
output.concat " #{boundary.to_s.rjust(5)} #{Room[boundary].title.first}\n"
end
end
output.concat "\n"
if CharSettings['targetable'].empty?
output.concat " targetable npcs: none\n"
else
output.concat " targetable npcs: #{CharSettings['targetable'].join(', ')}\n"
end
output.concat "\n"
if CharSettings['untargetable'].empty?
output.concat " untargetable npcs: none\n"
else
output.concat " untargetable npcs: #{CharSettings['untargetable'].join(', ')}\n"
end
output.concat "\n"
respond output
elsif script.vars[1] =~ /^clear$/i
CharSettings['boundary'] = Array.new
CharSettings['untargetable'] = Array.new
CharSettings['targetable'] = Array.new
respond 'done'
elsif script.vars.empty?
loop {
group = checkpcs.to_a
wander.call
group = group & checkpcs.to_a
group.push(Char.name)
start_npcs = npcs = GameObj.npcs
npcs.delete_if { |npc| (npc.status =~ /dead/) or CharSettings['untargetable'].include?(npc.name) }
if ((checkpcs.to_a - group).length > 0) or GameObj.loot.find { |obj| (obj.noun == 'disk') and (obj.name !~ /#{group.join('|')}/) } or npcs.nil? or npcs.empty?
sleep CharSettings['delay']
elsif npcs.any? { |npc| CharSettings['targetable'].include?(npc.name) }
break
else
clear
target_result = dothistimeout 'target random', 5, /^Could not find a valid target\.$|^You are now targeting/
if target_result =~ /^You are now targeting \w+ (.*)\.$/
target = $1
CharSettings['targetable'].push(target) unless CharSettings['targetable'].include?(target)
break
elsif target_result == 'Could not find a valid target.'
if GameObj.npcs == start_npcs
npcs.each { |npc| CharSettings['untargetable'].push(npc.name) unless CharSettings['untargetable'].include?(npc.name) }
end
sleep CharSettings['delay']
end
end
}
else
loop {
group = checkpcs.to_a
wander.call
group = group & checkpcs.to_a
group.push(Char.name)
if GameObj.pcs.any? { |pc| pc.noun =~ /#{script.vars[1..-1].join('|')}/i }
break
elsif GameObj.loot.any? { |loot| loot.name =~ /#{script.vars[1..-1].join('|')}/ }
break
elsif ((checkpcs.to_a - group).length > 0) or GameObj.loot.find { |obj| (obj.noun == 'disk') and (obj.name !~ /#{group.join('|')}/) }
sleep CharSettings['delay']
elsif GameObj.npcs.any? { |npc| (npc.status != 'dead') and npc.name =~ /#{script.vars[1..-1].join('|')}/ }
break
else
sleep CharSettings['delay']
end
}
end