-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.lua
More file actions
3147 lines (2975 loc) · 112 KB
/
init.lua
File metadata and controls
3147 lines (2975 loc) · 112 KB
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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
Created by Special.Ed
Shout out to the homies:
Lads
Dannuic (my on again off again thing)
Knightly (no, i won't take that bet)
--]]
--[[
Modified by Grimmier
Added a GUI and commands.
** Commands **
* /alertmaster show will toggle the search window.
* /alertmaster popup will toggle the alert popup window.
** Search Window **
* You can search with the search box
* Clicking the check box for track, and the spawn will be added to spawnlist
* Clicking ignore will remove the spawn from the list if it exists.
* you can navTo any spawn in the search window by clicking the button, rightclicking the name will target the spawn.
** Alert Window **
* The Alert Popup Window lists the spawns that you are tracking and are alive. Shown as "Name : Distance"
* Clicking the button on the Alert Window will NavTo the spawn.
* Closing the Alert Popup will keep it closed until something changes or your remind timer is up.
* remind setting is in minutes.
]]
local LIP = require('lib.lip')
local mq = require('mq')
local ImGui = require('ImGui')
local ZoneNames = require("defaults.ZoneNames")
Module = {}
Module.Name = 'AlertMaster'
Module.Path = string.format("%s/%s/", mq.luaDir, Module.Name)
if mq.TLO.EverQuest.GameState() ~= "INGAME" then
printf("\aw[\at%s\ax] \arNot in game, \ayTry again later...", Module.Name)
mq.exit()
end
---@diagnostic disable-next-line:undefined-global
local loadedExeternally = MyUI_ScriptName ~= nil and true or false
if not loadedExeternally then
Module.Utils = require('lib.common')
Module.CharLoaded = mq.TLO.Me.DisplayName()
Module.Colors = require('lib.colors')
Module.Guild = mq.TLO.Me.Guild() or 'NoGuild'
Module.Icons = require('mq.ICONS')
Module.ThemeLoader = require('lib.theme_loader')
Module.ThemeFile = Module.ThemeFile == nil and string.format('%s/MyUI/ThemeZ.lua', mq.configDir) or Module.ThemeFile
Module.Theme = require('defaults.themes')
Module.Path = string.format("%s/%s/", mq.luaDir, Module.Name)
Module.Server = mq.TLO.EverQuest.Server()
Module.Build = mq.TLO.MacroQuest.BuildName()
Module.PackageMan = require('mq.PackageMan')
Module.SQLite3 = Module.PackageMan.Require('lsqlite3')
Module.Actors = require('actors')
else
Module.Utils = MyUI_Utils
Module.CharLoaded = MyUI_CharLoaded
Module.Colors = MyUI_Colors
Module.Guild = MyUI_Guild
Module.Icons = MyUI_Icons
Module.ThemeLoader = MyUI_ThemeLoader
Module.ThemeFile = MyUI_ThemeFile
Module.Theme = MyUI_Theme
Module.Path = MyUI_Path
Module.Server = MyUI_Server
Module.Build = MyUI_Build
Module.SQLite3 = MyUI_SQLite3
Module.Actors = MyUI_Actor
end
Module.ActorMailBox = 'alertmaster'
Module.SoundPath = string.format("%s/sounds/default/",
Module.Path)
local Utils = Module.Utils
local ToggleFlags = bit32.bor(
Utils.ImGuiToggleFlags.PulseOnHover,
Utils.ImGuiToggleFlags.RightLabel)
-- Variables
local arg = { ..., }
local amVer = '2.07'
local SpawnCount = mq.TLO.SpawnCount
local NearestSpawn = mq.TLO.NearestSpawn
local smSettings = mq.configDir .. '/MQ2SpawnMaster.ini'
local config_dir = mq.TLO.MacroQuest.Path():gsub('\\', '/')
local settings_file = '/config/AlertMaster.ini'
local settings_path = config_dir .. settings_file
local smImportList = mq.configDir .. '/am_imports.lua'
local Group = mq.TLO.Group
local Raid = mq.TLO.Raid
local Zone = mq.TLO.Zone
local groupCmd = '/dgae ' -- assumes DanNet, if EQBC found we switch to '/bcca /'
local angle = 0
local CharConfig = 'Char_' ..
mq.TLO.Me.DisplayName() .. '_Config'
local CharCommands = 'Char_' ..
mq.TLO.Me.DisplayName() .. '_Commands'
local newConfigFile = string.format(
"%s/MyUI/AlertMaster/%s/%s.lua", mq.configDir, Module.Server, Module.CharLoaded)
local defaultConfig = {
delay = 1,
remindNPC = 5,
remind = 30,
aggro = false,
pcs = true,
spawns = true,
gms = true,
announce = false,
ignoreguild = true,
beep = false,
popup = false,
distmid = 600,
distfar = 1200,
locked = false,
}
local tSafeZones, spawnAlerts, spawnsSpawnMaster, settings = {}, {}, {}, {}
local npcs, tAnnounce, tPlayers, tSpawns, tGMs = {}, {}, {}, {}, {}
local alertTime, numAlerts = 0, 0
local volNPC, volGM, volPC, volPCEntered, volPCLeft = 100, 100, 100, 100, 100
local zone_id = Zone.ID() or 0
local soundGM = 'GM.wav'
local soundNPC = 'NPC.wav'
local soundPC = 'PC.wav'
local soundPCEntered = 'PCEntered.wav'
local soundPCLeft = 'PCLeft.wav'
local doBeep, doAlert, DoDrawArrow, haveSM, importZone, doSoundNPC, doSoundGM, doSoundPC, forceImport, doSoundPCEntered, doSoundPCLeft = false, false, false, false, false, false,
false, false, false, false, false
local delay, remind, pcs, spawns, gms, announce, ignoreguild, radius, zradius, remindNPC, showAggro = 1, 30, true, true, true, false, true, 100,
100, 5, true
-- [[ UI ]] --
local AlertWindow_Show, AlertWindowOpen, SearchWindowOpen, SearchWindow_Show, showTooltips, active = false, false, false, false, true, false
local currentTab = "zone"
local newSpawnName = ''
local zSettings = false
local useThemeName = 'Default'
local openConfigGUI = false
local ZoomLvl = 1.0
local doOnce = true
local importedZones = {}
local originalVolume = 50
local playTime = 0
local playing = false
local currZone, lastZone
-- local newSMFile = mq.configDir .. '/MyUI/MQ2SpawnMaster.ini'
local execCommands = false
local displayTablePlayers = {}
local numDisplayPlayers = 0
local DistColorRanges = {
orange = 600, -- distance the color changes from green to orange
red = 1200, -- distance the color changes from orange to red
}
local Table_Cache = {
Rules = {},
Unhandled = {},
Mobs = {},
Alerts = {},
}
local xTarTable = {}
local spawnListFlags = bit32.bor(
ImGuiTableFlags.Resizable,
ImGuiTableFlags.Sortable,
-- ImGuiTableFlags.SizingFixedFit,
ImGuiTableFlags.BordersV,
ImGuiTableFlags.BordersOuter,
ImGuiTableFlags.Reorderable,
ImGuiTableFlags.ScrollY,
ImGuiTableFlags.Hideable
)
Module.IsRunning = false
Module.GUI_Main = {
Open = false,
Show = false,
Locked = false,
Flags = bit32.bor(
ImGuiWindowFlags.None,
ImGuiWindowFlags.MenuBar
--ImGuiWindowFlags.NoSavedSettings
),
Refresh = {
Sort = {
Rules = true,
Filtered = true,
Unhandled = true,
Mobs = false,
},
Table = {
Rules = true,
Filtered = true,
Unhandled = true,
Mobs = false,
},
},
Search = '',
Table = {
Column_ID = {
ID = 1,
MobName = 2,
MobDirtyName = 3,
MobLoc = 4,
MobZoneName = 5,
MobDist = 6,
MobID = 7,
Action = 8,
Remove = 9,
MobLvl = 10,
MobConColor = 11,
MobAggro = 12,
MobDirection = 13,
Enum_Action = 14,
},
Flags = bit32.bor(
ImGuiTableFlags.Resizable,
ImGuiTableFlags.Sortable,
--ImGuiTableFlags.RowBg,
--ImGuiTableFlags.NoKeepColumnsVisible,
--ImGuiTableFlags.SizingFixedFit,
-- ImGuiTableFlags.MultiSortable, -- MultiSort seems to not work at all.
ImGuiTableFlags.NoBordersInBodyUntilResize,
--ImGuiTableFlags.BordersOuter,
ImGuiTableFlags.Reorderable,
ImGuiTableFlags.ScrollY,
ImGuiTableFlags.Hideable
),
SortSpecs = {
Rules = nil,
Unhandled = nil,
Filtered = nil,
Mobs = nil,
},
},
}
Module.GUI_Alert = {
Open = false,
Show = false,
Locked = false,
Flags = bit32.bor(ImGuiWindowFlags.NoCollapse),
Refresh = {
Sort = {
Rules = true,
Filtered = true,
Unhandled = true,
Mobs = false,
Alerts = true,
},
Table = {
Rules = true,
Filtered = true,
Unhandled = true,
Mobs = false,
Alerts = true,
},
},
Table = {
Column_ID = {
ID = 1,
MobName = 2,
MobDist = 3,
MobID = 4,
MobDirection = 5,
},
Flags = bit32.bor(
ImGuiTableFlags.Resizable,
ImGuiTableFlags.Sortable,
ImGuiTableFlags.SizingFixedFit,
ImGuiTableFlags.BordersV,
ImGuiTableFlags.BordersOuter,
ImGuiTableFlags.Reorderable,
ImGuiTableFlags.ScrollY,
ImGuiTableFlags.Hideable
),
SortSpecs = {
Rules = nil,
Unhandled = nil,
Filtered = nil,
Mobs = nil,
Alerts = nil,
},
},
}
Module.Settings = {}
Module.Settings[CharConfig] = {}
Module.Settings[CharCommands] = {}
Module.DBPath = string.format(
"%s/MyUI/AlertMaster/%s/AlertMasterSpawns.db", mq.configDir, Module.Server)
Module.WatchedSpawns = {}
local pSuccess = false
pSuccess, Module.ZoneList = pcall(require, 'lib.zone-list')
if not pSuccess then Module.ZoneList = {} end
Module.TempSettings = {}
------- Sounds ----------
local ffi = require("ffi")
-- C code definitions
ffi.cdef [[
int sndPlaySoundA(const char *pszSound, unsigned int fdwSound);
uint32_t waveOutSetVolume(void* hwo, uint32_t dwVolume);
uint32_t waveOutGetVolume(void* hwo, uint32_t* pdwVolume);
]]
local winmm = ffi.load("winmm")
local SND_ASYNC = 0x0001
local SND_LOOP = 0x0008
local SND_FILENAME = 0x00020000
local flags = SND_FILENAME + SND_ASYNC
local function getVolume()
local pdwVolume = ffi.new("uint32_t[1]")
winmm.waveOutGetVolume(nil, pdwVolume)
return pdwVolume[0]
end
local function resetVolume()
winmm.waveOutSetVolume(nil, originalVolume)
playTime = 0
playing = false
end
-- Function to play sound allowing for simultaneous plays
local function playSound(name)
local filename = Module.SoundPath .. name
playTime = os.time()
playing = true
winmm.sndPlaySoundA(filename, flags)
end
-- Function to set volume (affects all sounds globally)
local function setVolume(volume)
if volume < 0 or volume > 100 then
error("Volume must be between 0 and 100")
end
local vol = math.floor(volume / 100 * 0xFFFF)
local leftRightVolume = bit32.bor(bit32.lshift(vol, 16), vol) -- Set both left and right volume
winmm.waveOutSetVolume(nil, leftRightVolume)
end
-- helpers
local function MsgPrefix()
return string.format('\aw[\a-tAlert Master\aw] ::\ax ')
end
local function GetCharZone()
return '\aw[\ao' .. Module.CharLoaded .. '\aw] [\at' .. Zone.ShortName() .. '\aw] '
end
function Module:OpenDB()
local db = Module.SQLite3.open(Module.DBPath)
if not db then
Module.Utils.PrintOutput('MyUI', nil, "Failed to open the AlertMaster Database")
return nil
end
if db then
db:busy_timeout(2000)
end
return db
end
function Module.LoadSpawnsDB()
if not Module.Utils.File.Exists(Module.DBPath) then
-- Create the database and its table if it doesn't exist
Module.Utils.PrintOutput('MyUI', nil, "Creating the AlertMaster Database")
local db = Module.SQLite3.open(Module.DBPath)
db:exec("PRAGMA journal_mode=WAL;")
db:exec("BEGIN TRANSACTION")
db:exec [[
CREATE TABLE IF NOT EXISTS npc_spawns (
"zone_short" TEXT NOT NULL,
"spawn_name" TEXT NOT NULL,
"id" INTEGER PRIMARY KEY AUTOINCREMENT
);
]]
db:exec [[
CREATE TABLE IF NOT EXISTS pc_ignore (
"pc_name" TEXT NOT NULL UNIQUE,
"id" INTEGER PRIMARY KEY AUTOINCREMENT
);
]]
db:exec [[
CREATE TABLE IF NOT EXISTS safe_zones (
"zone_short" TEXT NOT NULL UNIQUE,
"id" INTEGER PRIMARY KEY AUTOINCREMENT
);
]]
db:exec("COMMIT")
db:exec("PRAGMA wal_checkpoint;")
-- import existing settings and spawns lists
db:exec("BEGIN TRANSACTION")
for zone, spawn in pairs(settings) do
if type(spawn) == 'table' and zone ~= 'SafeZones' and zone ~= 'Ignore' and not zone:find("^Char_") then
for key, spawnName in pairs(spawn) do
if key:find("Spawn") then
local stmt = db:prepare("INSERT INTO npc_spawns (zone_short, spawn_name) VALUES (?, ?);")
stmt:bind_values(zone, spawnName)
stmt:step()
stmt:finalize()
end
end
end
end
for _, pcName in pairs(settings.Ignore or {}) do
local stmt = db:prepare("INSERT INTO pc_ignore (pc_name) VALUES (?);")
stmt:bind_values(pcName)
stmt:step()
stmt:finalize()
end
for _, zoneShort in pairs(settings.SafeZones or {}) do
local stmt = db:prepare("INSERT INTO safe_zones (zone_short) VALUES (?);")
stmt:bind_values(zoneShort)
stmt:step()
stmt:finalize()
end
db:exec("COMMIT")
db:exec("PRAGMA wal_checkpoint;")
db:close()
end
end
--- Retrieve the spawns list for the current zone and return a table
---@param zoneShort any
function Module:GetSpawns(zoneShort, db)
if zoneShort == nil then zoneShort = Zone.ShortName() end
if not db then
Module.Utils.PrintOutput('MyUI', nil, "Failed to open the AlertMaster Database")
return {}
end
local WatchedSpawns = {}
local qry = string.format("SELECT spawn_name FROM npc_spawns WHERE zone_short = '%s'", zoneShort)
local stmt, err = db:prepare(qry)
if not stmt then
Module.Utils.PrintOutput('MyUI', nil, "Failed to prepare SQL statement: " .. err)
return {}
end
for row in stmt:nrows() do
if row.spawn_name and row.spawn_name ~= "" then
table.insert(WatchedSpawns, row.spawn_name)
end
end
stmt:finalize()
return WatchedSpawns
end
function Module:GetIgnoredPlayers(db)
if not db then
Module.Utils.PrintOutput('MyUI', nil, "Failed to open the AlertMaster Database")
return {}
end
local ignoredPlayers = {}
local stmt, err = db:prepare("SELECT pc_name FROM pc_ignore")
if not stmt then
Module.Utils.PrintOutput('MyUI', nil, "Failed to prepare SQL statement: " .. err)
return {}
end
for row in stmt:nrows() do
if row.pc_name and row.pc_name ~= "" then
table.insert(ignoredPlayers, row.pc_name)
end
end
stmt:finalize()
return ignoredPlayers
end
function Module:GetSafeZones(db)
if not db then
Module.Utils.PrintOutput('MyUI', nil, "Failed to open the AlertMaster Database")
return {}
end
local safeZones = {}
local stmt, err = db:prepare("SELECT * FROM safe_zones")
if not stmt then
Module.Utils.PrintOutput('MyUI', nil, "Failed to prepare SQL statement: " .. err)
return {}
end
for row in stmt:nrows() do
if row.zone_short and row.zone_short ~= "" then
table.insert(safeZones, row.zone_short)
end
end
stmt:finalize()
return safeZones
end
function Module:AddSafeZone(zoneShort)
local db = self:OpenDB()
if not db then
Module.Utils.PrintOutput('MyUI', nil, "Failed to open the AlertMaster Database")
return false
end
-- check for exiting
local existingStmt, errCheck = db:prepare("SELECT zone_short FROM safe_zones WHERE zone_short = ?")
if not existingStmt then
Module.Utils.PrintOutput('MyUI', nil, "Failed to prepare SQL statement: " .. errCheck)
db:close()
return false
end
existingStmt:bind_values(zoneShort)
local exists = existingStmt:step() == Module.SQLite3.ROW
existingStmt:finalize()
if exists then
db:close()
return false
end
-- skip conflicts
local qry = string.format("INSERT OR IGNORE INTO safe_zones (zone_short) VALUES ('%s')", zoneShort)
local stmt, err = db:prepare(qry)
if not stmt then
Module.Utils.PrintOutput('MyUI', nil, "Failed to prepare SQL statement: " .. err)
db:close()
return false
end
local result = stmt:step()
stmt:finalize()
if db then db:close() end
return result == Module.SQLite3.DONE
end
function Module:AddIgnorePCtoDB(pcName)
local db = self:OpenDB()
if not db then
Module.Utils.PrintOutput('MyUI', nil, "Failed to open the AlertMaster Database")
return false
end
-- check for existing entry
local existingStmt = db:prepare("SELECT pc_name FROM pc_ignore WHERE pc_name = ?")
existingStmt:bind_values(pcName)
local exists = existingStmt:step() == Module.SQLite3.ROW
existingStmt:finalize()
if exists then
db:close()
return false
end
-- skip conflicts
local stmt = db:prepare("INSERT OR IGNORE INTO pc_ignore (pc_name) VALUES (?)")
stmt:bind_values(pcName)
local result = stmt:step()
stmt:finalize()
if db then db:close() end
return result == Module.SQLite3.DONE
end
function Module:RemoveSafeZone(zoneShort)
local db = self:OpenDB()
if not db then
Module.Utils.PrintOutput('MyUI', nil, "Failed to open the AlertMaster Database")
return false
end
local stmt = db:prepare("DELETE FROM safe_zones WHERE zone_short = ?")
stmt:bind_values(zoneShort)
local result = stmt:step()
stmt:finalize()
if db then db:close() end
return result == Module.SQLite3.DONE
end
function Module:RemoveIgnoredPC(pcName)
local db = self:OpenDB()
if not db then
Module.Utils.PrintOutput('MyUI', nil, "Failed to open the AlertMaster Database")
return false
end
local stmt = db:prepare("DELETE FROM pc_ignore WHERE pc_name = ?")
stmt:bind_values(pcName)
local result = stmt:step()
stmt:finalize()
if db then db:close() end
return result == Module.SQLite3.DONE
end
function Module:AddSpawnToDB(zoneShort, spawnName)
local db = self:OpenDB()
if not db then
Module.Utils.PrintOutput('MyUI', nil, "Failed to open the AlertMaster Database")
return false
end
-- check for existing entry
local existingStmt = db:prepare("SELECT zone_short FROM npc_spawns WHERE zone_short = ? AND spawn_name = ?")
existingStmt:bind_values(zoneShort, spawnName)
local exists = existingStmt:step() == Module.SQLite3.ROW
existingStmt:finalize()
if exists then
db:close()
return false
end
-- skip conflicts
db:exec("BEGIN TRANSACTION")
local stmt = db:prepare("INSERT OR IGNORE INTO npc_spawns (zone_short, spawn_name) VALUES (?, ?)")
stmt:bind_values(zoneShort, spawnName)
local result = stmt:step()
stmt:finalize()
db:exec("COMMIT")
if db then db:close() end
return result == Module.SQLite3.DONE
end
function Module:DeleteSpawnFromDB(zoneShort, spawnName)
local db = self:OpenDB()
if not db then
Module.Utils.PrintOutput('MyUI', nil, "Failed to open the AlertMaster Database")
return false
end
local stmt = db:prepare("DELETE FROM npc_spawns WHERE zone_short = ? AND spawn_name = ?")
stmt:bind_values(zoneShort, spawnName)
local result = stmt:step()
stmt:finalize()
if db then db:close() end
return result == Module.SQLite3.DONE
end
local function print_status()
Module.Utils.PrintOutput('AlertMaster', nil, '\ayAlert Status: ' .. tostring(active and 'on' or 'off'))
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tPCs: \a-y' ..
tostring(pcs) ..
'\ax radius: \a-y' .. tostring(radius) .. '\ax zradius: \a-y' .. tostring(zradius) .. '\ax delay: \a-y' .. tostring(delay) ..
's\ax remind: \a-y' .. tostring(remind) .. ' seconds\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tremindNPC: \a-y' .. tostring(remindNPC) .. '\at minutes\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\agClose Range\a-t Below: \a-g' .. tostring(DistColorRanges.orange) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\aoMid Range\a-t Between: \a-g' .. tostring(DistColorRanges.orange) .. '\a-t and \a-r' .. tostring(DistColorRanges.red) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\arLong Rage\a-t Greater than: \a-r' .. tostring(DistColorRanges.red) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tAnnounce PCs: \a-y' .. tostring(announce) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tSpawns (zone wide): \a-y' .. tostring(spawns) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tGMs (zone wide): \a-y' .. tostring(gms) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tPopup Alerts: \a-y' .. tostring(doAlert) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tBeep: \a-y' .. tostring(doBeep) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tSound PC Alerts: \a-y' .. tostring(doSoundPC) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tSound NPC Alerts: \a-y' .. tostring(doSoundNPC) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tSound GM Alerts: \a-y' .. tostring(doSoundGM) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tVolume PC Alerts: \a-y' .. tostring(volPC) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tVolume NPC Alerts: \a-y' .. tostring(volNPC) .. '\ax')
Module.Utils.PrintOutput('AlertMaster', nil, '\a-tVolume GM Alerts: \a-y' .. tostring(volGM) .. '\ax')
end
local function save_settings()
-- LIP.save(settings_path, settings)
mq.pickle(newConfigFile, Module.Settings)
end
---comment
---@return boolean
local function check_safe_zone()
return settings.SafeZones[Zone.ShortName()] ~= nil
end
function Module:UpdateIgnoredPlayers()
settings.Ignore = {}
settings.Ignore = Module:GetIgnoredPlayers()
end
local function import_spawnmaster(val)
local zoneShort = Zone.ShortName()
local val_str = tostring(val):gsub("\"", "")
if zoneShort ~= nil then
local flag = true -- assume we are adding a new spawn
local count = 0
-- if settings[zoneShort] == nil then settings[zoneShort] = {} end
-- -- if the zone does exist in the ini, spin over entries and make sure we aren't duplicating
-- for k, v in pairs(settings[zoneShort]) do
-- if string.find(v, val_str) then
-- flag = false
-- end
-- if flag then
-- count = count + 1
-- end
-- end
for _, v in ipairs(Module.TempSettings.NpcList) do
if v == val_str then
flag = false
break
end
end
importedZones[zoneShort] = true
mq.pickle(smImportList, importedZones)
-- if we made it this far, the spawn isn't tracked -- add it to the table and store to ini
if flag then
-- settings[zoneShort]['Spawn' .. count + 1] = val_str
-- save_settings()
local result = Module:AddSpawnToList(val_str)
if result then
count = count + 1
end
end
return flag
end
end
local function set_settings()
useThemeName = Module.Settings[CharConfig]['theme'] or 'Default'
Module.Settings[CharConfig]['theme'] = useThemeName
ZoomLvl = Module.Settings[CharConfig]['ZoomLvl'] or 1.0
Module.Settings[CharConfig]['ZoomLvl'] = ZoomLvl
delay = Module.Settings[CharConfig]['delay']
remind = Module.Settings[CharConfig]['remind']
pcs = Module.Settings[CharConfig]['pcs']
spawns = Module.Settings[CharConfig]['spawns']
gms = Module.Settings[CharConfig]['gms']
announce = Module.Settings[CharConfig]['announce']
ignoreguild = Module.Settings[CharConfig]['ignoreguild']
radius = Module.Settings[CharConfig]['radius'] or radius
Module.Settings[CharConfig]['radius'] = radius
zradius = Module.Settings[CharConfig]['zradius'] or zradius
Module.Settings[CharConfig]['zradius'] = zradius
remindNPC = Module.Settings[CharConfig]['remindNPC'] or 5
Module.Settings[CharConfig]['remindNPC'] = remindNPC
doBeep = Module.Settings[CharConfig]['beep'] or false
Module.Settings[CharConfig]['beep'] = doBeep
DoDrawArrow = Module.Settings[CharConfig]['arrows'] or false
Module.Settings[CharConfig]['arrows'] = DoDrawArrow
Module.GUI_Main.Locked = Module.Settings[CharConfig]['locked'] or false
Module.Settings[CharConfig]['locked'] = Module.GUI_Main.Locked
doAlert = Module.Settings[CharConfig]['popup'] or false
Module.Settings[CharConfig]['popup'] = doAlert
showAggro = Module.Settings[CharConfig]['aggro'] or false
Module.Settings[CharConfig]['aggro'] = showAggro
DistColorRanges.orange = Module.Settings[CharConfig]['distmid'] or 600
Module.Settings[CharConfig]['distmid'] = DistColorRanges.orange
DistColorRanges.red = Module.Settings[CharConfig]['distfar'] or 1200
Module.Settings[CharConfig]['distfar'] = DistColorRanges.red
doSoundGM = Module.Settings[CharConfig]['doSoundGM'] or false
Module.Settings[CharConfig]['doSoundGM'] = doSoundGM
doSoundNPC = Module.Settings[CharConfig]['doSoundNPC'] or false
Module.Settings[CharConfig]['doSoundNPC'] = doSoundNPC
doSoundPC = Module.Settings[CharConfig]['doSoundPC'] or false
Module.Settings[CharConfig]['doSoundPC'] = doSoundPC
volGM = Module.Settings[CharConfig]['volGM'] or volGM
Module.Settings[CharConfig]['volGM'] = volGM
volNPC = Module.Settings[CharConfig]['volNPC'] or volNPC
Module.Settings[CharConfig]['volNPC'] = volNPC
volPC = Module.Settings[CharConfig]['volPC'] or volPC
Module.Settings[CharConfig]['volPC'] = volPC
soundGM = Module.Settings[CharConfig]['soundGM'] or soundGM
Module.Settings[CharConfig]['soundGM'] = soundGM
soundNPC = Module.Settings[CharConfig]['soundNPC'] or soundNPC
Module.Settings[CharConfig]['soundNPC'] = soundNPC
soundPC = Module.Settings[CharConfig]['soundPC'] or soundPC
Module.Settings[CharConfig]['soundPC'] = soundPC
soundPCEntered = Module.Settings[CharConfig]['soundPCEntered'] or soundPCEntered
Module.Settings[CharConfig]['soundPCEntered'] = soundPCEntered
soundPCLeft = Module.Settings[CharConfig]['soundPCLeft'] or soundPCLeft
Module.Settings[CharConfig]['soundPCLeft'] = soundPCLeft
volPCEntered = Module.Settings[CharConfig]['volPCEntered'] or volPCEntered
Module.Settings[CharConfig]['volPCEntered'] = volPCEntered
volPCLeft = Module.Settings[CharConfig]['volPCLeft'] or volPCLeft
Module.Settings[CharConfig]['volPCLeft'] = volPCLeft
doSoundPCLeft = Module.Settings[CharConfig]['doSoundPCLeft'] or false
Module.Settings[CharConfig]['doSoundPCLeft'] = doSoundPCLeft
doSoundPCEntered = Module.Settings[CharConfig]['doSoundPCEntered'] or false
Module.Settings[CharConfig]['doSoundPCEntered'] = doSoundPCEntered
end
local amActor = nil
function Module:MessageHandler()
amActor = Module.Actors.register('alertmaster', function(message)
if not message() then return end
local messageData = message()
local subject = messageData.Subject or 'Hello'
local who = messageData.Name
local zone = messageData.Zone or 'Unknown'
local replyTo = messageData.ReplyTo or Module.ActorMailBox
printf("AlertMaster MessageHandler received subject: %s from %s in zone %s replyTo: %s", subject, who, zone, replyTo)
if subject == 'GetNamed' and zone ~= 'Unknown' then
Module.TempSettings.SendNamed = true
Module.TempSettings.NamedZone = zone
Module.TempSettings.ReplyTo = replyTo
return
end
end)
end
local function load_settings()
local check = false
if Module.Utils.File.Exists(newConfigFile) then
local config = dofile(newConfigFile)
Module.Settings[CharCommands] = config[CharCommands] or {}
Module.Settings[CharConfig] = config[CharConfig] or {}
check = true
else
Module.Settings[CharCommands] = {}
Module.Settings[CharConfig] = defaultConfig
end
if Module.Utils.File.Exists(settings_path) and not check then
settings = LIP.load(settings_path)
if not check then
Module.Settings[CharConfig] = settings[CharConfig] or defaultConfig
Module.Settings[CharCommands] = settings[CharCommands] or {}
settings[CharConfig] = nil
settings[CharCommands] = nil
end
save_settings()
elseif not Module.Utils.File.Exists(settings_path) and not check then
settings = {
Ignore = {},
}
save_settings()
end
if not loadedExeternally then
if Module.Utils.File.Exists(Module.ThemeFile) then
Module.Theme = dofile(Module.ThemeFile)
end
end
-- if Module.Utils.File.Exists(newSMFile) then
-- spawnsSpawnMaster = LIP.loadSM(newSMFile)
-- haveSM = true
-- importZone = true
-- else
if Module.Utils.File.Exists(smSettings) then
spawnsSpawnMaster = LIP.loadSM(smSettings)
haveSM = true
importZone = true
for section, data in pairs(spawnsSpawnMaster) do
local lwrSection = section:lower()
if ZoneNames[lwrSection] then
spawnsSpawnMaster[ZoneNames[lwrSection]] = data
spawnsSpawnMaster[section] = nil
end
end
-- LIP.save(newSMFile, spawnsSpawnMaster)
end
local exportFile = string.format("%s/MyUI/ExportSM.lua", mq.configDir)
mq.pickle(exportFile, spawnsSpawnMaster)
if Module.Utils.File.Exists(smImportList) then
importedZones = dofile(smImportList)
end
Module.LoadSpawnsDB()
useThemeName = Module.Theme.LoadTheme
-- if this character doesn't have the sections in the ini, create them
if Module.Settings[CharConfig] == nil then Module.Settings[CharConfig] = defaultConfig end
if Module.Settings[CharCommands] == nil then Module.Settings[CharCommands] = {} end
local db = Module:OpenDB()
settings.SafeZones = Module:GetSafeZones(db)
settings.Ignore = Module:GetIgnoredPlayers(db)
if db then db:close() end
set_settings()
save_settings()
if Module.GUI_Main.Locked then
SearchWindow_Show = true
SearchWindowOpen = true
else
SearchWindow_Show = false
SearchWindowOpen = false
end
-- setup safe zone "set"
for _, v in ipairs(settings['SafeZones']) do tSafeZones[v] = true end
end
local function ColorDistance(distance)
if distance < DistColorRanges.orange then
-- Green color for Close Range
return Module.Colors.color('green')
elseif distance >= DistColorRanges.orange and distance <= DistColorRanges.red then
-- Orange color for Mid Range
return Module.Colors.color('orange')
else
-- Red color for Far Distance
return Module.Colors.color('red')
end
end
local function isSpawnInAlerts(spawnName, spawnAlertsTable)
for _, spawnData in pairs(spawnAlertsTable) do
if spawnData.DisplayName() == spawnName or spawnData.Name() == spawnName then
return true
end
end
return false
end
---@param spawn MQSpawn
local function SpawnToEntry(spawn, id, table)
if not spawn then return end
local pAggro = 0
if table == xTarTable then
pAggro = spawn.PctAggro() or 0
end
if spawn.ID() then
local surName = spawn.Surname() or ''
if surName:find("'s ") then return end
local entry = {
ID = id or 0,
MobName = spawn.DisplayName() or ' ',
MobDirtyName = spawn.Name() or ' ',
MobZoneName = Zone.Name() or ' ',
MobDist = math.floor(spawn.Distance() or 0),
MobLoc = spawn.Loc() or ' ',
MobID = spawn.ID() or 0,
MobLvl = spawn.Level() or 0,
MobConColor = string.lower(spawn.ConColor() or 'white'),
MobAggro = pAggro or 0,
MobDirection = spawn.HeadingTo() or '0',
Enum_Action = 'unhandled',
}
return entry
else
return
end
end
---@param spawn MQSpawn
local function InsertTableSpawn(dataTable, spawn, id, opts)
if spawn then
local entry = SpawnToEntry(spawn, id, dataTable)
if opts then
for k, v in pairs(opts) do
entry[k] = v
end
end
table.insert(dataTable, entry)
end
end
local function TableSortSpecs(a, b)
for i = 1, Module.GUI_Main.Table.SortSpecs.SpecsCount do
local spec = Module.GUI_Main.Table.SortSpecs:Specs(i)
local delta = 0
if spec.ColumnUserID == Module.GUI_Main.Table.Column_ID.MobName then
if a.MobName and b.MobName then
if a.MobName < b.MobName then
delta = -1
elseif a.MobName > b.MobName then
delta = 1
end
else
return 0
end
elseif spec.ColumnUserID == Module.GUI_Main.Table.Column_ID.MobID then
if a.MobID and b.MobID then
if a.MobID < b.MobID then
delta = -1
elseif a.MobID > b.MobID then
delta = 1
end
else
return 0
end
elseif spec.ColumnUserID == Module.GUI_Main.Table.Column_ID.MobLvl then
if a.MobLvl and b.MobLvl then
if a.MobLvl < b.MobLvl then
delta = -1
elseif a.MobLvl > b.MobLvl then
delta = 1
end
else
return 0
end
elseif spec.ColumnUserID == Module.GUI_Main.Table.Column_ID.MobDist then
if a.MobDist and b.MobDist then
if a.MobDist < b.MobDist then
delta = -1
elseif a.MobDist > b.MobDist then
delta = 1
end
else
return 0
end
elseif spec.ColumnUserID == Module.GUI_Main.Table.Column_ID.MobAggro then
if a.MobAggro and b.MobAggro then
if a.MobAggro < b.MobAggro then
delta = -1
elseif a.MobAggro > b.MobAggro then
delta = 1
end
else
return 0
end
elseif spec.ColumnUserID == Module.GUI_Main.Table.Column_ID.Action then
if a.Enum_Action < b.Enum_Action then
delta = -1
elseif a.Enum_Action > b.Enum_Action then
delta = 1
end
end
if delta ~= 0 then
if spec.SortDirection == ImGuiSortDirection.Ascending then
return delta < 0
else