<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<!--
Copyright(C) 2006 Soonil Nagarkar

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA  02111-1307  USA
-->

<!--
$Rev: 65 $
$Date: 2008-11-06 17:06:18 -0500 (Thu, 06 Nov 2008) $
$Author: sunflame $
$HeadURL: https://achaeasys.svn.sourceforge.net/svnroot/achaeasys/AchaeaCuringSystem2.xml $
-->

<muclient>
<plugin
  name="AchaeaCuringSystem"
  author="Sunflame"
  id="c3fda3e0e77a5fbebf3c5e10"
  language="Lua"
  purpose="Achaea Curing System (ACS 2.0)"
  save_state="y"
  date_written="2008-10-21 15:00:32"
  requires="3.80"
  version="1.00"
>

<description trim="y">
<![CDATA[
Props to the following people who have helped in various ways...

Sunflame
Tsunami
Larkin
Nexes
Nick Gammon

Beta Testers:

Hatori
Alexan
Relgar
Nexes

Disclaimer: This is in no way related to the ACP, a system for zMud coded and
maintained by Larkin. Larkin does not offer support for the ACS, nor do I offer
support for the ACP.

For your ease of use, all documentation has been placed within the /docs folder 
within the ACS2 root. Please refer there for instructions on how to install and 
use this plugin properly. Also included is a development manual for coding your 
own plugins for the ACS2. Please read the docs for licensing information before
using this plugin.
]]>
</description>
</plugin>

<aliases>
  <alias
   name="acs_startup"
   match="^acs startup$"
   enabled="y"
   group="acs"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
world.Execute('acs curing on')
world.Execute('acs health on')
world.Execute('acs mana on')
world.Execute('acs def on')
world.Execute('acs deftracking on')
world.Execute('acs track base')
world.Execute('acs bashing on')
world.Execute('acs addclass all')
world.Execute('acs autoparry on')
world.Execute('exits')
</send>
  </alias>
  <alias
   name="acs_help"
   match="^acs(:|\s)help$"
   enabled="y"
   group="acs"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Debugging:
 acs debug &lt;on|off&gt;
 acs array &lt;lua_array&gt;
 acs variable &lt;lua_array&gt;

Common:
 acombat &lt;on|off&gt;
 combat &lt;on|off&gt;

 acs config &lt;option&gt;

 pause
 unpause

Healing:
 acs health &lt;on|off&gt;
 acs mana &lt;on|off&gt;
 acs moss &lt;on|off&gt;

 acs priority &lt;health|mana&gt;

 dh - drink health
 dm - drink mana
 emm
 tt
 touch tree

Curing:
 acs curing &lt;on|off&gt;

 affclear
 unaeon
 unstun

 acs bashing &lt;on|off&gt;

 acs addclass &lt;class|all&gt;
 acs removeclass &lt;class|all&gt;
 acs classonly &lt;class&gt;

Defences:
 acs def &lt;on|off&gt;

 acs deftracking &lt;on|off&gt;
 acs track &lt;defence&gt; &lt;on|off&gt;
 acs track &lt;none|base|all&gt;

Enemy:
 acs tar &lt;target&gt;
 acs autoparry &lt;on|off&gt;

Pipes:
 acs &lt;valerian|skullcap|elm&gt;pipe &lt;pipe#&gt;

 fps - fill pipes
 lps - light pipes
 eps - empty pipes
 gps - get pipes

 smoke &lt;elm|skullcap|valerian&gt;

