-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathchar_defaults.lua
167 lines (156 loc) · 4.6 KB
/
char_defaults.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
-----------------------------
---- Begin char_defaults ----
-----------------------------
-- See README.md for documentation.
weapon_skills = { "Maces & Flails", "Axes", "Polearms", "Staves",
"Unarmed Combat", "Short Blades", "Long Blades" }
ranged_skills = { "Throwing", "Ranged Weapons" }
other_skills = { "Fighting", "Armour", "Dodging", "Shields", "Stealth",
"Spellcasting", "Conjurations", "Hexes", "Summonings",
"Necromancy", "Translocations", "Alchemy", "Fire Magic",
"Ice Magic", "Air Magic", "Earth Magic", "Invocations",
"Evocations", "Shapeshifting" }
skill_glyphs = { [1] = "+", [2] = "*" }
chdat = nil
char_combo = you.race() .. you.class()
loaded_attempted = false
-- Wrapper of crawl.mpr() that prints text in white by default.
if not mpr then
mpr = function (msg, color)
if not color then
color = "white"
end
crawl.mpr("<" .. color .. ">" .. msg .. "</" .. color .. ">")
end
end
function skill_message(prefix, skill, skill_type, value)
local msg = ""
if prefix then
msg = prefix .. ";"
end
if skill_type then
msg = msg .. skill_type .. "(" .. skill .. "):" .. value
else
msg = msg .. skill .. ":" .. value
end
return msg
end
function save_char_defaults(quiet)
if you.class() == "Wanderer" then
return
end
if not c_persist.char_defaults then
c_persist.char_defaults = { }
end
c_persist.char_defaults[char_combo] = { }
chdat = c_persist.char_defaults[char_combo]
local msg = nil
local have_weapon = false
for _,sk in ipairs(weapon_skills) do
if you.train_skill(sk) > 0 then
chdat["Weapon"] = you.train_skill(sk)
msg = skill_message(nil, sk, "Weapon",
skill_glyphs[chdat["Weapon"]])
have_weapon = true
break
end
end
if not have_weapon then
chdat["Weapon"] = nil
end
local have_ranged = false
for _,sk in ipairs(ranged_skills) do
if you.train_skill(sk) > 0 then
chdat["Ranged"] = you.train_skill(sk)
msg = skill_message(msg, sk, "Ranged",
skill_glyphs[chdat["Ranged"]])
have_ranged = true
break
end
end
if not have_ranged then
chdat["Ranged"] = nil
end
for _,sk in ipairs(other_skills) do
if you.train_skill(sk) > 0 then
chdat[sk] = you.train_skill(sk)
msg = skill_message(msg, sk, nil, skill_glyphs[chdat[sk]])
else
chdat[sk] = nil
end
end
if not quiet then
mpr("Saved default for " .. char_combo .. ": " .. msg)
end
end
function have_defaults()
return you.class() ~= "Wanderer"
and c_persist.char_defaults ~= nil
and c_persist.char_defaults[char_combo] ~= nil
end
function load_char_defaults(quiet)
if not have_defaults() then
return
end
local msg = nil
local found_weapon = false
chdat = c_persist.char_defaults[char_combo]
for _,sk in ipairs(weapon_skills) do
if you.base_skill(sk) > 0 and chdat["Weapon"] then
you.train_skill(sk, chdat["Weapon"])
msg = skill_message(msg, sk, "Weapon",
skill_glyphs[chdat["Weapon"]])
found_weapon = true
else
you.train_skill(sk, 0)
end
end
if chdat["Weapon"] and not found_weapon then
you.train_skill("Unarmed Combat", chdat["Weapon"])
msg = skill_message(msg, "Unarmed Combat", "Weapon",
skill_glyphs[chdat["Weapon"]])
end
local found_ranged = false
for _,sk in ipairs(ranged_skills) do
if you.base_skill(sk) > 0 and chdat["Ranged"] then
you.train_skill(sk, chdat["Ranged"])
msg = skill_message(msg, sk, "Ranged",
skill_glyphs[chdat["Ranged"]])
found_ranged = true
else
you.train_skill(sk, 0)
end
end
if chdat["Ranged"] and not found_ranged then
you.train_skill("Throwing", chdat["Ranged"])
msg = skill_message(msg, "Throwing", "Ranged",
skill_glyphs[chdat["Ranged"]])
end
for _,sk in ipairs(other_skills) do
if chdat[sk] then
you.train_skill(sk, chdat[sk])
msg = skill_message(msg, sk, nil, skill_glyphs[chdat[sk]])
else
you.train_skill(sk, 0)
end
end
if not quiet and msg ~= "" then
mpr("Loaded default for " .. char_combo .. ": " .. msg)
end
end
function char_defaults(quiet)
if you.turns() ~= 0 then
return
end
if not load_attempted then
load_char_defaults(quiet)
load_attempted = true
-- Open the skill menu if we don't have settings to load.
if not have_defaults() then
crawl.sendkeys("m")
end
end
end
---------------------------
---- End char_defaults ----
---------------------------