Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/TekNoLogic/Cork
Browse files Browse the repository at this point in the history
  • Loading branch information
tekkub committed Aug 7, 2016
2 parents c46a0ac + 5c0e86d commit 100e869
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 21 deletions.
17 changes: 10 additions & 7 deletions Cork.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ ae.RegisterEvent("Cork", "ADDON_LOADED", function(event, addon)
if addon:lower() ~= "cork" then return end

CorkDB = setmetatable(CorkDB or {}, {__index = defaults})
CorkDBPC = CorkDBPC or {{},{}}
if not CorkDBPC[1] then CorkDBPC = {CorkDBPC, {}} end
CorkDBPC = CorkDBPC or {{},{},{},{}}
if not CorkDBPC[1] then CorkDBPC = {CorkDBPC, {}, {}, {}} end
for _, i in ipairs({2,3,4}) do
if not CorkDBPC[i] then CorkDBPC[i] = {} end
end
Cork.db = CorkDB

anchor:SetPoint(Cork.db.point, Cork.db.x, Cork.db.y)
Expand All @@ -35,19 +38,19 @@ end)

local meta = {__index = Cork.defaultspc}
ae.RegisterEvent("Cork", "PLAYER_LOGIN", function()
local lastgroup = GetActiveSpecGroup()
Cork.dbpc = setmetatable(CorkDBPC[lastgroup], meta)
local lastspec = GetSpecialization()
Cork.dbpc = setmetatable(CorkDBPC[lastspec], meta)

for _,dataobj in pairs(Cork.sortedcorks) do if dataobj.Init then dataobj:Init() end end
for _,dataobj in pairs(Cork.sortedcorks) do dataobj:Scan() end

ae.RegisterEvent("Cork", "ZONE_CHANGED_NEW_AREA", Cork.Update)
ae.RegisterEvent("Cork", "PLAYER_TALENT_UPDATE", function()
if lastgroup == GetActiveSpecGroup() then return end
if lastspec == GetSpecialization() then return end

lastgroup = GetActiveSpecGroup()
lastspec = GetSpecialization()
for i,v in pairs(Cork.defaultspc) do if Cork.dbpc[i] == v then Cork.dbpc[i] = nil end end
Cork.dbpc = setmetatable(CorkDBPC[lastgroup], meta)
Cork.dbpc = setmetatable(CorkDBPC[lastspec], meta)

if Cork.config.Update then Cork.config:Update() end
for name,dataobj in pairs(Cork.corks) do if dataobj.Init then dataobj:Init() end end
Expand Down
95 changes: 81 additions & 14 deletions modules/Paladin.lua
Original file line number Diff line number Diff line change
@@ -1,27 +1,94 @@

local myname, Cork = ...
if Cork.MYCLASS ~= "PALADIN" then return end

local ldb, ae = LibStub:GetLibrary("LibDataBroker-1.1"), LibStub("AceEvent-3.0")

-- Righteous Fury
local spellname, _, icon = GetSpellInfo(25780)
Cork:GenerateSelfBuffer(spellname, icon)

-- Greater Blessings are any combination of 3 blessings across the whole raid.
local spellnames = {(GetSpellInfo(203538)), (GetSpellInfo(203528)), (GetSpellInfo(203539))}
local _, _, icon = GetSpellInfo(203538)
local rolespells = {TANK=1, DAMAGER=2, HEALER=3}
local dataobj = ldb:NewDataObject("Cork Greater Blessings", {
type = "cork",
corktype = "buff",
tiplink = GetSpellLink(203538)
})

-- Greater Blessing of Might
local spellname, _, icon = GetSpellInfo(203528)
Cork:GenerateSelfBuffer(spellname, icon)


-- Greater Blessing of Kings
local spellname, _, icon = GetSpellInfo(203538)
Cork:GenerateSelfBuffer(spellname, icon)


-- Greater Blessing of Wisdom
local spellname, _, icon = GetSpellInfo(203539)
Cork:GenerateSelfBuffer(spellname, icon)
function dataobj:Init()
Cork.defaultspc["Greater Blessings-enabled"] = GetSpellInfo(spellnames[1]) ~= nil
print("Blessings init: "..(Cork.defaultspc["Greater Blessings-enabled"] and "enabled" or "disabled"))
end

local raidunits, partyunits, otherunits = {}, {}, { ["player"] = true }
for i=1,40 do raidunits["raid"..i] = i end
for i=1,4 do partyunits["party"..i] = i end
function dataobj:Test(unit)
if not UnitExists(unit) or (unit ~= "player" and UnitIsUnit(unit, "player"))
or (IsInRaid() and partyunits[unit])
or (not raidunits[unit] and not partyunits[unit] and not otherunits[unit]) then return 0 end
local count = 0
for _, spellname in ipairs(spellnames) do
if UnitAura(unit, spellname, nil, "PLAYER") then
count = count + 1
end
end
return count
end
function dataobj:Scan(enteringcombat)
if not Cork.dbpc["Greater Blessings-enabled"] or (IsResting() and not Cork.db.debug) or (enteringcombat or InCombatLockdown()) then
self.player = nil
return
end
local count = self:Test("player")
-- We can't scan the same unit twice or we'll get inaccurate results
if IsInRaid() then
for k, _ in pairs(raidunits) do
count = count + self:Test(k)
if count >= 3 then break end
end
elseif IsInGroup() then
for k, _ in pairs(partyunits) do
count = count + self:Test(k)
if count >= 3 then break end
end
end
if count < 3 then
self.player = Cork.IconLine(icon, string.format("Greater Blessings (%d)", 3 - count))
else
self.player = nil
end
end
function dataobj:CorkIt(frame)
if self.player and Cork.SpellCastableOnUnit(spellnames[1], "player") then
-- figure out which spell in the list we don't have
-- prioritize the first spell based on our role
local role = GetSpecializationRole(GetSpecialization())
local rolespell = rolespells[role]
if role and not UnitAura("player", spellnames[rolespell], nil, "PLAYER") then -- should this be player-only?
return frame:SetManyAttributes("type1", "spell", "spell", spellnames[rolespell], "unit", "player")
end
-- otherwise just do the spells in order
for _, spellname in ipairs(spellnames) do
if not UnitAura("player", spellname, nil, "PLAYER") then -- should this be player-only?
return frame:SetManyAttributes("type1", "spell", "spell", spellname, "unit", "player")
end
end
end
end
local function isScanUnit(unit)
return not not (raidunits[unit] or partyunits[unit] or otherunits[unit])
end
function dataobj:TestUnit(event, unit)
if isScanUnit(unit) then self:Scan() end
end
ae.RegisterEvent(dataobj, "UNIT_AURA", "TestUnit")
ae.RegisterEvent(dataobj, "GROUP_ROSTER_UPDATE", "TestUnit")
ae.RegisterEvent(dataobj, "PLAYER_UPDATE_RESTING", function () dataobj:Scan() end)
ae.RegisterEvent(dataobj, "PLAYER_REGEN_DISABLED", function () dataobj:Scan(true) end)
ae.RegisterEvent(dataobj, "PLAYER_REGEN_ENABLED", function () dataobj:Scan() end)

-- Beacon of Light
local spellname, _, icon = GetSpellInfo(53563)
Expand Down

0 comments on commit 100e869

Please sign in to comment.