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