/trunk/ItemRackStun/libs/LibPlayerSpellInfo-1.0
## Title: Lib: PlayerSpellInfo-1.0 |
## Notes: |
## Author: Draake |
## Dependencies: LibStub, LibPlayerControl-1.0 |
## Dependencies: LibPlayerControl-1.0 |
LibStub\LibStub.lua |
lib.xml |
end |
function Round(input, places) |
local pow = 10 ^ math.ceil(places or 0) |
return floor(input * pow + 0.5) / pow |
local div = 10 ^ math.ceil(places or 0) |
return math.floor(input * div + 0.5) / div |
end |
function SetTimer(name, duration, func) |
function SetTimer(name, duration, func, value) |
if type(name) ~= "string" then |
name = #lib.timers + 1 |
end |
lib.timers[name].start = GetTime() |
lib.timers[name].duration = duration |
lib.timers[name].func = func |
lib.timers[name].value = value |
return lib.timers[name] |
end |
-------------------------------------------------------------------------------------------------- |
local IsPlayerSpell, HasItemInBags, GetSpellReqInfo, PlayerSpellParseTooltip |
local PackLocation, UnpackLocation |
if ( not lib.tooltip ) then |
lib.tooltip = CreateFrame("GameTooltip", |
local NO_REAGENT_PATTERN = string.format("^%s[|]?[c]?%%x*(.-)[|]?[r]?$", SPELL_REAGENTS) |
function PlayerSpellParseTooltip() |
print("PlayerSpellParseTooltip") |
local PlayerForms = {} |
for i = 1, GetNumShapeshiftForms(), 1 do |
PlayerForms[ SelectOne(2, GetShapeshiftFormInfo(i)) ] = 2 ^ i |
lib.events.GLYPH_REMOVED = lib.events.LEARNED_SPELL_IN_TAB |
function lib.events.BAG_UPDATE(bag) |
if CACHE.BAGSLOTS[bag] then |
local newSlots, oldSlots = GetContainerNumSlots(bag), #CACHE.BAGSLOTS[bag] |
for slot = 1, newSlots, 1 do |
if ( not CACHE.BAGSLOTS[bag][slot] ) then |
CACHE.BAGSLOTS[bag][slot] = {} |
end |
local TT = table.wipe(CACHE.BAGSLOTS[bag][slot]) |
local itemLink = GetContainerItemLink(bag, slot) |
if itemLink then |
local itemString, name = string.match(itemLink, "^|c%x+|H(.+)|h%[(.*)%]") |
local index = tonumber( SelectOne(2, strsplit(":", itemString)) ) |
TT.link, TT.index, TT.name, TT.count = itemLink, |
index, name, SelectOne(2, GetContainerItemInfo(bag, slot)) |
else |
TT.link, TT.index, TT.name, TT.count = EMPTY_SLOT_STRING, |
EMPTY_SLOT_NUMBER, EMPTY_SLOT_STRING, EMPTY_SLOT_NUMBER |
end |
if ( not CACHE.BAGSLOTS[bag] ) then |
return |
end |
local newSlots, oldSlots = GetContainerNumSlots(bag), #CACHE.BAGSLOTS[bag] |
for slot = 1, newSlots, 1 do |
if ( not CACHE.BAGSLOTS[bag][slot] ) then |
CACHE.BAGSLOTS[bag][slot] = {} |
end |
for slot = newSlots, oldSlots, 1 do |
CACHE.BAGSLOTS[bag][slot] = nil |
local TT = table.wipe(CACHE.BAGSLOTS[bag][slot]) |
local itemLink = GetContainerItemLink(bag, slot) |
if itemLink then |
local itemString, name = string.match(itemLink, "^|c%x+|H(.+)|h%[(.*)%]") |
local index = tonumber( SelectOne(2, strsplit(":", itemString)) ) |
TT.link, TT.index, TT.name, TT.count = itemLink, |
index, name, SelectOne(2, GetContainerItemInfo(bag, slot)) |
else |
TT.link, TT.index, TT.name, TT.count = EMPTY_SLOT_STRING, |
EMPTY_SLOT_NUMBER, EMPTY_SLOT_STRING, EMPTY_SLOT_NUMBER |
end |
end |
for slot = newSlots, oldSlots, 1 do |
CACHE.BAGSLOTS[bag][slot] = nil |
end |
end |
function lib.events.UNIT_INVENTORY_CHANGED(unit) |
-- |
-------------------------------------------------------------------------------------------------- |
local CAN_CAST_PARSE = {OPTION={},LOOKUP={{name="EFFECT",token={"effect="},type="string"},{name="SPELL",token={"&", "spell="},type="string"},{name="COOLDOWN",token={"cooldown=","gcd="},type="number"},{group={"start","stop","fail","done"},name="CAST",token={"cast="},type="string"},{group={"control","equip","form","reagent"},name="IGNORE",token={"ignore:","ign:"},type="group"}}} |
local CAN_CAST_PARSE = { OPTION={} } |
CAN_CAST_PARSE.LOOKUP = { |
{ |
name = "EFFECT", |
token = { "effect=" }, |
type = "string", |
}, |
{ |
name = "SPELL", |
token = { "&", "spell=" }, |
type = "string", |
}, |
{ |
name = "COOLDOWN", |
token = { "cooldown=", "gcd=" }, |
type = "number", |
}, |
{ |
name = "CAST", |
token = { "cast=" }, |
group = { "start", "stop", "fail", "done" }, |
type = "string", |
}, |
{ |
name = "IGNORE", |
token = { "ignore:", "ign:" }, |
group = { "control", "equip", "form", "reagent"}, |
type = "group", |
}, |
} |
for i, v in ipairs(CAN_CAST_PARSE.LOOKUP) do |
for j, k in ipairs(v.token) do |
CAN_CAST_PARSE.LOOKUP[k] = v |
local lookup = CAN_CAST_PARSE.LOOKUP[token] |
if ( not lookup ) or ( value == "" and lookup.type ~= "boolean" ) then |
return |
elseif lookup.type == "group" then |
for s in string.gmatch(value, "([^/]+)") do |
if lookup.group[s] then |
CAN_CAST_PARSE.OPTION[ lookup.name .. lookup.group[s] ] = bool |
else |
local bool = ( m2 ~= "no" ) |
if lookup.type == "group" then |
for s in string.gmatch(value, "([^/]+)") do |
if lookup.group[s] then |
CAN_CAST_PARSE.OPTION[ lookup.name .. lookup.group[s] ] = bool |
end |
end |
else |
value = tonumber(value) or value |
if lookup.type == "multi" or lookup.type == "string" |
and type(value) == "string" and ( not lookup.group or lookup.group[value] ) then |
CAN_CAST_PARSE.OPTION[ lookup.name ] = value |
elseif lookup.type == "number" and type(value) == "number" then |
CAN_CAST_PARSE.OPTION[ lookup.name ] = bool and value or -value |
elseif lookup.type == "boolean" then |
CAN_CAST_PARSE.OPTION[ lookup.name ] = bool |
end |
end |
else |
value = tonumber(value) or value |
if lookup.type == "multi" or lookup.type == "string" |
and type(value) == "string" and ( not lookup.group or lookup.group[value] ) then |
CAN_CAST_PARSE.OPTION[ lookup.name ] = value |
elseif lookup.type == "number" and type(value) == "number" then |
CAN_CAST_PARSE.OPTION[ lookup.name ] = bool and value or -value |
elseif lookup.type == "boolean" then |
CAN_CAST_PARSE.OPTION[ lookup.name ] = bool |
end |
end |
if ( not lookup.push ) then |
return "" |
end |
end |
local function ParseOptionList(list, optTable) |
if type(optTable) ~= "table" then |
optTable = table.wipe(CAN_CAST_PARSE.OPTION) -- Clear old options from value table |
else |
optTable = table.wipe(options) |
end |
if ( not list ) or ( list == "" ) then |
return optTable, true, nil |
end |
local command, target = SecureCmdOptionParse( list:gsub( |
"([^%[%P]?)(n?o?)(%w+)%s*([=:]?)%s*[-+]?([^,%]]*)", ParseOptionList_GSub) ) |
return optTable, ( command ~= nil ), target |
end |
-------------------------------------------------------------------------------------------------- |
-- Event Handling |
-------------------------------------------------------------------------------------------------- |
lib.frame:SetScript("OnUpdate", function(self, elapsed) |
for i, v in pairs(lib.timers) do |
if GetTime() > v.start + v.duration then |
v.func(); lib.timers[i] = nil |
v.func(v.value) |
lib.timers[i] = nil |
end |
end |
end) |
------------------------------------------------------------------------------------------------]] |
local ACTIVE_SPELL_EXCEPTION = { |
[ GetSpellInfo(17) ] = { -- Power Word: Shield |
func = function(spell, target, ...) |
return ( not target ) or ( not UnitDebuff(target, ...) ) |
end, |
args = { |
GetSpellInfo(6788), |
}, |
}, |
[ GetSpellInfo(100) ] = { -- Charge |
func = function(spell, target, ...) |
return true |
if ( not strict ) then |
return false, false, false, false, false, false, true, true, true, true |
else |
error("Invalid spell index/name/link passed. Must be a valid player spell.", 2) |
error("Invalid spell index/name/link passed to SpellCastInfo(). Must be a valid player spell.", 2) |
end |
end |
if ( not strict ) then |
return true, true, true |
else |
error("Invalid spell index/name/link passed. Must be a valid player spell.", 2) |
error("Invalid spell index/name/link passed to SpellCastInfo(). Must be a valid player spell.", 2) |
end |
end |
return GetSpellReqInfo(spell) |
return command |
else |
for list in string.gmatch(block, "(%[.-%])") do |
local OPT = table.wipe(CAN_CAST_PARSE.OPTION) -- Clear old options from value table |
local isTrueList, target = SecureCmdOptionParse( list:gsub( |
"([^%[%P]?)(n?o?)(%w+)%s*([=:]?)%s*[-+]?([^,%]]*)", ParseOptionList_GSub) ) |
if isTrueList then |
local OPT, isTrue, target = ParseOptionList(list) |
if isTrue then |
if OPT.EFFECT and LPC:PlayerHasEffect(OPT.EFFECT) then |
return command |
elseif OPT.CAST then |