-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmapnav.lic
More file actions
166 lines (141 loc) · 5.11 KB
/
mapnav.lic
File metadata and controls
166 lines (141 loc) · 5.11 KB
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
=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 (thisgenericname@gmail.com)
game: Gemstone
tags: core
version: 0.1.1
required: Lich >= 4.2.0
changelog:
0.1.1 (2017-04-17):
fixed 'save' not terminating script
0.1 (2017-04-17):
initial release
=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} 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 =~ /^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."
exit
elsif 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}."