annotate amr-constants.lua @ 33:4ba69d2ee252 v9

fixed bug with gem changes not appearing sometimes, mainWindow crash on startup, lua error for unknown item tooltips
author yellowfive
date Sat, 18 Oct 2014 18:13:55 -0700
parents 44c285acfff0
children 561cf98ced21
rev   line source
adam@17 1 local _, AskMrRobot = ...
adam@17 2 local L = AskMrRobot.L;
adam@17 3
adam@17 4 -- item link format: |cffa335ee|Hitem:itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:upgradeId:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2...|h[item name]|h|r
adam@17 5
adam@17 6 -- get an object with all of the parts fo the item link format that we care about
adam@17 7 function AskMrRobot.parseItemLink(itemLink)
adam@17 8 if not itemLink then return nil end
adam@17 9
adam@17 10 local str = string.match(itemLink, "|Hitem:([\-%d:]+)|")
adam@17 11 if not str then return nil end
adam@17 12
adam@17 13 local parts = { strsplit(":", str) }
adam@17 14
adam@17 15 local item = {}
adam@17 16 item.id = tonumber(parts[1])
adam@17 17 item.enchantId = tonumber(parts[2])
adam@17 18 item.gemIds = { tonumber(parts[3]), tonumber(parts[4]), tonumber(parts[5]), tonumber(parts[6]) }
adam@17 19 item.suffixId = math.abs(tonumber(parts[7])) -- convert suffix to positive number, that's what we use in our code
adam@17 20 --item.uniqueId = tonumber(parts[8])
adam@17 21 --item.level = tonumber(parts[9])
adam@17 22 item.upgradeId = tonumber(parts[10])
adam@17 23 --item.difficultyId = tonumber(parts[11])
adam@17 24
adam@17 25 local numBonuses = tonumber(parts[12])
adam@28 26 if numBonuses and numBonuses > 0 then
adam@17 27 item.bonusIds = {}
adam@17 28 for i = 13, 12 + numBonuses do
adam@17 29 table.insert(item.bonusIds, tonumber(parts[i]))
adam@17 30 end
adam@17 31 end
adam@17 32
adam@17 33 return item
adam@17 34 end
adam@17 35
yellowfive@31 36 -- item link format: |cffa335ee|Hitem:itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:upgradeId:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2...|h[item name]|h|r
yellowfive@31 37
yellowfive@31 38 function AskMrRobot.createItemLink(itemObj)
yellowfive@31 39
yellowfive@31 40 if itemObj == nil or itemObj.id == nil or itemObj.id == 0 then return nil end
yellowfive@31 41
yellowfive@31 42 local parts = {}
yellowfive@31 43 table.insert(parts, "item")
yellowfive@31 44 table.insert(parts, itemObj.id)
yellowfive@31 45 table.insert(parts, itemObj.enchantId)
yellowfive@31 46 table.insert(parts, itemObj.gemIds[1])
yellowfive@31 47 table.insert(parts, itemObj.gemIds[2])
yellowfive@31 48 table.insert(parts, itemObj.gemIds[3])
yellowfive@31 49 table.insert(parts, itemObj.gemIds[4])
yellowfive@33 50
yellowfive@33 51 if itemObj.suffixId == 0 then
yellowfive@33 52 table.insert(parts, 0)
yellowfive@33 53 else
yellowfive@33 54 table.insert(parts, -math.abs(itemObj.suffixId))
yellowfive@33 55 end
yellowfive@33 56
yellowfive@31 57 table.insert(parts, 0)
yellowfive@31 58 table.insert(parts, UnitLevel("player"))
yellowfive@31 59 table.insert(parts, itemObj.upgradeId)
yellowfive@31 60 table.insert(parts, 0)
yellowfive@31 61
yellowfive@31 62 if itemObj.bonusIds then
yellowfive@31 63 table.insert(parts, #itemObj.bonusIds)
yellowfive@31 64 for i,v in ipairs(itemObj.bonusIds) do
yellowfive@31 65 table.insert(parts, v)
yellowfive@31 66 end
yellowfive@31 67 end
yellowfive@31 68
yellowfive@31 69 return table.concat(parts, ":")
yellowfive@31 70 end
yellowfive@31 71
yellowfive@31 72 function AskMrRobot.createGemLink(gemId)
yellowfive@31 73
yellowfive@31 74 end
yellowfive@31 75
adam@17 76 -- convenience to get just the item id (or 0 if not a valid link) from an item link
adam@17 77 function AskMrRobot.getItemIdFromLink(itemLink)
adam@17 78 if not itemLink then return 0 end
adam@17 79 local parts = { strsplit(":", itemLink) }
adam@17 80 local id = tonumber(parts[2])
adam@17 81 return (id and id ~= 0 and id or 0)
adam@17 82 end
adam@17 83
adam@17 84 function AskMrRobot.getItemUniqueId(item, noUpgrade)
adam@17 85 if item == nil then return "" end
adam@17 86 local ret = item.id .. ""
adam@17 87 if item.bonusIds then
adam@17 88 for i = 1, #item.bonusIds do
adam@17 89 ret = ret .. "b" .. item.bonusIds[i]
adam@17 90 end
adam@17 91 end
adam@17 92 if item.suffixId ~= 0 then
adam@17 93 ret = ret .. "s" .. item.suffixId
adam@17 94 end
adam@17 95 if not noUpgrade and item.upgradeId ~= 0 then
adam@17 96 ret = ret .. "u" .. item.upgradeId
adam@17 97 end
adam@17 98 return ret
adam@17 99 end
adam@17 100
adam@17 101 AskMrRobot.instanceIds = {
adam@17 102 HeartOfFear = 1009,
adam@17 103 MogushanVaults = 1008,
adam@17 104 SiegeOfOrgrimmar = 1136,
adam@17 105 TerraceOfEndlessSpring = 996,
adam@17 106 ThroneOfThunder = 1098
adam@17 107 }
adam@17 108
adam@17 109 -- instances that we currently support logging for
adam@17 110 AskMrRobot.supportedInstanceIds = {
adam@17 111 [1136] = true
adam@17 112 }
adam@17 113
adam@17 114 -- returns true if currently in a supported instance
adam@17 115 function AskMrRobot.IsSupportedInstance()
adam@17 116
adam@17 117 local zone, _, difficultyIndex, _, _, _, _, instanceMapID = GetInstanceInfo()
adam@17 118 if AskMrRobot.supportedInstanceIds[tonumber(instanceMapID)] then
adam@17 119 return true
adam@17 120 else
adam@17 121 return false
adam@17 122 end
adam@17 123 end
adam@17 124
adam@17 125 AskMrRobot.classIds = {
adam@17 126 ["NONE"] = 0,
adam@17 127 ["DEATHKNIGHT"] = 1,
adam@17 128 ["DRUID"] = 2,
adam@17 129 ["HUNTER"] = 3,
adam@17 130 ["MAGE"] = 4,
adam@17 131 ["MONK"] = 5,
adam@17 132 ["PALADIN"] = 6,
adam@17 133 ["PRIEST"] = 7,
adam@17 134 ["ROGUE"] = 8,
adam@17 135 ["SHAMAN"] = 9,
adam@17 136 ["WARLOCK"] = 10,
adam@17 137 ["WARRIOR"] = 11,
adam@17 138 }
adam@17 139
adam@17 140 AskMrRobot.professionIds = {
adam@17 141 ["None"] = 0,
adam@17 142 ["Mining"] = 1,
adam@17 143 ["Skinning"] = 2,
adam@17 144 ["Herbalism"] = 3,
adam@17 145 ["Enchanting"] = 4,
adam@17 146 ["Jewelcrafting"] = 5,
adam@17 147 ["Engineering"] = 6,
adam@17 148 ["Blacksmithing"] = 7,
adam@17 149 ["Leatherworking"] = 8,
adam@17 150 ["Inscription"] = 9,
adam@17 151 ["Tailoring"] = 10,
adam@17 152 ["Alchemy"] = 11,
adam@17 153 ["Fishing"] = 12,
adam@17 154 ["Cooking"] = 13,
adam@17 155 ["First Aid"] = 14,
adam@17 156 ["Archaeology"] = 15
adam@17 157 }
adam@17 158
adam@17 159 AskMrRobot.raceIds = {
adam@17 160 ["None"] = 0,
adam@17 161 ["BloodElf"] = 1,
adam@17 162 ["Draenei"] = 2,
adam@17 163 ["Dwarf"] = 3,
adam@17 164 ["Gnome"] = 4,
adam@17 165 ["Human"] = 5,
adam@17 166 ["NightElf"] = 6,
adam@17 167 ["Orc"] = 7,
adam@17 168 ["Tauren"] = 8,
adam@17 169 ["Troll"] = 9,
adam@17 170 ["Scourge"] = 10,
adam@17 171 ["Undead"] = 10,
adam@17 172 ["Goblin"] = 11,
adam@17 173 ["Worgen"] = 12,
adam@17 174 ["Pandaren"] = 13
adam@17 175 }
adam@17 176
adam@17 177 AskMrRobot.factionIds = {
adam@17 178 ["None"] = 0,
adam@17 179 ["Alliance"] = 1,
adam@17 180 ["Horde"] = 2
adam@17 181 }
adam@17 182
adam@17 183 AskMrRobot.specIds = {
adam@17 184 [250] = 1, -- DeathKnightBlood
adam@17 185 [251] = 2, -- DeathKnightFrost
adam@17 186 [252] = 3, -- DeathKnightUnholy
adam@17 187 [102] = 4, -- DruidBalance
adam@17 188 [103] = 5, -- DruidFeral
adam@17 189 [104] = 6, -- DruidGuardian
adam@17 190 [105] = 7, -- DruidRestoration
adam@17 191 [253] = 8, -- HunterBeastMastery
adam@17 192 [254] = 9, -- HunterMarksmanship
adam@17 193 [255] = 10, -- HunterSurvival
adam@17 194 [62] = 11, -- MageArcane
adam@17 195 [63] = 12, -- MageFire
adam@17 196 [64] = 13, -- MageFrost
adam@17 197 [268] = 14, -- MonkBrewmaster
yellowfive@23 198 [270] = 15, -- MonkMistweaver
yellowfive@23 199 [269] = 16, -- MonkWindwalker
adam@17 200 [65] = 17, -- PaladinHoly
adam@17 201 [66] = 18, -- PaladinProtection
adam@17 202 [70] = 19, -- PaladinRetribution
adam@17 203 [256] = 20, -- PriestDiscipline
adam@17 204 [257] = 21, -- PriestHoly
adam@17 205 [258] = 22, -- PriestShadow
adam@17 206 [259] = 23, -- RogueAssassination
adam@17 207 [260] = 24, -- RogueCombat
adam@17 208 [261] = 25, -- RogueSubtlety
adam@17 209 [262] = 26, -- ShamanElemental
adam@17 210 [263] = 27, -- ShamanEnhancement
adam@17 211 [264] = 28, -- ShamanRestoration
adam@17 212 [265] = 29, -- WarlockAffliction
adam@17 213 [266] = 30, -- WarlockDemonology
adam@17 214 [267] = 31, -- WarlockDestruction
adam@17 215 [71] = 32, -- WarriorArms
adam@17 216 [72] = 33, -- WarriorFury
adam@17 217 [73] = 34 -- WarriorProtection
adam@17 218 }
adam@17 219
adam@17 220 -- reverse map of our spec ID to the game's spec ID
adam@17 221 AskMrRobot.gameSpecIds = {}
adam@17 222 for k,v in pairs(AskMrRobot.specIds) do
adam@17 223 AskMrRobot.gameSpecIds[v] = k
adam@17 224 end
adam@17 225
adam@17 226 -- lookup from our socket color ID to string
adam@17 227 AskMrRobot.socketColorIds = {
adam@17 228 [0] = "Prismatic",
adam@17 229 [1] = "Red",
adam@17 230 [2] = "Yellow",
adam@17 231 [3] = "Blue",
adam@17 232 [4] = "Meta",
adam@17 233 [5] = "Cogwheel",
adam@17 234 [6] = "ShaTouched"
adam@17 235 }
adam@17 236
adam@17 237 -- map of game slot names to slot IDs (same both in our code and in-game)
adam@17 238 AskMrRobot.slotNameToId = {
adam@17 239 ["HeadSlot"] = 1,
adam@17 240 ["NeckSlot"] = 2,
adam@17 241 ["ShoulderSlot"] = 3,
adam@17 242 ["ChestSlot"] = 5,
adam@17 243 ["WaistSlot"] = 6,
adam@17 244 ["LegsSlot"] = 7,
adam@17 245 ["FeetSlot"] = 8,
adam@17 246 ["WristSlot"] = 9,
adam@17 247 ["HandsSlot"] = 10,
adam@17 248 ["Finger0Slot"] = 11,
adam@17 249 ["Finger1Slot"] = 12,
adam@17 250 ["Trinket0Slot"] = 13,
adam@17 251 ["Trinket1Slot"] = 14,
adam@17 252 ["BackSlot"] = 15,
adam@17 253 ["MainHandSlot"] = 16,
adam@17 254 ["SecondaryHandSlot"] = 17
adam@17 255 }
adam@17 256
adam@17 257 -- map of slot ID to display text
adam@17 258 AskMrRobot.slotDisplayText = {
adam@17 259 [1] = _G["HEADSLOT"],
adam@17 260 [2] = _G["NECKSLOT"],
adam@17 261 [3] = _G["SHOULDERSLOT"],
adam@17 262 [5] = _G["CHESTSLOT"],
adam@17 263 [6] = _G["WAISTSLOT"],
adam@17 264 [7] = _G["LEGSSLOT"],
adam@17 265 [8] = _G["FEETSLOT"],
yellowfive@31 266 [9] = _G["WRISTSLOT"],
adam@17 267 [10] = _G["HANDSSLOT"],
yellowfive@31 268 [11] = _G["FINGER0SLOT"] .. " 1",
yellowfive@31 269 [12] = _G["FINGER1SLOT"] .. " 2",
yellowfive@31 270 [13] = _G["TRINKET0SLOT"] .. " 1",
yellowfive@31 271 [14] = _G["TRINKET1SLOT"] .. " 2",
adam@17 272 [15] = _G["BACKSLOT"],
adam@17 273 [16] = _G["MAINHANDSLOT"],
adam@17 274 [17] = _G["SECONDARYHANDSLOT"]
adam@17 275 }
adam@17 276
adam@17 277 -- all slot IDs that we care about, ordered in our standard display order
adam@17 278 AskMrRobot.slotIds = { 16, 17, 1, 2, 3, 15, 5, 9, 10, 6, 7, 8, 11, 12, 13, 14 }
adam@17 279
adam@17 280 -- cache slot orders to make slot sorting easier
adam@17 281 local _slotIdToOrder = {}
adam@17 282 for i = 1, #AskMrRobot.slotIds do
adam@17 283 _slotIdToOrder[AskMrRobot.slotIds[i]] = i
adam@17 284 end
adam@17 285
adam@17 286 -- given a table where the keys are slot IDs, sort in the standard slot order
adam@17 287 function AskMrRobot.sortSlots(t)
adam@17 288 return AskMrRobot.spairs(t, function(x, a, b)
adam@17 289 if a == nil and b == nil then return 0 end
adam@17 290 return _slotIdToOrder[a] < _slotIdToOrder[b]
adam@17 291 end)
adam@17 292 end