Move spellbook and itembook out of globals, remove prints

pull/1/head
4n0n 1 year ago
parent 9d47758f8c
commit 677229738d
  1. 40
      src/APL/APL.lua
  2. 20
      src/Aura/Aura.lua
  3. 6
      src/Item/Item.lua
  4. 6
      src/MythicPlusUtils/MythicPlusUtils.lua
  5. 3
      src/Sequencer/Sequencer.lua
  6. 16
      src/Unit/Unit.lua
  7. 18
      src/_bastion.lua

@ -1,5 +1,4 @@
-- Document with emmy lua: https://emmylua.github.io/ -- Document with emmy lua: https://emmylua.github.io/
-- Create an APL trait for the APL class -- Create an APL trait for the APL class
---@class APLTrait ---@class APLTrait
local APLTrait = {} local APLTrait = {}
@ -85,13 +84,11 @@ function APLActor:Execute()
-- If the actor is a sequencer we don't want to continue executing the APL if the sequencer is not finished -- If the actor is a sequencer we don't want to continue executing the APL if the sequencer is not finished
if self:GetActor().sequencer then if self:GetActor().sequencer then
if self:GetActor().condition and self:GetActor().condition() and not self:GetActor().sequencer:Finished() then if self:GetActor().condition and self:GetActor().condition() and not self:GetActor().sequencer:Finished() then
print("Execute?")
self:GetActor().sequencer:Execute() self:GetActor().sequencer:Execute()
return true return true
end end
if not self:GetActor().condition and not self:GetActor().sequencer:Finished() then if not self:GetActor().condition and not self:GetActor().sequencer:Finished() then
print("Execute?")
self:GetActor().sequencer:Execute() self:GetActor().sequencer:Execute()
return true return true
end end
@ -111,13 +108,12 @@ function APLActor:Execute()
if self:GetActor().condition then if self:GetActor().condition then
-- print("Bastion: APL:Execute: Condition for spell " .. self:GetActor().spell:GetName()) -- print("Bastion: APL:Execute: Condition for spell " .. self:GetActor().spell:GetName())
self:GetActor().spell:CastableIf(self:GetActor().castableFunc):OnCast(self:GetActor().onCastFunc):Cast( self:GetActor().spell:CastableIf(self:GetActor().castableFunc):OnCast(self:GetActor().onCastFunc):Cast(
self:GetActor().target, self:GetActor().target, self:GetActor().condition)
self:GetActor().condition)
end end
-- print("Bastion: APL:Execute: No condition for spell " .. self:GetActor().spell:GetName()) -- print("Bastion: APL:Execute: No condition for spell " .. self:GetActor().spell:GetName())
self:GetActor().spell:CastableIf(self:GetActor().castableFunc):OnCast(self:GetActor().onCastFunc):Cast(self self:GetActor().spell:CastableIf(self:GetActor().castableFunc):OnCast(self:GetActor().onCastFunc):Cast(
:GetActor().target) self:GetActor().target)
end end
if self:GetActor().item then if self:GetActor().item then
if self:GetActor().condition then if self:GetActor().condition then
@ -189,7 +185,11 @@ end
---@param cb fun(...):any ---@param cb fun(...):any
---@return APLActor ---@return APLActor
function APL:AddVariable(name, cb) function APL:AddVariable(name, cb)
local actor = APLActor:New({ variable = name, cb = cb, _apl = self }) local actor = APLActor:New({
variable = name,
cb = cb,
_apl = self
})
table.insert(self.apl, actor) table.insert(self.apl, actor)
return actor return actor
end end
@ -199,7 +199,10 @@ end
---@param cb fun(...):any ---@param cb fun(...):any
---@return APLActor ---@return APLActor
function APL:AddAction(action, cb) function APL:AddAction(action, cb)
local actor = APLActor:New({ action = action, cb = cb }) local actor = APLActor:New({
action = action,
cb = cb
})
table.insert(self.apl, actor) table.insert(self.apl, actor)
return actor return actor
end end
@ -234,7 +237,12 @@ function APL:AddItem(item, condition)
local usableFunc = item.UsableIfFunc local usableFunc = item.UsableIfFunc
local target = item:GetTarget() local target = item:GetTarget()
local actor = APLActor:New({ item = item, condition = condition, usableFunc = usableFunc, target = target }) local actor = APLActor:New({
item = item,
condition = condition,
usableFunc = usableFunc,
target = target
})
table.insert(self.apl, actor) table.insert(self.apl, actor)
@ -249,7 +257,10 @@ function APL:AddAPL(apl, condition)
if not condition then if not condition then
error("Bastion: APL:AddAPL: No condition for APL " .. apl.name) error("Bastion: APL:AddAPL: No condition for APL " .. apl.name)
end end
local actor = APLActor:New({ apl = apl, condition = condition }) local actor = APLActor:New({
apl = apl,
condition = condition
})
table.insert(self.apl, actor) table.insert(self.apl, actor)
return actor return actor
end end
@ -259,12 +270,10 @@ function APL:Execute()
for _, actor in ipairs(self.apl) do for _, actor in ipairs(self.apl) do
if actor:HasTraits() and actor:Evaluate() then if actor:HasTraits() and actor:Evaluate() then
if actor:Execute() then if actor:Execute() then
print("BREAQK", actor)
break break
end end
else else
if actor:Execute() then if actor:Execute() then
print("BREAQK", actor)
break break
end end
end end
@ -276,7 +285,10 @@ end
---@param condition fun(...):boolean ---@param condition fun(...):boolean
---@return APLActor ---@return APLActor
function APL:AddSequence(sequencer, condition) function APL:AddSequence(sequencer, condition)
local actor = APLActor:New({ sequencer = sequencer, condition = condition }) local actor = APLActor:New({
sequencer = sequencer,
condition = condition
})
table.insert(self.apl, actor) table.insert(self.apl, actor)
return actor return actor
end end

