· 6 years ago · Mar 05, 2019, 11:54 PM
1<?xml version="1.0" encoding="iso-8859-1"?>
2<!DOCTYPE muclient [
3 <!ENTITY show_vnums "true" >
4 <!ENTITY show_timing "false" >
5 <!ENTITY show_completed "false" >
6 <!ENTITY show_database_mods "true" >
7 <!ENTITY show_other_areas "false" >
8 <!ENTITY show_area_exits "false" >
9 <!ENTITY show_up_down "false" >
10 <!ENTITY two_way_exits "true" >
11 <!ENTITY speedwalk_prefix "" >
12]>
13
14<muclient>
15<plugin
16 name="AAMAPTEST"
17 id="eb8024bd7716677c072f553d"
18 language="Lua"
19 purpose="automapper test"
20 save_state="y"
21 date_written="2019-03-04"
22 requires="4.61"
23 >
24
25 <description trim="y">
26<![CDATA[
27
28]]>
29</description>
30
31</plugin>
32
33<triggers>
34
35 <trigger
36 enabled="y"
37 match="^kxwt_rvnum (?P<roomnum>[0-9-]+)$"
38 regexp="y"
39 name="Rvnum_Line"
40 script="Rvnum_Line"
41 sequence="90"
42 >
43 </trigger>
44
45 <trigger
46 enabled="y"
47 match="^kxwt_terrain (?P<terrain>[0-9-]+)$"
48 regexp="y"
49 script="Terrain_Line"
50 sequence="100"
51 >
52 </trigger>
53
54 <trigger
55 enabled="y"
56 match="^kxwt_rshort (?P<roomname>[^\r\n]*)"
57 regexp="y"
58 script="Name_Line"
59 sequence="100"
60 >
61 </trigger>
62
63 <trigger
64 enabled="y"
65 match="^kxwt_area (?P<areanum>[0-9-]+) (?P<areaname>[^\r\n]*)$"
66 regexp="y"
67 script="Area_Line"
68 sequence="100"
69 >
70 </trigger>
71
72 <trigger
73 enabled="y"
74 match="^kxwt_walkdir ((?P<walkdir>[0-9]+)|You begin your climb (?P<climbdir>.+)ward.)"
75 regexp="y"
76 script="Direction_Line"
77 sequence="100"
78 >
79 </trigger>
80
81 <trigger
82 enabled="y"
83 match="[Exits: *]"
84 script="Exit_Line"
85 sequence="100"
86 text_colour="9"
87 >
88 </trigger>
89
90</triggers>
91
92<aliases>
93
94 <alias
95 script="show_this_room"
96 match="msr"
97 enabled="y"
98 >
99</alias>
100
101</aliases>
102
103<script>
104
105local show_vnums = &show_vnums;
106local show_timing = &show_timing;
107local show_completed = &show_completed;
108local show_database_mods = &show_database_mods;
109local show_other_areas = &show_other_areas;
110local show_up_down = &show_up_down;
111local show_area_exits = &show_area_exits;
112local two_way_exits = &two_way_exits;
113local speedwalk_prefix = "&speedwalk_prefix;"
114
115<![CDATA[
116
117mapper = require "mapper"
118require "serialize"
119require "copytable"
120
121rooms = { }
122areas = { }
123
124local valid_direction = {
125 n = "n",
126 s = "s",
127 e = "e",
128 w = "w",
129 u = "u",
130 d = "d",
131 ne = "ne",
132 sw = "sw",
133 nw = "nw",
134 se = "se",
135 north = "n",
136 south = "s",
137 east = "e",
138 west = "w",
139 up = "u",
140 down = "d",
141 northeast = "ne",
142 northwest = "nw",
143 southeast = "se",
144 southwest = "sw",
145 ['in'] = "in",
146 out = "out",
147 } -- end of valid_direction
148
149-- for calculating the way back
150local inverse_direction = {
151 n = "s",
152 s = "n",
153 e = "w",
154 w = "e",
155 u = "d",
156 d = "u",
157 ne = "sw",
158 sw = "ne",
159 nw = "se",
160 se = "nw",
161 ['in'] = "out",
162 out = "in",
163 } -- end of inverse_direction
164---------------------------------------------
165function Rvnum_Line (name, line, wildcards)
166
167 roomnum = tonumber(wildcards["roomnum"])
168
169 EnableTrigger ("Terrain_Line", true)
170 EnableTrigger ("Rvnum_Line", false)
171
172end -- Rvnum_Line
173---------------------------------------------
174function Terrain_Line (name,line, wildcards)
175
176 replacements = {
177 ["0"] = "NOTSET",
178 ["1"] = "BUILDING",
179 ["2"] = "TOWN",
180 ["3"] = "FIELD",
181 ["4"] = "LFOREST",
182 ["5"] = "TFOREST",
183 ["6"] = "DFOREST",
184 ["7"] = "SWAMP",
185 ["8"] = "PLATEAU",
186 ["9"] = "SANDY",
187 ["10"] = "MOUNTAIN",
188 ["11"] = "ROCK",
189 ["12"] = "DESERT",
190 ["13"] = "TUNDRA",
191 ["14"] = "BEACH",
192 ["15"] = "HILL",
193 ["16"] = "DUNE",
194 ["17"] = "JUNGLE",
195 ["18"] = "OCEAN",
196 ["19"] = "STREAM",
197 ["20"] = "RIVER",
198 ["21"] = "UNDERWATER",
199 ["22"] = "UNDERGROUND",
200 ["23"] = "AIR",
201 ["24"] = "ICE",
202 ["25"] = "LAVA",
203 ["26"] = "RUINS",
204 ["27"] = "CAVE",
205 ["28"] = "CITY",
206 ["29"] = "MARSH",
207 ["30"] = "WASTELAND",
208 ["31"] = "CLOUD",
209 ["32"] = "WATER",
210 }
211 terrain = string.gsub (wildcards[1], "%d+",
212 function (str)
213 return replacements [str]
214 end
215 )
216
217 EnableTrigger ("Name_Line", true)
218 EnableTrigger ("Terrain_Line", false)
219
220end --Terrain_Line
221----------------------------------------------
222function Name_Line (name, line, wildcards)
223
224 roomname = wildcards["roomname"]
225
226 EnableTrigger ("Area_Line", true)
227 EnableTrigger ("Name_Line", false)
228
229 end -- Name_Line
230-------------------------------------------
231 function Area_Line (name, line, wildcards)
232
233 areanum = tonumber(wildcards["areanum"])
234 areaname = wildcards["areaname"]
235
236 uid = (string.format("%s.%s", areanum, roomnum))
237
238 if not rooms [uid] then
239 rooms [uid] = { name = roomname, exits = {} }
240 end -- if
241
242 if uid ~= current_room
243 and current_room
244 and last_direction_moved then
245 -- previous room led here
246 rooms [current_room].exits [last_direction_moved] = uid
247 -- assume inverse direction leads back
248 rooms [uid].exits [inverse_direction [last_direction_moved]] = current_room
249 end -- if
250
251 current_room = uid
252
253 local room = rooms [current_room]
254
255 if not room then
256 room = load_room_from_database (current_room)
257 end -- not in cache
258
259 if not room then
260 print ("Added room", uid)
261 print ("Name", roomname)
262
263 db:exec ("BEGIN TRANSACTION;")
264
265 save_room_to_database (current_room, roomname)
266 save_exits_to_database (current_room, string.lower(exits_str))
267
268 db:exec ("COMMIT;")
269
270 room = load_room_from_database (current_room)
271
272 end -- if room not there
273
274 -- draw this room
275 mapper.draw (current_room)
276
277 EnableTrigger ("Direction_Line", true)
278 EnableTrigger ("Area_Line", false)
279
280end -- Area_Line
281----------------------------------------------------------
282
283function Direction_Line (name, line, wildcards)
284
285 replacements = {
286 ["0"] = "N",
287 ["1"] = "E",
288 ["2"] = "S",
289 ["3"] = "W",
290 ["4"] = "NE",
291 ["5"] = "SE",
292 ["6"] = "SW",
293 ["7"] = "NW",
294 ["20"] = "U",
295 ["30"] = "D",
296 }
297 walkdir = string.gsub (wildcards[1], "%d+",
298 function (str)
299 return replacements [str]
300 end
301
302 )
303
304-- print ("Walkdir = ", walkdir)
305
306climbdir = wildcards["climbdir"]
307
308
309 EnableTrigger ("Exit_Line", true)
310 EnableTrigger ("Direction_Line", false)
311
312 end--Direction_Line
313 ---------------------------------------------------------
314function Exit_Line (name, line, wildcards)
315
316 EnableTrigger ("Direction_Line", false)
317
318 replacements = {
319 ["south"] = "S",
320 ["north"] = "N",
321 ["east"] = "E",
322 ["west"] = "W",
323 ["down"] = "D",
324 ["up"] = "U",
325 ["northeast"] = "NE",
326 ["northwest"] = "NW",
327 ["southeast"] = "SE",
328 ["southwest"] = "SW",
329 }
330 exits = string.gsub (wildcards[1], "%a+",
331 function (str)
332 return replacements [str]
333 end
334 )
335
336-- print ("Exits = ", exits)
337
338 EnableTrigger ("Rvnum_Line", true)
339 EnableTrigger ("Description_Line", false)
340 EnableTrigger ("Exit_Line", false)
341
342end -- Exit_Line
343
344-- -----------------------------------------------------------------
345-- mapper 'get_room' callback - it wants to know about room uid
346-- -----------------------------------------------------------------
347function get_room (uid)
348
349 room = rooms [uid]
350 if not room then
351 return nil
352 end -- if not found
353
354 -- look it up
355 local ourroom = rooms [uid]
356
357 -- not cached - see if in database
358 if not ourroom then
359 ourroom = load_room_from_database (uid)
360 rooms [uid] = ourroom -- cache for later
361 end -- not in cache
362
363 if not ourroom then
364 return nil
365 end -- if
366
367 local room = copytable.deep (ourroom)
368
369 room.area = areaname
370
371 -- build hover message
372
373 local texits = {}
374 for dir in pairs (room.exits) do
375 table.insert (texits, dir)
376 end -- for
377 table.sort (texits)
378
379room.hovermessage = string.format (
380 "%s\tExits: %s\nRoom: %s\n%s",
381 room.name,
382 table.concat (texits, ", "),
383 uid,
384 terrain
385 -- depth,
386 -- table.concat (path, ",")
387 )
388
389 if uid == current_room then
390 room.bordercolour = ColourNameToRGB "red"
391 room.borderpenwidth = 2
392 end -- not in this area
393
394 return room
395end -- get_room
396
397function show_this_room (name, line, wildcards)
398 local room = rooms[current_room]
399 if room ~= nil then
400 Note("Details about this room:")
401 Note("Name: "..(room.name or ""))
402 Note("ID: "..(current_room or ""))
403 Note("Area: "..(areaname or ""))
404 Note("Terrain: "..(terrain or ""))
405
406 end
407end -- show_this_room
408-------------------------------------------------
409function create_tables ()
410 -- create rooms table
411 dbcheck (db:execute[[
412
413 PRAGMA foreign_keys = ON;
414 PRAGMA journal_mode = WAL;
415
416 CREATE TABLE IF NOT EXISTS areas (
417 areaid INTEGER PRIMARY KEY AUTOINCREMENT,
418 areanum TEXT NOT NULL CHECK (area_num <> %s),
419 areaname TEXT NOT NULL DEFAULT %s,
420 instance INTEGER NOT NULL DEFAULT 0,
421 areanotes TEXT,
422 date_added DATE NOT NULL DEFAULT CURRENT_TIMESTAMP,
423 PRIMARY KEY (area_num)
424 );
425
426 CREATE TABLE IF NOT EXISTS rooms (
427 roomid INTEGER PRIMARY KEY AUTOINCREMENT,
428 uid TEXT NOT NULL,
429 roomname TEXT,
430 areanum TEXT NOT NULL,
431 terrain TEXT,
432 notes TEXT,
433 date_added DATE,
434 UNIQUE (uid)
435 FOREIGN KEY(area) REFERENCES areas(uid)
436 );
437
438 CREATE INDEX IF NOT EXISTS rname_index ON rooms (roomname);
439 CREATE INDEX IF NOT EXISTS area_index ON rooms (area);
440 CREATE INDEX IF NOT EXISTS terrain_index ON rooms (terrain);
441 CREATE INDEX IF NOT EXISTS notes_index ON rooms (notes);
442
443 CREATE TABLE IF NOT EXISTS exits (
444 exitid INTEGER PRIMARY KEY AUTOINCREMENT,
445 dir TEXT NOT NULL,
446 climb INTEGER NOT NULL DEFAULT 0 CHECK (climb = 0 OR climb = 1) --1 if climbing required
447 fromuid STRING NOT NULL,
448 touid STRING NOT NULL,
449 date_added DATE
450 PRIMARY KEY(fromuid, dir),
451 FOREIGN KEY(fromuid) REFERENCES rooms(uid)
452 );
453 CREATE INDEX IF NOT EXISTS fromuid_index ON exits (fromuid);
454 CREATE INDEX IF NOT EXISTS touid_index ON exits (touid);
455
456 ]])
457
458end -- function create_tables
459-------------------------------------------------------
460function OnPluginInstall ()
461
462 config = {} -- in case not found
463
464 mapper.init {
465 config = config,
466 get_room = get_room,
467 show_help = OnHelp,
468 room_click = room_click,
469 show_completed = show_completed,
470 show_other_areas = show_other_areas,
471 show_up_down = show_up_down,
472 show_area_exits = show_area_exits,
473 speedwalk_prefix = speedwalk_prefix,
474 }
475
476 mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
477
478-- open databases on disk
479 databasename = GetInfo (67) .. GetPluginID () .. "_mappertest.db"
480 db = assert (sqlite3.open(databasename))
481end -- OnPluginInstall
482--------------------------------------------
483function OnPluginSaveState ()
484 mapper.save_state ()
485 SetVariable ("config", "config = " .. serialize.save_simple (config))
486end -- OnPluginSaveState
487-------------------------------------------
488function OnPluginSent (sText)
489 last_direction_moved = valid_direction [sText]
490end -- OnPluginSent
491
492]]>
493</script>
494
495 </muclient>