Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized Blessing Auto Assignments #13

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
151 changes: 94 additions & 57 deletions PallyPower.lua
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ local function tablecopy(tbl)
end

local function safeget(t,k) -- always return nil or t[k] if at least t is a table / Treeston
return t and t[k]
return t and t[k]
end

function PallyPowerBlessings_Clear()
Expand Down Expand Up @@ -2078,7 +2078,7 @@ function PallyPower:UpdateRoster()
local n = select(3, unitid:find("(%d+)"))
tmp.name, tmp.rank, tmp.subgroup = GetRaidRosterInfo(n)
tmp.zone = select(7, GetRaidRosterInfo(n))

if self.opt.hideHighGroups then
local maxPlayerCount = (select(5, GetInstanceInfo()))
if maxPlayerCount and (maxPlayerCount > 5) then
Expand All @@ -2088,10 +2088,10 @@ function PallyPower:UpdateRoster()
end
end
end

local raidtank = select(10, GetRaidRosterInfo(n))
tmp.tank = ((raidtank == "MAINTANK") or (self.opt.mainAssist and (raidtank == "MAINASSIST")))

local class = self:GetClassID(pclass)
-- Warriors and Death Knights
if (class == 1 or (self.isWrath and class == 10)) then
Expand Down Expand Up @@ -2625,7 +2625,7 @@ function PallyPower:UpdateButton(button, baseName, classID)
if (not unit.visible) and InCombatLockdown() then
state = "have"
end

