<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="RatCounter"
   author="Soludra"
   id="bd396e47bc36a5f8de99bd09"
   language="Lua"
   save_state="n"
   purpose="Counts rats slain and calculates gold earned."
   date_written="2009-3-14 14:45:00"
   requires="4.35"
   version="1.5"
   />

<triggers>
  <trigger enabled="n" group="dead_rats" keep_evaluating="n" omit_from_output="n"
           regexp="y" send_to="12" sequence="100"
           match="^You have slain an?(?: (\w+))? rat\, retrieving the corpse\.$" >
    <send>
      type = ("%1" ~= "") and "%1" or "rat"
      ratgold[type] = ratgold[type] + gold[type]
      rats[type] = rats[type] + 1
    </send>
  </trigger>

  <trigger enabled="n" group="rats_parse" keep_evaluating="n" omit_from_output="n"
           regexp="y" send_to="12" sequence="100"
           match="^You will now notice the movement of rats\. Happy hunting!$" >
    <send>
      EnableGroup("rats_parse", false)
      RatsToggle(true)
    </send>
  </trigger>

  <trigger enabled="n" group="rats_parse" keep_evaluating="n" omit_from_output="n"
           regexp="y" send_to="12" sequence="100"
           match="^You will no longer take notice of the movement of rats\.$" >
    <send>
      EnableGroup("rats_parse", false)
      RatsToggle(false)
    </send>
  </trigger>

  <trigger enabled="n" group="rats_parse" keep_evaluating="y" omit_from_output="n"
           regexp="y" send_to="12" sequence="100"
           match="^(?:\d+h, )?(?:\d+m,? )?(?:\d+e,? )?(?:\d+w,? )?c?e?x?k?d?b?@? ?(?:Vote)?- ?$" >
    <send>
      EnableGroup("rats_parse", false)
    </send>
  </trigger>
</triggers>

<aliases>
  <alias enabled="y" ignore_case="y" omit_from_output="n"
         regexp="y" send_to="12" sequence="100"
         match="^\s*rats(?:\s*(\S+))?(?:\s*|\s+.*)$"
         script="RatCommand" />
</aliases>

<script>
<![CDATA[

--constants
gold = {baby = 7, young = 14,  rat = 21, old = 28, black = 35}

--statistics
ratgold = {baby = 0, young = 0, rat = 0, old = 0, black = 0}
rats = {baby = 0, young = 0, rat = 0, old = 0, black = 0}


RatsToggle = function (rats_toggle)
  EnableGroup("dead_rats", rats_toggle)

  if (rats_toggle) then
    Note("RatCounter activated.");
  else
    Note("RatCounter deactivated.");
  end
end

RatCommand = function (name, line, wildcards)
  if wildcards[1] == "stats" then
    RatsList()
  elseif wildcards[1] == "reset" then
    RatsReset()
  else
    EnableGroup("rats_parse")
    SendNoEcho("rats")
  end
end

RatsList = function()
  local total_gold = 0
  local total_rats = 0

  for k, v in pairs(rats) do
    AchaeaNote(v .. " " .. k .. " = " .. ratgold[k] .. " gold")
    total_gold = total_gold + ratgold[k]
    total_rats = total_rats + v
  end

  AchaeaNote()
  AchaeaNote("Total: " .. total_rats .. " rats = " .. total_gold .. " gold sovereigns")
  SendNoEcho();
end

RatsReset = function()
  for k, v in pairs(rats) do
    rats[k] = 0
    ratgold[k] = 0
  end
end

AchaeaNote = function(line)
  AnsiNote(ANSI(0), line or "");
end

]]>
</script>
</muclient>