@ -1,5 +1,4 @@
-- Document with emmy lua: https://emmylua.github.io/ -- Document with emmy lua: https://emmylua.github.io/
local Tinkr, Bastion = ... local Tinkr, Bastion = ...
-- Create a new Aura class -- Create a new Aura class
@ -66,19 +65,18 @@ function Aura:New(unit, index, type)
timeMod = 0, timeMod = 0,
index = nil, index = nil,
type = nil, type = nil
} }
if self.aura.spellId then if self.aura.spellId then
Bastion.SpellBook:GetSpell(self.aura.spellId) Bastion.Globals.SpellBook:GetSpell(self.aura.spellId)
end end
return self return self
end end
local name, icon, count, dispelType, duration, expirationTime, source, isStealable, nameplateShowPersonal, local name, icon, count, dispelType, duration, expirationTime, source, isStealable, nameplateShowPersonal, spellId,
spellId, canApplyAura, isBossDebuff, castByPlayer, nameplateShowAll, timeMod = UnitAura(unit:GetOMToken(), index, canApplyAura, isBossDebuff, castByPlayer, nameplateShowAll, timeMod = UnitAura(unit:GetOMToken(), index, type)
type)
local self = setmetatable({}, Aura) local self = setmetatable({}, Aura)
self.aura = { self.aura = {
@ -100,10 +98,10 @@ function Aura:New(unit, index, type)
auraInstanceID = nil, auraInstanceID = nil,
index = index, index = index,
type = type, type = type
} }
if self.aura.spellId then if self.aura.spellId then
Bastion.SpellBook:GetSpell(self.aura.spellId) Bastion.Globals.SpellBook:GetSpell(self.aura.spellId)
end end
return self return self
end end
@ -132,11 +130,11 @@ function Aura:CreateFromUnitAuraInfo(unitAuraInfo)
auraInstanceID = unitAuraInfo.auraInstanceID, auraInstanceID = unitAuraInfo.auraInstanceID,
index = nil, index = nil,
type = unitAuraInfo.isHarmful and "HARMFUL" or "HELPFUL", type = unitAuraInfo.isHarmful and "HARMFUL" or "HELPFUL"
} }
-- Register spell in spellbook -- Register spell in spellbook
Bastion.SpellBook:GetSpell(self.aura.spellId) Bastion.Globals.SpellBook:GetSpell(self.aura.spellId)
return self return self
end end
@ -239,7 +237,7 @@ end
-- Get the auras spell id -- Get the auras spell id
---@return Spell ---@return Spell
function Aura:GetSpell() function Aura:GetSpell()
return Bastion.SpellBook:GetSpell(self.aura.spellId) return Bastion.Globals.SpellBook:GetSpell(self.aura.spellId)
end end
-- Get the auras can apply aura status -- Get the auras can apply aura status

