annotate ICU.lua @ 0:98c6f55e6619

First commit
author Xiiph
date Sat, 05 Feb 2011 16:45:02 +0100
parents
children 6af2d0a0c537
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@0 45 }
Xiiph@0 46 }
Xiiph@0 47
Xiiph@0 48 function icu:OnInitialize()
Xiiph@0 49 self.db = LibStub("AceDB-3.0"):New("icuDB", defaults, true)
Xiiph@0 50
Xiiph@0 51 self.db.RegisterCallback(self, "OnProfileChanged", "refreshConfig")
Xiiph@0 52 self.db.RegisterCallback(self, "OnProfileCopied", "refreshConfig")
Xiiph@0 53 self.db.RegisterCallback(self, "OnProfileReset", "refreshConfig")
Xiiph@0 54
Xiiph@0 55 self.options = self:getOptions()
Xiiph@0 56
Xiiph@0 57 local AceConfig = LibStub("AceConfig-3.0")
Xiiph@0 58 local AceConfigDialog = LibStub("AceConfigDialog-3.0")
Xiiph@0 59
Xiiph@0 60 AceConfig:RegisterOptionsTable("ICU", self.options, {"icu"})
Xiiph@0 61
Xiiph@0 62 AceConfigDialog:AddToBlizOptions("ICU", nil, nil, "general")
Xiiph@0 63 AceConfigDialog:AddToBlizOptions("ICU", "Profiles","ICU","profile")
Xiiph@0 64 end
Xiiph@0 65
Xiiph@0 66 function icu:refreshConfig()
Xiiph@0 67 --print("ICU: Config refreshing ...");
Xiiph@0 68
Xiiph@0 69 if self.db.profile.manualCheckOnly then
Xiiph@0 70 icu:UnregisterEvent("READY_CHECK");
Xiiph@0 71 else
Xiiph@0 72 icu:RegisterEvent("READY_CHECK");
Xiiph@0 73 end
Xiiph@0 74
Xiiph@0 75 --print("ICU: Config refreshed!");
Xiiph@0 76 end
Xiiph@0 77
Xiiph@0 78 function icu:config()
Xiiph@0 79 InterfaceOptionsFrame_OpenToCategory("ICU")
Xiiph@0 80 end
Xiiph@0 81
Xiiph@0 82 function icu:getOptions()
Xiiph@0 83 local options = {
Xiiph@0 84 handler = icu,
Xiiph@0 85 type = 'group',
Xiiph@0 86 args = {
Xiiph@0 87 config = {
Xiiph@0 88 name = L["Options"],
Xiiph@0 89 desc = L["Shows the blizzard addon configuration window"],
Xiiph@0 90 type = 'execute',
Xiiph@0 91 func = "config",
Xiiph@0 92 hidden = true,
Xiiph@0 93 cmdHidden = false,
Xiiph@0 94 },
Xiiph@0 95 check = {
Xiiph@0 96 name = L["Raid Check"],
Xiiph@0 97 desc = L["Checks the raid for flask/food buffs"],
Xiiph@0 98 type = 'execute',
Xiiph@0 99 func = function() self:inspectRaid(false) end,
Xiiph@0 100 hidden = true,
Xiiph@0 101 cmdHidden = false,
Xiiph@0 102 },
Xiiph@0 103 quiet = {
Xiiph@0 104 name = L["Raid Check (Silent)"],
Xiiph@0 105 desc = L["Checks the raid for flask/food buffs, but does not remind raiders, regardless of other settings."],
Xiiph@0 106 type = 'execute',
Xiiph@0 107 func = function() self:inspectRaid(true) end,
Xiiph@0 108 hidden = true,
Xiiph@0 109 cmdHidden = false,
Xiiph@0 110 },
Xiiph@0 111 general = {
Xiiph@0 112 name = L["General Settings"],
Xiiph@0 113 type = 'group',
Xiiph@0 114 args = {
Xiiph@0 115 checkFlask = {
Xiiph@0 116 type = 'toggle',
Xiiph@0 117 name = L["Check for Flask"],
Xiiph@0 118 desc = L["Checks the raid for valid flasks and reports results"],
Xiiph@0 119 set = function(o,v,...) self.db.profile.checkFlask = v end,
Xiiph@0 120 get = function() return self.db.profile.checkFlask end,
Xiiph@0 121 },
Xiiph@0 122 checkLowFlaskDuration = {
Xiiph@0 123 type = 'toggle',
Xiiph@0 124 name = L["Flask expiration"],
Xiiph@0 125 desc = L["Check for soon to expire flask buffs"],
Xiiph@0 126 set = function(o,v,...) self.db.profile.checkLowFlaskDuration = v end,
Xiiph@0 127 get = function() return self.db.profile.checkLowFlaskDuration end,
Xiiph@0 128 },
Xiiph@0 129 checkFood = {
Xiiph@0 130 type = 'toggle',
Xiiph@0 131 name = L["Check for Food"],
Xiiph@0 132 desc = L["Checks the raid for valid food buffs and reports results"],
Xiiph@0 133 set = function(o,v,...) self.db.profile.checkFood = v end,
Xiiph@0 134 get = function() return self.db.profile.checkFood end,
Xiiph@0 135 },
Xiiph@0 136 advertiseICU = {
Xiiph@0 137 type = 'toggle',
Xiiph@0 138 name = L["Advertise ICU"],
Xiiph@0 139 desc = L["Let everyone know you are using ICU! Prefixes whispers and reports"],
Xiiph@0 140 set = function(o,v,...) self.db.profile.advertiseICU = v end,
Xiiph@0 141 get = function() return self.db.profile.advertiseICU end,
Xiiph@0 142 },
Xiiph@0 143 remindRaider = {
Xiiph@0 144 type = 'toggle',
Xiiph@0 145 name = L["Raid reminder"],
Xiiph@0 146 desc = L["Whisper the raider lacking (or soon to expire, if enabled) food/flask buff a reminder"],
Xiiph@0 147 set = function(o,v,...) self.db.profile.remindRaider = v end,
Xiiph@0 148 get = function() return self.db.profile.remindRaider end,
Xiiph@0 149 },
Xiiph@0 150 reportResults = {
Xiiph@0 151 type = 'toggle',
Xiiph@0 152 name = L["Report results"],
Xiiph@0 153 desc = L["Report the results after finishing"],
Xiiph@0 154 set = function(o,v,...) self.db.profile.reportResults = v end,
Xiiph@0 155 get = function() return self.db.profile.reportResults end,
Xiiph@0 156 },
Xiiph@0 157 reportDestination = {
Xiiph@0 158 type = 'select',
Xiiph@0 159 style = "dropdown",
Xiiph@0 160 name = L["Report Destination"],
Xiiph@0 161 desc = L["Report the results to the following channel"],
Xiiph@0 162 values = {
Xiiph@0 163 ["OFFICER"] = L["Officer"],
Xiiph@0 164 ["SAY"] = L["Say"],
Xiiph@0 165 ["RAID"] = L["Raid"],
Xiiph@0 166 ["GUILD"] = L["Guild"],
Xiiph@0 167 ["SELF"] = L["Self"],
Xiiph@0 168 },
Xiiph@0 169 set = function(o,v,...) self.db.profile.reportDestination = v end,
Xiiph@0 170 get = function() return self.db.profile.reportDestination end,
Xiiph@0 171 },
Xiiph@0 172 manualCheckOnly = {
Xiiph@0 173 type = 'toggle',
Xiiph@0 174 name = L["Manual checks only"],
Xiiph@0 175 desc = L["Only perform buff checks if initiated manually (via /icu check)"],
Xiiph@0 176 set = function(o,v,...) self.db.profile.manualCheckOnly = v; self:refreshConfig() end,
Xiiph@0 177 get = function() return self.db.profile.manualCheckOnly end,
Xiiph@0 178 },
Xiiph@0 179 checkAfterFinish = {
Xiiph@0 180 type = 'toggle',
Xiiph@0 181 name = L["Check after readycheck"],
Xiiph@0 182 desc = L["Don't check buffs until ready check has finished (or timed out)"],
Xiiph@0 183 set = function(o,v,...) self.db.profile.checkAfterFinish = v end,
Xiiph@0 184 get = function() return self.db.profile.checkAfterFinish end,
Xiiph@0 185 },
Xiiph@0 186 noFlaskMessage = {
Xiiph@0 187 type = 'input',
Xiiph@0 188 name = L["Flask reminder"],
Xiiph@0 189 desc = L["Message whispered to raiders missing a cataclysm flask"],
Xiiph@0 190 set = function(o,v,...) self.db.profile.noFlaskMessage = v end,
Xiiph@0 191 get = function() return self.db.profile.noFlaskMessage end,
Xiiph@0 192 },
Xiiph@0 193 lowFlaskDurationMessage = {
Xiiph@0 194 type = 'input',
Xiiph@0 195 name = L["Flask expiration"],
Xiiph@0 196 desc = L["Message whispered to raiders with less than 10 minutes left on their flask"],
Xiiph@0 197 set = function(o,v,...) self.db.profile.lowFlaskDurationMessage = v end,
Xiiph@0 198 get = function() return self.db.profile.lowFlaskDurationMessage end,
Xiiph@0 199 },
Xiiph@0 200 noFoodMessage = {
Xiiph@0 201 type = 'input',
Xiiph@0 202 name = L["Food reminder"],
Xiiph@0 203 desc = L["Message whispered to raiders missing the well-fed buff"],
Xiiph@0 204 set = function(o,v,...) self.db.profile.noFoodMessage = v end,
Xiiph@0 205 get = function() return self.db.profile.noFoodMessage end,
Xiiph@0 206 },
Xiiph@0 207
Xiiph@0 208 }
Xiiph@0 209 },
Xiiph@0 210 profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db),
Xiiph@0 211 },
Xiiph@0 212 }
Xiiph@0 213 return options
Xiiph@0 214 end
Xiiph@0 215
Xiiph@0 216 function icu:inspectRaid(silent)
Xiiph@0 217 -- Not in a raid group
Xiiph@0 218 local icuAd = "";
Xiiph@0 219
Xiiph@0 220 if GetNumRaidMembers() == 0 then
Xiiph@0 221 return true
Xiiph@0 222 end
Xiiph@0 223
Xiiph@0 224 if self.db.profile.advertiseICU then
Xiiph@0 225 icuAd = L["ICU"] .. ": ";
Xiiph@0 226 else
Xiiph@0 227 icuAd = "";
Xiiph@0 228 end
Xiiph@0 229
Xiiph@0 230 for i = 1, GetNumRaidMembers() do
Xiiph@0 231 local raider = GetRaidRosterInfo(i);
Xiiph@0 232 if raider then
Xiiph@0 233
Xiiph@0 234 local hasFood, hasFlask, hasLowDuration = icu:validateBuffs(i);
Xiiph@0 235
Xiiph@0 236 if not hasFood and self.db.profile.checkFood then
Xiiph@0 237 noFood[#noFood+1] = raider;
Xiiph@0 238 -- Tell player
Xiiph@0 239 if self.db.profile.remindRaider and not silent then
Xiiph@0 240 SendChatMessage(icuAd .. self.db.profile.noFoodMessage,"WHISPER",nil,raider);
Xiiph@0 241 end
Xiiph@0 242 end
Xiiph@0 243
Xiiph@0 244 if not hasFlask and self.db.profile.checkFlask then
Xiiph@0 245 noFlask[#noFlask+1] = raider;
Xiiph@0 246 -- Tell player
Xiiph@0 247 if self.db.profile.remindRaider and not silent then
Xiiph@0 248 SendChatMessage(icuAd .. self.db.profile.noFlaskMessage,"WHISPER",nil,raider);
Xiiph@0 249 end
Xiiph@0 250 elseif hasLowDuration and not silent then
Xiiph@0 251 if self.db.profile.remindRaider and self.db.profile.checkLowFlaskDuration then
Xiiph@0 252 SendChatMessage(icuAd .. self.db.profile.lowFlaskDurationMessage,"WHISPER",nil,raider);
Xiiph@0 253 end
Xiiph@0 254 end
Xiiph@0 255 end
Xiiph@0 256
Xiiph@0 257 end
Xiiph@0 258
Xiiph@0 259 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 260 SendChatMessage("---- "..L["ICU"].." "..L["Report"].." ----",self.db.profile.reportDestination,nil,nil);
Xiiph@0 261 end
Xiiph@0 262
Xiiph@0 263 if self.db.profile.reportResults then
Xiiph@0 264 if #noFlask > 0 and self.db.profile.checkFlask then
Xiiph@0 265 local reportFlaskMessage = L["Missing Flask"]..": " .. table.concat(noFlask, ", ");
Xiiph@0 266
Xiiph@0 267 if self.db.profile.reportDestination == "SELF" then
Xiiph@0 268 DEFAULT_CHAT_FRAME:AddMessage(reportFlaskMessage);
Xiiph@0 269 else
Xiiph@0 270 SendChatMessage(reportFlaskMessage,self.db.profile.reportDestination,nil,nil);
Xiiph@0 271 end
Xiiph@0 272 end
Xiiph@0 273
Xiiph@0 274 if #noFood > 0 and self.db.profile.checkFood then
Xiiph@0 275 local reportFoodMessage = L["Missing Food"]..": " .. table.concat(noFood, ", ");
Xiiph@0 276
Xiiph@0 277 if self.db.profile.reportDestination == "SELF" then
Xiiph@0 278 DEFAULT_CHAT_FRAME:AddMessage(reportFoodMessage);
Xiiph@0 279 else
Xiiph@0 280 SendChatMessage(reportFoodMessage,self.db.profile.reportDestination,nil,nil);
Xiiph@0 281 end
Xiiph@0 282 end
Xiiph@0 283 end
Xiiph@0 284
Xiiph@0 285 noFlask, noFood, hasLowDuration = {},{},{};
Xiiph@0 286 end
Xiiph@0 287
Xiiph@0 288 function icu:validateBuffs(playerIndex)
Xiiph@0 289 local i = 1;
Xiiph@0 290 local hasFood, hasFlask, hasLowDuration = false, false, false;
Xiiph@0 291 local name, _, _, _, _, _, expirationTime, _, _, _, spellId = UnitBuff("raid"..playerIndex,i);
Xiiph@0 292
Xiiph@0 293 while name do
Xiiph@0 294 -- Check for food
Xiiph@0 295 if not hasFood then
Xiiph@0 296 for k,v in ipairs(foodID) do
Xiiph@0 297 if v == spellId then
Xiiph@0 298 hasFood = true;
Xiiph@0 299 end
Xiiph@0 300 end
Xiiph@0 301 end
Xiiph@0 302 -- Check for flask
Xiiph@0 303 if not hasFlask then
Xiiph@0 304 for k,v in ipairs(flaskID) do
Xiiph@0 305 if v == spellId then
Xiiph@0 306 hasFlask = true;
Xiiph@0 307 -- Check if low duration
Xiiph@0 308 if expirationTime and ((expirationTime-GetTime())/60) <= minFlaskDuration then
Xiiph@0 309 hasLowDuration = true;
Xiiph@0 310 end
Xiiph@0 311 end
Xiiph@0 312 end
Xiiph@0 313 end
Xiiph@0 314 i = i + 1;
Xiiph@0 315 name, _, _, _, _, _, expirationTime, _, _, _, spellId = UnitBuff("raid"..playerIndex,i);
Xiiph@0 316 end
Xiiph@0 317
Xiiph@0 318 return hasFood, hasFlask, hasLowDuration;
Xiiph@0 319 end
Xiiph@0 320
Xiiph@0 321 function icu:READY_CHECK()
Xiiph@0 322 --print("Ready check init!");
Xiiph@0 323 if self.db.profile.manualCheckOnly then
Xiiph@0 324 icu:UnregisterEvent("READY_CHECK");
Xiiph@0 325 return true;
Xiiph@0 326 end
Xiiph@0 327
Xiiph@0 328 if not self.db.profile.checkAfterFinish then
Xiiph@0 329 self:inspectRaid();
Xiiph@0 330 else
Xiiph@0 331 self:ScheduleTimer("READY_CHECK_FINISHED", 30);
Xiiph@0 332 self:RegisterEvent("READY_CHECK_FINISHED");
Xiiph@0 333 end
Xiiph@0 334 end
Xiiph@0 335
Xiiph@0 336 function icu:READY_CHECK_FINISHED()
Xiiph@0 337 --print("Ready check finish!");
Xiiph@0 338 self:UnregisterEvent("READY_CHECK_FINISHED");
Xiiph@0 339 self:CancelAllTimers();
Xiiph@0 340 self:inspectRaid();
Xiiph@0 341 end
Xiiph@0 342
Xiiph@0 343 function icu:filterChat(self, event, msg)
Xiiph@0 344 if msg == self.db.profile.noFoodMessage or msg == self.db.profile.noFlaskMessage or msg == self.db.profile.lowFlaskDurationMessage or msg == L["ICU"]..": "..self.db.profile.noFoodMessage or msg == L["ICU"]..": "..self.db.profile.noFlaskMessage or msg == L["ICU"]..": "..self.db.profile.lowFlaskDurationMessage then return true end
Xiiph@0 345 end
Xiiph@0 346 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_ICU_INFORM", icu:filterChat)
Xiiph@0 347
Xiiph@0 348 icu:RegisterEvent("READY_CHECK");
Xiiph@0 349
Xiiph@0 350 --@do-not-package@
Xiiph@0 351 function icu:test(cond)
Xiiph@0 352 if true and not cond then
Xiiph@0 353 print("First.")
Xiiph@0 354 else
Xiiph@0 355 print("Second.")
Xiiph@0 356 end
Xiiph@0 357 end
Xiiph@0 358
Xiiph@0 359 function icu:grabVar(var)
Xiiph@0 360 print(self.db.profile[var])
Xiiph@0 361 end
Xiiph@0 362
Xiiph@0 363 _G.icu = icu;
Xiiph@0 364 --@end-do-not-package@