-
Notifications
You must be signed in to change notification settings - Fork 3
/
mapnav.lic
293 lines (259 loc) · 8.68 KB
/
mapnav.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
=begin
Navigate and map areas that mapmap can't by moving the direction specified and recording the data.
I primarily created this to map the area to Dragonspine Fane in Zul Logoth, as mapmap was getting confused by the staircases.
;mapnav help
;mapnav inspect
;mapnav climb downward stairs
author: LostRanger ([email protected])
game: Gemstone
tags: core
version: 0.1.1
required: Lich >= 4.2.0
changelog:
0.2 (2019-11-04)
added explicit room merging feature.
0.1.1 (2017-04-17):
fixed 'save' not terminating script
0.1 (2017-04-17):
initial release
=end
def do_merge(from, to)
first_room = Room[[from.to_i, to.to_i].min]
second_room = Room[[from.to_i, to.to_i].max]
second_room.title.each { |title| first_room.title.push(title) unless first_room.title.include?(title) }
second_room.description.each { |desc| first_room.description.push(desc) unless first_room.description.include?(desc) }
second_room.paths.each { |paths| first_room.paths.push(paths) unless first_room.paths.include?(paths) }
if first_room.location.nil?
first_room.location = second_room.location
end
second_room.wayto.each_pair { |adj_room,way|
unless first_room.wayto.keys.include?(adj_room)
first_room.wayto[adj_room] = way
first_room.timeto[adj_room] = second_room.timeto[adj_room]
end
}
# map_done.delete(second_room.id)
# map_pending.delete(second_room.id.to_s)
# fix_done.delete(second_room.id)
# fix_pending.delete(second_room.id.to_s)
key = second_room.id.to_s
Map.list[second_room.id] = nil
Map.list.each { |room|
if room.wayto.keys.include?(key)
room.wayto[first_room.id.to_s] = room.wayto[key]
room.timeto[first_room.id.to_s] = room.timeto[key]
room.wayto.delete(key)
room.timeto.delete(key)
end
}
Map.list.each { |room|
room.wayto.each_pair { |rm,way|
if (way.class == Proc) and way._dump =~ /#{second_room.id.to_s}/
respond
respond "#{room.id} => #{rm}"
respond way._dump
respond
clear
echo 'this path refrences the deleted room number'
echo "replace #{second_room.id} with #{first_room.id}? (send yes/no)"
respond
line = nil
line = get until line =~ /^yes$|^no$/i
if line =~ /^yes$/i
room.wayto[rm] = StringProc.new(way._dump.gsub(second_room.id.to_s, first_room.id.to_s))
end
end
}
}
#
#
# msg = []
# msg << "Will merge room #{from.to_s}"
# msg << "into room #{to.to_s}"
# msg << ""
# msg << "Afterwards, room ##{from.id} will be deleted and ##{to.id} will remain."
#
# # Find descriptions that will be merged.
# descriptions_to_add = []
# paths_to_add = []
# to_skip = 0
# rmfrom.description.each do |desc|
# if rmto.description.include?(desc)
# to_skip += 1
# else
# descriptions_to_add << desc
# end
# end
# msg << "#{to_skip.length} room description(s) already exist on the target."
# msg << "#{descriptions_to_add.length} room description(s) will be added." unless descriptions_to_add.length == 0
# rmfrom.paths.each do |desc|
# if rmto.paths.include?(desc)
# to_skip += 1
# else
# paths_to_add << desc
# end
# end
# msg <<
# msg << "#{descriptions_to_add.length} sets of obvious paths/exits already exist on the target."
#
# msg << "#{to_skip.length} room description(s) already exist."
#
#
#
#
end
command = script.vars[0].downcase
if not command or command == "help"
if not command
echo "no command specified, showing help"
end
# Code shamelessly plundered from mapmap
script_starter = "#{$lich_char}#{script.name}"
script_spacerr = ''.ljust(script_starter.length, ' ')
msg = []
msg << "This script manually updates your local map database in a simple four-step process:"
msg << " 1. Add the current room you're in (if it's not already in the DB)"
msg << " 2. Perform the specified command (e.g. GO DOOR or NORTH)"
msg << " 3. Add the room you arrive in (if it's not already in the DB)"
msg << " 4. Update the appropriate movement information for the origin room."
msg << ''
msg << "The database will not be updated if the move command fails or you otherwise end up in the same room"
msg << "that you started in."
msg << ''
msg << "Changes this script makes to your map database are not saved immediately. Use #{script_starter} SAVE"
msg << "or invoking another script that saves map changes (e.g. #{$lich_char}mapmap) will cause changes to be"
msg << "saved."
msg << ''
msg << "Usage:"
msg << ''
msg << " #{script_starter} help Shows this help text."
msg << ''
msg << " #{script_starter} inspect Inspect the current room."
msg << ''
msg << " #{script_starter} create Create current room in the map database if it doesn't exist, "
msg << " #{script_spacerr} then inspect it."
msg << ''
msg << " #{script_starter} retarget OLDID NEWID"
msg << " #{script_spacerr} Change exits in current room that point to OLD to now point to NEW"
msg << ''
msg << " #{script_starter} merge TO FROM"
msg << " #{script_spacerr} Explicitly merge duplicate room FROM into room TO."
msg << ''
msg << " #{script_starter} save Save the map database."
msg << ''
msg << " #{script_starter} MOVEMENT Execute MOVEMENT (e.g. 'go doorway') and record the result."
msg << ''
msg << "This script is not foolproof."
msg << ''
respond msg
exit
end
if command == "inspect"
current = Room.current
if current.nil?
echo "no matching room found in DB"
exit
end
echo "showing details for room ##{current.id}"
respond current.inspect
exit
end
if command == "create"
current = Room.current
if current.nil?
echo "no matching room found in DB, creating it"
current = Room.current_or_new
end
echo "showing details for room ##{current.id}"
respond current.inspect
exit
end
if command == "save"
Map.save
echo "map data saved"
exit
end
if command =~ /^merge(.*$)/
if $1 =~ /\s+(\d+)\s+(\d+)$/
rmto = Room[$1]
rmfrom = Room[$2]
unless rmto
echo "'to' room ##{$1} not found!"
exit
end
unless rmfrom
echo "'from' room ##{$2} not found!"
exit
end
echo rmto
echo rmfrom
echo "If these rooms are the same, unpause the script."
pause_script
do_merge(rmto.id, rmfrom.id)
exit
else
echo "Incorrect syntax. See help."
end
end
if command =~ /^retarget(.*)$/
if $1 =~ /\s+(\d+)\s+(\d+)$/
old = $1
new = $2
rm = Room.current
if rm.wayto[new] or rm.timeto[new]
echo "This room already has a wayto or timeto that goes to room #{new}"
exit
end
if rm.wayto[old]
rm.wayto[new] = rm.wayto[old]
echo "#{rm.id} => #{new}: wayto set to #{rm.wayto[new].inspect}"
if rm.timeto[old]
rm.timeto[new] = rm.timeto[old]
else
rm.timeto[new] = 0.2
echo "#{rm.id} => #{old}: WARNING: No timeto was set."
end
echo "#{rm.id} => #{new}: timeto set to #{rm.timeto[new].inspect}"
echo "#{rm.id} => #{old}: wayto cleared" if rm.wayto.delete(old)
echo "#{rm.id} => #{old}: timeto cleared" if rm.timeto.delete(old)
else
echo "This room does not conect to room #{old}"
end
exit
else
echo "Incorrect syntax. See help."
exit
end
end
is_direction = ["north","south","east","west","northeast","northwest","southeast","southwest","ne","nw","se","sw","out","up","down"].any?{ |dir| dir.start_with?(command) }
is_go = command.start_with?("go ", "climb ", "swim ")
if not (is_direction or is_go)
echo "suspicious command '#{command}'. You might have meant '#{$lich_char}#{script.name} help'. Trying your movement command anyways, use #{$lich_char}kill #{script.name} if navigation hangs..."
end
origin = Room.current_or_new
origin_id = String(origin.id)
move command
destination = Room.current_or_new
destination_id = String(destination.id)
if destination_id == origin_id
echo "Destination room and origin room are the same (##{origin_id}). Not recording navigation."
exit
end
old_wayto = origin.wayto[destination_id]
if old_wayto == command
echo "'#{command}' from room ##{origin_id} already goes to ##{destination_id}, no changes made."
else
if old_wayto
echo "Replacing previous wayto '#{old_wayto}'"
end
origin.wayto[destination_id] = command
if origin.timeto[destination_id].nil?
origin.timeto[destination_id] = 0.2 # Seems to be a default, not entirely certain what it does (Maybe factor in RT?)
end
echo "'#{command}' from room ##{origin_id} now goes to ##{destination_id}."
end
origin.wayto.find_all{|k, v| v == command && k != destination_id}.each do |k, v|
echo "Deleting conflicting wayto going to room #{k} (timeto=#{origin.timeto[k].inspect})"
origin.wayto.delete(k)
origin.timeto.delete(k)
end