if not loadStatFile then
dofile("statdesc.lua")
end
loadStatFile("stat_descriptions.csd")
classMap = {
["Martial Weapons"] = { "weapon" },
["Armour"] = { "armour" },
["Caster Weapons"] = { "caster" },
["All"] = { "weapon", "armour", "caster" },
}
function table.containsId(table, element)
for _, value in pairs(table) do
if value.Id == element then
return true
end
end
return false
end
local directiveTable = { }
directiveTable.type = function(state, args, out)
state.type = args
end
directiveTable.base = function(state, args, out)
local baseTypeId, displayName = args:match("([%w/_]+) (.+)")
if not baseTypeId then
baseTypeId = args
end
local baseItemType = dat("BaseItemTypes"):GetRow("Id", baseTypeId)
if not baseItemType then
printf("Invalid Id %s", baseTypeId)
return
end
if not displayName then
displayName = baseItemType.Name
end
displayName = displayName:gsub("\195\182","o")
displayName = displayName:gsub("^%s*(.-)%s*$", "%1") -- trim spaces GGG might leave in by accident
local function writeModLines(modLines, out)
for _, modLine in ipairs(modLines) do
out:write('\t\t["'..modLine.slotType..'"] = {\n')
out:write('\t\t\t\ttype = "Rune",\n')
-- only write labels/statOrder if present
if modLine.label and #modLine.label > 0 then
out:write('\t\t\t\t"'..table.concat(modLine.label, '",\n\t\t\t\t"')..'",\n')
local statOrder = modLine.statOrder or {}
out:write('\t\t\t\tstatOrder = { '..table.concat(statOrder, ', ')..' },\n')
end
out:write('\t\t\t\trank = { '..(modLine.rank or 0)..' },\n')
out:write('\t\t},\n')
end
end
-- Check for Standard Weapon, Armour, Caster Runes
local soulCores = dat("SoulCores"):GetRow("BaseItemTypes", baseItemType)
local soulCoreStats = dat("SoulCoreStats"):GetRowList("Id", soulCores)
out:write('\t["', displayName, '"] = {\n')
local modLines = { }
local rank = 0
for _, soulCoreStat in ipairs(soulCoreStats) do
rank = soulCores.LevelReq or 0
local stats = { }
for i, statKey in ipairs(soulCoreStat.Stats) do
local statValue = soulCoreStat["StatValue"][i]
stats[statKey.Id] = { min = statValue, max = statValue }
end
local bondedStats = { }
for i, statKey in ipairs(soulCoreStat.BondedStats) do
local statValue = soulCoreStat["BondedValues"][i]
bondedStats[statKey.Id] = { min = statValue, max = statValue, bonded = true }
end
if next(stats) then
for _, class in ipairs(classMap[soulCoreStat.Category.Id] or { string.lower(soulCoreStat.Category.Id) }) do
local stats, orders = describeStats(stats)
local bondedStats, bondedOrders = describeStats(bondedStats)
for i, stat in ipairs(bondedStats) do
bondedStats[i] = "Bonded: " .. stat
end
for _, stat in ipairs(bondedStats) do
table.insert(stats, stat)
end
for _, order in ipairs(bondedOrders) do
table.insert(orders, order)
end
if #orders > 0 then
local out = {
type = "Rune",
slotType = class,
label = stats,
statOrder = orders,
rank = rank,
}
table.insert(modLines, out)
end
end
end
end
writeModLines(modLines, out)
out:write('\t},\n')
end
directiveTable.baseMatch = function(state, argstr, out)
-- Default to look at the Id column for matching
local key = "Id"
local args = {}
for i in string.gmatch(argstr, "%S+") do
table.insert(args, i)
end
local value = args[1]
-- If column name is specified, use that
if args[2] then
key = args[1]
value = args[2]
end
for i, baseItemType in ipairs(dat("BaseItemTypes"):GetRowList(key, value, true)) do
directiveTable.base(state, baseItemType.Id, out)
end
end
local out = io.open("../Data/ModRunes.lua", "w")
out:write('-- This file is automatically generated, do not edit!\n')
out:write('-- Item data (c) Grinding Gear Games\n\nreturn {\n')
local state = { }
for line in io.lines("Bases/soulcore.txt") do
local spec, args = line:match("#(%a+) ?(.*)")
if spec then
if directiveTable[spec] then
directiveTable[spec](state, args, out)
else
printf("Unknown directive '%s'", spec)
end
end
end
out:write("}")
out:close()
print("Soul Cores exported.")