Plugins:
 acs addplugin &lt;plugin&gt;
 acs removeplugin &lt;plugin&gt;
 acs plugins</send>
  </alias>

  <!-- DEBUG -->
  
  <alias
   name="Debug"
   script="set_debug"
   ignore_case="y"
   match="^acs debug (on|off)$"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   name="CureDebug"
   script="set_cure_debug"
   ignore_case="y"
   match="^acs cure debug (on|off)$"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   send_to="12"
   ignore_case="y"
   match="^acs array (.+)$"
   enabled="y"
   regexp="y"
  >
  <send>arraystate(%1)</send>
  </alias>
  <alias
   send_to="12"
   ignore_case="y"
   match="^acs variable (.+)$"
   enabled="y"
   regexp="y"
  >
  <send>variablestate(%1)</send>
  </alias>
  
  <!-- OPTIONS -->
  
  <alias
   script="show_config"
   ignore_case="y"
   match="^acs config$"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   script="set_option"
   ignore_case="y"
   match="^acs config (\w+)$"
   enabled="y"
   regexp="y"
  >
  </alias>
  
  <!-- PLUGINS -->
  
  <alias
   script="add_plugin"
   ignore_case="y"
   match="^acs addplugin (\w+)$"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   script="remove_plugin"
   ignore_case="y"
   match="^acs removeplugin (\w+)$"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   script="list_plugins"
   ignore_case="y"
   match="^acs plugins$"
   enabled="y"
   regexp="y"
  >
  </alias>
  
  <!-- COMBAT -->
  
  <alias
   name="ArenaCombat"
   script="arena_combat"
   ignore_case="y"
   match="^acombat (on|off)$"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   name="Combat"
   script="live_combat"
   ignore_case="y"
   match="^combat (on|off)$"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   script="reset_all"
   ignore_case="y"
   match="^acs reset$"
   enabled="y"
   regexp="y"
  >
  </alias>
  
  <!-- PAUSE/UNPAUSE SYSTEM -->
  
  <alias
   ignore_case="y"
   match="^pause$"
   enabled="y"
   regexp="y"
   script="pause"
  >
  </alias>
  <alias
   ignore_case="y"
   match="^unpause$"
   enabled="y"
   regexp="y"
   script="unpause"
  >
  </alias>
</aliases>

<triggers>

  <!-- DEATH -->
  
  <trigger
   enabled="y"
   match="^You have been slain by (.+)\.$"
   regexp="y"
   script="prepare_death"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   match="^Your starburst tattoo flares as the world is momentarily tinted red\.$"
   regexp="y"
   script="prepare_death"
   sequence="100"
  >
  </trigger>

  <!-- ARENA OFF TRIGGERS -->
  
  <trigger
   name="ArenaCombatOff"
   enabled="n"
   match="^(The spectator stands of the Colosseum Diabolus|Colosseum Diabolus staging grounds|Spectator stands in the Collosea en Duir|Staging Grounds for the Collosea en Duir|Cyrenian spectator stands|Cyrenian staging grounds|The Shallamese Arena Staging ground|The spectator stands of the Maran La\'Saen Memorial Arena|The spectator stands of the Matsuhama Arena|Arena Staging Grounds|Spectator stands of the Stadia Coronae|Outside the Gates of the Stadia Coronae|The spectator enclosure|The arena gates)\.$"
   regexp="y"
   script="combat_off"
   match_text_colour="y"
   text_colour="11"
   sequence="100"
  >
  </trigger>
</triggers>

