-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathnecronomicon.lua
98 lines (85 loc) · 3.09 KB
/
necronomicon.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
-- lists books that contain secrets of life and death.
local argparse = require("argparse")
function get_book_interactions(item)
local title, book_interactions = nil, {}
for _, improvement in ipairs(item.improvements) do
if improvement._type == df.itemimprovement_pagesst or
improvement._type == df.itemimprovement_writingst then
for _, content_id in ipairs(improvement.contents) do
local written_content = df.written_content.find(content_id)
title = written_content.title
for _, ref in ipairs (written_content.refs) do
if ref._type == df.general_ref_interactionst then
local interaction = df.interaction.find(ref.interaction_id)
table.insert(book_interactions, interaction)
end
end
end
end
end
return title, book_interactions
end
function check_slab_secrets(item)
local type_id = item.engraving_type
local type = df.slab_engraving_type[type_id]
return type == "Secrets"
end
function get_item_artifact(item)
for _, ref in ipairs(item.general_refs) do
if ref._type == df.general_ref_is_artifactst then
return df.artifact_record.find(ref.artifact_id)
end
end
end
function print_interactions(interactions)
for _, interaction in ipairs(interactions) do
-- Search interaction.str for the tag [CDI:ADV_NAME:<string>]
-- for example: [CDI:ADV_NAME:Raise fetid corpse]
for _, str in ipairs(interaction.str) do
local _, e = string.find(str.value, "ADV_NAME")
if e then
print(" " .. string.sub(str.value, e + 2, #str.value - 1))
end
end
end
end
function necronomicon(include_slabs)
if include_slabs then
print("Slabs:")
print()
for _, item in ipairs(df.global.world.items.other.SLAB) do
if check_slab_secrets(item) then
local artifact = get_item_artifact(item)
local name = dfhack.TranslateName(artifact.name)
print(" " .. dfhack.df2console(name))
end
end
print()
end
print("Books and Scrolls:")
print()
for _, vec in ipairs{df.global.world.items.other.BOOK, df.global.world.items.other.TOOL} do
for _, item in ipairs(vec) do
local title, interactions = get_book_interactions(item)
if next(interactions) ~= nil then
print(" " .. dfhack.df2console(title))
print_interactions(interactions)
print()
end
end
end
end
local help = false
local include_slabs = false
local args = argparse.processArgsGetopt({...}, {
{"s", "include-slabs", handler=function() include_slabs = true end},
{"h", "help", handler=function() help = true end}
})
local cmd = args[1]
if help or cmd == "help" then
print(dfhack.script_help())
elseif cmd == nil or cmd == "" then
necronomicon(include_slabs)
else
print(('necronomicon: Invalid argument: "%s"'):format(cmd))
end