diff --git a/scripts/outlaw.lua b/scripts/outlaw.lua index 18b59e8..79d3f4a 100644 --- a/scripts/outlaw.lua +++ b/scripts/outlaw.lua @@ -89,7 +89,7 @@ local KickTarget = Bastion.UnitManager:CreateCustomUnit('kick', function(unit) return false end - if unit:IsInterruptible(5) then + if Player:InMelee(unit) and unit:IsInterruptible(5) and Player:IsFacing(unit) then purge = unit return true end diff --git a/src/Unit/Unit.lua b/src/Unit/Unit.lua index fdbf6cb..3b44b3a 100644 --- a/src/Unit/Unit.lua +++ b/src/Unit/Unit.lua @@ -385,4 +385,44 @@ function Unit:IsTanking(unit) return isTanking end +-- IsFacing +function Unit:IsFacing(unit) + local rot = ObjectRotation(self.unit) + local x, y, z = ObjectPosition(self.unit) + local x2, y2, z2 = ObjectPosition(unit.unit) + + if not x or not x2 then + return false + end + + local angle = math.atan2(y2 - y, x2 - x) - rot + angle = math.deg(angle) + angle = angle % 360 + if angle > 180 then + angle = angle - 360 + end + + return math.abs(angle) < 90 +end + +-- IsBehind +function Unit:IsBehind(unit) + local rot = ObjectRotation(unit.unit) + local x, y, z = ObjectPosition(unit.unit) + local x2, y2, z2 = ObjectPosition(self.unit) + + if not x or not x2 then + return false + end + + local angle = math.atan2(y2 - y, x2 - x) - rot + angle = math.deg(angle) + angle = angle % 360 + if angle > 180 then + angle = angle - 360 + end + + return math.abs(angle) > 90 +end + return Unit