From 3d203c280c460c96acba975d697bebf9f7ae65f1 Mon Sep 17 00:00:00 2001 From: ck Date: Tue, 26 Dec 2023 10:11:46 -0600 Subject: [PATCH] Updates to Spell Charge functions. --- src/EventManager/EventManager.lua | 15 ++++---- src/Spell/Spell.lua | 58 ++++++++++++++----------------- src/Unit/Unit.lua | 42 ++++++++++++++++------ 3 files changed, 66 insertions(+), 49 deletions(-) diff --git a/src/EventManager/EventManager.lua b/src/EventManager/EventManager.lua index 8c0a62e..d9d9439 100644 --- a/src/EventManager/EventManager.lua +++ b/src/EventManager/EventManager.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 diff --git a/src/Spell/Spell.lua b/src/Spell/Spell.lua index d49bc4e..13be388 100644 --- a/src/Spell/Spell.lua +++ b/src/Spell/Spell.lua @@ -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 diff --git a/src/Unit/Unit.lua b/src/Unit/Unit.lua index d1cd614..eb3511e 100644 --- a/src/Unit/Unit.lua +++ b/src/Unit/Unit.lua @@ -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