Merge branch 'main' into main

pull/10/head
abunai 2 years ago
commit 764d995516
  1. 4
      .gitignore
  2. 17
      scripts/ExampleModule.lua
  3. 14
      scripts/Libraries/ExampleLibrary.lua
  4. 2
      src/APL/APL.lua
  5. 1
      src/AuraTable/AuraTable.lua
  6. 16
      src/List/List.lua
  7. 3
      src/Sequencer/Sequencer.lua
  8. 19
      src/Unit/Unit.lua
  9. 10
      src/UnitManager/UnitManager.lua
  10. 46
      src/Vector3/Vector3.lua
  11. 57
      src/_bastion.lua

4
.gitignore vendored

@ -7,7 +7,11 @@ DS_Store
## ignore all files in scripts ## ignore all files in scripts
scripts/* scripts/*
!scripts/Libraries
scripts/Libraries/*
!scripts/.gitkeep !scripts/.gitkeep
!scripts/ExampleModule.lua
!scripts/Libraries/ExampleLibrary.lua
## ignore vscode settings ## ignore vscode settings
.vscode/* .vscode/*

@ -0,0 +1,17 @@
local Tinkr, Bastion = ...
local ExampleModule = Bastion.Module:New('ExampleModule')
local Player = Bastion.UnitManager:Get('player')
local FlashHeal = Bastion.SpellBook:GetSpell(2061)
local AdvancedMath = Bastion:GetLibrary('AdvancedMath')
print(AdvancedMath:Add(1, 2))
ExampleModule:Sync(function()
if Player:GetHP() <= 50 then
FlashHeal:Cast(Player)
end
end)
Bastion:Register(ExampleModule)

@ -0,0 +1,14 @@
local Tinkr, Bastion = ...
local ExampleModule = Bastion.Module:New('ExampleModule')
local Player = Bastion.UnitManager:Get('player')
local AdvancedMath = {}
AdvancedMath.__index = AdvancedMath
function AdvancedMath:Add(a, b)
return a + b
end
Bastion:RegisterLibrary('AdvancedMath', AdvancedMath)

@ -206,7 +206,7 @@ end
-- Add a spell to the APL -- Add a spell to the APL
---@param spell Spell ---@param spell Spell
---@param condition fun(...):boolean ---@param condition? fun(...):boolean
---@return APLActor ---@return APLActor
function APL:AddSpell(spell, condition) function APL:AddSpell(spell, condition)
local castableFunc = spell.CastableIfFunc local castableFunc = spell.CastableIfFunc

@ -275,7 +275,6 @@ function AuraTable:Find(spell)
end end
for k, a in pairs(aurasub) do for k, a in pairs(aurasub) do
print(a)
if a ~= nil then if a ~= nil then
if a:IsUp() then -- Handle expired and non refreshed dropoffs not coming in UNIT_AURA if a:IsUp() then -- Handle expired and non refreshed dropoffs not coming in UNIT_AURA
return a return a

@ -90,9 +90,9 @@ function List:each(callback)
end end
---@param callback fun(value: any): boolean ---@param callback fun(value: any): boolean
---@return boolean ---@return List
function List:map(callback) function List:map(callback)
local newList = List.new() local newList = List:New()
for _, v in ipairs(self._list) do for _, v in ipairs(self._list) do
newList:push(callback(v)) newList:push(callback(v))
end end
@ -100,9 +100,9 @@ function List:map(callback)
end end
---@param callback fun(value: any): boolean ---@param callback fun(value: any): boolean
---@return boolean ---@return List
function List:filter(callback) function List:filter(callback)
local newList = List.new() local newList = List:New()
for _, v in ipairs(self._list) do for _, v in ipairs(self._list) do
if callback(v) then if callback(v) then
newList:push(v) newList:push(v)
@ -111,7 +111,7 @@ function List:filter(callback)
return newList return newList
end end
---@param callback fun(value: any): boolean ---@param callback fun(result: any, value: any): boolean
---@param initialValue any ---@param initialValue any
---@return boolean ---@return boolean
function List:reduce(callback, initialValue) function List:reduce(callback, initialValue)
@ -152,7 +152,7 @@ end
---@return List ---@return List
function List:reverse() function List:reverse()
local newList = List.new() local newList = List:New()
for i = #self._list, 1, -1 do for i = #self._list, 1, -1 do
newList:push(self._list[i]) newList:push(self._list[i])
end end
@ -161,7 +161,7 @@ end
---@return List ---@return List
function List:clone() function List:clone()
local newList = List.new() local newList = List:New()
for _, v in ipairs(self._list) do for _, v in ipairs(self._list) do
newList:push(v) newList:push(v)
end end
@ -171,7 +171,7 @@ end
---@param list List ---@param list List
---@return List ---@return List
function List:concat(list) function List:concat(list)
local newList = List.new() local newList = List:New()
for _, v in ipairs(self._list) do for _, v in ipairs(self._list) do
newList:push(v) newList:push(v)
end end

@ -1,6 +1,9 @@
-- Create a sequencer class that takes a table of actions and executes them in order -- Create a sequencer class that takes a table of actions and executes them in order
---@class Sequencer ---@class Sequencer
---@field resetCondition fun(): boolean
---@field abortCondition fun(): boolean
---@field actions fun(sequencer: Sequencer)[]
local Sequencer = {} local Sequencer = {}
Sequencer.__index = Sequencer Sequencer.__index = Sequencer

@ -1125,6 +1125,25 @@ function Unit:IsWithinCone(Target, Angle, Distance, rotation)
return diff <= Angle and self:GetDistance(Target) <= Distance return diff <= Angle and self:GetDistance(Target) <= Distance
end end
function Unit:GetEmpoweredStage()
local stage = 0
local _, _, _, startTime, _, _, _, spellID, _, numStages = UnitChannelInfo(self:GetOMToken())
if numStages and numStages > 0 then
startTime = startTime / 1000
local currentTime = GetTime()
local stageDuration = 0
for i = 1, numStages do
stageDuration = stageDuration + GetUnitEmpowerStageDuration((self:GetOMToken()), i - 1) / 1000
if startTime + stageDuration > currentTime then
break
end
stage = i
end
end
return stage
end
-- local empowering = {} -- local empowering = {}
-- Bastion.EventManager:RegisterWoWEvent("UNIT_SPELLCAST_EMPOWER_START", function(...) -- Bastion.EventManager:RegisterWoWEvent("UNIT_SPELLCAST_EMPOWER_START", function(...)

@ -153,7 +153,7 @@ end
-- Set a unit by guid -- Set a unit by guid
---@param unit Unit ---@param unit Unit
---@return Unit ---@return nil
function UnitManager:SetObject(unit) function UnitManager:SetObject(unit)
self.objects[unit:GetGUID()] = unit self.objects[unit:GetGUID()] = unit
end end
@ -224,6 +224,7 @@ function UnitManager:GetNumFriendsWithBuff(spell)
if unit:GetAuras():FindMy(spell):IsUp() then if unit:GetAuras():FindMy(spell):IsUp() then
count = count + 1 count = count + 1
end end
return false
end) end)
return count return count
end end
@ -236,6 +237,7 @@ function UnitManager:GetNumFriendsAlive()
if unit:IsAlive() then if unit:IsAlive() then
count = count + 1 count = count + 1
end end
return false
end) end)
return count return count
end end
@ -255,6 +257,7 @@ function UnitManager:GetFriendWithMostFriends(radius)
if other:IsAlive() and u:GetDistance(other) <= radius then if other:IsAlive() and u:GetDistance(other) <= radius then
c = c + 1 c = c + 1
end end
return false
end) end)
if c > count then if c > count then
unit = u unit = u
@ -264,9 +267,11 @@ function UnitManager:GetFriendWithMostFriends(radius)
if other:IsAlive() and u:GetDistance(other) <= radius then if other:IsAlive() and u:GetDistance(other) <= radius then
table.insert(friends, other) table.insert(friends, other)
end end
return false
end) end)
end end
end end
return false
end) end)
return unit, friends return unit, friends
end end
@ -283,6 +288,7 @@ function UnitManager:GetEnemiesWithMostEnemies(radius)
if other:IsAlive() and u:GetDistance(other) <= radius then if other:IsAlive() and u:GetDistance(other) <= radius then
c = c + 1 c = c + 1
end end
return false
end) end)
if c > count then if c > count then
unit = u unit = u
@ -292,9 +298,11 @@ function UnitManager:GetEnemiesWithMostEnemies(radius)
if other:IsAlive() and u:GetDistance(other) <= radius then if other:IsAlive() and u:GetDistance(other) <= radius then
table.insert(enemies, other) table.insert(enemies, other)
end end
return false
end) end)
end end
end end
return false
end) end)
return unit, enemies return unit, enemies
end end

@ -1,7 +1,7 @@
-- Create a Vector3 class -- Create a Vector3 class
---@class Vector3 ---@class Vector3
local Vector3 = {} local Vector3 = { }
Vector3.__index = Vector3 Vector3.__index = Vector3
---@return string ---@return string
@ -69,87 +69,129 @@ function Vector3:__index(k)
return Vector3[k] return Vector3[k]
end end
---@class Vector3
---@field length number
if k == "length" then if k == "length" then
return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z) return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
end end
---@class Vector3
---@field normalized Vector3
if k == "normalized" then if k == "normalized" then
local length = math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z) local length = math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
return Vector3:New(self.x / length, self.y / length, self.z / length) return Vector3:New(self.x / length, self.y / length, self.z / length)
end end
---@class Vector3
---@field magnitude number
if k == "magnitude" then if k == "magnitude" then
return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z) return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
end end
---@class Vector3
---@field sqrMagnitude number
if k == "sqrMagnitude" then if k == "sqrMagnitude" then
return self.x * self.x + self.y * self.y + self.z * self.z return self.x * self.x + self.y * self.y + self.z * self.z
end end
---@class Vector3
---@field zero Vector3
if k == "zero" then if k == "zero" then
return Vector3:New(0, 0, 0) return Vector3:New(0, 0, 0)
end end
---@class Vector3
---@field one Vector3
if k == "one" then if k == "one" then
return Vector3:New(1, 1, 1) return Vector3:New(1, 1, 1)
end end
---@class Vector3
---@field up Vector3
if k == "up" then if k == "up" then
return Vector3:New(0, 1, 0) return Vector3:New(0, 1, 0)
end end
---@class Vector3
---@field down Vector3
if k == "down" then if k == "down" then
return Vector3:New(0, -1, 0) return Vector3:New(0, -1, 0)
end end
---@class Vector3
---@field left Vector3
if k == "left" then if k == "left" then
return Vector3:New(-1, 0, 0) return Vector3:New(-1, 0, 0)
end end
---@class Vector3
---@field right Vector3
if k == "right" then if k == "right" then
return Vector3:New(1, 0, 0) return Vector3:New(1, 0, 0)
end end
---@class Vector3
---@field forward Vector3
if k == "forward" then if k == "forward" then
return Vector3:New(0, 0, 1) return Vector3:New(0, 0, 1)
end end
---@class Vector3
---@field back Vector3
if k == "back" then if k == "back" then
return Vector3:New(0, 0, -1) return Vector3:New(0, 0, -1)
end end
---@class Vector3
---@field positiveInfinity Vector3
if k == "positiveInfinity" then if k == "positiveInfinity" then
return Vector3:New(math.huge, math.huge, math.huge) return Vector3:New(math.huge, math.huge, math.huge)
end end
---@class Vector3
---@field negativeInfinity Vector3
if k == "negativeInfinity" then if k == "negativeInfinity" then
return Vector3:New(-math.huge, -math.huge, -math.huge) return Vector3:New(-math.huge, -math.huge, -math.huge)
end end
---@class Vector3
---@field nan Vector3
if k == "nan" then if k == "nan" then
return Vector3:New(0 / 0, 0 / 0, 0 / 0) return Vector3:New(0 / 0, 0 / 0, 0 / 0)
end end
---@class Vector3
---@field epsilon number
if k == "epsilon" then if k == "epsilon" then
return 1.401298E-45 return 1.401298E-45
end end
---@class Vector3
---@field maxValue number
if k == "maxValue" then if k == "maxValue" then
return 3.402823E+38 return 3.402823E+38
end end
---@class Vector3
---@field minValue number
if k == "minValue" then if k == "minValue" then
return -3.402823E+38 return -3.402823E+38
end end
---@class Vector3
---@field x number
if k == "x" then if k == "x" then
return self[1] return self[1]
end end
---@class Vector3
---@field y number
if k == "y" then if k == "y" then
return self[2] return self[2]
end end
---@class Vector3
---@field z number
if k == "z" then if k == "z" then
return self[3] return self[3]
end end
@ -272,7 +314,7 @@ function Vector3:ProjectOnPlane(planeNormal)
return self - self:Project(planeNormal) return self - self:Project(planeNormal)
end end
---@param inDirection Vector3 ---@param inNormal Vector3
---@return Vector3 ---@return Vector3
function Vector3:Reflect(inNormal) function Vector3:Reflect(inNormal)
return -2 * inNormal:Dot(self) * inNormal + self return -2 * inNormal:Dot(self) * inNormal + self

@ -7,7 +7,7 @@ local Bastion = {
Bastion.__index = Bastion Bastion.__index = Bastion
function Bastion.require(class) function Bastion.require(class)
return Tinkr:require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion)
end end
---@type ClassMagic ---@type ClassMagic
@ -34,6 +34,7 @@ Bastion.Unit = Bastion.require("Unit")
Bastion.Aura = Bastion.require("Aura") Bastion.Aura = Bastion.require("Aura")
---@type APL, APLActor, APLTrait ---@type APL, APLActor, APLTrait
Bastion.APL, Bastion.APLActor, Bastion.APLTrait = Bastion.require("APL") Bastion.APL, Bastion.APLActor, Bastion.APLTrait = Bastion.require("APL")
---@type Module
Bastion.Module = Bastion.require("Module") Bastion.Module = Bastion.require("Module")
---@type UnitManager ---@type UnitManager
Bastion.UnitManager = Bastion.require("UnitManager"):New() Bastion.UnitManager = Bastion.require("UnitManager"):New()
@ -61,7 +62,8 @@ Bastion.CombatTimer = Bastion.Timer:New('combat')
Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New() Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New()
---@type NotificationsList ---@type NotificationsList
Bastion.Notifications = Bastion.NotificationsList:New() Bastion.Notifications = Bastion.NotificationsList:New()
Bastion.modules = {} local LIBRARIES = {}
local MODULES = {}
Bastion.Enabled = false Bastion.Enabled = false
Bastion.EventManager:RegisterWoWEvent('UNIT_AURA', function(unit, auras) Bastion.EventManager:RegisterWoWEvent('UNIT_AURA', function(unit, auras)
@ -89,7 +91,7 @@ end)
local pguid = UnitGUID("player") local pguid = UnitGUID("player")
local missed = {} local missed = {}
Bastion.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function() Bastion.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function()
local args = { CombatLogGetCurrentEventInfo() } local args = {CombatLogGetCurrentEventInfo()}
local subEvent = args[2] local subEvent = args[2]
local sourceGUID = args[4] local sourceGUID = args[4]
@ -131,6 +133,16 @@ Bastion.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function()
end end
end end
end) end)
function Bastion:RegisterLibrary(name, payload)
LIBRARIES[name] = payload
-- Bastion:Print("Registered Library", name)
end
function Bastion:GetLibrary(name)
return LIBRARIES[name]
end
Bastion.Ticker = C_Timer.NewTicker(0.1, function() Bastion.Ticker = C_Timer.NewTicker(0.1, function()
if not Bastion.CombatTimer:IsRunning() and UnitAffectingCombat("player") then if not Bastion.CombatTimer:IsRunning() and UnitAffectingCombat("player") then
Bastion.CombatTimer:Start() Bastion.CombatTimer:Start()
@ -140,29 +152,30 @@ Bastion.Ticker = C_Timer.NewTicker(0.1, function()
if Bastion.Enabled then if Bastion.Enabled then
Bastion.ObjectManager:Refresh() Bastion.ObjectManager:Refresh()
for i = 1, #Bastion.modules do for i = 1, #MODULES do
Bastion.modules[i]:Tick() MODULES[i]:Tick()
end end
end end
end) end)
function Bastion:Register(module) function Bastion:Register(module)
table.insert(Bastion.modules, module) table.insert(MODULES, module)
Bastion:Print("Registered", module) Bastion:Print("Registered", module)
end end
-- Find a module by name -- Find a module by name
function Bastion:FindModule(name) function Bastion:FindModule(name)
for i = 1, #Bastion.modules do for i = 1, #MODULES do
if Bastion.modules[i].name == name then if MODULES[i].name == name then
return Bastion.modules[i] return MODULES[i]
end end
end end
return nil return nil
end end
function Bastion:Print(...) function Bastion:Print(...)
local args = { ... } local args = {...}
local str = "|cFFDF362D[Bastion]|r |cFFFFFFFF" local str = "|cFFDF362D[Bastion]|r |cFFFFFFFF"
for i = 1, #args do for i = 1, #args do
str = str .. tostring(args[i]) .. " " str = str .. tostring(args[i]) .. " "
@ -174,7 +187,7 @@ function Bastion:Debug(...)
if not Bastion.DebugMode then if not Bastion.DebugMode then
return return
end end
local args = { ... } local args = {...}
local str = "|cFFDF6520[Bastion]|r |cFFFFFFFF" local str = "|cFFDF6520[Bastion]|r |cFFFFFFFF"
for i = 1, #args do for i = 1, #args do
str = str .. tostring(args[i]) .. " " str = str .. tostring(args[i]) .. " "
@ -207,13 +220,16 @@ Command:Register('dumpspells', 'Dump spells to a file', function()
while true do while true do
local spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL) local spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL)
if not spellName then if not spellName then
do break end do
break
end
end end
-- use spellName and spellSubName here -- use spellName and spellSubName here
local spellID = select(7, GetSpellInfo(spellName)) local spellID = select(7, GetSpellInfo(spellName))
if spellID then if spellID then
spellName = spellName:gsub("[%W%s]", "")
WriteFile('bastion-' .. UnitClass('player') .. '-' .. rand .. '.lua', WriteFile('bastion-' .. UnitClass('player') .. '-' .. rand .. '.lua',
"local " .. spellName .. " = Bastion.SpellBook:GetSpell(" .. spellID .. ")", true) "local " .. spellName .. " = Bastion.SpellBook:GetSpell(" .. spellID .. ")", true)
end end
@ -261,14 +277,17 @@ Command:Register('missed', 'Dump the list of immune kidney shot spells', functio
end end
end) end)
local files = ListFiles("scripts/bastion/scripts") local function Load(dir)
local files = ListFiles(dir)
for i = 1, #files do
local file = files[i]
if file:sub(-4) == ".lua" or file:sub(-5) == '.luac' then
Tinkr:require("scripts/bastion/scripts/" .. file:sub(1, -5), Bastion) for i = 1, #files do
local file = files[i]
if file:sub(-4) == ".lua" or file:sub(-5) == '.luac' then
require(dir .. file:sub(1, -5), Bastion)
end
end end
end end
Load("scripts/bastion/scripts/Libraries/")
Load("scripts/bastion/scripts/Modules/")
Load("scripts/bastion/scripts/")

Loading…
Cancel
Save