diff --git a/ClassicAPI.lua b/ClassicAPI.lua index 5224412..b0897b6 100644 --- a/ClassicAPI.lua +++ b/ClassicAPI.lua @@ -286,6 +286,15 @@ function API.GetSpellBonusHealing() return GetSpellBonusHealing() end +-- Spell haste for `unit` as a percentage: 0 unhasted, positive when casts are +-- sped up, negative while slowed (Curse of Tongues). 0 for a unit that doesn't +-- resolve. Vanilla has no haste API at all -- ClassicAPI derives this from the +-- UNIT_MOD_CAST_SPEED descriptor field the server folds into the cast time, so +-- it's exact and needs no nampower GetUnitField dependency. +function API.UnitSpellHaste(unit) + return UnitSpellHaste(unit) +end + -------------------------------------------------------------------------------- -- Unit Health -------------------------------------------------------------------------------- diff --git a/Conditionals.lua b/Conditionals.lua index 6eb2ae7..5dcf3dc 100644 --- a/Conditionals.lua +++ b/Conditionals.lua @@ -3249,6 +3249,25 @@ function CleveRoids.ValidatePowerLost(unit, operator, amount) return false end +-- Checks the given unit's spell haste percentage vs the given amount +-- unit: The unit we're checking +-- operator: valid comparitive operator symbol +-- amount: The required amount, in percent (0 = unhasted, negative = slowed) +-- returns: True or false +-- NOTE: the shared arg parser doesn't accept a sign on the amount, so a +-- specific negative threshold ([myspellhaste:<-10]) can't be written; use +-- [myspellhaste:<0] to test for being slowed at all. +function CleveRoids.ValidateSpellHaste(unit, operator, amount) + if not unit or not operator or not amount then return false end + local haste = CleveRoids.ClassicAPI.UnitSpellHaste(unit) + + if CleveRoids.operators[operator] then + return CleveRoids.comparators[operator](haste, amount) + end + + return false +end + -- Checks whether or not the given unit has hp in percent vs the given amount -- unit: The unit we're checking -- operator: valid comparitive operator symbol @@ -6482,6 +6501,30 @@ CleveRoids.Keywords = { end, conditionals, "mylevel") end, + myspellhaste = function(conditionals) + return Multi(conditionals.myspellhaste, function(args) + if type(args) ~= "table" then return false end + + -- Handle multi-comparison (e.g., >50&<80) + if args.comparisons and type(args.comparisons) == "table" then + local haste = CleveRoids.ClassicAPI.UnitSpellHaste("player") + + -- ALL comparisons must pass (AND logic) + for _, comp in ipairs(args.comparisons) do + if not CleveRoids.operators[comp.operator] then + return false + end + if not CleveRoids.comparators[comp.operator](haste, comp.amount) then + return false + end + end + return true + end + + return CleveRoids.ValidateSpellHaste("player", args.operator, args.amount) + end, conditionals, "myspellhaste") + end, + myhp = function(conditionals) return Multi(conditionals.myhp, function(args) if type(args) ~= "table" then return false end diff --git a/MacroErrorChecker.lua b/MacroErrorChecker.lua index 4074ebb..350a75c 100644 --- a/MacroErrorChecker.lua +++ b/MacroErrorChecker.lua @@ -669,6 +669,7 @@ local function validateConditional(conditional, args, action) button = true, form = true, stance = true, level = true, mylevel = true, + myspellhaste = true, distance = true, nodistance = true, swingtimer = true, stimer = true, rangedtimer = true, rtimer = true, @@ -689,7 +690,7 @@ local function validateConditional(conditional, args, action) if args and type(args) == "string" then local hasHpOrPower = safeStringFind(baseCond, "hp") or safeStringFind(baseCond, "power") or safeStringFind(baseCond, "mana") or safeStringFind(baseCond, "energy") or - safeStringFind(baseCond, "rage") or + safeStringFind(baseCond, "rage") or safeStringFind(baseCond, "haste") or safeStringFind(baseCond, "combo") or baseCond == "stat" if hasHpOrPower then local hasOperator = safeStringFind(args, "[<>=~]+")