Files
DucielandClaude Opus 5.5 49f3e0aa62 Stealth: rings shrink to the stealth detection range, D-shaped
While stealthed, each ring shows where the mob would detect you (Tortoise
Unit::CanDetectStealthOf): 5 * level stealth (Spell.dbc) plus Master of
Deception / Feral Instinct and an "extra from items" option, 9 yards less
behind the mob, 1.5 yards minimum, edge to edge. The ring is a D that turns
with the mob (needs the ducielperf build with DP_DRingModelPath; older
builds get a circle of the front radius).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 19:03:33 +01:00

484 lines
20 KiB
Lua

-- DucielAggro: a ring on the ground around each nearby hostile mob, at the
-- distance where it would aggro you.
--
-- Server formula (Tortoise core, Creature::GetAttackDistance):
-- radius = 18 - (yourLevel - mobLevel), the difference capped at -25, at least 5 yards
-- world bosses (level ??) count as your level + 3
-- 18 is the default creature detection range: the client never learns a
-- creature's own value, so a few mobs may differ. Line of sight is ignored.
--
-- Needs: ducielperf.dll "models" module (DP_* functions) and SuperWoW (GUIDs as unit tokens).
-- /daggro open the options
-- /daggro toggle on/off
-- /daggro range <n> show rings for mobs within n yards (20-100)
-- /daggro debug why your target has (or has no) ring
-- /daggro reset rebuild every ring
local UPDATE_INTERVAL = 0.15
local COLORS = {
inside = { 1.00, 0.12, 0.08, 0.90 },
close = { 1.00, 0.60, 0.10, 0.75 },
far = { 1.00, 0.95, 0.65, 0.35 },
}
local DEFAULTS = {
enabled = true,
range = 50, -- yards: mobs farther than this get no ring
margin = 5, -- yards outside the radius drawn as "close"
maxRings = 40,
showFar = true, -- faint rings for mobs you are not close to
all = false, -- also mobs already in combat
minimap = true,
minimapAngle = 200,
stealth = true, -- while stealthed, rings show the stealth detection range
stealthExtra = 0, -- stealth from items, added to level and talents
}
local rings = {} -- guid -> { id, path }
local db
local applyOptions -- forward
local function print(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cffff5533DucielAggro|r: " .. msg)
end
local function available()
return DP_SpawnModel and DP_GetNearbyCreatures and DP_AttachModel and UnitPosition ~= nil
end
local function clearAll()
if not DP_RemoveModel then return end
for guid, r in pairs(rings) do
DP_RemoveModel(r.id)
rings[guid] = nil
end
end
local function mobLevelFor(playerLevel, guid)
local mobLevel = UnitLevel(guid)
if not mobLevel or mobLevel <= 0 or UnitClassification(guid) == "worldboss" then
mobLevel = playerLevel + 3
end
return mobLevel
end
local function aggroRadius(playerLevel, guid)
local mobLevel = mobLevelFor(playerLevel, guid)
local diff = playerLevel - mobLevel
if diff < -25 then diff = -25 end
local radius = 18 - diff
if radius < 5 then radius = 5 end
return radius
end
-- --- Stealth ------------------------------------------------------------------------------
-- Tortoise core, Unit::CanDetectStealthOf (creature detecting a player):
-- visible = 5/6 + (5 * mobLevel + mobDetectBonus - stealth) * yardsPerLevel / 5
-- yardsPerLevel = 5/6, doubled when the mob is more than 3 levels above you
-- clamped to 0..30, then 9 yards less when you are outside the 180 degrees in
-- front of the mob; closer than 1.5 yards it always sees you. These distances
-- are edge to edge (both bounding radii), the aggro radius is centre to centre.
-- stealth = 5 * your level (Stealth, Prowl: Spell.dbc, effect value 5 per level)
-- + Master of Deception / Feral Instinct talents + the options' extra value.
-- A mob's own detection bonus is never sent to the client: assumed 0.
local STEALTH_ICONS = { "Ability_Stealth", "Ability_Ambush", "Ability_Vanish" } -- Stealth/Vanish, Prowl/Shadowmeld
local STEALTH_TALENTS = { -- value per rank (Spell.dbc)
["Master of Deception"] = { 3, 6, 9, 12, 15 },
["Feral Instinct"] = { 5, 10, 15, 12, 15 },
}
local talentBonus -- cached, nil = recompute
local function isStealthed()
for i = 1, 32 do
local tex = UnitBuff("player", i)
if not tex then return false end
for _, name in ipairs(STEALTH_ICONS) do
if string.find(tex, name, 1, true) then return true end
end
end
return false
end
local function stealthTalentBonus()
if talentBonus then return talentBonus end
talentBonus = 0
for tab = 1, (GetNumTalentTabs and GetNumTalentTabs() or 0) do
for i = 1, GetNumTalents(tab) do
local name, _, _, _, rank = GetTalentInfo(tab, i)
local values = name and STEALTH_TALENTS[name]
if values and rank and rank > 0 then talentBonus = talentBonus + (values[rank] or 0) end
end
end
return talentBonus
end
local function stealthValue(playerLevel)
return 5 * playerLevel + stealthTalentBonus() + (db.stealthExtra or 0)
end
-- Edge-to-edge detection distance in front of the mob (behind: 9 less).
local function detectRange(playerLevel, mobLevel, stealth)
local perLevel = 5 / 6
if mobLevel - playerLevel > 3 then perLevel = perLevel * 2 end
local v = 5 / 6 + (5 * mobLevel - stealth) * perLevel / 5
if v > 30 then v = 30 elseif v < 0 then v = 0 end
return v
end
local function wanted(guid)
if not UnitExists(guid) or UnitIsDead(guid) or UnitIsPlayer(guid) then return false end
if UnitPlayerControlled(guid) then return false end -- pets, totems, charmed
local reaction = UnitReaction(guid, "player")
if not reaction or reaction > 2 then return false end -- only red (hostile) mobs aggro
if not UnitCanAttack("player", guid) then return false end -- e.g. escorts and caravans you can't hit
if not db.all and UnitAffectingCombat(guid) then return false end
return true
end
-- The ring for one mob: front and back radius (centre to centre, front = the way
-- the mob faces). Not stealthed, or without D rings in the DLL: a circle.
local function ringShape(playerLevel, guid, stealth, playerBR, mobBR)
local radius = aggroRadius(playerLevel, guid)
if not stealth then return radius, radius end
local vis = detectRange(playerLevel, mobLevelFor(playerLevel, guid), stealth)
local br = (playerBR or 0) + (mobBR or 0)
local front = math.max(vis, 1.5) + br
local back = math.max(vis - 9, 1.5) + br
return math.min(radius, front), math.min(radius, back)
end
local function update()
local px, py, pz, _, playerBR = DP_UnitWorldPosition("player")
if not px then return end
local playerLevel = UnitLevel("player")
local dShapes = DP_DRingModelPath ~= nil
local stealth = db.stealth and isStealthed() and stealthValue(playerLevel) or nil
-- Every mob that would get a ring, then the closest maxRings of them.
local candidates = {}
local guids = DP_GetNearbyCreatures(db.range)
for i = 1, table.getn(guids) do
local guid = guids[i]
if wanted(guid) then
local x, y, z, facing, mobBR = DP_UnitWorldPosition(guid)
if x then
local front, back = ringShape(playerLevel, guid, stealth, playerBR, mobBR)
if not dShapes or not facing then back = front end
local dx, dy, dz = x - px, y - py, z - pz
local dist = math.sqrt(dx * dx + dy * dy + dz * dz)
-- Which half of the ring you are in: in front of the mob uses `front`.
local radius = front
if back < front and dx * math.cos(facing) + dy * math.sin(facing) > 0 then
radius = back -- dx points from you to the mob: positive = you are behind it
end
local c
if dist <= radius then
c = COLORS.inside
elseif dist <= radius + db.margin then
c = COLORS.close
elseif db.showFar then
c = COLORS.far
end
if c then
local path
if back < front then
path = DP_DRingModelPath(front, back, c[1], c[2], c[3], c[4])
else
path = DP_RingModelPath(front, c[1], c[2], c[3], c[4])
end
table.insert(candidates, { guid = guid, x = x, y = y, z = z, facing = facing or 0,
edge = dist - radius, path = path })
end
end
end
end
-- Nearest aggro edge first: the mobs most likely to pull come first.
table.sort(candidates, function(a, b) return a.edge < b.edge end)
local n = table.getn(candidates)
if n > db.maxRings then n = db.maxRings end
local keep = {}
for i = 1, n do keep[candidates[i].guid] = candidates[i] end
-- Remove the dropped rings first so their model slots are free.
for guid, r in pairs(rings) do
local k = keep[guid]
if not k or r.path ~= k.path or not DP_ModelExists(r.id) then
DP_RemoveModel(r.id)
rings[guid] = nil
end
end
for guid, k in pairs(keep) do
if not rings[guid] then
local id = DP_SpawnModel(k.path, k.x, k.y, k.z, k.facing)
if id then
DP_AttachModel(id, guid, 0, 1) -- follow the unit and turn with it
rings[guid] = { id = id, path = k.path }
end
end
end
end
local frame = CreateFrame("Frame", "DucielAggroFrame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed < UPDATE_INTERVAL then return end
elapsed = 0
update()
end)
frame:Hide()
local function apply()
if db.enabled and available() then
frame:Show()
else
frame:Hide()
clearAll()
end
if applyOptions then applyOptions() end
end
local function setOption(key, value)
db[key] = value
if key == "minimap" and DucielAggroMinimapButton then
if value then DucielAggroMinimapButton:Show() else DucielAggroMinimapButton:Hide() end
end
if key == "range" or key == "maxRings" or key == "showFar" or key == "all" or key == "margin" then
clearAll() -- rebuilt on the next update with the new settings
end
apply()
end
-- --- Minimap button ---------------------------------------------------------------------
local button = CreateFrame("Button", "DucielAggroMinimapButton", Minimap)
button:SetWidth(31)
button:SetHeight(31)
button:SetFrameStrata("MEDIUM")
button:SetFrameLevel(8)
button:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
button:RegisterForDrag("LeftButton")
local icon = button:CreateTexture(nil, "BACKGROUND")
icon:SetTexture("Interface\\Icons\\Ability_Warrior_Challange")
icon:SetWidth(20)
icon:SetHeight(20)
icon:SetPoint("TOPLEFT", button, "TOPLEFT", 6, -5)
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
local border = button:CreateTexture(nil, "OVERLAY")
border:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
border:SetWidth(53)
border:SetHeight(53)
border:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0)
local function placeButton()
local a = math.rad(db.minimapAngle or DEFAULTS.minimapAngle)
button:ClearAllPoints()
button:SetPoint("CENTER", Minimap, "CENTER", 80 * math.cos(a), 80 * math.sin(a))
end
local function dragUpdate()
local mx, my = Minimap:GetCenter()
local x, y = GetCursorPosition()
local s = Minimap:GetEffectiveScale()
db.minimapAngle = math.mod(math.deg(math.atan2(y / s - my, x / s - mx)) + 360, 360)
placeButton()
end
button:SetScript("OnDragStart", function() this:SetScript("OnUpdate", dragUpdate) end)
button:SetScript("OnDragStop", function() this:SetScript("OnUpdate", nil) end)
button:SetScript("OnClick", function()
if arg1 == "RightButton" then
setOption("enabled", not db.enabled)
print(db.enabled and "on." or "off.")
else
if DucielAggroOptions:IsShown() then DucielAggroOptions:Hide() else DucielAggroOptions:Show() end
end
end)
button:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_LEFT")
GameTooltip:SetText("DucielAggro")
GameTooltip:AddLine(db.enabled and "|cff00ff00On|r" or "|cffff5555Off|r")
GameTooltip:AddLine("Left-click: options", 1, 1, 1)
GameTooltip:AddLine("Right-click: on / off", 1, 1, 1)
GameTooltip:AddLine("Drag: move", 1, 1, 1)
GameTooltip:Show()
end)
button:SetScript("OnLeave", function() GameTooltip:Hide() end)
-- --- Options panel ----------------------------------------------------------------------
local panel = CreateFrame("Frame", "DucielAggroOptions", UIParent)
panel:SetWidth(300)
panel:SetHeight(410)
panel:SetPoint("CENTER", UIParent, "CENTER", 0, 60)
panel:SetFrameStrata("DIALOG")
panel:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true, tileSize = 32, edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 },
})
panel:EnableMouse(true)
panel:SetMovable(true)
panel:RegisterForDrag("LeftButton")
panel:SetScript("OnDragStart", function() this:StartMoving() end)
panel:SetScript("OnDragStop", function() this:StopMovingOrSizing() end)
panel:Hide()
tinsert(UISpecialFrames, "DucielAggroOptions") -- Escape closes it
local title = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOP", panel, "TOP", 0, -18)
title:SetText("DucielAggro")
local close = CreateFrame("Button", "DucielAggroOptionsClose", panel, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -6, -6)
local controls = {}
local function tooltip(widget, text)
widget:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:SetText(text, 1, 1, 1, 1, 1)
GameTooltip:Show()
end)
widget:SetScript("OnLeave", function() GameTooltip:Hide() end)
end
local function checkbox(key, label, help, y)
local name = "DucielAggroOpt_" .. key
local cb = CreateFrame("CheckButton", name, panel, "UICheckButtonTemplate")
cb:SetWidth(26)
cb:SetHeight(26)
cb:SetPoint("TOPLEFT", panel, "TOPLEFT", 20, y)
getglobal(name .. "Text"):SetText(label)
cb:SetScript("OnClick", function() setOption(key, this:GetChecked() and true or false) end)
tooltip(cb, help)
controls[key] = function() cb:SetChecked(db[key]) end
end
local function slider(key, label, help, minV, maxV, step, unit, y)
local name = "DucielAggroOpt_" .. key
local s = CreateFrame("Slider", name, panel, "OptionsSliderTemplate")
s:SetWidth(240)
s:SetHeight(16)
s:SetPoint("TOPLEFT", panel, "TOPLEFT", 30, y)
s:SetMinMaxValues(minV, maxV)
s:SetValueStep(step)
getglobal(name .. "Low"):SetText(minV)
getglobal(name .. "High"):SetText(maxV)
local text = getglobal(name .. "Text")
local updating
s:SetScript("OnValueChanged", function()
local v = math.floor(this:GetValue() / step + 0.5) * step
text:SetText(label .. ": " .. v .. unit)
if not updating and v ~= db[key] then setOption(key, v) end
end)
tooltip(s, help)
controls[key] = function()
updating = true
s:SetValue(db[key])
text:SetText(label .. ": " .. db[key] .. unit)
updating = nil
end
end
checkbox("enabled", "Show aggro rings", "Draw a ring around each nearby hostile mob at its aggro radius.", -48)
checkbox("showFar", "Show faint rings for far mobs",
"Off: only mobs you are close to (orange) or inside the radius of (red) get a ring.", -76)
checkbox("all", "Include mobs already in combat",
"Mobs fighting you or someone else no longer aggro by proximity, so they are hidden by default.", -104)
checkbox("minimap", "Minimap button", "Show this addon's minimap button. /daggro opens these options.", -132)
checkbox("stealth", "Stealth: show detection range",
"While stealthed, rings shrink to where the mob would see you: a D shape, smaller behind the mob.", -160)
slider("range", "Show rings within", "Mobs farther away than this get no ring.", 20, 100, 5, " yd", -208)
slider("margin", "Orange warning margin",
"A mob's ring turns orange when you are within this many yards outside its aggro radius.", 0, 15, 1, " yd", -258)
slider("maxRings", "Maximum rings", "Most rings drawn at once (the closest mobs first).", 5, 60, 5, "", -308)
slider("stealthExtra", "Extra stealth from items", "Stealth bonuses from gear or enchants (talents are counted already).", 0, 20, 1, "", -358)
-- Only refreshes the panel: the minimap button is placed once at login and
-- when dragged, so a button collector (e.g. pfUI's addon button panel) keeps it.
applyOptions = function()
for _, refresh in pairs(controls) do refresh() end
end
local function showButton()
if db.minimap then button:Show() else button:Hide() end
end
-- --- Events and slash command ---------------------------------------------------------------
frame:RegisterEvent("VARIABLES_LOADED")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("CHARACTER_POINTS_CHANGED")
frame:SetScript("OnEvent", function()
if event == "VARIABLES_LOADED" then
DucielAggroDB = DucielAggroDB or {}
db = DucielAggroDB
for k, v in pairs(DEFAULTS) do
if db[k] == nil then db[k] = v end
end
if not available() then
print("disabled: needs ducielperf.dll with the \"models\" module, and SuperWoW.")
end
placeButton()
showButton()
apply()
elseif event == "PLAYER_ENTERING_WORLD" then
if db then clearAll() end -- models are per map; start fresh
talentBonus = nil
elseif event == "CHARACTER_POINTS_CHANGED" then
talentBonus = nil
end
end)
SLASH_DUCIELAGGRO1 = "/daggro"
SlashCmdList["DUCIELAGGRO"] = function(msg)
if not db then return end
local _, _, cmd, val = string.find(msg or "", "^%s*(%a*)%s*(%d*)")
if cmd == "range" and tonumber(val) then
local n = tonumber(val)
if n < 20 then n = 20 elseif n > 100 then n = 100 end
setOption("range", n)
print("range " .. n .. " yards.")
elseif cmd == "debug" then
local yn = function(v) return v and "yes" or "no" end
print("enabled " .. yn(db.enabled) .. ", DLL/SuperWoW found " .. yn(available()) ..
", update running " .. yn(frame:IsShown()) .. ", range " .. db.range .. ", rings drawn " ..
(function() local n = 0 for _ in pairs(rings) do n = n + 1 end return n end)())
local _, guid = UnitExists("target")
if not guid then print("target a mob for details.") return end
local listed = false
local guids = DP_GetNearbyCreatures and DP_GetNearbyCreatures(db.range) or {}
for i = 1, table.getn(guids) do
if string.upper(guids[i]) == string.upper(guid) then listed = true end
end
local px, py, pz = DP_UnitWorldPosition("player")
local x, y, z = DP_UnitWorldPosition(guid)
local dist = (px and x) and math.sqrt((x-px)*(x-px) + (y-py)*(y-py) + (z-pz)*(z-pz)) or nil
print("target " .. guid .. ": in nearby list " .. yn(listed) .. " (" .. table.getn(guids) .. " creatures)" ..
", position " .. (x and string.format("%.1f %.1f %.1f", x, y, z) or "none") ..
", distance " .. (dist and string.format("%.1f", dist) or "?"))
print("reaction " .. tostring(UnitReaction(guid, "player")) .. " (needs 1-2), in combat " ..
yn(UnitAffectingCombat(guid)) .. ", player-controlled " .. yn(UnitPlayerControlled(guid)) .. ", attackable " .. yn(UnitCanAttack("player", guid)) ..
", dead " .. yn(UnitIsDead(guid)) .. ", level " .. tostring(UnitLevel(guid)) ..
", radius " .. aggroRadius(UnitLevel("player"), guid) .. ", passes filters " .. yn(wanted(guid)))
local r = rings[guid] or rings[string.upper(guid)]
local lvl = UnitLevel("player")
local st = isStealthed()
local _, _, _, _, pbr = DP_UnitWorldPosition("player")
local _, _, _, mfacing, mbr = DP_UnitWorldPosition(guid)
local f, b = ringShape(lvl, guid, st and stealthValue(lvl), pbr, mbr)
print("stealthed " .. yn(st) .. ", stealth " .. stealthValue(lvl) .. " (talents " .. stealthTalentBonus() .. "), ring front " .. string.format("%.1f", f) .. " back " .. string.format("%.1f", b) .. ", D rings in DLL " .. yn(DP_DRingModelPath))
print("ring: " .. (r and ("model " .. r.id .. " exists " .. yn(DP_ModelExists(r.id)) .. ", " .. r.path) or "none"))
elseif cmd == "reset" then
clearAll()
if DP_RemoveAllModels then DP_RemoveAllModels() end
print("rings rebuilt.")
elseif cmd == "toggle" then
setOption("enabled", not db.enabled)
print(db.enabled and "on." or "off.")
else
DucielAggroOptions:Show()
end
end