forked from oldkcole/sg1-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashing.lua
581 lines (518 loc) · 17.8 KB
/
bashing.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
module (..., package.seeall)
local valid = {}
local targets = {}
local room_inv = {}
function init(v)
if v and type(v) == "table" then
valid = {}
local pcount = 0
for k,t in pairs(v) do
local prio = t.priority
if not prio then
prio = 1000 + pcount
pcount = pcount + 1
end
valid[k] = { priority = prio, target = t.target or "notarget" }
end
end
end
function reset()
targets = {}
EnableGroup("Bashable", false)
end
function count()
return #targets
end
local function destruction(targ)
local attack = "manifest destruction at"
if enemy.is_shielded(GetVariable("target_name") or targ) then
if main.auto("raze") then
if main.has_skill("lowmagic") then
attack = "invoke nullify"
elseif main.has_skill("highmagic") then
attack = "evoke void"
end
elseif able.generic_beast("aggressive") and main.auto("braze") then
Execute("beast order attack " .. targ)
else
return
end
elseif able.to("beast order attack") and main.auto("bbash") then
Execute("beast order attack " .. targ)
end
if bals.can_act() and not flags.get("bashing1") then
Execute(attack .. " " .. targ)
flags.set("bashing1", true, 0.3)
flags.set("bashing2", true, 0.3)
end
end
local function warrior_2(targ)
local attacks = { "jab", "swing" }
attacks = { attacks[math.random(2)], attacks[math.random(2)] }
local raze = 0
if enemy.is_shielded(GetVariable("target_name") or targ) then
raze = raze + 1
end
if enemy.has_aura(targ) then
raze = raze + 1
end
if main.auto("raze") then
if raze > 0 then
attacks[1] = "raze"
end
if raze > 1 then
attacks[2] = "raze"
end
end
if able.to("beast order attack") then
if (main.auto("bbash") and raze < 1) or
(main.auto("braze") and beast.has_ability("aggressive") and raze > 0) then
Execute("beast order attack " .. targ)
end
end
if (bals.get("larm") or bals.get("rarm")) and
not flags.get("bashing1") then
Execute(attacks[1] .. " " .. targ)
flags.set("bashing1", true, 0.3)
end
if bals.get("larm") and bals.get("rarm") and
not flags.get("bashing2") then
Execute(attacks[2] .. " " .. targ)
flags.set("bashing2", true, 0.3)
end
end
local function warrior_1(targ)
local attacks = { "jab", "swing" }
local attack = attacks[math.random(2)]
local raze = 0
if enemy.is_shielded(GetVariable("target_name") or targ) then
raze = raze + 1
end
if enemy.has_aura(targ) then
raze = raze + 1
end
if main.auto("raze") and
(main.has_ability("axelord", "cleave") or
main.has_ability("pureblade", "cleave") or
main.has_ability("cavalier", "cleave")) and
raze > 0 then
attack = "cleave"
elseif able.to("beast order attack") then
if (main.auto("bbash") and raze < 1) or
(main.auto("braze") and beast.has_ability("aggressive") and raze > 0) then
Execute("beast order attack " .. targ)
end
end
if bals.can_act() and
not flags.get("bashing1") then
Execute(attack .. " " .. targ)
flags.set("bashing1", true, 0.3)
flags.set("bashing2", true, 0.3)
end
end
local function bard(targ)
local attack = "play minorsecond"
if enemy.is_shielded(GetVariable("target_name") or targ) then
if main.auto("raze") then
attack = "play blanknote"
elseif able.to("beast order attack") and
beast.has_ability("aggressive") and
main.auto("braze") then
Execute("beast order attack " .. targ)
else
return
end
elseif able.to("beast order attack") and main.auto("bbash") then
Execute("beast order attack " .. targ)
end
if bals.can_act() and not flags.get("bashing1") then
Execute(attack .. " " .. targ)
flags.set("bashing1", true, 0.3)
flags.set("bashing2", true, 0.3)
end
end
local function wiccan(targ)
local attack = "nature curse"
if defs.has("drawdown") then
if GetVariable("sg1_option_bash_attack") == "moonfire" then
attack = "moonfire"
else
attack = "moonburst"
end
end
if enemy.is_shielded(GetVariable("target_name") or targ) then
if main.auto("raze") then
if main.has_skill("lowmagic") then
attack = "invoke nullify"
elseif main.has_skill("highmagic") then
attack = "evoke void"
end
elseif able.to("beast order attack") and
beast.has_ability("aggressive") and
main.auto("braze") then
Execute("beast order attack " .. targ)
else
return
end
elseif able.to("beast order attack") and main.auto("bbash") then
Execute("beast order attack " .. targ)
end
if bals.can_act() and not flags.get("bashing1") then
Execute(attack .. " " .. targ)
flags.set("bashing1", true, 0.3)
flags.set("bashing2", true, 0.3)
end
end
local function druid(targ)
local attack = "point cudgel"
if enemy.is_shielded(GetVariable("target_name") or targ) then
if main.auto("raze") then
if main.has_skill("lowmagic") then
attack = "invoke nullify"
elseif main.has_skill("highmagic") then
attack = "evoke void"
end
elseif able.generic_beast("aggressive") and main.auto("braze") then
Execute("beast order attack " .. targ)
else
return
end
elseif able.to("beast order attack") and main.auto("bbash") then
Execute("beast order attack " .. targ)
end
if bals.can_act() and not flags.get("bashing1") then
if attack == "point cudgel" and main.has_ability("druidry", "lightningbugs") then
Execute(attack .. " " .. targ .. " lightningbugs")
else
Execute(attack .. " " .. targ)
end
flags.set("bashing1", true, 0.3)
flags.set("bashing2", true, 0.3)
end
end
local function is_present(thing)
local id = tonumber(thing)
if id then
for _,item in ipairs(room_inv) do
if id == item.id and not string.find(item.name, "^the corpse of ") then
return true
end
end
else
for _,item in ipairs(room_inv) do
if string.find(item.name, thing) and not string.find(item.name, "^the corpse of ") then
return true
end
end
end
return false
end
function attack()
if main.auto("bash") and #targets > 0 then
prompt.queue(function () bashing.attack() end, "autobash")
else
EnableGroup("Bashable", false)
return
end
if not able.to("bash") then
return
end
local targ = GetVariable("target") or ""
if not is_present(targ) then
if bals.can_act() then
table.sort(targets, function (a,b) return a.priority < b.priority end)
targ = targets[1].id or targets[1].name
Execute("t " .. targ)
else
return
end
end
if GetVariable("sg1_option_bash_destruction") == "1" then
destruction(targ)
elseif main.has_skill("bonecrusher") or
main.has_skill("blademaster") then
warrior_2(targ)
elseif main.has_skill("knighthood") then
warrior_1(targ)
elseif main.has_skill("music") then
bard(targ)
elseif main.has_skill("druidry") then
druid(targ)
elseif main.has_skill("nature") then
wiccan(targ)
else
display.Error("Bashing is currently not available for your skills. Sorry.")
Execute("reset bashing")
if IsConnected() then
Send("")
end
end
end
function handle_target(name, line, wildcards, styles)
local id = tonumber(wildcards[1])
local tname = wildcards[1]
if id then
for _,item in ipairs(room_inv) do
if id == item.id then
tname = (valid[item.name] and valid[item.name].target) or item.name
end
end
end
SetVariable("target", wildcards[1])
SetVariable("target_name", tname)
display.Info("Targeting: " .. GetVariable("target"))
main.info("target")
if IsConnected() then
Send("")
end
end
function handle_kill(name, line, wildcards, styles)
local targ = wildcards[1]
if not targ or #targ == 0 then
targ = GetVariable("target")
end
if valid[string.lower(targ)] then
targ = valid[string.lower(targ)].target
end
table.insert(targets, {name = targ, id = false, priority = 1000})
display.Debug("Added '" .. targ .. "' to bashing queue", "bash")
if not main.auto("bash") then
Execute("auto bash on")
end
EnableGroup("Bashable", true)
attack()
end
function handle_pkill(name, line, wildcards, styles)
if #targets > 0 then
display.Error("Target queue not empty; force a reset first, if desired.")
if IsConnected() then
Send("")
end
return
end
if not main.auto("bash") then
Execute("auto bash on")
end
EnableGroup("Bashable", true)
targets = {}
for _,item in ipairs(room_inv) do
if valid[item.name] then
table.insert(targets, {name = item.name, id = item.id, priority = valid[item.name].priority})
end
end
if #targets == 0 then
display.Info("No valid targets found at your present location.")
if IsConnected() then
Send("")
end
return
end
table.sort(targets, function (a,b) return a.priority < b.priority end)
attack()
end
function handle_notarget(name, line, wildcards, styles)
if affs.has("blindness") then
display.Debug("No bashable target because of blindness", "bash")
return
end
if #targets < 1 then
display.Debug("No bashable targets to remove", "bash")
return
end
local targ = GetVariable("target") or ""
local id = tonumber(targ)
display.Debug("Looking to remove '" .. targ .. "' from queue", "bash")
if id then
for i = #targets,1,-1 do
if (targets[i].id and id == targets[i].id) or (not targets[i].id and targets[i].name == targ) then
display.Debug("Removed target '" .. targets[i].name .. "' at position " .. i, "bash")
table.remove(targets, i)
end
end
else
for i = #targets,1,-1 do
if string.find(targets[i].name, targ) then
display.Debug("Removed target '" .. targets[i].name .. "' at position " .. i, "bash")
table.remove(targets, i)
end
end
end
if #targets == 0 then
EnableGroup("Bashable", false)
end
--flags.clear{"bashing1", "bashing2"}
end
local bash_affs = {
["bashing_ablaze__"] = function () affs.add_queue("ablaze") affs.burning() end,
["bashing_ablaze_blackout__"] = function () affs.add_queue("ablaze") affs.burning() end,
["bashing_ablaze_paralysis__"] = function () affs.add_queue("ablaze") affs.burning() affs.prone("paralysis") end,
["bashing_aeon__"] = function () affs.aeon() end,
["bashing_arms__"] = function () affs.add_queue("mending_arms") end,
["bashing_blacklung__"] = function () affs.add_queue("black_lung") end,
["bashing_blackout__"] = function () end,
["bashing_blackout_aeon__"] = function () affs.aeon() end,
["bashing_blackout_legs__"] = function () affs.add_queue("mending_legs") end,
["bashing_blackout_paralysis__"] = function () affs.add_queue("paralysis") end,
["bashing_blackout_prone__"] = function () affs.add_queue("prone") end,
["bashing_blackout_stupidity__"] = function () affs.add_queue("stupidity") end,
["bashing_blinded__"] = function () affs.blinded() end,
["bashing_blinded_entangled__"] = function () affs.prone("entangled") affs.blinded() end,
["bashing_blinded_paralysis__"] = function () affs.prone("paralysis") affs.blinded() end,
["bashing_charybdon__"] = function () main.charybdon() end,
["bashing_charybdon_paralysis__"] = function () main.charybdon() affs.prone("paralysis") flags.damaged_health() end,
["bashing_cold__"] = function () affs.cold() end,
["bashing_cold2__"] = function () affs.cold() end,
["bashing_cold_arm__"] = function () affs.cold() EnableTrigger("bashing_cold_arm2__", true) prompt.queue(function () EnableTrigger("bashing_cold_arm2__", false) end) end,
["bashing_cold_arm2__"] = function () affs.add_queue("mending_arms") end,
["bashing_cold_paralysis__"] = function () affs.prone("paralysis") end,
["bashing_damaged__"] = function () flags.damaged_health() end,
["bashing_deafened__"] = function () affs.deafened() end,
["bashing_entangled__"] = function () affs.prone("entangled") end,
["bashing_entangled_arms__"] = function () affs.prone{"entangled", "mending_arms"} end,
["bashing_entangled_stupidity__"] = function () affs.prone{"entangled", "stupidity"} end,
["bashing_fear__"] = function () affs.add_queue("fear") end,
["bashing_fear_stupidity__"] = function () affs.add_queue{"fear", "stupidity"} end,
["bashing_legs__"] = function () affs.add_queue("mending_legs") end,
["bashing_limb_mend__"] = function (wc) affs.add_queue("mending_" .. wc[1] .. "s") end,
["bashing_paralysis__"] = function () affs.prone("paralysis") end,
["bashing_paralysis_cold__"] = function () affs.prone("paralysis") affs.cold() end,
["bashing_paralysis_poisoned__"] = function () affs.prone("paralysis") main.poisons_on() end,
["bashing_paralysis_stupidity__"] = function () affs.prone{"paralysis", "stupidity"} end,
["bashing_paranoia__"] = function () affs.add_queue("paranoia") end,
["bashing_poisoned__"] = function () main.poisons_on() end,
["bashing_poisoned_bleed__"] = function () main.poisons_on() affs.bleed(200) end,
["bashing_prone__"] = function () affs.prone() end,
["bashing_prone2__"] = function () affs.prone() end,
["bashing_prone_deaf__"] = function () affs.prone() affs.deafened() end,
["bashing_prone_entangled__"] = function () affs.prone{"prone", "entangled"} end,
["bashing_prone_leg__"] = function (wc) affs.prone() affs.limb_queue(wc[1], "leg", "broken") end,
["bashing_prone_legs__"] = function () affs.prone{"prone", "mending_legs"} end,
["bashing_prone_poisoned__"] = function () affs.prone() main.poisons_on() end,
["bashing_prone_stupidity__"] = function () affs.prone{"prone", "stupidity"} end,
["bashing_sensitivity_2__"] = function () affs.add_queue("sensitivity") end,
["bashing_stupidity__"] = function () affs.add_queue("stupidity") end,
["bashing_stupidity_damaged__"] = function () affs.add_queue("stupidity") flags.damaged_health() end,
["bashing_unshield__"] = function () defs.del_queue("shield") end,
}
function aff(name, line, wildcards, styles)
local fn = bash_affs[name]
if not fn then
display.Error("No bashing affs function defined for " .. name)
return
end
if type(fn) == "function" then
fn(wildcards)
else
affs.add_queue(fn)
end
end
function bleed(name, line, wildcards, styles)
-- local amt = tonumber(string.match(name, "^bashing_bleed_(%d+)__$"))
-- if not amt then
-- return
-- end
-- affs.bleed(amt)
failsafe.check("bleeding")
end
function items_list(name, line, wildcards, styles)
display.q = true
local wc = string.gsub(wildcards[1] or "", "bearing the name \"(%w+)\"", "bearing the name '%%1'")
local stuff = json.decode(wc)
if stuff.location == "room" then
room_inv = {}
for _,item in ipairs(stuff.items) do
display.Debug("Bashing noticed: " .. string.format("%d, ", tonumber(item.id)) .. item.name, "bash")
table.insert(room_inv, {name = item.name, id = tonumber(item.id)})
end
end
display.q = false
end
function items_add(name, line, wildcards, styles)
display.q = true
local stuff = json.decode(wildcards[1])
if stuff.location == "room" then
local id = tonumber(stuff.item.id)
for i,item in ipairs(room_inv) do
if id == item.id then
id = false
break
end
end
if id then
table.insert(room_inv, {name = stuff.item.name, id = id})
display.Debug("Bashing noticed: " .. string.format("%d, ", id) .. stuff.item.name, "bash")
if main.auto("target") and #targets > 0 and valid[stuff.item.name] then
table.insert(targets, {name = stuff.item.name, id = id, priority = valid[stuff.item.name].priority})
display.Debug("Bashing added: " .. string.format("%d, ", id) .. stuff.item.name .. " [" .. targets[#targets].priority .. "]", "bash")
end
end
end
display.q = false
end
function items_remove(name, line, wildcards, styles)
display.q = true
local stuff = json.decode(wildcards[1])
if stuff.location == "room" then
local id = tonumber(stuff.item.id)
for i = #room_inv,1,-1 do
if id == room_inv[i].id then
display.Debug("Bashing unnoticed: " .. string.format("%d, ", id) .. room_inv[i].name, "bash")
table.remove(room_inv, i)
break
end
end
for i = #targets,1,-1 do
if id == targets[i].id then
display.Debug("Bashing removed: " .. string.format("%d, ", id) .. targets[i].name, "bash")
table.remove(targets, i)
break
end
end
end
display.q = false
end
function items_update(name, line, wildcards, styles)
display.q = true
local stuff = json.decode(wildcards[1])
if stuff.location == "room" and string.find(stuff.item.name, "^the corpse of ") then
local id = tonumber(stuff.item.id)
for i = #room_inv,1,-1 do
if id == room_inv[i].id then
room_inv[i].name = stuff.item.name
display.Debug("Bashing unnoticed: " .. string.format("%d, ", id) .. stuff.item.name, "bash")
break
end
end
for i = #targets,1,-1 do
if (targets[i].id and id == targets[i].id) or (not targets[i].id and string.find(stuff.item.name, targets[i].name)) then
display.Debug("Bashing removed: " .. string.format("%d, ", id) .. targets[i].name, "bash")
table.remove(targets, i)
break
end
end
end
display.q = false
end
function show_queue()
display.Info("Bashing Report:")
local active = false
for i,item in ipairs(targets) do
active = true
display.Prefix()
ColourNote("dimgray", "", string.format(" %2d ", i), "saddlebrown", "", string.format(" %6d ", item.id or 0),
"darkorange", "", string.format(" %-40s ", string.sub(item.name, 1, 40)))
end
if not active then
display.Prefix()
ColourNote("dimgray", "", " Nothing on the agenda.")
end
if IsConnected() then
Send("")
end
end
DeleteAlias("bashing_iht__")
DeleteTrigger("bashing_iht_add__")
DeleteTrigger("bashing_iht_done__")
DeleteTrigger("bashing_target_dead__")
DeleteTrigger("bashing_target_slain__")
DeleteTrigger("bashing_entangled_stupidity__")