libcast: add spell rank detection

This commit is contained in:
shagu
2020-01-31 22:45:20 +01:00
parent 71b3297c51
commit 2a98fa59da
+36 -14
View File
@@ -47,6 +47,9 @@ if pfUI.client > 11200 then return end
-- return instantly when another libcast is already active
if pfUI.api.libcast then return end
local lastcasttex, lastrank, _
local scanner = libtipscan:GetScanner("libcast")
local libcast = CreateFrame("Frame", "pfEnemyCast")
local player = UnitName("player")
@@ -61,7 +64,7 @@ UnitChannelInfo = _G.UnitChannelInfo or function(unit)
if db and db.cast and db.start + db.casttime / 1000 > GetTime() then
if not db.channel then return end
cast = db.cast
nameSubtext = ""
nameSubtext = db.rank
text = ""
texture = db.icon
startTime = db.start * 1000
@@ -70,6 +73,7 @@ UnitChannelInfo = _G.UnitChannelInfo or function(unit)
elseif db then
-- remove cast action to the database
db.cast = nil
db.rank = nil
db.start = nil
db.casttime = nil
db.icon = nil
@@ -90,7 +94,7 @@ UnitCastingInfo = _G.UnitCastingInfo or function(unit)
if db and db.cast and db.start + db.casttime / 1000 > GetTime() then
if db.channel then return end
cast = db.cast
nameSubtext = ""
nameSubtext = db.rank or ""
text = ""
texture = db.icon
startTime = db.start * 1000
@@ -99,6 +103,7 @@ UnitCastingInfo = _G.UnitCastingInfo or function(unit)
elseif db then
-- remove cast action to the database
db.cast = nil
db.rank = nil
db.start = nil
db.casttime = nil
db.icon = nil
@@ -118,6 +123,7 @@ function libcast:AddAction(mob, spell, channel)
-- add cast action to the database
if not self.db[mob] then self.db[mob] = {} end
self.db[mob].cast = spell
self.db[mob].rank = nil
self.db[mob].start = GetTime()
self.db[mob].casttime = casttime
self.db[mob].icon = icon
@@ -134,6 +140,7 @@ function libcast:RemoveAction(mob, spell)
-- remove cast action to the database
self.db[mob].cast = nil
self.db[mob].rank = nil
self.db[mob].start = nil
self.db[mob].casttime = nil
self.db[mob].icon = nil
@@ -164,12 +171,6 @@ libcast:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_CREATURE_BUFFS")
libcast:RegisterEvent("CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE")
libcast:RegisterEvent("CHAT_MSG_SPELL_CREATURE_VS_CREATURE_BUFF")
-- scan for textures
local lastcasttex = nil
hooksecurefunc("UseAction", function(id) lastcasttex = GetActionTexture(id) end)
hooksecurefunc("CastSpell", function(id, bookType) lastcasttex = GetSpellTexture(id, bookType) end)
hooksecurefunc("UseContainerItem", function(id, index) lastcasttex = GetContainerItemInfo(id, index) end)
-- player spells
libcast:RegisterEvent("SPELLCAST_START")
libcast:RegisterEvent("SPELLCAST_STOP")
@@ -187,6 +188,7 @@ libcast:SetScript("OnEvent", function()
local icon = L["spells"][arg1] and L["spells"][arg1].icon and string.format("%s%s", "Interface\\Icons\\", L["spells"][arg1].icon) or lastcasttex
-- add cast action to the database
this.db[player].cast = arg1
this.db[player].rank = lastrank
this.db[player].start = GetTime()
this.db[player].casttime = arg2
this.db[player].icon = icon
@@ -196,17 +198,19 @@ libcast:SetScript("OnEvent", function()
L["spells"][arg1].icon = L["spells"][arg1].icon or icon
L["spells"][arg1].t = L["spells"][arg1].t or arg2
end
lastcasttex = nil
lastcasttex, lastrank = nil, nil
elseif event == "SPELLCAST_STOP" or event == "SPELLCAST_FAILED" or event == "SPELLCAST_INTERRUPTED" then
if this.db[player] and not this.db[player].channel then
-- remove cast action to the database
this.db[player].cast = nil
this.db[player].rank = nil
this.db[player].rank = nil
this.db[player].start = nil
this.db[player].casttime = nil
this.db[player].icon = nil
this.db[player].channel = nil
else
lastcasttex = nil
lastcasttex, lastrank = nil, nil
end
elseif event == "SPELLCAST_DELAYED" then
if this.db[player].cast then
@@ -215,15 +219,17 @@ libcast:SetScript("OnEvent", function()
elseif event == "SPELLCAST_CHANNEL_START" then
-- add cast action to the database
this.db[player].cast = arg2
this.db[player].rank = lastrank
this.db[player].start = GetTime()
this.db[player].casttime = arg1
this.db[player].icon = L["spells"][arg2] and L["spells"][arg2].icon and string.format("%s%s", "Interface\\Icons\\", L["spells"][arg2].icon) or lastcasttex
this.db[player].channel = true
lastcasttex = nil
lastcasttex, lastrank = nil, nil
elseif event == "SPELLCAST_CHANNEL_STOP" then
if this.db[player] and this.db[player].channel then
-- remove cast action to the database
this.db[player].cast = nil
this.db[player].rank = nil
this.db[player].start = nil
this.db[player].casttime = nil
this.db[player].icon = nil
@@ -312,6 +318,7 @@ libcast.customcast[strlower(aimedshot)] = function(begin)
-- add cast action to the database
libcast.db[player].cast = aimedshot
libcast.db[player].rank = lastrank
libcast.db[player].start = start
libcast.db[player].casttime = duration
libcast.db[player].icon = icon
@@ -319,6 +326,7 @@ libcast.customcast[strlower(aimedshot)] = function(begin)
else
-- remove cast action to the database
libcast.db[player].cast = nil
libcast.db[player].rank = nil
libcast.db[player].start = nil
libcast.db[player].casttime = nil
libcast.db[player].icon = nil
@@ -334,6 +342,7 @@ libcast.customcast[strlower(multishot)] = function(begin)
-- add cast action to the database
libcast.db[player].cast = multishot
libcast.db[player].rank = lastrank
libcast.db[player].start = start
libcast.db[player].casttime = duration
libcast.db[player].icon = icon
@@ -341,6 +350,7 @@ libcast.customcast[strlower(multishot)] = function(begin)
else
-- remove cast action to the database
libcast.db[player].cast = nil
libcast.db[player].rank = nil
libcast.db[player].start = nil
libcast.db[player].casttime = nil
libcast.db[player].icon = nil
@@ -358,25 +368,37 @@ local function CastCustom(spell)
end
end
hooksecurefunc("UseContainerItem", function(id, index)
lastcasttex = GetContainerItemInfo(id, index)
end)
hooksecurefunc("CastSpell", function(id, bookType)
_, lastrank = libspell.GetSpellInfo(id, bookType)
lastcasttex = GetSpellTexture(id, bookType)
if GetSpellCooldown(id, bookType) ~= 0 then
local spellName = GetSpellName(id, bookType)
CastCustom(spellName)
end
end, true)
hooksecurefunc("CastSpellByName", function(spellName, target)
hooksecurefunc("CastSpellByName", function(spell, target)
_, lastrank = libspell.GetSpellInfo(spell)
for i=1,120 do
-- detect if any cast is ongoing
if IsCurrentAction(i) then
CastCustom(spellName)
CastCustom(spell)
return
end
end
end, true)
local scanner = libtipscan:GetScanner("libcast")
hooksecurefunc("UseAction", function(slot, target, button)
scanner:SetAction(slot)
_, lastrank = scanner:Line(1)
lastcasttex = GetActionTexture(slot)
if GetActionText(slot) or not IsCurrentAction(slot) then return end
scanner:SetAction(slot)
local spellName = scanner:Line(1)