-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXPTimer.xml
691 lines (610 loc) · 20.4 KB
/
XPTimer.xml
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, April 09, 2017, 11:32 AM -->
<!-- MuClient version 5.04 -->
<!--
XP Hotspot Timer by Ruhsbaar
-->
<muclient>
<plugin
name="XPTimer"
author="Ruhsbaar"
id="2cc9f421b4a4a393d32e9cfe"
language="Lua"
purpose="Measure time since last visit to XP Hotspots in DiscworldMUD."
date_written="2017-04-09 11:30:16"
requires="5.04"
version="1.0"
>
</plugin>
<include name="constants.lua"/>
<aliases>
<alias
enabled="y"
match="^deathtimers$"
regexp="y"
script="DeathTimers"
sequence="100"
></alias>
<alias
enabled="y"
match="^dt$"
regexp="y"
script="DeathTimers"
sequence="100"
></alias>
<alias
enabled="y"
match="^dtreset (?<target>[\w\s]+)$"
regexp="y"
script="SpotReset"
sequence="100"
></alias>
<alias
enabled="y"
match="^gsdt$"
regexp="y"
script="GroupSend"
sequence="100"
></alias>
<alias
enabled="y"
match="^dtdebug$"
regexp="y"
script="DebugToggle"
sequence="100"
></alias>
<alias
enabled="y"
match="^dtwindow$"
regexp="y"
script="WindowToggle"
sequence="100"
></alias>
<alias
enabled="y"
match="^dtsync (?<target>\w+)$"
regexp="y"
script="SyncSend"
sequence="100"
></alias>
<alias
enabled="y"
match="^help (deathtimer|dt|death timer|spottimer|spot timer|xptimer|XPTimer)$"
regexp="y"
script="HelpFile"
sequence="100"
></alias>
</aliases>
<triggers>
<trigger
enabled="y"
keep_evaluating="n"
match="^(?P<killer>[- 'A-Za-z]+) deals the death blow to\s(?P<victim>.+)\.$"
regexp="y"
script="DeathBlowHandler"
name="OtherDeathBlowHandler"
sequence="100"
></trigger>
<trigger
enabled="y"
keep_evaluating="n"
match="^(?P<killer>You) kill\s(?P<victim>.+)\.$"
regexp="y"
script="DeathBlowHandler"
name="YouDeathBlowHandler"
sequence="100"
></trigger>
<trigger
enabled="y"
keep_evaluating="n"
match="^(?P<syncer>[\w\s ]+) tells you: ruhs_dtsync=\[(?P<dtimes>.+)\] \| ruhs_vtsync=\[(?P<vtimes>.+)\]$"
regexp="y"
script="SyncReceiveTimers"
name="SyncTrigger"
sequence="100"
></trigger>
</triggers>
<script>
<![CDATA[
require "json"
require "movewindow"
-- Utils
function initSpot(name, display, group)
local spot = {
["time"] = 0,
["name"] = name,
["display"] = display
}
if group then
spot["group"] = true
end
return spot
end
-- Data
debug_flag = false
window_flag = false
window_name = "xpwindow_" .. GetPluginID()
spot_count = 21
window_info = {}
last_room = {
["name"] = "",
["identifier"] = ""
}
kill_timers = {
[1] = initSpot("Delbert", "delbert"),
[2] = initSpot("the Triad boss", "medina boss"),
[3] = initSpot("the bandit leader", "bandit leader"),
[4] = initSpot("Hlakket the Bartender", "hlakket"),
[5] = initSpot("the Zoon Liar", "zoon liar"),
[6] = initSpot("Slim Stevie", "rogues"),
[7] = initSpot("the smuggler captain", "smuggler captain"),
[8] = initSpot("the ceremonial guard", "cguards"),
[9] = initSpot("the %l+ %l+ lion", "shaker lions"),
[10] = initSpot("the %l+ student", "dojo"),
[11] = initSpot("the %l+ grflx worker", "grflx", true),
[12] = initSpot("the %l+ grflx workleader", "grflx", true),
[13] = initSpot("the giant leader", "giant leader"),
[14] = initSpot("Geraldo Ciaco", "casino", true),
[15] = initSpot("Marlon Gumboni", "casino", true),
[16] = initSpot("Charles Marchella", "casino", true),
[17] = initSpot("Frankie Harvard", "casino", true),
[18] = initSpot("Joe Corrola", "stables", true),
[19] = initSpot("Enrico Persuica", "stables", true),
[20] = initSpot("Samuel Casso", "stables", true),
[21] = initSpot("Louis Accardo", "stables", true),
[22] = initSpot("the %l+ rujona", "snail", true),
[23] = initSpot("the %l+ nitsuni", "snail", true),
[24] = initSpot("the Ome outlaw", "snail", true),
}
visit_timers = {
-- shades maze entrance
[1] = initSpot("AMShades", "shades"),
-- smugglers cove entrance
[2] = initSpot("ebff897af2b8bb6800a9a8636143099d0714be07", "smugglers"),
-- second floor kitchen, salt shaker
[3] = initSpot("cb8aaf1cc79bb5e8977a6d0124791dd116eef443", "shaker"),
-- offler crocodile pond
[4] = initSpot("70546ec71867645ab5c51e9ce6087b75dcf4176f", "offler"),
-- northern corner of the black market
[5] = initSpot("f6c60dd36ed38707eb954c3a670f2f9370a79399", "black market", true),
-- southern side of the black market
[6] = initSpot("0ae9d8c4f2b48f4fcc4cb57fd85443399be2ecc5", "black market", true),
-- southwest corner of oasis
[7] = initSpot("066ae1b58fc230eb5750bb3c81a52c12ddc1ccce", "oasis", true),
-- se center of oasis
[8] = initSpot("c8516e4e4017a99cd19183e5918c3bf767918ef0", "oasis", true),
-- sw center of oasis
[9] = initSpot("6dd759fc275793325c3f7449cd7f319af4f9892d", "oasis", true),
-- nw center of oasis
[10] = initSpot("b15950601c93e3adab31fb7755829cf3ed93b5b5", "oasis", true),
-- ne center of oasis
[11] = initSpot("899ad0dfdfc25ad0ebeb4ed861ea18e339adb4d0", "oasis", true),
-- the flamming cabbage
[12] = initSpot("cca9645565f2bb0d017ea9b1dcc9d1b3e9fcfe72", "cabbage"),
-- 1k parades southwest corner
[13] = initSpot("3862c5fd0fe83f4080bdb9b94519bf8da89d5015", "parades", true),
-- 1k parades northeast corner
[14] = initSpot("95ede200c782fdb09239a2db85dd9f8775922f86", "parades", true),
}
metatbl = { __lt = function (k1, k2) print (k1["time"]); return k1["time"] > k2["time"] end }
for _, v in ipairs(kill_timers) do setmetatable(v, mt) end
for _, v in ipairs(visit_timers) do setmetatable(v, mt) end
-- XPTimer
function DebugToggle(name, line, wildcards)
debug_flag = not debug_flag
Note("[XPTimer] Debug flag toggled to " .. tostring(debug_flag))
end
function DeathBlowHandler(name, line, wildcards)
local killer = wildcards.killer
local victim = wildcards.victim
if debug_flag then
Note("[XPTimer] Killer: " .. killer .. " | Victim: " .. victim)
end
for k,v in pairs(kill_timers) do
if string.match(victim, v["name"]) then
v["time"] = os.time()
end
end
-- Update our window if its enabled
if window_flag == true then
DrawWindow()
end
end
function OnPluginBroadcast(msg, id, name, text)
roominfo = '^room.info (.+)'
roominfo = string.match(text, roominfo)
if(roominfo) then
-- Record the last room we were in
last_room = assert(json.decode(roominfo))
if debug_flag then
Note("[XPTimer] Room Name: \"" .. last_room["name"] .. "\" Identifier: \"" .. last_room["identifier"] .. "\"")
end
-- Check it against our saved vnums
for k,v in pairs(visit_timers) do
if v["name"] == last_room["identifier"] then
v["time"] = os.time()
end
end
end
-- Update our window if its enabled
if window_flag == true then
DrawWindow()
end
end
function SpotReset(name, line, wildcards)
if wildcards.target == "all" then
Note("[XPTimer] Resetting all spots to Unseen.")
for k,v in pairs(kill_timers) do
v["time"] = 0
end
for k,v in pairs(visit_timers) do
v["time"] = 0
end
else
for k,v in pairs(kill_timers) do
if v["display"] == wildcards.target then
Note("[XPTimer] Resetting death timer for " .. v["display"] .. ".")
v["time"] = os.time()
end
end
for k,v in pairs(visit_timers) do
if v["display"] == wildcards.target then
Note("[XPTimer] Resetting visit timer for " .. v["display"] .. ".")
v["time"] = os.time()
end
end
end
DrawWindow()
end
-- Output
function DeathTimers()
local current_time = os.time()
local difference = os.time()
function PrintTimerTable(timers)
local groups = {}
for index,spot in ipairs(timers) do
if spot["group"] then
if not groups[spot["display"]] then
groups[spot["display"]] = spot["time"]
else
if groups[spot["display"]] < spot["time"] then
groups[spot["display"]] = spot["time"]
end
end
else
if spot["time"] == 0 then
Note(" - (???)\t" .. spot["display"])
else
difference = math.floor((current_time - spot["time"]) + 0.5)
local mins = math.floor(difference/60)
if mins < 10 then
Note(" - (0" .. mins .. "m)\t" .. spot["display"])
else
Note(" - (" .. mins .. "m)\t" .. spot["display"])
end
end
end
end
for display,time in pairs(groups) do
if time == 0 then
Note(" - (???)\t" .. display)
else
difference = math.floor((current_time - time) + 0.5)
local mins = math.floor(difference/60)
if mins < 10 then
Note(" - (0" .. mins .. "m)\t" .. display)
else
Note(" - (" .. mins .. "m)\t" .. display)
end
end
end
end
Note(".:: Death Timers ::.")
PrintTimerTable(kill_timers)
Note("\n.:: Visit Timers ::.")
PrintTimerTable(visit_timers)
end
function GroupSend(name, line, wildcards)
local current_time = os.time()
local difference = os.time()
function PrintTimerTable(timers)
local output = ""
local groups = {}
for index,spot in ipairs(timers) do
if spot["group"] then
if not groups[spot["display"]] then
groups[spot["display"]] = spot["time"]
else
if groups[spot["display"]] < spot["time"] then
groups[spot["display"]] = spot["time"]
end
end
else
if spot["time"] == 0 then
output = output .. spot["display"] .. ": ??? | "
else
difference = math.floor((current_time - spot["time"]) + 0.5)
local mins = math.floor(difference/60)
output = output .. spot["display"] .. ": " .. mins .. "m | "
end
end
end
for display,time in pairs(groups) do
if time == 0 then
output = output .. display .. ": ??? | "
else
difference = math.floor((current_time - time) + 0.5)
local mins = math.floor(difference/60)
output = output .. display .. ": " .. mins .. "m | "
end
end
output = output:sub(1, output:len()-2)
return output
end
-- List out death timers
local kto = PrintTimerTable(kill_timers)
-- List out visit timers
local vto = PrintTimerTable(visit_timers)
Send("group say " .. kto .. " | " .. vto)
end
--
-- Miniwindow nonsense
--
WIN_WIDTH, WIN_HEIGHT = 165, 460
function OnPluginInstall()
window_info = movewindow.install(window_name, miniwin.pos_center_all, 0)
--local line_height = WindowFontInfo(window_name, "f", 1)
--WIN_HEIGHT = line_height * (spot_count + 8)
WindowCreate(
window_name,
window_info.window_left,
window_info.window_top,
WIN_WIDTH, WIN_HEIGHT,
window_info.window_mode,
window_info.window_flags,
ColourNameToRGB("black")
)
movewindow.add_drag_handler(window_name, 0, 0, 0, 0, miniwin.cursor_both_arrow)
movewindow.save_state(window_name)
WindowFont(window_name, "f", "Consolas", 8, true, false, false, false)
DrawWindow()
end
function WindowToggle(name, line, wildcards)
if window_flag == false then
WindowShow(window_name, true)
window_flag = true
DrawWindow()
else
EraseWindow()
window_flag = false
end
end
function DrawWindow()
-- Clear the window
WindowRectOp(window_name, miniwin.rect_fill, 0, 0, 0, 0, ColourNameToRGB("black"))
-- Add a border to define edges
WindowRectOp(window_name, miniwin.rect_frame, 0, 0, WIN_WIDTH, WIN_HEIGHT, ColourNameToRGB("white"))
-- Write out our timers
DrawTimersOnWindow()
end
function DrawTimersOnWindow()
local num_lines = -1
local line_height = WindowFontInfo(window_name, "f", 1)
local current_time = os.time()
local difference = os.time()
function PrintTimerTable(timers)
local groups = {}
-- table.sort(timers)
-- local fns = kill_timers[1] < kill_timers[2]
function DrawLine(time, display)
num_lines = num_lines + 1
local height = (num_lines * line_height) + 4
local length = 0
local spaces_needed = 5
if type(time) == "number" then
if time == 0 then
length = 0
else
length = math.floor(math.log10(time))
end
else
length = time:len() + 1
end
spaces_needed = spaces_needed - length
-- start output
local output = " - ("
-- add zero for under 10 minutes
if length < 1 then output = output .. "0" end
-- add minutes
output = output .. time
-- add "m" minutes label
if type(time) == "number" then output = output .. "m" end
-- close parens
output = output .. ")"
WindowText(window_name, "f", output, 5, height, 0, 0, ColourNameToRGB("white"), false)
if type(time) == "number" and time > 70 then
WindowText(window_name, "f", display, 60, height, 0, 0, ColourNameToRGB("white"), false)
elseif type(time) == "number" and time > 50 then
WindowText(window_name, "f", display, 60, height, 0, 0, ColourNameToRGB("red"), false)
elseif type(time) == "number" and time > 30 then
WindowText(window_name, "f", display, 60, height, 0, 0, ColourNameToRGB("yellow"), false)
else
WindowText(window_name, "f", display, 60, height, 0, 0, ColourNameToRGB("white"), false)
end
end
for index,spot in ipairs(timers) do
if spot["group"] then
if not groups[spot["display"]] then
groups[spot["display"]] = spot["time"]
else
if groups[spot["display"]] < spot["time"] then
groups[spot["display"]] = spot["time"]
end
end
else
if spot["time"] == 0 then
DrawLine("???", spot["display"])
else
difference = math.floor((current_time - spot["time"]) + 0.5)
local mins = math.floor(difference/60)
if mins > 99 then mins = 99 end
DrawLine(mins, spot["display"])
end
end
end
for display,time in pairs(groups) do
if time == 0 then
DrawLine("???", display)
else
difference = math.floor((current_time - time) + 0.5)
local mins = math.floor(difference/60)
if mins > 99 then mins = 99 end
DrawLine(mins, display)
end
end
end
-- Blank Line
num_lines = num_lines +1
local output = ""
local height = (num_lines * line_height)
WindowText(window_name, "f", output, 5, height, 0, 0, ColourNameToRGB("white"), false)
-- Note(".:: Death Timers ::.")
num_lines = num_lines +1
local output = "-- [ Death Timers ] -- "
local height = (num_lines * line_height)
WindowText(window_name, "f", output, 5, height, 0, 0, ColourNameToRGB("white"), false)
PrintTimerTable(kill_timers)
-- Blank Line
num_lines = num_lines +1
local output = ""
local height = (num_lines * line_height)
WindowText(window_name, "f", output, 5, height, 0, 0, ColourNameToRGB("white"), false)
-- Note("\n.:: Visit Timers ::.")
num_lines = num_lines +1
local output = " -- [ Visit Timers ] -- "
local height = (num_lines * line_height)
WindowText(window_name, "f", output, 5, height, 0, 0, ColourNameToRGB("white"), false)
PrintTimerTable(visit_timers)
end
function EraseWindow()
movewindow.save_state(window_name)
WindowShow(window_name, false)
end
function OnPluginDisable()
EraseWindow()
end
function OnPluginClose()
EraseWindow()
end
--
-- Between-player syncing
--
function SyncSend(name, line, wildcards)
local dtsync = "ruhs_dtsync=["
local vtsync = "ruhs_vtsync=["
--
-- Death Timers
--
local groups = {}
for index,spot in ipairs(kill_timers) do
if spot["group"] then
if not groups[spot["display"]] then
groups[spot["display"]] = spot["time"]
else
if groups[spot["display"]] < spot["time"] then
groups[spot["display"]] = spot["time"]
end
end
else
if spot["time"] ~= 0 then
dtsync = dtsync .. spot["display"] .. "=" .. spot["time"] .. ","
end
end
end
for display,time in pairs(groups) do
if time ~= 0 then
dtsync = dtsync .. display .. "=" .. time .. ","
end
end
--
-- Visit Timers
--
local groups = {}
for index,spot in ipairs(visit_timers) do
if spot["group"] then
if not groups[spot["display"]] then
groups[spot["display"]] = spot["time"]
else
if groups[spot["display"]] < spot["time"] then
groups[spot["display"]] = spot["time"]
end
end
else
if spot["time"] ~= 0 then
vtsync = vtsync .. spot["display"] .. "=" .. spot["time"] .. ","
end
end
end
for display,time in pairs(groups) do
if time ~= 0 then
vtsync = vtsync .. display .. "=" .. time .. ","
end
end
-- Remove trailing commas if needed
if dtsync:len() > 14 then
dtsync = dtsync:sub(1, dtsync:len()-1) .. "]"
else
dtsync = dtsync .. "]"
end
if vtsync:len() > 14 then
vtsync = vtsync:sub(1, vtsync:len()-1) .. "]"
else
vtsync = vtsync .. "]"
end
-- If we have values beyond boilerplate-length, send sync
if dtsync:len() > 15 or vtsync:len() > 15 then
local tell_string = "tell " .. wildcards.target .. " " .. dtsync .. " | " .. vtsync
Send(tell_string)
end
end
function SyncReceiveTimers(name, line, wildcards)
local count = 0
pattern = "([%a%s]+)=([%d]+)"
for display, clock in string.gmatch(wildcards.dtimes, pattern) do
for index,spot in ipairs(kill_timers) do
if spot["display"] == display then
if tonumber(clock) > spot["time"] then
spot["time"] = tonumber(clock)
count = count + 1
end
end
end
end
for display, clock in string.gmatch(wildcards.vtimes, pattern) do
for index,spot in ipairs(visit_timers) do
if spot["display"] == display then
if tonumber(clock) > spot["time"] then
spot["time"] = tonumber(clock)
count = count + 1
end
end
end
end
Note("[XPTimer] Syncing " .. count .. " spot times from " .. wildcards.syncer)
end
--
-- Helpfile
--
function HelpFile(name, line, wildcards)
Note("XP Hotspot Timer by Ruhsbaar")
Note(" - 'dt' or 'deathtimers': display a list of XP hotspot timers")
Note(" - 'dtwindow' : open draggable miniwindow displaying timers")
Note(" - 'gsdt': share the list over group chat")
Note(" - 'dtreset <all/target>': reset the target XP hotspot timer to zero")
Note(" - 'dtsync <player>': send a tell to a player and attempt to sync your times to them")
Note(" - 'dtdebug': toggle debug mode. Useful to find NPC string or room id to add spots")
end
]]>
</script>
</muclient>