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

extendBuff( aura, duration ) function for cleaner code #4114

Draft
wants to merge 10 commits into
base: thewarwithin
Choose a base branch
from
34 changes: 34 additions & 0 deletions State.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,40 @@ local function removeBuff( aura )
end
state.removeBuff = removeBuff

-- Modify buff/debuff remaining duration function, defaults to 1 second if no value supplied, breaks out if supplied a 0 or a faulty input
local function auraDuration( unit, aura, duration )

-- ???
if not aura then aura = unit; unit = "target" end
if duration == 0 then return false end -- dont waste time checking buffs to add 0 to it
duration = duration or 1 -- default to +1 second if no value is supplied

-- buff/debuff handling
local b = state.buff[ aura ]
if not b then
local d = state.debuff[ aura ]
if not d then -- you supplied an oopsie
Error( "Attempted to extend/shorten a nameless aura '%s'.\n\n%s", aura or "nil", debugstack() )
return false
else -- it's a debuff
if duration + d.remains <= 0 then --duration decrease will remove buff
removeDebuff( unit, aura )
else
d.expires = d.expires + duration
end
return true
end
else -- it's a buff
if duration + a.remains <= 0 then --duration decrease will remove buff
removeBuff( aura )
else
a.expires = a.expires + duration
end
return true
end

end
state.auraDuration = auraDuration

-- Apply stacks of a buff to the current game state.
-- Wraps around Buff() to check for an existing buff.
Expand Down