comparison Main.lua @ 465:efdbef365ec0

Replaced local hacky map code with HereBeDragons library.
author Caleb Atherton <catherton@curse.com>
date Sat, 14 May 2016 23:38:15 -0400
parents 6e78d7849ea3
children eb87dbc295b3
comparison
equal deleted inserted replaced
464:6e78d7849ea3 465:efdbef365ec0
23 23
24 local LibStub = _G.LibStub 24 local LibStub = _G.LibStub
25 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceConsole-3.0", "AceEvent-3.0") 25 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceConsole-3.0", "AceEvent-3.0")
26 26
27 local deformat = LibStub("LibDeformat-3.0") 27 local deformat = LibStub("LibDeformat-3.0")
28 local HereBeDragons = LibStub("HereBeDragons-1.0")
28 29
29 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate") 30 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate")
30 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE") 31 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
31 32
32 33
142 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure", 143 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
143 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure", 144 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
144 UNIT_SPELLCAST_SENT = true, 145 UNIT_SPELLCAST_SENT = true,
145 UNIT_SPELLCAST_SUCCEEDED = true, 146 UNIT_SPELLCAST_SUCCEEDED = true,
146 VOID_STORAGE_OPEN = true, 147 VOID_STORAGE_OPEN = true,
147 ZONE_CHANGED = "HandleZoneChange",
148 ZONE_CHANGED_INDOORS = "HandleZoneChange",
149 ZONE_CHANGED_NEW_AREA = "HandleZoneChange",
150 } 148 }
151 149
152 150
153 -- VARIABLES ---------------------------------------------------------- 151 -- VARIABLES ----------------------------------------------------------
154 152
179 local last_garrison_cache_object_id 177 local last_garrison_cache_object_id
180 local block_chat_loot_data 178 local block_chat_loot_data
181 local chat_loot_data = {} 179 local chat_loot_data = {}
182 local chat_loot_timer_handle 180 local chat_loot_timer_handle
183 local current_target_id 181 local current_target_id
184 local current_area_id
185 local current_loot 182 local current_loot
186 183
187 184
188 -- Data for our current action. Including possible values as a reference. 185 -- Data for our current action. Including possible values as a reference.
189 local current_action = { 186 local current_action = {
208 205
209 local function Debug(message, ...) 206 local function Debug(message, ...)
210 if not DEBUGGING or not message then 207 if not DEBUGGING or not message then
211 return 208 return
212 end 209 end
213 210
214 if ... then 211 if ... then
215 local args = { ... } 212 local args = { ... }
216 213
217 for index = 1, #args do 214 for index = 1, #args do
218 args[index] = tostring(args[index]) 215 args[index] = tostring(args[index])
249 246
250 function TradeSkillExecutePer(iter_func) 247 function TradeSkillExecutePer(iter_func)
251 if not _G.TradeSkillFrame or not _G.TradeSkillFrame:IsVisible() then 248 if not _G.TradeSkillFrame or not _G.TradeSkillFrame:IsVisible() then
252 return 249 return
253 end 250 end
254 251
255 if (private.isLegion) then 252 if (private.isLegion) then
256 local recipes = _G.C_TradeSkillUI.GetAllRecipeIDs() 253 local recipes = _G.C_TradeSkillUI.GetAllRecipeIDs()
257 254
258 if recipes and (#recipes > 0) then 255 if recipes and (#recipes > 0) then
259 for i = 1, #recipes do 256 for i = 1, #recipes do
260 if iter_func(_G.C_TradeSkillUI.GetRecipeInfo(recipes[i]).name, recipes[i]) then 257 if iter_func(_G.C_TradeSkillUI.GetRecipeInfo(recipes[i]).name, recipes[i]) then
261 break 258 break
262 end 259 end
263 end 260 end
264 end 261 end
265 else 262 else
266 -- Clear the search box focus so the scan will have correct results. 263 -- Clear the search box focus so the scan will have correct results.
267 local search_box = _G.TradeSkillFrameSearchBox 264 local search_box = _G.TradeSkillFrameSearchBox
268 search_box:SetText("") 265 search_box:SetText("")
269 266
270 _G.TradeSkillSearch_OnTextChanged(search_box) 267 _G.TradeSkillSearch_OnTextChanged(search_box)
271 search_box:ClearFocus() 268 search_box:ClearFocus()
272 search_box:GetScript("OnEditFocusLost")(search_box) 269 search_box:GetScript("OnEditFocusLost")(search_box)
273 270
274 table.wipe(header_list) 271 table.wipe(header_list)
275 272
276 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it. 273 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it.
277 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials 274 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials
278 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp 275 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp
279 276
280 if have_materials then 277 if have_materials then
281 _G.TradeSkillFrame.filterTbl.hasMaterials = false 278 _G.TradeSkillFrame.filterTbl.hasMaterials = false
282 _G.TradeSkillOnlyShowMakeable(false) 279 _G.TradeSkillOnlyShowMakeable(false)
283 end 280 end
284 281
285 if have_skillup then 282 if have_skillup then
286 _G.TradeSkillFrame.filterTbl.hasSkillUp = false 283 _G.TradeSkillFrame.filterTbl.hasSkillUp = false
287 _G.TradeSkillOnlyShowSkillUps(false) 284 _G.TradeSkillOnlyShowSkillUps(false)
288 end 285 end
289 _G.SetTradeSkillInvSlotFilter(0, true, true) 286 _G.SetTradeSkillInvSlotFilter(0, true, true)
290 _G.TradeSkillUpdateFilterBar() 287 _G.TradeSkillUpdateFilterBar()
291 _G.TradeSkillFrame_Update() 288 _G.TradeSkillFrame_Update()
292 289
293 -- Expand all headers so we can see all the recipes there are 290 -- Expand all headers so we can see all the recipes there are
294 for tradeskill_index = 1, _G.GetNumTradeSkills() do 291 for tradeskill_index = 1, _G.GetNumTradeSkills() do
295 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index) 292 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
296 293
297 if tradeskill_type == "header" or tradeskill_type == "subheader" then 294 if tradeskill_type == "header" or tradeskill_type == "subheader" then
298 if not is_expanded then 295 if not is_expanded then
299 header_list[name] = true 296 header_list[name] = true
300 _G.ExpandTradeSkillSubClass(tradeskill_index) 297 _G.ExpandTradeSkillSubClass(tradeskill_index)
301 end 298 end
302 elseif iter_func(name, tradeskill_index) then 299 elseif iter_func(name, tradeskill_index) then
303 break 300 break
304 end 301 end
305 end 302 end
306 303
307 -- Restore the state of the things we changed. 304 -- Restore the state of the things we changed.
308 for tradeskill_index = 1, _G.GetNumTradeSkills() do 305 for tradeskill_index = 1, _G.GetNumTradeSkills() do
309 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index) 306 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
310 307
311 if header_list[name] then 308 if header_list[name] then
312 _G.CollapseTradeSkillSubClass(tradeskill_index) 309 _G.CollapseTradeSkillSubClass(tradeskill_index)
313 end 310 end
314 end 311 end
315 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials 312 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials
316 _G.TradeSkillOnlyShowMakeable(have_materials) 313 _G.TradeSkillOnlyShowMakeable(have_materials)
317 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup 314 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup
318 _G.TradeSkillOnlyShowSkillUps(have_skillup) 315 _G.TradeSkillOnlyShowSkillUps(have_skillup)
319 316
320 _G.TradeSkillUpdateFilterBar() 317 _G.TradeSkillUpdateFilterBar()
321 _G.TradeSkillFrame_Update() 318 _G.TradeSkillFrame_Update()
322 end 319 end
323 end 320 end
324 end -- do-block 321 end -- do-block
325 322
326 323
327 local ActualCopperCost 324 local ActualCopperCost
375 return "NONE:0:false" 372 return "NONE:0:false"
376 end 373 end
377 374
378 375
379 local function CurrentLocationData() 376 local function CurrentLocationData()
380 if _G.GetCurrentMapAreaID() ~= current_area_id then 377 local x, y, current_area_id, map_level = HereBeDragons:GetPlayerZonePosition(true)
381 return _G.GetRealZoneText(), current_area_id, 0, 0, 0, InstanceDifficultyToken() 378
382 end 379 -- Put coordinates into expected format (as integers, they don't get a billion decimals output in the SavedVariables)
383 local map_level = _G.GetCurrentMapDungeonLevel() or 0 380 local x_int = _G.floor(x * 1000)
384 local x, y = _G.GetPlayerMapPosition("player") 381 local y_int = _G.floor(y * 1000)
385 382 if x_int % 2 ~= 0 then
386 x = x or 0 383 x_int = x_int + 1
387 y = y or 0 384 end
388 385 if y_int % 2 ~= 0 then
389 if x == 0 and y == 0 then 386 y_int = y_int + 1
390 for level_index = 1, _G.GetNumDungeonMapLevels() do 387 end
391 _G.SetDungeonMapLevel(level_index) 388
392 x, y = _G.GetPlayerMapPosition("player") 389 return _G.GetRealZoneText(), current_area_id, x_int, y_int, map_level, InstanceDifficultyToken()
393
394 if x and y and (x > 0 or y > 0) then
395 _G.SetDungeonMapLevel(map_level)
396 map_level = level_index
397 break
398 end
399 end
400 end
401
402 if _G.DungeonUsesTerrainMap() then
403 map_level = map_level - 1
404 end
405 local x = _G.floor(x * 1000)
406 local y = _G.floor(y * 1000)
407
408 if x % 2 ~= 0 then
409 x = x + 1
410 end
411
412 if y % 2 ~= 0 then
413 y = y + 1
414 end
415 return _G.GetRealZoneText(), current_area_id, x, y, map_level, InstanceDifficultyToken()
416 end 390 end
417 391
418 392
419 local function DBEntry(data_type, unit_id) 393 local function DBEntry(data_type, unit_id)
420 if not data_type or not unit_id then 394 if not data_type or not unit_id then
610 local _, _, _, _, _, is_lootable = _G.GetContainerItemInfo(bag_index, slot_index) 584 local _, _, _, _, _, is_lootable = _G.GetContainerItemInfo(bag_index, slot_index)
611 if is_lootable then 585 if is_lootable then
612 any_loot = true 586 any_loot = true
613 end 587 end
614 end 588 end
615 589
616 -- Check if we've marked this item as one Blizzard provides bad is_lootable data for 590 -- Check if we've marked this item as one Blizzard provides bad is_lootable data for
617 if private.CONTAINER_ITEM_ID_LIST[item_id] ~= nil then 591 if private.CONTAINER_ITEM_ID_LIST[item_id] ~= nil then
618 any_loot = true 592 any_loot = true
619 end 593 end
620 594
813 return text 787 return text
814 end 788 end
815 end -- do-block 789 end -- do-block
816 790
817 791
818 -- Contains a dirty hack due to Blizzard's strange handling of Micro Dungeons; GetMapInfo() will not return correct information
819 -- unless the WorldMapFrame is shown.
820 do
821 -- MapFileName = MapAreaID
822 local MICRO_DUNGEON_IDS = {
823 ShrineofTwoMoons = 903,
824 ShrineofSevenStars = 905,
825 }
826
827 local function SetCurrentAreaID()
828 if private.in_combat then
829 private.set_area_id = true
830 return
831 end
832 local map_area_id = _G.GetCurrentMapAreaID()
833
834 if map_area_id == current_area_id then
835 return
836 end
837 local world_map = _G.WorldMapFrame
838 local map_visible = world_map:IsVisible()
839 local sfx_value = tonumber(_G.GetCVar("Sound_EnableSFX"))
840
841 if not map_visible then
842 _G.SetCVar("Sound_EnableSFX", 0)
843 world_map:Show()
844 end
845 local _, _, _, _, micro_dungeon_map_name = _G.GetMapInfo()
846 local micro_dungeon_id = MICRO_DUNGEON_IDS[micro_dungeon_map_name]
847
848 _G.SetMapToCurrentZone()
849
850 if micro_dungeon_id then
851 current_area_id = micro_dungeon_id
852 else
853 current_area_id = _G.GetCurrentMapAreaID()
854 end
855
856 if map_visible then
857 _G.SetMapByID(map_area_id)
858 else
859 world_map:Hide()
860 _G.SetCVar("Sound_EnableSFX", sfx_value)
861 end
862 end
863
864 function WDP:HandleZoneChange(event_name)
865 in_instance = _G.IsInInstance()
866 SetCurrentAreaID()
867 end
868 end
869
870
871 -- TIMERS ------------------------------------------------------------- 792 -- TIMERS -------------------------------------------------------------
872 793
873 function ClearKilledNPC() 794 function ClearKilledNPC()
874 killed_npc_id = nil 795 killed_npc_id = nil
875 end 796 end
1041 --local unknown_upgrade_related_id = tonumber(item_results[12]) 962 --local unknown_upgrade_related_id = tonumber(item_results[12])
1042 local instance_difficulty_id = tonumber(item_results[13]) or 0 963 local instance_difficulty_id = tonumber(item_results[13]) or 0
1043 local num_bonus_ids = tonumber(item_results[14]) or 0 964 local num_bonus_ids = tonumber(item_results[14]) or 0
1044 -- upgrade_id is optional since 6.2! can probably be detected using unknown_upgrade_related_id, but it's just as easy to check like this 965 -- upgrade_id is optional since 6.2! can probably be detected using unknown_upgrade_related_id, but it's just as easy to check like this
1045 local upgrade_id = tonumber(item_results[15 + num_bonus_ids]) or 0 966 local upgrade_id = tonumber(item_results[15 + num_bonus_ids]) or 0
1046 967
1047 -- LEGION 968 -- LEGION
1048 if private.isLegion then 969 if private.isLegion then
1049 local unkItemField1 = tonumber(item_results[16 + num_bonus_ids]) or 0 970 local unkItemField1 = tonumber(item_results[16 + num_bonus_ids]) or 0
1050 local unkItemField2 = tonumber(item_results[17 + num_bonus_ids]) or 0 971 local unkItemField2 = tonumber(item_results[17 + num_bonus_ids]) or 0
1051 if unkItemField1 > 0 then Debug("unkItemField1 is non-zero, specifically %d.", unkItemField1) end 972 if unkItemField1 > 0 then Debug("unkItemField1 is non-zero, specifically %d.", unkItemField1) end
1064 985
1065 -- Get ready for bonus IDs 986 -- Get ready for bonus IDs
1066 if not item.seen_bonuses then 987 if not item.seen_bonuses then
1067 item.seen_bonuses = {} 988 item.seen_bonuses = {}
1068 end 989 end
1069 990
1070 if num_bonus_ids > 0 then 991 if num_bonus_ids > 0 then
1071 -- We want the bonus ID combo output to be in the form ["bonusID1:bonusID2:bonusID3"] = true 992 -- We want the bonus ID combo output to be in the form ["bonusID1:bonusID2:bonusID3"] = true
1072 -- And sorted numerically with the smallest bonusID first 993 -- And sorted numerically with the smallest bonusID first
1073 local sorted_bonus_string = "" 994 local sorted_bonus_string = ""
1074 local min_bonus_id_array = {} 995 local min_bonus_id_array = {}
1374 Debug("%s: When handling the Garrison cache, the top level loot data was missing for objectID %d.", event_name, last_garrison_cache_object_id) 1295 Debug("%s: When handling the Garrison cache, the top level loot data was missing for objectID %d.", event_name, last_garrison_cache_object_id)
1375 end 1296 end
1376 else 1297 else
1377 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) 1298 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link)
1378 end 1299 end
1379 1300
1380 -- Wipe object ID until future mouseover 1301 -- Wipe object ID until future mouseover
1381 last_garrison_cache_object_id = nil 1302 last_garrison_cache_object_id = nil
1382 elseif raid_boss_id then 1303 elseif raid_boss_id then
1383 local npc = NPCEntry(raid_boss_id) 1304 local npc = NPCEntry(raid_boss_id)
1384 if npc then 1305 if npc then
1665 local RECIPE_MATCH = _G.ERR_LEARN_RECIPE_S:gsub("%%s", "(.*)") 1586 local RECIPE_MATCH = _G.ERR_LEARN_RECIPE_S:gsub("%%s", "(.*)")
1666 1587
1667 1588
1668 local function RecordDiscovery(tradeskill_name, tradeskill_index) 1589 local function RecordDiscovery(tradeskill_name, tradeskill_index)
1669 if tradeskill_name == private.discovered_recipe_name then 1590 if tradeskill_name == private.discovered_recipe_name then
1670 if (private.isLegion) then 1591 if (private.isLegion) then
1671 DBEntry("spells", tonumber(_G.C_TradeSkillUI.GetRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))).discovery = ("%d:%d"):format(private.previous_spell_id, private.profession_level) 1592 DBEntry("spells", tonumber(_G.C_TradeSkillUI.GetRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))).discovery = ("%d:%d"):format(private.previous_spell_id, private.profession_level)
1672 else 1593 else
1673 DBEntry("spells", tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))).discovery = ("%d:%d"):format(private.previous_spell_id, private.profession_level) 1594 DBEntry("spells", tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))).discovery = ("%d:%d"):format(private.previous_spell_id, private.profession_level)
1674 end 1595 end
1675 1596
1676 private.discovered_recipe_name = nil 1597 private.discovered_recipe_name = nil
1677 private.profession_level = nil 1598 private.profession_level = nil
1678 private.previous_spell_id = nil 1599 private.previous_spell_id = nil
1679 1600
1856 if NON_DAMAGE_EVENTS[sub_event] then 1777 if NON_DAMAGE_EVENTS[sub_event] then
1857 table.wipe(previous_combat_event) 1778 table.wipe(previous_combat_event)
1858 end 1779 end
1859 end 1780 end
1860 1781
1861 1782
1862 local DIPLOMACY_SPELL_ID = 20599 1783 local DIPLOMACY_SPELL_ID = 20599
1863 local MR_POP_RANK1_SPELL_ID = 78634 1784 local MR_POP_RANK1_SPELL_ID = 78634
1864 local MR_POP_RANK2_SPELL_ID = 78635 1785 local MR_POP_RANK2_SPELL_ID = 78635
1865 local TRADING_PACT_SPELL_ID = 170200 1786 local TRADING_PACT_SPELL_ID = 170200
1866 1787
1933 modifier = modifier + buff_data_table.modifier 1854 modifier = modifier + buff_data_table.modifier
1934 end 1855 end
1935 end 1856 end
1936 end 1857 end
1937 end 1858 end
1938 1859
1939 npc.reputations = npc.reputations or {} 1860 npc.reputations = npc.reputations or {}
1940 npc.reputations[("%s:%s"):format(faction_name, faction_standings[faction_name])] = math.floor(amount / modifier) 1861 npc.reputations[("%s:%s"):format(faction_name, faction_standings[faction_name])] = math.floor(amount / modifier)
1941 end 1862 end
1942 end -- do-block 1863 end -- do-block
1943 1864
2574 end 2495 end
2575 2496
2576 2497
2577 function WDP:QUEST_COMPLETE(event_name) 2498 function WDP:QUEST_COMPLETE(event_name)
2578 local quest = UpdateQuestJuncture("end") 2499 local quest = UpdateQuestJuncture("end")
2579 2500
2580 if not quest then 2501 if not quest then
2581 return 2502 return
2582 end 2503 end
2583 2504
2584 if ALLOWED_LOCALES[CLIENT_LOCALE] then 2505 if ALLOWED_LOCALES[CLIENT_LOCALE] then
2657 if (private.isLegion) then 2578 if (private.isLegion) then
2658 link = _G.C_TradeSkillUI.GetRecipeLink(tradeskill_index) 2579 link = _G.C_TradeSkillUI.GetRecipeLink(tradeskill_index)
2659 else 2580 else
2660 link = _G.GetTradeSkillRecipeLink(tradeskill_index) 2581 link = _G.GetTradeSkillRecipeLink(tradeskill_index)
2661 end 2582 end
2662 2583
2663 if link then 2584 if link then
2664 local spell_id = tonumber(link:match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)")) 2585 local spell_id = tonumber(link:match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))
2665 local required_tool 2586 local required_tool
2666 if (private.isLegion) then 2587 if (private.isLegion) then
2667 required_tool = _G.C_TradeSkillUI.GetRecipeTools(tradeskill_index) 2588 required_tool = _G.C_TradeSkillUI.GetRecipeTools(tradeskill_index)