From 22b48bb284c63aa1a4abb212fb089962eb4c98ad Mon Sep 17 00:00:00 2001 From: Ryan Crockett Date: Mon, 20 Mar 2023 16:02:46 -0400 Subject: [PATCH] More optomization --- scripts/frost/frost.lua | 55 +++++++++++++++++++++++++++------ src/Unit/Unit.lua | 7 ++++- src/UnitManager/UnitManager.lua | 17 +++++----- 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/scripts/frost/frost.lua b/scripts/frost/frost.lua index c7cd0d3..5b1aca9 100644 --- a/scripts/frost/frost.lua +++ b/scripts/frost/frost.lua @@ -35,7 +35,7 @@ local GetFrostOption = Tinkr:require("scripts/bastion/scripts/frost/frost-gui", local function isUnitFrozen(unit) if not unit:Exists() then return false end - if unit:GetAuras():FindMy(IceNova):IsUp() or unit:GetAuras():FindMy(FrostNova):IsUp() or unit:GetAuras():FindMy(WintersChill):IsUp() then + if unit:GetAuras():FindMy(IceNova):IsUp() or unit:GetAuras():FindMy(FrostNova):IsUp() then return true end @@ -84,7 +84,7 @@ local IceLanceTarget = Bastion.UnitManager:CreateCustomUnit('icelance', function end) local FrozenOrbTarget = Bastion.UnitManager:CreateCustomUnit('frozen_orb', function() - local unit = Bastion.UnitManager:GetEnemyWithMostEnemies(11) + local unit = Bastion.UnitManager:GetEnemyWithMostEnemies(40, 10) if not unit then if Target:Exists() and Target:GetDistance(Player) <= 40 then @@ -97,30 +97,65 @@ local FrozenOrbTarget = Bastion.UnitManager:CreateCustomUnit('frozen_orb', funct return unit end) +local HasRotatedForOrb = false + +FrozenOrb:OnCast(function() + HasRotatedForOrb = false +end) ---@return boolean local function CombatRotation() local targetCount = GetRangedTargetCount(40) - if GetFrostOption("CdsEnabled") and IcyVeins:IsKnown() and not Player:IsCastingOrChanneling() and not Player:IsMoving() then - IcyVeins:Cast(Player) + if GetFrostOption("CdsEnabled") and IcyVeins:IsKnownAndUsable() and not Player:IsMoving() and Target:Exists() then + return IcyVeins:Cast(Player) end - if GetFrostOption("CdsEnabled") and RuneOfPower:IsKnownAndUsable() and not Player:GetAuras():FindMy(RuneOfPower):IsUp() and not Player:IsMoving() then + if GetFrostOption("CdsEnabled") and RuneOfPower:IsKnownAndUsable() and not Player:GetAuras():FindMy(RuneOfPower):IsUp() and not Player:IsMoving() and Target:Exists() and IcyVeins:GetLastCastTime() ~= false and GetTime() - IcyVeins:GetLastCastTime() > 5 then return RuneOfPower:Cast(Player) end if FrozenOrb:IsKnownAndUsable() and GetFrostOption("FrozenOrbEnabled") and FrozenOrbTarget:Exists() then - FaceObject(FrozenOrbTarget:GetGUID()) - return FrozenOrb:Cast(Player) + if not HasRotatedForOrb then + print("TURNING TO ORB TARGET") + FaceObject(FrozenOrbTarget:GetGUID()) + SendMovementHeartbeat() + HasRotatedForOrb = true + else + return FrozenOrb:Cast(Player) + end end - if IceLance:IsKnownAndUsable() and IceLanceTarget:Exists() then + if IceLanceTarget:Exists() then return IceLance:Cast(IceLanceTarget) end - if Target:Exists() and Player:CanSee(Target) and IceLance:IsKnownAndUsable() and IceLance:IsInRange(Target) and (isUnitFrozen(Target) or Player:GetAuras():FindMy(FingersOfFrost):IsUp()) then - return IceLance:Cast(Target) + if Target:Exists() and Player:CanSee(Target) and IceLance:IsKnownAndUsable() and IceLance:IsInRange(Target) then + -- Winters Chill + if Target:GetAuras():FindMy(WintersChill):IsUp() then + local winters_chill_stacks = Target:GetAuras():FindMy(WintersChill):GetCount() + print("WC STACKS: ", winters_chill_stacks) + if winters_chill_stacks == 1 and not IceLance:IsInFlightToUnit(Target) then + return IceLance:Cast(Target) + end + + if winters_chill_stacks > 1 then + return IceLance:Cast(Target) + end + end + + -- Fingers of Frost + if Player:GetAuras():FindMy(FingersOfFrost):IsUp() then + local fof_stacks = Player:GetAuras():FindMy(FingersOfFrost):GetCount() + print("FOF STACKS: ", fof_stacks) + if fof_stacks == 1 and not IceLance:IsInFlightToUnit(Target) then + return IceLance:Cast(Target) + end + + if fof_stacks > 1 then + return IceLance:Cast(Target) + end + end end if Target:Exists() and Player:CanSee(Target) and Flurry:IsKnownAndUsable() and Player:GetAuras():FindMy(BrainFreeze):IsUp() then diff --git a/src/Unit/Unit.lua b/src/Unit/Unit.lua index eec052b..9ffd652 100644 --- a/src/Unit/Unit.lua +++ b/src/Unit/Unit.lua @@ -588,12 +588,17 @@ end -- IsFacing ---@param unit Unit +---@param fov? number ---@return boolean -function Unit:IsFacing(unit) +function Unit:IsFacing(unit, fov) local rot = ObjectRotation(self:GetOMToken()) local x, y, z = ObjectPosition(self:GetOMToken()) local x2, y2, z2 = ObjectPosition(unit:GetOMToken()) + local fovToUse = 90 + + if fov then fovToUse = fov end + if not x or not x2 or not rot then return false end diff --git a/src/UnitManager/UnitManager.lua b/src/UnitManager/UnitManager.lua index 6c53278..601fbae 100644 --- a/src/UnitManager/UnitManager.lua +++ b/src/UnitManager/UnitManager.lua @@ -311,18 +311,19 @@ function UnitManager:FindFriendsCentroid(radius, range) end -- Get the enemy with the most enemies within a given radius +---@param distanceFromPlayer number ---@param radius number ---@return Unit ---@return table -function UnitManager:GetEnemyWithMostEnemies(radius) +function UnitManager:GetEnemyWithMostEnemies(distanceFromPlayer, radius) local unit = nil local count = 0 local enemies = {} self:EnumEnemies(function(u) - if u:IsAlive() then + if u:IsAlive() and u:IsAffectingCombat() and u:GetDistance(self:Get("player")) <= distanceFromPlayer then local c = 0 self:EnumEnemies(function(other) - if other:IsAlive() and u:GetDistance(other) <= radius then + if other:IsAlive() and other:IsAffectingCombat() and u:GetDistance(other) <= radius then c = c + 1 end end) @@ -331,7 +332,7 @@ function UnitManager:GetEnemyWithMostEnemies(radius) count = c enemies = {} self:EnumEnemies(function(other) - if other:IsAlive() and u:GetDistance(other) <= radius then + if other:IsAlive() and other:IsAffectingCombat() and u:GetDistance(other) <= radius then table.insert(enemies, other) end end) @@ -342,11 +343,11 @@ function UnitManager:GetEnemyWithMostEnemies(radius) end -- Find the centroid of the most dense area of friends (party/raid members) of a given radius within a given range +---@param distanceFromPlayer number ---@param radius number ----@param range number ---@return Vector3 | nil -function UnitManager:FindEnemiesCentroid(radius, range) - local unit, enemies = self:GetEnemyWithMostEnemies(radius) +function UnitManager:FindEnemiesCentroid(distanceFromPlayer, radius) + local unit, enemies = self:GetEnemyWithMostEnemies(distanceFromPlayer, radius) if unit == nil then return nil end @@ -361,7 +362,7 @@ function UnitManager:FindEnemiesCentroid(radius, range) centroid = centroid / #enemies - if unit:GetPosition():Distance(centroid) > range then + if unit:GetPosition():Distance(centroid) > distanceFromPlayer then return unit:GetPosition() end