vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | ----------------------------------------------------- |
2 | -- Changelog -- |
||
3 | ----------------------------------------------------- |
||
4 | -- Version 1.1 -- |
||
5 | ----------------------------------------------------- |
||
6 | -- # Changed first parameter of CT_RABoss_Schedule -- |
||
7 | -- to take either a string or a function as its -- |
||
8 | -- first argument. -- |
||
9 | -- -- |
||
10 | -- # Added CT_RABoss_PlaySound, which takes an id -- |
||
11 | -- between 1-3 and plays the corresponding sound. -- |
||
12 | -- -- |
||
13 | -- # Added CT_RABoss_Debug, which prints to chat -- |
||
14 | -- if and when debug is enabled for that debug -- |
||
15 | -- level. See the function for more details. -- |
||
16 | -- -- |
||
17 | -- # Added slash command /rabossdebug [level] or -- |
||
18 | -- /rabd, which toggles debugg for the chosen -- |
||
19 | -- level if specified, otherwise toggles debugging -- |
||
20 | -- for all levels. -- |
||
21 | ----------------------------------------------------- |
||
22 | -- Version 1.0 -- |
||
23 | ----------------------------------------------------- |
||
24 | -- # Release version. -- |
||
25 | ----------------------------------------------------- |
||
26 | |||
27 | CT_RABoss_ModsToLoad = { }; |
||
28 | CT_RABoss_ScheduledActions = { }; |
||
29 | CT_RABoss_Events = { }; |
||
30 | CT_RABoss_Mods = { }; |
||
31 | CT_RABoss_Save = { }; |
||
32 | CT_RABoss_DropDown = { }; |
||
33 | CT_RABoss_HasLoadedVars = nil; |
||
34 | |||
35 | CT_RABoss_Locations = { |
||
36 | { CT_RABOSS_LOCATIONS_NAXXRAMAS, 0 }, { CT_RABOSS_LOCATIONS_AHNQIRAJTEMPLE, 0 }, { CT_RABOSS_LOCATIONS_AHNQIRAJRUINS, 0 }, { CT_RABOSS_LOCATIONS_MOLTENCORE, 0 }, { CT_RABOSS_LOCATIONS_BLACKWINGSLAIR, 0 }, { CT_RABOSS_LOCATIONS_ONYXIASLAIR, 0 }, { CT_RABOSS_LOCATIONS_ZULGURUB, 0 }, { CT_RABOSS_LOCATIONS_OUTDOOR, 0 }, { CT_RABOSS_LOCATIONS_OTHER, 0 } |
||
37 | }; |
||
38 | |||
39 | CT_RABoss_DebugLevels = { |
||
40 | ["enableDebug"] = false, |
||
41 | [1] = true, |
||
42 | [2] = true, |
||
43 | [3] = true, |
||
44 | [4] = true, |
||
45 | [5] = true |
||
46 | }; |
||
47 | |||
48 | -- Displays the message(s) if the debug level specified is enabled, and enableDebug is set to true. |
||
49 | function CT_RABoss_Debug(level, ...) |
||
50 | if ( CT_RABoss_DebugLevels["enableDebug"] and CT_RABoss_DebugLevels[(level or 1)] ) then |
||
51 | local msg = ""; |
||
52 | for i = 1, arg.n, 1 do |
||
53 | if ( strlen(msg) > 0 ) then |
||
54 | msg = msg .. " |r#|c00FFFFFF "; |
||
55 | end |
||
56 | if ( type(arg[i]) == "string" ) then |
||
57 | msg = msg .. "\"" .. arg[i] .. "\""; |
||
58 | elseif ( type(arg[i]) == "number" ) then |
||
59 | msg = msg .. arg[i]; |
||
60 | else |
||
61 | msg = msg .. strupper(type(arg[i])); |
||
62 | end |
||
63 | end |
||
64 | CT_RA_Print("<CTRA Debug " .. (level or 1) .. "> |c00FFFFFF" .. msg .. "|r", 1, 1, 0); |
||
65 | end |
||
66 | end |
||
67 | |||
68 | -- Function to schedule a function |
||
69 | function CT_RABoss_Schedule(nameOrFunction, timeUntil, optParam) |
||
70 | tinsert(CT_RABoss_ScheduledActions, { nameOrFunction, GetTime()+timeUntil, optParam }); |
||
71 | end |
||
72 | |||
73 | -- Function to unschedule all functions where the first index is "name" |
||
74 | function CT_RABoss_UnSchedule(name, optParam) |
||
75 | local v; |
||
76 | for k = getn(CT_RABoss_ScheduledActions), 1, -1 do |
||
77 | v = CT_RABoss_ScheduledActions[k]; |
||
78 | if ( v[1] == name and ( not optParam or v[3] == optParam ) ) then |
||
79 | tremove(CT_RABoss_ScheduledActions, k); |
||
80 | end |
||
81 | end |
||
82 | end |
||
83 | |||
84 | -- Function to process scheduled actions |
||
85 | function CT_RABoss_OnUpdate(elapsed) |
||
86 | this.elapsed = this.elapsed + elapsed; |
||
87 | if ( this.elapsed >= 0.1 ) then |
||
88 | this.elapsed = this.elapsed - 0.1; |
||
89 | local currTime = GetTime(); |
||
90 | local v; |
||
91 | for k = getn(CT_RABoss_ScheduledActions), 1, -1 do |
||
92 | v = CT_RABoss_ScheduledActions[k]; |
||
93 | if ( v and currTime >= v[2] ) then |
||
94 | tremove(CT_RABoss_ScheduledActions, k); |
||
95 | if ( type(v[1]) == "function" ) then |
||
96 | v[1](v[3]); |
||
97 | else |
||
98 | getglobal(v[1])(v[3]); |
||
99 | end |
||
100 | end |
||
101 | end |
||
102 | end |
||
103 | end |
||
104 | |||
105 | -- Handles all the events |
||
106 | function CT_RABoss_OnEvent(event) |
||
107 | if ( event == "VARIABLES_LOADED" ) then |
||
108 | CT_RABoss_LoadMods(); |
||
109 | CT_RABoss_HasLoadedVars = 1; |
||
110 | -- Add new mods that aren't saved yet |
||
111 | for k, v in CT_RABoss_Save do |
||
112 | if ( CT_RABoss_Mods[k] ) then |
||
113 | for key, val in v do |
||
114 | CT_RABoss_Mods[k][key] = val; |
||
115 | end |
||
116 | else |
||
117 | CT_RABoss_Save[k] = nil; |
||
118 | end |
||
119 | end |
||
120 | elseif ( event == "PLAYER_ENTERING_WORLD" ) then |
||
121 | CT_RABoss_Schedule("CT_RABoss_ScanModZones", 20); |
||
122 | end |
||
123 | |||
124 | for k, v in CT_RABoss_Events do |
||
125 | if ( v[event] ) then |
||
126 | v[event](event); |
||
127 | end |
||
128 | end |
||
129 | end |
||
130 | |||
131 | -- Function to disable/enable mods based on zone |
||
132 | function CT_RABoss_ScanModZones() |
||
133 | local zone = GetRealZoneText(); |
||
134 | for k, v in CT_RABoss_Mods do |
||
135 | if ( v["location"] ) then |
||
136 | if ( v["location"] == CT_RABOSS_LOCATIONS_NAXXRAMAS ) then |
||
137 | CT_RABoss_Mods[k].enabled = ( zone == CT_RABOSS_MINIMAPLOC_NAXXRAMAS ); |
||
138 | elseif ( v["location"] == CT_RABOSS_LOCATIONS_AHNQIRAJTEMPLE ) then |
||
139 | CT_RABoss_Mods[k].enabled = ( zone == CT_RABOSS_MINIMAPLOC_AHNQIRAJTEMPLE ); |
||
140 | elseif ( v["location"] == CT_RABOSS_LOCATIONS_AHNQIRAJRUINS ) then |
||
141 | CT_RABoss_Mods[k].enabled = ( zone == CT_RABOSS_MINIMAPLOC_AHNQIRAJRUINS ); |
||
142 | elseif ( v["location"] == CT_RABOSS_LOCATIONS_BLACKWINGSLAIR ) then |
||
143 | CT_RABoss_Mods[k].enabled = ( zone == CT_RABOSS_MINIMAPLOC_BLACKWINGSLAIR ); |
||
144 | elseif ( v["location"] == CT_RABOSS_LOCATIONS_ONYXIASLAIR ) then |
||
145 | CT_RABoss_Mods[k].enabled = ( zone == CT_RABOSS_MINIMAPLOC_ONYXIASLAIR ); |
||
146 | elseif ( v["location"] == CT_RABOSS_LOCATIONS_MOLTENCORE ) then |
||
147 | CT_RABoss_Mods[k].enabled = ( zone == CT_RABOSS_MINIMAPLOC_MOLTENCORE ); |
||
148 | elseif ( v["location"] == CT_RABOSS_LOCATIONS_ZULGURUB ) then |
||
149 | CT_RABoss_Mods[k].enabled = ( zone == CT_RABOSS_MINIMAPLOC_ZULGURUB ); |
||
150 | elseif ( v["location"] == CT_RABOSS_LOCATIONS_OUTDOOR ) then |
||
151 | local x, y = GetPlayerMapPosition("player"); |
||
152 | CT_RABoss_Mods[k].enabled = ( x ~= 0 or y ~= 0 ); |
||
153 | else |
||
154 | CT_RABoss_Mods[k].enabled = true; |
||
155 | end |
||
156 | end |
||
157 | end |
||
158 | end |
||
159 | -- Add event |
||
160 | function CT_RABoss_AddEvent(modName, event, func) |
||
161 | if ( not CT_RABoss_Events[modName] ) then |
||
162 | CT_RABoss_Events[modName] = { }; |
||
163 | end |
||
164 | CT_RABoss_Events[modName][event] = func; |
||
165 | CT_RABossModsFrame:RegisterEvent(event); |
||
166 | end |
||
167 | |||
168 | -- Add mod |
||
169 | function CT_RABoss_AddMod(modName, modDescript, modStatus, modLocation) |
||
170 | if ( not modLocation ) then |
||
171 | modLocation = "Other"; |
||
172 | end |
||
173 | |||
174 | local found; |
||
175 | for k, v in CT_RABoss_Locations do |
||
176 | if ( v[1] == modLocation ) then |
||
177 | found = 1; |
||
178 | break; |
||
179 | end |
||
180 | end |
||
181 | if ( not found ) then |
||
182 | tinsert(CT_RABoss_Locations, { modLocation, 0 }); |
||
183 | end |
||
184 | if ( not CT_RABoss_HasLoadedVars and not CT_RABoss_Save[modName]) then |
||
185 | CT_RABoss_Save[modName] = { ["status"] = modStatus }; |
||
186 | end |
||
187 | if ( not CT_RABoss_HasLoadedVars or not CT_RABoss_Mods[modName] ) then |
||
188 | CT_RABoss_Mods[modName] = { ["status"] = modStatus, ["descript"] = modDescript, ["location"] = modLocation }; |
||
189 | end |
||
190 | end |
||
191 | |||
192 | -- Enable/Disable mod |
||
193 | function CT_RABoss_EnableMod() |
||
194 | CT_RABoss_Mods[this.value]["status"] = not CT_RABoss_Mods[this.value]["status"]; |
||
195 | if ( not CT_RABoss_Save[this.value] ) then |
||
196 | CT_RABoss_Save[this.value] = { |
||
197 | ["status"] = CT_RABoss_Mods[this.value]["status"] |
||
198 | }; |
||
199 | else |
||
200 | CT_RABoss_Save[this.value]["status"] = not CT_RABoss_Save[this.value]["status"]; |
||
201 | end |
||
202 | CT_RAMenuBoss_Update(); |
||
203 | end |
||
204 | |||
205 | -- Get mod info |
||
206 | function CT_RABoss_ModInfo(modName, modVar) |
||
207 | if ( CT_RABoss_Mods[modName] and CT_RABoss_Mods[modName][modVar] ) then |
||
208 | if ( type(CT_RABoss_Mods[modName][modVar]) or CT_RABoss_Mods[modName][modVar] ~= 0 ) then |
||
209 | return 1; |
||
210 | end |
||
211 | end |
||
212 | end |
||
213 | |||
214 | -- Set mod info |
||
215 | function CT_RABoss_SetInfo() |
||
216 | CT_RABoss_SetVar(this.value[1], this.value[2], not CT_RABoss_Mods[this.value[1]][this.value[2]]); |
||
217 | end |
||
218 | |||
219 | function CT_RABoss_SetVar(modName, modVar, modValue) |
||
220 | CT_RABoss_Mods[modName][modVar] = modValue; |
||
221 | if ( CT_RABoss_HasLoadedVars ) then |
||
222 | if ( not CT_RABoss_Save[modName] ) then |
||
223 | CT_RABoss_Save[modName] = { }; |
||
224 | end |
||
225 | CT_RABoss_Save[modName][modVar] = modValue; |
||
226 | end |
||
227 | if ( CT_RAMenuBoss_Update ) then |
||
228 | CT_RAMenuBoss_Update(); |
||
229 | end |
||
230 | end |
||
231 | |||
232 | -- Add dropdown buttons |
||
233 | function CT_RABoss_AddDropDownButton(modName, btnDesc, btnVar, btnParams, btnSetFunc) |
||
234 | if ( not CT_RABoss_DropDown[modName] ) then |
||
235 | CT_RABoss_DropDown[modName] = { }; |
||
236 | end |
||
237 | tinsert( CT_RABoss_DropDown[modName], { btnDesc, btnVar, btnParams, btnSetFunc } ); |
||
238 | end |
||
239 | |||
240 | -- Announce function |
||
241 | function CT_RABoss_Announce(msg, fullRaid) |
||
242 | if ( fullRaid and CT_RA_Level >= 1 ) then |
||
243 | CT_RA_AddMessage("MS " .. msg); |
||
244 | SendChatMessage(msg, "RAID"); |
||
245 | end |
||
246 | CT_RA_WarningFrame:AddMessage(msg, 1, 1, 1, 1, UIERRORS_HOLD_TIME); |
||
247 | end |
||
248 | |||
249 | function CT_RABoss_PlaySound(id) |
||
250 | local soundTable = { |
||
251 | "Sound\\Doodad\\BellTollHorde.wav", |
||
252 | "Sound\\Doodad\\BellTollAlliance.wav", |
||
253 | "Sound\\Doodad\\BellTollNightElf.wav", |
||
254 | }; |
||
255 | PlaySoundFile(soundTable[id]); |
||
256 | end |