
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, October 15, 2006, 5:29 AM -->
<!-- MuClient version 3.74 -->

<!-- Plugin "Aardwolf_Stat_SeparateLUA" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Aardwolf_Stats"
   author="Onoitsu2/Lasher"
   id="0778870a4855be6de2e34b6d"
   language="Lua"
   purpose="Displays the Stat on Aardwolf within another window"
   date_written="2006-10-15 05:27:29"
   requires="3.74"
   version="1.1"
   save_state="y"
   >
<description trim="n">
<![CDATA[
Aardwolf_Stat_SeparaterLUA Help File

This Plugin is used to redirect stats displayed on Aardwolf
into another window (Open World File). The default window is
"Stats". If you change that, you will need to modify
the world name variable.

]]>
</description>

</plugin>

<script>
<![CDATA[

line_count = nil

require "getworld"
require "checkplugin"

worldname = "Stats"
folder = "Aardwolf"

function OnPluginBroadcast (msg, id, name, text)
  if msg == 1 and id == "8a710e0783b431c06d61a54c" then
    Stat_Start ()
  end -- stats changed
end

function Stat_Start(sName,sLine,wildcards)
  local statwin = get_a_world(worldname, folder)
 
  local stats = GetPluginVariableList ("8a710e0783b431c06d61a54c")
  
  local  statcol = "#eeeeee";
  local  labelcol= "#00d6d6";
  local  goldlcol="#d6d600";
  
  if not statwin then
    ColourNote("white", "red", "AardStat 'Send To' Window (" .. worldname .. ") NOT Open!")
    EnablePlugin (GetPluginID (), false)  -- disable ourselves
    return
  end -- if we have a stat window
  
   --- Clear existing input.
   statwin:DeleteOutput()
   
   --- Just a blank line, better way? no
   statwin:Note ("")
   
   formatStat (statcol, statwin, stats.str, stats.base_str, 
              "Strength     : ", false);
   statwin:Tell ("   ");
   formatPool (statwin, stats.hp, stats.max_hp,
              "Health  : ", true);
   
   formatStat (statcol, statwin, stats.int, stats.base_int, 
              "Intelligence : ", false);
   statwin:Tell ("   ");
   formatPool (statwin, stats.mana, stats.max_mana,
              "Mana    : ", true);

   formatStat (statcol, statwin, stats.wis, stats.base_wis, 
              "Wisdom       : ", false);
   statwin:Tell ("   ");
   formatPool (statwin, stats.moves, stats.max_moves,
              "Moves   : ", true);
   
   formatStat (statcol, statwin, stats.dex, stats.base_dex, 
              "Dexterity    : ", true);

   formatStat (statcol, statwin, stats.con, stats.base_con, 
              "Constitution : ", false);
   statwin:Tell ("   ");
   formatSingle (statcol, statwin, stats.hitroll,
              "Hitroll : ", true);

   formatStat (statcol, statwin, stats.luck, stats.base_luck, 
              "Luck         : ", false);
   statwin:Tell ("   ");
   formatSingle (statcol, statwin, stats.damroll,
              "Damroll : ", true);
       
   statwin:Note ("")

   statwin:ColourNote (
      labelcol, "", "Exp to Level : ", 
      statcol,  "", string.format ("%5d     ", stats.to_level), 
      labelcol, "", "Level   : ",
      "#00ee00", "", string.format ("%5d", stats.level));
      
   statwin:ColourNote (
      labelcol, "", "Alignment    : ", 
      statcol,  "", string.format ("%5d     ", stats.align), 
      labelcol, "", "Gold    : ", 
      "#eeee00","", string.format ("%5d", stats.gold));

   statwin:Note ("")

   ---colorBar ("Health", stats.hp_percent,    statwin);
   ---colorBar ("Mana",   stats.mana_percent,  statwin);
   ---colorBar ("Moves ", stats.moves_percent, statwin);

   statwin:Note ("")
   statwin:ColourNote ("#eeeeee", "", stats.doing);
 
   --- Enemy percent 9999 is hax for 'no enemy' :)
   ---if  (stats.enemy_percent ~= "9999") then
   ---  colorBar ("Enemy", stats.enemy_percent, statwin);
   ---end

end -- Stat_Start


--- 
--- Format display of a stat/base
---
function formatStat(statcol, w, current, base, label, cr)
  sepcol = "#00d6d6";
  if base == nil or current == nil then return end
  str = {
    sepcol,  "", label, 
    statcol, "", string.format("%3d",current),
    sepcol,  "", "/",
    statcol, "", string.format("%-3d",base)
    };
    
  if cr then
    w:ColourNote (unpack(str));
  else
    w:ColourTell (unpack(str));
  end
end

--- 
--- Format display of a 5d stat, probably a better way to combine these two
---
function formatPool(w,current,base,label,cr)
  statcol= "#eeeeee";
  sepcol = "#00d6d6";
  if base == nil or current == nil then return end
  str = {
    sepcol,  "", label,
    statcol, "", string.format("%5d",current),
    sepcol,  "", "/",
    statcol, "", string.format("%-5d",base)};
  if cr then
    w:ColourNote (unpack(str));
  else
    w:ColourTell (unpack(str));
  end
end

---
--- Format display of a single stat.
---
function formatSingle(statcol, world,current,label,cr)
  sepcol = "#00d6d6";
  if current == nil then return end

  str = {sepcol,"black",label,statcol,"black",string.format("%5d",current)};
  if cr then
     world:ColourNote(unpack(str));
  else
     world:ColourNote(unpack(str));
  end  
end

--
-- Draw colored bars based on percentage input.
---
function colorBar (label, pct, world)
  if pct == nil then return end

  -- show at most 7 x #
  local function show_blocks (color, number)
    world:ColourTell (color, "", string.rep ("#", math.min (number, 7)))
    return number - 7
  end -- function

  local blocks = pct / 3

  world:ColourTell ("#eeeeee", "",
              string.format ("%-7s: (%3i%%) ", label, pct))

  local colors = { "#880000",   -- red
                   "#d6d600",   -- yellow
                   "#d2d2d2",   -- gray
                   "#ffffff",   -- white
                   "#00d600" }  -- green

  for i = 1, #colors do
    if blocks <= 0 then
      break  -- all done
    end
    blocks = show_blocks (colors [i], blocks)
  end -- for

  world:Note "" -- wrap up line
end -- function colourBar

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
  
  OnPluginEnable ()  -- do initialization stuff
  
end -- OnPluginInstall

function OnPluginEnable()
  
  -- ensure world file exists
  local w = get_a_world (worldname, folder)

  if w == nil then
     CallPlugin ("35dfdbf3afc8cbf60c91277c", "CreateWorldFile", folder .. "," .. chat_world)
     w = get_a_world (chat_world, folder)
  end   
  
  if w then
    w:DeleteOutput ()
    w:Note "Stats will appear here."
    w:SetOption ("do_not_show_outstanding_lines", 1)
    w:SetOption ("do_not_add_macros_to_command_history", 1)
    w:SetOption ("auto_resize_command_window", 0)
    w:SetCommandWindowHeight (0)  -- no command window
    w:SetWorldWindowStatus (3) -- restore it     
  end -- no world
 
  -- check our stats detector is there
  checkplugin ("8a710e0783b431c06d61a54c", "Stats_Detector.xml")
  
end -- OnPluginEnable

function OnPluginDisable()
  local w = get_a_world (worldname, folder)
  if w then
    w:SetWorldWindowStatus (2) -- minimize it on disable
  end -- if 
end -- OnPluginDisable

function OnPluginSaveState ()
  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
end -- OnPluginSaveState


]]>
</script> 

</muclient>

