Updates to Spell Charge functions.

main
ck 1 year ago
parent 6fd60c6a4f
commit 3d203c280c
  1. 15
      src/EventManager/EventManager.lua
  2. 58
      src/Spell/Spell.lua
  3. 42
      src/Unit/Unit.lua

@ -40,8 +40,8 @@ function EventManager:New()
end
end)
self:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function(event)
self:CLEUHandler(event, CombatLogGetCurrentEventInfo())
self:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function()
self:CLEUHandler(CombatLogGetCurrentEventInfo())
end)
return self
@ -125,19 +125,18 @@ function EventManager:RegisterCombatEvent(subevent, handler)
end
end
---@param event "COMBAT_LOG_EVENT_UNFILTERED"
---@param timestamp number
---@param subevent string
---@param ... any
function EventManager:CLEUHandler(event, timestamp, subevent, ...)
function EventManager:CLEUHandler(timestamp, subevent, ...)
if self.selfCombatEventHandlers[subevent] and select(2, ...) == UnitGUID("player") then
for _, handler in pairs(self.selfCombatEventHandlers[subevent]) do
handler(timestamp, subevent, ...)
for _, callback in ipairs(self.selfCombatEventHandlers[subevent]) do
callback(timestamp, subevent, ...)
end
end
if self.CombatEventHandlers[subevent] then
for _, handler in pairs(self.CombatEventHandlers[subevent]) do
handler(timestamp, subevent, ...)
for _, callback in ipairs(self.CombatEventHandlers[subevent]) do
callback(timestamp, subevent, ...)
end
end
end

@ -114,23 +114,6 @@ function Spell:GetCooldown()
return select(2, GetSpellCooldown(self:GetID()))
end
-- Get the full cooldown (time until all charges are available)
---@return number
function Spell:GetFullRechargeTime()
local start, duration, enabled = GetSpellCooldown(self:GetID())
if enabled == 0 then
return 0
end
local charges, maxCharges, chargeStart, chargeDuration = GetSpellCharges(self:GetID())
if charges == maxCharges then
return 0
end
local totalChargeTime = ((maxCharges - charges) * chargeDuration) - ((chargeStart + chargeDuration) - GetTime())
return totalChargeTime
end
-- Return the castable function
function Spell:GetCastableFunction()
return self.CastableIfFunc
@ -296,9 +279,10 @@ function Spell:IsUsable()
end
-- Check if the spell is castable
---@param override? boolean
---@return boolean
function Spell:IsKnownAndUsable()
return self:IsKnown() and not self:IsOnCooldown() and self:IsUsable()
function Spell:IsKnownAndUsable(override)
return self:IsKnown(override) and not self:IsOnCooldown() and self:IsUsable()
end
-- Check if the spell is castable
@ -441,29 +425,41 @@ function Spell:GetMaxCharges()
return select(2, GetSpellCharges(self:GetID()))
end
---@return number
function Spell:GetCastLength()
return select(4, GetSpellInfo(self:GetID()))
end
-- Get the spells charges
-- Get the full cooldown (time until all charges are available)
---@return number
function Spell:GetChargesFractional()
local charges, maxCharges, start, duration = GetSpellCharges(self:GetID())
function Spell:GetFullRechargeTime()
local charges, maxCharges, _, duration = GetSpellCharges(self:GetID())
if not charges or not maxCharges or charges == maxCharges then
return 0
end
return (maxCharges - self:GetChargesFractional()) * duration
end
function Spell:Recharge()
local charges, maxCharges, startTime, duration = GetSpellCharges(self:GetID())
if charges == maxCharges then
return maxCharges
return charges
end
if charges == 0 then
return 0
end
local recharge = startTime + duration - GetTime()
return recharge > 0 and recharge or 0
end
local timeSinceStart = GetTime() - start
local timeLeft = duration - timeSinceStart
local timePerCharge = duration / maxCharges
local chargesFractional = charges + (timeLeft / timePerCharge)
-- Get the spells charges plus fractional
---@return number
function Spell:GetChargesFractional()
local charges, maxCharges, _, duration = GetSpellCharges(self:GetID())
return chargesFractional
if charges == maxCharges then
return charges
end
return charges + ((duration - self:Recharge()) / duration)
end
-- Get the spells charges remaining

@ -513,25 +513,47 @@ function Unit:GetLOSSourcePosition()
end
local losFlag = bit.bor(0x10)
-- Check if the unit can see another unit
---@param targetUnit Unit
---@param unit Unit
---@return boolean
function Unit:CanSee(targetUnit)
local npcId = targetUnit:GetID()
if npcId and losBlacklist[npcId] then
return true
function Unit:CanSee(unit)
-- mechagon smoke cloud
-- local mechagonID = 2097
-- local smokecloud = 298602
-- local name, instanceType, difficultyID, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceID, instanceGroupSize, LfgDungeonID =
-- GetInstanceInfo()
-- otherUnit = otherUnit and otherUnit or "player"
-- if instanceID == 2097 then
-- if (self:debuff(smokecloud, unit) and not self:debuff(smokecloud, otherUnit))
-- or (self:debuff(smokecloud, otherUnit) and not self:debuff(smokecloud, unit))
-- then
-- return false
-- end
-- end
local ax, ay, az = ObjectPosition(self:GetOMToken())
local ah = ObjectHeight(self:GetOMToken())
local attx, atty, attz = GetUnitAttachmentPosition(unit:GetOMToken(), 34)
if not attx or not ax then
return false
end
local src = self:GetLOSSourcePosition()
local dst = targetUnit:GetHitSphere()
if not ah then
return false
end
if (src.x == 0 and src.y == 0 and src.z == 0) or (dst.x == 0 and dst.y == 0 and dst.z == 0) then
if (ax == 0 and ay == 0 and az == 0) or (attx == 0 and atty == 0 and attz == 0) then
return true
end
local contactPoint = src + (dst - src):directionOrZero() * math.min(targetUnit:GetDistance(self), self:GetCombatReach())
if not attx or not ax then
return false
end
local x, y, z = TraceLine(src.x, src.y, src.z, contactPoint.x, contactPoint.y, contactPoint.z, losFlag)
local x, y, z = TraceLine(ax, ay, az + ah, attx, atty, attz, losFlag)
if x ~= 0 or y ~= 0 or z ~= 0 then
return false
else

Loading…
Cancel
Save