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.
 
 
 
Mekanome/dist/managers/mob-manager.lua

233 lines
6.6 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
local function __TS__ArrayIsArray(value)
return type(value) == "table" and (value[1] ~= nil or next(value) == nil)
end
local function __TS__ArrayConcat(self, ...)
local items = {...}
local result = {}
local len = 0
for i = 1, #self do
len = len + 1
result[len] = self[i]
end
for i = 1, #items do
local item = items[i]
if __TS__ArrayIsArray(item) then
for j = 1, #item do
len = len + 1
result[len] = item[j]
end
else
len = len + 1
result[len] = item
end
end
return result
end
local function __TS__ObjectAssign(target, ...)
local sources = {...}
for i = 1, #sources do
local source = sources[i]
for key in pairs(source) do
target[key] = source[key]
end
end
return target
end
-- End of Lua Library inline imports
local ____exports = {}
local CreateMobFromObject, GetMob, Mekanome, DUMMYS, mobs
function CreateMobFromObject(mobObject)
local ____type = "unknown"
local id = mobObject:id()
local unit = mobObject:unit()
if UnitIsFriend("player", unit) or UnitInParty(unit, nil) or UnitInRaid(unit, nil) then
____type = "friend"
end
if UnitCanAttack("player", unit) or type(id) == "number" and __TS__ArrayIncludes(DUMMYS, id) then
____type = "enemy"
end
return {
type = ____type,
token = mobObject:unit(),
guid = mobObject:guid(),
id = mobObject:id(),
auras = Mekanome.AuraManager.New(mobObject:unit())
}
end
function GetMob(____bindingPattern0)
local guid
local token
token = ____bindingPattern0.token
guid = ____bindingPattern0.guid
local id = nil
if guid then
id = guid
elseif token then
id = token == "none" and token or ObjectGUID(token)
end
if id == nil then
return nil
end
if mobs[id] ~= nil == false then
local gameObject = Object(id)
if gameObject ~= false then
mobs[id] = CreateMobFromObject(gameObject)
end
end
return mobs[id]
end
local _, _Mekanome = ...
Mekanome = _Mekanome
local isInitialized = false
local CREATURE_TYPES_TO_IGNORE = {8, 12, 13, 14}
DUMMYS = {
31146,
31144,
32666,
32667,
46647,
114832,
153285,
153292,
198594,
194648,
189632,
194643,
194644,
197833,
189617,
194649,
193563,
65310,
66374,
196394,
196406,
199057
}
mobs = {}
local function GetMobFromObject(mobObject)
return mobs[mobObject:guid()]
end
--- Updates the time in which a mob was last in combat.
--
-- @param guid The GUID of the mob to update.
local function UpdateCombatTime(guid)
local mob = GetMob({guid = guid})
if mob and mob.type == "enemy" then
mob.lastCombatTime = GetTime()
mobs[guid] = mob
end
end
--- Refreshes the list of mobs.
local function Refresh()
local touchedMobs = {}
local unitObjects = Objects(5)
local playerObjects = Objects(6)
local activePlayerObject = Objects(7)
local objects = __TS__ArrayConcat(
__TS__ArrayConcat(unitObjects, playerObjects),
activePlayerObject
)
for ____, gameObject in ipairs(objects) do
local objectType = ObjectCreatureType(gameObject)
if __TS__ArrayIncludes(CREATURE_TYPES_TO_IGNORE, objectType) == false then
local existingMob = GetMobFromObject(gameObject)
local mob = CreateMobFromObject(gameObject)
touchedMobs[#touchedMobs + 1] = mob.guid
if existingMob == nil then
mobs[mob.guid] = mob
else
local isStale = existingMob.id ~= mob.id or existingMob.token ~= mob.token
if isStale then
mobs[existingMob.guid] = __TS__ObjectAssign({}, existingMob, {id = mob.id, token = mob.token})
end
end
end
end
for guid, _ in pairs(mobs) do
if __TS__ArrayIncludes(touchedMobs, guid) == false then
mobs[guid] = nil
end
end
end
--- Iterates over the mob list, and calls a function for each mob.
--
-- @param callback Function called for each mob in the list.
-- @param type The type of mobs to iterate over. "enemies_active" iterates over enemies that are in combat.
local function Iterate(callback, ____type)
for _, mob in pairs(mobs) do
if ____type ~= nil then
if ____type == "enemies_active" then
local combatOdds = Mekanome.MobUtils.InCombatOdds(mob)
if combatOdds ~= nil and combatOdds < 0.4 then
callback(nil, mob)
end
elseif mob.type == ____type then
callback(nil, mob)
end
else
callback(nil, mob)
end
end
end
--- Initializes the mob manager.
local function Init()
if isInitialized == false then
Mekanome.EventManager.RegisterEventHandler(
"COMBAT_LOG_EVENT_UNFILTERED",
function()
if Mekanome.enabled then
local ____, ____, ____, source, ____, ____, ____, dest = CombatLogGetCurrentEventInfo()
UpdateCombatTime(source)
UpdateCombatTime(dest)
end
end,
"mm_combat_log_event_unfiltered"
)
Mekanome.EventManager.RegisterEventHandler(
"UNIT_AURA",
function(____, ____bindingPattern0)
local auraInfo
local token
token = ____bindingPattern0[1]
auraInfo = ____bindingPattern0[2]
local mob = GetMob({token = token})
if mob then
local updatedAuras = Mekanome.AuraManager.GetUpdatedAuras(auraInfo, mob)
mob.auras = updatedAuras
mobs[mob.guid] = mob
end
end,
"mm_unit_aura"
)
isInitialized = true
end
end
local _MobManager = {Iterate = Iterate, Refresh = Refresh, GetMob = GetMob, Init = Init}
Mekanome.MobManager = _MobManager
____exports.default = {}
return ____exports