/
LotJShopDB.xml
683 lines (619 loc) · 27.5 KB
/
LotJShopDB.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
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE muclient>
<muclient>
<plugin name="LotJShopDB" author="@Johnson" id="d81f71a4639d9e0a1e753017" language="Lua" purpose="LotJ Shop Equipment Database" save_state="y" requires="4.73" version="1.04">
<description trim="y">
<![CDATA[
This plugin allows storing of gear sold in shops, saving it to a local database for later searching and printing.
This plugin saves gear shop locations and collects gear stats which can then be searched and displayed, or equipment stats overlaid onto your worn equipment.
Use `shophelp` for detailed information about what commands this plugin offers.
]]>
</description>
</plugin>
<!-- Get our standard constants -->
<include name="constants.lua" />
<!-- Triggers -->
<triggers>
<!-- Shop equipment storing triggers -->
<trigger name="shopBegin" script="beginShop" match="^\(Ref\) \[Price(\s+)?\] \[Category(\s+)?\]( \[ Compare \])? Item$" regexp="y" enabled="y" group="LotJShopStart" sequence="100" />
<trigger name="shopCaptureItem" script="captureShopItem" match="^\((.*)\) \[(?P<price>[\s\d]+)\] \[(?P<category>.*?)\]( \[(?P<compare>.*)\])? (?P<item>.*)$" regexp="y" enabled="n" keep_evaluating="y" group="LotJShopGrab" sequence="100" />
<trigger name="shopOverlayItem" script="overlayItem" match="^\((.*)\) \[(?P<price>[\s\d]+)\] \[(?P<category>.*?)\]( \[(?P<compare>.*)\])? (?P<item>.*)$" regexp="y" enabled="n" keep_evaluating="y" group="LotJShopOverlay" sequence="100" />
<trigger name="shopEnd" script="endShop" match="^$" regexp="y" enabled="n" group="LotJShopGrab" sequence="100" />
<!-- Equipment stat storing aliases -->
<trigger name="examineStart" script="examineStart" match="^This is (?P<item>.*).$" regexp="y" enabled="n" group="LotJShopExamineStart" sequence="100" />
<trigger name="vendorExamineStart" script="examineStart" match="^(.*) allows you a close up look of (?P<item>.*).$" regexp="y" enabled="n" group="LotJShopExamineStart" sequence="100" />
<trigger name="examineGrabStat" script="examineFoundStat" match="^Affects (?P<stat>.*) by (?P<amount>.*)\.?$" regexp="y" enabled="n" group="LotJShopExamine" sequence="100" />
<trigger name="examineGrabCyber" script="examineFoundCyber" match="^This will enhance a patient with\: (?P<stat>.*)" regexp="y" enabled="n" group="LotJShopExamine" sequence="100" />
<trigger name="examineGrabWeight" script="examineFoundWeight" match="^Item Weight: (?P<weight>.*)$" regexp="y" enabled="n" group="LotJShopExamine" sequence="100" />
<trigger name="examineWearloc" script="examineFoundWearloc" match="^Wear locations: (?P<wearlocs>.*)$" regexp="y" enabled="n" group="LotJShopExamine" sequence="100" />
<trigger name="examineCharge" script="examineFoundCharge" match="^It has (?P<amount>.*) units of charge remaining\.$" regexp="y" enabled="n" group="LotJShopExamine" sequence="100" />
<trigger name="examineStop" script="examineStop" match="^$" regexp="y" enabled="n" keep_evaluating="y" group="LotJShopExamine" sequence="100" />
<!-- Worn equipment stat overlay triggers -->
<trigger name="overlayStart" script="overlayStart" match="^(You are (using|carrying)|(.*) contains):$" regexp="y" enabled="n" group="LotJOverlayStart" sequence="100" />
<trigger name="wornOverlayItem" script="overlayItem" match="^\<(.*)\> (?P<item>.*)$" regexp="y" enabled="n" group="LotJWornOverlay" sequence="100" />
<trigger name="wornOverlayStop" script="wornOverlayStop" match="^$" regexp="y" enabled="n" keep_evaluating="y" group="LotJWornOverlay" sequence="100" />
<trigger name="heldOverlayItem" script="overlayItem" match="^(\s+)(?P<item>.*)$" regexp="y" enabled="n" group="LotJHeldOverlay" sequence="100" />
<trigger name="heldOverlayStop" script="heldOverlayStop" match="^$" regexp="y" enabled="n" keep_evaluating="y" group="LotJHeldOverlay" sequence="100" />
</triggers>
<!-- Aliases -->
<aliases>
<!-- Shop equipment aliases -->
<alias name="shopToggle" script="toggleShop" match="^shopToggle(\s+(.*))?$" enabled="y" ignore_case="y" regexp="y" group="LotJShopDB" sequence="100" />
<alias name="shopFindItems" script="printFilterItems" match="^shopfind(\s?(?P<filter>.*))?$" enabled="y" ignore_case="y" regexp="y" group="LotJShopDB" sequence="100" />
<alias name="shopDeleteItems" script="deleteFilterItems" match="^shopdelete(\s?(?P<filter>.*))?$" enabled="y" ignore_case="y" regexp="y" group="LotJShopDB" sequence="100" />
<!-- Equipment stat storing aliases -->
<alias name="examineItem" script="examineItem" match="^examineItem(\s?(?P<item>.*))?$" enabled="y" ignore_case="y" regexp="y" group="LotJShopDB" sequence="100" />
<!-- Worn equipment stat overlay aliases -->
<alias name="overlayToggle" script="toggleOverlay" match="^shopOverlay(\s+(.*))?$" enabled="y" ignore_case="y" regexp="y" group="LotJShopDB" sequence="100" />
<alias match="^shophelp(\s*(.*))?$" script="shopHelp" enabled="y" regexp="y" ignore_case="y" group="LotJShopDB" sequence="100" />
</aliases>
<!-- Script -->
<script>
<![CDATA[
require "tprint"
require "serialize"
require "copytable"
dofile(GetPluginInfo(GetPluginID(), 20) .. "lotj_colors.lua")
dofile(GetPluginInfo(GetPluginID(), 20) .. "LotJMSDPHelper.lua")
local AUTHOR = GetPluginInfo(GetPluginID(), 2) -- author info
local VERSION = string.format("%1.2f", GetPluginInfo(GetPluginID(), 19)) -- version info
shopDB = {}
loadstring(GetVariable("shopDB") or "")()
eqdb = {}
loadstring(GetVariable("eqdb") or "")()
local transactCreate = 0
local transactUpdate = 0
local transactDelete = 0
local transactCaptured = 0
local shopToggle = true
local overlayToggle = true
function toggleShopOff()
shopToggle = false
ColourNote(db_main_color,"","[LotJShopDB] shop scanning is now OFF")
EnableTriggerGroup("LotJShopGrab", false)
EnableTriggerGroup("LotJShopStart", false)
end
function toggleShopOn()
shopToggle = true
ColourNote(db_main_color,"","[LotJShopDB] shop scanning is now ON")
EnableTriggerGroup("LotJShopStart", true)
end
function toggleShop(name, line, args)
if (args[1]:find("on")) then
toggleShopOn()
elseif (args[1]:find("off")) then
toggleShopOff()
else
if (shopToggle) then
toggleShopOff()
else
toggleShopOn()
end
end
end
function toggleOverlay(name, line, args)
if (args[1]:find("on")) then
toggleOverlayOn()
elseif (args[1]:find("off")) then
toggleOverlayOff()
else
if (overlayToggle) then
toggleOverlayOff()
else
toggleOverlayOn()
end
end
end
function toggleOverlayOff()
overlayToggle = false
ColourNote(db_main_color,"","[LotJShopDB] equipment overlays are now OFF")
EnableTriggerGroup("LotJWornOverlay", false)
EnableTriggerGroup("LotJOverlayStart", false)
EnableTriggerGroup("LotJShopOverlay", false)
end
function toggleOverlayOn()
overlayToggle = true
ColourNote(db_main_color,"","[LotJShopDB] equipment overlays are now ON")
EnableTriggerGroup("LotJOverlayStart", true)
EnableTriggerGroup("LotJShopOverlay", true)
end
local overlayTotals = {}
function overlayStart(name, line, args)
if args[0]:find("using") then -- enable worn overlay
EnableTriggerGroup("LotJWornOverlay", true)
overlayTotals = {}
elseif (args[0]:find("carrying") or args[0]:find("contains")) then -- enable held overlay
EnableTriggerGroup("LotJHeldOverlay", true)
end
end
function overlayItem(name, line, args, styles)
local item = stripName(removeItemTags(args.item))
for i, v in ipairs(eqdb) do
if (string.match(nameToString(v.name), item) and v.stats) then
DeleteLines(1)
for a, b in pairs(styles) do
ColourTell (RGBColourToName(b.textcolour or 111111), RGBColourToName(b.backcolour or 0), b.text)
end
local stats = printItemStats(v, true, false, false)
for k, v in pairs(stats) do
if overlayTotals[k] then -- stat already exists, add the value
if type(v)=="number" then
overlayTotals[k] = overlayTotals[k] + v
end
else
if type(v)=="table" then
overlayTotals[k] = table.deepcopy(v)
elseif type(v)=="string" then
overlayTotals[k] = v
elseif type(v)=="number" then
overlayTotals[k] = tonumber(v)
end
end
end
return
end
end
end
function wornOverlayStop(name, line, args)
if overlayTotals then -- we found some worn stats
local sortedTotals = {}
for k, v in pairs(overlayTotals) do
sortedTotals[#sortedTotals + 1] = {name = k, value = v}
end
table.sort(sortedTotals, function (k1, k2) return ((tonumber(k1.value) and k1.value) or 0) < ((tonumber(k2.value) and k2.value) or 0) end )
ColourTell(db_main_color,"","[",db_highlight_color,"","LotJShopDB",db_main_color,"","] Gear totals: ")
local num = 0
for k, v in pairs(sortedTotals) do
num = num + 1
if num >= 6 then -- limit stats to 6 per output line
Tell("\n"..string.rep(' ', 26))
num = 0
end
ColourTell(db_highlight_color,"",((((tonumber(v.value) and v.value>0) and "+") or "")..v.value.." "),db_main_color,"",v.name..((k==#sortedTotals and "") or ", "))
end
Note()
end
EnableTriggerGroup("LotJWornOverlay", false)
end
function heldOverlayStop(name, line, args)
EnableTriggerGroup("LotJHeldOverlay", false)
end
function removeItemTags(item)
item = item:gsub("%(.+%)", '')
item = Trim(item)
return item
end
local captureItem = {}
local captureItemStats = {}
function examineItem(name, line, args)
local list, stop = args.item:find("list")
if list then
Send("list"..args.item:sub(stop+1, #args.item).." examine")
else
Send("examine "..args.item)
end
EnableTriggerGroup("LotJShopExamineStart", true)
end
function examineStart(name, line, args, styles)
captureItem = {}
captureItemStats = {}
EnableTriggerGroup("LotJShopExamine", true)
EnableTriggerGroup("LotJShopExamineStart", false)
captureItem.name = args.item
captureItem.styledName = getStyledNameFromLine(line, args.item, styles)
beginTransaction()
end
function examineFoundStat(name, line, args)
if captureItemStats[Trim(args.stat)] then -- stat already exists, add more to the value
captureItemStats[Trim(args.stat)] = captureItemStats[Trim(args.stat)] + tonumber(args.amount)
else
captureItemStats[Trim(args.stat)] = tonumber(args.amount) or args.amount
end
end
function examineFoundCyber(name, line, args)
captureItem.cyber = args.stat
end
function examineFoundWeight(name, line, args)
captureItem.weight = tonumber(args.weight)
end
function examineFoundWearloc(name, line, args)
local locs = utils.split(Trim(args.wearlocs), " ")
captureItem.wearlocs = copytable.deep(locs)
end
function examineFoundCharge(name, line, args)
if captureItemStats["charge"] then
captureItemStats["charge"] = captureItemState["charge"] + tonumber(args.amount)
else
captureItemStats["charge"] = tonumber(args.amount) or args.amount
end
end
function examineStop()
captureItem.stats = copytable.deep(captureItemStats)
EnableTriggerGroup("LotJShopExamine", false)
EnableTriggerGroup("LotJShopExamineStart", false)
storeStatsToDB(captureItem)
endTransaction()
--ColourNote(db_main_color,"","[LotJShopDB] scanned "..transactCaptured.." items. "..transactCreate.." creates. "..transactUpdate.." updates.")
end
function storeStatsToDB(item)
local newItem = { name = item.styledName or item.name, weight = item.weight or 0, stats = copytable.deep(item.stats), cyber = item.cyber, wearlocs = copytable.deep(item.wearlocs) }
storeItemToDB(newItem)
end
function checkUpdated(existing, new)
if existing then return existing, nil end
if new then return new, 1 end
return nil, nil
end
function storeItemToDB(item)
transactCaptured = transactCaptured + 1
local strippedName = stripName(nameToString(item.name))
local found, duplicate = false, false
for i, v in ipairs(eqdb) do
if (string.match(nameToString(v.name),strippedName)) then -- found existing item that shares name after stripping
duplicate = (item.vnum and v.vnum and (item.vnum ~= v.vnum)) -- found a duplicate item with a different vnum, add it
found = true
local update = {}
eqdb[i].vnum, update.vnum = checkUpdated(v.vnum, item.vnum)
eqdb[i].planet, update.planet = checkUpdated(v.planet, item.planet)
eqdb[i].price, update.price = checkUpdated(v.price, item.price)
eqdb[i].category, update.category = checkUpdated(v.category, item.category)
eqdb[i].room, update.room = checkUpdated(v.room, item.room)
eqdb[i].name, update.name = checkUpdated(v.name, item.name)
eqdb[i].stats, update.stats = checkUpdated(v.stats, item.stats)
eqdb[i].cyber, update.cyber = checkUpdated(v.cyber, item.cyber)
-- check to see if we actually changed anything
if update.vnum or update.planet or update.price or update.category or update.room or update.name or update.stats or update.cyber then
transactUpdate = transactUpdate + 1
--else -- didn't update anything, overlay stored stats
-- local stats = printItemStats(v, true, false, false)
end
end
end
-- didn't find a matching item in the database add it now
if not found or duplicate then
eqdb[#eqdb + 1] = copytable.deep(item)
transactCreate = transactCreate + 1
end
end
function beginTransaction()
transactCreate = 0
transactUpdate = 0
transactDelete = 0
transactCaptured = 0
end
function endTransaction()
ColourNote(db_main_color,"","[LotJShopDB] scanned "..transactCaptured.." item"..((transactCaptured ~= 1 and "s") or "")..". "..transactCreate.." creates. "..transactUpdate.." updates.")
end
function beginShop(name, line, args)
EnableTriggerGroup('LotJShopGrab', true)
beginTransaction()
end
function stripName(name)
name = strip_colours(name) -- remove colors
name = name:gsub("%A", "%%A") -- escape non-word characters for pattern matching
return name
end
function nameToString(name)
local out = ""
if (type(name)=="table") then
for _, v in ipairs(name) do
out = out .. v.text
end
elseif type(name)=="number" then
out = out .. name
else
out = name
end
return out
end
function getStyledNameFromLine(line, name, styles)
local strippedName = stripName(name)
local startIndex, endIndex = string.find(line, strippedName)
local trimmedStyles = StylesToColoursOneLine(styles, startIndex, endIndex)
local styledName = ColoursToStyles(trimmedStyles)
return styledName
end
function captureShopItem(name, line, args, styles)
local planet = getmsdp("PLANET") or "Unknown"
local room = getmsdp("ROOMNAME") or "Unknown"
local vnum = getmsdp("ROOMVNUM") or "Unknown"
local styledName = getStyledNameFromLine(args[0], args.item, styles)
local item = { name = styledName or args.item, price = tonumber(args.price), category = Trim(args.category), planet = planet, room = room, vnum = vnum }
storeItemToDB(item)
end
function endShop(name, line, args)
EnableTriggerGroup('LotJShopGrab', false)
endTransaction()
end
function printAllItems()
local m1, m2, m3, m4 = findMaxFilterLengths(eqdb)
ColourNote(db_main_color,"","Printing all items in LotJShopDB:")
for i,v in ipairs(eqdb) do
printItem(i, v, m1, m2, m3, m4)
end
ColourNote(db_highlight_color,"",#eqdb,db_main_color,""," items in LotJShopDB.")
end
function itemToString(item)
local itemString = ""
for k,v in pairs(item) do
if (type(v)=="table") then
if k ~= "stats" and k ~= "wearlocs" then
for k, j in ipairs(v) do
itemString = itemString .. j.text
end
end
elseif type(v) == "string" then
itemString = itemString .. " " .. v
elseif type(v) == "number" then
itemString = itemString .. " " .. v
end
end
return itemString
end
function filterMatchesItem(item, filter)
local filter = stripName(filter:lower())
local itemString = itemToString(item):lower()
return string.match(itemString, filter)
-- return string.match(item.name:lower(), filter) or string.match(item.planet:lower(), filter) or string.match(item.category:lower(), filter) or string.match(item.room:lower(), filter)
end
function printFilterItems(name, line, args)
if (args.filter~="") then -- found an argument
local found = 0
local filter = utils.split(Trim(args.filter):lower(), ' ')
local items = {}
-- first gather items from main db that match first filter term
for k, j in ipairs(filter) do
if k == 1 then -- first filter item
for i, v in ipairs(eqdb) do
if filterMatchesItem(v, j) then
items[#items+1] = v -- store matching item into matching item list
end
end
else -- second filter item and beyond
local i = 0
while i < #items do
i = i + 1
local v = items[i]
if not filterMatchesItem(v, j) then
table.remove(items, i)
i = i - 1
end
end
end
end
local w1, w2, w3, w4 = findMaxFilterLengths(items)
ColourNote(db_main_color,"","Printing items in LotJShopDB matching ",db_highlight_color,"",table.concat(filter, " "),db_main_color,"",":")
for i,v in ipairs(items) do
printItem(i, v, w1, w2, w3, w4)
end
if #items > 0 then
ColourNote(db_main_color,""," ",db_highlight_color,"",#items,db_main_color,""," items matched.")
else
ColourNote(db_main_color,""," None.")
end
else
printAllItems()
end
end
function findMaxFilterLengths(items)
local w1, m2, w2, w3, w4 = 0, 0, 0, 0, 0
-- find max widths
-- If these variables are not found the width defaults to 7 because
-- we will print "Unknown" if they don't exist
for i,v in ipairs(items) do
if (((v.planet and #v.planet) or 7) > w1) then
w1 = ((v.planet and #v.planet) or 7)
end
if (((v.price and v.price) or 0) > m2) then
m2 = ((v.price and v.price) or 0)
end
if (((v.category and #v.category) or 7) > w3) then
w3 = ((v.category and #v.category) or 7)
end
if (((v.room and #v.room) or 7) > w4) then
w4 = ((v.room and #v.room) or 7)
end
end
local m = 1
while (m < m2) do
w2 = w2 + 1
m = m * 10
end
return w1+1, w2+1, w3+1, w4+1
end
db_main_color = "silver"
db_highlight_color = "cyan"
-- quick function to check if there are any stats in the item table
function hasStats(item)
for k, v in pairs(item.stats) do
return true
end
return false
end
function printItemStats(item, abbrev, showWeight, showWearlocs)
local stats = {}
if (showWeight and item.weight) or (item.stats and hasStats(item)) or (showWearlocs and item.wearlocs) or item.cyber then
ColourTell(db_main_color,""," (")
end
if showWeight and item.weight then
ColourTell(db_main_color,"","Weight:",db_highlight_color,"",item.weight.." ")
end
if item.weight then
stats.weight = item.weight
end
if item.cyber then
ColourTell(db_highlight_color,"",item.cyber..((hasStats(item) and " ") or ""))
stats.cyber = item.cyber
end
if item.stats and hasStats(item) then
local out = {}
for stat, amt in pairs(item.stats) do
stat = (stat:find("armor") and "armor") or stat
out[#out + 1] = {stat = stat, amt = amt}
if stats[stat] then
stats[stat] = stats[stat] + amt
else
stats[stat] = amt
end
end
for i, v in ipairs(out) do
-- don't abbreviate 'charge' stat because it becomes (cha) which can be mistaken with Charisma
ColourTell(db_highlight_color,"",((((tonumber(v.amt) and v.amt>0) and "+") or "")..v.amt.." "),db_main_color,"",(((abbrev and (v.stat ~= "charge")) and v.stat:sub(1,3)) or v.stat)..((i < #out and " ") or ""))
end
end
if showWearlocs and item.wearlocs then
ColourTell(db_main_color,""," Wear locs:",db_highlight_color,"",table.concat(item.wearlocs," "))
end
if (showWeight and item.weight) or (item.stats and hasStats(item)) or (showWearlocs and item.wearlocs) or item.cyber then
ColourTell(db_main_color,"",")")
end
-- returning the stats that we printed in order to calculate total worn stats
return stats
end
function printItemName(item)
if (type(item.name) == "string") then
ColourTell(db_highlight_color, "", item.name,db_main_color,"","]")
elseif (type(item.name) == "table") then
for _, v in ipairs(item.name) do
ColourTell(RGBColourToName(v.textcolour or 111111), RGBColourToName(v.backcolour or 000000), v.text)
end
ColourTell(db_main_color, "", "]")
end
end
function printItem(i, item, w1, w2, w3, w4)
local planetWidth = w1 or 15
local priceWidth = w2 or 7
local catWidth = w3 or 15
local roomWidth = w4 or 20
ColourTell(db_main_color,"","(",db_highlight_color,"",string.format("%3d", i),db_main_color,"",") ["
,db_highlight_color,"",string.format("%-"..planetWidth.."s", item.planet or "Unknown"),db_main_color,"","] ["
,db_main_color,"",string.format("%-"..roomWidth.."s", item.room or "Unknown"), db_main_color,"","] ["
,"yellow","",string.format("%-"..priceWidth.."d", item.price or 0),db_main_color,"","] ["
,"lime","",string.format("%-"..catWidth.."s", item.category or "Unknown"),db_main_color,"","] [")
printItemName(item)
printItemStats(item, false, false, false)
Note()
end
function clearItems()
eqdb = {}
ColourNote(db_main_color,"","[",db_highlight_color,"","LotJShopDB",db_main_color,"","] database cleared.")
OnPluginSaveState()
end
function deleteFilterItems(name, linem, args)
if (args.filter~="") then -- found an argument
local found = 0
local filter = Trim(args.filter)
if (tonumber(filter)) then
filter = tonumber(filter)
end
ColourNote(db_main_color,"","Deleting items in LotJShopDB matching ",db_highlight_color,"",filter,db_main_color,"",":")
if (tonumber(filter)) then
deleteItem(filter)
found = found + 1
else
for i, v in ipairs(eqdb) do
if (filterMatchesItem(v, filter)) then
deleteItem(i)
found = found + 1
end
end
end
if found then
ColourNote(db_main_color,""," ".. found .. " items deleted.")
else
ColourNote(db_main_color,""," None.")
end
else
clearItems()
end
end
function deleteItem(i)
assert(type(i)=="number")
if (i < 0 or i > #eqdb) then
ColourNote(db_highlight_color,"","Invalid attempt to delete LotJShopDB item at index ".. i)
return
end
if (type(eqdb[i].name == "table")) then
ColourTell(db_highlight_color,"","Deleted item ")
for i, v in ipairs(eqdb[i].name) do
ColourTell(RGBColourToName(v.textcolour or 111111), RGBColourToName(v.backcolour or 000000), v.text)
end
ColourTell(db_highlight_color,"", " from database.\n")
else
ColourNote(db_highlight_color,"","Deleted item ".. eqdb[i].name .. " from database.")
end
table.remove(eqdb, i)
end
function OnPluginSaveState()
SetVariable("eqdb", ((eqdb and serialize.save("eqdb")) or ""))
SetVariable("shopToggle", tostring(shopToggle))
SetVariable("overlayToggle", tostring(overlayToggle))
end
function OnPluginInstall()
loadstring(GetVariable("eqdb") or "")()
shopToggle = GetVariable("shopToggle") == "true"
EnableTriggerGroup("LotJShopStart", shopToggle)
overlayToggle = GetVariable("overlayToggle") == "true"
EnableTriggerGroup("LotJOverlayStart", overlayToggle)
EnableTriggerGroup("LotJShopOverlay", overlayToggle)
end
-- define our help command structure
local commands = {
{ name = "shopToggle", desc = "Toggles automatic shop equipment scanning.",
args = { { name="<none>" , desc = "Toggles the state of automatic shop equipment scanning." },
{ name="<on/off>" , desc = "Indicates the desired state of automatic shop equipment scanning." }, }
},
{ name = "shopOverlay", desc = "Toggles equipment stat overlays.",
args = { { name="<none>" , desc = "Toggles the state of equipment stat overlays." },
{ name="<on/off>" , desc = "Indicates the desired state of equipment stat overlays." }, },
},
{ name = "shopFind", desc = "Searches the database for stored equipment.",
args = { { name = "<none>", desc = "Prints every item currently stored in the equipment database." },
{ name = "<searchTerm>", desc = "Searches the database for items matching the given search term and prints them.\nNotice: Will match the item description, planet, equipment type, or shop location."}, }
},
{ name = "shopDelete", desc = "Deletes items from the equipment database.",
args = { { name = "<none>", desc = "Clears the equipment database."},
{ name = "<searchTerm>", desc = "Searches the database for the first item matching the given search term and deletes it.\nNotice: This will match the item index number, item description, planet, equipment type, or shop location."}, }
},
{ name = "examineItem", desc = "Examines an item attempting to grab the item stats.",
args = { { name = "list <item/#>", desc = "Examine an item currently for sale in a shop by keyword or index #." },
{ name = "<item>", desc = "Keyword of item to be examined for stats."}, }
},
{ name = "shopHelp", desc = "Displays this help file.",
args = { { name = "<command>", desc = "Displays more detailed information on the specified command."}, }
},
}
function shopHelp(name, line, args)
local found = false
if args[1] == "" then -- show general help
ColourNote("white","",GetPluginInfo(GetPluginID(), 1),"cyan",""," v"..VERSION,"white",""," by "..AUTHOR..". Enter '","red","","shophelp <command>","white","","' for more detailed information.")
for a, b in ipairs(commands) do -- commands
local command = b
ColourNote("red","",string.format("%-20s", command.name),"silver",""," : "..command.desc)
end
Note()
else -- entered something
ColourNote("white","",GetPluginInfo(GetPluginID(), 1),"cyan",""," v"..VERSION,"white",""," by "..AUTHOR..". Enter '","red","","shophelp","white","","' for more general information.")
for a, b in ipairs(commands) do -- scroll through commands
if (string.match(b.name:lower(), Trim(args[1]):lower())) then -- found our argument, using string match allows for partial matches
found = true
ColourNote("red","",b.name,"silver",""," : " .. b.desc)
ColourNote("silver","","Available arguments:")
if #b.args == 0 then -- no arguments
ColourNote("red",""," None.")
else -- arguments to print
for i, k in ipairs(b.args) do
ColourNote("red","",string.format("%20s", k.name),"silver",""," : " .. k.desc)
end -- end print arguments
end -- end no arguments
Note()
end -- end found command
end -- end scroll commands
if not found then
ColourNote("red","","Command '"..args[1].."' not found.")
end
end -- end no input
end
]]>
</script>
</muclient>