-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattleHerald_TriggerSystem.lua
130 lines (101 loc) · 3.55 KB
/
BattleHerald_TriggerSystem.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
--[[
BattleHerald_TriggerSystem.lua
Implements the Trigger system that in turn shows Text Alerts and executes Sound Alerts
]]--
function BattleHerald_InitializeTriggersFrame()
local frame = CreateFrame("Frame", "BattleHerald_TriggersFrame");
frame:SetScript("OnEvent", BattleHerald_TriggerSystemEvent);
BattleHerald_TriggerSystemLoad();
end
function BattleHerald_TriggerSystemLoad()
for k, v in pairs(BattleHerald_Triggers) do
-- Register for the events in the Trigger list.
BattleHerald_TriggersFrame:RegisterEvent(v.event);
end
end
local function HomeStyle()
if (GetBattlefieldArenaFaction() == 0) then
return "HORDE";
else
return "ALLIANCE";
end
end
local function EnemyStyle()
if (GetBattlefieldArenaFaction() == 0) then
return "ALLIANCE";
else
return "HORDE";
end
end
function BattleHerald_GetStyleByActor(actor)
-- Looks for the specified actor in the player's raid.
-- If it finds it, returns back the player's faction as style.
-- Enemy faction, otherwise.
for i = 1, GetNumRaidMembers() do
if (UnitName("raid"..i) == actor) then
return HomeStyle();
end
end
return EnemyStyle();
end
local function LocalizeFactionStyle(style)
if (style == "ALLIANCE") then
return BHSTR_ALLIANCE;
else
return BHSTR_HORDE;
end
end
-- /run BattleHerald_TriggerSystemEvent(BattleHerald_TriggersFrame, "CHAT_MSG_BG_SYSTEM_NEUTRAL", "Test Trigger", nil, nil, nil, "Klishu");
function BattleHerald_TriggerSystemEvent(self, event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)
local match;
if (arg5 == "" or arg5 == nil) then
match = arg1;
else
match = gsub(arg1, arg5, "%%s");
end
for k, v in pairs(BattleHerald_Triggers) do
if (event == v.event and (GetRealZoneText() == v.zone or GetInstanceInfo() == v.zone)) then
if (match == v.match) then
if (BattleHerald_GetUserOption(v.textOpt) and v.text[1]) then
-- Show the text alert!
-- Use %t to substitute in the localized faction name
if (v.actorStyle) then
local style = BattleHerald_GetStyleByActor(arg5);
BattleHerald_AddToTextQueue(gsub(v.text[1], "%%t", LocalizeFactionStyle(style)), style);
else
BattleHerald_AddToTextQueue(v.text[1], v.style);
end
end
if (BattleHerald_GetUserOption(v.soundOpt) and v.sound[1] and v.sound[2]) then
-- Play the sound
-- Use %t to substitute in the localized faction name
if (v.actorStyle) then
local style = BattleHerald_GetStyleByActor(arg5);
BattleHerald_AddSoundToQueueByKey(v.sound[1], gsub(v.sound[2], "%%T", style));
else
BattleHerald_AddSoundToQueueByKey(v.sound[1], v.sound[2]);
end
end
if (v.handler) then
-- Trigger has a handler. Execute it.
v.handler(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
end
return;
end
end
end
end
-- Attach a handler function to a trigger (referred to it by its label).
-- When that trigger is executed, the handler is also called.
-- The handler will be passed the event and the event args up to arg11.
function BattleHerald_SetTriggerHandler(label, handler)
assert(label, "Invalid Trigger label specified.");
assert(handler, "Invalid Trigger handler specified.");
local i;
for i = 1, #BattleHerald_Triggers do
if (BattleHerald_Triggers[i].label == label) then
BattleHerald_Triggers[i].handler = handler;
end
end
end
BattleHerald_InitializeTriggersFrame();