forked from oldkcole/sg1-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbals.lua
353 lines (293 loc) · 6.71 KB
/
bals.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
module (..., package.seeall)
local lost = {}
local locked = {}
prone = false
function lose(b, time)
if lost[b] then
return
end
lost[b] = true
if affs.slow() and time and time < 4 then
time = 4
end
local dbg = "Balance '" .. b .. "' lost"
if time then
flags.set(b .. "_try", true, 0)
if failsafe.fn[b] then
failsafe.exec(b, time)
end
dbg = dbg .. " (timeout = " .. tostring(time) .. ")"
end
display.Debug(dbg, "bals")
end
function gain(b)
if not lost[b] then
return
end
lost[b] = nil
flags.clear(b .. "_try")
failsafe.disable(b)
failsafe.disable(b .. "_off")
scan.update = true
display.Debug("Balance '" .. b .. "' restored", "bals")
end
function gained(name, line, wildcards, styles)
gain(wildcards[1])
end
function gained_brew(name, line, wildcards, styles)
gain(wildcards[1])
flags.clear("brew_off")
end
function regain(name, line, wildcards, styles)
local bx = {
["balance on all limbs"] = "bal",
["equilibrium"] = "eq",
["balance on your left arm"] = "larm",
["balance on your right arm"] = "rarm",
["balance on your left leg"] = "legs",
["balance on your right leg"] = "legs",
}
local wc = wildcards[1]
if not bx[wc] then
return
end
local fg = GetVariable("sg1_color_fg_" .. bx[wc]) or "silver"
local bg = GetVariable("sg1_color_bg_" .. bx[wc]) or ""
local t = flags.get(bx[wc] .. "_time")
ColourTell(fg, bg, line)
if t then
ColourTell("dimgray", "", " [" .. string.format("%0.3f", os.clock() - t) .. "s]")
end
Note("")
end
function get(b)
return not lost[b]
end
function reset()
display.Debug("Balances cleared", "bals")
lost = {}
end
function confirm(b, time)
if not flags.get(b .. "_try") then
return false
end
flags.clear(b .. "_try")
failsafe.disable(b)
if time then
failsafe.exec(b .. "_off", time, true)
end
return true
end
function lock(name, line, wildcards, styles)
local chan = string.lower(wildcards[1])
locked[chan] = true
end
function unlock(name, line, wildcards, styles)
local chan = string.lower(wildcards[1])
locked[chan] = nil
end
function is_locked(chan)
return locked[string.lower(chan)] or false
end
function can_act()
if not get("bal") or not get("eq") then
return false
end
if not get("rarm") or not get("larm") then
return false
end
if (not get("sub") and not is_locked("sub")) or
(not get("super") and not is_locked("super")) or
(not get("id") and not is_locked("id")) then
return false
end
return true
end
function pflags()
local pf = ""
if beast.locate() == "mounted" then
pf = pf .. "m"
else
pf = pf .. "-"
end
if get("eq") then
pf = pf .. "e"
end
if main.has_skill("psionics") then
if get("sub") then
pf = pf .. "s"
end
if get("super") then
pf = pf .. "S"
end
if get("id") then
pf = pf .. "i"
end
end
if main.has_skill("kata") then
if get("head") then
pf = pf .. "h"
end
if get("legs") then
pf = pf .. "L"
end
if get("larm") then
pf = pf .. "l"
end
if get("rarm") then
pf = pf .. "r"
end
elseif main.has_skill("bonecrusher") or main.has_skill("blademaster") then
if get("larm") then
pf = pf .. "l"
end
if get("rarm") then
pf = pf .. "r"
end
end
if get("bal") then
pf = pf .. "x"
end
if defs.has("kafe") then
pf = pf .. "k"
end
if defs.has("truehearing") or affs.has("deafness") then
pf = pf .. "d"
end
if defs.has("sixthsense") or affs.has("blindness") then
pf = pf .. "b"
end
if prone then
pf = pf .. "p"
end
if prompt.cloaked then
pf = pf .. "<>"
end
pf = pf .. "-"
return pf
end
function show()
local all = {"allheale", "beast", "brew", "charm", "focus", "health", "herb", "music", "purgative",
"salve", "scroll", "sparkle"}
if main.has_skill("bonecrusher") or main.has_skill("blademaster") then
table.insert(all, "larm")
table.insert(all, "rarm")
end
if main.has_skill("kata") then
table.insert(all, "head")
table.insert(all, "larm")
table.insert(all, "rarm")
table.insert(all, "legs")
end
if main.has_skill("psionics") then
table.insert(all, "id")
table.insert(all, "sub")
table.insert(all, "super")
end
display.Info("Balance Status Report:")
for _,bal in pairs(all) do
display.Prefix()
ColourTell("silver", "black", string.format("%11s", bal) .. " ")
if is_locked(bal) then
ColourNote("yellow", "", "LOCKED")
elseif lost[bal] then
ColourNote("red", "", "OFF")
else
ColourNote("green", "", "ON")
end
end
if IsConnected() then
Send("")
end
end
function failed(b)
if flags.get(b .. "_try") then
bals.gain(b)
end
end
failsafe.fn.allheale = function ()
bals.failed("allheale")
flags.clear_elixir("allheale")
end
failsafe.fn.allheale_off = function ()
bals.gain("allheale")
end
failsafe.fn.beast = function ()
bals.failed("beast")
flags.clear("beast_order")
end
failsafe.fn.beast_off = function ()
bals.gain("beast")
end
failsafe.fn.brew = function ()
bals.failed("brew")
end
failsafe.fn.brew_off = function ()
bals.gain("brew")
end
failsafe.fn.charm = function ()
bals.failed("charm")
end
failsafe.fn.charm_off = function ()
bals.gain("charm")
end
failsafe.fn.focus = function ()
bals.failed("focus")
local f = flags.get("focusing")
if f and f ~= "body" then
flags.clear("focusing")
end
end
failsafe.fn.focus_off = function ()
bals.gain("focus")
end
failsafe.fn.health = function ()
bals.failed("health")
flags.clear("health_applying")
flags.clear_elixir("health mana bromide")
end
failsafe.fn.health_off = function ()
bals.gain("health")
end
failsafe.fn.herb = function ()
bals.failed("herb")
if flags.get("smoking") ~= "faeleaf" then
flags.clear("smoking")
end
end
failsafe.fn.herb_off = function ()
bals.gain("herb")
end
failsafe.fn.music = function ()
bals.failed("music")
end
failsafe.fn.music_off = function ()
bals.gain("music")
end
failsafe.fn.purgative = function ()
bals.failed("purgative")
flags.clear_elixir("antidote choleric fire frost galvanism love phlegmatic sanguine")
end
failsafe.fn.purgative_off = function ()
bals.gain("purgative")
end
failsafe.fn.salve = function ()
bals.failed("salve")
flags.clear{"salve", "regenerating_arms", "regenerating_chest",
"regenerating_gut", "regenerating_head", "regenerating_legs"}
end
failsafe.fn.salve_off = function ()
bals.gain("salve")
end
failsafe.fn.scroll = function ()
bals.failed("scroll")
end
failsafe.fn.scroll_off = function ()
bals.gain("scroll")
end
failsafe.fn.sparkle = function ()
bals.failed("sparkle")
end
failsafe.fn.sparkle_off = function ()
bals.gain("sparkle")
end