Add critical/fumble tables
This commit is contained in:
@ -5,6 +5,10 @@ local _CRIT_KEYS = {"A", "B", "C", "D", "E"}
|
||||
|
||||
local function process_values(rest, condition)
|
||||
-- Get the +XH (with X being a number)
|
||||
if not rest then
|
||||
return {}
|
||||
end
|
||||
|
||||
local damage = rest:match("%+(%d*)H")
|
||||
|
||||
-- π = mustparry
|
||||
@ -77,7 +81,7 @@ local function process_values(rest, condition)
|
||||
round_penalty_duration = round_penalty_duration,
|
||||
round_penalty_value = round_penalty_value,
|
||||
round_bonus_duration = round_bonus_duration,
|
||||
round_bonus_value = round_bonus_value,
|
||||
round_bonus_value = round_bonus_value,
|
||||
mustparry_duration = mustparry_duration,
|
||||
mustparry_value = mustparry_value
|
||||
}
|
||||
@ -85,6 +89,27 @@ end
|
||||
|
||||
local all_criticals = {}
|
||||
|
||||
local function process_line(line)
|
||||
local effects = {}
|
||||
-- Get description (ie all text befire the first \n)
|
||||
local desc = line:match("([^\n]+)")
|
||||
-- Get the rest of the text
|
||||
local rest = line:match("\n(.+)")
|
||||
if rest then
|
||||
if rest:match("with ") then
|
||||
local reasonwith, with, reasonwithout, without = rest:match("(with[^:]*): ([^w]+)(w/o[^:]*): (.+)")
|
||||
print("SPLITTEW WITH", desc)
|
||||
effects[1] = process_values(with, reasonwith)
|
||||
effects[2] = process_values(without, reasonwithout)
|
||||
else
|
||||
effects[1] = process_values(rest)
|
||||
end
|
||||
else
|
||||
print("NO REST", desc)
|
||||
end
|
||||
return desc, effects
|
||||
end
|
||||
|
||||
-- Loop thru all JSON files in the criticals_data directory
|
||||
for file in lfs.dir("./") do
|
||||
if file:match("json$") then
|
||||
@ -93,38 +118,32 @@ for file in lfs.dir("./") do
|
||||
json_file:close()
|
||||
|
||||
local crit = {
|
||||
name = string.match(file, "(%w+).json"),
|
||||
name = string.match(file, "([%w_]+).json"),
|
||||
criticals = {}
|
||||
}
|
||||
|
||||
local rows = json.decode(json_data)
|
||||
if not rows then
|
||||
print("Error decoding JSON file: " .. file)
|
||||
return
|
||||
end
|
||||
for _, c in ipairs(rows) do
|
||||
local new_crit = {
|
||||
score = c.Score,
|
||||
isCreature = false,
|
||||
levels = {}
|
||||
}
|
||||
|
||||
-- Process tables with A-E criticals
|
||||
local isWeapon = true
|
||||
for _, key in ipairs(_CRIT_KEYS) do
|
||||
local effects = {}
|
||||
local line = c[key]
|
||||
if not line then
|
||||
isWeapon = false
|
||||
break
|
||||
end
|
||||
-- Get description (ie all text befire the first \n)
|
||||
local desc = line:match("([^\n]+)")
|
||||
-- Get the rest of the text
|
||||
local rest = line:match("\n(.+)")
|
||||
if rest then
|
||||
if rest:match("with ") then
|
||||
local reasonwith, with, reasonwithout , without = rest:match("(with[^:]*): ([^w]+)(w/o[^:]*): (.+)")
|
||||
print("SPLITTEW WITH", desc)
|
||||
effects[1] = process_values(with, reasonwith)
|
||||
effects[2] = process_values(without, reasonwithout)
|
||||
else
|
||||
effects[1] = process_values(rest)
|
||||
end
|
||||
else
|
||||
print("NO REST", desc)
|
||||
end
|
||||
|
||||
local desc, effects = process_line(line)
|
||||
new_crit.levels[key] = {
|
||||
key = key,
|
||||
description = desc,
|
||||
@ -132,14 +151,37 @@ for file in lfs.dir("./") do
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
-- Creatures table
|
||||
if not isWeapon then
|
||||
new_crit.isCreature = true
|
||||
for key, line in pairs(c) do
|
||||
if key ~= "Score" then
|
||||
local desc, effects = process_line(line)
|
||||
new_crit.levels[key] = {
|
||||
key = key,
|
||||
description = desc,
|
||||
effects = effects
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(crit.criticals, new_crit)
|
||||
end
|
||||
|
||||
all_criticals[crit.name] = crit
|
||||
end
|
||||
end
|
||||
|
||||
-- Convert to JSON
|
||||
local json_data = json.encode(all_criticals, {indent = true})
|
||||
local json_data = json.encode(all_criticals, {
|
||||
indent = true
|
||||
})
|
||||
print(json_data)
|
||||
|
||||
-- Write the whole json_data to a single file
|
||||
local json_file = io.open("criticals.json", "w+")
|
||||
json_file:write(json_data)
|
||||
json_file:close()
|
||||
|
||||
|
Reference in New Issue
Block a user