<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, July 15, 2008, 9:13 AM -->
<!-- MuClient version 4.33 -->

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

<muclient>
<plugin
   name="Aardwolf_Quest_Noter_v2"
   author="Nick Gammon/Bast"
   id="76c899eda20ad99787c6b438"
   language="Lua"
   purpose="Remembers standard quest instructions"
   date_written="2008-07-24"
   requires="4.34"
   version="2.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[
Remembers what a quest-giver told you to do.
]]>
</description>

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="Welcome to Aardwolf. May your adventures be mystical, challenging and rewarding."
   send_to="12" sequence="100"
  >
  <send>
  Send("quest info")
  </send>
  </trigger>
  
  <trigger
   enabled="y"
   match="############# Reconnecting to Game #############"
   sequence="100"
   send_to="12"    
  >
  <send>
  Send("quest info")
  </send>
  </trigger>
  
  <trigger
   enabled="n"
   regexp="y"
   match="(.*) tells you 'Seek (.*) out somewhere in the vicinity'$"
   name="mobName"
   group="qinfo"
   script="mobName"
   sequence="100"
   text_colour="6"
  >
  </trigger>
  
  <trigger
   enabled="n"
   regexp="y"
   match="(.*) tells you 'of (.*) which is in the general area'$"
   name="roomName"
   group="qinfo"
   script="roomName"
   sequence="100"
   text_colour="6"
  >
  </trigger>
  
  <trigger
   enabled="n"
   regexp="y"
   match="(.*) tells you 'of (.*).'$"
   name="areaName"
   group="qinfo"
   script="areaName"
   sequence="100"
   text_colour="6"
  >
  </trigger>
  
  <trigger
   enabled="y"
   match="You ask * for a quest."
   script="start_questor_stuff"
   sequence="100"
  >
  </trigger>
  
  <trigger
   match="@questor tells you 'You have * to complete your quest.'"
   name="questor_end"
   script="questor_end"
   sequence="10"
   expand_variables="y"
   group="qinfo"
  >
  </trigger>
  
 <trigger
   enabled="y"
   match="QUEST: You have almost completed your QUEST!"
   sequence="100"
   script="quest_done"
  >
  </trigger>

 <trigger
   enabled="y"
   match="You inform * that you have completed your quest."
   sequence="100"
   script="quest_handed_in"
  >
  </trigger>
  
 <trigger
   enabled="y"
   match="There are * minutes remaining until you can go on another quest."
   sequence="100"
   script="quest_time_to_go"
  >
  </trigger>

 <trigger
   enabled="y"
   match="QUEST: You may now quest again."
   sequence="100"
   script="quest_available"
  >
  </trigger>

  <trigger
   enabled="y"
   match="You do not have to wait to go on another quest."
   sequence="100"
   script="quest_available"
  >
  </trigger>
     
</triggers>

<!--  Timers  -->


<timers>
  <timer 
      script="show_when_quest_available" 
      enabled="y" 
      second="30.00" 
      name="questtimer"
      >
  </timer>
</timers>

<!--  Script  -->


<script>
<![CDATA[
require "window"
require "commas"
require "var"

quest_text = {}
quest_info = {mob=nil, room=nil, area=nil}
onquest = false

bg_colour = 0xE7FFFF
text_colour = 0x000000
heading_colour = 0x800080
time_colour = 0x82004B

questwin = Window{name="Quest", font="Comic Sans MS", bg_colour=0xE7FFFF, text_colour=0x000000, windowpos=7, header_height=0, width_padding=5, height_padding=3}
questwin:disable()

function quest_handed_in (name, line, wildcards)
--  Send "score"
  next_quest_time = os.time () + (30 * 60)  -- 30 mins to go
  quest_text = {}
  onquest = false
  check(EnableTimer("questtimer", true) )
  show_when_quest_available ()
end -- quest_handed_in

function quest_time_to_go (name, line, wildcards)
  local mins = tonumber (wildcards [1])
  if mins then
    next_quest_time = os.time () + mins * 60
  else
    next_quest_time = nil
  end -- if
  quest_text = {}
  show_when_quest_available ()
end -- quest_time_to_go

function quest_available (name, line, wildcards)
  next_quest_time = os.time ()
  quest_text = {}
  show_when_quest_available ()
end -- quest_available

function quest_done (name, line, wildcards)
  quest_text = { "Quest complete - go hand it in." }
  check(EnableTimer("questtimer", false))
  show_quest_text ()
end -- quest_done

function start_questor_stuff (name, line, wildcards)
  EnableTriggerGroup( "qinfo", true )
  quest_text = {}
  quest_info = {}
  var.questor = wildcards [1]
  check(EnableTimer("questtimer", true))
end -- start_questor_stuff

function mobName( strTriggerName, trig_line, wildcards )
  quest_info.mob = wildcards[2]
end -- mobName

function roomName( strTriggerName, trig_line, wildcards )
  quest_info.room = wildcards[2]
end -- roomName

function areaName( strTriggerName, trig_line, wildcards )
  quest_info.area = wildcards[2]
end

function show_when_quest_available ()
  if next_quest_time == nil then
    return
  end
  if onquest then
    build_quest()
    return
  end

  local time_to_go = next_quest_time - os.time ()
  
  local style = {}
  style.textcolour = time_colour
  style.style = 0  
  if time_to_go <= 0 then
    style.text = "You can quest again!"
    style.backcolour = "red"
    style.len = #style.text
    style.textcolour = "black"
    check(EnableTimer("questtimer", false))
  else
    style.text=  string.format ("Time until next quest: %s", convert_time (time_to_go))
    style.len = #style.text
  end -- if
  quest_text = {}
  table.insert(quest_text, {style})
    
  show_quest_text()
  
end -- show_when_quest_available

function show_quest_text ()

                
  -- do nothing if no quest
  if #quest_text == 0 then
    return
  end -- if

  questwin:enable()
  questwin:createwin(quest_text)
    
    
end -- show_quest_text

function questor_end (name, line, wildcards)

  local text = wildcards [1]
  
   -- work out when quest ends
  
  when_required = os.time ()
  
  local days = string.match (text, "(%d+) days?")
  if days then
    when_required = when_required + tonumber (days) * 60 * 60 * 24
  end -- some days left
  
  local hours = string.match (text, "(%d+) hours?")  
  if hours then
    when_required = when_required + tonumber (hours) * 60 * 60
  end -- some days left

  local minutes = string.match (text, "(%d+) minutes?")  
  if minutes then
    when_required = when_required + tonumber (minutes) * 60
  end -- some days left

  onquest = true
  
  build_quest() 

end -- questor_end

function build_quest()
  quest_text = {}
  local mobstring = string.format("%-7s: %s", "Mob", quest_info.mob)
  table.insert(quest_text, mobstring)
  local roomstring = string.format("%-7s: %s", "Room", quest_info.room)
  table.insert(quest_text, roomstring)
  local areastring = string.format("%-7s: %s", "Area", quest_info.area)
  table.insert(quest_text, areastring)
  
  local time_to_go = when_required - os.time ()
  
  local style = {}
  style.text = string.format ("Time to go: %s", convert_time (time_to_go))
  style.len = #style.text
  style.textcolour = time_colour
  style.style = 0
  table.insert (quest_text, {style})
  
  EnableTriggerGroup( "qinfo", false )
  show_quest_text ()
end

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

function OnPluginInstall ()

 if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    check (EnablePlugin(GetPluginID (), false))
    return
  end -- they didn't enable us last time
  
end -- OnPluginInstall

function OnPluginDisable ()
  questwin:disable()
end -- OnPluginDisable


]]>
</script>

</muclient>
