annotate ICU.lua @ 1:6af2d0a0c537

Added support for disabling certain instances (based on Zone, need testing). Cleaned up options.
author Xiiph
date Sat, 05 Feb 2011 20:27:14 +0100
parents 98c6f55e6619
children e883b490ff93
rev   line source
Xiiph@0 1 local L = LibStub("AceLocale-3.0"):GetLocale("ICU")
Xiiph@0 2 if not L then return end
Xiiph@0 3
Xiiph@0 4 local icu = LibStub("AceAddon-3.0"):NewAddon("ICU", "AceEvent-3.0", "AceTimer-3.0");
Xiiph@0 5
Xiiph@0 6 -- Accepted flasks
Xiiph@0 7 local flaskID = {
Xiiph@0 8 79469, -- Flask of Steelskin
Xiiph@0 9 79470, -- Flask of the Draconic Mind
Xiiph@0 10 79471, -- Flask of the Winds
Xiiph@0 11 79472, -- Flask of Titanic Strength
Xiiph@0 12 94160, -- Flask of Flowing Water
Xiiph@0 13 };
Xiiph@0 14
Xiiph@0 15 -- Accepted well-fed buffs
Xiiph@0 16 local foodID = {
Xiiph@0 17 87545, -- 90 Strength
Xiiph@0 18 87546, -- 90 Agility
Xiiph@0 19 87547, -- 90 Intellect
Xiiph@0 20 87548, -- 90 Spirit
Xiiph@0 21 87549, -- 90 Mastery
Xiiph@0 22 87550, -- 90 Hit
Xiiph@0 23 87551, -- 90 Crit
Xiiph@0 24 87552, -- 90 Haste
Xiiph@0 25 };
Xiiph@0 26
Xiiph@0 27
Xiiph@0 28 local minFlaskDuration = 10;
Xiiph@0 29 local noFlask, noFood, hasLowDuration = {},{},{};
Xiiph@0 30
Xiiph@0 31 local defaults = {
Xiiph@0 32 profile = {
Xiiph@0 33 checkFlask = true,
Xiiph@0 34 checkFood = true,
Xiiph@0 35 checkLowFlaskDuration = true,
Xiiph@0 36 remindRaider = true,
Xiiph@0 37 reportResults = true,
Xiiph@0 38 reportDestination = "OFFICER",
Xiiph@0 39 manualCheckOnly = false,
Xiiph@0 40 checkAfterFinish = true,
Xiiph@0 41 advertiseICU = true,
Xiiph@0 42 noFoodMessage = L["Well Fed reminder!"],
Xiiph@0 43 noFlaskMessage = L["Flask reminder!"],
Xiiph@0 44 lowFlaskDurationMessage = L["Your Flask runs out in less than 10 minutes!"],
Xiiph@1 45 disabledZones = {},
Xiiph@0 46 }
Xiiph@0 47 }
Xiiph@0 48
Xiiph@0 49 function icu:OnInitialize()
Xiiph@0 50 self.db = LibStub("AceDB-3.0"):New("icuDB", defaults, true)
Xiiph@0 51
Xiiph@0 52 self.db.RegisterCallback(self, "OnProfileChanged", "refreshConfig")
Xiiph@0 53 self.db.RegisterCallback(self, "OnProfileCopied", "refreshConfig")
Xiiph@0 54 self.db.RegisterCallback(self, "OnProfileReset", "refreshConfig")
Xiiph@0 55
Xiiph@0 56 self.options = self:getOptions()
Xiiph@0 57
Xiiph@0 58 local AceConfig = LibStub("AceConfig-3.0")
Xiiph@0 59 local AceConfigDialog = LibStub("AceConfigDialog-3.0")
Xiiph@0 60
Xiiph@0 61 AceConfig:RegisterOptionsTable("ICU", self.options, {"icu"})
Xiiph@0 62
Xiiph@0 63 AceConfigDialog:AddToBlizOptions("ICU", nil, nil, "general")
Xiiph@0 64 AceConfigDialog:AddToBlizOptions("ICU", "Profiles","ICU","profile")
Xiiph@1 65 AceConfigDialog:AddToBlizOptions("ICU", "Whispers","ICU","messages")
Xiiph@1 66 AceConfigDialog:AddToBlizOptions("ICU", "Disabled Zones","ICU","zones")
Xiiph@0 67 end
Xiiph@0 68
Xiiph@0 69 function icu:refreshConfig()
Xiiph@0 70 --print("ICU: Config refreshing ...");
Xiiph@0 71
Xiiph@0 72 if self.db.profile.manualCheckOnly then
Xiiph@0 73 icu:UnregisterEvent("READY_CHECK");
Xiiph@0 74 else
Xiiph@0 75 icu:RegisterEvent("READY_CHECK");
Xiiph@0 76 end
Xiiph@0 77
Xiiph@0 78 --print("ICU: Config refreshed!");
Xiiph@0 79 end
Xiiph@0 80
Xiiph@0 81 function icu:config()
Xiiph@0 82 InterfaceOptionsFrame_OpenToCategory("ICU")
Xiiph@0 83 end
Xiiph@0 84
Xiiph@0 85 function icu:getOptions()
Xiiph@0 86 local options = {
Xiiph@0 87 handler = icu,
Xiiph@0 88 type = 'group',
Xiiph@0 89 args = {
Xiiph@0 90 config = {
Xiiph@0 91 name = L["Options"],
Xiiph@0 92 desc = L["Shows the blizzard addon configuration window"],
Xiiph@0 93 type = 'execute',
Xiiph@0 94 func = "config",
Xiiph@0 95 hidden = true,
Xiiph@0 96 cmdHidden = false,
Xiiph@0 97 },
Xiiph@0 98 check = {
Xiiph@0 99 name = L["Raid Check"],
Xiiph@0 100 desc = L["Checks the raid for flask/food buffs"],
Xiiph@0 101 type = 'execute',
Xiiph@0 102 func = function() self:inspectRaid(false) end,
Xiiph@0 103 hidden = true,
Xiiph@0 104 cmdHidden = false,
Xiiph@0 105 },
Xiiph@0 106 quiet = {
Xiiph@0 107 name = L["Raid Check (Silent)"],
Xiiph@0 108 desc = L["Checks the raid for flask/food buffs, but does not remind raiders, regardless of other settings."],
Xiiph@0 109 type = 'execute',
Xiiph@0 110 func = function() self:inspectRaid(true) end,
Xiiph@0 111 hidden = true,
Xiiph@0 112 cmdHidden = false,
Xiiph@0 113 },
Xiiph@0 114 general = {
Xiiph@0 115 name = L["General Settings"],
Xiiph@0 116 type = 'group',
Xiiph@0 117 args = {
Xiiph@0 118 checkFlask = {
Xiiph@0 119 type = 'toggle',
Xiiph@0 120 name = L["Check for Flask"],
Xiiph@0 121 desc = L["Checks the raid for valid flasks and reports results"],
Xiiph@0 122 set = function(o,v,...) self.db.profile.checkFlask = v end,
Xiiph@0 123 get = function() return self.db.profile.checkFlask end,
Xiiph@0 124 },
Xiiph@0 125 checkLowFlaskDuration = {
Xiiph@0 126 type = 'toggle',
Xiiph@0 127 name = L["Flask expiration"],
Xiiph@0 128 desc = L["Check for soon to expire flask buffs"],
Xiiph@0 129 set = function(o,v,...) self.db.profile.checkLowFlaskDuration = v end,
Xiiph@0 130 get = function() return self.db.profile.checkLowFlaskDuration end,
Xiiph@0 131 },
Xiiph@0 132 checkFood = {
Xiiph@0 133 type = 'toggle',
Xiiph@0 134 name = L["Check for Food"],
Xiiph@0 135 desc = L["Checks the raid for valid food buffs and reports results"],
Xiiph@0 136 set = function(o,v,...) self.db.profile.checkFood = v end,
Xiiph@0 137 get = function() return self.db.profile.checkFood end,
Xiiph@0 138 },
Xiiph@0 139 advertiseICU = {
Xiiph@0 140 type = 'toggle',
Xiiph@0 141 name = L["Advertise ICU"],
Xiiph@0 142 desc = L["Let everyone know you are using ICU! Prefixes whispers and reports"],
Xiiph@0 143 set = function(o,v,...) self.db.profile.advertiseICU = v end,
Xiiph@0 144 get = function() return self.db.profile.advertiseICU end,
Xiiph@0 145 },
Xiiph@0 146 remindRaider = {
Xiiph@0 147 type = 'toggle',
Xiiph@0 148 name = L["Raid reminder"],
Xiiph@0 149 desc = L["Whisper the raider lacking (or soon to expire, if enabled) food/flask buff a reminder"],
Xiiph@0 150 set = function(o,v,...) self.db.profile.remindRaider = v end,
Xiiph@0 151 get = function() return self.db.profile.remindRaider end,
Xiiph@0 152 },
Xiiph@0 153 reportResults = {
Xiiph@0 154 type = 'toggle',
Xiiph@0 155 name = L["Report results"],
Xiiph@0 156 desc = L["Report the results after finishing"],
Xiiph@0 157 set = function(o,v,...) self.db.profile.reportResults = v end,
Xiiph@0 158 get = function() return self.db.profile.reportResults end,
Xiiph@0 159 },
Xiiph@0 160 reportDestination = {
Xiiph@0 161 type = 'select',
Xiiph@0 162 style = "dropdown",
Xiiph@0 163 name = L["Report Destination"],
Xiiph@0 164 desc = L["Report the results to the following channel"],
Xiiph@0 165 values = {
Xiiph@0 166 ["OFFICER"] = L["Officer"],
Xiiph@0 167 ["SAY"] = L["Say"],
Xiiph@0 168 ["RAID"] = L["Raid"],
Xiiph@0 169 ["GUILD"] = L["Guild"],
Xiiph@0 170 ["SELF"] = L["Self"],
Xiiph@0 171 },
Xiiph@0 172 set = function(o,v,...) self.db.profile.reportDestination = v end,
Xiiph@0 173 get = function() return self.db.profile.reportDestination end,
Xiiph@0 174 },
Xiiph@0 175 manualCheckOnly = {
Xiiph@0 176 type = 'toggle',
Xiiph@0 177 name = L["Manual checks only"],
Xiiph@0 178 desc = L["Only perform buff checks if initiated manually (via /icu check)"],
Xiiph@0 179 set = function(o,v,...) self.db.profile.manualCheckOnly = v; self:refreshConfig() end,
Xiiph@0 180 get = function() return self.db.profile.manualCheckOnly end,
Xiiph@0 181 },
Xiiph@0 182 checkAfterFinish = {
Xiiph@0 183 type = 'toggle',
Xiiph@0 184 name = L["Check after readycheck"],
Xiiph@0 185 desc = L["Don't check buffs until ready check has finished (or timed out)"],
Xiiph@0 186 set = function(o,v,...) self.db.profile.checkAfterFinish = v end,
Xiiph@0 187 get = function() return self.db.profile.checkAfterFinish end,
Xiiph@0 188 },
Xiiph@1 189 },
Xiiph@1 190 },
Xiiph@1 191 messages = {
Xiiph@1 192 name = L["Messages"],
Xiiph@1 193 type = 'group',
Xiiph@1 194 args = {
Xiiph@1 195 noFlaskMessage = {
Xiiph@1 196 type = 'input',
Xiiph@1 197 width = 'double',
Xiiph@1 198 name = L["Flask reminder"],
Xiiph@1 199 desc = L["Message whispered to raiders missing a cataclysm flask"],
Xiiph@1 200 set = function(o,v,...) self.db.profile.noFlaskMessage = v end,
Xiiph@1 201 get = function() return self.db.profile.noFlaskMessage end,
Xiiph@1 202 },
Xiiph@1 203 lowFlaskDurationMessage = {
Xiiph@1 204 type = 'input',
Xiiph@1 205 width = 'double',
Xiiph@1 206 name = L["Flask expiration"],
Xiiph@1 207 desc = L["Message whispered to raiders with less than 10 minutes left on their flask"],
Xiiph@1 208 set = function(o,v,...) self.db.profile.lowFlaskDurationMessage = v end,
Xiiph@1 209 get = function() return self.db.profile.lowFlaskDurationMessage end,
Xiiph@1 210 },
Xiiph@1 211 noFoodMessage = {
Xiiph@1 212 type = 'input',
Xiiph@1 213 width = 'double',
Xiiph@1 214 name = L["Food reminder"],
Xiiph@1 215 desc = L["Message whispered to raiders missing the well-fed buff"],
Xiiph@1 216 set = function(o,v,...) self.db.profile.noFoodMessage = v end,
Xiiph@1 217 get = function() return self.db.profile.noFoodMessage end,
Xiiph@1 218 },
Xiiph@1 219 },
Xiiph@1 220 },
Xiiph@1 221 zones = {
Xiiph@1 222 name = L["Disabled Zones"],
Xiiph@1 223 type = 'group',
Xiiph@1 224 set = function(i,v) self.db.profile.disabledZones[i[#i]] = v end,
Xiiph@1 225 get = function(i) return self.db.profile.disabledZones[i[#i]] end,
Xiiph@1 226 args = {
Xiiph@1 227 help = {
Xiiph@1 228 type = 'description',
Xiiph@1 229 name = L['Toggle ICU automatic checking |cffcc0000off|r in the selected zones.'],
Xiiph@1 230 width = 'full',
Xiiph@1 231 order = 0,
Xiiph@0 232 },
Xiiph@1 233 bwd = {
Xiiph@1 234 type = 'toggle',
Xiiph@1 235 name = L["Blackwing Descent"],
Xiiph@1 236 width = 'double',
Xiiph@0 237 },
Xiiph@1 238 bot = {
Xiiph@1 239 type = 'toggle',
Xiiph@1 240 name = L["Bastion of Twilight"],
Xiiph@1 241 width = 'double',
Xiiph@0 242 },
Xiiph@1 243 tfw = {
Xiiph@1 244 type = 'toggle',
Xiiph@1 245 name = L["Throne of the Four Winds"],
Xiiph@1 246 width = 'double',
Xiiph@1 247 },
Xiiph@1 248 bh = {
Xiiph@1 249 type = 'toggle',
Xiiph@1 250 name = L["Baradin Hold"],
Xiiph@1 251 width = 'double',
Xiiph@1 252 },
Xiiph@0 253 }
Xiiph@0 254 },
Xiiph@0 255 profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db),
Xiiph@0 256 },
Xiiph@0 257 }
Xiiph@0 258 return options
Xiiph@0 259 end
Xiiph@0 260
Xiiph@1 261 function icu:inspectRaid(silent,automatic)
Xiiph@1 262 -- Check if any zones have been disabled
Xiiph@1 263 if #self.db.profile.disabledZones > 0 and automatic then
Xiiph@1 264 local currentZone = GetRealZoneText();
Xiiph@1 265
Xiiph@1 266 for i = 1, #self.db.profile.disabledZones do
Xiiph@1 267 if currentZone == self.db.profile.disabledZones[i] then return true end
Xiiph@1 268 end
Xiiph@1 269 end
Xiiph@1 270
Xiiph@0 271 -- Not in a raid group
Xiiph@0 272 local icuAd = "";
Xiiph@0 273
Xiiph@0 274 if GetNumRaidMembers() == 0 then
Xiiph@0 275 return true
Xiiph@0 276 end
Xiiph@0 277
Xiiph@0 278 if self.db.profile.advertiseICU then
Xiiph@0 279 icuAd = L["ICU"] .. ": ";
Xiiph@0 280 else
Xiiph@0 281 icuAd = "";
Xiiph@0 282 end
Xiiph@0 283
Xiiph@0 284 for i = 1, GetNumRaidMembers() do
Xiiph@0 285 local raider = GetRaidRosterInfo(i);
Xiiph@0 286 if raider then
Xiiph@0 287
Xiiph@0 288 local hasFood, hasFlask, hasLowDuration = icu:validateBuffs(i);
Xiiph@0 289
Xiiph@0 290 if not hasFood and self.db.profile.checkFood then
Xiiph@0 291 noFood[#noFood+1] = raider;
Xiiph@0 292 -- Tell player
Xiiph@0 293 if self.db.profile.remindRaider and not silent then
Xiiph@0 294 SendChatMessage(icuAd .. self.db.profile.noFoodMessage,"WHISPER",nil,raider);
Xiiph@0 295 end
Xiiph@0 296 end
Xiiph@0 297
Xiiph@0 298 if not hasFlask and self.db.profile.checkFlask then
Xiiph@0 299 noFlask[#noFlask+1] = raider;
Xiiph@0 300 -- Tell player
Xiiph@0 301 if self.db.profile.remindRaider and not silent then
Xiiph@0 302 SendChatMessage(icuAd .. self.db.profile.noFlaskMessage,"WHISPER",nil,raider);
Xiiph@0 303 end
Xiiph@0 304 elseif hasLowDuration and not silent then
Xiiph@0 305 if self.db.profile.remindRaider and self.db.profile.checkLowFlaskDuration then
Xiiph@0 306 SendChatMessage(icuAd .. self.db.profile.lowFlaskDurationMessage,"WHISPER",nil,raider);
Xiiph@0 307 end
Xiiph@0 308 end
Xiiph@0 309 end
Xiiph@0 310
Xiiph@0 311 end
Xiiph@0 312
Xiiph@0 313 if self.db.profile.reportResults and (#noFlask > 0 or #noFood > 0) and self.db.profile.advertiseICU and self.db.profile.reportDestination ~= "SELF" then
Xiiph@0 314 SendChatMessage("---- "..L["ICU"].." "..L["Report"].." ----",self.db.profile.reportDestination,nil,nil);
Xiiph@0 315 end
Xiiph@0 316
Xiiph@0 317 if self.db.profile.reportResults then
Xiiph@0 318 if #noFlask > 0 and self.db.profile.checkFlask then
Xiiph@0 319 local reportFlaskMessage = L["Missing Flask"]..": " .. table.concat(noFlask, ", ");
Xiiph@0 320
Xiiph@0 321 if self.db.profile.reportDestination == "SELF" then
Xiiph@0 322 DEFAULT_CHAT_FRAME:AddMessage(reportFlaskMessage);
Xiiph@0 323 else
Xiiph@0 324 SendChatMessage(reportFlaskMessage,self.db.profile.reportDestination,nil,nil);
Xiiph@0 325 end
Xiiph@0 326 end
Xiiph@0 327
Xiiph@0 328 if #noFood > 0 and self.db.profile.checkFood then
Xiiph@0 329 local reportFoodMessage = L["Missing Food"]..": " .. table.concat(noFood, ", ");
Xiiph@0 330
Xiiph@0 331 if self.db.profile.reportDestination == "SELF" then
Xiiph@0 332 DEFAULT_CHAT_FRAME:AddMessage(reportFoodMessage);
Xiiph@0 333 else
Xiiph@0 334 SendChatMessage(reportFoodMessage,self.db.profile.reportDestination,nil,nil);
Xiiph@0 335 end
Xiiph@0 336 end
Xiiph@0 337 end
Xiiph@0 338
Xiiph@0 339 noFlask, noFood, hasLowDuration = {},{},{};
Xiiph@0 340 end
Xiiph@0 341
Xiiph@0 342 function icu:validateBuffs(playerIndex)
Xiiph@0 343 local i = 1;
Xiiph@0 344 local hasFood, hasFlask, hasLowDuration = false, false, false;
Xiiph@0 345 local name, _, _, _, _, _, expirationTime, _, _, _, spellId = UnitBuff("raid"..playerIndex,i);
Xiiph@0 346
Xiiph@0 347 while name do
Xiiph@0 348 -- Check for food
Xiiph@0 349 if not hasFood then
Xiiph@0 350 for k,v in ipairs(foodID) do
Xiiph@0 351 if v == spellId then
Xiiph@0 352 hasFood = true;
Xiiph@0 353 end
Xiiph@0 354 end
Xiiph@0 355 end
Xiiph@0 356 -- Check for flask
Xiiph@0 357 if not hasFlask then
Xiiph@0 358 for k,v in ipairs(flaskID) do
Xiiph@0 359 if v == spellId then
Xiiph@0 360 hasFlask = true;
Xiiph@0 361 -- Check if low duration
Xiiph@0 362 if expirationTime and ((expirationTime-GetTime())/60) <= minFlaskDuration then
Xiiph@0 363 hasLowDuration = true;
Xiiph@0 364 end
Xiiph@0 365 end
Xiiph@0 366 end
Xiiph@0 367 end
Xiiph@0 368 i = i + 1;
Xiiph@0 369 name, _, _, _, _, _, expirationTime, _, _, _, spellId = UnitBuff("raid"..playerIndex,i);
Xiiph@0 370 end
Xiiph@0 371
Xiiph@0 372 return hasFood, hasFlask, hasLowDuration;
Xiiph@0 373 end
Xiiph@0 374
Xiiph@0 375 function icu:READY_CHECK()
Xiiph@0 376 --print("Ready check init!");
Xiiph@0 377 if self.db.profile.manualCheckOnly then
Xiiph@0 378 icu:UnregisterEvent("READY_CHECK");
Xiiph@0 379 return true;
Xiiph@0 380 end
Xiiph@0 381
Xiiph@0 382 if not self.db.profile.checkAfterFinish then
Xiiph@1 383 self:inspectRaid(nil,true);
Xiiph@0 384 else
Xiiph@0 385 self:ScheduleTimer("READY_CHECK_FINISHED", 30);
Xiiph@0 386 self:RegisterEvent("READY_CHECK_FINISHED");
Xiiph@0 387 end
Xiiph@0 388 end
Xiiph@0 389
Xiiph@0 390 function icu:READY_CHECK_FINISHED()
Xiiph@0 391 --print("Ready check finish!");
Xiiph@0 392 self:UnregisterEvent("READY_CHECK_FINISHED");
Xiiph@0 393 self:CancelAllTimers();
Xiiph@1 394 self:inspectRaid(nil,true);
Xiiph@0 395 end
Xiiph@0 396
Xiiph@1 397 function icu:getDB()
Xiiph@1 398 return self.db;
Xiiph@0 399 end
Xiiph@1 400
Xiiph@1 401 function filterChat(self, event, msg)
Xiiph@1 402 local db = icu:getDB();
Xiiph@1 403 if msg == db.profile.noFoodMessage or msg == db.profile.noFlaskMessage or msg == db.profile.lowFlaskDurationMessage or msg == L["ICU"]..": "..db.profile.noFoodMessage or msg == L["ICU"]..": "..db.profile.noFlaskMessage or msg == L["ICU"]..": "..db.profile.lowFlaskDurationMessage then return true end
Xiiph@1 404 end
Xiiph@1 405 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_ICU_INFORM", filterChat)
Xiiph@0 406
Xiiph@0 407 icu:RegisterEvent("READY_CHECK");
Xiiph@0 408
Xiiph@0 409 --@do-not-package@
Xiiph@0 410 function icu:test(cond)
Xiiph@0 411 if true and not cond then
Xiiph@0 412 print("First.")
Xiiph@0 413 else
Xiiph@0 414 print("Second.")
Xiiph@0 415 end
Xiiph@0 416 end
Xiiph@0 417
Xiiph@0 418 function icu:grabVar(var)
Xiiph@0 419 print(self.db.profile[var])
Xiiph@0 420 end
Xiiph@0 421
Xiiph@0 422 _G.icu = icu;
Xiiph@0 423 --@end-do-not-package@