From 6f4bd69d00612d93c67baf9e1fc48b4a59e55bbc Mon Sep 17 00:00:00 2001 From: Xurkon Date: Fri, 5 Jun 2026 22:27:27 -0500 Subject: [PATCH] fix: draw pins from immediate learner kill evidence --- Database/QuestieDB.lua | 45 +++++++++++++++++++++ Modules/Quest/QuestieQuestPrivates.lua | 4 +- Tests/QuestieLearnerDataSourceMode_spec.lua | 23 ++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/Database/QuestieDB.lua b/Database/QuestieDB.lua index fcc0fa2..3e44faa 100644 --- a/Database/QuestieDB.lua +++ b/Database/QuestieDB.lua @@ -233,6 +233,43 @@ local function _GetLearnerRecord(storeName, id) return store[id] or store[tostring(id)] end +local function _BuildSpawnTableFromGuidEvidence(evidence) + if type(evidence) ~= "table" then + return nil + end + + local spawns = {} + local hasEntries = false + for _, entry in pairs(evidence) do + if type(entry) == "table" and entry.zoneId and entry.x and entry.y then + local zoneId = tonumber(entry.zoneId) + local x = tonumber(entry.x) + local y = tonumber(entry.y) + if zoneId and x and y then + spawns[zoneId] = spawns[zoneId] or {} + local zoneSpawns = spawns[zoneId] + local exists = false + for _, coord in ipairs(zoneSpawns) do + if coord[1] == x and coord[2] == y then + exists = true + break + end + end + if not exists then + zoneSpawns[#zoneSpawns + 1] = { x, y } + hasEntries = true + end + end + end + end + + if not hasEntries then + return nil + end + + return spawns +end + ---@type QuestieQuest local QuestieQuest = QuestieLoader:ImportModule("QuestieQuest") ---@type QuestieQuestPrivate @@ -2157,6 +2194,14 @@ function QuestieDB:GetNPC(npcId) local friendlyToFaction = npc.friendlyToFaction npc.friendly = (not friendlyToFaction) and true or factionReactions[friendlyToFaction] + if (not npc.spawns or next(npc.spawns) == nil) and mode == "learner" then + local guidSpawns = rawdata[8] + local learnedSpawns = _BuildSpawnTableFromGuidEvidence(guidSpawns) + if learnedSpawns then + npc.spawns = learnedSpawns + end + end + _QuestieDB.npcCache[npcId] = npc return npc end diff --git a/Modules/Quest/QuestieQuestPrivates.lua b/Modules/Quest/QuestieQuestPrivates.lua index 366d57b..8879118 100644 --- a/Modules/Quest/QuestieQuestPrivates.lua +++ b/Modules/Quest/QuestieQuestPrivates.lua @@ -181,7 +181,7 @@ monster = function(npcId, objective) local isLearned = false - if dataSourceMode == "none" or dataSourceMode == "learner" then + if dataSourceMode == "none" then spawns = {} end @@ -276,7 +276,7 @@ object = function(objectId, objective) end local isLearned = false - if dataSourceMode == "none" or dataSourceMode == "learner" then + if dataSourceMode == "none" then spawns = {} end diff --git a/Tests/QuestieLearnerDataSourceMode_spec.lua b/Tests/QuestieLearnerDataSourceMode_spec.lua index 12ca3bc..ab9ef79 100644 --- a/Tests/QuestieLearnerDataSourceMode_spec.lua +++ b/Tests/QuestieLearnerDataSourceMode_spec.lua @@ -36,7 +36,7 @@ describe("QuestieLearner data source mode", function() local priv = read("Modules/Quest/QuestieQuestPrivates.lua") local tip = read("Modules/Tooltips/Tooltip.lua") assert.is_true(has(quest, "dataSourceMode == \"auto\" or dataSourceMode == \"learner\"")) - assert.is_true(has(priv, "dataSourceMode == \"none\" or dataSourceMode == \"learner\"")) + assert.is_true(has(priv, "dataSourceMode == \"none\"")) assert.is_true(has(tip, "mode ~= \"static\" and mode ~= \"none\"")) end) @@ -167,6 +167,27 @@ describe("QuestieDB learner source fallback", function() assert.equals(44, npc.zoneID) end) + it("turns learner kill evidence into NPC spawn coordinates immediately in learner mode", function() + Questie.dbLearner.global.npcs[9003] = { + [1] = "Learner Kill", + [8] = { + [101] = { + zoneId = 44, + x = 18.5, + y = 27.25, + }, + }, + } + + local npc = QuestieDB:GetNPC(9003) + assert.is_table(npc) + assert.is_table(npc.spawns) + assert.is_table(npc.spawns[44]) + assert.equals(1, #npc.spawns[44]) + assert.equals(18.5, npc.spawns[44][1][1]) + assert.equals(27.25, npc.spawns[44][1][2]) + end) + it("returns learner object data when static queries are unavailable", function() local obj = QuestieDB:GetObject(9002) assert.is_table(obj)