Guest User

Untitled

a guest
Jul 22nd, 2021
150
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE muclient>
  3. <muclient>
  4. <plugin
  5. name="Inquisition_Mapper"
  6. author="Nick Gammon"
  7. id="2a5655924080806ca252f1e6"
  8. language="Lua"
  9. purpose="Mapper for The Inquisition"
  10. save_state="y"
  11. date_written="2018-01-15"
  12. date_modified="2021-07-21 13:09"
  13. requires="5.00"
  14. version="1.5"
  15. >
  16.  
  17. <description trim="y">
  18. <![CDATA[
  19. THE INQUISITION MAPPER ... by Nick Gammon
  20.  
  21. ACTIONS
  22.  
  23. mapper help --> this help (or click the "?" button on the bottom right)
  24. mapper zoom out --> zoom out
  25. mapper zoom in --> zoom in
  26. mapper hide --> hide map
  27. mapper show --> show map
  28.  
  29. FINDING
  30.  
  31. mapper find <word> --> find a room matching part of a name / description
  32. mapper where <vnum> --> show directions to a room
  33.  
  34. MOVING
  35.  
  36. mapper goto <room> --> walk to a room by its room number (vnum)
  37. mapper stop --> cancel any current speedwalk
  38.  
  39.  
  40. ]]>
  41. </description>
  42.  
  43. </plugin>
  44.  
  45. <aliases>
  46. <alias
  47. match="mapper help"
  48. script="OnHelp"
  49. enabled="y"
  50. >
  51. </alias>
  52.  
  53. <!-- finding stuff -->
  54.  
  55. <alias
  56. match="mapper find *"
  57. enabled="y"
  58. sequence="100"
  59. script="map_find"
  60. >
  61. </alias>
  62.  
  63. <alias
  64. match="mapper where *"
  65. enabled="y"
  66. sequence="100"
  67. script="map_where"
  68. >
  69. </alias>
  70.  
  71. <!-- zooming aliases -->
  72.  
  73. <alias
  74. match="mapper zoom out"
  75. enabled="y"
  76. sequence="100"
  77. omit_from_command_history="y"
  78. omit_from_output="y"
  79. script="mapper.zoom_out"
  80. >
  81. </alias>
  82.  
  83. <alias
  84. match="mapper zoom in"
  85. enabled="y"
  86. sequence="100"
  87. omit_from_command_history="y"
  88. omit_from_output="y"
  89. script="mapper.zoom_in"
  90. >
  91. </alias>
  92.  
  93.  
  94. <alias
  95. match="mapper goto *"
  96. enabled="y"
  97. sequence="100"
  98. script="map_goto"
  99. >
  100. </alias>
  101.  
  102. <!-- cancel speedwalking -->
  103.  
  104. <alias
  105. match="mapper stop"
  106. enabled="y"
  107. sequence="100"
  108. script="mapper.cancel_speedwalk"
  109. >
  110. </alias>
  111.  
  112. <!-- show/hide mapper -->
  113.  
  114. <alias
  115. match="mapper hide"
  116. enabled="y"
  117. sequence="100"
  118. script="mapper.hide"
  119. >
  120. </alias>
  121.  
  122. <alias
  123. match="mapper show"
  124. enabled="y"
  125. sequence="100"
  126. script="mapper.show"
  127. >
  128. </alias>
  129.  
  130. </aliases>
  131.  
  132. <triggers>
  133. <trigger
  134. enabled="y"
  135. match="[RPXP Gain: *] [HP:* MV:* P:*] * (vnum *)*"
  136. script="got_prompt"
  137. sequence="100"
  138. name="prompt"
  139. keep_evaluating="y"
  140. >
  141. </trigger>
  142.  
  143. <trigger
  144. enabled="y"
  145. match="^([^\[(].*)$"
  146. script="got_room_name"
  147. keep_evaluating="y"
  148. sequence="90"
  149. regexp="y"
  150. name="room_name"
  151. >
  152. </trigger>
  153.  
  154. <trigger
  155. enabled="y"
  156. match="^\["
  157. script="got_weather_line"
  158. keep_evaluating="y"
  159. sequence="90"
  160. regexp="y"
  161. name="weather_line"
  162. >
  163. </trigger>
  164.  
  165. <trigger
  166. enabled="y"
  167. match="[ Exits: * ]"
  168. script="got_exits"
  169. sequence="100"
  170. >
  171. </trigger>
  172.  
  173. <trigger
  174. enabled="n"
  175. match="*"
  176. script="got_description_line"
  177. sequence="200"
  178. name="description_line"
  179. >
  180. </trigger>
  181.  
  182.  
  183. <!--
  184. Things which prevent us moving.
  185.  
  186. Right now we assume they are yellow on black in bold. If this isn't (always) the case
  187. change match_text_colour, match_back_colour and match_bold to be "n" (as appropriate).
  188.  
  189. See "cannot_move_messages" table further down for the exact messages that are matched on.
  190.  
  191. -->
  192.  
  193. <trigger
  194. match="*"
  195.  
  196. enabled="y"
  197. match_back_colour="y"
  198. match_text_colour="y"
  199.  
  200. match_bold="y"
  201. bold="y"
  202.  
  203. text_colour="3"
  204. back_colour="8"
  205.  
  206. script="check_for_cannot_go"
  207. keep_evaluating="y"
  208. sequence="1"
  209. >
  210. </trigger>
  211.  
  212. </triggers>
  213.  
  214. <!-- Script -->
  215.  
  216. <script>
  217. <![CDATA[
  218.  
  219. -- mapper module
  220. require "mapper"
  221.  
  222. -- configuration table
  223. config = {
  224. OUR_ROOM_COLOUR = { name = "Our room", colour = ColourNameToRGB "black", },
  225. }
  226.  
  227. -- all the rooms we have come across
  228. rooms = { }
  229.  
  230. -- for serialization
  231. require "serialize"
  232.  
  233. -- -----------------------------------------------------------------
  234. -- these commands will be considered "room changing" commands
  235. -- -----------------------------------------------------------------
  236. local valid_direction = {
  237. n = "n",
  238. s = "s",
  239. e = "e",
  240. w = "w",
  241. u = "u",
  242. d = "d",
  243. ne = "ne",
  244. sw = "sw",
  245. nw = "nw",
  246. se = "se",
  247. north = "n",
  248. south = "s",
  249. east = "e",
  250. west = "w",
  251. up = "u",
  252. down = "d",
  253. northeast = "ne",
  254. northwest = "nw",
  255. southeast = "se",
  256. southwest = "sw",
  257. ["in"] = "in",
  258. out = "out",
  259. } -- end of valid_direction
  260.  
  261. -- for calculating the way back
  262. local inverse_direction = {
  263. n = "s",
  264. s = "n",
  265. e = "w",
  266. w = "e",
  267. u = "d",
  268. d = "u",
  269. ne = "sw",
  270. sw = "ne",
  271. nw = "se",
  272. se = "nw",
  273. ["in"] = "out",
  274. out = "in",
  275. } -- end of inverse_direction
  276.  
  277. -- put messages from the MUD which stop you moving here ...
  278. -- Use * for wildcards, everything else matches literally.
  279.  
  280. local cannot_move_messages = {
  281. "Nah... * feels too relaxed...",
  282. "In * dreams, or what?",
  283.  
  284. -- add more here
  285.  
  286. }
  287.  
  288. -- -----------------------------------------------------------------
  289. -- for converting things like ^ $ * etc. into "escaped" sequences
  290. -- -----------------------------------------------------------------
  291. function fix_regexp_magic_characters (r)
  292. return string.gsub (r, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%1")
  293. end -- fix_regexp_magic_characters
  294.  
  295. -- -----------------------------------------------------------------
  296. -- mapper 'get_room' callback - it wants to know about room uid
  297. -- -----------------------------------------------------------------
  298. function get_room (uid)
  299.  
  300. room = rooms [uid]
  301. if not room then
  302. return nil
  303. end -- if not found
  304.  
  305. -- how to draw this particular room
  306. room.bordercolour = config.ROOM_COLOUR.colour
  307. room.borderpen = miniwin.pen_solid
  308. room.borderpenwidth = 1
  309. room.fillbrush = miniwin.brush_null -- no fill
  310.  
  311. -- draw current room in bolder colour
  312. if uid == current_room then
  313. room.bordercolour = config.OUR_ROOM_COLOUR.colour
  314. room.borderpenwidth = 2
  315. end -- not in this area
  316.  
  317. room.area = "The Inquisition" -- assume every room is in this area
  318.  
  319. local texits = {}
  320. for dir in pairs (room.exits) do
  321. table.insert (texits, dir)
  322. end -- for
  323. table.sort (texits)
  324.  
  325. room.hovermessage = string.format (
  326. "%s\tExits: %s\nVnum: %s\n\n%s",
  327. room.name,
  328. table.concat (texits, ", "),
  329. uid,
  330. room.description or ""
  331. )
  332.  
  333. return room
  334. end -- get_room
  335.  
  336. -- -----------------------------------------------------------------
  337. -- Plugin Install
  338. -- -----------------------------------------------------------------
  339. function OnPluginInstall ()
  340.  
  341. assert (loadstring (GetVariable ("config") or "")) ()
  342. assert (loadstring (GetVariable ("rooms") or "")) ()
  343.  
  344. -- initialize mapper
  345. mapper.init {
  346. config = config, -- ie. colours, sizes
  347. get_room = get_room, -- info about room (uid)
  348. show_help = OnHelp, -- to show help
  349. }
  350.  
  351. mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
  352. ColourNote ("orange", "", "Mapper plugin 'save state' file name is:")
  353. ColourNote ("yellow", "", (string.format ("%s%s-%s-state.xml",
  354. GetInfo (85), GetWorldID (), GetPluginID ())))
  355. mapper.mapprint ("Consider backing up the above file regularly as it has the mapper database in it.")
  356.  
  357. -- fix up wildcards in "cannot_move_messages" table
  358. for k, v in ipairs (cannot_move_messages) do
  359. -- replace wildcard (asterisk) by 0x00
  360. v = string.gsub (v, '%*', string.char (0))
  361. -- fix all other characters like periods
  362. v = fix_regexp_magic_characters (v)
  363. -- put the wildcards back (convert 0x00 to ".*")
  364. cannot_move_messages [k] = string.gsub (v, string.char (0), '.*' )
  365. end -- for each message
  366.  
  367. end -- OnPluginInstall
  368.  
  369. -- -----------------------------------------------------------------
  370. -- Plugin Help
  371. -- -----------------------------------------------------------------
  372. function OnHelp ()
  373. mapper.mapprint (string.format ("[MUSHclient mapper, version %0.1f]", mapper.VERSION))
  374. mapper.mapprint (GetPluginInfo (GetPluginID (), 3))
  375. end
  376.  
  377. -- -----------------------------------------------------------------
  378. -- Here on prompt
  379. -- -----------------------------------------------------------------
  380. function got_prompt (name, line, wildcards)
  381. uid = wildcards [6] -- change this if you change the prompt trigger
  382.  
  383. -- assume we know the room name and description by now
  384. -- add to rooms table if not there
  385. if not rooms [uid] then
  386. rooms [uid] = { name = room_name, exits = {}, description = room_description or ""}
  387. mapper.mapprint (string.format ("Added room <%s> (vnum %s) to the mapper database", room_name, uid))
  388. end -- if
  389.  
  390. if rooms [uid].description ~= room_description then
  391. rooms [uid].description = room_description
  392. -- mapper.mapprint ("Updating room description to be: " .. room_description)
  393. end -- if description not previously found
  394.  
  395. -- add stub entries for known exits
  396. if next (rooms [uid].exits) == nil and current_exits then
  397. for exit in string.gmatch (current_exits, "%a+") do
  398. local direction = valid_direction [exit]
  399. if direction then
  400. rooms [uid].exits [direction] = 0 -- dummy non-existent room
  401. end -- if a known exit direction
  402. end -- for each exit word
  403. end -- if no exits known
  404.  
  405. -- if we changed rooms assume that our last movement sent us here
  406. if uid ~= current_room
  407. and current_room
  408. and last_direction_moved then
  409. -- previous room led here
  410. rooms [current_room].exits [last_direction_moved] = uid
  411. -- assume inverse direction leads back
  412. rooms [uid].exits [inverse_direction [last_direction_moved]] = current_room
  413. last_direction_moved = nil -- we have to move again now
  414. end -- if
  415.  
  416. -- this is now our current room
  417. current_room = uid
  418.  
  419. -- draw this room
  420. mapper.draw (current_room)
  421.  
  422. -- await more exits
  423. current_exits = nil
  424.  
  425. end -- got_prompt
  426.  
  427. -- -----------------------------------------------------------------
  428. -- Here on room name
  429. -- -----------------------------------------------------------------
  430. function got_room_name (name, line, wildcards, styles)
  431. if styles == nil or styles[1].textcolour ~= ColourNameToRGB("#FF0000") then
  432. return
  433. end -- if not the right colour
  434.  
  435. local name = wildcards [1]
  436.  
  437. -- ignore really long lines
  438. if #name > 60 then
  439. return
  440. end -- if
  441.  
  442. room_name = name
  443. current_exits = nil
  444. description = { }
  445. room_description = nil
  446.  
  447. end -- got_room_name
  448.  
  449. -- -----------------------------------------------------------------
  450. -- Here on "exits" line
  451. -- -----------------------------------------------------------------
  452. function got_exits (name, line, wildcards, styles)
  453. if styles == nil or styles[1].textcolour ~= ColourNameToRGB("#008080") then
  454. return
  455. end -- if not the right colour
  456. -- remember the exits
  457. current_exits = wildcards [1]
  458. EnableTrigger ("description_line", false)
  459. room_description = Trim (table.concat (description, "\n"))
  460. description = { }
  461. end -- got_exits
  462.  
  463. -- -----------------------------------------------------------------
  464. -- try to detect when we send a movement command
  465. -- -----------------------------------------------------------------
  466. function OnPluginSent (sText)
  467. local direction = valid_direction [sText]
  468. if direction then
  469. last_direction_moved = direction
  470. end -- if
  471. end -- OnPluginSent
  472.  
  473. -- -----------------------------------------------------------------
  474. -- on saving state, serialize the rooms and configuration
  475. -- -----------------------------------------------------------------
  476. function OnPluginSaveState ()
  477. SetVariable ("config", "config = " .. serialize.save_simple (config))
  478.  
  479. -- just save the relevant stuff - you may need to update this if you add more things
  480. local wanted_keys = { "name", "exits", "description" }
  481.  
  482. local saved_rooms = { }
  483. for k, v in pairs (rooms) do
  484. saved_rooms [k] = { }
  485. for i, j in ipairs (wanted_keys) do
  486. saved_rooms [k] [j] = v [j]
  487. end -- for
  488. end -- for
  489.  
  490. SetVariable ("rooms", "rooms = " .. serialize.save_simple (saved_rooms))
  491. end -- function OnPluginSaveState
  492.  
  493. -- -----------------------------------------------------------------
  494. -- map_find: mapper find xxx
  495. -- -----------------------------------------------------------------
  496. function map_find (name, line, wildcards)
  497.  
  498. mapper.mapprint (string.rep ("-", 25) .. " Mapper search " .. string.rep ("-", 25))
  499.  
  500. local reset = ANSI (0)
  501. local bold = ANSI (1)
  502. local unbold = ANSI (22)
  503.  
  504. local matches = { }
  505. local count = 0
  506. local target = Trim (wildcards [1]:lower ())
  507.  
  508. if target == "" then
  509. mapper.maperror ("No search string specified")
  510. return
  511. end -- if
  512.  
  513. if not mapper.check_we_can_find () then
  514. return
  515. end -- if find not OK
  516.  
  517. -- fix up any regular expression "magic" letters to be escaped by a %
  518. local fixed_target = fix_regexp_magic_characters (target)
  519.  
  520. -- fix up for caseless searches in the room description (eg. "a" becomes "[aA]")
  521. local caseless_target = string.gsub (fixed_target, "(%a)", function (a)
  522. return "[" .. a:lower () .. a:upper () .. "]"
  523. end -- function
  524. )
  525.  
  526. -- do a simple string search to find matching rooms
  527. for k, v in pairs (rooms) do
  528.  
  529. -- don't want nil descriptions
  530. if not v.description then
  531. v.description = ""
  532. end -- if no description
  533.  
  534. if string.find (v.name:lower (), fixed_target) or
  535. string.find (v.description:lower (), fixed_target) then
  536. matches [k] = true
  537. count = count + 1
  538. end -- if match
  539. end -- for each room
  540.  
  541. local function show_snippet (uid)
  542. local room = rooms [uid]
  543. if not room then
  544. return
  545. end -- if
  546.  
  547. -- don't bother if the wanted words was in the room name
  548. if string.find (room.name:lower (), fixed_target) then
  549. return
  550. end -- if
  551.  
  552. -- otherwise show the wanted word in the description, in bold
  553. AnsiNote (reset .. string.gsub (room.description, caseless_target, bold .. "%1" .. unbold))
  554.  
  555. end -- show_snippet
  556.  
  557. -- see if nearby
  558. mapper.find (
  559. function (uid)
  560. local room = matches [uid]
  561. if room then
  562. matches [uid] = nil
  563. end -- if
  564. return room, next (matches) == nil
  565. end, -- function
  566. show_vnums, -- show vnum?
  567. count, -- how many to expect
  568. false, -- don't auto-walk
  569. show_snippet -- show find snippet
  570. )
  571. end -- map_find
  572.  
  573. -- -----------------------------------------------------------------
  574. -- map_goto for: mapper goto xxx
  575. -- -----------------------------------------------------------------
  576. function map_goto (name, line, wildcards)
  577. local wanted = wildcards [1]
  578. -- check valid string
  579. if string.match (wanted, "%D") then
  580. mapper.maperror ("Room number must be numeric, you entered: " .. wanted)
  581. return
  582. end -- if
  583.  
  584. -- see if already there
  585. if current_room and string.match (current_room, "^" .. wanted) then
  586. mapper.mapprint ("You are already in that room.")
  587. return
  588. end -- if
  589. -- find desired room
  590. mapper.find (
  591. function (uid)
  592. local found = string.match (uid, "^" .. wanted)
  593. return found, found
  594. end, -- function
  595. show_vnums, -- show vnum?
  596. 1, -- how many to expect
  597. true -- just walk there
  598. )
  599. end -- map_goto
  600.  
  601. -- -----------------------------------------------------------------
  602. -- got_weather_line: Called when we get the weather line (the description follows)
  603. -- -----------------------------------------------------------------
  604. function got_weather_line (name, line, wildcards, styles)
  605. if styles[1].textcolour ~= ColourNameToRGB("#FF0000") then
  606. return
  607. end -- if not the right colour
  608. EnableTrigger ("description_line", true)
  609. description = { }
  610. end -- got_weather_line
  611.  
  612. -- -----------------------------------------------------------------
  613. -- got_description_line: Called for each line of the room description
  614. -- -----------------------------------------------------------------
  615. function got_description_line (name, line, wildcards)
  616. -- stop collecting descriptions after a blank line
  617. if Trim (line) == "" then
  618. EnableTrigger ("description_line", false)
  619. end -- if blank line
  620.  
  621. table.insert (description, line) -- build up the description
  622. end -- got_description_line
  623.  
  624. -- -----------------------------------------------------------------
  625. -- map_where: Show where a room is
  626. -- -----------------------------------------------------------------
  627. function map_where (name, line, wildcards)
  628. if not mapper.check_we_can_find () then
  629. return
  630. end -- if
  631. local wanted = wildcards [1]
  632. if current_room and wanted == current_room then
  633. mapper.mapprint ("You are already in that room.")
  634. return
  635. end -- if
  636. local paths = mapper.find_paths (current_room,
  637. function (uid)
  638. return uid == wanted, -- wanted room?
  639. uid == wanted -- stop searching?
  640. end)
  641. local uid, item = next (paths, nil) -- extract first (only) path
  642. -- nothing? room not found
  643. if not item then
  644. mapper.mapprint (string.format ("Room %s not found", wanted))
  645. return
  646. end -- if
  647. -- turn into speedwalk
  648. local path = mapper.build_speedwalk (item.path)
  649. -- display it
  650. mapper.mapprint (string.format ("Path to %s is: %s", wanted, path))
  651. end -- map_where
  652.  
  653. -- -----------------------------------------------------------------
  654. -- cannot_walk - we tried to walk but failed
  655. -- -----------------------------------------------------------------
  656. function cannot_walk (name, line, wildcards)
  657. mapper.cancel_speedwalk ()
  658. room_description = nil
  659. current_exits = nil
  660. room_name = nil
  661. last_direction_moved = nil
  662. -- mapper.mapprint ("Attempt to walk cancelled.")
  663.  
  664. end -- cannot_walk
  665.  
  666. -- -----------------------------------------------------------------
  667. -- check_for_cannot_go - look up the line in a table of failure messages
  668. -- see table: cannot_move_messages
  669. -- -----------------------------------------------------------------
  670. function check_for_cannot_go (name, line, wildcards)
  671.  
  672. for _, v in ipairs (cannot_move_messages) do
  673. if string.find (line, v) then
  674. cannot_walk ()
  675. break
  676. end -- if match
  677. end -- for each message
  678. end -- check_for_cannot_go
  679.  
  680. ]]>
  681.  
  682. </script>
  683. </muclient>
RAW Paste Data