Add FindAny to aura tables, update subtlety, add APL AddVariable

pull/1/head
4n0n 2 years ago
parent 1aa8c67dd4
commit 0b329a6463
  1. 2192
      scripts/subtlety.lua
  2. 16
      src/APL/APL.lua
  3. 10
      src/AuraTable/AuraTable.lua
  4. 5
      src/Spell/Spell.lua
  5. 210
      src/Unit/Unit.lua

File diff suppressed because it is too large Load Diff

@ -70,7 +70,7 @@ end
-- Execute
function APLActor:Execute()
if self:GetActor().apl then
if self:GetActor().condition() then
if self:GetActor().condition and self:GetActor().condition() then
-- print("Bastion: APL:Execute: Executing sub APL " .. self:GetActor().apl.name)
self:GetActor().apl:Execute()
end
@ -99,6 +99,10 @@ function APLActor:Execute()
-- print("Bastion: APL:Execute: Executing action " .. self:GetActor().action)
self:GetActor().cb(self)
end
if self:GetActor().variable then
-- print("Bastion: APL:Execute: Setting variable " .. self:GetActor().variable)
self:GetActor()._apl.variables[self:GetActor().variable] = self:GetActor().cb(self:GetActor()._apl)
end
end
-- has traits
@ -137,6 +141,13 @@ function APL:GetVariable(name)
return self.variables[name]
end
-- Add variable
function APL:AddVariable(name, cb)
local actor = APLActor:New({ variable = name, cb = cb, _apl = self })
table.insert(self.apl, actor)
return actor
end
-- Add a manual action to the APL
function APL:AddAction(action, cb)
local actor = APLActor:New({ action = action, cb = cb })
@ -170,6 +181,9 @@ end
-- Add an APL to the APL (for sub APLs)
function APL:AddAPL(apl, condition)
if not condition then
error("Bastion: APL:AddAPL: No condition for APL " .. apl.name)
end
local actor = APLActor:New({ apl = apl, condition = condition })
table.insert(self.apl, actor)
return actor

@ -237,6 +237,16 @@ function AuraTable:FindMy(spell)
return Bastion.Aura:New()
end
-- Find any
function AuraTable:FindAny(spell)
local a = self:Find(spell)
if a:IsValid() then
return a
end
return self:FindMy(spell)
end
-- Has any stealable aura
function AuraTable:HasAnyStealableAura()
for _, auras in pairs(self:GetUnitAuras()) do

@ -91,6 +91,11 @@ function Spell:GetCooldownRemaining()
return start + duration - GetTime()
end
-- On cooldown
function Spell:OnCooldown()
return self:GetCooldownRemaining() > 0
end
-- Cast the spell
function Spell:Cast(unit, condition)
if condition and not self:EvaluateCondition(condition) then

