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.
517 lines
18 KiB
517 lines
18 KiB
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
-- Lua Library inline imports
|
|
local function __TS__ArrayIncludes(self, searchElement, fromIndex)
|
|
if fromIndex == nil then
|
|
fromIndex = 0
|
|
end
|
|
local len = #self
|
|
local k = fromIndex
|
|
if fromIndex < 0 then
|
|
k = len + fromIndex
|
|
end
|
|
if k < 0 then
|
|
k = 0
|
|
end
|
|
for i = k + 1, len do
|
|
if self[i] == searchElement then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
-- End of Lua Library inline imports
|
|
local ____exports = {}
|
|
local ____, _Mekanome = ...
|
|
local Mekanome = _Mekanome
|
|
--- Check whether or not the mob is a valid wow mob.
|
|
local function IsValid(mob)
|
|
return mob.token ~= "none" and mob.token ~= nil and Mekanome.GetObject(mob.token) ~= false
|
|
end
|
|
--- Get whether or not the mob is alive.
|
|
local function IsAlive(mob)
|
|
return UnitIsDeadOrGhost(mob.token) == false
|
|
end
|
|
--- Get whether or not the mob is a pet.
|
|
local function IsPet(mob)
|
|
return UnitIsUnit(mob.token, "pet")
|
|
end
|
|
--- Get whether or not the player can attack this mob.
|
|
local function CanAttack(mob)
|
|
local token = mob.token
|
|
local isFriend = UnitIsFriend("player", token)
|
|
if isFriend then
|
|
return false
|
|
end
|
|
local isAttackable = UnitCanAttack("player", token)
|
|
if isAttackable == false then
|
|
return false
|
|
end
|
|
local reaction = UnitReaction("player", token)
|
|
if reaction == nil then
|
|
return false
|
|
else
|
|
local isPositiveReaction = reaction >= 5
|
|
if isPositiveReaction then
|
|
return false
|
|
end
|
|
end
|
|
return true
|
|
end
|
|
--- Get the name of the mob.
|
|
local function GetName(mob)
|
|
local unitName = UnitName(mob.token)
|
|
return unitName
|
|
end
|
|
--- Get the health of the mob.
|
|
local function GetHealth(mob)
|
|
local token = mob.token
|
|
local absorbAmount = UnitGetTotalHealAbsorbs(token)
|
|
local health = UnitHealth(token, false) - absorbAmount
|
|
return health
|
|
end
|
|
--- Get the mobs current health expressed as a percentage of their max health.
|
|
local function GetHealthPercent(mob)
|
|
local health = GetHealth(mob)
|
|
local maxHealth = UnitHealthMax(mob.token)
|
|
return health / maxHealth * 100
|
|
end
|
|
--- Get the mobs default powertype, eg 1 for Rage.
|
|
local function GetPowerType(mob)
|
|
local powerType = UnitPowerType(mob.token, 0)
|
|
return powerType
|
|
end
|
|
--- Get the mobs maximum power of their default power type, or a specified one.
|
|
local function GetMaxPower(mob, powerType)
|
|
local maxPower = UnitPowerMax(
|
|
mob.token,
|
|
powerType or GetPowerType(mob),
|
|
false
|
|
)
|
|
return maxPower
|
|
end
|
|
--- Get the current value for the mobs default powertype, or a specified one.
|
|
local function GetCurrentPower(mob, powerType)
|
|
local power = UnitPower(
|
|
mob.token,
|
|
powerType or GetPowerType(mob),
|
|
false
|
|
)
|
|
return power
|
|
end
|
|
--- Get the current value for the mobs default powertype, or a specified one, expressed as a percentage of the max for that powertype.
|
|
local function GetPowerPercent(mob, powerType)
|
|
local power = GetCurrentPower(mob, powerType)
|
|
local maxPower = GetMaxPower(mob, powerType)
|
|
return power / maxPower * 100
|
|
end
|
|
--- Gets the group role of the mob if it exists.
|
|
local function GetRole(mob)
|
|
return UnitGroupRolesAssigned(mob.token)
|
|
end
|
|
--- Check whether or not the mob is in combat according to the wow api.
|
|
local function IsAffectingCombat(mob)
|
|
return UnitAffectingCombat(mob.token)
|
|
end
|
|
--- Returns the Vector3 coords of the mob.
|
|
local function GetPosition(mob)
|
|
local x, y, z = ObjectPosition(mob.token)
|
|
return Mekanome.VectorUtils.Create({x = x, y = y, z = z})
|
|
end
|
|
--- Returns distance between two mobs.
|
|
local function GetDistanceBetween(referenceMob, compareMob)
|
|
return Mekanome.VectorUtils.Distance(
|
|
GetPosition(referenceMob),
|
|
GetPosition(compareMob)
|
|
)
|
|
end
|
|
--- Get whether or not a mob can see another mob un-obstructed.
|
|
local function CanSee(reference, compare)
|
|
local ax, ay, az = ObjectPosition(reference.token)
|
|
local ah = ObjectHeight(reference.token)
|
|
local attx, atty, attz = GetUnitAttachmentPosition(compare.token, 34)
|
|
if attx == nil or ax == nil or ah == nil then
|
|
return false
|
|
end
|
|
if ax == 0 and ay == 0 and az == 0 or attx == 0 and atty == 0 and attz == 0 then
|
|
return true
|
|
end
|
|
local x, y, z = TraceLine(
|
|
ax,
|
|
ay,
|
|
az + ah,
|
|
attx,
|
|
atty,
|
|
attz,
|
|
0
|
|
)
|
|
if x ~= 0 or y ~= 0 or z ~= 0 then
|
|
return false
|
|
else
|
|
return true
|
|
end
|
|
end
|
|
--- Returns whether or not a mob is casting a spell
|
|
local function IsCasting(mob)
|
|
return ({UnitCastingInfo(mob.token)}) ~= nil
|
|
end
|
|
--- Returns whether or not a mob is channeling a spell
|
|
local function IsChanneling(mob)
|
|
return ({UnitChannelInfo(mob.token)}) ~= nil
|
|
end
|
|
--- Returns whether or not a mob is channeling or casting a spell
|
|
local function IsCastingOrChanneling(mob)
|
|
return IsChanneling(mob) or IsCasting(mob)
|
|
end
|
|
local function GetEndTime(startMs, endMs, percent)
|
|
local castLength = endMs - startMs
|
|
local startTime = startMs / 1000
|
|
local timeUntil = castLength / 1000 * ((percent or 100) / 100)
|
|
return startTime + timeUntil
|
|
end
|
|
--- If a mob is casting a spell, return the time when it will end.
|
|
--
|
|
-- @param percent : By default the cast end time is when the cast is complete. If you want to consider
|
|
-- a spell as being done once it reaches a certain percentage threshold, pass in this value.
|
|
local function GetCastEndTime(mob, percent)
|
|
local castingInfo = {UnitCastingInfo(mob.token)}
|
|
if castingInfo ~= nil then
|
|
local name = castingInfo[1]
|
|
local startTimeMS = castingInfo[4]
|
|
local endTimeMs = castingInfo[5]
|
|
if name ~= nil and startTimeMS ~= nil and endTimeMs ~= nil then
|
|
return GetEndTime(startTimeMS, endTimeMs, percent)
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
--- If a mob is channeling a spell, return the time when it will end.
|
|
--
|
|
-- @param percent : By default the cast end time is when the channel ends. If you want to consider
|
|
-- a spell as being done once it reaches a certain percentage threshold, pass in this value.
|
|
local function GetChannelEndTime(mob, percent)
|
|
local channelInfo = {UnitChannelInfo(mob.token)}
|
|
if channelInfo ~= nil then
|
|
local name = channelInfo[1]
|
|
local startTimeMS = channelInfo[4]
|
|
local endTimeMs = channelInfo[5]
|
|
if name ~= nil and startTimeMS ~= nil and endTimeMs ~= nil then
|
|
return GetEndTime(startTimeMS, endTimeMs, percent)
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
local function GetCastOrChannelEndTime(mob, percent)
|
|
return GetCastEndTime(mob, percent) or GetChannelEndTime(mob, percent)
|
|
end
|
|
--- If the mob is casting or channeling a spell, this returns the target mob of said spell.
|
|
local function GetCastTarget(mob)
|
|
local isMobCasting = IsCastingOrChanneling(mob)
|
|
if isMobCasting then
|
|
local target = ObjectCastingTarget(mob.token)
|
|
if target ~= false then
|
|
local targetMob = Mekanome.MobManager.GetMob({guid = target:guid()})
|
|
return targetMob or Mekanome.MobManager.GetMob({token = "none"})
|
|
else
|
|
return Mekanome.MobManager.GetMob({token = "none"})
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
--- If the mob is casting or channeling a spell, this returns how far into the cast the mob is, as a percentage.
|
|
local function GetCastOrChannelPercentComplete(mob)
|
|
local name = nil
|
|
local startTimeMS = nil
|
|
local endTimeMs = nil
|
|
local castingInfo = {UnitCastingInfo(mob.token)}
|
|
if castingInfo == nil then
|
|
local channelInfo = {UnitChannelInfo(mob.token)}
|
|
if channelInfo ~= nil then
|
|
name = channelInfo[1]
|
|
startTimeMS = channelInfo[4]
|
|
endTimeMs = channelInfo[5]
|
|
end
|
|
else
|
|
name = castingInfo[1]
|
|
startTimeMS = castingInfo[4]
|
|
endTimeMs = castingInfo[5]
|
|
end
|
|
if name ~= nil and startTimeMS ~= nil and endTimeMs ~= nil then
|
|
local start = startTimeMS / 1000
|
|
local finish = endTimeMs / 1000
|
|
local current = GetTime()
|
|
return (current - start) / (finish - start) * 100
|
|
end
|
|
return nil
|
|
end
|
|
--- If the mob is casting or channeling a spell, returns whether or not that spell is interruptible.
|
|
local function GetIsInterruptible(mob)
|
|
local name = nil
|
|
local notInterruptible = nil
|
|
local castingInfo = {UnitCastingInfo(mob.token)}
|
|
if castingInfo == nil then
|
|
local channelInfo = {UnitChannelInfo(mob.token)}
|
|
if channelInfo ~= nil then
|
|
name = channelInfo[1]
|
|
notInterruptible = channelInfo[7]
|
|
end
|
|
else
|
|
name = castingInfo[1]
|
|
notInterruptible = castingInfo[8]
|
|
end
|
|
if name ~= nil and notInterruptible ~= nil then
|
|
return notInterruptible == false
|
|
end
|
|
return false
|
|
end
|
|
--- Returns whether or not a mob is interruptible at a specific percentage of their cast.
|
|
--
|
|
-- @param interruptPercent The percent to check against.
|
|
-- @param ignoreInterruptible By default this will return false if the active spell is not interruptible. This bypasses that check.
|
|
local function GetIsInterruptibleAt(mob, interruptPercent, ignoreInterruptible)
|
|
if not ignoreInterruptible and GetIsInterruptible(mob) == false then
|
|
return false
|
|
end
|
|
local castPercent = GetCastOrChannelPercentComplete(mob)
|
|
if castPercent and castPercent >= interruptPercent then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
--- Gets whether or not the mob is moving.
|
|
local function GetIsMoving(mob)
|
|
local currentSpeed = GetUnitSpeed(mob.token)
|
|
return currentSpeed > 0
|
|
end
|
|
--- Checks if a mob is facing another using their current positions.
|
|
local function IsFacingMob(reference, compare)
|
|
local rotation = ObjectRotation(reference.token)
|
|
local x, y = ObjectPosition(reference.token)
|
|
local x2, y2 = ObjectPosition(compare.token)
|
|
if not x or not x2 or not rotation then
|
|
return false
|
|
end
|
|
local angle = math.atan2(y2 - y, x2 - x) - rotation
|
|
angle = math.deg(angle)
|
|
angle = angle % 360
|
|
if angle > 180 then
|
|
angle = angle - 360
|
|
end
|
|
return math.abs(angle) < 90
|
|
end
|
|
--- Checks if a mob is behind another using their current positions.
|
|
local function IsBehindMob(reference, compare)
|
|
local rotation = ObjectRotation(reference.token)
|
|
local x, y = ObjectPosition(reference.token)
|
|
local x2, y2 = ObjectPosition(compare.token)
|
|
if not x or not x2 or not rotation then
|
|
return false
|
|
end
|
|
local angle = math.atan2(y2 - y, x2 - x) - rotation
|
|
angle = math.deg(angle)
|
|
angle = angle % 360
|
|
if angle > 180 then
|
|
angle = angle - 360
|
|
end
|
|
return math.abs(angle) > 90
|
|
end
|
|
--- Gets the model ID for the mob.
|
|
local function GetModelId(mob)
|
|
return ObjectModelId(mob.token)
|
|
end
|
|
--- Returns whether or not the mob is in a party with the player.
|
|
local function IsInParty(mob)
|
|
return UnitInParty(mob.token, nil)
|
|
end
|
|
--- Returns whether or not the mob is in a raid with the player.
|
|
local function IsInRaid(mob)
|
|
return UnitInRaid(mob.token, nil) ~= nil
|
|
end
|
|
--- Returns whether or not the mob is in a party or raid with the player.
|
|
local function IsInPartyOrRaid(mob)
|
|
return IsInParty(mob) or IsInRaid(mob)
|
|
end
|
|
--- Returns whether or not the player is mounted, or shapeshifted into a mount form.
|
|
local function IsMounted(mob)
|
|
local isMounted = UnitIsMounted(mob.token)
|
|
if isMounted then
|
|
return true
|
|
end
|
|
local mountFormIds = {3, 27, 29}
|
|
local shapeShiftId = GetShapeshiftFormID()
|
|
return shapeShiftId ~= nil and __TS__ArrayIncludes(mountFormIds, shapeShiftId)
|
|
end
|
|
--- Returns the "Combat reach" of a mob. The combat reach of a mob is a bounding radius from which distance calcs begin for the purposes of calculating combat distance.
|
|
local function GetCombatReach(mob)
|
|
return ObjectCombatReach(mob.token) or 0
|
|
end
|
|
--- Returns the distance between two mobs, with combat reach accounted for.
|
|
local function GetCombatDistanceBetween(reference, compare)
|
|
local ____ = GetDistanceBetween(reference, compare) - GetCombatReach(compare)
|
|
end
|
|
--- Gets whether or not the mob is currently online.
|
|
local function GetIsOnline(mob)
|
|
return UnitIsConnected(mob.token)
|
|
end
|
|
--- Get whether or not the mob is being resurrected.
|
|
local function HasIncomingRessurection(mob)
|
|
return IsAlive(mob) == false and UnitHasIncomingResurrection(mob.token)
|
|
end
|
|
--- Get whether or not the mob is currently targetting something.
|
|
local function HasTarget(mob)
|
|
return ObjectTarget(mob.token) ~= nil
|
|
end
|
|
--- Get the mobs current target.
|
|
local function GetTarget(mob)
|
|
local objTarget = ObjectTarget(mob.token)
|
|
if not objTarget then
|
|
return nil
|
|
end
|
|
local mobManagerMob = Mekanome.MobManager.GetMob({token = objTarget:unit()})
|
|
return mobManagerMob
|
|
end
|
|
--- Returns whether or not a mob is within a certain distance from another mob, with combat reach accounted for.
|
|
local function IsWithinCombatDistance(reference, compare, distance)
|
|
if not IsValid(compare) then
|
|
return false
|
|
end
|
|
return GetDistanceBetween(reference, compare) <= distance + GetCombatReach(compare)
|
|
end
|
|
--- Returns whether or not a mob is within a certain distance from another mob.
|
|
local function IsWithinDistance(reference, compare, distance)
|
|
return GetDistanceBetween(reference, compare) <= distance
|
|
end
|
|
--- Returns the number of loss of control effects on the mob. Interrupt lockouts included.
|
|
local function GetLossOfControlCount(mob)
|
|
return C_LossOfControl.GetActiveLossOfControlDataCountByUnit(mob.token)
|
|
end
|
|
--- Returns the mobs outgoing missiles.
|
|
local function GetOutgoingMissles(self, ____bindingPattern0)
|
|
local spellVisualId
|
|
local spellId
|
|
local target
|
|
local reference
|
|
reference = ____bindingPattern0.reference
|
|
target = ____bindingPattern0.target
|
|
spellId = ____bindingPattern0.spellId
|
|
spellVisualId = ____bindingPattern0.spellVisualId
|
|
local missiles = Missiles()
|
|
local results = {}
|
|
if type(missiles) == "table" and IsValid(reference) then
|
|
for ____, missile in pairs(missiles) do
|
|
local ____opt_0 = missile.source
|
|
local missileSource = ____opt_0 and ____opt_0:unit()
|
|
if missileSource then
|
|
local ____UnitIsUnit_result_6 = UnitIsUnit(reference.token, missileSource)
|
|
if ____UnitIsUnit_result_6 then
|
|
local ____temp_5 = not target
|
|
if not ____temp_5 then
|
|
local ____UnitIsUnit_4 = UnitIsUnit
|
|
local ____opt_2 = missile.target
|
|
____temp_5 = ____UnitIsUnit_4(
|
|
____opt_2 and ____opt_2:unit() or "none",
|
|
target.token
|
|
)
|
|
end
|
|
____UnitIsUnit_result_6 = ____temp_5
|
|
end
|
|
if ____UnitIsUnit_result_6 and (not spellId or not not spellId and spellId == missile.spellId) and (not spellVisualId or not not spellVisualId and spellVisualId == missile.spellVisualId) then
|
|
results[#results + 1] = missile
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return results
|
|
end
|
|
--- Returns the mobs incoming missiles.
|
|
local function GetIncomingMissiles(____bindingPattern0)
|
|
local spellVisualId
|
|
local spellId
|
|
local source
|
|
local reference
|
|
reference = ____bindingPattern0.reference
|
|
source = ____bindingPattern0.source
|
|
spellId = ____bindingPattern0.spellId
|
|
spellVisualId = ____bindingPattern0.spellVisualId
|
|
local missiles = Missiles()
|
|
local results = {}
|
|
if type(missiles) == "table" and IsValid(reference) then
|
|
for ____, missile in pairs(missiles) do
|
|
local ____opt_7 = missile.target
|
|
local missileTarget = ____opt_7 and ____opt_7:unit()
|
|
if missileTarget and UnitIsUnit(reference.token, missileTarget) and (not source or UnitIsUnit(source.token or "none", reference.token)) and (not spellId or spellId == missile.spellId) and (not spellVisualId or spellVisualId == missile.spellVisualId) then
|
|
table.insert(results, missile)
|
|
end
|
|
end
|
|
end
|
|
return results
|
|
end
|
|
--- Gets the amount of time the mob has been in combat.
|
|
local function GetCombatTime(mob)
|
|
if not mob.lastCombatTime then
|
|
return nil
|
|
end
|
|
return GetTime() - mob.lastCombatTime
|
|
end
|
|
--- Get combat odds (if the last combat time is less than 1 minute ago return 1 / time, else return 0)
|
|
-- the closer to 0 the more likely the unit is to be in combat (0 = 100%) 60 = 0%
|
|
--
|
|
-- @param mob The mob to check
|
|
-- @returns number | undefined
|
|
local function InCombatOdds(mob)
|
|
local combatTime = GetCombatTime(mob)
|
|
if combatTime == nil then
|
|
return nil
|
|
end
|
|
local percent = 1 - combatTime / 60
|
|
return percent * 100
|
|
end
|
|
local _MobUtils = {
|
|
GetLossOfControlCount = GetLossOfControlCount,
|
|
GetTarget = GetTarget,
|
|
IsWithinCombatDistance = IsWithinCombatDistance,
|
|
IsWithinDistance = IsWithinDistance,
|
|
GetOutgoingMissles = GetOutgoingMissles,
|
|
GetIncomingMissiles = GetIncomingMissiles,
|
|
HasTarget = HasTarget,
|
|
HasIncomingRessurection = HasIncomingRessurection,
|
|
GetCombatDistanceBetween = GetCombatDistanceBetween,
|
|
GetCombatReach = GetCombatReach,
|
|
IsInPartyOrRaid = IsInPartyOrRaid,
|
|
IsMounted = IsMounted,
|
|
GetModelId = GetModelId,
|
|
IsInRaid = IsInRaid,
|
|
IsInParty = IsInParty,
|
|
IsBehindMob = IsBehindMob,
|
|
GetIsOnline = GetIsOnline,
|
|
IsFacingMob = IsFacingMob,
|
|
GetIsMoving = GetIsMoving,
|
|
GetIsInterruptible = GetIsInterruptible,
|
|
GetCastOrChannelPercentComplete = GetCastOrChannelPercentComplete,
|
|
IsCasting = IsCasting,
|
|
GetCastOrChannelEndTime = GetCastOrChannelEndTime,
|
|
IsChanneling = IsChanneling,
|
|
GetIsInterruptibleAt = GetIsInterruptibleAt,
|
|
IsCastingOrChanneling = IsCastingOrChanneling,
|
|
IsAffectingCombat = IsAffectingCombat,
|
|
GetPowerType = GetPowerType,
|
|
CanSee = CanSee,
|
|
GetMaxPower = GetMaxPower,
|
|
GetCurrentPower = GetCurrentPower,
|
|
GetPowerPercent = GetPowerPercent,
|
|
GetCastTarget = GetCastTarget,
|
|
InCombatOdds = InCombatOdds,
|
|
GetName = GetName,
|
|
CanAttack = CanAttack,
|
|
GetHealthPercent = GetHealthPercent,
|
|
IsAlive = IsAlive,
|
|
GetPosition = GetPosition,
|
|
GetDistanceBetween = GetDistanceBetween,
|
|
IsPet = IsPet,
|
|
GetRole = GetRole,
|
|
GetCombatTime = GetCombatTime,
|
|
GetChannelEndTime = GetChannelEndTime,
|
|
GetCastEndTime = GetCastEndTime
|
|
}
|
|
Mekanome.MobUtils = _MobUtils
|
|
____exports.default = {}
|
|
return ____exports
|
|
|