fix(learner): don't purge NPCs with name/zone/kills/quests but no spawns

The InjectLearnedData purge loop was deleting entire NPC entries from
Questie.dbLearner.global.npcs whenever data[7] (spawns) was empty,
even if the entry still had a name, home zone, recorded kills, or
quest references. This caused learner data to silently disappear on
/reload for NPCs that had been learned but never killed in a position
the learner could record (e.g. party-kill position attribution fix
now passes nil coords for uncredited kills).

Now only purges when ALL of name, zone, kills, and quest references
are missing. Entries with other useful state get data[7] set to nil
instead so the row stays.
This commit is contained in:
Xurkon
2026-06-09 22:02:39 -05:00
parent fa37ab8eb5
commit 86e37857c0
+18 -5
View File
@@ -2767,18 +2767,31 @@ function QuestieLearner:InjectLearnedData()
purgedNpcs = purgedNpcs + 1
Questie:Debug(Questie.DEBUG_INFO, "[QuestieLearner] Purged player-spawned NPC", npcId, data[1] or "?")
elseif data[7] then
-- Check for empty spawn table (no coords at all = stale learner artifact)
-- Check for empty spawn table (no coords at all = stale learner artifact).
-- Only purge if the NPC has no other useful state — keep entries that
-- still have a name, home zone, recorded kills, or quest references,
-- so a kill recorded with no position (e.g. party-kill position
-- attribution, or pre-record normalization) doesn't drop the whole row.
local hasCoords = false
for zoneKey, coords in pairs(data[7]) do
for _zoneKey, coords in pairs(data[7]) do
if type(coords) == "table" and #coords > 0 then
hasCoords = true
break
end
end
if not hasCoords then
learned.npcs[npcId] = nil
purgedNpcs = purgedNpcs + 1
Questie:Debug(Questie.DEBUG_INFO, "[QuestieLearner] Purged NPC with empty spawns", npcId, data[1] or "?")
local hasName = type(data[1]) == "string" and data[1] ~= ""
local hasZone = type(data[9]) == "number"
local hasKills = (tonumber(data.mc) or 0) > 0
local hasQuests = type(data[10]) == "table" and next(data[10]) ~= nil
if not hasName and not hasZone and not hasKills and not hasQuests then
learned.npcs[npcId] = nil
purgedNpcs = purgedNpcs + 1
Questie:Debug(Questie.DEBUG_INFO, "[QuestieLearner] Purged NPC with empty spawns and no other state", npcId, "?")
else
-- Drop the empty [7] table so it doesn't trip future checks
data[7] = nil
end
end
end
end