View Single Post
09-04-20, 08:15 AM   #11
benots4
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 20
Code:
local DebugLevel = 3
local THISAP = "AMine"
AMine = LibStub("AceAddon-3.0"):NewAddon("AMine")
--local ActionBars = {'Action','MultiBarBottomLeft','MultiBarBottomRight','MultiBarRight','MultiBarLeft'}
local ActionBars = {'Action','MultiBarBottomLeft'} -- choose from above to scan for actions
local actionList = {}
local displaySlots = {}
local lastTime = GetTime()
local mainFrame
local gate = true
local loginLock = false  -- multiple action bar changed events during login causes issues
-- Variables to be in config file
local LOOPTIME = 0.25 --0.15
local STOPIT= false
local GATEUPDATE = true
local GCD = false
--local PRIORITYDEPTH = 2
-- string colors
local LIGHT_BLUE  = "|cff00ccff"
local LIGHT_RED   = "|cffff6060"
local GREEN       = "|cff71C671"
local LIGHT_GREEN = "|cff71FF71"
local YELLOW      = "|cffffff00"
local GRAY        = "|cff888888"
local GOLD        = "|cffffcc00"
local RED         = "|cffff0000"
local WHITE       = "|cffffffff"
local function AddColor(str,color)
 return color..str.."|r"
end

--------------------- slash command
SLASH_TEST1 = "/am"
SLASH_TEST2 = "/ab"
 local defaults = {
		profile = {
				enabled = true,
				DebugLevel = 0,
				NumOCells = 5,
				MFpoint = "TOP",
				MFrelpoint = "BOTTOM",
				MFXOffset = -100 ,
				MFYOffset = 50,
				CLXOffset = 0 ,
				CLYOffset = 0,
				MFOrientation = "Vertical",
				MFIconSize = 25,
				MFAlpha =  .6,
				HealthFactor = .5,
				CellPriorityActions = {"interrupt", "heal" , "increaseStat", "increaseHaste", "damageReduction","removeCC","AOE", "damage", "stun", "increaseSpeed","reduceSpeed", "cc", "mount","PVP", "unknown", "empty"},
			}
		}


	local function copyDefaults(src, dst)
		-- If no source (defaults) is specified, return an empty table:
		if type(src) ~= "table" then return {} end
		-- If no target (saved variable) is specified, create a new table:
		if type(dst) then dst = {} end
		-- Loop through the source (defaults):
		for k, v in pairs(src) do
			-- If the value is a sub-table:
			if type(v) == "table" then
				-- Recursively call the function:
				dst[k] = copyDefaults(v, dst[k])
			-- Or if the default value type doesn't match the existing value type:
			elseif type(v) ~= type(dst[k]) then
				-- Overwrite the existing value with the default one:
				dst[k] = v
			end
		end
		-- Return the destination table:
		return dst
	end

	-- Copy the values from the defaults table into the saved variables table
	-- if it exists, and assign the result to the saved variable:
--	MyAddonDB = copyDefaults(defaults, MyAddonDB)
function parseCommands(mesg)
local slin = strlen(mesg)
local tstart, tend = strfind(mesg, "(%a)")
local msg = string.match(mesg, "(%a)", tstart)
	tstart, tend = strfind(mesg, "(%d+)", tend)
	if tstart == nil then 
		return msg, 0 , 0  -- no arguments
	else
		arg = string.match(mesg, "%d+",tend) 
		tstart, tend = strfind(mesg, "(%d+)", tend)
		if tstart == nil then 
			return msg , arg , 0-- 1st argument
		else 
			tstart, tend = strfind(mesg, "(%d+)", tend + 1)
			if tstart == nil then
				return msg , arg , 0-- 1st argument
			else 
				arg, arg2 = string.match(mesg, "(%d+) (%d+)")
				return msg, arg, arg2
			end
		end
	end 
end
function getCommands(mesg)
	msg, arg, arg1, arg2 = string.match(mesg, "(%a+) (%d+) (%d+) (%d+)")
	if msg == nil then 
		msg, arg, arg1 = string.match(mesg, "(%a+) (%d+) (%d+)")
		if msg == nil then 
			msg, arg = string.match(mesg, "(%a+) (%d+)")
			if msg == nil then 
				msg = string.match(mesg, "(%a+)")
				return msg, 0, 0, 0
			else
				return msg, arg, 0, 0
			end 
		else 
			return msg, arg, arg1, 0 
		end 
	else
		return msg, arg, arg1, arg2
	end 

end 
function prntInfo()
	DEFAULT_CHAT_FRAME:AddMessage("AM  " .. AddColor("Slash Commands",GOLD))
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("dlev ",GOLD).. AddColor("level[0-5] ",GREEN) .. " Debug Level")
	DEFAULT_CHAT_FRAME:AddMessage("          " .. AddColor("0",GREEN).." Debug messages off")
	DEFAULT_CHAT_FRAME:AddMessage("          " .. AddColor("1",GREEN).." fake action list info")
	DEFAULT_CHAT_FRAME:AddMessage("          " .. AddColor("2",GREEN).." print Action List")
	DEFAULT_CHAT_FRAME:AddMessage("          " .. AddColor("3",GREEN).." print events")
	DEFAULT_CHAT_FRAME:AddMessage("          " .. AddColor("4",GREEN).." Print update display slots")
	DEFAULT_CHAT_FRAME:AddMessage("          " .. AddColor("5",GREEN).." print Debug test function")
	DEFAULT_CHAT_FRAME:AddMessage("          " .. AddColor("6",GREEN).." print Combat log event ")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("alcnt ",GOLD).. " count of action list items")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("aldmp ",GOLD).. " Dump complete Action List")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("testI ",GOLD).. AddColor(" [action_bar_item] ",GREEN) .. " print results from testing item from action bar")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("tstcll ",GOLD).. AddColor(" [action_bar_item] ",GREEN) .. " print results from testing item from action bar")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("cllprty ",GOLD).. AddColor(" [action_bar_item] ",GREEN) .. " print cell and priority for action item")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("swpcllprty ",GOLD).. AddColor(" [cell] ",GREEN) .. AddColor(" [piortiy_1] ",LIGHT_BLUE) .. AddColor(" [piortiy_2] ",LIGHT_GREEN) .. " swap action item prioriy 1 and 2")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("cllprtys ",GOLD).. AddColor("cell[0-5] ",GREEN) .. " print action items in cell by priority")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("aifromcll ",GOLD).. AddColor("cell[0-5] ",GREEN).. AddColor(" [piortiy_1] ",LIGHT_BLUE) .. " get action item from cell and priority")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("aicllprty ",GOLD).. AddColor("[action_bar_item] ",GREEN) .. " action bar items cell and priortiy")	
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("aivl ",GOLD).. AddColor("[action_bar_item] ",GREEN) .. " action bar item's values")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("splid ",GOLD).. AddColor("[action_bar_item] ",GREEN) .. " Get spellID for action bar item")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("splinf ",GOLD).. AddColor("[spellID] ",GREEN) .. " Get spell info by spellID ")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("splinfbyai ",GOLD).. AddColor("[action_bar_item] ",GREEN) .. " Get spell info for action bar item ")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("aibycllprty ",GOLD).. AddColor("[action_bar_item] ",GREEN) .. " Get action bar item name by cell and priority")
	DEFAULT_CHAT_FRAME:AddMessage("     " .. AddColor("hlth ",GOLD).. AddColor("player / target ",GREEN) .. " Get health of player or target")
end 

