-
Notifications
You must be signed in to change notification settings - Fork 15
/
Realm_Of_Magic_Mapper.xml
1629 lines (1285 loc) · 43.6 KB
/
Realm_Of_Magic_Mapper.xml
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient [
<!ENTITY show_vnums "true" >
<!ENTITY show_timing "false" >
<!ENTITY show_completed "true" >
<!ENTITY show_database_mods "true" >
<!ENTITY show_other_areas "false" >
<!ENTITY show_area_exits "false" >
<!ENTITY show_up_down "true" >
<!ENTITY speedwalk_prefix "" >
<!ENTITY mud_name "Realm of Magic">
<!ENTITY two_way_exits "true" >
<!ENTITY debugging "false" >
]>
<muclient>
<plugin
name="Realm_Of_Magic_Mapper"
author="Nick Gammon"
id="b79c1e219a6246eb8f62faf4"
language="Lua"
purpose="Mapper for Realm of Magic"
save_state="y"
date_written="2014-10-17 07:00"
date_modified="2014-10-23 07:56"
requires="4.61"
version="1.6"
>
<description trim="y">
<![CDATA[
AUTOMATIC MAPPER ... by Nick Gammon
The window can be dragged to a new location by dragging the room name.
Your current room is always in the center with a bolder border.
LH-click on a room to speed-walk to it. RH-click on a room for options.
LH-click on the "*" button on the bottom-left corner to configure it.
** WHY DOES THE MAP CHANGE? **
The mapper draws from your room outwards - that is, it draws your room's exits
first, then the rooms leading from those rooms, and so on.
Eventually it finds an overlap, and draws a short "stub" line to indicate there
is a room there which there isn't space to draw. If you get closer to that
room the stub will disappear and the room(s) in question will be drawn.
ACTIONS
mapper help --> this help (or click the "?" button on the bottom right)
mapper zoom out --> zoom out
mapper zoom in --> zoom in
mapper hide --> hide map
mapper show --> show map
FINDING THINGS
mapper bookmarks --> show nearby rooms that you bookmarked
mapper find <text> --> full-text search (eg. shop OR baker)
mapper shop --> show nearby shops/banks etc.
mapper train --> show nearby trainers
mapper inn --> show nearby inns
mapper guild --> show nearby guild master
mapper where <room> --> show directions to a room
MOVING
mapper goto <room> --> walk to a room by its room number (partial)
mapper stop --> cancel any current speedwalk
mapper resume --> resume last speedwalk or hyperlinked speedwalk
]]>
</description>
</plugin>
<!-- Triggers -->
<triggers>
<!-- Things which prevent us moving -->
<trigger
enabled="y"
match="*"
script="check_for_cannot_go"
keep_evaluating="y"
sequence="1"
>
</trigger>
<trigger
enabled="n"
match="Sorry, but you can't do that here!"
name="shop_trigger"
omit_from_output="y"
send_to="12"
sequence="100"
>
<send>
ColourNote ("dimgray", "", "(Not a shop)")
EnableTrigger ( "shop_trigger" , false )
</send>
</trigger>
<trigger
enabled="y"
match=" Nr-lev-----------------------------*"
send_to="12"
sequence="100"
>
<send>
if current_room and rooms [current_room] and not rooms [current_room].shop then
ColourNote ("yellow", "", "ALERT! Room appears to be a shop but is not marked as such")
end -- if
</send>
</trigger>
</triggers>
<aliases>
<!-- zooming aliases -->
<alias
match="mapper zoom out"
enabled="y"
sequence="100"
omit_from_command_history="y"
omit_from_output="y"
script="mapper.zoom_out"
>
</alias>
<alias
match="mapper zoom in"
enabled="y"
sequence="100"
omit_from_command_history="y"
omit_from_output="y"
script="mapper.zoom_in"
>
</alias>
<alias
match="mapper goto *"
enabled="y"
sequence="100"
script="map_goto"
>
</alias>
<!-- finding aliases -->
<alias
match="^mapper find ([\w* %d/"]+)$"
enabled="y"
sequence="100"
script="map_find"
regexp="y"
>
</alias>
<alias
match="^mapper book\w*$"
regexp="y"
enabled="y"
sequence="100"
script="map_bookmarks"
>
</alias>
<alias
match="mapper where *"
enabled="y"
sequence="100"
script="map_where"
>
</alias>
<alias
match="^mapper shops?$"
regexp="y"
enabled="y"
sequence="100"
script="map_shops"
>
</alias>
<alias
match="^mapper train\w*$"
regexp="y"
enabled="y"
sequence="100"
script="map_trainers"
>
</alias>
<alias
match="^mapper inns?$"
regexp="y"
enabled="y"
sequence="100"
script="map_inns"
>
</alias>
<alias
match="^mapper guilds?$"
regexp="y"
enabled="y"
sequence="100"
script="map_guilds"
>
</alias>
<alias
match="mapper resume"
enabled="y"
sequence="100"
script="map_resume"
>
</alias>
<alias
match="mapper rooms"
enabled="y"
sequence="100"
script="map_rooms"
>
</alias>
<alias
script="OnHelp"
match="mapper help"
enabled="y"
>
</alias>
<!-- cancel speedwalking -->
<alias
match="mapper stop"
enabled="y"
sequence="100"
script="mapper.cancel_speedwalk"
>
</alias>
<!-- show/hide mapper -->
<alias
match="mapper hide"
enabled="y"
sequence="100"
script="mapper.hide"
>
</alias>
<alias
match="mapper show"
enabled="y"
sequence="100"
script="mapper.show"
>
</alias>
</aliases>
<!-- Script -->
<script>
-- pull in the plugin entities
local show_vnums = &show_vnums;
local show_timing = &show_timing;
local show_completed = &show_completed;
local show_database_mods = &show_database_mods;
local show_other_areas = &show_other_areas;
local show_up_down = &show_up_down;
local show_area_exits = &show_area_exits;
local speedwalk_prefix = "&speedwalk_prefix;"
local mud_name = "&mud_name;"
local two_way_exits = &two_way_exits;
local debugging = &debugging;
<![CDATA[
require "mapper"
require "serialize"
require "copytable"
rooms = {}
areas = {}
moves = {}
local valid_direction = {
n = "n",
s = "s",
e = "e",
w = "w",
u = "u",
d = "d",
ne = "ne",
sw = "sw",
nw = "nw",
se = "se",
north = "n",
south = "s",
east = "e",
west = "w",
up = "u",
down = "d",
northeast = "ne",
northwest = "nw",
southeast = "se",
southwest = "sw",
['in'] = "in",
out = "out",
} -- end of valid_direction
local available_directions = {
n = "north",
s = "south",
e = "east",
w = "west",
u = "up",
d = "down",
ne = "northeast",
sw = "southwest",
nw = "northwest",
se = "southeast",
['in'] = "in",
out = "out",
} -- end of available_directions
-- for calculating one-way paths
local inverse_direction = {
n = "s",
s = "n",
e = "w",
w = "e",
u = "d",
d = "u",
ne = "sw",
sw = "ne",
nw = "se",
se = "nw",
['in'] = "out",
out = "in",
} -- end of inverse_direction
local cannot_move_messages = { }
-- put messages from the MUD which stop you moving here ...
for _, v in ipairs {
"Alas, you cannot go that way...",
"Nah... You feel too relaxed to do that..",
"In your dreams, or what?",
"You need a boat or be an excellent swimmer to go there.",
"You need a boat or be able to swim to go there.",
"Maybe you should get on your feet first?",
"A guildguard blocks your way.",
"The door seems to be closed.",
"The gate seems to be closed.",
"The door is closed.",
"The gate is closed.",
"As you try to enter the corridor, a field of energy pushes you back.",
"You are too exhausted to go any farther.",
"It is pitch black...",
"No way! You're fighting for your life!",
-- add more here
} do cannot_move_messages [v] = true end
-- output debugging message if debugging is true
function debugprint (...)
if debugging then
local old_note_colour = GetNoteColourFore ()
SetNoteColourFore(ColourNameToRGB ("saddlebrown"))
print (...)
SetNoteColourFore (old_note_colour)
end -- if debugging
end -- debugprint
-- output debugging 'tprint' if debugging is true
function debugtprint (t)
if debugging then
local old_note_colour = GetNoteColourFore ()
SetNoteColourFore(ColourNameToRGB ("saddlebrown"))
print (string.rep ("-", 80))
tprint (t)
print (string.rep ("-", 80))
SetNoteColourFore (old_note_colour)
end -- if debugging
end -- debugprint
-- see table: cannot_move_messages
function check_for_cannot_go (name, line, wildcards)
if cannot_move_messages [line] then
Cannot_Go ()
end -- if
end -- check_for_cannot_go
function Cannot_Go ()
debugprint ("Cannot go this way, cancelling speedwalk.")
mapper.cancel_speedwalk ()
if #moves > 0 then
debugprint ("Removing the following outstanding moves ...")
debugtprint (moves)
moves = {}
end -- if
end -- Cannot_Go
-- -----------------------------------------------------------------
-- mapper 'get_room' callback - it wants to know about room uid
-- -----------------------------------------------------------------
function get_room (uid)
-- check we got room at all
if not uid then
return nil
end -- if
-- look it up
local ourroom = rooms [uid]
-- not cached - see if in database
if not ourroom then
ourroom = load_room_from_database (uid)
rooms [uid] = ourroom -- cache for later
end -- not in cache
if not ourroom then
return nil
end -- if
local room = copytable.deep (ourroom)
room.area = mud_name
if uid == current_room then
current_area = room.area
end -- if
-- default colours
room.bordercolour = config.ROOM_COLOUR.colour
room.borderpen = miniwin.pen_solid
room.borderpenwidth = 1
room.fillcolour = ColourNameToRGB "blue"
room.fillbrush = miniwin.brush_null
-- build hover message
-- for the hover message, and also sets the room colour
local function getinfo (which, description, colour)
if room [which] then
room.fillcolour = colour
room.fillbrush = miniwin.brush_fine_pattern
return "\nRoom " .. description
else
return ""
end -- if
end -- getinfo
local notes = ""
if room.notes then
notes = "\nBookmark: " .. room.notes
end -- if notes
local texits = {}
for dir in pairs (room.exits) do
table.insert (texits, dir)
end -- for
table.sort (texits)
room.hovermessage = string.format (
"%s\tExits: %s\nRoom: %s%s%s%s%s%s",
room.name,
table.concat (texits, ", "),
uid,
getinfo ("shop", "is a shop", config.SHOP_FILL_COLOUR.colour),
getinfo ("train", "has a trainer", config.TRAINER_FILL_COLOUR.colour),
getinfo ("inn", "is an inn", config.INN_FILL_COLOUR.colour),
getinfo ("guild", "is a guild room", config.GUILD_FILL_COLOUR.colour),
notes
-- depth,
-- table.concat (path, ",")
)
if uid == current_room then
room.bordercolour = config.OUR_ROOM_COLOUR.colour
room.borderpenwidth = 2
elseif room.area ~= current_area then
room.bordercolour = config.DIFFERENT_AREA_COLOUR.colour
end -- not in this area
return room
end -- get_room
-- -----------------------------------------------------------------
-- We have changed rooms - work out where the previous room led to
-- -----------------------------------------------------------------
function fix_up_exit ()
-- discard old moves (maybe we logged out or something)
-- we will allow 10 seconds from the time you move to when it happens
while #moves > 0 and (moves [1].time + 10) < os.time () do
debugprint ("Time-out! Removing move from", moves [1].from, "in direction", moves [1].dir)
table.remove (moves, 1)
end -- for
if #moves == 0 then
debugprint "No outstanding moves."
return
end -- if
if not current_room then
return
end -- if don't know where we are
debugprint "Fixing up exits"
debugtprint (moves)
-- get the earliest move we made
last_direction_moved = moves [1].dir
from_room = moves [1].from
table.remove (moves, 1)
-- where we were before
local room = rooms [from_room]
debugprint ("Moved from", from_room, "to", current_room, "in direction", last_direction_moved)
-- leads to here
if from_room ~= current_room then
local current_dest = nil
local current_return = nil
local inv_dir = inverse_direction [last_direction_moved]
-- see if we have an exit at present from the previous room to this one
for exitrow in db:nrows(string.format ("SELECT * FROM exits WHERE fromuid = %s AND dir = %s",
fixsql (from_room), -- fromuid
fixsql (last_direction_moved) -- dir
)) do
current_dest = exitrow.touid
end -- for each exit
-- see if we have an exit at present from this one to the previous room
if two_way_exits and inv_dir then
for exitrow in db:nrows(string.format ("SELECT * FROM exits WHERE fromuid = %s AND touid = %s AND dir = %s",
fixsql (current_room), -- fromuid
fixsql (from_room), -- touid
fixsql (inv_dir))) do
current_return = exitrow.touid
end -- for each exit
end -- if we have an inverse direction
debugprint ("Current destination = ", current_dest)
debugprint ("Current return = ", current_return)
if current_room ~= current_dest then
dbcheck (db:execute (string.format ([[
UPDATE exits SET touid = %s WHERE fromuid = %s AND dir = %s;
]],
fixsql (current_room), -- (touid) destination room
fixsql (from_room), -- (fromuid) from previous room
fixsql (last_direction_moved) -- (dir) direction (eg. "n")
)))
if show_database_mods then
mapper.mapprint ("Fixed exit", last_direction_moved, "from room", from_room, "to be to", current_room)
end -- if
end -- if destination different
if two_way_exits and
from_room and
inv_dir and
(current_return == nil or current_return == "0") then
if current_return == "0" then
dbcheck (db:execute (string.format ([[
UPDATE exits SET touid = %s WHERE fromuid = %s AND dir = %s;
]],
fixsql (from_room), -- (touid) to previous room
fixsql (current_room), -- (fromuid) from current room
fixsql (inv_dir) -- (dir) inverse direction (eg. "s")
)))
if show_database_mods then
mapper.mapprint ("Fixed reverse exit", inv_dir, "from room", current_room, "to be to", from_room)
end -- if
else
dbcheck (db:execute (string.format ([[
INSERT INTO exits (dir, fromuid, touid, date_added)
VALUES (%s, %s, %s, DATETIME('NOW'));
]], fixsql (inv_dir), -- direction (eg. "s")
fixsql (current_room), -- from current room
fixsql (from_room) -- destination room the we just came from
)))
if show_database_mods then
mapper.mapprint ("Added reverse exit", inv_dir, "from room", current_room, "to be to", from_room)
end -- if
end -- if no exit on file
if rooms [current_room] then
rooms [current_room].exits [inv_dir] = from_room
end -- if room
end -- if two_way_exits wanted and don't have right one yet
if rooms [from_room] then
rooms [from_room].exits [last_direction_moved] = current_room
end -- if
end -- if
-- clear for next time
last_direction_moved = nil
end -- fix_up_exit
-- -----------------------------------------------------------------
-- try to detect when we send a movement command
-- -----------------------------------------------------------------
function OnPluginSent (sText)
last_direction_moved = valid_direction [sText]
if last_direction_moved then
debugprint ("Just moved", last_direction_moved)
if current_room and rooms [current_room] then
expected_exit = rooms [current_room].exits [last_direction_moved]
debugprint ("expected exit for this direction is to room", expected_exit)
end -- if have a current room
t = { dir = last_direction_moved, time = os.time () }
if #moves == 0 then
t.from = current_room
end -- if first stacked move
table.insert (moves, t)
debugtprint (t)
from_room = moves [1].from
end -- if valid direction
end -- OnPluginSent
default_config = {
-- assorted colours
BACKGROUND_COLOUR = { name = "Background", colour = ColourNameToRGB "lightseagreen", },
ROOM_COLOUR = { name = "Room", colour = ColourNameToRGB "cyan", },
EXIT_COLOUR = { name = "Exit", colour = ColourNameToRGB "darkgreen", },
EXIT_COLOUR_UP_DOWN = { name = "Exit up/down", colour = ColourNameToRGB "darkmagenta", },
EXIT_COLOUR_IN_OUT = { name = "Exit in/out", colour = ColourNameToRGB "#3775E8", },
OUR_ROOM_COLOUR = { name = "Our room", colour = ColourNameToRGB "black", },
UNKNOWN_ROOM_COLOUR = { name = "Unknown room", colour = ColourNameToRGB "#00CACA", },
DIFFERENT_AREA_COLOUR = { name = "Another area", colour = ColourNameToRGB "#009393", },
SHOP_FILL_COLOUR = { name = "Shop", colour = ColourNameToRGB "darkolivegreen", },
GUILD_FILL_COLOUR = { name = "Guild", colour = ColourNameToRGB "yellowgreen", },
BANK_FILL_COLOUR = { name = "Bank", colour = ColourNameToRGB "lightblue", },
INN_FILL_COLOUR = { name = "Inn", colour = ColourNameToRGB "gold", },
TRAINER_FILL_COLOUR = { name = "Trainer", colour = ColourNameToRGB "lightgreen" },
ROOM_NAME_TEXT = { name = "Room name text", colour = ColourNameToRGB "#BEF3F1", },
ROOM_NAME_FILL = { name = "Room name fill", colour = ColourNameToRGB "#105653", },
ROOM_NAME_BORDER = { name = "Room name box", colour = ColourNameToRGB "black", },
AREA_NAME_TEXT = { name = "Area name text", colour = ColourNameToRGB "#BEF3F1",},
AREA_NAME_FILL = { name = "Area name fill", colour = ColourNameToRGB "#105653", },
AREA_NAME_BORDER = { name = "Area name box", colour = ColourNameToRGB "black", },
FONT = { name = get_preferred_font {"Dina", "Lucida Console", "Fixedsys", "Courier", "Sylfaen",} ,
size = 8
} ,
-- size of map window
WINDOW = { width = 400, height = 400 },
-- how far from where we are standing to draw (rooms)
SCAN = { depth = 30 },
-- speedwalk delay
DELAY = { time = 0.0 },
-- how many seconds to show "recent visit" lines (default 3 minutes)
LAST_VISIT_TIME = { time = 60 * 3 },
} -- end of default_config
-- -----------------------------------------------------------------
-- Plugin Install
-- -----------------------------------------------------------------
function OnPluginInstall ()
config = {} -- in case not found
-- get saved configuration
assert (loadstring (GetVariable ("config") or "")) ()
-- allow for additions to config
for k, v in pairs (default_config) do
config [k] = config [k] or v
end -- for
-- initialize mapper
mapper.init { config = config,
get_room = get_room,
show_help = OnHelp, -- to show help
room_click = room_click, -- called on RH click on room square
timing = show_timing, -- want to see timing
show_completed = show_completed, -- want to see "Speedwalk completed." message
show_other_areas = show_other_areas, -- want to see areas other than the current one?
show_up_down = show_up_down, -- want to follow up/down exits?
show_area_exits = show_area_exits, -- want to see area exits?
speedwalk_prefix = speedwalk_prefix, -- how to speedwalk
}
mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
-- open databases on disk
db = assert (sqlite3.open(GetInfo (66) .. Trim (WorldAddress ()) .. "_" .. WorldPort () .. ".db"))
create_tables () -- create database structure if necessary
end -- OnPluginInstall
-- -----------------------------------------------------------------
-- Plugin Save State
-- -----------------------------------------------------------------
function OnPluginSaveState ()
mapper.save_state ()
SetVariable ("config", "config = " .. serialize.save_simple (config))
end -- OnPluginSaveState
function map_resume (name, line, wildcards)
local wanted = mapper.last_hyperlink_uid or mapper.last_speedwalk_uid
if not wanted then
mapper.print "No outstanding speedwalks or hyperlinks."
return
end -- if nothing to do
-- find desired room
mapper.find (
function (uid)
return uid == wanted, uid == wanted
end, -- function
show_vnums, -- show vnum?
1, -- how many to expect
true -- just walk there
)
end -- map_resume
function map_goto (name, line, wildcards)
local wanted = wildcards [1]
-- check valid string
if string.match (wanted, "%X") then
mapper.maperror ("Room number must be hex string (0-9, A-F), you entered: " .. wanted)
return
end -- if
-- internally rooms are upper-case hex
wanted = wanted:upper ()
-- see if already there
if current_room and string.match (current_room, "^" .. wanted) then
mapper.mapprint ("You are already in that room.")
return
end -- if
-- find desired room
mapper.find (
function (uid)
local found = string.match (uid, "^" .. wanted)
return found, found
end, -- function
show_vnums, -- show vnum?
1, -- how many to expect
true -- just walk there
)
end -- map_goto
function map_where (name, line, wildcards)
if not mapper.check_we_can_find () then
return
end -- if
local wanted = wildcards [1]
if current_room and wanted == current_room then
mapper.mapprint ("You are already in that room.")
return
end -- if
local paths = mapper.find_paths (current_room,
function (uid)
return uid == wanted, -- wanted room?
uid == wanted -- stop searching?
end)
local uid, item = next (paths, nil) -- extract first (only) path
-- nothing? room not found
if not item then
mapper.mapprint (string.format ("Room %s not found", wanted))
return
end -- if
-- turn into speedwalk
local path = mapper.build_speedwalk (item.path)
-- display it
mapper.mapprint (string.format ("Path to %s is: %s", wanted, path))
end -- map_where
function OnHelp ()
mapper.mapprint (string.format ("[MUSHclient mapper, version %0.1f]", mapper.VERSION))
mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
end -- end of OnHelp
room_not_in_database = {}
room_in_database = {}
function dbcheck (code)
if code ~= sqlite3.OK and -- no error
code ~= sqlite3.ROW and -- completed OK with another row of data
code ~= sqlite3.DONE then -- completed OK, no more rows
local err = db:errmsg () -- the rollback will change the error message
db:exec ("ROLLBACK") -- rollback any transaction to unlock the database
error (err, 2) -- show error in caller's context
end -- if
end -- dbcheck
function fixsql (s)
if s then
return "'" .. (string.gsub (s, "'", "''")) .. "'" -- replace single quotes with two lots of single quotes
else
return "NULL"
end -- if
end -- fixsql
function fixbool (b)
if b then
return 1
else
return 0
end -- if
end -- fixbool
function load_room_from_database (uid)
local room
assert (uid, "No UID supplied to load_room_from_database")
-- if not in database, don't look again
if room_not_in_database [uid] then
return nil
end -- no point looking
for row in db:nrows(string.format ("SELECT * FROM rooms WHERE uid = %s", fixsql (uid))) do
room = {
name = row.name,
area = row.area,
description = row.description,
shop = tonumber (row.shop) == 1,
train = tonumber (row.train) == 1,
inn = tonumber (row.inn) == 1,
guild = tonumber (row.guild) == 1,
notes = row.notes,
exits = {} }
for exitrow in db:nrows(string.format ("SELECT * FROM exits WHERE fromuid = %s", fixsql (uid))) do
room.exits [exitrow.dir] = tostring (exitrow.touid)
end -- for each exit
end -- finding room
if room then
rooms [uid] = room
return room
end -- if found
room_not_in_database [uid] = true
return nil
end -- load_room_from_database
function save_room_to_database (uid, title, description)
assert (uid, "No UID supplied to save_room_to_database")
dbcheck (db:execute (string.format (
"INSERT INTO rooms (uid, name, description, date_added) VALUES (%s, %s, %s, DATETIME('NOW'));",
fixsql (uid),
fixsql (title),
fixsql (description)
)))
dbcheck (db:execute (string.format ([[
INSERT INTO rooms_lookup (uid, name, description) VALUES (%s, %s, %s);
]], fixsql (uid),
fixsql (title),
fixsql (description)
)))
room_not_in_database [uid] = false
if show_database_mods then
mapper.mapprint ("Added room", uid, "to database. Name:", title)
end -- if
end -- function save_room_to_database
function save_exits_to_database (uid, exits)
for dir in string.gmatch (exits, "%a+") do
-- fix up in and out
dir = ({ ['i'] = "in", o = "out", }) [dir] or dir
dbcheck (db:execute (string.format ([[
INSERT INTO exits (dir, fromuid, touid, date_added)
VALUES (%s, %s, %s, DATETIME('NOW'));
]], fixsql (dir), -- direction (eg. "n")
fixsql (uid), -- from current room
fixsql (0) -- destination room (not known)
)))
if show_database_mods then
mapper.mapprint ("Added unknown exit", dir, "from room", uid, "to database.")
end -- if
end -- for each exit
end -- function save_exits_to_database
function create_tables ()
-- create rooms table
dbcheck (db:execute[[
PRAGMA foreign_keys = ON;
PRAGMA journal_mode = WAL;
CREATE TABLE IF NOT EXISTS rooms (
roomid INTEGER PRIMARY KEY AUTOINCREMENT,
uid TEXT NOT NULL, -- vnum or how the MUD identifies the room
name TEXT, -- name of room
description TEXT, -- description
building TEXT, -- which building it is in
shop INTEGER, -- 1 = shop here
train INTEGER, -- 1 = trainer here
inn INTEGER, -- 1 = inn here
guild INTEGER, -- 1 = guild master here
notes TEXT, -- player notes
date_added DATE, -- date added to database
UNIQUE (uid)
);
CREATE INDEX IF NOT EXISTS shop_index ON rooms (shop);
CREATE INDEX IF NOT EXISTS inn_index ON rooms (inn);
CREATE INDEX IF NOT EXISTS guild_index ON rooms (guild);
CREATE INDEX IF NOT EXISTS train_index ON rooms (train);