@ -54,7 +54,7 @@ function Item:New(id)
local name, spellID = GetItemSpell(self:GetID()) local name, spellID = GetItemSpell(self:GetID())
if spellID then if spellID then
self.spellID = spellID self.spellID = spellID
Bastion.SpellBook:GetSpell(spellID) Bastion.Globals.SpellBook:GetSpell(spellID)
end end
return self return self
@ -302,7 +302,7 @@ end
-- Get the last use time -- Get the last use time
---@return number ---@return number
function Item:GetLastUseTime() function Item:GetLastUseTime()
return Bastion.SpellBook:GetSpell(self:GetID()):GetLastCastTime() return Bastion.Globals.SpellBook:GetSpell(self:GetID()):GetLastCastTime()
end end
-- Get time since last use -- Get time since last use
@ -430,7 +430,7 @@ end
---@return Spell | nil ---@return Spell | nil
function Item:GetSpell() function Item:GetSpell()
if self.spellID then if self.spellID then
return Bastion.SpellBook:GetSpell(self.spellID) return Bastion.Globals.SpellBook:GetSpell(self.spellID)
end end
return nil return nil

@ -430,7 +430,7 @@ function MythicPlusUtils:New()
} }
} }
Bastion.EventManager:RegisterWoWEvent('UNIT_AURA', function(unit, auras) Bastion.Globals.EventManager:RegisterWoWEvent('UNIT_AURA', function(unit, auras)
if not self.debuffLogging then if not self.debuffLogging then
return return
end end
@ -453,7 +453,7 @@ function MythicPlusUtils:New()
end end
end) end)
Bastion.EventManager:RegisterWoWEvent('UNIT_SPELLCAST_START', function(unitTarget, castGUID, spellID) Bastion.Globals.EventManager:RegisterWoWEvent('UNIT_SPELLCAST_START', function(unitTarget, castGUID, spellID)
if not self.castLogging then if not self.castLogging then
return return
end end
@ -472,7 +472,7 @@ function MythicPlusUtils:New()
]], true) ]], true)
end) end)
Bastion.EventManager:RegisterWoWEvent('UNIT_SPELLCAST_CHANNEL_START', function(unitTarget, castGUID, spellID) Bastion.Globals.EventManager:RegisterWoWEvent('UNIT_SPELLCAST_CHANNEL_START', function(unitTarget, castGUID, spellID)
if not self.castLogging then if not self.castLogging then
return return
end end

@ -1,5 +1,4 @@
-- 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 resetCondition fun(): boolean
---@field abortCondition fun(): boolean ---@field abortCondition fun(): boolean
@ -45,12 +44,10 @@ end
---@return boolean ---@return boolean
function Sequencer:Next() function Sequencer:Next()
if self:Finished() then if self:Finished() then
print("Its finished?")
return false return false
end end
local action = self.actions[self.index] local action = self.actions[self.index]
print("Attempting action: " .. self.index .. "")
if action(self) then if action(self) then
self.index = self.index + 1 self.index = self.index + 1
return true return true

@ -422,7 +422,7 @@ function Unit:GetCastingOrChannelingSpell()
end end
if name then if name then
return Bastion.SpellBook:GetSpell(spellId) return Bastion.Globals.SpellBook:GetSpell(spellId)
end end
return nil return nil
@ -926,12 +926,12 @@ end
-- IsStealthed -- IsStealthed
---@return boolean ---@return boolean
function Unit:IsStealthed() function Unit:IsStealthed()
local Stealth = Bastion.SpellBook:GetSpell(1784) local Stealth = Bastion.Globals.SpellBook:GetSpell(1784)
local Vanish = Bastion.SpellBook:GetSpell(1856) local Vanish = Bastion.Globals.SpellBook:GetSpell(1856)
local ShadowDance = Bastion.SpellBook:GetSpell(185422) local ShadowDance = Bastion.Globals.SpellBook:GetSpell(185422)
local Subterfuge = Bastion.SpellBook:GetSpell(115192) local Subterfuge = Bastion.Globals.SpellBook:GetSpell(115192)
local Shadowmeld = Bastion.SpellBook:GetSpell(58984) local Shadowmeld = Bastion.Globals.SpellBook:GetSpell(58984)
local Sepsis = Bastion.SpellBook:GetSpell(328305) local Sepsis = Bastion.Globals.SpellBook:GetSpell(328305)
return self:GetAuras():FindAny(Stealth) or self:GetAuras():FindAny(ShadowDance) return self:GetAuras():FindAny(Stealth) or self:GetAuras():FindAny(ShadowDance)
end end
@ -959,7 +959,7 @@ end
---@return nil ---@return nil
function Unit:WatchForSwings() function Unit:WatchForSwings()
Bastion.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function() Bastion.Globals.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function()
local _, subtype, _, sourceGUID, sourceName, _, _, destGUID, destName, destFlags, _, spellID, spellName, _, amount, interrupt, a, b, c, d, offhand, multistrike = local _, subtype, _, sourceGUID, sourceName, _, _, destGUID, destName, destFlags, _, spellID, spellName, _, amount, interrupt, a, b, c, d, offhand, multistrike =
CombatLogGetCurrentEventInfo() CombatLogGetCurrentEventInfo()

@ -10,6 +10,8 @@ function Bastion.require(class)
return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion)
end end
Bastion.Globals = {}
---@type ClassMagic ---@type ClassMagic
Bastion.ClassMagic = Bastion.require("ClassMagic") Bastion.ClassMagic = Bastion.require("ClassMagic")
---@type List ---@type List
@ -43,15 +45,18 @@ Bastion.UnitManager = Bastion.require("UnitManager"):New()
---@type ObjectManager ---@type ObjectManager
Bastion.ObjectManager = Bastion.require("ObjectManager"):New() Bastion.ObjectManager = Bastion.require("ObjectManager"):New()
---@type EventManager ---@type EventManager
Bastion.EventManager = Bastion.require("EventManager"):New() Bastion.EventManager = Bastion.require("EventManager")
Bastion.Globals.EventManager = Bastion.EventManager:New()
---@type Spell ---@type Spell
Bastion.Spell = Bastion.require("Spell") Bastion.Spell = Bastion.require("Spell")
---@type SpellBook ---@type SpellBook
Bastion.SpellBook = Bastion.require("SpellBook") Bastion.SpellBook = Bastion.require("SpellBook")
Bastion.Globals.SpellBook = Bastion.SpellBook:New()
---@type Item ---@type Item
Bastion.Item = Bastion.require("Item") Bastion.Item = Bastion.require("Item")
---@type ItemBook ---@type ItemBook
Bastion.ItemBook = Bastion.require("ItemBook") Bastion.ItemBook = Bastion.require("ItemBook")
Bastion.Globals.ItemBook = Bastion.ItemBook:New()
---@type AuraTable ---@type AuraTable
Bastion.AuraTable = Bastion.require("AuraTable") Bastion.AuraTable = Bastion.require("AuraTable")
---@type Class ---@type Class
@ -64,11 +69,13 @@ 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()
local LIBRARIES = {} local LIBRARIES = {}
local MODULES = {} local MODULES = {}
Bastion.Enabled = false Bastion.Enabled = false
Bastion.EventManager:RegisterWoWEvent('UNIT_AURA', function(unit, auras) 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
@ -76,7 +83,7 @@ Bastion.EventManager:RegisterWoWEvent('UNIT_AURA', function(unit, auras)
end end
end) end)
Bastion.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.SpellBook:GetIfRegistered(spellID) local spell = Bastion.SpellBook:GetIfRegistered(spellID)
@ -92,7 +99,8 @@ end)
local pguid = UnitGUID("player") local pguid = UnitGUID("player")
local missed = {} local missed = {}
Bastion.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]
@ -207,6 +215,7 @@ Command:Register('debug', 'Toggle debug mode on/off', function()
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)
@ -284,7 +293,6 @@ end
---@param library Library ---@param library Library
function Bastion:RegisterLibrary(library) function Bastion:RegisterLibrary(library)
LIBRARIES[library.name] = library LIBRARIES[library.name] = library
print("Registered library", library.name)
end end
function Bastion:CheckLibraryDependencies() function Bastion:CheckLibraryDependencies()

Loading…
Cancel
Save