comparison Core.lua @ 124:e31b02b24488

Updated for 8.0 pre-patch and BfA.
author yellowfive
date Tue, 17 Jul 2018 09:57:39 -0700
parents f1da233629be
children 65c285394049
comparison
equal deleted inserted replaced
123:7a6364917f86 124:e31b02b24488
1 -- AskMrRobot
2 -- Does cool stuff associated with askmrrobot.com:
3 -- Import/Export gear and optimization solutions from/to the website
4 -- Improve the combat logging experience and augment it with extra data not available directly in the log file
5 -- Team Optimizer convenience functionality
6
7 AskMrRobot = LibStub("AceAddon-3.0"):NewAddon("AskMrRobot", "AceEvent-3.0", "AceComm-3.0", "AceConsole-3.0", "AceSerializer-3.0") 1 AskMrRobot = LibStub("AceAddon-3.0"):NewAddon("AskMrRobot", "AceEvent-3.0", "AceComm-3.0", "AceConsole-3.0", "AceSerializer-3.0")
8 local Amr = AskMrRobot 2 local Amr = AskMrRobot
9 Amr.Serializer = LibStub("AskMrRobot-Serializer") 3 Amr.Serializer = LibStub("AskMrRobot-Serializer")
10 4
11 Amr.ADDON_NAME = "AskMrRobot" 5 Amr.ADDON_NAME = "AskMrRobot"
12 6
13 -- types of inter-addon messages that we receive, used to parcel them out to the proper handlers 7 -- types of inter-addon messages that we receive, used to parcel them out to the proper handlers
14 Amr.MessageTypes = { 8 Amr.MessageTypes = {
15 Version = "_V", 9 Version = "_V",
16 VersionRequest = "_VR", 10 VersionRequest = "_VR"
17 Team = "_T"
18 } 11 }
19 12
20 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true) 13 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true)
21 local AceGUI = LibStub("AceGUI-3.0") 14 local AceGUI = LibStub("AceGUI-3.0")
22 15
25 type = "launcher", 18 type = "launcher",
26 text = "Ask Mr. Robot", 19 text = "Ask Mr. Robot",
27 icon = "Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\icon", 20 icon = "Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\icon",
28 OnClick = function(self, button, down) 21 OnClick = function(self, button, down)
29 if button == "LeftButton" then 22 if button == "LeftButton" then
30 if IsControlKeyDown() then 23 --if IsControlKeyDown() then
31 Amr:Wipe() 24 -- Amr:Wipe()
32 else 25 --else
33 Amr:Toggle() 26 Amr:Toggle()
34 end 27 --end
35 elseif button == "RightButton" then 28 elseif button == "RightButton" then
36 Amr:EquipGearSet() 29 Amr:EquipGearSet()
37 end 30 end
38 end, 31 end,
39 OnTooltipShow = function(tt) 32 OnTooltipShow = function(tt)
50 43
51 local defaults = { 44 local defaults = {
52 char = { 45 char = {
53 FirstUse = true, -- true if this is first time use, gets cleared after seeing the export help splash window 46 FirstUse = true, -- true if this is first time use, gets cleared after seeing the export help splash window
54 Talents = {}, -- for each spec, selected talents 47 Talents = {}, -- for each spec, selected talents
55 Artifacts = {}, -- for each spec, artifact info 48 Equipped = {}, -- for each spec, slot id to item info
56 Equipped = {}, -- for each spec, slot id to item link 49 BagItems = {}, -- list of item info for bags
57 BagItems = {}, -- list of item links for bag 50 BankItems = {}, -- list of item info for bank
58 BankItems = {}, -- list of item links for bank
59 VoidItems = {}, -- list of item links for void storage
60 BagItemsAndCounts = {}, -- used mainly for the shopping list 51 BagItemsAndCounts = {}, -- used mainly for the shopping list
61 BankItemsAndCounts = {}, -- used mainly for the shopping list 52 BankItemsAndCounts = {}, -- used mainly for the shopping list
62 GearSets = {}, -- imported gear sets, key by spec group (1 or 2), slot id to item object 53 GearSets = {}, -- imported gear sets
63 ExtraItemData = {}, -- for each spec group (1 or 2): mainly for legacy support, item id to object with socketColor and duplicateId information 54 ExtraEnchantData = {}, -- enchant id to enchant display information and material information
64 ExtraGemData = {}, -- for each spec group (1 or 2): gem enchant id to gem display information, and data used to detect identical gems (mainly for legacy support)
65 ExtraEnchantData = {}, -- for each spec group (1 or 2): enchant id to enchant display information and material information
66 Logging = { -- character logging settings 55 Logging = { -- character logging settings
67 Enabled = false, -- whether logging is currently on or not 56 Enabled = false, -- whether logging is currently on or not
68 LastZone = nil, -- last zone the player was in 57 LastZone = nil, -- last zone the player was in
69 LastDiff = nil, -- last difficulty for the last zone the player was in 58 LastDiff = nil, -- last difficulty for the last zone the player was in
70 LastWipe = nil -- last time a wipe was called by this player 59 LastWipe = nil -- last time a wipe was called by this player
71 },
72 TeamOpt = {
73 AllItems = {}, -- all equippable items no matter where it is, list of item unique ids, used to determine when a player gains a new equippable item
74 History = {}, -- history of drops since joining the current group
75 Rolls = {}, -- current loot choices for a loot distribution in progress
76 Role = nil, -- Leader or Member, changes UI to the mode most appropriate for this user
77 Loot = {}, -- the last loot seen by the master looter
78 LootGuid = nil, -- guid of the last unit looted by the master looter, will be "container" if there is no target
79 LootInProgress = false -- true if looting is currently in progress
80 } 60 }
81 }, 61 },
82 profile = { 62 profile = {
83 minimap = { -- minimap hide/show and position settings 63 minimap = { -- minimap hide/show and position settings
84 hide = false 64 hide = false
85 }, 65 },
86 window = {}, -- main window position settings 66 window = {}, -- main window position settings
87 lootWindow = {}, -- loot window position settings
88 shopWindow = {}, -- shopping list window position settings 67 shopWindow = {}, -- shopping list window position settings
89 options = { 68 options = {
90 autoGear = false, -- auto-equip saved gear sets when changing specs 69 autoGear = false, -- auto-equip saved gear sets when changing specs
91 shopAh = false, -- auto-show shopping list at AH 70 shopAh = false, -- auto-show shopping list at AH
92 disableEm = false, -- disable auto-creation of equipment manager sets 71 disableEm = false, -- disable auto-creation of equipment manager sets
101 Shopping = {}, -- shopping list data stored globally for access on any character 80 Shopping = {}, -- shopping list data stored globally for access on any character
102 Logging = { -- a lot of log data is stored globally for simplicity, can only be raiding with one character at a time 81 Logging = { -- a lot of log data is stored globally for simplicity, can only be raiding with one character at a time
103 Wipes = {}, -- times that a wipe was called 82 Wipes = {}, -- times that a wipe was called
104 PlayerData = {}, -- player data gathered at fight start 83 PlayerData = {}, -- player data gathered at fight start
105 PlayerExtras = {} -- player extra data like auras, gathered at fight start 84 PlayerExtras = {} -- player extra data like auras, gathered at fight start
106 },
107 TeamOpt = { -- this stuff is stored globally in case a player e.g. switches to an alt in a raid group
108 LootGear = {}, -- gear info that needs to be transmitted with the next loot
109 Rankings = {}, -- last rankings imported by the loot ranker
110 RankingString = nil -- last ranking string imported, kept around for efficient serialization
111 } 85 }
112 } 86 }
113 } 87 }
114 88
115 Amr.db = LibStub("AceDB-3.0"):New("AskMrRobotDb3", defaults) 89 Amr.db = LibStub("AceDB-3.0"):New("AskMrRobotDb4", defaults)
116 90
117 -- set defaults for auto logging; if a new zone is added and some other stuff was turned on, turn on the new zone too 91 -- set defaults for auto logging; if a new zone is added and some other stuff was turned on, turn on the new zone too
118 local hasSomeLogging = false 92 local hasSomeLogging = false
119 local addedLogging = {} 93 local addedLogging = {}
120 for i, instanceId in ipairs(Amr.InstanceIdsOrdered) do 94 for i, instanceId in ipairs(Amr.InstanceIdsOrdered) do
173 Amr.Wait(5, function() 147 Amr.Wait(5, function()
174 Amr:InitializeVersions() 148 Amr:InitializeVersions()
175 Amr:InitializeGear() 149 Amr:InitializeGear()
176 Amr:InitializeExport() 150 Amr:InitializeExport()
177 Amr:InitializeCombatLog() 151 Amr:InitializeCombatLog()
178 Amr:InitializeTeamOpt()
179 end) 152 end)
180 end 153 end
181 154
182 function onPlayerEnteringWorld() 155 function onPlayerEnteringWorld()
183 156
224 ---------------------------------------------------------------------------------------- 197 ----------------------------------------------------------------------------------------
225 local _slashMethods = { 198 local _slashMethods = {
226 hide = "Hide", 199 hide = "Hide",
227 show = "Show", 200 show = "Show",
228 toggle = "Toggle", 201 toggle = "Toggle",
229 equip = "EquipGearSet", -- parameter is "primary" or "secondary", or no parameter to toggle 202 equip = "EquipGearSet",
230 version = "PrintVersions", 203 version = "PrintVersions",
231 wipe = "Wipe", 204 --wipe = "Wipe",
232 undowipe = "UndoWipe", 205 --undowipe = "UndoWipe",
233 reset = "Reset", 206 reset = "Reset",
234 test = "Test" 207 test = "Test"
235 } 208 }
236 209
237 function Amr:SlashCommand(input) 210 function Amr:SlashCommand(input)
447 function Amr.StartsWith(str, prefix) 420 function Amr.StartsWith(str, prefix)
448 if string.len(str) < string.len(prefix) then return false end 421 if string.len(str) < string.len(prefix) then return false end
449 return string.sub(str, 1, string.len(prefix)) == prefix 422 return string.sub(str, 1, string.len(prefix)) == prefix
450 end 423 end
451 424
425 function Amr.IsEmpty(table)
426 return next(table) == nil
427 end
428
429 function Amr.Contains(table, value)
430 if not table then return false end
431 for k,v in pairs(table) do
432 if v == value then
433 return true
434 end
435 end
436 return false
437 end
438
452 -- helper to get the unit identifiers (e.g. to pass to GetUnitName) for all members of the player's current group/raid 439 -- helper to get the unit identifiers (e.g. to pass to GetUnitName) for all members of the player's current group/raid
453 function Amr:GetGroupUnitIdentifiers() 440 function Amr:GetGroupUnitIdentifiers()
454 441
455 local units = {} 442 local units = {}
456 if IsInRaid() then 443 if IsInRaid() then
525 end 512 end
526 end 513 end
527 return false 514 return false
528 end 515 end
529 516
530 -- helper to determine if we can equip an item (it is already soulbound or account bound) 517 -- helper to determine if we can equip an item (it is soulbound)
531 function Amr:CanEquip(bagId, slotId) 518 function Amr:CanEquip(bagId, slotId)
532 local tt = Amr.GetItemTooltip(bagId, slotId) 519 local item = Item:CreateFromBagAndSlot(bagId, slotId)
533 if self:IsTextInTooltip(tt, ITEM_SOULBOUND) then return true end 520 if item then
534 if self:IsTextInTooltip(tt, ITEM_BNETACCOUNTBOUND) then return true end 521 local loc = item:GetItemLocation()
535 if self:IsTextInTooltip(tt, ITEM_ACCOUNTBOUND) then return true end 522 return C_Item.IsBound(loc)
523 else
524 -- for now just return true if we can't find the item... will get an error trying to equip if it isn't bound
525 return true
526 end
527
528 --local tt = Amr.GetItemTooltip(bagId, slotId)
529 --if self:IsTextInTooltip(tt, ITEM_SOULBOUND) then return true end
530 --if self:IsTextInTooltip(tt, ITEM_BNETACCOUNTBOUND) then return true end
531 --if self:IsTextInTooltip(tt, ITEM_ACCOUNTBOUND) then return true end
536 end 532 end
537 533
538 -- helper to determine if an item has a unique constraint 534 -- helper to determine if an item has a unique constraint
539 function Amr:IsUnique(bagId, slotId) 535 function Amr:IsUnique(bagId, slotId)
540 local tt = Amr.GetItemTooltip(bagId, slotId) 536 local tt = Amr.GetItemTooltip(bagId, slotId)
582 end 578 end
583 579
584 -- any other kind of message is ignored if the version is too old 580 -- any other kind of message is ignored if the version is too old
585 if not ver or ver < Amr.MIN_ADDON_VERSION then return end 581 if not ver or ver < Amr.MIN_ADDON_VERSION then return end
586 582
583 --[[
587 if Amr.StartsWith(message, Amr.MessageTypes.Team) then 584 if Amr.StartsWith(message, Amr.MessageTypes.Team) then
588 -- if fully initialized, process team optimizer messages 585 -- if fully initialized, process team optimizer messages
589 if Amr["ProcessTeamMessage"] then 586 if Amr["ProcessTeamMessage"] then
590 Amr:ProcessTeamMessage(message) 587 Amr:ProcessTeamMessage(message)
591 end 588 end
593 -- if we are fully loaded, process a player snapshot when it is received (combat logging) 590 -- if we are fully loaded, process a player snapshot when it is received (combat logging)
594 if Amr["ProcessPlayerSnapshot"] then 591 if Amr["ProcessPlayerSnapshot"] then
595 self:ProcessPlayerSnapshot(message) 592 self:ProcessPlayerSnapshot(message)
596 end 593 end
597 end 594 end
595 ]]
598 end 596 end
599 597
600 598
601 ---------------------------------------------------------------------------------------- 599 ----------------------------------------------------------------------------------------
602 -- Events 600 -- Events
633 631
634 632
635 ---------------------------------------------------------------------------------------- 633 ----------------------------------------------------------------------------------------
636 -- Debugging 634 -- Debugging
637 ---------------------------------------------------------------------------------------- 635 ----------------------------------------------------------------------------------------
636 function Amr:dump(o)
637 if type(o) == 'table' then
638 local s = '{ '
639 for k,v in pairs(o) do
640 if type(k) ~= 'number' then k = '"'..k..'"' end
641 s = s .. '['..k..'] = ' .. Amr:dump(v) .. ','
642 end
643 return s .. '} '
644 else
645 return tostring(o)
646 end
647 end
648
638 function Amr:Test() 649 function Amr:Test()
639 650
651 --local itemLink = GetInventoryItemLink("player", 17)
652
653 --print(itemLink)
654
655 --local blah = Amr.ParseItemLink(itemLink)
656
657 --print(dump(blah.relicBonusIds))
658
659 --[[
660 --print(NUM_BANKBAGSLOTS)
661
662 local bagId = NUM_BAG_SLOTS + 1
663
664 local item = Item:CreateFromBagAndSlot(bagId, 2)
665 if item then
666 print(item:GetItemName())
667 else
668 print("no item")
669 end
670
671 local numSlots = GetContainerNumSlots(bagId)
672 print(numSlots .. " bag slots")
673 ]]
674
675 -- EquipItemByName
676
677 --[[
678 for slotId = 1, numSlots do
679 local _, itemCount, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId)
680 if itemLink ~= nil then
681 print(slotId .. " " .. itemLink)
682 end
683 end
684 ]]
685
686 --[[
640 local s = "|cff0070dd|Hitem:127224:5337:0:0:0:0:0:0:100:105:512:22:2:615:656:100|h[Staff of Polarities]|h|r" 687 local s = "|cff0070dd|Hitem:127224:5337:0:0:0:0:0:0:100:105:512:22:2:615:656:100|h[Staff of Polarities]|h|r"
641 Amr.GetItemInfo(s, function(obj, name, link, quality, iLevel) 688 Amr.GetItemInfo(s, function(obj, name, link, quality, iLevel)
642 print(iLevel) 689 print(iLevel)
643 end) 690 end)
644 end 691 ]]
645 692 end
646 --[[
647 function Amr:Test(val1, val2, val3)
648
649 local link = GetLootSlotLink(tonumber(val1))
650 local index = Amr:TestLootIndex(link)
651 print("loot index: " .. index)
652
653 if val2 then
654 local candidate = Amr:TestLootCandidate(link, val2, val3)
655 print("loot candidate: " .. candidate)
656
657 GiveMasterLoot(index, candidate)
658 end
659 end
660 ]]