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

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

<muclient>
<plugin
   name="Aardwolf_Campaign_Noter_v2"
   author="Nick Gammon"
   id="23c3c91af0a26790c625f5d1"
   language="Lua"
   purpose="Shows remaining campaign objectives"
   date_written="2008-07-22"
   requires="4.34"
   version="2.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[
Shows outstanding campaign objectives.

To activate, type:        cp check
To hide the window:       hide_campaign
To show the window again: show_campaign
]]>
</description>

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   match="You have * to finish this campaign."
   name="cp_time"
   script="cp_time"
   sequence="100"
  >
  </trigger>
  <trigger
   match="^You still have to kill \* (.*?)$"
   name="campaign_item"
   script="campaign_item"
   sequence="100"
   regexp="y"
  >
  </trigger>
  
 <trigger
   enabled="y"
   match="Congratulations, that was one of your CAMPAIGN mobs!"
   send_to="10"
   sequence="100"
  >
  <send>cp check</send>
  </trigger>

 <trigger
   enabled="y"
   match="CONGRATULATIONS! You have completed your campaign."
   sequence="100"
   script="campaign_done"
  >
  </trigger>


</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   name="cp_check"
   script="cp_check"
   match="^(cp|campaign) check$"
   enabled="y"
   regexp="y"
   sequence="100"
  >
  <send>cp check</send>
  </alias>
</aliases>


<!--  Timers  -->


<timers>
  <timer 
      script="show_campaign_text" 
      enabled="y" 
      second="30.00" 
      >
  </timer>
</timers>

<aliases>
  <alias
   match="hide_campaign"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>WindowShow (win, false)</send>
  </alias>

  <alias
   match="show_campaign"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>WindowShow (win, true)</send>
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[

require "commas"

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

campaign_info = {}
 
function capitalize (s)
  return string.sub (s, 1, 1):upper () .. string.sub (s, 2):lower ()
end -- capitalize 

function campaign_item (name, line, wildcards)
  local text =  wildcards [1]
  text = string.sub (text, 1, 1):upper () .. string.sub (text, 2)
  table.insert (campaign_info, text)
  max_width = math.max (max_width, WindowTextWidth (win, font_id, text))
end -- campaign_item

function campaign_done (name, line, wildcards)
  Send "score"
  WindowShow (win, false)
  campaign_info = {}
end -- campaign_done

function Display_Line (i, text, id, colour)

local left = 5
local top =  (i * font_height) - font_height

  WindowText (win, id, text, left, top, 0, 0, colour)

end -- Display_Line

function show_campaign_text ()

  -- do nothing if no campaign
  if #campaign_info == 0 or when_required == nil then
    return
  end -- if

  -- recreate the window the correct size
  check (WindowCreate (win, 
                 0, 0,   -- left, top (auto-positions)
                 max_width + 10,     -- width
                 (#campaign_info + 2)   * font_height + 5,  -- height
                 7,       -- auto-position: top middle
                 0,  -- flags
                 0xE7FFFF) )
 
  -- heading
  local text = "Current campaign. You need to kill:"
  max_width = math.max (max_width, WindowTextWidth (win, font_id, text))
  Display_Line (1, text, font_id, heading_colour)

  -- list of mobs
  for i, v in ipairs (campaign_info) do
    Display_Line (i + 1, v, font_id, text_colour)
  end -- for
  
  -- how long to go
  local time_to_go = when_required - os.time ()
  
  if time_to_go < 0 then
    return
  end -- if
  
  text = string.format ("Time to go: %s", convert_time (time_to_go))
  max_width = math.max (max_width, WindowTextWidth (win, font_id, text))
  Display_Line (#campaign_info + 2, text, font_id, time_colour)
    
  WindowShow (win, true)  
end -- show_campaign_text

function cp_time (name, line, wildcards)
  local text = wildcards [1]
    
  -- work out when campaign 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

  
  check (EnableTrigger ("campaign_item", false))
  check (EnableTrigger ("cp_time", false))

  show_campaign_text ()

end -- cp_time

function cp_check( name, line, wildcards)
  check (EnableTrigger ("campaign_item", true))
  check (EnableTrigger ("cp_time", true))
  campaign_info = {}
  max_width = 0
  
end -- cp_check


function OnPluginInstall ()
  
  win = GetPluginID ()
  font_id = "fn"
  
  font_name = "Comic Sans MS"    -- the actual font
  
  -- make window so I can grab the font info
  check (WindowCreate (win, 
                 0, 0, 1, 1,  
                 1,   -- irrelevant
                 0, 
                 background_colour) )

  check (WindowFont (win, font_id, font_name, 8, false, false, false, false, 0, 0))  -- normal  
  font_height = WindowFontInfo (win, font_id, 1)  -- height
end -- OnPluginInstall

function OnPluginDisable ()
  WindowShow (win, false)
end -- OnPluginDisable

]]>
</script>

</muclient>