<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, December 01, 2008, 3:08 PM -->
<!-- MuClient version 4.37 -->

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

<muclient>
<plugin
   name="Aardwolf_Regen"
   author="Eric Davis"
   id="952f716e12d4fb06621b7b25"
   language="Lua"
   purpose="To do stuff automatically when entering the aard hotel"
   save_state="y"
   date_written="2008-12-01 15:06:56"
   requires="4.37"
   version="1.0"
   >
<description trim="y">
<![CDATA[
This plugin is designed to wear the regen ring at certain times
  sleeping
  when entering aard hotel and other healing rooms

It will reequip the variable rring in your world when
  standing
  when leaving aard hotel and other healing rooms
Requires swalec's aardwolf exit detector
]]>
</description>

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="^[Rr]egen:help$"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   name="sleep"
   script="sleep"
   match="^(sl|sle|slee|sleep)[ ]*[.]*$"
   enabled="y"
   regexp="y"
   ignore_case="y"
   sequence="100"
  >
  </alias>
</aliases>
<triggers>
  <trigger
   enabled="y"
   omit_from_output="n"
   match="^You wear Aardwolf Ring of Regeneration on your (.*) finger.$"
   script="fregenworn"
   regexp="y"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   omit_from_output="n"
   match="^You remove Aardwolf Ring of Regeneration from your (.*) finger.$"
   script="fregenremoved"
   regexp="y"
   sequence="100"
  >
  </trigger>
</triggers>

<script>
<![CDATA[

require "checkplugin"
require "verify"

stats = {}
oldstats = {}
status = {}
oldstatus = {}
tryremove = false
trywear = false
clientAFK = false
regenworn = verify_bool(GetVariable( "regenworn" )) or false
inhealing = verify_bool(GetVariable( "inhealing" )) or false


function OnHelp ()
  world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end

function OnPluginSaveState ()
  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
  SetVariable ("regenworn", tostring(regenworn))
  SetVariable ("inhealing", tostring(inhealing))
end -- OnPluginSaveState

function OnPluginEnable ()
  
  checkplugin ("18c24130ab326dc05b49420d", "Aardwolf Exits Detector")
  checkplugin ("8a710e0783b431c06d61a54c", "Aardwolf Stats Detector")
  checkplugin ("f5b05e8826711cdb0d141939", "Aardwolf Playing Detector")

end

function OnPluginInstall ()

end

function OnPluginBroadcast (msg, id, name, text)
  -- stats change
  if id == "8a710e0783b431c06d61a54c" then
    oldstats = stats
    stats = GetPluginVariableList("8a710e0783b431c06d61a54c")    
  -- state change
  elseif id == "f5b05e8826711cdb0d141939" then
    oldstatus = status
    status = GetPluginVariableList("f5b05e8826711cdb0d141939")
    if status.statestring == 'active' then
       checkstand()
    end
  elseif id == "18c24130ab326dc05b49420d" then
    if msg == 4 or msg == 8 then
      print("entering healing")
      inhealing = true
      wear_regen()
    elseif msg == 5 or msg == 9 then
      print("leaving healing")
      inhealing = false
      remove_regen()  
    end
      
    if not inhealing and status.statestring == 'active' and regenworn and not tryremove then
      remove_regen()
    end  
  elseif id == "0e191dc7829ff2ac2433c2d8" then
    if msg == 1 then
      clientAFK = text == "y"
      if clientAFK then
        wear_regen()
      elseif (not clientAFK) and not inhealing then
        remove_regen()
      end
    end
   end -- AFK status changed  
end

function fregenworn()
  regenworn = true
  trywear = false
  SaveState()
end

function fregenremoved()
  regenworn = false
  tryremove = false
  SaveState()
end

function wear_regen()
  if not regenworn then
    trywear = true
    --DoAfterSpecial (3, 'try_wear()', sendto.script)
    Send("wear regen")
  end
end

function remove_regen()
  if regenworn or trywear then
    ring = GetPluginVariable ("", "rring")
    tryremove = true
    Send("wear " .. ring)
  end
end

function try_wear()
  if not tryremove then
    send("wear regen")
  end
end

function sleep(name, line, wildcards)
  wear_regen()
  Send(line)
end

function checkstand()
  if oldstatus.statestring == 'sleeping' and not inhealing then
    remove_regen()
  end
end
]]>
</script> 

</muclient>
