Skip to content

Commit

Permalink
Dark magic: scan for zone-custom mobs
Browse files Browse the repository at this point in the history
  • Loading branch information
kemayo committed Aug 15, 2024
1 parent 23f12dc commit d0f62ca
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
33 changes: 32 additions & 1 deletion core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,37 @@ function addon:SetCustom(uiMapID, id, watch, quiet)
return true
end

do
local empty = {}
local function mobsForZone(uiMapID, suppressAnyZone)
local mobs = ns.mobsByZone[uiMapID] or empty
for id, coords in pairs(mobs) do
coroutine.yield(id, #coords > 0)
end
if globaldb.custom[uiMapID] then
for id in pairs(globaldb.custom[uiMapID]) do
if not mobs[id] then
coroutine.yield(id, false)
end
end
end
if not suppressAnyZone then
for id in pairs(globaldb.custom.any) do
if not mobs[id] then
coroutine.yield(id, false)
end
end
end
end
-- Get mobs that're relevant to the a given map; this means known rares, custom mobs for that map, and custom mobs for all maps
-- iterator returns: id, hasCoords
function addon:IterateRelevantMobs(uiMapID, suppressAnyZone)
return coroutine.wrap(function()
return mobsForZone(uiMapID, suppressAnyZone)
end)
end
end

-- returns name, vignette, tameable, last_seen, times_seen
function addon:GetMobInfo(id)
if mobdb[id] then
Expand Down Expand Up @@ -435,7 +466,7 @@ do
end
function addon:IsMobInPhase(id, zone)
local phased, poi = true, true
if not mobdb[id] then return end
if not mobdb[id] then return true end
if mobdb[id].art then
phased = mobdb[id].art == C_Map.GetMapArtID(zone)
end
Expand Down
13 changes: 9 additions & 4 deletions scan/darkmagic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,23 @@ function module:Update()
if not core.db.profile.instances and IsInInstance() then
return self.timer and self.timer:Cancel()
end
-- build a cached table of mobs

local zone = HBD:GetPlayerZone()
local mobs = zone and ns.mobsByZone[zone]
if not mobs then
local hasMobs = false
-- Mobs from data, and custom mobs specific to the zone
for _ in core:IterateRelevantMobs(zone, true) do
hasMobs = true
break
end
if not hasMobs then
-- Moving into a different zone that has mobs will have us try again
return
end
-- The name we use here is what's going to be passed as the event arg
-- later, so wrap gives us something more identifiable than just
-- coroutine.resume...
local SDTargetUnitWasForbidden = coroutine.wrap(function()
for id in pairs(mobs) do
for id in core:IterateRelevantMobs(zone, true) do
local name = core:NameForMob(id)
local attempted
if
Expand Down

0 comments on commit d0f62ca

Please sign in to comment.