<?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="1.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[
Shows outstanding campaign objectives.

To activate, type: cp check
You are not currently on a campaign.
TODO:
   add ability to colour mobs in scan
]]>
</description>

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="Welcome to Aardwolf. May your adventures be mystical, challenging and rewarding."
   sequence="100"
   send_to="12"   
  >
  <send>
  Send("cp check")
  </send>
  </trigger>
  
  <trigger
   enabled="y"
   match="############# Reconnecting to Game #############"
   sequence="100"
   send_to="12"   
  >
  <send>
  Send("cp check")
  </send>
  </trigger>
  
  <trigger
   enabled="y"
   match="You are not currently on a campaign."
   name="cp_none"
   script="cp_none"
   sequence="100"
  >
  </trigger>
  <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"
   script="cp_mob_dead"
  >
  </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>
  <alias
   script="togglewindow"
   match="^togglecp$"
   enabled="y"
   regexp="y"
   sequence="100"
   ignore_case="y"
  >
  </alias>  
</aliases>


<!--  Timers  -->


<timers>
  <timer 
      script="show_cp_text" 
      enabled="y" 
      second="59.00" 
      >
  </timer>
</timers>


<!--  Script  -->


<script>
<![CDATA[

require "commas"
require 'miniwin'
require 'stringfuncs'
require 'tprint'

cpwin = Miniwindow{name="CP", windowpos=7, font_size=8, font="Sylfaen"}
cpwin:disable()

mobs = {}
enemy = ""

-- showhide
function togglewindow()
  cpwin:togglewindow(cpwin)
end

-- mousedown
function mousedown (flags, hotspotid)
  cpwin:mousedown(flags, hotspotid)
end -- mousedown

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

function cleanname(name)
  return string.lower(string.gsub(name, ",", ""))
end

function campaign_item (name, line, wildcards)
  if cpwin.disabled == 1 then
    cpwin:enable()
  end
  local text =  wildcards [1]
  text = string.sub (text, 1, 1):upper () .. string.sub (text, 2)
  ttable = utils.split(text, "(")
  name = strip(ttable[1])
  room = strip(string.sub(ttable[2], 1, -2))
  table.insert(mobs, {name=name, room=room, clean=cleanname(name)})
end -- campaign_item

function cp_mob_dead (name, line, wildcards)
  local tenemy = enemy
  local found = false
  for i,v in ipairs(mobs) do
    if v.clean == string.lower(tenemy) then
      table.remove(mobs, i)
      found = true
      break
    end   
  end
  if not found then
    print("CP: could not find mob", enemy)
  end
  show_cp_text()
end

function campaign_done (name, line, wildcards)
  Send "score"
  cpwin.ishidden = 1
  cpwin.text = nil
  cpwin:disable()
  mobs = {}
end -- campaign_done

function show_cp_text ()

  local texttable = {}

  local style = {}

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

  -- heading
  style = {}
  style.text = "Current campaign. You need to kill:  "
  style.len = #style.text
  style.style = 0
  table.insert (texttable, {style})

  -- list of mobs
  for i, v in ipairs (mobs) do
    style = {}
    style.text = v.name .. " (" .. v.room .. ")"
    style.len = #v
    style.style = 0
    table.insert (texttable, {style})
  end -- for
  
  -- how long to go
  local time_to_go = when_required - os.time ()
  
  if time_to_go < 0 then
    return
  end -- if
  
  style = {}
  style.text = string.format ("Time to go: %s", convert_time (time_to_go))
  style.len = #style.text
  style.textcolour = 0xD670DA
  style.style = 0
  table.insert (texttable, {style})  
  
  cpwin:createwin(texttable)
  
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

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

end -- cp_time

function cp_check( name, line, wildcards)
  check (EnableTrigger ("campaign_item", true))
  check (EnableTrigger ("cp_time", true))
  --cpwin:enable()
  mobs = {}
  
end -- cp_check

function cp_none( name, line, wildcards)
  check (EnableTrigger ("campaign_item", false))
  check (EnableTrigger ("cp_time", false))
  cpwin:disable()
  mobs = {}  
end

function OnPluginBroadcast (msg, id, name, text)
  if msg == 1 and id == "8a710e0783b431c06d61a54c" then
  
    -- get one variable
    enemy = GetPluginVariable ("8a710e0783b431c06d61a54c", "enemy")
     
  end -- stats changed
end

function OnPluginInstall ()

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

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

function OnPluginEnable ()
  --cpwin:enable()
end -- OnPluginEnable

function OnPluginSaveState ()
    --cpwin:savestate()
end -- OnPluginSaveState
]]>
</script>

</muclient>
