annotate Constants.lua @ 61:cf2b6b9a8337 v23

6.2 update, shopping list bug fixes, ui scale option
author yellowfive
date Tue, 23 Jun 2015 00:27:21 -0700
parents ee701ce45354
children f1d5827dbde0
rev   line source
yellowfive@57 1 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
yellowfive@57 2 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true)
yellowfive@57 3
yellowfive@57 4 -- min import version that we will read from the website
yellowfive@59 5 Amr.MIN_IMPORT_VERSION = 21
yellowfive@57 6
yellowfive@57 7 -- min addon version that we will support for inter-addon communication for e.g. the team optimizer
yellowfive@59 8 Amr.MIN_ADDON_VERSION = 22
yellowfive@57 9
yellowfive@57 10 -- import some constants from the serializer for convenience
yellowfive@57 11 Amr.ChatPrefix = Amr.Serializer.ChatPrefix
yellowfive@57 12 Amr.RegionNames = Amr.Serializer.RegionNames
yellowfive@57 13 Amr.SlotIds = Amr.Serializer.SlotIds
yellowfive@57 14 Amr.SpecIds = Amr.Serializer.SpecIds
yellowfive@57 15 Amr.ClassIds = Amr.Serializer.ClassIds
yellowfive@57 16 Amr.ProfessionIds = Amr.Serializer.ProfessionIds
yellowfive@57 17 Amr.RaceIds = Amr.Serializer.RaceIds
yellowfive@57 18 Amr.FactionIds = Amr.Serializer.FactionIds
yellowfive@57 19 Amr.InstanceIds = Amr.Serializer.InstanceIds
yellowfive@57 20 Amr.SupportedInstanceIds = Amr.Serializer.SupportedInstanceIds
yellowfive@57 21 Amr.ParseItemLink = Amr.Serializer.ParseItemLink
yellowfive@57 22 Amr.IsSupportedInstanceId = Amr.Serializer.IsSupportedInstanceId
yellowfive@57 23 Amr.IsSupportedInstance = Amr.Serializer.IsSupportedInstance
yellowfive@57 24 Amr.SetTokenIds = Amr.Serializer.SetTokenIds
yellowfive@57 25
yellowfive@57 26 -- map of slot ID to display text
yellowfive@57 27 Amr.SlotDisplayText = {
yellowfive@57 28 [1] = _G["HEADSLOT"],
yellowfive@57 29 [2] = _G["NECKSLOT"],
yellowfive@57 30 [3] = _G["SHOULDERSLOT"],
yellowfive@57 31 [5] = _G["CHESTSLOT"],
yellowfive@57 32 [6] = _G["WAISTSLOT"],
yellowfive@57 33 [7] = _G["LEGSSLOT"],
yellowfive@57 34 [8] = _G["FEETSLOT"],
yellowfive@57 35 [9] = _G["WRISTSLOT"],
yellowfive@57 36 [10] = _G["HANDSSLOT"],
yellowfive@57 37 [11] = _G["FINGER0SLOT"] .. " 1",
yellowfive@57 38 [12] = _G["FINGER1SLOT"] .. " 2",
yellowfive@57 39 [13] = _G["TRINKET0SLOT"] .. " 1",
yellowfive@57 40 [14] = _G["TRINKET1SLOT"] .. " 2",
yellowfive@57 41 [15] = _G["BACKSLOT"],
yellowfive@57 42 [16] = _G["MAINHANDSLOT"],
yellowfive@57 43 [17] = _G["SECONDARYHANDSLOT"]
yellowfive@57 44 }
yellowfive@57 45
yellowfive@57 46 Amr.SlotEnumDisplayText = {
yellowfive@57 47 Head = _G["HEADSLOT"],
yellowfive@57 48 Neck = _G["NECKSLOT"],
yellowfive@57 49 Shoulder = _G["SHOULDERSLOT"],
yellowfive@57 50 Chest = _G["CHESTSLOT"],
yellowfive@57 51 Waist = _G["WAISTSLOT"],
yellowfive@57 52 Legs = _G["LEGSSLOT"],
yellowfive@57 53 Feet = _G["FEETSLOT"],
yellowfive@57 54 Wrist = _G["WRISTSLOT"],
yellowfive@57 55 Hands = _G["HANDSSLOT"],
yellowfive@57 56 Finger1 = _G["FINGER0SLOT"],
yellowfive@57 57 Finger2 = _G["FINGER0SLOT"],
yellowfive@57 58 Trinket1 = _G["TRINKET0SLOT"],
yellowfive@57 59 Trinket2 = _G["TRINKET0SLOT"],
yellowfive@57 60 Back = _G["BACKSLOT"],
yellowfive@57 61 MainHand = _G["MAINHANDSLOT"],
yellowfive@57 62 OffHand = _G["SECONDARYHANDSLOT"]
yellowfive@57 63 }
yellowfive@57 64
yellowfive@57 65 Amr.SpecIcons = {
yellowfive@57 66 [1] = "spell_deathknight_bloodpresence", -- DeathKnightBlood
yellowfive@57 67 [2] = "spell_deathknight_frostpresence", -- DeathKnightFrost
yellowfive@57 68 [3] = "spell_deathknight_unholypresence", -- DeathKnightUnholy
yellowfive@57 69 [4] = "spell_nature_starfall", -- DruidBalance
yellowfive@57 70 [5] = "ability_druid_catform", -- DruidFeral
yellowfive@57 71 [6] = "ability_racial_bearform", -- DruidGuardian
yellowfive@57 72 [7] = "spell_nature_healingtouch", -- DruidRestoration
yellowfive@57 73 [8] = "ability_hunter_bestialdiscipline", -- HunterBeastMastery
yellowfive@57 74 [9] = "ability_hunter_focusedaim", -- HunterMarksmanship
yellowfive@57 75 [10] = "ability_hunter_camouflage", -- HunterSurvival
yellowfive@57 76 [11] = "spell_holy_magicalsentry", -- MageArcane
yellowfive@57 77 [12] = "spell_fire_firebolt02", -- MageFire
yellowfive@57 78 [13] = "spell_frost_frostbolt02", -- MageFrost
yellowfive@57 79 [14] = "spell_monk_brewmaster_spec", -- MonkBrewmaster
yellowfive@57 80 [15] = "spell_monk_mistweaver_spec", -- MonkMistweaver
yellowfive@57 81 [16] = "spell_monk_windwalker_spec", -- MonkWindwalker
yellowfive@57 82 [17] = "spell_holy_holybolt", -- PaladinHoly
yellowfive@57 83 [18] = "ability_paladin_shieldofthetemplar", -- PaladinProtection
yellowfive@57 84 [19] = "spell_holy_auraoflight", -- PaladinRetribution
yellowfive@57 85 [20] = "spell_holy_powerwordshield", -- PriestDiscipline
yellowfive@57 86 [21] = "spell_holy_guardianspirit", -- PriestHoly
yellowfive@57 87 [22] = "spell_shadow_shadowwordpain", -- PriestShadow
yellowfive@57 88 [23] = "ability_rogue_eviscerate", -- RogueAssassination
yellowfive@57 89 [24] = "ability_backstab", -- RogueCombat
yellowfive@57 90 [25] = "ability_stealth", -- RogueSubtlety
yellowfive@57 91 [26] = "spell_nature_lightning", -- ShamanElemental
yellowfive@57 92 [27] = "spell_nature_lightningshield", -- ShamanEnhancement
yellowfive@57 93 [28] = "spell_nature_magicimmunity", -- ShamanRestoration
yellowfive@57 94 [29] = "spell_shadow_deathcoil", -- WarlockAffliction
yellowfive@57 95 [30] = "spell_shadow_metamorphosis", -- WarlockDemonology
yellowfive@57 96 [31] = "spell_shadow_rainoffire", -- WarlockDestruction
yellowfive@57 97 [32] = "ability_warrior_savageblow", -- WarriorArms
yellowfive@57 98 [33] = "ability_warrior_innerrage", -- WarriorFury
yellowfive@57 99 [34] = "ability_warrior_defensivestance", -- WarriorProtection
yellowfive@57 100 [38] = "ability_warrior_defensivestance", -- WarriorProtection, used for special subspec handling
yellowfive@57 101 [39] = "spell_warrior_gladiatorstance" -- WarriorProtectionGlad, used for special subspec handling
yellowfive@57 102 }
yellowfive@57 103
yellowfive@57 104 -- instance IDs ordered in preferred display order
yellowfive@61 105 Amr.InstanceIdsOrdered = { 1448, 1205, 1228 }
yellowfive@57 106
yellowfive@57 107 Amr.Difficulties = {
yellowfive@57 108 Lfr = 17,
yellowfive@57 109 Normal = 14,
yellowfive@57 110 Heroic = 15,
yellowfive@57 111 Mythic = 16
yellowfive@57 112 }
yellowfive@57 113
yellowfive@57 114 -- get the game's spec id from the AMR spec id
yellowfive@57 115 function Amr.GetGameSpecId(specId)
yellowfive@57 116 for k, v in pairs(Amr.SpecIds) do
yellowfive@57 117 if v == specId then return k end
yellowfive@57 118 end
yellowfive@57 119 return nil
yellowfive@57 120 end
yellowfive@57 121
yellowfive@57 122
yellowfive@57 123 ------------------------------------------------------------------------------------------
yellowfive@57 124 -- Item Methods
yellowfive@57 125 ------------------------------------------------------------------------------------------
yellowfive@57 126
yellowfive@57 127 -- 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@57 128
yellowfive@57 129 function Amr.CreateItemLink(itemObj)
yellowfive@57 130
yellowfive@57 131 if itemObj == nil or itemObj.id == nil or itemObj.id == 0 then return nil end
yellowfive@57 132
yellowfive@57 133 local parts = {}
yellowfive@57 134 table.insert(parts, "item")
yellowfive@57 135 table.insert(parts, itemObj.id)
yellowfive@57 136 table.insert(parts, itemObj.enchantId)
yellowfive@57 137 table.insert(parts, itemObj.gemIds[1])
yellowfive@57 138 table.insert(parts, itemObj.gemIds[2])
yellowfive@57 139 table.insert(parts, itemObj.gemIds[3])
yellowfive@57 140 table.insert(parts, itemObj.gemIds[4])
yellowfive@57 141
yellowfive@57 142 if itemObj.suffixId == 0 then
yellowfive@57 143 table.insert(parts, 0)
yellowfive@57 144 else
yellowfive@57 145 table.insert(parts, -math.abs(itemObj.suffixId))
yellowfive@57 146 end
yellowfive@57 147
yellowfive@57 148 table.insert(parts, 0)
yellowfive@57 149 table.insert(parts, UnitLevel("player"))
yellowfive@57 150 table.insert(parts, itemObj.upgradeId)
yellowfive@57 151 table.insert(parts, 0)
yellowfive@57 152
yellowfive@57 153 if itemObj.bonusIds then
yellowfive@57 154 table.insert(parts, #itemObj.bonusIds)
yellowfive@57 155 for i,v in ipairs(itemObj.bonusIds) do
yellowfive@57 156 table.insert(parts, v)
yellowfive@57 157 end
yellowfive@57 158 end
yellowfive@57 159
yellowfive@57 160 return table.concat(parts, ":")
yellowfive@57 161 end
yellowfive@57 162
yellowfive@57 163 -- a unique ID useful for determining if a player has an item equipped or not
yellowfive@57 164 function Amr.GetItemUniqueId(item, noUpgrade)
yellowfive@57 165 if item == nil then return "" end
yellowfive@57 166 local ret = item.id .. ""
yellowfive@57 167 if item.bonusIds then
yellowfive@57 168 for i = 1, #item.bonusIds do
yellowfive@57 169 ret = ret .. "b" .. item.bonusIds[i]
yellowfive@57 170 end
yellowfive@57 171 end
yellowfive@57 172 if item.suffixId ~= 0 then
yellowfive@57 173 ret = ret .. "s" .. item.suffixId
yellowfive@57 174 end
yellowfive@57 175 if not noUpgrade and item.upgradeId ~= 0 then
yellowfive@57 176 ret = ret .. "u" .. item.upgradeId
yellowfive@57 177 end
yellowfive@57 178 return ret
yellowfive@57 179 end
yellowfive@57 180
yellowfive@57 181 -- the server event for getting item info does not specify which item it just fetched... have to track manually
yellowfive@57 182 local _pendingItemIds = {}
yellowfive@57 183
yellowfive@57 184 -- helper for getting item information, which is not always guaranteed to be loaded into memory
yellowfive@57 185 function Amr.GetItemInfo(itemIdOrLinkOrName, callback, customArg)
yellowfive@57 186 if not itemIdOrLinkOrName then
yellowfive@57 187 callback(customArg)
yellowfive@57 188 return
yellowfive@57 189 end
yellowfive@57 190
yellowfive@57 191 -- see if we can get the information immediately
yellowfive@57 192 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemIdOrLinkOrName)
yellowfive@57 193 if name then
yellowfive@57 194 callback(customArg, name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice)
yellowfive@57 195 return
yellowfive@57 196 end
yellowfive@57 197
yellowfive@57 198 -- get the list of registered callbacks for this particular item
yellowfive@57 199 local list = _pendingItemIds[itemIdOrLinkOrName]
yellowfive@57 200 -- if there was a list, then just add the callback to the list
yellowfive@57 201 if list then
yellowfive@57 202 table.insert(list, { Callback = callback, Arg = customArg })
yellowfive@57 203 else
yellowfive@57 204 -- there wasn't a list, so make a new one with this callback
yellowfive@57 205 _pendingItemIds[itemIdOrLinkOrName] = { { Callback = callback, Arg = customArg } }
yellowfive@57 206 end
yellowfive@57 207 end
yellowfive@57 208
yellowfive@57 209 Amr:AddEventHandler("GET_ITEM_INFO_RECEIVED", function()
yellowfive@57 210 -- go through all unresolved items since we don't know which one was just resolved
yellowfive@57 211 for itemId, callbacks in pairs(_pendingItemIds) do
yellowfive@57 212 -- attempt to get the item info again, remove from pending list if we find it
yellowfive@57 213 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemId)
yellowfive@57 214 if name then
yellowfive@57 215 _pendingItemIds[itemId] = nil
yellowfive@57 216
yellowfive@57 217 -- call each callback
yellowfive@57 218 for i = 1, #callbacks do
yellowfive@57 219 callbacks[i].Callback(callbacks[i].Arg, name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice)
yellowfive@57 220 end
yellowfive@57 221 end
yellowfive@57 222 end
yellowfive@57 223 end)