annotate ICU.lua @ 2:e883b490ff93

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