Fix up the log messages a lil

Unbutcher inviter
This commit is contained in:
2025-01-08 17:11:07 +01:00
parent fca49c6302
commit d3004019c6
15 changed files with 647 additions and 305 deletions

View File

@@ -29,34 +29,46 @@ function shared.Spotter.Init()
---@return string? error
local function ShouldNotify(unit, name, faction, hostile)
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: ShouldNotify", ModuleName))
shared.dumpTable(Heimdall_Data.config.spotter)
print(string.format("[%s] Checking notification criteria for %s (%s)", ModuleName, name, faction))
end
if Heimdall_Data.config.agents[name] then return false end
if Heimdall_Data.config.agents[name] then
if Heimdall_Data.config.spotter.debug then
print(string.format("[%s] Skipping agent: %s", ModuleName, name))
end
return false
end
if Heimdall_Data.config.spotter.stinky then
if Heimdall_Data.config.stinkies[name] then
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: Stinky found in config", ModuleName))
print(string.format("[%s] Notifying - Found stinky: %s", ModuleName, name))
end
return true
end
end
if Heimdall_Data.config.spotter.alliance then
if faction == "Alliance" then
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: Alliance", ModuleName))
print(string.format("[%s] Notifying - Found Alliance player: %s", ModuleName, name))
end
return true
end
end
if Heimdall_Data.config.spotter.hostile then
if hostile then
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: Hostile", ModuleName))
print(string.format("[%s] Notifying - Found hostile player: %s", ModuleName, name))
end
return true
end
end
if Heimdall_Data.config.spotter.debug then
print(string.format("[%s] Using everyone setting: %s", ModuleName, tostring(Heimdall_Data.config.spotter.everyone)))
end
return Heimdall_Data.config.spotter.everyone
end
@@ -64,22 +76,28 @@ function shared.Spotter.Init()
---@return string?
local function NotifySpotted(unit)
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: NotifySpotted", ModuleName))
shared.dumpTable(Heimdall_Data.config.spotter)
print(string.format("[%s] Processing spotted unit: %s", ModuleName, unit))
end
if not unit then return string.format("Could not find unit %s", tostring(unit)) end
if not UnitIsPlayer(unit) then return nil end
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: UnitIsPlayer", ModuleName))
if not UnitIsPlayer(unit) then
if Heimdall_Data.config.spotter.debug then
print(string.format("[%s] Ignoring non-player unit: %s", ModuleName, unit))
end
return nil
end
local name = UnitName(unit)
if not name then return string.format("Could not find name for unit %s", tostring(unit)) end
if Heimdall_Data.config.spotter.debug then
print(string.format("[%s] Processing player: %s", ModuleName, name))
end
local time = GetTime()
if throttleTable[name] and time - throttleTable[name] < Heimdall_Data.config.spotter.throttleTime then
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: Throttled %s", ModuleName, tostring(name)))
local remainingTime = Heimdall_Data.config.spotter.throttleTime - (time - throttleTable[name])
print(string.format("[%s] Player %s throttled for %.1f more seconds", ModuleName, name, remainingTime))
end
return string.format("Throttled %s", tostring(name))
end
@@ -90,36 +108,32 @@ function shared.Spotter.Init()
local faction = shared.raceMap[race]
if not faction then return string.format("Could not find faction for race %s", tostring(race)) end
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: Faction %s", ModuleName, tostring(faction)))
print(string.format("[%s] Player %s is %s (%s)", ModuleName, name, race, faction))
end
local hostile = UnitCanAttack("player", unit)
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: Hostile %s", ModuleName, tostring(hostile)))
print(string.format("[%s] Player %s is %s", ModuleName, name, hostile and "hostile" or "friendly"))
end
local doNotify = ShouldNotify(unit, name, faction, hostile)
if not doNotify then return string.format("Not notifying for %s", tostring(name)) end
if not doNotify then
if Heimdall_Data.config.spotter.debug then
print(string.format("[%s] Skipping notification for %s", ModuleName, name))
end
return string.format("Not notifying for %s", tostring(name))
end
local hp = UnitHealth(unit)
if not hp then return string.format("Could not find hp for unit %s", tostring(unit)) end
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: HP %s", ModuleName, tostring(hp)))
end
local maxHp = UnitHealthMax(unit)
if not maxHp then return string.format("Could not find maxHp for unit %s", tostring(unit)) end
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: MaxHP %s", ModuleName, tostring(maxHp)))
print(string.format("[%s] Player %s health: %s/%s", ModuleName, name, FormatHP(hp), FormatHP(maxHp)))
end
local class = UnitClass(unit)
if not class then return string.format("Could not find class for unit %s", tostring(unit)) end
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: Class %s", ModuleName, tostring(class)))
end
local location = Heimdall_Data.config.spotter.zoneOverride
if not location or location == "" then
@@ -128,17 +142,16 @@ function shared.Spotter.Init()
local subzone = GetSubZoneText()
if not subzone then subzone = "" end
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: Zone %s", ModuleName, tostring(zone)))
print(string.format("%s: Subzone %s", ModuleName, tostring(subzone)))
print(string.format("[%s] Player %s location: %s (%s)", ModuleName, name, zone, subzone))
end
location = string.format("%s (%s)", zone, subzone)
end
local x, y = GetPlayerMapPosition("player")
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: X %s", ModuleName, tostring(x)))
print(string.format("%s: Y %s", ModuleName, tostring(y)))
print(string.format("[%s] Player %s coordinates: %.2f, %.2f", ModuleName, name, x * 100, y * 100))
end
local stinky = Heimdall_Data.config.stinkies[name] or false
local text = string.format("I see (%s) %s/%s %s of race %s (%s) with health %s/%s at %s (%2.2f, %2.2f)",
hostile and "Hostile" or "Friendly",
@@ -151,10 +164,10 @@ function shared.Spotter.Init()
FormatHP(maxHp),
location,
x * 100, y * 100)
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: Text %s", ModuleName, tostring(text)))
end
if Heimdall_Data.config.spotter.debug then
print(string.format("[%s] Sending notification: %s", ModuleName, text))
end
---@type Message
local msg = {
@@ -162,10 +175,6 @@ function shared.Spotter.Init()
data = Heimdall_Data.config.spotter.notifyChannel,
message = text
}
if Heimdall_Data.config.spotter.debug then
print(string.format("%s: Inserting message into queue", ModuleName))
shared.dumpTable(msg)
end
table.insert(shared.messenger.queue, msg)
end
@@ -173,15 +182,31 @@ function shared.Spotter.Init()
frame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
frame:RegisterEvent("UNIT_TARGET")
frame:SetScript("OnEvent", function(self, event, unit)
if not Heimdall_Data.config.spotter.enabled then return end
if Heimdall_Data.config.spotter.debug then
print(string.format("[%s] Event received: %s for unit: %s", ModuleName, event, unit or "target"))
end
if not Heimdall_Data.config.spotter.enabled then
if Heimdall_Data.config.spotter.debug then
print(string.format("[%s] Module disabled, ignoring event", ModuleName))
end
return
end
if event == "UNIT_TARGET" then
unit = "target"
end
local err = NotifySpotted(unit)
if err then
print(string.format("Error notifying %s: %s", tostring(unit), tostring(err)))
if Heimdall_Data.config.spotter.debug then
print(string.format("[%s] Error processing unit %s: %s", ModuleName, unit, err))
end
end
end)
print("Heimdall - Spotter loaded")
if Heimdall_Data.config.spotter.debug then
print(string.format("[%s] Module initialized", ModuleName))
end
print("[Heimdall] Spotter loaded")
end