You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
152 lines
5.9 KiB
152 lines
5.9 KiB
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
local ____exports = {}
|
|
local _, _Mekanome = ...
|
|
local Mekanome = _Mekanome
|
|
--- Creates a useable spell
|
|
local function Create(id, traits)
|
|
local spellInfo = C_Spell.GetSpellInfo(id)
|
|
if spellInfo == nil or spellInfo.name == nil then
|
|
error(
|
|
Mekanome.Error("Unable to find info for spell " .. tostring(id)),
|
|
0
|
|
)
|
|
end
|
|
return {
|
|
id = id,
|
|
minRange = spellInfo.minRange,
|
|
maxRange = spellInfo.maxRange,
|
|
name = spellInfo.name,
|
|
traits = traits
|
|
}
|
|
end
|
|
--- Get cooldown information for the spell.
|
|
local function GetCooldownInfo(spell)
|
|
local ____, cdDuration, enabled = GetSpellCooldown(spell.id)
|
|
local ____, ccDuration = GetSpellLossOfControlCooldown(spell.id)
|
|
local ____Mekanome_PlayerStateManager_GetPlayerState_result_0 = Mekanome.PlayerStateManager.GetPlayerState()
|
|
local spellQueueWindow = ____Mekanome_PlayerStateManager_GetPlayerState_result_0.spellQueueWindow
|
|
local secondsUntilReady = cdDuration == 0 and ccDuration or cdDuration
|
|
local secondsUntilCastable = secondsUntilReady - spellQueueWindow / 1000
|
|
return {secondsUntilReady = secondsUntilReady, secondsUntilCastable = secondsUntilCastable < 0 and 0 or secondsUntilCastable, isActive = enabled == 0}
|
|
end
|
|
--- Handles undefined / funciton traits to get a more usuable set of trait values
|
|
local function GetSpellTraits(spell)
|
|
local isCastableWhileMoving = false
|
|
local isCastableWhileCasting = false
|
|
local isOverride = false
|
|
if spell.traits ~= nil then
|
|
if spell.traits.isOverride ~= nil then
|
|
isOverride = spell.traits.isOverride
|
|
end
|
|
if spell.traits.isCastableWhileCasting ~= nil then
|
|
if type(spell.traits.isCastableWhileCasting) == "function" then
|
|
isCastableWhileCasting = spell.traits:isCastableWhileCasting()
|
|
else
|
|
isCastableWhileCasting = spell.traits.isCastableWhileCasting
|
|
end
|
|
end
|
|
if spell.traits.isCastableWhileMoving ~= nil then
|
|
if type(spell.traits.isCastableWhileMoving) == "function" then
|
|
isCastableWhileMoving = spell.traits:isCastableWhileMoving()
|
|
else
|
|
isCastableWhileMoving = spell.traits.isCastableWhileMoving
|
|
end
|
|
end
|
|
end
|
|
return {isCastableWhileMoving = isCastableWhileMoving, isCastableWhileCasting = isCastableWhileCasting, isOverride = isOverride}
|
|
end
|
|
--- Evaluates the spells traits & conditions to see if it is currently castable.
|
|
local function IsCastable(____bindingPattern0)
|
|
local spell
|
|
spell = ____bindingPattern0.spell
|
|
local target = ____bindingPattern0.target
|
|
local position = ____bindingPattern0.position
|
|
local player = Mekanome.MobManager.GetMob({token = "player"})
|
|
local ____GetSpellTraits_result_1 = GetSpellTraits(spell)
|
|
local isCastableWhileCasting = ____GetSpellTraits_result_1.isCastableWhileCasting
|
|
local isCastableWhileMoving = ____GetSpellTraits_result_1.isCastableWhileMoving
|
|
local isOverride = ____GetSpellTraits_result_1.isOverride
|
|
if player == nil then
|
|
return false
|
|
end
|
|
local traits = Mekanome.PlayerStateManager.GetPlayerState()
|
|
if isOverride == true then
|
|
if IsSpellKnownOrOverridesKnown(spell.id) ~= true then
|
|
return false
|
|
end
|
|
else
|
|
if IsSpellKnown(spell.id) ~= true then
|
|
return false
|
|
end
|
|
end
|
|
local ____GetCooldownInfo_result_2 = GetCooldownInfo(spell)
|
|
local isActive = ____GetCooldownInfo_result_2.isActive
|
|
local secondsUntilCastable = ____GetCooldownInfo_result_2.secondsUntilCastable
|
|
print("COOLDOWN: " .. tostring(secondsUntilCastable))
|
|
if isActive then
|
|
return false
|
|
end
|
|
if secondsUntilCastable ~= 0 then
|
|
return false
|
|
end
|
|
if traits.isMoving and isCastableWhileMoving == false then
|
|
return false
|
|
end
|
|
if traits.isCasting == true and isCastableWhileCasting == false then
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
--- Get the localized name of the spell.
|
|
local function GetName(spell)
|
|
local name = C_Spell.GetSpellInfo(spell.id).name
|
|
return name
|
|
end
|
|
--- Gets the action button binding for the provided spell.
|
|
local function GetBindingForSpell(spell)
|
|
local binding = Mekanome.BindingsManager.GetBindingForSpell(spell)
|
|
if binding == nil then
|
|
error(
|
|
Mekanome.Error(("Unable to cast " .. GetName(spell)) .. " without binding."),
|
|
0
|
|
)
|
|
end
|
|
return binding
|
|
end
|
|
--- Generates a castable to cast the spell on the player
|
|
local function SelfCast(spell)
|
|
local binding = GetBindingForSpell(spell)
|
|
if IsCastable({spell = spell}) == false then
|
|
return nil
|
|
end
|
|
return {id = spell.id, variant = "self", binding = binding}
|
|
end
|
|
--- Generates a castable to cast the spell at the specified target.
|
|
local function TargetCast(spell, _target)
|
|
local binding = GetBindingForSpell(spell)
|
|
local target = type(_target) == "function" and _target(nil) or _target
|
|
if IsCastable({spell = spell, target = target}) == false then
|
|
return nil
|
|
end
|
|
return {id = spell.id, variant = "target", binding = binding, target = target}
|
|
end
|
|
--- Generates a castable to cast the spell at the specified location
|
|
local function GroundCast(spell, _position)
|
|
local binding = GetBindingForSpell(spell)
|
|
local position = type(_position) == "function" and _position(nil) or _position
|
|
if IsCastable({spell = spell, position = position}) == false then
|
|
return nil
|
|
end
|
|
return {id = spell.id, variant = "ground", binding = binding, position = position}
|
|
end
|
|
local _SpellUtils = {
|
|
Create = Create,
|
|
GetName = GetName,
|
|
GetCooldownInfo = GetCooldownInfo,
|
|
SelfCast = SelfCast,
|
|
GroundCast = GroundCast,
|
|
TargetCast = TargetCast
|
|
}
|
|
Mekanome.SpellUtils = _SpellUtils
|
|
____exports.default = {}
|
|
return ____exports
|
|
|