main
jeffi 6 months ago
parent 85bbe24db1
commit 1a796811bc
  1. 88
      src/Aura/Aura.lua
  2. 12
      src/AuraTable/AuraTable.lua
  3. 55
      src/Item/Item.lua
  4. 2
      src/ObjectManager/ObjectManager.lua
  5. 118
      src/Spell/Spell.lua
  6. 5
      src/Unit/Unit.lua

@ -100,6 +100,11 @@ function Aura:New(unit, index, type)
return self return self
end end
if C_UnitAuras.GetAuraDataByIndex then
local unitAuraInfo = C_UnitAuras.GetAuraDataByIndex(unit:GetOMToken(), index, type)
return Aura:CreateFromUnitAuraInfo(unitAuraInfo, index, type)
end
local name, icon, count, dispelType, duration, expirationTime, source, isStealable, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, castByPlayer, nameplateShowAll, timeMod, v1, v2, v3, v4 = local name, icon, count, dispelType, duration, expirationTime, source, isStealable, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, castByPlayer, nameplateShowAll, timeMod, v1, v2, v3, v4 =
UnitAura(unit:GetOMToken(), index, type) UnitAura(unit:GetOMToken(), index, type)
---@class Bastion.Aura ---@class Bastion.Aura
@ -137,10 +142,10 @@ function Aura:New(unit, index, type)
end end
local foodAndDrinkStrings = { local foodAndDrinkStrings = {
[5] = "Refreshment",
[1] = MINIMAP_TRACKING_VENDOR_FOOD, -- Food & Drink [1] = MINIMAP_TRACKING_VENDOR_FOOD, -- Food & Drink
[2] = POWER_TYPE_FOOD, -- Food [2] = POWER_TYPE_FOOD, -- Food
[4] = TUTORIAL_TITLE12, -- Drink [3] = TUTORIAL_TITLE12, -- Drink
[4] = "Refreshment",
} }
---@type { [number]: boolean } ---@type { [number]: boolean }
@ -151,9 +156,10 @@ function Aura:IsFoodOrDrink()
if cachedFoodAndDrinkIDs[self.aura.spellId] then if cachedFoodAndDrinkIDs[self.aura.spellId] then
return cachedFoodAndDrinkIDs[self.aura.spellId] return cachedFoodAndDrinkIDs[self.aura.spellId]
else else
if self.aura.name then local name = self:GetName()
if type(name) == "string" then
for i = 1, #foodAndDrinkStrings do for i = 1, #foodAndDrinkStrings do
if self.aura.name:find(foodAndDrinkStrings[i]) then if name:find(foodAndDrinkStrings[i]) then
cachedFoodAndDrinkIDs[self.aura.spellId] = true cachedFoodAndDrinkIDs[self.aura.spellId] = true
return true return true
end end
@ -165,46 +171,40 @@ function Aura:IsFoodOrDrink()
end end
-- Constructor -- Constructor
---@param unitAuraInfo AuraData ---@param unitAuraInfo? AuraData
---@param index? number
---@param type? "HELPFUL"|"HARMFUL"
---@return Bastion.Aura ---@return Bastion.Aura
function Aura:CreateFromUnitAuraInfo(unitAuraInfo) function Aura:CreateFromUnitAuraInfo(unitAuraInfo, index, type)
---@class Bastion.Aura if unitAuraInfo then
local self = setmetatable({}, Aura) ---@class Bastion.Aura
--[[ self.aura = {
applications name = unitAuraInfo.name,
charges icon = unitAuraInfo.icon,
isNameplateOnly count = unitAuraInfo.applications,
isRaid dispelType = unitAuraInfo.dispelName,
maxCharges duration = unitAuraInfo.duration,
]] expirationTime = unitAuraInfo.expirationTime,
-- source = unitAuraInfo.sourceUnit,
--print(unitAuraInfo.name, unitAuraInfo.sourceUnit, unitAuraInfo.expirationTime, unitAuraInfo.duration) isStealable = unitAuraInfo.isStealable,
self.aura = { nameplateShowPersonal = unitAuraInfo.nameplateShowPersonal,
auraInstanceID = unitAuraInfo.auraInstanceID, spellId = unitAuraInfo.spellId,
canApplyAura = unitAuraInfo.canApplyAura, canApplyAura = unitAuraInfo.canApplyAura,
castByPlayer = unitAuraInfo.isFromPlayerOrPlayerPet, isBossDebuff = unitAuraInfo.isBossAura,
count = unitAuraInfo.applications, castByPlayer = unitAuraInfo.isFromPlayerOrPlayerPet,
dispelType = unitAuraInfo.dispelName or "", nameplateShowAll = unitAuraInfo.nameplateShowAll,
duration = unitAuraInfo.duration, timeMod = unitAuraInfo.timeMod,
expirationTime = unitAuraInfo.expirationTime, auraInstanceID = unitAuraInfo.auraInstanceID,
icon = unitAuraInfo.icon, points = unitAuraInfo.points,
isBossDebuff = unitAuraInfo.isBossAura, index = index,
isStealable = unitAuraInfo.isStealable, type = type or unitAuraInfo.isHarmful and "HARMFUL" or "HELPFUL",
name = unitAuraInfo.name, }
nameplateShowAll = unitAuraInfo.nameplateShowAll,
nameplateShowPersonal = unitAuraInfo.nameplateShowPersonal,
points = unitAuraInfo.points,
source = unitAuraInfo.sourceUnit,
spellId = unitAuraInfo.spellId,
timeMod = unitAuraInfo.timeMod,
index = nil,
type = unitAuraInfo.isHarmful and "HARMFUL" or "HELPFUL",
}
-- Register spell in spellbook -- Register spell in spellbook
Bastion.Globals.SpellBook:GetSpell(self.aura.spellId) Bastion.Globals.SpellBook:GetSpell(self.aura.spellId)
return self return self
end
return Aura:New()
end end
-- Check if the aura is valid -- Check if the aura is valid
@ -400,4 +400,8 @@ function Aura:IsDispelableBySpell(spell)
return false return false
end end
function Aura:GetPoints()
return self.aura.points
end
Bastion.Aura = Aura Bastion.Aura = Aura

