<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, October 30, 2008, 7:39 PM -->
<!-- MuClient version 4.33 -->

<!-- Plugin "Aardwolf_exits_detector" generated by Plugin Wizard -->

<muclient>
<plugin
   name="xExits_Detector"
   id="18c24130ab326dc05b49420d"
   language="Lua"
   purpose="Detect Exits and Room changes in Aardwolf"
   author = "swalec"
   date_written="2008-10-30 19:38:12"
   requires="4.33"
   version="1.0"
   >



<!--
Copyright (c) 2008 Swalec

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

-->

<description trim="y">

This is a support plugin meant for other plugin authors. 

This detects parts of the mud associated with movement. These
include current exits, current room title. It also detects 
the inability to move. 

Example of use

-- detect room or exit changes
function OnPluginBroadcast( msg, id, name, text )

  if ( id == "18c24130ab326dc05b49420d" ) then
      if ( msg == 2 ) then
         exits_change()
      end
      if ( msg == 1 ) then
         room_change()
      end
      if ( msg == 3 ) then 
         cant_move()
      end
  end
end
  
-- get the room name
local var = GetPluginVariableList(  "18c24130ab326dc05b49420d" )
var.roomname

-- get the exits
loadstring( var.exits )()
current_exits = exits


Exits are stored as a table with valid exit directions as keys. 
Value 1 indicates an exit, Value 2 indicates a closed exit. 


 

License:

Copyright 2008 Swalec

This is released under the MIT license, which is the same license as Lua.

</description>

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>
<aliases>
  <alias
   script="OnHelp"
   match="Aardwolf_exits_detector:help"
   enabled="y"
  >
  </alias>
</aliases>

<triggers>
  <trigger
      enabled="y"
      match="{exits}*"
      send_to="12"
      sequence="100"
      script="process_exits"
      omit_from_output="y"
      />

  <trigger
      enabled="y"
      match="{rname}*"
      send_to="12"
      sequence="100"
      script="process_room"
      omit_from_output="y"
      />


  <trigger
      enabled = "y"
      group = "swalec.exits"
      match = "You can only fly there."
      script = "process_stuck"
      make_underline = "y"
      >
  </trigger>

  <trigger
      enabled = "y"
      group = "swalec.exits"
      match = "You are trapped in quicksand."
      sequence = "100"
      script = "process_stuck"
      make_underline="y"
      >
  </trigger>
  
  <trigger
      enabled = "y"
      make_underline = "y"
      match = "^The (.*) is locked and you do not have a key.$"
      regexp= "y"
      script = "process_stuck"
      >
  </trigger>

</triggers>

<!--  Plugin help  -->
<script>
<![CDATA[
function OnHelp ()
  world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end
]]>
</script> 


<script>
<![CDATA[
require "var"
require "serialize"

specialexits = {
  hotel = {enter=4, leave=5, rooms={"The Aardwolf Plaza Hotel", 'The Luxury "Suite"'}},
  healing = {enter=8, leave=9, rooms={"The Cloak Room", "Infirmary"}},
  recall =  {enter=6, leave=7, rooms={"The Grand City of Aylor"}},
}

current = nil

function process_stuck ( name, line, wildcards, styles )
   BroadcastPlugin( 3, "" )
end

function process_exits ( name, line, wildcards, styles )
   local exitstring = wildcards[ 1 ]
   local exits = {}
   ColourNote ( "Lime", "", exitstring )
   
   for _,direction in ipairs( {"north", "south", "west", "east",
                       "up", "down", "none"} ) do
      if string.find( exitstring, direction ) then
         if string.find( exitstring, "[(]" .. direction .. "[)]" ) then
            exits[ direction ] = 2
         else
            exits[ direction ] = 1
         end
      end 
   end

   var.exits = serialize.save( "exits", exits )
   BroadcastPlugin( 2, "" )
end

function build_re(room)
  return "^" .. room .. " *[%(G%)]*$"
end

function process_room ( name, line, wildcards, styles )
  ColourNote( "Lime", "", wildcards[ 1 ] )
  local oldroom = var.roomname or ""
  local newroom = wildcards[1]
  var.roomname = newroom
  var.oldroom = oldroom
  local leaving = nil
  local entering = nil  
  for i,v in pairs(specialexits) do
    for _, room in ipairs(v.rooms) do
      roomre = build_re(room)
      if string.find(oldroom, roomre) and not (oldroom == newroom) then
        leaving = i
      end
      if string.find(newroom, roomre) and not (oldroom == newroom) then
        entering = i
      end
    end
  end
  if leaving and leaving ~= entering then
    print("Leaving", leaving)
    BroadcastPlugin(specialexits[leaving].leave, "")
    current = nil
  end
  if entering and entering ~= leaving then
    print("Entering",entering)
    BroadcastPlugin(specialexits[entering].enter, "")
    current = entering
  end
  BroadcastPlugin( 1, "" )
end

function OnPluginEnable ()
   OnPluginConnect()
end -- OnPluginEnable

function OnPluginDisable ()
   OnPluginClose()
end -- OnPluginDisable


-- pull in telnet option handling
dofile (GetPluginInfo (GetPluginID (), 20) .. "telnet_options.lua")
  
function OnPluginConnect ()
   TelnetOptionOff(TELOPT_QUIET)
   TelnetOptionOn(TELOPT_EXIT_NAMES)
   TelnetOptionOn(TELOPT_ROOM_NAMES)
end -- function OnPluginConnect

function OnPluginClose ()
   TelnetOptionOff(TELOPT_EXIT_NAMES)
   TelnetOptionOff(TELOPT_ROOM_NAMES)
end -- OnPluginClose

function OnPluginInstall ()
  -- if we are connected when the plugin loads, it must have been reloaded whilst playing
   
  if IsConnected () then
    OnPluginConnect ()
  end -- if already connected
end -- OnPluginInstall

]]>
</script>
</muclient>
