11.0
main
4n0n 6 months ago
parent f9583a85d8
commit 86e7aeccec
  1. 327
      src/_bastion.lua

@ -1,9 +1,9 @@
local Tinkr = ... local Tinkr = ...
local Evaulator = Tinkr.Evaluator
---@class Bastion ---@class Bastion
local Bastion = { local Bastion = {DebugMode = false}
DebugMode = false
}
Bastion.__index = Bastion Bastion.__index = Bastion
function Bastion:Require(file) function Bastion:Require(file)
@ -50,80 +50,84 @@ function Bastion.require(class)
return Bastion:Require("~/src/" .. class .. "/" .. class) return Bastion:Require("~/src/" .. class .. "/" .. class)
end end
Bastion.Globals = {} -- fenv for all required files
function Bastion.Bootstrap()
---@type ClassMagic
Bastion.ClassMagic = Bastion.require("ClassMagic") Bastion.Globals = {}
---@type List
Bastion.List = Bastion.require("List") ---@type ClassMagic
---@type Library Bastion.ClassMagic = Bastion.require("ClassMagic")
Bastion.Library = Bastion.require("Library") ---@type List
---@type NotificationsList, Notification Bastion.List = Bastion.require("List")
Bastion.NotificationsList, Bastion.Notification = Bastion.require("NotificationsList") ---@type Library
---@type Vector3 Bastion.Library = Bastion.require("Library")
Bastion.Vector3 = Bastion.require("Vector3") ---@type NotificationsList, Notification
---@type Sequencer Bastion.NotificationsList, Bastion.Notification = Bastion.require(
Bastion.Sequencer = Bastion.require("Sequencer") "NotificationsList")
---@type Command ---@type Vector3
Bastion.Command = Bastion.require("Command") Bastion.Vector3 = Bastion.require("Vector3")
---@type Cache ---@type Sequencer
Bastion.Cache = Bastion.require("Cache") Bastion.Sequencer = Bastion.require("Sequencer")
---@type Cacheable ---@type Command
Bastion.Cacheable = Bastion.require("Cacheable") Bastion.Command = Bastion.require("Command")
---@type Refreshable ---@type Cache
Bastion.Refreshable = Bastion.require("Refreshable") Bastion.Cache = Bastion.require("Cache")
---@type Unit ---@type Cacheable
Bastion.Unit = Bastion.require("Unit") Bastion.Cacheable = Bastion.require("Cacheable")
---@type Aura ---@type Refreshable
Bastion.Aura = Bastion.require("Aura") Bastion.Refreshable = Bastion.require("Refreshable")
---@type APL, APLActor, APLTrait ---@type Unit
Bastion.APL, Bastion.APLActor, Bastion.APLTrait = Bastion.require("APL") Bastion.Unit = Bastion.require("Unit")
---@type Module ---@type Aura
Bastion.Module = Bastion.require("Module") Bastion.Aura = Bastion.require("Aura")
---@type UnitManager ---@type APL, APLActor, APLTrait
Bastion.UnitManager = Bastion.require("UnitManager"):New() Bastion.APL, Bastion.APLActor, Bastion.APLTrait = Bastion.require("APL")
---@type ObjectManager ---@type Module
Bastion.ObjectManager = Bastion.require("ObjectManager"):New() Bastion.Module = Bastion.require("Module")
---@type EventManager ---@type UnitManager
Bastion.EventManager = Bastion.require("EventManager") Bastion.UnitManager = Bastion.require("UnitManager"):New()
Bastion.Globals.EventManager = Bastion.EventManager:New() ---@type ObjectManager
---@type Spell Bastion.ObjectManager = Bastion.require("ObjectManager"):New()
Bastion.Spell = Bastion.require("Spell") ---@type EventManager
---@type SpellBook Bastion.EventManager = Bastion.require("EventManager")
Bastion.SpellBook = Bastion.require("SpellBook") Bastion.Globals.EventManager = Bastion.EventManager:New()
Bastion.Globals.SpellBook = Bastion.SpellBook:New() ---@type Spell
---@type Item Bastion.Spell = Bastion.require("Spell")
Bastion.Item = Bastion.require("Item") ---@type SpellBook
---@type ItemBook Bastion.SpellBook = Bastion.require("SpellBook")
Bastion.ItemBook = Bastion.require("ItemBook") Bastion.Globals.SpellBook = Bastion.SpellBook:New()
Bastion.Globals.ItemBook = Bastion.ItemBook:New() ---@type Item
---@type AuraTable Bastion.Item = Bastion.require("Item")
Bastion.AuraTable = Bastion.require("AuraTable") ---@type ItemBook
---@type Class Bastion.ItemBook = Bastion.require("ItemBook")
Bastion.Class = Bastion.require("Class") Bastion.Globals.ItemBook = Bastion.ItemBook:New()
---@type Timer ---@type AuraTable
Bastion.Timer = Bastion.require("Timer") Bastion.AuraTable = Bastion.require("AuraTable")
---@type Timer ---@type Class
Bastion.CombatTimer = Bastion.Timer:New('combat') Bastion.Class = Bastion.require("Class")
---@type MythicPlusUtils ---@type Timer
Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New() Bastion.Timer = Bastion.require("Timer")
---@type NotificationsList ---@type Timer
Bastion.Notifications = Bastion.NotificationsList:New() Bastion.CombatTimer = Bastion.Timer:New('combat')
---@type MythicPlusUtils
local LIBRARIES = {} Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New()
local MODULES = {} ---@type NotificationsList
Bastion.Notifications = Bastion.NotificationsList:New()
Bastion.Enabled = false
local LIBRARIES = {}
Bastion.Globals.EventManager:RegisterWoWEvent('UNIT_AURA', function(unit, auras) local MODULES = {}
Bastion.Enabled = false
Bastion.Globals.EventManager:RegisterWoWEvent('UNIT_AURA',
function(unit, auras)
local u = Bastion.UnitManager[unit] local u = Bastion.UnitManager[unit]
if u then if u then u:GetAuras():OnUpdate(auras) end
u:GetAuras():OnUpdate(auras) end)
end
end)
Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_SPELLCAST_SUCCEEDED", function(...) Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_SPELLCAST_SUCCEEDED",
function(...)
local unit, castGUID, spellID = ... local unit, castGUID, spellID = ...
local spell = Bastion.Globals.SpellBook:GetIfRegistered(spellID) local spell = Bastion.Globals.SpellBook:GetIfRegistered(spellID)
@ -135,12 +139,13 @@ Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_SPELLCAST_SUCCEEDED", functi
spell:GetPostCastFunction()(spell) spell:GetPostCastFunction()(spell)
end end
end end
end) end)
local pguid = UnitGUID("player") local pguid = UnitGUID("player")
local missed = {} local missed = {}
Bastion.Globals.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function() Bastion.Globals.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED",
function()
local args = {CombatLogGetCurrentEventInfo()} local args = {CombatLogGetCurrentEventInfo()}
local subEvent = args[2] local subEvent = args[2]
@ -161,14 +166,13 @@ Bastion.Globals.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", fun
local t = GetTime() local t = GetTime()
if u then if u then u:SetLastCombatTime(t) end
u:SetLastCombatTime(t)
end
if u2 then if u2 then
u2:SetLastCombatTime(t) u2:SetLastCombatTime(t)
if subEvent == "SPELL_MISSED" and sourceGUID == pguid and spellID == 408 then if subEvent == "SPELL_MISSED" and sourceGUID == pguid and spellID ==
408 then
local missType = args[15] local missType = args[15]
if missType == "IMMUNE" then if missType == "IMMUNE" then
@ -182,104 +186,109 @@ Bastion.Globals.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", fun
end end
end end
end end
end) 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()
elseif Bastion.CombatTimer:IsRunning() and not UnitAffectingCombat("player") then elseif Bastion.CombatTimer:IsRunning() and
not UnitAffectingCombat("player") then
Bastion.CombatTimer:Reset() Bastion.CombatTimer:Reset()
end end
if Bastion.Enabled then if Bastion.Enabled then
Bastion.ObjectManager:Refresh() Bastion.ObjectManager:Refresh()
for i = 1, #MODULES do for i = 1, #MODULES do MODULES[i]:Tick() end
MODULES[i]:Tick()
end
end end
end) end)
function Bastion:Register(module) function Bastion:Register(module)
table.insert(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, #MODULES do for i = 1, #MODULES do
if MODULES[i].name == name then if MODULES[i].name == name then return MODULES[i] end
return MODULES[i]
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]) .. " " end
str = str .. tostring(args[i]) .. " "
end
print(str) print(str)
end
function Bastion:Debug(...)
if not Bastion.DebugMode then
return
end end
function Bastion:Debug(...)
if not Bastion.DebugMode then return 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]) .. " " end
str = str .. tostring(args[i]) .. " "
end
print(str) print(str)
end end
local Command = Bastion.Command:New('bastion') local Command = Bastion.Command:New('bastion')
Command:Register('toggle', 'Toggle bastion on/off', function() Command:Register('toggle', 'Toggle bastion on/off', function()
Bastion.Enabled = not Bastion.Enabled Bastion.Enabled = not Bastion.Enabled
if Bastion.Enabled then if Bastion.Enabled then
Bastion:Print("Enabled") Bastion:Print("Enabled")
else else
Bastion:Print("Disabled") Bastion:Print("Disabled")
end end
end) end)
Command:Register('debug', 'Toggle debug mode on/off', function() Command:Register('debug', 'Toggle debug mode on/off', function()
Bastion.DebugMode = not Bastion.DebugMode Bastion.DebugMode = not Bastion.DebugMode
if Bastion.DebugMode then if Bastion.DebugMode then
Bastion:Print("Debug mode enabled") Bastion:Print("Debug mode enabled")
else else
Bastion:Print("Debug mode disabled") Bastion:Print("Debug mode disabled")
end end
end) end)
Command:Register('dumpspells', 'Dump spells to a file', function() Command:Register('dumpspells', 'Dump spells to a file', function()
local i = 1 local i = 1
local rand = math.random(100000, 999999) local rand = math.random(100000, 999999)
local BOOKTYPE_SPELL = BOOKTYPE_SPELL or (Enum.SpellBookSpellBank.Player and Enum.SpellBookSpellBank.Player or 'spell')
while true do while true do
local spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL) local spellName, spellSubName
if not spellName then
do if C_SpellBook.GetSpellBookItemName then
break spellName, spellSubName = C_SpellBook.GetSpellBookItemName(i, BOOKTYPE_SPELL)
end else
spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL)
end end
if not spellName then do break end end
-- use spellName and spellSubName here -- use spellName and spellSubName here
local spellID = select(7, GetSpellInfo(spellName)) local spellID
if C_Spell.GetSpellInfo then
local info = C_Spell.GetSpellInfo(spellName)
spellID = info.spellID
else
spellID = select(7, GetSpellInfo(spellName))
end
if spellID then if spellID then
spellName = spellName:gsub("[%W%s]", "") spellName = spellName:gsub("[%W%s]", "")
WriteFile('bastion-' .. UnitClass('player') .. '-' .. rand .. '.lua', WriteFile('bastion-' .. UnitClass('player') .. '-' .. rand ..
"local " .. spellName .. " = Bastion.Globals.SpellBook:GetSpell(" .. spellID .. ")\n", true) '.lua',
"local " .. spellName ..
" = Bastion.Globals.SpellBook:GetSpell(" ..
spellID .. ")\n", true)
end end
i = i + 1 i = i + 1
end end
end) end)
Command:Register('module', 'Toggle a module on/off', function(args) Command:Register('module', 'Toggle a module on/off', function(args)
local module = Bastion:FindModule(args[2]) local module = Bastion:FindModule(args[2])
if module then if module then
module:Toggle() module:Toggle()
@ -291,19 +300,22 @@ Command:Register('module', 'Toggle a module on/off', function(args)
else else
Bastion:Print("Module not found") Bastion:Print("Module not found")
end end
end) end)
Command:Register('mplus', 'Toggle m+ module on/off', function(args) Command:Register('mplus', 'Toggle m+ module on/off', function(args)
local cmd = args[2] local cmd = args[2]
if cmd == 'debuffs' then if cmd == 'debuffs' then
Bastion.MythicPlusUtils:ToggleDebuffLogging() Bastion.MythicPlusUtils:ToggleDebuffLogging()
Bastion:Print("Debuff logging", Bastion.MythicPlusUtils.debuffLogging and "enabled" or "disabled") Bastion:Print("Debuff logging", Bastion.MythicPlusUtils
.debuffLogging and "enabled" or "disabled")
return return
end end
if cmd == 'casts' then if cmd == 'casts' then
Bastion.MythicPlusUtils:ToggleCastLogging() Bastion.MythicPlusUtils:ToggleCastLogging()
Bastion:Print("Cast logging", Bastion.MythicPlusUtils.castLogging and "enabled" or "disabled") Bastion:Print("Cast logging",
Bastion.MythicPlusUtils.castLogging and "enabled" or
"disabled")
return return
end end
@ -311,20 +323,19 @@ Command:Register('mplus', 'Toggle m+ module on/off', function(args)
Bastion:Print("Available commands:") Bastion:Print("Available commands:")
Bastion:Print("debuffs") Bastion:Print("debuffs")
Bastion:Print("casts") Bastion:Print("casts")
end) end)
Command:Register('missed', 'Dump the list of immune kidney shot spells', function() Command:Register('missed', 'Dump the list of immune kidney shot spells',
for k, v in pairs(missed) do function()
Bastion:Print(k) for k, v in pairs(missed) do Bastion:Print(k) end
end end)
end)
---@param library Library ---@param library Library
function Bastion:RegisterLibrary(library) function Bastion:RegisterLibrary(library)
LIBRARIES[library.name] = library LIBRARIES[library.name] = library
end end
function Bastion:CheckLibraryDependencies() function Bastion:CheckLibraryDependencies()
for k, v in pairs(LIBRARIES) do for k, v in pairs(LIBRARIES) do
if v.dependencies then if v.dependencies then
for i = 1, #v.dependencies do for i = 1, #v.dependencies do
@ -333,13 +344,16 @@ function Bastion:CheckLibraryDependencies()
if LIBRARIES[dep].dependencies then if LIBRARIES[dep].dependencies then
for j = 1, #LIBRARIES[dep].dependencies do for j = 1, #LIBRARIES[dep].dependencies do
if LIBRARIES[dep].dependencies[j] == v.name then if LIBRARIES[dep].dependencies[j] == v.name then
Bastion:Print("Circular dependency detected between " .. v.name .. " and " .. dep) Bastion:Print(
"Circular dependency detected between " ..
v.name .. " and " .. dep)
return false return false
end end
end end
end end
else else
Bastion:Print("Library " .. v.name .. " depends on " .. dep .. " but it's not registered") Bastion:Print("Library " .. v.name .. " depends on " ..
dep .. " but it's not registered")
return false return false
end end
end end
@ -347,19 +361,17 @@ function Bastion:CheckLibraryDependencies()
end end
return true return true
end end
function Bastion:Import(library) function Bastion:Import(library)
local lib = self:GetLibrary(library) local lib = self:GetLibrary(library)
if not lib then if not lib then error("Library " .. library .. " not found") end
error("Library " .. library .. " not found")
end
return lib:Resolve() return lib:Resolve()
end end
function Bastion:GetLibrary(name) function Bastion:GetLibrary(name)
if not LIBRARIES[name] then if not LIBRARIES[name] then
error("Library " .. name .. " not found") error("Library " .. name .. " not found")
end end
@ -386,12 +398,15 @@ function Bastion:GetLibrary(name)
-- end -- end
return library return library
end end
-- if not Bastion:CheckLibraryDependencies() then
-- return
-- end
-- if not Bastion:CheckLibraryDependencies() then Load("@Libraries/")
-- return Load("@Modules/")
-- end Load("@")
end
Load("@Libraries/") Bastion.Bootstrap()
Load("@Modules/")
Load("@")

Loading…
Cancel
Save