@ -156,9 +156,10 @@ function AuraTable:GetUnitBuffs()
end end
return return
end end
local auraIndex = 0
AuraUtil_ForEachAura(self.unit:GetOMToken(), "HELPFUL", nil, function(a) AuraUtil_ForEachAura(self.unit:GetOMToken(), "HELPFUL", nil, function(a)
local aura = Bastion.Aura:CreateFromUnitAuraInfo(a) auraIndex = auraIndex + 1
local aura = Bastion.Aura:CreateFromUnitAuraInfo(a, auraIndex)
if aura:IsValid() then if aura:IsValid() then
self:AddOrUpdateAuraInstanceID(aura:GetAuraInstanceID(), aura) self:AddOrUpdateAuraInstanceID(aura:GetAuraInstanceID(), aura)
@ -195,9 +196,10 @@ function AuraTable:GetUnitDebuffs()
end end
return return
end end
local auraIndex = 0
AuraUtil_ForEachAura(self.unit:GetOMToken(), "HARMFUL", nil, function(a) AuraUtil_ForEachAura(self.unit:GetOMToken(), "HARMFUL", nil, function(a)
local aura = Bastion.Aura:CreateFromUnitAuraInfo(a) auraIndex = auraIndex + 1
local aura = Bastion.Aura:CreateFromUnitAuraInfo(a, auraIndex)
if aura:IsValid() then if aura:IsValid() then
self:AddOrUpdateAuraInstanceID(aura:GetAuraInstanceID(), aura) self:AddOrUpdateAuraInstanceID(aura:GetAuraInstanceID(), aura)
@ -802,7 +804,7 @@ function AuraTable:HasAnyDispelableAura(spell)
end end
function AuraTable:HasAnyFoodOrDrinkAura() function AuraTable:HasAnyFoodOrDrinkAura()
for _, auras in pairs(self:GetUnitAuras()) do for _, auras in pairs(self:GetMyUnitAuras()) do
for _, aura in pairs(auras) do for _, aura in pairs(auras) do
if aura:IsUp() then -- Handle expired and non refreshed dropoffs not coming in UNIT_AURA if aura:IsUp() then -- Handle expired and non refreshed dropoffs not coming in UNIT_AURA
if aura:IsFoodOrDrink() then if aura:IsFoodOrDrink() then

@ -106,7 +106,7 @@ function Item:New(id)
self.shouldUpdate = true self.shouldUpdate = true
C_Item.RequestLoadItemDataByID(id) C_Item.RequestLoadItemDataByID(id)
else else
local name, spellID = GetItemSpell(self:GetID()) local name, spellID = self:GetItemSpell()
if spellID then if spellID then
self.spellID = spellID self.spellID = spellID
Bastion.Globals.SpellBook:GetSpell(spellID) Bastion.Globals.SpellBook:GetSpell(spellID)
@ -176,10 +176,17 @@ function Item:EvaluateTraits()
return true return true
end end
function Item:GetItemSpell()
if C_Item.GetItemSpell then
return C_Item.GetItemSpell(self:GetID())
end
return GetItemSpell(self:GetID())
end
function Item:Update() function Item:Update()
if self:ShouldUpdate() then if self:ShouldUpdate() then
if not self.spellID and self.playerUsable then if not self.spellID and self.playerUsable then
local name, spellID = GetItemSpell(self:GetID()) local name, spellID = self:GetItemSpell()
if spellID then if spellID then
self.spellID = spellID self.spellID = spellID
self.shouldUpdate = false self.shouldUpdate = false
@ -189,6 +196,13 @@ function Item:Update()
end end
end end
function Item:GetItemInfo()
if C_Item.GetItemInfo then
return C_Item.GetItemInfo(self:GetID())
end
return GetItemInfo(self:GetID())
end
-- Get the Items id -- Get the Items id
---@return number ---@return number
function Item:GetID() function Item:GetID()
@ -196,21 +210,22 @@ function Item:GetID()
end end
-- Get the Items name -- Get the Items name
---@return string
function Item:GetName() function Item:GetName()
return select(1, GetItemInfo(self:GetID())) return select(1, self:GetItemInfo())
end end
-- Get the Items icon -- Get the Items icon
---@return number
function Item:GetIcon() function Item:GetIcon()
return select(3, GetItemInfo(self:GetID())) if C_Item.GetItemIconByID then
return C_Item.GetItemIconByID(self:GetID())
end
return select(3, self:GetItemInfo())
end end
-- Get the Items cooldown -- Get the Items cooldown
---@return number ---@return number
function Item:GetCooldown() function Item:GetCooldown()
return select(2, C_Container.GetItemCooldown(self:GetID())) return select(2, self:GetItemCooldown())
end end
-- Return the Usable function -- Return the Usable function
@ -231,10 +246,17 @@ function Item:GetOnUseFunction()
return self.OnUseFunc return self.OnUseFunc
end end
function Item:GetItemCooldown()
if C_Item.GetItemCooldown then
return C_Item.GetItemCooldown(self:GetID())
end
return C_Container.GetItemCooldown(self:GetID())
end
-- Get the Items cooldown remaining -- Get the Items cooldown remaining
---@return number ---@return number
function Item:GetCooldownRemaining() function Item:GetCooldownRemaining()
local start, duration = C_Container.GetItemCooldown(self:GetID()) local start, duration = self:GetItemCooldown()
return start == 0 and 0 or start + duration - GetTime() return start == 0 and 0 or start + duration - GetTime()
end end
@ -311,7 +333,7 @@ end
-- Check if the Item is known -- Check if the Item is known
function Item:IsEquipped() function Item:IsEquipped()
return IsEquippedItem(self:GetID()) return C_Item.IsEquippedItem(self:GetID())
end end
function Item:GetEquippedSlot() function Item:GetEquippedSlot()
@ -353,14 +375,17 @@ end
-- Check if the Item is on cooldown -- Check if the Item is on cooldown
---@return boolean ---@return boolean
function Item:IsOnCooldown() function Item:IsOnCooldown()
local _, duration = C_Container.GetItemCooldown(self:GetID()) return select(2, self:GetItemCooldown()) > 0
return duration > 0
end end
-- Check if the Item is usable -- Check if the Item is usable
---@return boolean ---@return boolean
function Item:IsUsable() function Item:IsUsable()
local usable, noMana = C_Item.IsUsableItem(self:GetID()) if C_Item.IsUsableItem then
local usable, noMana = C_Item.IsUsableItem(self:GetID())
return usable or usableExcludes[self:GetID()]
end
local usable, noMana = IsUsableItem(self:GetID())
return usable or usableExcludes[self:GetID()] return usable or usableExcludes[self:GetID()]
end end
@ -372,6 +397,9 @@ end
-- Is equippable -- Is equippable
function Item:IsEquippable() function Item:IsEquippable()
if C_Item.IsEquippableItem then
return C_Item.IsEquippableItem(self:GetID())
end
return IsEquippableItem(self:GetID()) return IsEquippableItem(self:GetID())
end end
@ -506,6 +534,9 @@ end
-- Get the Items charges -- Get the Items charges
---@return number ---@return number
function Item:GetCharges() function Item:GetCharges()
if C_Item.GetItemCount then
return C_Item.GetItemCount(self:GetID(), false, true, false)
end
local chargeInfo = GetItemCharges(self:GetID()) local chargeInfo = GetItemCharges(self:GetID())
return chargeInfo and chargeInfo.currentCharges or 0 return chargeInfo and chargeInfo.currentCharges or 0
end end

@ -137,7 +137,7 @@ function ObjectManager:Refresh(force)
table.insert(self.objects, object) table.insert(self.objects, object)
self:EnumLists(object) self:EnumLists(object)
if ({ [5] = true, [6] = true, [7] = true })[objectType] then if ({ [5] = true, [6] = true, [7] = true })[objectType] then
if objectType == 5 and ObjectCreatureType(object) == 8 then if objectType == 5 and object:creatureType() == 8 then
self.critters:push(Bastion.Globals.UnitManager:GetObject(objectGuid) or self.critters:push(Bastion.Globals.UnitManager:GetObject(objectGuid) or
Bastion.Globals.UnitManager:SetObject(Bastion.Unit:New(object), objectGuid)) Bastion.Globals.UnitManager:SetObject(Bastion.Unit:New(object), objectGuid))
elseif object:id() == 204560 --[[ unit:GetID() == 204560 ]] then elseif object:id() == 204560 --[[ unit:GetID() == 204560 ]] then

@ -568,8 +568,10 @@ function Spell:GetRange()
return self.maxRange, self.minRange return self.maxRange, self.minRange
end end
---@param target? Bastion.Unit ---@param source Bastion.Unit
function Spell:CheckRange(target) ---@param target Bastion.Unit
function Spell:CheckRange(source, target)
return self.isMelee and source:InMelee(target) or source:GetCombatDistance(target) <= self.maxRange
end end
---@param target? Bastion.Unit ---@param target? Bastion.Unit
@ -609,12 +611,11 @@ function Spell:IsInRange(unit)
end end
local inRange = C_Spell.IsSpellInRange(self:GetName(), unit:GetOMToken()) or false local inRange = C_Spell.IsSpellInRange(self:GetName(), unit:GetOMToken()) or false
if inRange then
--[[ if inRange then
return true return true
end ]] end
return inRange
--return Bastion.Globals.UnitManager:Get("player"):InMelee(unit) return Bastion.Globals.UnitManager:Get("player"):InMelee(unit)
end end
-- Get the last cast time -- Get the last cast time
@ -793,7 +794,8 @@ end
---@return boolean ---@return boolean
function Spell:IsEnrageDispel() function Spell:IsEnrageDispel()
return ({ return ({
[2908] = true, [2908] = true, -- Soothe
[19801] = true, -- Tranq Shot
})[self:GetID()] })[self:GetID()]
end end
@ -801,7 +803,12 @@ end
---@return boolean ---@return boolean
function Spell:IsMagicDispel() function Spell:IsMagicDispel()
return ({ return ({
[88423] = true, [77130] = true, -- Purify Spirit
[115450] = true, -- Detox
[4987] = true, -- Cleanse
[527] = true, -- Purify
[32375] = true, -- Mass Dispel
[89808] = true, -- Singe Magic
})[self:GetID()] })[self:GetID()]
end end
@ -809,7 +816,10 @@ end
---@return boolean ---@return boolean
function Spell:IsCurseDispel() function Spell:IsCurseDispel()
return ({ return ({
[88423] = true, [77130] = true, -- Purify Spirit
[2782] = true,
[475] = true, -- Remove Curse
[51886] = true, -- Cleanse Spirit
})[self:GetID()] })[self:GetID()]
end end
@ -817,14 +827,23 @@ end
---@return boolean ---@return boolean
function Spell:IsPoisonDispel() function Spell:IsPoisonDispel()
return ({ return ({
[88423] = true, [2782] = true,
[115450] = true, -- Detox
[4987] = true, -- Cleanse
[213644] = true, -- Cleanse Toxins
})[self:GetID()] })[self:GetID()]
end end
-- IsDiseaseDispel -- IsDiseaseDispel
---@return boolean ---@return boolean
function Spell:IsDiseaseDispel() function Spell:IsDiseaseDispel()
return ({})[self:GetID()] return ({
[115450] = true, -- Detox
[4987] = true, -- Cleanse
[213644] = true, -- Cleanse Toxins
[527] = true, -- Purify
[213634] = true, -- Purify Disease
})[self:GetID()]
end end
-- IsSpell -- IsSpell
@ -964,79 +983,4 @@ function Spell:InFlight(params)
return #self:GetMissiles(params) > 0 return #self:GetMissiles(params) > 0
end end
--[[ ---@param target? Bastion.Unit
function Spell:IsMineUp(target)
target = target or Bastion.UnitManager:Get("player")
return target:GetAuras():FindMy(self):IsUp()
end
---@param target? Bastion.Unit
function Spell:IsMineRefreshable(target)
target = target or Bastion.UnitManager:Get("player")
return target:GetAuras():FindMy(self):Refreshable()
end
---@param spells Bastion.List
---@param source Bastion.Unit
---@param target Bastion.Unit
function Spell:IsAnyUp(spells, source, target)
local targetAuras = source:Exists() and target:GetAuras():FindAnyFrom(spells + self, source) or
target:GetAuras():FindAnyOf(spells + self)
return targetAuras:IsUp()
end
---@param source Bastion.Unit
---@params target Bastion.Unit
function Spell:IsUp(source, target)
local targetAuras = source:Exists() and target:GetAuras():FindFrom(self, source) or target:GetAuras():FindAny(self)
return targetAuras:IsUp()
end
---@param source Bastion.Unit
---@param target Bastion.Unit
function Spell:IsDown(source, target)
local targetAuras = source:Exists() and target:GetAuras():FindFrom(self, source) or target:GetAuras():FindAny(self)
return targetAuras:IsDown()
end
---@param spells Bastion.List
---@param target Bastion.Unit
function Spell:IsAnyOfMineUp(spells, target)
target = target or Bastion.UnitManager:Get("player")
return target:GetAuras():FindAnyOfMy(spells + self):IsUp()
end
---@param source Bastion.Unit
---@param target Bastion.Unit
function Spell:GetAuraCount(source, target)
return (source:Exists() and target:GetAuras():FindFrom(self, source) or target:GetAuras():FindAny(self)):GetCount()
end
---@param target? Bastion.Unit
function Spell:GetMyCount(target)
target = target or Bastion.UnitManager:Get("player")
return target:GetAuras():FindMy(self):GetCount()
end
---@param source Bastion.Unit
---@param target Bastion.Unit
function Spell:GetRemainingTime(source, target)
local targetAuras = source:Exists() and target:GetAuras():FindFrom(self, source) or target:GetAuras():FindAny(self)
return targetAuras:GetRemainingTime()
end
---@param target? Bastion.Unit
function Spell:GetMyRemainingTime(target)
target = target or Bastion.UnitManager:Get("player")
return target:GetAuras():FindMy(self):GetRemainingTime()
end
---@param spells Bastion.List
---@param source Bastion.Unit
---@param target Bastion.Unit
function Spell:GetAnyRemainingTime(spells, source, target)
return (source:Exists() and target:GetAuras():FindAnyFrom(spells + self, source) or target:GetAuras():FindAnyOf(spells + self))
:GetRemainingTime()
end ]]
Bastion.Spell = Spell Bastion.Spell = Spell

@ -1439,6 +1439,10 @@ function Unit:GetPowerRegen()
return GetPowerRegen(self:GetOMToken()) return GetPowerRegen(self:GetOMToken())
end end
function Unit:GetPowerRegenByType(powerType)
return GetPowerRegenForPowerType(powerType)
end
-- Get the units staggered health relation -- Get the units staggered health relation
---@return number ---@return number
function Unit:GetStaggeredHealth() function Unit:GetStaggeredHealth()
@ -1820,7 +1824,6 @@ function Unit:TimeToDie2(minSamples)
end end
end end
return ttd[minSamples] or v return ttd[minSamples] or v
end end

Loading…
Cancel
Save