-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvents.lua
More file actions
110 lines (95 loc) · 3.75 KB
/
Copy pathEvents.lua
File metadata and controls
110 lines (95 loc) · 3.75 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
local _, VoxGM = ...
local Events = VoxGM.Events
local parsers = {}
local unpackFn = table.unpack or unpack
function Events:Init()
if self._initialized then return end
self._initialized = true
local frame = VoxGM.eventFrame
frame:RegisterEvent("CHAT_MSG_SYSTEM")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:HookScript("OnEvent", function(self, event, ...)
if event == "CHAT_MSG_SYSTEM" then
Events:OnSystemMessage(...)
elseif event == "PLAYER_ENTERING_WORLD" then
Events:OnEnteringWorld(...)
end
end)
end
function Events:RegisterParser(pattern, callback)
table.insert(parsers, { pattern = pattern, callback = callback })
end
function Events:OnSystemMessage(msg)
if not msg then return end
for _, parser in ipairs(parsers) do
local captures = { msg:match(parser.pattern) }
if #captures > 0 then
parser.callback(unpackFn(captures))
end
end
end
function Events:OnEnteringWorld(isLogin, isReload)
-- Reset session toggles on fresh login (not reload)
if isLogin and not isReload then
local s = VoxGM.State.session
s.flyOn = false
s.gmOn = false
s.gmVisible = false
s.godMode = false
s.stealthOn = false
s.typingOn = false
s.combatLogOn = false
s.ranMaxrep = false
s.ranMaxtitles = false
s.ranMaxachieve = false
s.ranProfs = false
s.ranGoldPackage = false
s._godInProgress = nil
s._visInProgress = nil
s.phaseId = nil
end
end
-- Built-in parsers for common TC responses.
-- Patterns verified against trinity_string DB entries and cs_gm.cpp send calls.
-- Note: SendNotification messages may or may not appear as CHAT_MSG_SYSTEM
-- depending on client version. These parsers are best-effort state sync;
-- the addon also uses optimistic state (button click sets toggle).
function Events:RegisterDefaultParsers()
-- GM mode: SendNotification(LANG_GM_ON/OFF) → "GM mode is ON" / "GM mode is OFF"
self:RegisterParser("^GM mode is (%u+)", function(state)
VoxGM.State.session.gmOn = (state == "ON")
VoxGM.UI:RefreshActiveTab()
end)
-- Fly mode: PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS) → "[Name]'s Fly Mode on/off"
self:RegisterParser("Fly Mode (o[nf]+)$", function(state)
VoxGM.State.session.flyOn = (state == "on")
VoxGM.UI:RefreshActiveTab()
end)
-- GM visibility: SendNotification(LANG_INVISIBLE_VISIBLE/INVISIBLE)
-- → "You are now visible." / "You are now invisible."
self:RegisterParser("^You are now (%a+)%.", function(state)
VoxGM.State.session.gmVisible = (state == "visible")
VoxGM.UI:RefreshActiveTab()
end)
-- Speed: PSendSysMessage → "You set all speeds of [name] from normal to 6.00."
-- or "You set the speed of [name] from normal to 6.00."
self:RegisterParser("speeds? of .+ from normal to (%d+%.?%d*)", function(speed)
local n = tonumber(speed)
if n then VoxGM.State:SetLastUsed("speed", math.floor(n + 0.5)) end
end)
-- Phase tracking: PSendSysMessage → "* Phases: 169" or "PhaseID: 1, PhaseGroup: 0"
local function onPhase(phaseId)
local id = tonumber(phaseId)
if id and id > 0 then
VoxGM.State.session.phaseId = id
VoxGM.PhaseTracker:OnPhaseReceived(id)
end
end
self:RegisterParser("[Pp]hases[%s:]+(%d+)", onPhase)
self:RegisterParser("PhaseID:%s*(%d+)", onPhase)
-- Cheat mode: PSendSysMessage → "Godmode: ON." / "Casttime: OFF." / "Cooldown: ON." / "Power: OFF."
self:RegisterParser("^(Godmode):%s+(%u+)%.", function(_, state)
VoxGM.State.session.godMode = (state == "ON")
VoxGM.UI:RefreshActiveTab()
end)
end