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

@ -156,9 +156,10 @@ function AuraTable:GetUnitBuffs()
end
return
end
local auraIndex = 0
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
self:AddOrUpdateAuraInstanceID(aura:GetAuraInstanceID(), aura)
@ -195,9 +196,10 @@ function AuraTable:GetUnitDebuffs()
end
return
end
local auraIndex = 0
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
self:AddOrUpdateAuraInstanceID(aura:GetAuraInstanceID(), aura)
@ -802,7 +804,7 @@ function AuraTable:HasAnyDispelableAura(spell)
end
function AuraTable:HasAnyFoodOrDrinkAura()
for _, auras in pairs(self:GetUnitAuras()) do
for _, auras in pairs(self:GetMyUnitAuras()) do
for _, aura in pairs(auras) do
if aura:IsUp() then -- Handle expired and non refreshed dropoffs not coming in UNIT_AURA
if aura:IsFoodOrDrink() then

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

@ -137,7 +137,7 @@ function ObjectManager:Refresh(force)
table.insert(self.objects, object)
self:EnumLists(object)
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
Bastion.Globals.UnitManager:SetObject(Bastion.Unit:New(object), objectGuid))
elseif object:id() == 204560 --[[ unit:GetID() == 204560 ]] then

@ -568,8 +568,10 @@ function Spell:GetRange()
return self.maxRange, self.minRange
end
---@param target? Bastion.Unit
function Spell:CheckRange(target)
---@param source Bastion.Unit
---@param target Bastion.Unit
function Spell:CheckRange(source, target)
return self.isMelee and source:InMelee(target) or source:GetCombatDistance(target) <= self.maxRange
end
---@param target? Bastion.Unit
@ -609,12 +611,11 @@ function Spell:IsInRange(unit)
end
local inRange = C_Spell.IsSpellInRange(self:GetName(), unit:GetOMToken()) or false
--[[ if inRange then
if inRange then
return true
end ]]
return inRange
--return Bastion.Globals.UnitManager:Get("player"):InMelee(unit)
end
return Bastion.Globals.UnitManager:Get("player"):InMelee(unit)
end
-- Get the last cast time
@ -793,7 +794,8 @@ end
---@return boolean
function Spell:IsEnrageDispel()
return ({
[2908] = true,
[2908] = true, -- Soothe
[19801] = true, -- Tranq Shot
})[self:GetID()]
end
@ -801,7 +803,12 @@ end
---@return boolean
function Spell:IsMagicDispel()
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()]
end
@ -809,7 +816,10 @@ end
---@return boolean
function Spell:IsCurseDispel()
return ({
[88423] = true,
[77130] = true, -- Purify Spirit
[2782] = true,
[475] = true, -- Remove Curse
[51886] = true, -- Cleanse Spirit
})[self:GetID()]
end
@ -817,14 +827,23 @@ end
---@return boolean
function Spell:IsPoisonDispel()
return ({
[88423] = true,
[2782] = true,
[115450] = true, -- Detox
[4987] = true, -- Cleanse
[213644] = true, -- Cleanse Toxins
})[self:GetID()]
end
-- IsDiseaseDispel
---@return boolean
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
-- IsSpell
@ -964,79 +983,4 @@ function Spell:InFlight(params)
return #self:GetMissiles(params) > 0
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

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

Loading…
Cancel
Save