forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-legendary.lua
106 lines (92 loc) · 2.67 KB
/
make-legendary.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
99
100
101
102
103
104
105
106
-- Make a skill or skills of a unit Legendary +5
local utils = require('utils')
function getName(unit)
return dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit)))
end
function legendize(unit, skill_idx)
utils.insert_or_update(unit.status.current_soul.skills,
{new=true, id=skill_idx, rating=df.skill_rating.Legendary5},
'id')
end
function make_legendary(skillname)
local unit = dfhack.gui.getSelectedUnit()
if not unit then
return
end
local skillnum = df.job_skill[skillname]
if not skillnum then
qerror('The skill name provided is not in the list')
end
local skillnamenoun = df.job_skill.attrs[skillnum].caption_noun
if not skillnamenoun then
qerror('skill name noun not found')
end
legendize(unit, skillnum)
print(getName(unit) .. ' is now a legendary ' .. skillnamenoun)
end
function PrintSkillList()
for i, name in ipairs(df.job_skill) do
local attr = df.job_skill.attrs[i]
if attr.caption then
print(('%s (%s), Type: %s'):format(
name, attr.caption, df.job_skill_class[attr.type]))
end
end
print()
print('Provide the UPPER_CASE argument, for example: ENGRAVE_STONE rather than Engraving.')
end
function BreathOfArmok()
local unit = dfhack.gui.getSelectedUnit()
if not unit then
return
end
for i in ipairs(df.job_skill) do
legendize(unit, i)
end
print('The breath of Armok has engulfed ' .. getName(unit))
end
function LegendaryByClass(skilltype)
local unit = dfhack.gui.getSelectedUnit()
if not unit then
return
end
for i in ipairs(df.job_skill) do
local attr = df.job_skill.attrs[i]
if skilltype == df.job_skill_class[attr.type] then
print(('%s skill %s is now legendary for %s'):format(
skilltype, attr.caption, getName(unit)))
legendize(unit, i)
end
end
end
function PrintSkillClassList()
print('Skill class names:')
for _, name in ipairs(df.job_skill_class) do
print(' ' .. name)
end
print()
print('Provide one of these arguments, and all skills of that type will be made Legendary')
print('For example: Medical will make all medical skills legendary')
end
--main script operation starts here
----
local opt = ...
if not opt then
print(dfhack.script_help())
return
end
if opt == 'list' then
PrintSkillList()
return
elseif opt == 'classes' then
PrintSkillClassList()
return
elseif opt == 'all' then
BreathOfArmok()
return
elseif df.job_skill_class[opt] then
LegendaryByClass(opt)
return
else
make_legendary(opt)
end