SlashCmdList["TEST"] = function(mesg)
	msg, arg, arg2, arg3 = getCommands(mesg)
	if msg == nil then prntInfo()
			return
	end
	if DebugLevel > 0 then print( "msg " .. msg .. " arg " .. arg .. " arg2 ".. arg2 .. " arg3 ".. arg3) end
	if msg == "stop" then if STOPIT then 
		STOPIT = false 
		mainFrame:Show()		
	else 
		STOPIT = true 
		DebugLevel = 0
		mainFrame:Hide()
	end
	elseif msg == "aldmp" then dumpActionList()
	elseif msg == "alcnt" then print("Total actions " .. #actionList)
	elseif msg == "dlev" then 
		AMine.db.profile.DebugLevel = tonumber(arg)
		DebugLevel = tonumber(arg)
		print("Debug Level is " .. DebugLevel)
	elseif msg == "tgate" then if GATEUPDATE == true then GATEUPDATE = false else GATEUPDATE = true end
	elseif msg == "testI" then print(testItem(tonumber(arg), actionList[tonumber(arg)].spells.id ))
	elseif msg == "tstcll" then print(runTests(tonumber(arg), true))
	elseif msg == "cllprty" then printCellPriority(tonumber(arg))
	elseif msg == "swpcllprty" then print(changePriorities(arg, arg2, arg3))
	elseif msg == "cllprtys" then print(printCellPrioritys(tonumber(arg)))
	elseif msg == "aifromcll" then print (findPriorityCell(tonumber(arg), tonumber(arg2)))
	elseif msg == "aicllprty" then printCellPriority(tonumber(arg))
	elseif msg == "aivl" then print (printActionList (tonumber(arg)))
	elseif msg == "aivl" then print (printActionList (tonumber(arg)))
	elseif msg == "splid" then print (actionList[tonumber(arg)].spells.id)
	elseif msg == "spinf" then print(GetSpellInfo(actionList[tonumber(arg)].spells.id))
	elseif msg == "splinfbyai" then print (string.lower(GetSpellDescription(actionList[tonumber(arg)].spells.id)))
	elseif msg == "aibycllprty" then print(findPriorityCell(tonumber(arg)), actionList[tonumber(arg2)].spells.name )
	elseif msg == "hlth" then print(mittigateDamage( "player"))
	elseif msg == "pad" then printActionDamage(tonumber(arg))
	elseif msg == "b" then OnInitialize()
	elseif msg == "c" then action_list()
	elseif msg == "d" then addActionListInfo()
	elseif msg == "e" then mainFrame = createMainFrame()
	elseif msg == "f" then UpdateDisplaySlots(mainFrame)
	elseif msg == "g" then print(UnitCanAttack("player","target"))
	elseif msg == "h" then runLoop(mainFrame)
	elseif msg == "s" then sortActionList()
	elseif msg == "or" then if AMine.db.profile.orientation == "Vertical" then 
		AMine.db.profile.orientation = "Horizontal" 
		AMine.db.profile.MFrelpoint = "TOPRIGHT"
		AMine.db.profile.CLXOffset = 12
		else AMine.db.profile.orientation = "Vertical" 
		AMine.db.profile.MFrelpoint = "BOTTOM"
		AMine.db.profile.CLXOffset = 0
		end
	elseif msg == "gt" then print(GetActionText(tonumber(arg)))
	elseif msg == "dd" then print(debugDescription(tonumber(arg)))
	elseif msg == "pa" then print(PlaceAction(tonumber(arg)))
	elseif msg == "mac" then print(GetMacroBody(actionList[tonumber(arg)].spells.name))GetSpellCooldown(spellID)
	elseif msg == "gsc" then print(GetSpellCooldown(actionList[tonumber(arg)].spells.name))
	elseif msg == "srtcll" then print(sortLoop(tonumber(arg),tonumber(arg2), tonumber(arg3)))
	elseif msg == "findx" then print(findpriorityx(tonumber(arg),tonumber(arg2), tonumber(arg3) ))	
	elseif msg == "di" then print(doItem(actionList[tonumber(arg)].spells.name))	
	elseif msg == "ga" then print(getActionAction(tonumber(arg)))	
	elseif msg == "ca" then print(checkActionAction(tonumber(arg)))	
	elseif msg == "fam" then print(forceActionMemory(tonumber(arg)))
	elseif msg == "wipe" then wipe(AMine.db.profile.actions)
	elseif msg == "getItem" then print(#getListFromDB(AMine.db.profile.items))
					
	end 
end 

 function getListFromDB(DB)
  local items = {} 
	if DB == nil then return "dbEmpty" end
	for index, value in pairs(DB)do
		tinsert(items, index)
	end
	return items	
 end
-----------------------Debug functions 
function debugDescription(actionItem)
local description = GetSpellDescription(actionList[actionItem].spells.id)
	if description then		
	return descriptionMatch(description)
	end
end
function testActionCell()
	return 1 , 2 
end
function printCellPrioritys(cell)
local cntr = 0
			repeat
				cntr = cntr + 1
				found = findPriorityCell(cell, cntr)
				if tonumber(found) then 
					if actionList[tonumber(found)].spells.name ~= nil then 
						print(actionList[tonumber(found)].spells.priority .. "  " .. actionList[tonumber(found)].spells.name .. "  " .. actionList[tonumber(found)].spells.action) 
					end
				end				
			until found == "noCellPriorty"
end 
function printActionList (num)
	print(tostring(actionList[num].spells.name) .. "**********************  " .. num)
	for index, value in pairs(actionList[num].spells) do
		DEFAULT_CHAT_FRAME:AddMessage(tostring(index).." : "..tostring(value) )			
	end
end 
function printCellPriority(j)
	 print(actionList[j].spells.name .. " Cell " .. actionList[j].spells.cell .. " Priority " .. actionList[j].spells.priority)
	
end 
function dumpActionList()
	DEFAULT_CHAT_FRAME:AddMessage(#actionList .. "action List Items Found" )
	for j = 1, #actionList do
		if actionList[j].spells.actionType == "spell" then  print(actionList[j].spells.name .. "**********************  " .. j) end
		for index, value in pairs(actionList[j].spells) do
			DEFAULT_CHAT_FRAME:AddMessage(tostring(index).." : "..tostring(value) )			
		end
	end
end
function printArguments(eventName, ...) -- these change without updates to documents
	local a, b , d, e, f, g, h, i = ...
	print( "*********** " .. eventName)
	if a then print("ar1 " .. tostring(a)) end
	if b then print("ar2 " .. tostring(b)) end
	if c then print("ar3 " .. tostring(c)) end
	if d then print("ar4 " .. tostring(d)) end
	if e then print("ar5 " .. tostring(e)) end
	if f then print("ar6 " .. tostring(f)) end
	if f then print("ar7 " .. tostring(g)) end
	if f then print("ar8 " .. tostring(h)) end
	if f then print("ar9 " .. tostring(i)) end
end 
function printActionDamage(ACTION_ITEM)
		local Slot = actionList[ACTION_ITEM].spells.slot
		local SpellID = actionList[ACTION_ITEM].spells.id
		print(actionList[ACTION_ITEM].spells.name .. " action damage test result is " .. testTargetDamage(Slot, SpellID))
end 

-----------------------Test Functions
function mittigateDamage(unit)
	if tonumber(GetUnitHealth(unit)) < floor(tonumber(UnitHealthMax(unit) * AMine.db.profile.HealthFactor)) then 
		return "doIt"
	else
		return "Healthy"
	end 
end 
function GetUnitHealth(unit)
	local uHealth = -1 
	uHealth = UnitHealth(unit)
	return uHealth  
end 
function testplayerDebuffIsUp(slot, ID)
-- 	name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, isCastByPlayer, nameplateShowAll, timeMod, ... = AuraUtil.FindAuraByName(auraName, unit, filter)
local cntr = 0
repeat 
	cntr = cntr + 1
	local name, icon, a, b, c, etime, d , e, f , source,g, h  , spellid, i, j , castby, k , l ,m   = UnitDebuff("player", cntr)
	if name ~= nil then 
		if source == ID then 
			return name .." Buff is up"
		elseif actionList[slot].spells.name == name then 
			return name .. " Buff Name match"
		end 
	end 
	until name == nil 
	return "doIt"
end 
function testTargetDebuffIsUp(slot, ID)
-- 	name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, isCastByPlayer, nameplateShowAll, timeMod, ... = AuraUtil.FindAuraByName(auraName, unit, filter)
local cntr = 0
repeat 
	cntr = cntr + 1
	local name, icon, a, b, c, etime, d , e, f , source,g, h  , spellid, i, j , castby, k , l ,m   = UnitDebuff("target", cntr)
	if name ~= nil then
		if source == ID then 
			return name .." Buff is up"
		elseif actionList[slot].spells.name == name then 
			return  name .. " Buff Name match"
		end 
	end 
until name == nil
	return "doIt"
end 
function testSelfBuffIsUp(slot, ID)
-- 	name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, isCastByPlayer, nameplateShowAll, timeMod, ... = AuraUtil.FindAuraByName(auraName, unit, filter)
local cntr = 0
repeat 
	cntr = cntr + 1
	local name, icon, a, b, c, etime, d , e, f , source,g, h  , spellid, i, j , castby, k , l ,m   = UnitBuff("player", cntr)
	if name ~= nil then 
		if source == ID then 
			return name .." Buff is up"
		elseif actionList[slot].spells.name == name then 
			return name .. " Buff Name match"
		end 
	end 
	until name == nil 
	return "doIt"
end 
function testItem(slot, itemID)
	local usable, noMana = IsUsableItem(itemID)
		if usable == nil then 
			return "Item test useable is nil"
		elseif usable then 
			if actionList[getActionListNumber("slot",slot)].spells.ranged == false then return "doIt" end
			local inRange = IsActionInRange(actionSlot)
			if inRange == true then 
				local start, duration, enabled = GetItemCooldown(itemID);
				print(duration)
					if  (duration < GCD) then 
						return "doIt"
					else
						return "cooldown"
					end
			elseif inRange == false then return "outORange"
			elseif inRange == nil then return"noTarget"
			end 

		else
			if DebugLevel == 7 then print ( actionList[getActionListNumber("slot",slot)].spells.name .. "  test result unUseable ") end
			return "not useable"
		end 
end
function testNoTarget(actionSlot, spellID)
		if HasAction(actionSlot) == false then return "noAvailableAction" end
		local usable, noMana = IsUsableAction(actionSlot, spellID)
--		print(actionSlot .. " " ..  tostring(usable) .." ".. tostring(noMana))
		if usable == false then 
			if noMana then return "noMana"
			else return "notUseable"
			end
		else
			local start, duration, enabled = GetSpellCooldown(spellID);
			if start == 0 then 
				return "doIt"
			else
				return "cooldown"
			end
		end
end
function isActionInRange(actionItem)
local inRange = IsActionInRange(actionItem)	
	if inRange == true then return "doIt"
	elseif inRange == false then return "outORange"
	elseif inRange == nil then return"noTarget"
	end
end 
function testTargetDamage(actionSlot, spellID)
local gcd
	if actionList[getActionListNumber("slot",actionSlot)].spells.GCD == nil then 
		gcd = 1.5
	elseif actionList[getActionListNumber("slot",actionSlot)].spells.GCD == 0 then 
		gcd = 1.5
	else
		gcd = actionList[getActionListNumber("slot",actionSlot)].spells.GCD
	end 
	if UnitExists("target") then
		if UnitIsDead ("target") == true then return "TargetIsDead" end
		if UnitCanAttack ("player", "target") == false then return "InvalidTarget" end
		local usable, noMana = IsUsableAction(actionSlot)
		if usable == nil then 
			if noMana == 1 then return "noMana" end
		else
			if usable == true then
				local start, duration, enabled, modRate = GetSpellCooldown(spellID);
				if DebugLevel == 8 then print(actionSlot .. " duration " .. duration) end
					if duration < gcd  then -- actionList[getActionListNumber("slot",actionSlot)].spells.GCD then 
						return isActionInRange(actionSlot)
					else
						return "cooldown"
					end
				
				return isActionInRange(actionSlot)
			else  
			if DebugLevel == 8 then 
				if actionSlot == nil then 
				else
--					print (actionList[getActionListNumber("slot",actionSlot)].spells.name .. "  test Action Damage result unUseable ") 
				end
			end
			return "unUseable" 
			end
		end
	else return "noTarget" 
	end
	return "FunctionFail"	
end
function TestCanInterruptSpell(unit)
	if UnitCastingInfo(unit) ~= nil or UnitChannelInfo(unit) ~= nil then
		return "doIt"
	else
		return "NotCasting"
	end
end
function testPvp(unit)
	if UnitIsPVP(unit) == 1 then 
		return "doIt"
	else
		return "NotPVP"
	end
end 
function runTests(j, dbug)
local doIt 
--		if DebugLevel == 5 then printArguments("Test action type " .. actionList[j].spells.actionType .. " with Action " .. actionList[j].spells.action) end
--MOUNT		
		if actionList[j].spells.action == "mount" then 
			if InCombatLockdown() == true then
				doIt = "doIt"
			else
				doIt = "inCombat"
			end			
--INCREASE_HASTE		
		elseif actionList[j].spells.action == "increaseHaste" then 
			if InCombatLockdown() == true then 
			doIt = testNoTarget(actionList[j].spells.slot, actionList[j].spells.id)
			if doIt == "doIt" then doIt = testSelfBuffIsUp(j, actionList[j].spells.id) end 
			else doIt = "notInCombat" end
--INCREASE_STAT		
		elseif actionList[j].spells.action == "increaseStat" then 
			if InCombatLockdown() == true then 
				doIt = testNoTarget(actionList[j].spells.slot, actionList[j].spells.id)	
				if doIt == "doIt" then doIt = testSelfBuffIsUp(j, actionList[j].spells.id) end 
			else doIt = "notInCombat" end
--PVP
		elseif actionList[j].spells.action == "PVP" then 
			if InCombatLockdown() == true then 
				doIt = testTargetDamage(actionList[j].spells.slot, actionList[j].spells.id)	
				if doIt == "doIt" then doIt = testPvp("target") end 
			else doIt = "notInCombat" end		
--INCREASE_SPEED		
		elseif actionList[j].spells.action == "increaseSpeed" then 
			doIt = testNoTarget(actionList[j].spells.slot, actionList[j].spells.id)	
--HEAL			
		elseif actionList[j].spells.action == "heal" then 
			doIt = mittigateDamage("player")
			if doIt == "doIt" then doIt = testNoTarget(actionList[j].spells.slot, actionList[j].spells.id) end
			if doIt == "doIt" then doIt = testSelfBuffIsUp(j, actionList[j].spells.id) end
--DAMAGE_REDUCTION
		elseif actionList[j].spells.action == "damageReduction" then 
			doIt = mittigateDamage("player")
			if doIt == "doIt" then doIt = testNoTarget(actionList[j].spells.slot, actionList[j].spells.id) end
			if doIt == "doIt" then doIt = testSelfBuffIsUp(j, actionList[j].spells.id) end
--INTERRUPT
		elseif actionList[j].spells.action == "interrupt" then
				doIt = TestCanInterruptSpell("target")
				if doIt == "doIt" then doIt = testTargetDamage(actionList[j].spells.slot, actionList[j].spells.id) end
--CC
		elseif actionList[j].spells.action == "cc" then
			doIt = testTargetDamage(actionList[j].spells.slot, actionList[j].spells.id)		
--REMOVE_CC		
		elseif actionList[j].spells.action == "removeCC" then
				local hasControl = HasFullControl()
				if hasControl then doIt = "hasControl"
				else doIt = "doIt"
				end 
--AOE
		elseif  actionList[j].spells.action == "AOE" then 
			doIt = testNoTarget(actionList[j].spells.slot, actionList[j].spells.id)
--DAMAGE
		elseif actionList[j].spells.action == "damage" and actionList[j].spells.ranged == true then 
			doIt = testTargetDamage(actionList[j].spells.slot, actionList[j].spells.id)
			if dbug then print("Test action damage " .. doIt) end
			if doIt == "doIt" then doIt = testTargetDebuffIsUp(j, actionList[j].spells.id) end
			if doIt == "doIt" then doIt = testSelfBuffIsUp(j, actionList[j].spells.id) end
--RANGED_NOT_DAMAGE
		elseif actionList[j].spells.ranged == true then 
			doIt = isActionInRange(j)
		else
--NO TARGET
			doIt = testNoTarget(actionList[j].spells.slot, actionList[j].spells.id)
			if doIt == "doIt" then doIt = testTargetDebuffIsUp(j, actionList[j].spells.id) end
			if doIt == "doIt" then doIt = testSelfBuffIsUp(j, actionList[j].spells.id) end
		end
	if DebugLevel == 5 then 
		if actionList[j].spells.actionType == "macro" then 
			print("doIt " .. doIt)
		else 
			print(doIt .." action " .. actionList[j].spells.name ) 
		end
	end
	return doIt
end

----------------------actionList functions
function doActionList()
	if loginLock == false then 
		loginLock = true
		action_list()
		addActionListInfo()
		sortActionList()
		loginLock = false
	end 
end
function action_list() -- read button bar(s) and create action list
	actionList = table.wipe(actionList)
	local actionListCntr = 0
	for _, barName in pairs(ActionBars) do
        for j = 1, 12 do 
			actionListCntr = #actionList + 1 
			local button = _G[barName .. 'Button' .. j]
            local slot = ActionButton_GetPagedID(button) or ActionButton_CalculateAction(button) or button:GetAttribute('action') or 0
			if actionList[actionListCntr] == nil then
				actionList[actionListCntr] = {}
			end
			if actionList[actionListCntr].spells == nil then 
				actionList[actionListCntr].spells = {}
			else
--				table.wipe(actionList[j].spells)
--				print("action list wipe it out")
			end
           if HasAction(slot) then
				local actionType, id = GetActionInfo(slot)
				local actionTexture = GetActionTexture(slot)
				if actionType == 'macro' then actionName = GetActionText(slot)
				elseif actionType == 'item' then actionName = GetItemInfo(id)
					if actionName == nil then print("No Item Name ***************************") end
				elseif actionType == 'spell' then actionName = GetSpellInfo(id)
				elseif actionType == 'summonmount' then actionName = "Summon Mount"
				elseif actionType == 'flyout' then actionName = "flyout"
				else actionName = "lostName"
				end 
					isEquiped = IsEquippedAction(slot) -- weapon test
					consumable = IsConsumableAction(slot)
					attackAction = IsAttackAction(slot)
					autoRepeat = IsAutoRepeatAction(slot)
					hasRange = ActionHasRange(slot)
					GCD, CD = GetSpellBaseCooldown(id)
					if DebugLevel == 1 then cell, priority = testActionCell() end
				actionList[actionListCntr].spells = {
						["slot"] = slot,
						["name"] = actionName,
						["actionType"] = actionType,
						["id"] = id,
						["icon"] = actionTexture,
						["equiped"] = isEquiped,
						["consumable"] = consumable,
						["attack"] = attackAction,
						["auto"] = autoRepeat,
						["ranged"] = hasRange,
						["cell"] = cell,
						["priority"] = priority,
						["action"] = "",
						["strength"] = "",	
						["coolDown"] = CD,
						["globalCoolDown"]= GCD,
					}
				
				else 
				actionList[actionListCntr].spells = {
						["slot"] = slot,
						["name"] = "blank",
						["actionType"] = "empty",
						["id"] = "",
						["icon"] = "",
						["equiped"] = "",
						["consumable"] = "",
						["attack"] = false,
						["auto"] = false,
						["ranged"] = false,
						["cell"] = cell,
						["priority"] = priority,
						["action"] = "",
						["strength"] = "",	
						["coolDown"] = "",
						["globalCoolDown"]= "",
					}
				end
					
			end
		end

	end
function getItemAction(actionIndex)
	if AMine.db.profile.items == nil then AMine.db.profile.items = {} end
	if actionList[actionIndex].spells.name == nil then print("612 - name is nil") return "fail" end
		if AMine.db.profile.items[actionList[actionIndex].spells.name] == nil then 
			AMine.db.profile.items[actionList[actionIndex].spells.name] = {
				["action"] = "unknown", 
				["ranged"] = false
				}
		end  
		if AMine.db.profile.itemsCnt == nil then AMine.db.profile["itemsCnt"] = 0 end
		if AMine.db.profile.itemPicker == nil then AMine.db.profile["itemPicker"] = 0 end	
		actionList[actionIndex].spells.action = AMine.db.profile.items[actionList[actionIndex].spells.name].action
		actionList[actionIndex].spells.ranged = AMine.db.profile.items[actionList[actionIndex].spells.name].ranged
		return "done"
end
function getMacroAction(actionIndex)
	if AMine.db.profile.macros == nil then AMine.db.profile.macros = {} end
		if AMine.db.profile.macros[actionList[actionIndex].spells.name] == nil then 
			AMine.db.profile.macros[actionList[actionIndex].spells.name] = {
			["action"] = "unknown", 
			["ranged"] = true
			}
		end 
		if AMine.db.profile.macrosCnt == nil then AMine.db.profile["microsCnt"] = 0 end
		if AMine.db.profile.macroPicker == nil then AMine.db.profile["microPicker"] = 0 end
		actionList[actionIndex].spells.action = AMine.db.profile.macros[actionList[actionIndex].spells.name].action
		actionList[actionIndex].spells.ranged = AMine.db.profile.macros[actionList[actionIndex].spells.name].ranged		
end
function getActionAction(actionIndex)-- Add unknown actions to db
--	if HasAction(actionIndex) == nil then return "noActionExists" end
	if AMine.db.profile.actions == nil then AMine.db.profile.actions = {} end
			if AMine.db.profile.actions[actionList[actionIndex].spells.name] == nil then 
				AMine.db.profile.actions[actionList[actionIndex].spells.name] = {
				["action"] = "unknown", 
				["ranged"] = true
				}
			end 
		if AMine.db.profile.actionsCnt == nil then AMine.db.profile["actionsCnt"] = 0 end
		if AMine.db.profile.actionPicker == nil then AMine.db.profile["actionPicker"] = 0 end
			actionList[actionIndex].spells.action = AMine.db.profile.actions[actionList[actionIndex].spells.name].action
			actionList[actionIndex].spells.ranged = AMine.db.profile.actions[actionList[actionIndex].spells.name].ranged	
	return "unknown"
end
function checkActionAction(actionIndex)  -- get actions that have been saved to db
--	print("checkActionAction : " .. actionIndex)
	if AMine.db.profile.actions == nil then AMine.db.profile.actions = {} end
--	if #AMine.db.profile.actions > 0 then 
		if AMine.db.profile.actions[actionList[actionIndex].spells.name]  then 
--			print ("from memory " .. tostring(AMine.db.profile.actions[actionList[actionIndex].spells.name]))
			actionList[actionIndex].spells.action = AMine.db.profile.actions[actionList[actionIndex].spells.name].action
		else 
			actionList[actionIndex].spells.action = "unknown"
		end 
--	end 
	return actionList[actionIndex].spells.action
end 
function updateActionAction( actionIndex, ACTION) -- update db if actions have changed
	if AMine.db.profile.actions[actionList[actionIndex].spells.name] ~= nil then 
		if AMine.db.profile.actions[actionList[actionIndex].spells.name][action] ~= ACTION then 
			AMine.db.profile.actions[actionList[actionIndex].spells.name].action = ACTION
		end 
	end
end
function addActionListInfo()
local cell = 1
local priority = 1
	if DebugLevel == 3 then print("addActionListInfo")  end
		for j = 1 , #actionList do
		spellName = actionList[j].spells.name
			if actionList[j].spells.actionType == "empty" then
				actionList[j].spells.action = "empty"
--				actionList[j].spells.cell = cell
--				cell = cell + 1
--				actionList[j].spells.priority = priority
				if DebugLevel == 2 then print(spellName .. " is " .. actionList[j].spells.action)end	
			elseif actionList[j].spells.actionType == "item" then
				local status = getItemAction(j)
				if status == "fail" then return "tryAgain" end
--				actionList[j].spells.cell = cell
--				cell = cell + 1
--				actionList[j].spells.priority = priority
				if DebugLevel == 2 then print(spellName .. " is " .. actionList[j].spells.action)end	
			elseif actionList[j].spells.actionType == "macro" then
				getMacroAction(j)			
--				actionList[j].spells.cell = cell
--				cell = cell + 1
--				actionList[j].spells.priority = priority
				if DebugLevel == 2 then print(spellName .. " is " .. actionList[j].spells.action)end	
			elseif actionList[j].spells.actionType == "summonmount" then
				actionList[j].spells.action = "mount"
--				actionList[j].spells.cell = cell
--				cell = cell + 1
--				actionList[j].spells.priority = priority
				if DebugLevel == 2 then print(spellName .. " is " .. actionList[j].spells.action)end	
			else
				ACTION = checkActionAction(j)
				if ACTION == "unknown" then 
				local description = GetSpellDescription(actionList[j].spells.id)
					if description then
						ACTION = descriptionMatch(description)
						if ACTION == "unknown" then getActionAction(j) end
	--					anum = string.match(description, "%d+%d+")
						if anum == nil then anum = 1 end
					end
					updateActionAction(j, ACTION)
				end
				actionList[j].spells.action = ACTION
--				actionList[j].spells.strength = anum

				if DebugLevel == 2 then print(tostring(spellName) .. " is " .. tostring(actionList[j].spells.action))end	
			end
			actionList[j].spells.cell = cell
			cell = cell + 1
			actionList[j].spells.priority = priority	
			
		if cell > AMine.db.profile.NumOCells then
				cell = 1
				priority = priority + 1					
		end 
	end
end 
function descriptionMatch(originalDescription)
	description = string.lower(originalDescription)
		local z = string.find(description, "%.")
		description = strsub(description, 1, z)
		z = string.find(description, " and ")
		description = strsub(description, 1, z)
		ACTION = parseDescription(description)
		if ACTION == "unknown" then
			description = string.lower(originalDescription)
			local z = string.find(description, "%.")
			description = strsub(description, 1, z)
			ACTION = parseDescription(description)
		end
		if ACTION == "unknown" then
			ACTION = parseDescription(originalDescription)
		end
	return ACTION
end
function parseDescription(description)
--TAUNT
		if string.match(description, "target toward you" ) or  string.match(description, "target to attack you" ) then ACTION = "taunt"			
		elseif string.match(description, "intimidate" )then ACTION = "taunt"	
--AOE
		elseif string.match(description, "target location") then ACTION = "AOE"
		elseif string.match(description, "damage over time") then ACTION = "AOE"
		elseif string.match(description, "damage") and string.match(description, "area") then ACTION = "AOE"
--DAMAGE_REDUCTION
		elseif string.match(description, "less damage") then ACTION = "damageReduction"
		elseif string.match(description, "damage") and string.match(description, "reduc") then ACTION = "damageReduction"
		elseif string.match(description, "damage") and string.match(description, "absorb") then ACTION = "damageReduction"
--DAMAGE
		elseif string.match(description, "damage") then ACTION = "damage" --  and string.match(description , "enemies")damage = 
--REMOVE_CC
		elseif string.match(description, "remove") and string.match(description , "effect") then ACTION = "removeCC"
		elseif string.match(description, "immunity") and string.match(description , "effect") then ACTION = "removeCC"
--CC
		elseif string.match(description, "fear") then ACTION = "cc"
--HEAL
		elseif string.match(description, "heal") then ACTION = "heal"--  and string.match(description , "enemies")	
--INTERRUPT		
		elseif string.match(description, "interrupt") then ACTION = "interrupt"
--INCREASE_HASTE
		elseif string.match(description, "increas") and string.match(description , "haste") then ACTION = "increaseHaste"
--INCREASE_SPEED
		elseif string.match(description, "movement") and string.match(description , "increas") then ACTION = "increaseSpeed"
--INCREASE_STAT
		elseif string.match(description , "increas") then ACTION = "increaseStat"
--STUN
		elseif string.match(description, "stuns") then ACTION = "stun"	
--SELF_BUFF		
		elseif string.match(description, "increas") and string.match(description , "your") then ACTION = "selfBuf"	
--REDUCE_SPEED		
		elseif string.match(description, "reduc") and string.match(description , "movement") then ACTION = "reduceSpeed"		
		elseif string.match(description, "slow") and string.match(description , "movement") then ACTION = "reduceSpeed"
--UNKNOWN
		else ACTION = "unknown"
		end 
	return ACTION
end
function changePriorities(cell, priority, newPriority)
		foundNew = findPriorityCell(tonumber(cell), tonumber(newPriority))	
		if tonumber(foundNew) then 
			found = findPriorityCell(tonumber(cell), tonumber(priority))
			if tonumber(found) then 
				newPri = actionList[tonumber(foundNew)].spells.priority
				Pri = actionList[tonumber(found)].spells.priority
				actionList[tonumber(foundNew)].spells.priority = tonumber(Pri)
				actionList[tonumber(found)].spells.priority = tonumber(newPri) 
				return "done ".. actionList[foundNew].spells.priority
			else
			return "Cant find newPriority"
			end			
		else
			return "Cant find newPriority"
		end
end 
function getActionListNumber( item, value)
	local out
	for j = 1, #actionList do
		out = actionList[j].spells[item]
		if out == value then 
		return  j
		end
	end
	return -1
end
function getActionListItem( item, value, item2 )
	local out
	for j = 1, #actionList do
		out = actionList[j].spells[item]
		if out == value then 
		return  actionList[j].spells[item2]
		end
	end
	return -1
end 
function findPriorityCell(cell, priority)
	for j = 1, #actionList do
		if actionList[j].spells.cell == cell and actionList[j].spells.priority == priority then 
			return j
		else 
			
		end
	end
	return "noCellPriorty"
end
function findActionPriority(ACTION)
local priority = 0
local value 
	if DebugLevel == 9 then print("Finding action priority for : " .. ACTION) end
	for priority = 1 , #AMine.db.profile.CellPriorityActions do
		value = AMine.db.profile.CellPriorityActions[priority]
		if value == ACTION then return priority end
	end
	return "DidNotFindCellPriorityAction"
end
function forceActionMemory(actionIndex)
	if AMine.db.profile.actions[actionList[actionIndex].spells.name] == nil then 
		AMine.db.profile.actions[actionList[actionIndex].spells.name] = {
		["action"] = actionList[actionIndex].spells.action, 
		["ranged"] = actionList[actionIndex].spells.ranged
		}
	end 
end 
---------------------- sort functions
function findCellDepth(cell)
local cellDepth = 0
	repeat  
		cellDepth = cellDepth + 1
		local found = findPriorityCell(cell, cellDepth)
	until found == "noCellPriorty" 
	return cellDepth - 1	
end
function findAIbyCellLevel(cell, cellDepth, cellLevel) 
		actionItem = findPriorityCell(cell, cntr)
		return actionList[actionItem].spells.action
end
function findLowerPriority(cell, cellDepth, priorityCellLevel, prioritizedAction )
local returnValue = "go"
	repeat 
	if tonumber(priorityCellLevel) == nil then return "noPriority"
	elseif tonumber(priorityCellLevel) <= 1 then return "nothingToDo"
	else
		local lowerCellLevel = tonumber(priorityCellLevel) -1  
		if DebugLevel == 9 then print("lower cell level: ".. lowerCellLevel .. " cell: " .. cell) end 
--		cellLevelValue = findpriorityx(cell, cellDepth,  lowerCellLevel )
		cellLevelAI = findPriorityCell(cell, lowerCellLevel)
		if cellLevelAI == "noCellPriorty" then
			if DebugLevel == 9 then print("lower cell level value cnt: ".. cellLevelValue) end 
			return "LowerDoesn'tExist"
		else 
			if DebugLevel == 9 then print("lower cell level action Item : ".. cellLevelAI .. "  lower cell level action: " .. actionList[cellLevelAI].spells.action) end 			
			cellLevelaction = actionList[cellLevelAI].spells.action
			lowerPriority = findActionPriority(cellLevelaction)
			if DebugLevel == 9 then print("Lower priority: " .. lowerPriority) end 		
			if tonumber( lowerPriority ) and tonumber(prioritizedAction) < tonumber(lowerPriority) then
				if DebugLevel == 9 then print("swapping cells : " .. priorityCellLevel .. " with "  .. lowerCellLevel)end
				changePriorities(cell, priorityCellLevel,  lowerCellLevel) 
				priorityCellLevel = lowerCellLevel
--				return "swapped"
			else
				return "done"
			end
		end 		
	end
		until returnValue == "done"
end
function findpriorityx(cell, cellDepth,  prioritizedAction )  -- return cell levels
	local levels = {}
	wipe(levels)
	local cellPriortiy = AMine.db.profile.CellPriorityActions[prioritizedAction]
	for z = 1, cellDepth do 
		ActionItem = findPriorityCell(cell, z)
		if cellPriortiy == actionList[ActionItem].spells.action then 
			table.insert(levels, z)
			if DebugLevel == 9 then print("found prioritzed action(s) at cell level(s): " .. z) end
		end
	end
	if #levels > 0 then 
		return levels
	else 
		return levels
	end
end
function sortLoop(cell, cellDepth, prioritizedAction)
	repeat
		local priorityCellLevel = findpriorityx(cell, cellDepth, prioritizedAction)
		if #priorityCellLevel > 0 then 
			if DebugLevel == 9 then print("prioritized action count: " .. #priorityCellLevel) end
			for y = 1, #priorityCellLevel do 
					local did = findLowerPriority(cell, cellDepth, priorityCellLevel[y], prioritizedAction )
					if DebugLevel == 9 then print("findLowerPriority: " .. tostring(did)) end
			end 
		else
--		if DebugLevel == 9 then print(priorityCellLevel  .. " for " .. prioritizedAction ) end
		end 
	until did ~= "done"
end 
function sortActionList()
	local prioritizedAction = 1
	for cell = 1 , AMine.db.profile.NumOCells do 
		local cellDepth = findCellDepth(cell)
		for x = 1, #AMine.db.profile.CellPriorityActions do 
			sortLoop(cell, cellDepth, x)
		end 
	end
end
function getActionPriortiy(ActionItem)
		for index, value in ipairs(AMine.db.profile.CellPriorityActions)do
			if value == actionList[ActionItem].spells.action then
				if DebugLevel == 9 then print("724 " .. actionList[ActionItem].spells.name .. " " ..  index .. " " .. value .. "  " .. actionList[ActionItem].spells.action)end
			return index end 
		end 
		return "ActionPriorityFail"
end 

--------------------------------Events
function eventHandler(self, event, ...)
	local arg1, arg2 , arg3, arg4, arg5, arg6, arg7, i = ...
	if DebugLevel == 3 then printArguments(event, ...) end
	if STOPIT then return end
	if event == "ADDON_LOADED" then 
		if arg1 == AMine then AMineDB = copyDefaults(defaults, AMineDB) end
	elseif event == "PLAYER_ENTERING_WORLD"then	
--		UpdateDisplaySlots(mainFrame)	
	elseif event == "PLAYER_LOGIN" then 
		
--		kickoff()
	elseif event == "PLAYER_LEAVE_COMBAT"then		
	elseif event == "ACTIONBAR_SLOT_CHANGED" then 
			if #actionList > 0 then doActionList() end
	elseif event == "ACTIONBAR_UPDATE_COOLDOWN" then 
		if #actionList == 0 then doActionList() end
		UpdateDisplaySlots(mainFrame)
		GCD = true
	elseif event == "ACTIONBAR_UPDATE_USABLE" then 
		if #actionList == 0 then doActionList() end
		UpdateDisplaySlots(mainFrame)
	elseif event == "ACTIONBAR_UPDATE_STATE" then 
			if #actionList == 0 then doActionList() end
		if GCD == false then 
			UpdateDisplaySlots(mainFrame)
			GCD = true
		end
	elseif event == "PLAYER_TARGET_CHANGED" then UpdateDisplaySlots(mainFrame)		
	elseif event == "UNIT_SPELLCAST_SENT" then  UpdateDisplaySlots(mainFrame)		
	elseif event == "PET_BATTLE_OPENING_DONE" then 
		mainFrame:Hide()
	elseif event == "PET_BATTLE_CLOSE" then 
		mainFrame:Show()	
	elseif event == "COMBAT_LOG_EVENT" then 
		eventInfo = {CombatLogGetCurrentEventInfo()}
--		 UpdateDisplaySlots(mainFrame)
--		local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = CombatLogGetCurrentEventInfo()
		if DebugLevel == 6 then
			for index,value in pairs(eventInfo) do 
				DEFAULT_CHAT_FRAME:AddMessage(tostring(index).." : "..tostring(value))
				print(eventInfo[2] .. " from " .. tostring(eventInfo[13]) )
				spellId, spellName, spellSchool, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing, isOffHand = select(12, eventInfo)
			end
		end
	end 
end 
--------------------------------Main and Display 
function FrameAdjustments(MainFrame) -- adjustment actions for main frame 
	MainFrame:SetMovable(true)
	MainFrame:EnableMouse(true)
	MainFrame:RegisterForDrag("LeftButton")
	MainFrame:SetScript("OnDragStart", 
		function() 
			if IsShiftKeyDown() then
				MainFrame:StartMoving() 
			end
		end)
	MainFrame:SetScript("OnDragStop",
		function()
			MainFrame:StopMovingOrSizing()
			AMine.db.profile.MFpoint, AMine.db.profile.relativeTo, AMine.db.profile.MFrelativePoint, AMine.db.profile.MFXOffset, AMine.db.profile.MFYOffset = MainFrame:GetPoint()
			AMine.db.profile.MFXOffset = math.floor(AMine.db.profile.MFXOffset)
			AMine.db.profile.MFYOffset = math.floor(AMine.db.profile.MFYOffset)
        end)
	MainFrame:SetScript("OnMouseUp", 
		function() 
			if IsShiftKeyDown() then
--				self:HideAnchor()
			end
			if IsAltKeyDown() then
--				self:RotateAnchor()
			end
		end)
end 
function UpdateDisplaySlots(MainFrame)
	doIt = "notInitialized" 
	cntr = 1
	found = 0
	if DebugLevel == 3 then print("update display slots")  end
	if DebugLevel == 4 then print("*************************** Gate is " .. tostring(gate) .. " **** GCD is " .. tostring(GCD))end
	if gate == true then 
		if GATEUPDATE then gate = false else gate = true end
		if DebugLevel == 4 then print("***************************")end
		for j = 1, AMine.db.profile.NumOCells do
			cntr = 1
			repeat
				found = findPriorityCell(j, cntr) 
				if  tonumber(found) then doIt = runTests(found , false) 
					if DebugLevel == 4 then print(tostring(actionList[found].spells.name) .. " " .. tostring(actionList[found].spells.cell) .. " " .. tostring(actionList[found].spells.priority) .. " " .. doIt) end
				else 
					doIt = "NoMatch"
				end
				cntr = cntr + 1
--				if cntr > #actionList then doIt = "NoMatch" end
			until doIt == "doIt" or doIt == "NoMatch" 
			cntr = 1
			if doIt == "doIt" then 
				if  tonumber(found)then
				displaySlots[j].texture:SetTexture(actionList[found].spells.icon) 
				local show = actionList[found].spells.action
					if show == "interrupt" or show == "heal" then 
						displaySlots[j].texture:SetVertexColor(1, 1, 1, AMine.db.profile.MFAlpha)
					elseif show == "damage" then --  gray it
						displaySlots[j].texture:SetVertexColor(0.8, 0.8, 0.8, 1)
					elseif show == "increaseStat" or show == "increaseHaste" then --   red it
						displaySlots[j].texture:SetVertexColor(0.0, 0.7, 0.7, AMine.db.profile.MFAlpha)
					elseif show == "damageReduction" or show =="removeCC" then -- full color
						displaySlots[j].texture:SetVertexColor(0.5, 0.5,0.5, AMine.db.profile.MFAlpha - 0.2)
					elseif show == "increaseSpeed" or show == "reduceSpeed" or show == "mount" then -- dim it
						displaySlots[j].texture:SetVertexColor(0.4, 0.4, 0.3, AMine.db.profile.MFAlpha - 0.2)
					elseif show == "cc" or show =="AOE" then -- blue it
						displaySlots[j].texture:SetVertexColor(0.5, 0.5, 0.7, AMine.db.profile.MFAlpha)
					end
				
				end 
				if DebugLevel == 4 then print("doIt display slot " .. j .. " found " .. found) end
				displaySlots[j].texture:SetAlpha(1)
			else
				if DebugLevel == 4 then print("Not doIt so hide slot " .. j) end
				displaySlots[j].texture:SetAlpha(0)
			end
			if DebugLevel == 6 then print("display slot " .. j .. "  " ..  actionList[found].spells.name) end
		end
	
	end	
	gate = true
end
function Disable(MainFrame)
	MainFrame:SetScript("OnUpdate", nil)
	MainFrame:Hide()
end
function runLoop(MainFrame) --  run the loop
	MainFrame:EnableMouse(false)
	MainFrame:SetScript("OnUpdate", 
		function() 
			now = GetTime()
			elapsed = now - lastTime
			if  elapsed > LOOPTIME then
				FrameAdjustments(MainFrame)
				if GCD == true then 
--						UpdateDisplaySlots(MainFrame)
						GCD = false
				end
			lastTime = now
			end
		end)
	
end
function createDisplaySlots(mainFrame)
	for j = 1, AMine.db.profile.NumOCells do
		displaySlots[j] = {}
		displaySlots[j].texture = mainFrame:CreateTexture(nil,"OVERLAY")
		displaySlots[j].texture:ClearAllPoints()
		if j == 1 then 	displaySlots[j].texture:SetPoint(AMine.db.profile.MFpoint,mainFrame , AMine.db.profile.MFpoint, AMine.db.profile.CLXOffset, AMine.db.profile.CLYOffset)
		else displaySlots[j].texture:SetPoint(AMine.db.profile.MFpoint,displaySlots[j-1].texture , AMine.db.profile.MFrelpoint, AMine.db.profile.CLXOffset, AMine.db.profile.CLYOffset)
		end
		displaySlots[j].texture:SetWidth(AMine.db.profile.MFIconSize)
		displaySlots[j].texture:SetHeight(AMine.db.profile.MFIconSize)
--		displaySlots[j].texture:SetTexture(actionList[j].spells.icon)
		displaySlots[j].texture:SetVertexColor(0.5,0.5,0.5, 1) -- dimed
--		displaySlots[j].texture:SetAlpha(.5)
	end
end 
function registerEvents(mainFrame)
	mainFrame:RegisterEvent("ADDON_LOADED")
	mainFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
	mainFrame:RegisterEvent("PLAYER_LOGIN")
	mainFrame:RegisterEvent("PLAYER_LEAVE_COMBAT")
	mainFrame:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN")
	mainFrame:RegisterEvent("ACTIONBAR_UPDATE_STATE")
	mainFrame:RegisterEvent("ACTIONBAR_UPDATE_USABLE")
	mainFrame:RegisterEvent("PLAYER_TARGET_CHANGED")
	mainFrame:RegisterEvent("UNIT_SPELLCAST_SENT")
	mainFrame:RegisterEvent("COMBAT_LOG_EVENT")
	mainFrame:RegisterEvent("PET_BATTLE_OPENING_DONE")
	mainFrame:RegisterEvent("PET_BATTLE_CLOSE") 
	mainFrame:RegisterEvent("ACTIONBAR_PAGE_CHANGED")
	mainFrame:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
end 
function createMainFrame()  -- Create Main Frame 
	local xspacing = 0
	local yspacing = 0
	local width
	local height
	local f = CreateFrame("Frame","MainFrame",UIParent)
	f:SetFrameStrata("BACKGROUND")
	f:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
			edgeFile = nil , -- "Interface/Tooltips/UI-Tooltip-Border",
			tile = false, tileSize = 16, edgeSize = 16,
			insets = { left = 5, right =5, top = 5, bottom = 5 }})
	f:SetPoint("CENTER", UIParent , "CENTER", AMine.db.profile.MFXOffset, AMine.db.profile.MFYOffset)
	f:SetBackdropColor(0.2,0.2,0.2, 0)
	f:SetAlpha(AMine.db.profile.MFAlpha)
	if AMine.db.profile.MFOrientation == "Vertical" then 
		f:SetHeight(AMine.db.profile.NumOCells * AMine.db.profile.MFIconSize) -- Set these to whatever height/width is needed 
		f:SetWidth(AMine.db.profile.MFIconSize) -- for your Texture
	else	
		print("horz")
		f:SetHeight(AMine.db.profile.MFIconSize) -- Set these to whatever height/width is needed 
		f:SetWidth(AMine.db.profile.NumOCells * AMine.db.profile.MFIconSize) -- for your Texture
	end

	return f
end 
function OnInitialize()
--[[
optionsFrame = {}
optionsFrame.general = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ActionReady", nil, nil,"general") 
optionsFrame.displaySettings = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ActionReady", "Display", "ActionReady", "displaySettings")
optionsFrame.spellsels = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ActionReady", "Watch Spells", "ActionReady", "spellsels")  
]]--
end 


--[[
function AMine:OnInitialize()	
	self.db = LibStub("AceDB-3.0"):New("AMineDB", defaults) 	
	self.profileOptions = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db);
	LibStub("AceConfig-3.0"):RegisterOptionsTable("Profiles", self.profileOptions);

	self.myOptions = LibStub("AceDBOptions-3.0"):GetOptionsTable(myOptionsTable);
	LibStub("AceConfig-3.0"):RegisterOptionsTable(THISAP, myOptionsTable);	
	self.myOptions.general = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(THISAP, nil, nil,"general")  
	self.myOptions.buh = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(THISAP, "buh", THISAP, "spellsels");
	self.profilesFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Profiles", "Profiles", THISAP);
end
]]--
function kickoff()
	AMine.db = LibStub("AceDB-3.0"):New("AMineDB", defaults) 	
	AMine.profileOptions = LibStub("AceDBOptions-3.0"):GetOptionsTable(AMine.db);
	LibStub("AceConfig-3.0"):RegisterOptionsTable("Profiles", AMine.profileOptions);

	LibStub("AceConfig-3.0"):RegisterOptionsTable(THISAP, myOptionsTable);	
	AMine.myOptions = LibStub("AceDBOptions-3.0"):GetOptionsTable(myOptionsTable);
	AMine.myOptions = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(THISAP, nil, nil)  
	AMine.myOptions.buh = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(THISAP, "buh", THISAP, "spellsels");
	AMine.profilesFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Profiles", "Profiles", THISAP);
end
function AMine:OnEnable()
    --initialize Saved Variables and other start up tasks
		kickoff()
--			AMineDB = copyDefaults(defaults, AMineDB) 
	
--	DebugLevel = AMine.db.profile.DebugLevel
	mainFrame = createMainFrame()
	registerEvents(mainFrame)
	MainFrame:SetScript("OnEvent", eventHandler)
	createDisplaySlots(mainFrame)	
	mainFrame:Show()
	runLoop(mainFrame)
end


myOptionsTable = {
  type = "group",
  args = {
	general = {			
			type = 'group',
			name = 'General', 
			order = 1, 
			inline = true,
				args = {
					Top ={
					name = 'Enable and Auto Group',
					type = 'group',
					order = 2,
					inline = true,
						args ={
							enable = {
							  name = "Enable",
							  desc = "Enables / disables the addon",
							  type = "toggle",
							  set = function(info,val) AMine.db.profile.enabled = val end,
							  get = function(info) return AMine.db.profile.enabled end
							},
							numOcells = {
							  name = "Number of cells",
							  desc = "Sets the number of cells to display",
							  type = "range",
							  max = 12,
							  set = function(info,val) AMine.db.profile.NumOCells = val end,
							  get = function(info) return AMine.db.profile.NumOCells end
							},
							orientation = {
								name = "Vertial Display",
								desc = "horizontal or vertical",
								type = "toggle",
								get = function() if AMine.db.profile.MFOrientation == "Vertical" then 
												return true	else return false end end,
								set = function(_,f) if f == true then AMine.db.profile.MFOrientation = "Vertical"
											else AMine.db.profile.MFOrientation = "Horizontal" end end,
							},
							dbugLevel ={
							name = "Debug Level",
							  desc = "set the debug message level",
							  type = "range",
							  min = 0,
							  max = 12,
							  step = 1,
							  set = function(info,val) AMine.db.profile.DebugLevel = val
											DebugLevel = val end,
							  get = function(info) return AMine.db.profile.DebugLevel end
							
							},

							}
						}
					}
    			},
		spellsels ={
			name = 'Edit Actions',
			type = 'group',
			args = {
					Top ={
					name = 'Items',
					type = 'group',
					order = 1,
					inline = true,
					args ={
						itemMax = {
							name = "MaxItem",
							type = "input",
							width = 10,
--							hidden = true,
							set = function(info, val) AMine.db.profile.itemsCnt = val end,
							get = function(info) items = getListFromDB(AMine.db.profile.items)
										if items =="dbEmpty" or #items == 0 then return "duho"
										else 
										AMine.db.profile.itemsCnt = #items
										return tostring(#items)end
								end,				
						},
						selectItem ={
						 name = "selector",
						  desc = "Pick the entry to display",
						  type = "range",
						  max = itemsCnt,
						  min = 1,
						  step = 1,
						  set = function (info, val) if val <= AMine.db.profile.itemsCnt then AMine.db.profile["itemPicker"] = val end end,
						  get =  function(info) if AMine.db.profile.itemPicker ~= nil and  AMine.db.profile.itemPicker <=  AMine.db.profile.itemsCnt then return AMine.db.profile.itemPicker 
												else AMine.db.profile.itemPicker = AMine.db.profile.itemsCnt  end end,
						
						},
						items ={
							name = 'Name', 
							desc = 'Item Name',
							type = 'input', 
							order = 2,
							set = function(info,val)end,
							get = function(info) items = getListFromDB(AMine.db.profile.items)
									if items =="dbEmpty" then return "" 
									else return items[AMine.db.profile.itemPicker]
									end
									end,
							},
						actionTypes = {
							name = "action",
							desc = "Item action",
							type = "select",
							style = "dropdown",
							values = function() return AMine.db.profile.CellPriorityActions end,
							set = function(info,val)items = getListFromDB(AMine.db.profile.items)
							AMine.db.profile.items[items[AMine.db.profile.itemPicker]].action = AMine.db.profile.CellPriorityActions[val] end,
							get = function(info) items = getListFromDB(AMine.db.profile.items)
									if items =="dbEmpty" then return "" 
									else  for index, value in ipairs(AMine.db.profile.CellPriorityActions)do
--										if value == AMine.db.profile.items[items[AMine.db.profile.itemPicker]].action then return index end
										end
									end
									end,
									},
						itemRanged ={
							name = 'Ranged', 
							desc = 'Does Item have range limitations',
							type = 'toggle', 
							order = 2,
							set = function(info,val) items = getListFromDB(AMine.db.profile.items) AMine.db.profile.items[items[AMine.db.profile.itemPicker]].ranged = val end,
							get = function(info) items = getListFromDB(AMine.db.profile.items)
									if items =="dbEmpty" or #items == 0 then return "" 
--									elseif AMine.db.profile.itemPicker <=  AMine.db.profile.itemsCnt then return  AMine.db.profile.items[items[AMine.db.profile.itemPicker]].ranged
									else 
									
									end
									end,
							},
					}
				
				},
			
			Center ={
					name = 'Macros',
					type = 'group',
					order = 2,
					inline = true,
					args ={
					itemMax = {
					name = "MaxItem",
					type = "input",
					width = 10,
					hidden = false,
					set = function(info, val)AMine.db.profile.macrosCnt = val end,
					get = function(info) items = getListFromDB(AMine.db.profile.macros)
							if items =="dbEmpty" or #items == 0 then return "duho"
							else 
							AMine.db.profile["macrosCnt"] = #items
							return tostring(#items)end
					end,				
						},
				selectItem ={
				 name = "selector",
				  desc = "Pick the entry to display",
				  type = "range",
				  max = macrosCnt,
				  min = 1,
				  step = 1,
				  set = function (info, val) if val <= AMine.db.profile.macrosCnt then AMine.db.profile.macroPicker = val end end,
				  get =  function(info) if AMine.db.profile.macroPicker == nil then AMine.db.profile.macroPicker = 0 end
						if AMine.db.profile.macrosCnt == nil then AMine.db.profile.macrosCnt = 0 end
						if AMine.db.profile.macroPicker <=  AMine.db.profile.macrosCnt then 
							return AMine.db.profile.macroPicker 
						else AMine.db.profile.macroPicker = AMine.db.profile.macrosCnt  
						end 
						end,				
				},
				items ={
					name = 'Name', 
					desc = 'Item Name',
					type = 'input', 
					order = 2,
					set = function(info,val)end,
					get = function(info) items = getListFromDB(AMine.db.profile.macros)
							if items =="dbEmpty" then return 0
							elseif #items == 0 then return 0 
							else return items[AMine.db.profile.macroPicker]
							end
							end,
					},
				actionTypes = {
					name = "action",
					desc = "macro action",
					type = "select",
					style = "dropdown",
					values = function() return AMine.db.profile.CellPriorityActions end,
					set = function(info,val)items = getListFromDB(AMine.db.profile.macros) AMine.db.profile.macros[items[AMine.db.profile.macroPicker]].action = AMine.db.profile.CellPriorityActions[val] end,
					get = function(info) items = getListFromDB(AMine.db.profile.macros)
							if items =="dbEmpty" then return "" 
							else  for index, value in ipairs(AMine.db.profile.CellPriorityActions)do
								if value == AMine.db.profile.macros[items[AMine.db.profile.macroPicker]].action then return index end
								end
							end
							end,
							},
			itemRanged ={
					name = 'Ranged', 
					desc = 'Does Item have range limitations',
					type = 'toggle', 
					order = 2,
					set = function(info,val)items = getListFromDB(AMine.db.profile.macros) AMine.db.profile.macros[items[AMine.db.profile.macroPicker]].ranged = val end,
					get = function(info) items = getListFromDB(AMine.db.profile.macros)
							if items =="dbEmpty" or #items == 0 then return "" 
								elseif AMine.db.profile.macroPicker <=  AMine.db.profile.macrosCnt then return  AMine.db.profile.macros[items[AMine.db.profile.macroPicker]].ranged
									else 
									
									end
									end,
					}, 
				}
					},
			Bottom ={
					name = 'Action',
					type = 'group',
					order = 3,
					inline = true,
					args ={
						doIt = {
							name = "reload",
							type = "execute",
							func = function() reload() end, -- ReloadUI(
						},
						itemMax = {
							name = "MaxItem",
							type = "input",
							width = 10,
							hidden = false,
							set = function(info, val)AMine.db.profile.actionsCnt = val end,
							get = function(info) items = getListFromDB(AMine.db.profile.actions)
									if items =="dbEmpty" or #items == 0 then return "0"
									else 
									actionsCnt = #items
--										AMine.db.profile["actionsCnt"] = 
										actionsCnt = #items
										print("Action Count is " .. actionsCnt)
										return tostring(#items)
									end
							end,				
						},
						selectAction ={							
							name = "action selector",
							desc = "Pick the entry to display",
							type = "range",
							max = actionsCnt,
							min = 1,
							step = 1,
							set = function (info, val)if val <= AMine.db.profile.actionsCnt then AMine.db.profile.actionPicker = val end end,
							get =  function(info) if AMine.db.profile.actionPicker == nil then AMine.db.profile.actionPicker = 0 end
										if AMine.db.profile.actionsCnt == nil then AMine.db.profile.actionsCnt = 0 end
										if AMine.db.profile.actionPicker <=  AMine.db.profile.actionsCnt then return AMine.db.profile.actionPicker 
												else AMine.db.profile.actionPicker = AMine.db.profile.actionsCnt  end 
												 
												 end,
												 
						},
						items ={
							name = 'Name', 
							desc = 'Item Name',
							type = 'input', 
							order = 2,
							set = function(info,val)end,
							get = function(info) items = getListFromDB(AMine.db.profile.actions)
									if items =="dbEmpty" then return "" 
									else return items[AMine.db.profile.actionPicker]
									end
									end,
							},
						actionTypes = {
							name = "action",
							desc = "Item action",
							type = "select",
							style = "dropdown",
							values = function() return AMine.db.profile.CellPriorityActions end,
							set = function(info,val) AMine.db.profile.items[items[AMine.db.profile.actionPicker]].action = AMine.db.profile.CellPriorityActions[val] end,
							get = function(info) items = getListFromDB(AMine.db.profile.actions)
									if items =="dbEmpty"  or #items == 0 then return "" 
									else  for index, value in ipairs(AMine.db.profile.CellPriorityActions)do
										if value == AMine.db.profile.actions[items[AMine.db.profile.actionPicker]].action then return index end
										end
									end
									end,
									},
						itemRanged ={
							name = 'Ranged', 
							desc = 'Does Item have range limitations',
							type = 'toggle', 
							order = 2,
							set = function(info,val) AMine.db.profile.actions[items[AMine.db.profile.actionPicker]].ranged = val end,
							get = function(info) items = getListFromDB(AMine.db.profile.actions)
									if items =="dbEmpty" then return "" 
									elseif #items > 0 then return AMine.db.profile.actions[items[AMine.db.profile.actionPicker]].ranged
									end
									end,
							},
				}
					},					
					
				}
		}		
	},
}
  Reply With Quote