232 lines
8.9 KiB
Lua
232 lines
8.9 KiB
Lua
-- Turns merged.lua into the addon's Data.lua.
|
|
-- usage: lua generate.lua merged.lua Data.lua
|
|
local data = dofile(arg[1])
|
|
local q = data.quests
|
|
|
|
local FIVE_MAN = {}
|
|
for _, n in ipairs({ "Ragefire Chasm", "The Deadmines", "Wailing Caverns", "Shadowfang Keep", "Blackfathom Deeps",
|
|
"The Stockade", "Gnomeregan", "Razorfen Kraul", "Scarlet Monastery", "Razorfen Downs", "Uldaman", "Zul'Farrak",
|
|
"Maraudon", "The Temple of Atal'Hakkar", "Blackrock Depths", "Blackrock Spire", "Dire Maul", "Scholomance",
|
|
"Stratholme" }) do FIVE_MAN[n] = true end
|
|
|
|
local UNNAMED = ""
|
|
local dungeon = {}
|
|
for id, r in pairs(q) do
|
|
local name = r.zoneOrSort and data.zoneNames[r.zoneOrSort]
|
|
if not r.hasWork then
|
|
-- "Go talk to someone" steps happen outside, even when filed under the dungeon.
|
|
elseif name and FIVE_MAN[name] then
|
|
dungeon[id] = name
|
|
elseif data.tags[id] and not name then
|
|
dungeon[id] = UNNAMED
|
|
end
|
|
end
|
|
|
|
local function intersects(a, b)
|
|
for i = 0, 52 do
|
|
local bit = 2 ^ i
|
|
if math.floor(a / bit) % 2 == 1 and math.floor(b / bit) % 2 == 1 then return true end
|
|
end
|
|
return false
|
|
end
|
|
|
|
local nexts = {}
|
|
local function edge(a, b)
|
|
if a and b and a ~= 0 and b ~= 0 and a ~= b and q[a] and q[b] then
|
|
nexts[a] = nexts[a] or {}
|
|
nexts[a][b] = true
|
|
end
|
|
end
|
|
for id, r in pairs(q) do
|
|
for _, a in ipairs(r.preQuestSingle or {}) do edge(a, id) end
|
|
for _, a in ipairs(r.preQuestGroup or {}) do edge(a, id) end
|
|
edge(id, r.nextQuestInChain)
|
|
edge(id, r.breadcrumbForQuestId)
|
|
for _, a in ipairs(r.breadcrumbs or {}) do edge(a, id) end
|
|
end
|
|
|
|
local FACTIONS = { { bit = 1, mask = data.ALL_ALLIANCE }, { bit = 2, mask = data.ALL_HORDE } }
|
|
local CLASSES = { "WARRIOR", "PALADIN", "HUNTER", "ROGUE", "PRIEST", "SHAMAN", "MAGE", "WARLOCK", "DRUID" }
|
|
local ALL_CLASSES = 0
|
|
for _, c in ipairs(CLASSES) do ALL_CLASSES = ALL_CLASSES + data.classKeys[c] end
|
|
|
|
local function available(r, factionMask, classBit)
|
|
local races, classes = r.requiredRaces or 0, r.requiredClasses or 0
|
|
if races ~= 0 and not intersects(races, factionMask) then return false end
|
|
if classes ~= 0 and not intersects(classes, classBit) then return false end
|
|
return true
|
|
end
|
|
|
|
-- result[quest][dungeon][factionBit] = class mask
|
|
local result = {}
|
|
for _, faction in ipairs(FACTIONS) do
|
|
for _, class in ipairs(CLASSES) do
|
|
local classBit = data.classKeys[class]
|
|
local function walk(id, seen, found)
|
|
for b in pairs(nexts[id] or {}) do
|
|
if not seen[b] and available(q[b], faction.mask, classBit) then
|
|
seen[b] = true
|
|
if dungeon[b] then found[dungeon[b]] = true end
|
|
walk(b, seen, found)
|
|
end
|
|
end
|
|
end
|
|
for id, r in pairs(q) do
|
|
if available(r, faction.mask, classBit) then
|
|
local found = {}
|
|
walk(id, { [id] = true }, found)
|
|
found[dungeon[id] or false] = nil
|
|
for name in pairs(found) do
|
|
result[id] = result[id] or {}
|
|
result[id][name] = result[id][name] or {}
|
|
result[id][name][faction.bit] = (result[id][name][faction.bit] or 0) + classBit
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
local names, nameIndex = {}, {}
|
|
for _, n in ipairs(data.allDungeons) do
|
|
if FIVE_MAN[n] and not nameIndex[n] then
|
|
names[#names + 1] = n
|
|
nameIndex[n] = #names
|
|
end
|
|
end
|
|
nameIndex[UNNAMED] = 0
|
|
|
|
local ids = {}
|
|
for id in pairs(result) do ids[#ids + 1] = id end
|
|
table.sort(ids)
|
|
|
|
local out = assert(io.open(arg[2], "w"))
|
|
out:write("-- Generated from QuestieDB's Forever quest data. Do not edit.\n")
|
|
out:write("-- quests[id] = { dungeon, faction, classes, ... }; faction 1 Alliance, 2 Horde, 3 both; classes 0 = all; dungeon 0 = unnamed.\n")
|
|
out:write("local _, ns = ...\n\nns.dungeons = {\n")
|
|
for _, n in ipairs(names) do out:write(string.format(" %q,\n", n)) end
|
|
out:write("}\n\nns.quests = {\n")
|
|
for _, id in ipairs(ids) do
|
|
local parts = {}
|
|
local dungeonsHere = {}
|
|
for name in pairs(result[id]) do dungeonsHere[#dungeonsHere + 1] = name end
|
|
table.sort(dungeonsHere)
|
|
for _, name in ipairs(dungeonsHere) do
|
|
local byFaction = result[id][name]
|
|
local a, h = byFaction[1], byFaction[2]
|
|
local function emit(faction, mask)
|
|
parts[#parts + 1] = nameIndex[name] .. "," .. faction .. "," .. (mask == ALL_CLASSES and 0 or mask)
|
|
end
|
|
if a and a == h then
|
|
emit(3, a)
|
|
else
|
|
if a then emit(1, a) end
|
|
if h then emit(2, h) end
|
|
end
|
|
end
|
|
out:write(" [", id, "]={", table.concat(parts, ","), "},\n")
|
|
end
|
|
out:write("}\n")
|
|
out:close()
|
|
|
|
local function summary(faction, classBit, label)
|
|
local n, named = 0, 0
|
|
for id, row in pairs(result) do
|
|
local any, anyNamed = false, false
|
|
for name, f in pairs(row) do
|
|
if f[faction] and intersects(f[faction], classBit) then
|
|
any = true
|
|
if name ~= UNNAMED then anyNamed = true end
|
|
end
|
|
end
|
|
if any then n = n + 1 end
|
|
if anyNamed then named = named + 1 end
|
|
end
|
|
print(label, "pre-quests", n, "with a named dungeon", named)
|
|
end
|
|
print("rows", #ids)
|
|
summary(1, data.classKeys.SHAMAN, "Alliance shaman")
|
|
summary(1, data.classKeys.WARRIOR, "Alliance warrior")
|
|
summary(2, data.classKeys.WARRIOR, "Horde warrior")
|
|
|
|
local function show(id)
|
|
local r = result[id]
|
|
local list = {}
|
|
for name, f in pairs(r or {}) do
|
|
list[#list + 1] = (name == UNNAMED and "(unnamed)" or name) .. " A:" .. tostring(f[1]) .. " H:" .. tostring(f[2])
|
|
end
|
|
print(id, q[id] and q[id].name, table.concat(list, " | "))
|
|
end
|
|
for _, id in ipairs({ 65, 155, 166, 8928, 8916, 94501 }) do show(id) end
|
|
|
|
-- Quest giver locations and the rules for when each quest can be picked up.
|
|
-- Quests whose requirements the addon can't check get no marker.
|
|
if arg[3] then
|
|
local UNSUPPORTED = { "requiredSkill", "requiredMinRep", "requiredMaxRep", "requiredSpell", "requiredSpecialization",
|
|
"requiredRanks", "availableUntilCompleted", "availableStartingWith", "disabledByQuest", "parentQuest", "requiredMaxLevel" }
|
|
local MAX_SPAWNS = 20
|
|
|
|
local function isRepeatable(r) return r.specialFlags and r.specialFlags % 2 == 1 end
|
|
local function unsupported(r)
|
|
if isRepeatable(r) then return true end
|
|
for _, field in ipairs(UNSUPPORTED) do
|
|
local v = r[field]
|
|
if v ~= nil and v ~= 0 then return true end
|
|
end
|
|
return false
|
|
end
|
|
|
|
local function addSpawns(flat, source, list)
|
|
for _, id in ipairs(list or {}) do
|
|
for zone, coords in pairs(source[id] or {}) do
|
|
local map = data.areaToMap[zone]
|
|
if map then
|
|
for _, c in ipairs(coords) do
|
|
if c[1] and c[1] > 0 and c[2] and c[2] > 0 and #flat < MAX_SPAWNS * 3 then
|
|
flat[#flat + 1] = map
|
|
flat[#flat + 1] = string.format("%.4f", c[1] / 100)
|
|
flat[#flat + 1] = string.format("%.4f", c[2] / 100)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
local function list(t)
|
|
if type(t) ~= "table" or #t == 0 then return "nil" end
|
|
return "{" .. table.concat(t, ",") .. "}"
|
|
end
|
|
|
|
local stats = { pinned = 0, unsupported = 0, noPlace = 0 }
|
|
local pinOut = assert(io.open(arg[3], "w"))
|
|
pinOut:write("-- Generated from QuestieDB's Forever data. Do not edit.\n")
|
|
pinOut:write("local _, ns = ...\n\nns.raceBits = {")
|
|
local races = {}
|
|
for race in pairs(data.raceBits) do races[#races + 1] = race end
|
|
table.sort(races)
|
|
for _, race in ipairs(races) do pinOut:write("[", race, "]=", string.format("%.0f", data.raceBits[race]), ",") end
|
|
pinOut:write("}\n\nns.pinQuests = {\n")
|
|
for _, id in ipairs(ids) do
|
|
local r = q[id]
|
|
if unsupported(r) then
|
|
stats.unsupported = stats.unsupported + 1
|
|
else
|
|
local flat = {}
|
|
local starters = type(r.startedBy) == "table" and r.startedBy or {}
|
|
addSpawns(flat, data.npcs, starters[1])
|
|
addSpawns(flat, data.objects, starters[2])
|
|
if #flat == 0 then
|
|
stats.noPlace = stats.noPlace + 1
|
|
else
|
|
stats.pinned = stats.pinned + 1
|
|
pinOut:write(string.format("[%d]={n=%q,l=%d,r=%.0f,c=%d,p=%s,g=%s,x=%s,nx=%d,b=%d,s={%s}},\n",
|
|
id, r.name or "?", r.requiredLevel or 0, r.requiredRaces or 0, r.requiredClasses or 0,
|
|
list(r.preQuestSingle), list(r.preQuestGroup), list(r.exclusiveTo),
|
|
r.nextQuestInChain or 0, r.breadcrumbForQuestId or 0, table.concat(flat, ",")))
|
|
end
|
|
end
|
|
end
|
|
pinOut:write("}\n")
|
|
pinOut:close()
|
|
print("markers", stats.pinned, "skipped: requirements", stats.unsupported, "no location", stats.noPlace)
|
|
end
|