if state == "need_big" then
nneed = nneed + 1
elseif state == "need_small" then
Expand Down Expand Up @@ -2822,7 +2822,7 @@ function PallyPower:UpdatePButton(button, baseName, classID, playerID, mousebutt
buffIcon:SetTexture(self.BlessingIcons[spellID])
buffIcon:SetVertexColor(1, 1, 1)
time:SetText(self:FormatTime(unit.hasbuff))

-- The following logic keeps Blessing of Salvation from being assigned to Warrior, Druid and Paladin tanks while in a RAID
-- and SalvInCombat isn't enabled. Allows Normal Blessing of Salvation on everyone else and all other blessings.
if not InCombatLockdown() then
Expand Down Expand Up @@ -2857,7 +2857,7 @@ function PallyPower:UpdatePButton(button, baseName, classID, playerID, mousebutt
button:SetAttribute("spell2", nSpell)
end
end

local state = ClassifyUnitBuffStateForButton(unit)
if state == "need_big" then
self:ApplyBackdrop(button, self.opt.cBuffNeedAll)
Expand All @@ -2866,7 +2866,7 @@ function PallyPower:UpdatePButton(button, baseName, classID, playerID, mousebutt
else
self:ApplyBackdrop(button, self.opt.cBuffGood)
end

if unit.hasbuff then
buffIcon:SetAlpha(1)
if not unit.visible and not unit.inrange then
Expand Down Expand Up @@ -3485,7 +3485,7 @@ function PallyPower:AutoBuff(button, mousebutton)
buffExpire = 0
penalty = 0
end

if not self.isWrath and gspellID == 4 then
-- If for some reason the targeted unit is in combat and there is a tank present
-- in the Class Group then disable Greater Blessing of Salvation for this unit.
Expand All @@ -3501,7 +3501,7 @@ function PallyPower:AutoBuff(button, mousebutton)
penalty = 9999
end
end

if (not PallyPower.petsShareBaseClass) and unit.unitid:find("pet") then
buffExpire = 9999
penalty = 9999
Expand Down Expand Up @@ -3590,7 +3590,7 @@ function PallyPower:AutoBuff(button, mousebutton)
-- Raid than there are buffs to assign so an Alternate Blessing might not be in
-- use to wipe Salvation from a tank. Prevents getting stuck buffing a tank when
-- auto buff rotates among players in the class group.

if unit.tank then
if not self.isWrath and (spellID == 4 and not self.opt.SalvInCombat) then
buffExpire = 9999
Expand Down Expand Up @@ -3844,7 +3844,7 @@ function PallyPower:LoadPreset()
for pname, passignments in pairs(PallyPower_NormalAssignments) do
if (AllPallys[pname] and PallyPower:GetUnitIdByName(pname) and passignments) then
for class, cassignments in pairs(passignments) do
if cassignments then
if cassignments then
for tname, value in pairs(cassignments) do
PallyPower:SendNormalBlessings(pname, class, tname)
end
Expand Down Expand Up @@ -4007,25 +4007,58 @@ function PallyPower:SelectBuffsByClass(pallycount, class, prioritylist)
tinsert(pallys, name)
end
end
local bufftable = prioritylist
if pallycount > 0 then
local pallycounter = 1
for _, nextspell in pairs(bufftable) do
if pallycounter <= pallycount then
local buffer = self:BuffSelections(nextspell, class, pallys)
for i in pairs(pallys) do
if buffer == pallys[i] then
tremove(pallys, i)

if not self:BuffSelectionOptimized(pallys, class, prioritylist) then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a quick look over your code, if I unserstand correctly - you added a new logic for the greater Blessing-Assignments "onTop" of the old AutoAssignment-Logic and you completely fallback to this old assignment-code when your logic "fails".

I think when we do a logic refresh we should get rid of the old code (BuffSelections stuff) entirely

local bufftable = prioritylist
if pallycount > 0 then
local pallycounter = 1
for _, nextspell in pairs(bufftable) do
if pallycounter <= pallycount then
local buffer = self:BuffSelections(nextspell, class, pallys)
for i in pairs(pallys) do
if buffer == pallys[i] then
tremove(pallys, i)
end
end
if buffer ~= "" then
pallycounter = pallycounter + 1
end
end
if buffer ~= "" then
pallycounter = pallycounter + 1
end
end
end
end
end

function PallyPower:BuffSelectionOptimized(pallys, class, prioritylist)
local buffers = self.isWrath and {
[1] = WisdomPallys,
[2] = MightPallys,
[3] = KingsPallys,
[4] = SancPallys,
} or {
[1] = WisdomPallys,
[2] = MightPallys,
[3] = KingsPallys,
[4] = SalvPallys,
[5] = LightPallys,
[6] = SancPallys,
}
local assignments = PallyPowerAutoAssignments(pallys, prioritylist, buffers)
if assignments == nil then
return false
end

for buff, buffer in pairs(assignments) do
if PallyPower_Assignments[buffer] == nil then
PallyPower_Assignments[buffer] = {}
end
PallyPower_Assignments[buffer][class] = buff
self:TankNormalBlessingOverride(buff, class, buffer)
end

return true
end

function PallyPower:BuffSelections(buff, class, pallys)
local t = {}
if buff == 1 then
Expand Down Expand Up @@ -4073,49 +4106,53 @@ function PallyPower:BuffSelections(buff, class, pallys)
else
PallyPower_Assignments[Buffer][class] = buff
end
if IsInRaid() then
-----------------------------------------------------------------------------------------------------------------
-- Warriors and Death Knights
-----------------------------------------------------------------------------------------------------------------
if (buff == self.opt.mainTankGSpellsW) and (class == 1 or (self.isWrath and class == 10)) and self.opt.mainTank then
for i = 1, MAX_RAID_MEMBERS do
local playerName, _, _, _, playerClass = GetRaidRosterInfo(i)
if playerName and self:CheckMainTanks(playerName) and (class == self:GetClassID(string.upper(playerClass))) then
SetNormalBlessings(Buffer, class, playerName, self.opt.mainTankSpellsW)
end
self:TankNormalBlessingOverride(buff, class, Buffer)
else
end
return Buffer
end

function PallyPower:TankNormalBlessingOverride(buff, class, Buffer)
if IsInRaid() then
-----------------------------------------------------------------------------------------------------------------
-- Warriors and Death Knights
-----------------------------------------------------------------------------------------------------------------
if (buff == self.opt.mainTankGSpellsW) and (class == 1 or (self.isWrath and class == 10)) and self.opt.mainTank then
for i = 1, MAX_RAID_MEMBERS do
local playerName, _, _, _, playerClass = GetRaidRosterInfo(i)
if playerName and self:CheckMainTanks(playerName) and (class == self:GetClassID(string.upper(playerClass))) then
SetNormalBlessings(Buffer, class, playerName, self.opt.mainTankSpellsW)
end
end
if (buff == self.opt.mainAssistGSpellsW) and (class == 1 or (self.isWrath and class == 10)) and self.opt.mainAssist then
for i = 1, MAX_RAID_MEMBERS do
local playerName, _, _, _, playerClass = GetRaidRosterInfo(i)
if playerName and self:CheckMainAssists(playerName) and (class == self:GetClassID(string.upper(playerClass))) then
SetNormalBlessings(Buffer, class, playerName, self.opt.mainAssistSpellsW)
end
end
if (buff == self.opt.mainAssistGSpellsW) and (class == 1 or (self.isWrath and class == 10)) and self.opt.mainAssist then
for i = 1, MAX_RAID_MEMBERS do
local playerName, _, _, _, playerClass = GetRaidRosterInfo(i)
if playerName and self:CheckMainAssists(playerName) and (class == self:GetClassID(string.upper(playerClass))) then
SetNormalBlessings(Buffer, class, playerName, self.opt.mainAssistSpellsW)
end
end
-----------------------------------------------------------------------------------------------------------------
-- Druids and Paladins
-----------------------------------------------------------------------------------------------------------------
if (buff == self.opt.mainTankGSpellsDP) and (class == 4 or class == 5) and self.opt.mainTank then
for i = 1, MAX_RAID_MEMBERS do
local playerName, _, _, _, playerClass = GetRaidRosterInfo(i)
if playerName and self:CheckMainTanks(playerName) and (class == self:GetClassID(string.upper(playerClass))) then
SetNormalBlessings(Buffer, class, playerName, self.opt.mainTankSpellsDP)
end
end
-----------------------------------------------------------------------------------------------------------------
-- Druids and Paladins
-----------------------------------------------------------------------------------------------------------------
if (buff == self.opt.mainTankGSpellsDP) and (class == 4 or class == 5) and self.opt.mainTank then
for i = 1, MAX_RAID_MEMBERS do
local playerName, _, _, _, playerClass = GetRaidRosterInfo(i)
if playerName and self:CheckMainTanks(playerName) and (class == self:GetClassID(string.upper(playerClass))) then
SetNormalBlessings(Buffer, class, playerName, self.opt.mainTankSpellsDP)
end
end
if (buff == self.opt.mainAssistGSpellsDP) and (class == 4 or class == 5) and self.opt.mainAssist then
for i = 1, MAX_RAID_MEMBERS do
local playerName, _, _, _, playerClass = GetRaidRosterInfo(i)
if playerName and self:CheckMainAssists(playerName) and (class == self:GetClassID(string.upper(playerClass))) then
SetNormalBlessings(Buffer, class, playerName, self.opt.mainAssistSpellsDP)
end
end
if (buff == self.opt.mainAssistGSpellsDP) and (class == 4 or class == 5) and self.opt.mainAssist then
for i = 1, MAX_RAID_MEMBERS do
local playerName, _, _, _, playerClass = GetRaidRosterInfo(i)
if playerName and self:CheckMainAssists(playerName) and (class == self:GetClassID(string.upper(playerClass))) then
SetNormalBlessings(Buffer, class, playerName, self.opt.mainAssistSpellsDP)
end
end
end
else
end
return Buffer
end

function PallyPower:PallyAvailable(pally, pallys)
Expand Down
1 change: 1 addition & 0 deletions PallyPower.toc
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ locale\zhTW.lua
PallyPower.lua
PallyPowerValues.lua
PallyPowerOptions.lua
PallyPowerAutoAssignment.lua
PallyPower_Wrath.xml
Loading