<script>
<![CDATA[
PLUGIN_VERSION = world.GetPluginInfo(world.GetPluginID(), 19)
PLUGIN_AUTHOR = world.GetPluginInfo(world.GetPluginID(), 2)
PLUGIN_NAME = world.GetPluginInfo(world.GetPluginID(), 1)
CTRL_DEBUG = false

--require "flc.kutils"
local plug_name = GetPluginInfo(GetPluginID(), 1) or "main world"

function DoNote(msg)
  AnsiNote(ANSI(33), "[", ANSI(36), plug_name, ANSI(33), "]: ", ANSI(37), msg, ANSI(0))
end

function DoAlertNote(msg)
  AnsiNote(ANSI(33), "[", ANSI(36), plug_name, ANSI(33), "]: ", ANSI(31,1), "Alert: " .. msg, ANSI(0))
end

function DoErrorNote(msg)
  AnsiNote(ANSI(33), "[", ANSI(36), plug_name, ANSI(33), "]: ", ANSI(31,1), "Error: " .. msg, ANSI(0))
end

function NoteCured(affl)
  local str = "   [CURED]: " .. affl .. "   "
  ColourNote("","", string.rep(" ", (60-#str)/2),"mediumspringgreen", RGBColourToName(15872), str)
end

function DoDebugNote(msg)
  AnsiNote(ANSI(33), "[", ANSI(36), plug_name, ANSI(33), "]: ", ANSI(32,1), "Debug: " .. msg, ANSI(0))
end

system = {}

--THESE THREE SHOULD NOT BE RELIED UPON
system.live					= false
system.arena				= false
system.bashing				= false

system.afflictions			= false
system.defences				= false
system.paused				= false

system.illusion_check		= false
system.auto_parry			= false

--nil signifies not set yet

config = {}
config.installed			= false

config.lag					= -1

config.parry_method			= 'parry'
config.actionnote			= 'YOU ARE READY'
config.deathnote			= 'YOU HAVE DIED'

config.enemy_on_reject		= false
config.arm_balance			= true

config.use_tree				= false
	config.tree_balance		= 35
	
config.use_insomnia			= false
config.use_focus			= false
config.use_deathsight		= false
config.use_thirdeye			= false

config.min_mental_mana		= .5
config.clot_value			= 60

config.healthheal_percent	= .85
config.manaheal_percent		= .8
config.mosshealth_percent	= .5
config.mossmana_percent		= .5
config.health_priority		= true

plugins = {}

DoNote(PLUGIN_NAME .. ' v' .. PLUGIN_VERSION .. ' - ' .. PLUGIN_AUTHOR)

--INIT RAND
world.MtSrand(world.GetInfo(304))

function OnPluginInstall()
	prompt.maxhealth = tonumber(world.GetVariable('MaxHealth') or 1000)
	prompt.maxmana = tonumber(world.GetVariable('MaxMana') or 1000)
	
	prompt.health = prompt.maxhealth
	prompt.mana = prompt.maxmana
	
	pipes.elm.num = world.GetVariable('ElmPipe') or '<elmpipe>'
	pipes.skullcap.num = world.GetVariable('SkullcapPipe') or '<skullcappipe>'
	pipes.valerian.num = world.GetVariable('ValerianPipe') or '<valerianpipe>'
	
	local config_list = unserialize(world.GetVariable('Config') or '<t></t>')
	for option,value in pairs(config_list) do
		config[option] = value
	end
	
	if(not config.installed) then
		install()
	elseif(world.GetVariable('CharacterName') == nil) then
		set_charactername()
	end
	
	local plugin_list = unserialize(world.GetVariable('Plugins') or '<t></t>')
	for plugin,_ in pairs(plugin_list) do
		add_plugin('','',{plugin})
	end
	
	if(world.IsConnected()) then
		set_stats()
	end
	
	reset_lag_trigger()
end
function OnPluginSaveState()
	world.SetVariable('MaxHealth', prompt.maxhealth)
	world.SetVariable('MaxMana', prompt.maxmana)
	
	world.SetVariable('ElmPipe', pipes.elm.num)
	world.SetVariable('SkullcapPipe', pipes.skullcap.num)
	world.SetVariable('ValerianPipe', pipes.valerian.num)
	
	world.SetVariable('Config', serialize(config))
	world.SetVariable('Plugins', serialize(plugins))
	
	for plugin,_ in pairs(plugins) do
		if(_G[string.lower(plugin) .. '_plugin_uninstall']) then
			_G[string.lower(plugin) .. '_plugin_uninstall']()
		end
	end
end

--BEGIN LAG CHECK

function OnPluginSent()
	if(world.IsConnected() and config.lag > 0) then
		prompt.commands = prompt.commands + 1
		
		if(prompt.commands > config.lag and prompt.commands - 1 <= config.lag) then
			DoNote('LAG - FAILSAFES PAUSED.')
			pause_failsafes()
		end
	end
end

--REMOVE LAG

function reset_lag_trigger()
	--[[
	if(config.lag > 0 and OnPluginLineReceived == nil) then
		OnPluginLineReceived = system.lag_pointer
	elseif(config.lag < 1 and not (OnPluginLineReceived == nil)) then
		system.lag_pointer = OnPluginLineReceived
		OnPluginLineReceived = nil
	end
	--]]
end

--COMBAT ALIASES

function arena_combat(name,output,wildcs)
	system.arena = (string.lower(wildcs[1]) == 'on')
	if(system.arena) then system.live = false end
	
	sipping.healthing = system.arena
	sipping.manaing = system.arena
	sipping.mossing = system.arena
	
	system.illusion_check = false
	set_autoparrying_alias(system.arena)
	
	clean_balances()
		
	clean_afflictions()
	add_all_classes()
	set_afflictions_alias(system.arena)
	set_bashing_alias(false)
	
	clean_defences(total)
	tracking.def_reset = true
	set_defences_alias(true)
	
	world.EnableTrigger('ArenaCombatOff',system.arena)
	
	if(system.arena) then
		pipes_light()
		DoNote('***ARENA COMBAT ENABLED, USE DEF TO RESET DEFENCES, LOAD APPROPRIATE CLASSES***')
	else
		DoNote('***ARENA COMBAT DISABLED***')
	end
end
function live_combat(name,output,wildcs)
	system.live = (string.lower(wildcs[1]) == 'on')
	system.arena = false
	
	world.EnableTrigger('ArenaCombatOff',false)
	
	sipping.healthing = system.live
	sipping.manaing = system.live
	sipping.mossing = false
	
	system.illusion_check = false
	set_autoparrying_alias(system.live)
	
	clean_balances()
		
	clean_afflictions()
	add_all_classes()
	set_afflictions_alias(system.live)
	
	clean_defences(total)
	tracking.def_reset = true
	set_defences_alias(true)
	
	if(system.live) then
		world.Send('outr 1 goldenseal')
		world.Send('outr 1 bloodroot')
		
		pipes_light()
		
		DoNote('***COMBAT ENABLED, USE DEF TO RESET DEFENCES, LOAD APPROPRIATE CLASSES***')
	else
		DoNote('***COMBAT DISABLED***')
	end
end
function combat_off()
	if(system.arena) then
		arena_combat('','',{'off'})
		prompt.watch_death = false
	else
		live_combat('','',{'off'})
	end
	
	world.EnableTrigger('ArenaCombatOff',false)
	world.DoAfterNote(7,'---INR ALL HERBS AND PUT AWAY GOLD---')
end

--DEATH FUNCTION

function prepare_death()
	prompt.watch_death = true
end
function death()
	DoNote('===' .. string.rep('=',string.len(config.deathnote)) .. '===')
	DoNote('== ' .. config.deathnote .. ' ==')
	DoNote('===' .. string.rep('=',string.len(config.deathnote)) .. '===')
	DoNote()
	
	if(system.arena) then
		
	else
		pause()
	end
	
	clean_balances()
	if(system.afflictions) then clean_afflictions() end
	if(system.defences) then clean_defences(total) end
end

--RESET

function reset_all()
	clean_balances()
	--clean_afflictions()
	--clean_defences(true)
	
	system.paused = false
	
	DoNote('***ACS RESET***')
end

--PAUSE

function pause()
	system.paused = true
	DoNote('---ACS PAUSED---')
end
function unpause()
	if(system.paused) then
		system.paused = false
		DoNote('---ACS UNPAUSED---')
		
		recheck_balances()
		prompt.cure = true
	end
end

function pause_failsafes()
	failsafes = {
		healthmana = world.GetTimerInfo('HealthManaTimer',6),
		moss = world.GetTimerInfo('MossBalanceTimer',6),
		herb = world.GetTimerInfo('HerbBalanceTimer',6),
		salve = world.GetTimerInfo('SalveBalanceTimer',6),
		elixir = world.GetTimerInfo('ElixirBalanceTimer',6),
		pipe = world.GetTimerInfo('PipeBalanceTimer',6),
		standing = world.GetTimerInfo('StandingBalanceTimer',6),
		waking = world.GetTimerInfo('WakingBalanceTimer',6),
		writhing = world.GetTimerInfo('WrithingBalanceTimer',6)
	}
	
	world.EnableTimer('HealthManaTimer',false)
	world.EnableTimer('MossBalanceTimer',false)
	world.EnableTimer('HerbBalanceTimer',false)
	world.EnableTimer('SalveBalanceTimer',false)
	world.EnableTimer('ElixirBalanceTimer',false)
	world.EnableTimer('PipeBalanceTimer',false)
	world.EnableTimer('StandingBalanceTimer',false)
	world.EnableTimer('WakingBalanceTimer',false)
	world.EnableTimer('WrithingBalanceTimer',false)
	DoNote(tostring(world.GetTimerInfo('HerbBalanceTimer',6)))
end
function unpause_failsafes()
	if(not (type(failsafes) == 'table')) then
		return
	end
	
	if(failsafes.healthmana) then world.EnableTimer('HealthManaTimer',true) end
	if(failsafes.moss) then world.EnableTimer('MossBalanceTimer',true) end
	if(failsafes.herb) then world.EnableTimer('HerbBalanceTimer',true) end
	if(failsafes.salve) then world.EnableTimer('SalveBalanceTimer',true) end
	if(failsafes.elixir) then world.EnableTimer('ElixirBalanceTimer',true) end
	if(failsafes.pipe) then world.EnableTimer('PipeBalanceTimer',true) end
	if(failsafes.standing) then world.EnableTimer('StandingBalanceTimer',true) end
	if(failsafes.waking) then world.EnableTimer('WakingBalanceTimer',true) end
	if(failsafes.writhing) then world.EnableTimer('WrithingBalanceTimer',true) end
end

--INSTALL FUNCTIONS

function install()
	set_charactername()
	set_parrymethod()
	set_actionnote()
	set_deathnote()
	set_skills()
	remind_pipes()
	
	config.installed = true
end

function set_skills()
	local skills = {tree='TREE TATTOO',recovery='RECOVERY (Survival)',clot='CLOTTING (Survival/Kaido)',insomnia='INSOMNIA (Survival)',focus='FOCUS (Survival)',deathsight='DEATHSIGHT (Vision)',thirdeye='THIRDEYE (Vision)'}
	local result = utils.multilistbox('Please select all of the following tattoos/skills that your character possesses (Shift-Click and Ctrl-Click to select):','Skills',skills)
	
	if(result and type(result) == 'table') then
		config.use_tree = result.tree and true
		config.tree_balance = result.recovery and 12 or 35
		config.clot_value = result.clot and config.clot_value or 0
		config.use_insomnia = result.insomnia and true
		config.use_focus = result.focus and true
		config.use_deathsight = result.deathsight and true
		config.use_thirdeye = result.thirdeye and true
	end
end

function set_charactername()
	local result = utils.inputbox('What is your character name (case-sensitive)?','Character Name',config.character_name or '');
	if(result) then world.SetVariable('CharacterName',result) end
end
function set_parrymethod()
	local choices = {'parry','guard'}
	local result = utils.choose('Which command will you parry with?','Auto-Parry',choices,1)
	config.parry_method = choices[result] or 'parry'
end
function set_actionnote()
	local result = utils.inputbox('What would you like to display to notify yourself of complete readiness (leave blank to disable)?','Action Note',config.actionnote or 'YOU ARE READY');
	config.actionnote = ((not result) or (result == '')) and false or result
end
function set_deathnote()
	local result = utils.inputbox('What would you like to display to notify yourself of death (leave blank to disable)?','Death Note',config.deathnote or 'YOU HAVE DIED');
	config.deathnote = ((not result) or (result == '')) and false or result
end
function set_clotting()
	local result = utils.msgbox('Do you wish to use the CLOT skill?','Clotting','yesno','?',1)
	config.clot_value = (result == 'yes') and (config.clot_value or 60) or 0
	world.EnableTriggerGroup('Clotting',system.afflictions and not (config.clot_value == 0))
end
function set_focus()
	local result = utils.msgbox('Do you wish to use the FOCUS ability?','Focus','yesno','?',1)
	config.use_focus = (result == 'yes')
end
function set_insomnia()
	local result = utils.msgbox('Do you wish to use the INSOMNIA ability?','Insomnia','yesno','?',1)
	config.use_insomnia = (result == 'yes')
end
function set_minmentalmana()
	local result = utils.inputbox('What is the minimum mana percentage at which to use mental abilities (FOCUS, INSOMNIA, etc...)?','Minimum Mana',(config.min_mental_mana or .5)*100)
	config.min_mental_mana = result and tonumber(result)/100 or .5
end
function set_tree()
	local result = utils.msgbox('Do you wish to use a tree tattoo?','Tree Tattoo','yesno','?',1)
	config.use_tree = (result == 'yes')
end
function set_recovery()
	local result = utils.msgbox('Do you have the RECOVERY skill?','Recovery','yesno','?',1)
	config.tree_balance = (result == 'yes') and 12 or 35
end
function remind_pipes()
	utils.msgbox('Remember to set all your pipe variables before you start to use the ACS2.','Pipes','ok','!',1)
end

function set_enemyonreject()
	local result = utils.msgbox('Do you wish to enemy people upon rejecting them?','Enemy on Rejection','yesno','?',1)
	config.enemy_on_reject = (result == 'yes')
end
function set_armbalance()
	local result = utils.msgbox('Do you wish to track arm balance (only applicable to monks, but will do no harm in any case)?','Arm Balance','yesno','?',1)
	config.arm_balance = (result == 'yes')
end
function set_healthsip()
	local result = utils.inputbox('What is the maximum health percentage at which to sip health?','Sip Health',(config.healthheal_percent or .85)*100)
	config.healthheal_percent = result and tonumber(result)/100 or .85
end
function set_manasip()
	local result = utils.inputbox('What is the maximum mana percentage at which to sip mana?','Sip Mana',(config.manaheal_percent or .8)*100)
	config.manaheal_percent = result and tonumber(result)/100 or .8
end
function set_mosshealtheat()
	local result = utils.inputbox('What is the maximum health percentage at which to eat moss?','Eat Moss - Health',(config.mosshealth_percent or .5)*100)
	config.mosshealth_percent = result and tonumber(result)/100 or .5
end
function set_mossmanaeat()
	local result = utils.inputbox('What is the maximum mana percentage at which to eat moss?','Eat Moss - Mana',(config.mossmana_percent or .5)*100)
	config.mossmana_percent = result and tonumber(result)/100 or .5
end
function set_healthpriority()
	local result = utils.msgbox('Do you wish to prioritize mana over health?','Mana Priority','yesno','?',1)
	config.health_priority = not (result == 'yes')
end
function set_lag()
	local result = utils.msgbox('Would you like to use lag protection (Experimental feature)?','Lag Protection','yesno','?',2)
	config.lag = (result == 'yes') and 10 or -1
	reset_lag_trigger()
end

--CONFIG OPTION FUNCTIONS

function set_option(name,output,wildcs)
	wildcs[1] = string.lower(wildcs[1])
	
	if(wildcs[1] == 'character_name') then
		set_charactername()
	elseif(wildcs[1] == 'parry_method') then
		set_parrymethod()
	elseif(wildcs[1] == 'action_note') then
		set_actionnote()
	elseif(wildcs[1] == 'death_note') then
		set_deathnote()
	elseif(wildcs[1] == 'enemy_on_reject') then
		set_enemyonreject()
	elseif(wildcs[1] == 'arm_balance') then
		set_armbalance()
	elseif(wildcs[1] == 'use_tree') then
		set_tree()
	elseif(wildcs[1] == 'recovery_balance') then
		set_recovery()
	elseif(wildcs[1] == 'use_focus') then
		set_focus()
	elseif(wildcs[1] == 'use_insomnia') then
		set_insomnia()
	elseif(wildcs[1] == 'min_mental_mana') then
		set_minmentalmana()
	elseif(wildcs[1] == 'clotting') then
		set_clotting()
	elseif(wildcs[1] == 'healthheal_percent') then
		set_healthsip()
	elseif(wildcs[1] == 'health_sip') then
		set_healthsip()
	elseif(wildcs[1] == 'manaheal_percent') then
		set_manasip()
	elseif(wildcs[1] == 'mana_sip') then
		set_manasip()
	elseif(wildcs[1] == 'moss_health_eat') then
		set_mosshealtheat()
	elseif(wildcs[1] == 'moss_mana_eat') then
		set_mossmanaeat()
	elseif(wildcs[1] == 'mana_priority') then
		set_healthpriority()
	elseif(wildcs[1] == 'skills') then
		set_skills()
	elseif(wildcs[1] == 'lag') then
		set_lag()
	end
end

function show_config()
	DoNote('Config Values')
	for name,value in pairs(config) do
		DoNote('  ' .. name .. string.rep(' ',20-string.len(name)) .. tostring(value))
	end
	DoNote('-----------------------------------')
end

--PLUGIN FUNCTIONS

function add_plugin(name,output,wildcs)
	if(plugins[wildcs[1]]) then
		DoNote('THAT PLUGIN IS ALREADY LOADED.')
		return
	end
	
	loaded,error = pcall(require,'plugins.' .. wildcs[1])
	if(loaded) then
		plugins[wildcs[1]] = true
		if(_G[string.lower(wildcs[1]) .. '_plugin_install']) then
			_G[string.lower(wildcs[1]) .. '_plugin_install']()
		end
		
		DoNote('\'' .. string.upper(wildcs[1]) .. '\' PLUGIN HAS BEEN INSTALLED.')
	else
		DoNote('ERROR LOADING THE ' .. string.upper(wildcs[1]) .. ' PLUGIN: ' .. error)
	end
end
function remove_plugin(name,output,wildcs)
	if(plugins[wildcs[1]]) then
		plugins[wildcs[1]] = nil
		if(_G[string.lower(wildcs[1]) .. '_plugin_uninstall']) then
			_G[string.lower(wildcs[1]) .. '_plugin_uninstall']()
		end
		
		if(not (name == 'noecho')) then
			DoNote('\'' .. string.upper(wildcs[1]) .. '\' PLUGIN WILL BE UNINSTALLED WHEN ACS2 IS RELOADED.')
		end
	else
		DoNote('NO PLUGIN BY THAT NAME INSTALLED.')
	end
end
function list_plugins()
	DoNote('Plugin                   Author              Version')
	DoNote('----------------------------------------------------')
	for plugin,_ in pairs(plugins) do
		local author = (_G[string.upper(plugin) .. '_AUTHOR'] and _G[string.upper(plugin) .. '_AUTHOR'] or 'Unknown')
		local version = (_G[string.upper(plugin) .. '_VERSION'] and _G[string.upper(plugin) .. '_VERSION'] or '-')
		
		DoNote(plugin .. string.rep(' ',25 - string.len(plugin)) .. author .. string.rep(' ',20 - string.len(author)) .. version)
	end
end

--DEBUG FUNCTIONS

function set_debug(name,output,wildcs)
	CTRL_DEBUG = (string.lower(wildcs[1]) == 'on')
	DoDebugNote('DEBUG FUNCTION IS ' .. string.upper(wildcs[1]) .. '.')
end

function set_cure_debug(name,output,wildcs)
	CURE_DEBUG = (string.lower(wildcs[1]) == 'on')
	DoDebugNote('CURE DEBUG FUNCTION IS ' .. string.upper(wildcs[1]) .. '.')
end

function arraystate(table,indent)
	if(not indent) then indent = '  ' end
	for index,value in pairs(table) do
		if(not (type(value) == 'function')) then
			DoNote(indent .. tostring(index) .. ':' .. string.rep(' ',30 - string.len(tostring(index)) - string.len(indent) + 2) .. tostring(value))
			if(type(value) == 'table' and not (value == table)) then
				arraystate(value,indent .. '  ')
			end
		end
	end
end
function variablestate(variable)
	DoNote(variable)
end

function require_error(error)
	DoErrorNote('UNABLE TO LOAD REQUIRED MODULE: ' .. error)
end

--SERIALIZATION FUNCTIONS

function serialize(var,compression)
	if(type(var) == 'table') then
		local output = ''
		for index,value in pairs(var) do
			if(not (value == var)) then
				output = output .. '<i i="' .. index .. '">' .. serialize(value) .. '</i>'
			end
		end
		
		if(compression) then
			return '<ct>' .. utils.base64encode(utils.compress(output,9)) .. '</ct>'
		else
			return '<t>' .. output .. '</t>'
		end
	elseif(type(var) == 'number') then
		return '<n>' .. var .. '</n>'
	elseif(type(var) == 'string') then
		return '<s>' .. var .. '</s>'
	elseif(type(var) == 'boolean') then
		return '<b>' .. (var and 't' or 'f') .. '</b>'
	end
	
	return ''
end
function unserialize(var)
	if(var == nil) then
		return nil
	end
	
	local root = utils.xmlread(var)	
	
	if(root) then
		return unserialize_xml(root.nodes[1])
	else
		return nil
	end
end
function unserialize_xml(node)
	if(node.name == 'n') then return tonumber(node.content) end
	if(node.name == 's') then return tostring(node.content) end
	if(node.name == 'b') then return (tostring(node.content) == 't') end
	
	if(node.name == 'ct') then
		node.name = 't'
		local root = utils.xmlread(utils.decompress(utils.base64decode(node.content)))
		
		if(root) then
			node.nodes = root.nodes
		else
			return {}
		end
	end
	
	if(node.name == 't') then
		local t = {}
	
		if(node.nodes) then
			for _,child in ipairs(node.nodes) do
				if(child.name == 'i') then
					t[child.attributes['i']] = unserialize_xml(child.nodes[1])
				end
			end
		end
		
		return t
	end
	
	return nil
end

-- ATCP code
-- this script borrows heavily from Keldar's ATCP plugin
-- it was also pulled from Trevize's plugin

Z = {
  tpairs = function (tbl)
    local i = 0
    return function ()
      i = i + 1
      if tbl[i] ~= nil then return tbl[i] end
    end -- func
  end, -- func
  }

tpairs = Z.tpairs



client_id =  "Muclient ".. Version()

nexus_opts = {
  {"hello", client_id},
  {"auth", "1"},
  {"char_name", "1"},
  {"char_vitals", "1"},
  {"room_brief", "1"},
  {"room_exits", "1"},
}

codes = {
  ["IAC WILL ATCP"] = "\255\251\200",
  ["IAC WONT ATCP"] = "\255\252\200",
  ["IAC DO ATCP"]   = "\255\253\200",
  ["IAC DONT ATCP"] = "\255\254\200",
  ["IAC SB ATCP"]   = "\255\250\200",
  ["IAC SE"]        = "\255\240",
  ["IAC DO EOR"]    = "\255\253\025",
  ["IAC WILL EOR"]  = "\255\251\025",
  ["IAC GA"]        = "\255\249",
}


SendATCP = function (msg)
  SendPkt(codes["IAC SB ATCP"] .. msg .. codes["IAC SE"])
end

leftovers = ""

PAT = codes["IAC SB ATCP"] .. "(.-)" .. codes["IAC SE"]



OnPluginBroadcast = function (msg, id, name, text)
  if (id == "7c08e2961c5e20e5bdbf7fc5") then
    if (msg == 0) then
      EnableModuleATCP("room_brief")
      EnableModuleATCP("room_exits")
      EnableModuleATCP("char_vitals")
    else
      local sep = text:find("|")
      local msg, text = text:sub(1, sep-1), text:sub(sep+1)

      if (msg == "Room.Brief") then
        BroadcastPlugin(2, text)
      elseif (msg == "Room.Exits") then
        BroadcastPlugin(3, text)
      elseif (msg == "Char.Vitals") then
        BroadcastPlugin(1, text)
      end -- if
    end -- if
  end -- if
end -- func

]]>
</script>

<include name="$PLUGINDIR\modules\LuaInit.xml"/>
<include name="$PLUGINDIR\modules\PromptTriggers.xml"/>
<include name="$PLUGINDIR\modules\BalanceTriggers.xml"/>
<include name="$PLUGINDIR\modules\AfflictionTriggers.xml"/>
<include name="$PLUGINDIR\modules\DefenceTriggers.xml"/>
<include name="$PLUGINDIR\modules\PipeTriggers.xml"/>
<include name="$PLUGINDIR\modules\TreeTriggers.xml"/>
<include name="$PLUGINDIR\modules\FocusTriggers.xml"/>
<include name="$PLUGINDIR\modules\DiagTriggers.xml"/>
<include name="$PLUGINDIR\modules\DefTriggers.xml"/>
<include name="$PLUGINDIR\modules\TargetTriggers.xml"/>

</muclient>
