Skip to main content

Spell Class

Important Note About Checks

Several checks are automatically performed in the cast() and smartaoe() functions, making manual checks redundant. These include:

  • ready() - No need to check if spell is ready before casting
  • castable(unit) - No need to check if spell is castable before casting
  • isusable() - No need to check if spell is usable before casting
  • inrange(unit) - No need to check range before casting
  • unit.distance - No need to check distance before casting
  • unit.los - No need to check line of sight before casting
  • unit.facing - No need to check facing before casting

Incorrect Usage:

if spell:ready() and spell:castable("target") and target.los and target.distanceto(player) < 40 then
spell:cast("target") -- Redundant checks!
end

Correct Usage:

spell:cast("target") -- All necessary checks are performed internally

The Spell class provides a comprehensive interface for handling spells in World of Warcraft. It includes functionality for checking spell availability, casting spells, managing cooldowns, and handling various spell-specific behaviors.

Installation

local spell = Aurora.SpellHandler.NewSpell(spellID, payload)

Parameters

ParameterTypeDescription
spellIDnumber | number[]Single spell ID or array of spell IDs for different ranks
payloadtableOptional configuration settings

Payload Options

OptionTypeDefaultDescription
ignoreCastingbooleanfalseIgnore if player is casting
ignoreChannelingbooleanfalseIgnore if player is channeling
ignoreCostbooleanfalseIgnore resource costs
ignoreFacingbooleanfalseIgnore facing requirements
ignoreMovingbooleanfalseIgnore movement restrictions
isSkillshotbooleanfalseTreat as skillshot spell
maxOffsetnumber0Maximum targeting offset
minOffsetnumber0Minimum targeting offset
nextMeleebooleanfalseQueue for next melee
radiusnumber0Spell effect radius
queuedbooleanfalseAllow spell queueing
timeToHitnumber0Time until spell impact
petspellbooleanfalseCheck if said spell is a pet spell
castbyIDbooleanfalseCast spell by ID instead of name (useful for spells like mangle(cat) & mangle(feral) on classic WoW)

Core Methods

cast(unit)

Attempts to cast the spell on the specified unit.

local success = spell:cast(target) -- Returns boolean indicating success

castable(unit)

Checks if spell can be cast on the specified unit.

local canCast = spell:castable(target) -- Returns boolean

ready()

Checks if spell is ready to be cast (off cooldown and usable).

local isReady = spell:ready() -- Returns boolean

Cooldown Methods

getcd()

Gets remaining cooldown time in seconds.

local cooldown = spell:getcd() -- Returns number (seconds)

charges()

Gets current number of charges.

local currentCharges = spell:charges() -- Returns number

maxcharges()

Gets maximum number of charges.

local maxCharges = spell:maxcharges() -- Returns number

chargesleft()

Gets fractional charges remaining (includes partial charge regeneration).

local fractionalCharges = spell:chargesleft() -- Returns number

timetofull()

Gets time until all charges are regenerated.

local timeToFull = spell:timetofull() -- Returns number (seconds)

timetonextcharge()

Gets time until next charge is available.

local timeToNext = spell:timetonextcharge() -- Returns number (seconds)

Cast History Methods

waslastcast(timeWindow)

Checks if this spell was the last one cast within the specified time window.

local wasLast = spell:waslastcast(1.5) -- Returns boolean

wasSecondLastCast()

Checks if this spell was the second-to-last spell cast.

local wasSecondLast = spell:wasSecondLastCast() -- Returns boolean

timeSinceLastCast()

Gets time elapsed since this spell was last cast.

local timeSince = spell:timeSinceLastCast() -- Returns number (seconds)

AOE Methods

smartaoe(target, options)

Intelligently casts AOE spell considering multiple targets.

spell:smartaoe(target, {
offsetMin = 0, -- Minimum offset distance
offsetMax = 8, -- Maximum offset distance
distanceSteps = 24, -- Number of distance checks
circleSteps = 48, -- Number of circular positions to check
filter = function(unit, distance, position) -- Optional filter function
return true -- Return true to count this unit
end,
ignoreEnemies = false, -- Ignore enemy units
ignoreFriends = false -- Ignore friendly units
})

smartaoeposition(target, options)

Gets the optimal position for an AOE spell cast.

local position = spell:smartaoeposition(target, {
-- Same options as smartaoe()
})
-- Returns {x, y, z, hitCount} or nil

Utility Methods

inrange(unit)

Checks if target is within spell range.

local inRange = spell:inrange(target) -- Returns boolean

rank()

Gets the current rank of a talent spell.

local rank = spell:rank() -- Returns number

overlayed()

Checks if the spell is currently overlayed (glowing).

local isOverlayed = spell:overlayed() -- Returns boolean

getcasttime()

Gets the cast time of the spell in seconds.

local castTime = spell:getcasttime() -- Returns number (seconds)

isusable()

Checks if spell is currently usable (has resources, etc).

local isusable, notEnoughResources = spell:isusable() -- Returns two booleans

Example Usage

-- Create a new spell object for Fireball
local fireball = Aurora.SpellHandler.NewSpell(133, {
})

-- Check if we can cast Fireball on our target
if fireball:castable("target") then
-- Cast Fireball
fireball:cast("target")
end

-- Create an AOE spell like Blizzard
local blizzard = Aurora.SpellHandler.NewSpell(190356, {
isSkillshot = true,
radius = 8
})

-- Cast Blizzard optimally on groups of enemies
blizzard:smartaoe("target", {
offsetMax = 30,
filter = function(unit, distance, position)
return unit.enemy and not unit.dead
end
})