@ -5,6 +5,10 @@ local Unit = {
cache = nil,
aura_table = nil,
unit = nil,
last_shadow_techniques = 0,
swings_since_sht = 0,
last_off_attack = 0,
last_main_attack = 0,
}
function Unit:__index(k)
@ -428,6 +432,15 @@ function Unit:GetComboPoints()
return UnitPower(self.unit, 4)
end
function Unit:GetComboPointsMax()
return UnitPowerMax(self.unit, 4)
end
-- Get combopoints deficit
function Unit:GetComboPointsDeficit()
return self:GetComboPointsMax() - self:GetComboPoints()
end
-- IsUnit
function Unit:IsUnit(unit)
return UnitIsUnit(self.unit, unit.unit)
@ -618,4 +631,201 @@ function Unit:GetCombatTime()
return GetTime() - self.last_combat_time
end
-- Get units gcd time
function Unit:GetGCD()
local start, duration = GetSpellCooldown(61304)
if start == 0 then
return 0
end
return duration - (GetTime() - start)
end
-- Get units max gcd time
--[[
The GCD without Haste is 1.5 seconds
With 50% Haste the GCD is 1 second
With 100% Haste the GCD is 0.5 seconds
The GCD won't drop below 1 second
More than 50% Haste will drop a spell below 1 second
]]
function Unit:GetMaxGCD()
local haste = UnitSpellHaste(self.unit)
if haste > 50 then
haste = 50
end
return 1.5 / (1 + haste / 100)
end
-- IsStealthed
function Unit:IsStealthed()
local Stealth = Bastion.SpellBook:GetSpell(1784)
local Vanish = Bastion.SpellBook:GetSpell(1856)
local ShadowDance = Bastion.SpellBook:GetSpell(185422)
local Subterfuge = Bastion.SpellBook:GetSpell(115192)
local Shadowmeld = Bastion.SpellBook:GetSpell(58984)
local Sepsis = Bastion.SpellBook:GetSpell(328305)
return self:GetAuras():FindAny(Stealth) or self:GetAuras():FindAny(ShadowDance)
end
-- Get unit swing timers
function Unit:GetSwingTimers()
local main_speed, off_speed = UnitAttackSpeed(self.unit)
local main_speed = main_speed or 2
local off_speed = off_speed or 2
local main_speed_remains = main_speed - (GetTime() - self.last_main_attack)
local off_speed_remains = off_speed - (GetTime() - self.last_off_attack)
if main_speed_remains < 0 then
main_speed_remains = 0
end
if off_speed_remains < 0 then
off_speed_remains = 0
end
return main_speed_remains, off_speed_remains
end
function Unit:WatchForSwings()
Bastion.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function()
local _, subtype, _, sourceGUID, sourceName, _, _, destGUID, destName, destFlags, _, spellID, spellName, _, amount, interrupt, a, b, c, d, offhand, multistrike = CombatLogGetCurrentEventInfo()
if sourceGUID == self:GetGUID() then
if subtype == "SPELL_ENERGIZE" and spellID == 196911 then
self.last_shadow_techniques = GetTime()
self.swings_since_sht = 0
end
if subtype:sub(1, 5) == "SWING" and not multistrike then
if subtype == "SWING_MISSED" then
offhand = spellName
end
local now = GetTime()
if now > self.last_shadow_techniques + 3 then
self.swings_since_sht = self.swings_since_sht + 1
end
if offhand then
self.last_off_attack = GetTime()
else
self.last_main_attack = GetTime()
end
end
end
end)
end
-- GetTimeToShurikenTornado
--[[
spec:RegisterStateTable( "time_to_sht", setmetatable( {}, {
__index = function( t, k )
local n = tonumber( k )
n = n - ( n % 1 )
if not n or n > 5 then return 3600 end
if n <= swings_since_sht then return 0 end
local mh_speed = swings.mainhand_speed
local mh_next = ( swings.mainhand > now - 3 ) and ( swings.mainhand + mh_speed ) or now + ( mh_speed * 0.5 )
local oh_speed = swings.offhand_speed
local oh_next = ( swings.offhand > now - 3 ) and ( swings.offhand + oh_speed ) or now
table.wipe( sht )
if mh_speed and mh_speed > 0 then
for i = 1, 4 do
insert( sht, mh_next + ( i * mh_speed ) )
end
end
if oh_speed and oh_speed > 0 then
for i = 1, 4 do
insert( sht, oh_next + ( i * oh_speed ) )
end
end
local i = 1
while( sht[i] ) do
if sht[i] < last_shadow_techniques + 3 then
table.remove( sht, i )
else
i = i + 1
end
end
if #sht > 0 and n - swings_since_sht < #sht then
table.sort( sht )
return max( 0, sht[ n - swings_since_sht ] - query_time )
else
return 3600
end
end
} ) )
]]
function Unit:GetTimeToShurikenTornado(n)
local now = GetTime()
local sht = {}
local swings = self:GetSwingTimers()
if not self.swings_since_sht then
self.swings_since_sht = 0
end
if not self.last_shadow_techniques then
self.last_shadow_techniques = 0
end
if n <= self.swings_since_sht then
return 0
end
local mh_speed = swings[1]
local mh_next = (self.last_mh > now - 3) and (self.last_mh + mh_speed) or now + (mh_speed * 0.5)
local oh_speed = swings[2]
local oh_next = (self.last_oh > now - 3) and (self.last_oh + oh_speed) or now
table.wipe(sht)
if mh_speed and mh_speed > 0 then
for i = 1, 4 do
table.insert(sht, mh_next + (i * mh_speed))
end
end
if oh_speed and oh_speed > 0 then
for i = 1, 4 do
table.insert(sht, oh_next + (i * oh_speed))
end
end
local i = 1
while (sht[i]) do
if sht[i] < self.last_shadow_techniques + 3 then
table.remove(sht, i)
else
i = i + 1
end
end
if #sht > 0 and n - self.swings_since_sht < #sht then
table.sort(sht)
return math.max(0, sht[n - self.swings_since_sht] - now)
else
return 3600
end
end
return Unit

Loading…
Cancel
Save