changeset 129:d9a059484b22 v60

Several bug fixes for 8.0.
author yellowfive
date Wed, 18 Jul 2018 13:08:22 -0700
parents b16e1f4d100e
children 559f1d35bc72
files AskMrRobot-Serializer/AskMrRobot-Serializer.lua AskMrRobot.toc Constants.lua Core.lua Gear.lua
diffstat 5 files changed, 95 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/AskMrRobot-Serializer/AskMrRobot-Serializer.lua	Tue Jul 17 16:32:43 2018 -0700
+++ b/AskMrRobot-Serializer/AskMrRobot-Serializer.lua	Wed Jul 18 13:08:22 2018 -0700
@@ -1,6 +1,6 @@
 -- AskMrRobot-Serializer will serialize and communicate character data between users.
 
-local MAJOR, MINOR = "AskMrRobot-Serializer", 59
+local MAJOR, MINOR = "AskMrRobot-Serializer", 60
 local Amr, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
 
 if not Amr then return end -- already loaded by something else
@@ -228,20 +228,24 @@
 				item.relicBonusIds[1] = readBonusIdList(parts, 17 + offset, 16 + offset + numBonuses)
 			end
 					
-			offset= offset + numBonuses
+			offset = offset + numBonuses
 			if #parts > 17 + offset then
 				numBonuses = tonumber(parts[17 + offset])
-				if numBonuses > 0 then
-					item.relicBonusIds[2] = readBonusIdList(parts, 18 + offset, 17 + offset + numBonuses)
+				if numBonuses then
+					if numBonuses > 0 then
+						item.relicBonusIds[2] = readBonusIdList(parts, 18 + offset, 17 + offset + numBonuses)
+					end
+
+					offset= offset + numBonuses
+					if #parts > 18 + offset then
+						numBonuses = tonumber(parts[18 + offset])
+						if numBonuses then
+							if numBonuses > 0 then
+								item.relicBonusIds[3] = readBonusIdList(parts, 19 + offset, 18 + offset + numBonuses)
+							end	
+						end
+					end
 				end
-
-				offset= offset + numBonuses
-				if #parts > 18 + offset then
-					numBonuses = tonumber(parts[18 + offset])
-					if numBonuses > 0 then
-						item.relicBonusIds[3] = readBonusIdList(parts, 19 + offset, 18 + offset + numBonuses)
-					end	
-				end		
 			end
 		end
 	end
--- a/AskMrRobot.toc	Tue Jul 17 16:32:43 2018 -0700
+++ b/AskMrRobot.toc	Wed Jul 18 13:08:22 2018 -0700
@@ -1,7 +1,7 @@
 ## Interface: 80000
 ## Title: Ask Mr. Robot
 ## Author: Team Robot, Inc.
-## Version: 59
+## Version: 60
 ## Notes: Gear import/export, combat logging, and more.
 ## URL: www.askmrrobot.com
 ## SavedVariables: AskMrRobotDb4
--- a/Constants.lua	Tue Jul 17 16:32:43 2018 -0700
+++ b/Constants.lua	Wed Jul 18 13:08:22 2018 -0700
@@ -24,6 +24,7 @@
 Amr.GetItemTooltip = Amr.Serializer.GetItemTooltip
 Amr.GetItemLevel = Amr.Serializer.GetItemLevel
 Amr.GetItemUniqueId = Amr.Serializer.GetItemUniqueId
+Amr.ReadAzeritePowers = Amr.Serializer.ReadAzeritePowers
 
 -- map of slot ID to display text
 Amr.SlotDisplayText = {
--- a/Core.lua	Tue Jul 17 16:32:43 2018 -0700
+++ b/Core.lua	Wed Jul 18 13:08:22 2018 -0700
@@ -4,8 +4,6 @@
 
 Amr.ADDON_NAME = "AskMrRobot"
 
-local VAR_VERSION = 1
-
 -- types of inter-addon messages that we receive, used to parcel them out to the proper handlers
 Amr.MessageTypes = {
 	Version = "_V",
@@ -43,26 +41,24 @@
 -- initialize the database
 local function initializeDb()
 
-	local charDefaults = {			
-		FirstUse = true,           -- true if this is first time use, gets cleared after seeing the export help splash window
-		Talents = {},              -- for each spec, selected talents
-		Equipped = {},             -- for each spec, slot id to item info
-		BagItems = {},             -- list of item info for bags
-		BankItems = {},            -- list of item info for bank
-		BagItemsAndCounts = {},    -- used mainly for the shopping list
-		BankItemsAndCounts = {},   -- used mainly for the shopping list			
-		GearSets = {},             -- imported gear sets
-		ExtraEnchantData = {},     -- enchant id to enchant display information and material information
-		Logging = {                -- character logging settings
-			Enabled = false,       -- whether logging is currently on or not
-			LastZone = nil,        -- last zone the player was in
-			LastDiff = nil,        -- last difficulty for the last zone the player was in
-			LastWipe = nil         -- last time a wipe was called by this player
-		}
-	}
-
 	local defaults = {
-		char = charDefaults,
+		char = {			
+			FirstUse = true,           -- true if this is first time use, gets cleared after seeing the export help splash window
+			Talents = {},              -- for each spec, selected talents
+			Equipped = {},             -- for each spec, slot id to item info
+			BagItems = {},             -- list of item info for bags
+			BankItems = {},            -- list of item info for bank
+			BagItemsAndCounts = {},    -- used mainly for the shopping list
+			BankItemsAndCounts = {},   -- used mainly for the shopping list			
+			GearSets = {},             -- imported gear sets
+			ExtraEnchantData = {},     -- enchant id to enchant display information and material information
+			Logging = {                -- character logging settings
+				Enabled = false,       -- whether logging is currently on or not
+				LastZone = nil,        -- last zone the player was in
+				LastDiff = nil,        -- last difficulty for the last zone the player was in
+				LastWipe = nil         -- last time a wipe was called by this player
+			}
+		},
 		profile = {
 			minimap = {                -- minimap hide/show and position settings
 				hide = false
@@ -92,11 +88,6 @@
 	
 	Amr.db = LibStub("AceDB-3.0"):New("AskMrRobotDb4", defaults)
 	
-	-- make sure character data is on current version
-	if not Amr.db.char.VarVersion or Amr.db.char.VarVersion ~= VAR_VERSION then
-		Amr.db.char = charDefaults
-	end
-
 	-- set defaults for auto logging; if a new zone is added and some other stuff was turned on, turn on the new zone too
 	local hasSomeLogging = false
 	local addedLogging = {}
--- a/Gear.lua	Tue Jul 17 16:32:43 2018 -0700
+++ b/Gear.lua	Wed Jul 18 13:08:22 2018 -0700
@@ -84,7 +84,7 @@
 	if not list then return nil end
 	
 	local found = false
-	for k,listItem in pairs(list) do
+	for k,listItem in pairs(list) do		
 		if listItem then
 			local diff = countItemDifferences(item, listItem)
 			if diff < bestDiff then
@@ -112,9 +112,7 @@
 	local bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, equipped, nil, 10000, nil, usedItems, "equip")
 	bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, player.BagItems, bestItem, bestDiff, bestLoc, usedItems, "bag")
 	if player.BankItems then
-		for bagId,bagList in pairs(player.BankItems) do
-			bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, bagList, bestItem, bestDiff, bestLoc, usedItems, "bank" .. bagId)
-		end
+		bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, player.BankItems, bestItem, bestDiff, bestLoc, usedItems, "bank")		
 	end	
 
 	if bestDiff >= 10000 then
@@ -592,6 +590,8 @@
 		bestItem, bestDiff, bestLink = scanBagForItem(item, bagId, bestItem, bestDiff, bestLink)
 	end
 
+	-- with new approach, the item to use should never be equipped, should be in bags at this point
+	--[[
 	-- equipped items, but skip slots we have just equipped (to avoid e.g. just moving 2 of the same item back and forth between mh oh weapon slots)
 	for slotNum = 1, #Amr.SlotIds do
 		local slotId = Amr.SlotIds[slotNum]
@@ -610,7 +610,8 @@
 			end
 		end
 	end
-	
+	]]
+
 	-- bank
 	if bestDiff > 0 then
 		bestItem, bestDiff, bestLink = scanBagForItem(item, BANK_CONTAINER, bestItem, bestDiff, bestLink)
@@ -754,6 +755,8 @@
 
 		else
 
+			--print("equipping " .. bestLink .. " in slot " .. _currentGearOp.nextSlot)
+
 			-- an item in the player's bags or already equipped, equip it
 			if bestItem.bag then
 				PickupContainerItem(bestItem.bag, bestItem.slot)
@@ -897,6 +900,12 @@
 	return tbl
 end
 
+local _ohFirst = {
+    [20] = true, -- PaladinProtection
+    [32] = true, -- WarlockDemonology
+    [36] = true -- WarriorProtection
+}
+
 function beginEquipGearSet(spec, passes)
 
 	local gear = Amr.db.char.GearSets[spec]
@@ -907,17 +916,20 @@
 
 	-- ensure all our stored data is up to date
 	local player = Amr:ExportCharacter()
+	local doOhFirst = _ohFirst[player.Specs[spec]]
 
 	local itemsToEquip = {
 		legendaries = {},
 		weapons = {},
+		mh = {},
+		oh = {},
 		rings = {},
 		trinkets = {},
 		others = {},
 		blanks = {}
 	}
 	local remaining = 0
-	local usedItems = {}	
+	local usedItems = {}
 
 	-- check for items that need to be equipped, do in a random order to try and defeat any unique constraint issues we might hit
 	local slots = {}
@@ -930,8 +942,10 @@
 
 		-- we do stuff in batches that avoids most unique conflicts
 		local list = itemsToEquip.others
-		if slotId == 16 or slotId == 17 then
-			list = itemsToEquip.weapons
+		if slotId == 16 then
+			list = itemsToEquip.mh
+		elseif slotId == 17 then
+			list = itemsToEquip.oh
 		elseif slotId == 11 or slotId == 12 then
 			list = itemsToEquip.rings
 		elseif slotId == 13 or slotId == 14 then
@@ -948,10 +962,19 @@
 			if quality == 6 then
 				if not old or new.id ~= old.id then
 					list[slotId] = new
+					if list == itemsToEquip.mh or list == itemsToEquip.oh then
+						itemsToEquip.weapons[slotId] = {}
+					end
 					remaining = remaining + 1
 				end
-			else				
+			else
+				-- find the best matching item anywhere in the player's gear
+				local bestItem, bestDiff = Amr:FindMatchingItem(new, player, usedItems)
+				new = bestItem
+
 				local diff = countItemDifferences(old, new)
+
+				--[[
 				if diff > 0 and diff < 1000 then
 					-- same item, see if inventory has one that is closer (e.g. a duplicate item with correct enchants/gems)
 					local bestItem, bestDiff = Amr:FindMatchingItem(new, player, usedItems)
@@ -960,13 +983,17 @@
 						diff = bestDiff
 					end
 				end
+				]]
 
-				if diff > 0 then
+				if diff > 0 then	
 					list[slotId] = new
+					if list == itemsToEquip.mh or list == itemsToEquip.oh then
+						itemsToEquip.weapons[slotId] = {}
+					end
 					remaining = remaining + 1
 				end
 			end
-		else
+		elseif old then
 			-- need to remove this item
 			itemsToEquip.blanks[slotId] = {}
 			remaining = remaining + 1
@@ -988,14 +1015,21 @@
 		if passes < 5 then
 			_pendingGearOps = {}
 
-			if not Amr.IsEmpty(itemsToEquip.blanks) then
+			if not Amr.IsEmpty(itemsToEquip.blanks) then				
 				-- if gear set wants slots to be blank, do that first
 				table.insert(_pendingGearOps, { items = itemsToEquip.blanks, remove = true, label = "blanks" }) 
-			end
+			end			
 			if not Amr.IsEmpty(itemsToEquip.weapons) then
-				-- change weapons first: remove both, wait, then equip new ones
-				table.insert(_pendingGearOps, { items = itemsToEquip.weapons, remove = true, label = "remove weapons" })				
-				table.insert(_pendingGearOps, { items = itemsToEquip.weapons, wait = true, label = "equip weapons" })
+				-- change weapons first: remove both, wait, then equip each weapon one by one, waiting after each
+				table.insert(_pendingGearOps, { items = itemsToEquip.weapons, remove = true, label = "remove weapons" })
+				local thisWeapon = doOhFirst and itemsToEquip.oh or itemsToEquip.mh
+				if not Amr.IsEmpty(thisWeapon) then
+					table.insert(_pendingGearOps, { items = thisWeapon, wait = true, label = "equip weapon 1" })
+				end
+				thisWeapon = doOhFirst and itemsToEquip.mh or itemsToEquip.oh
+				if not Amr.IsEmpty(thisWeapon) then
+					table.insert(_pendingGearOps, { items = thisWeapon, wait = true, label = "equip weapon 2" })
+				end
 			end
 			if not Amr.IsEmpty(itemsToEquip.legendaries) then 
 				-- remove any legendaries, wait
@@ -1041,13 +1075,15 @@
 
 	local auto = Amr.db.profile.options.autoGear
 	local currentSpec = GetSpecialization()
+	local waitingSpec = _waitingForSpec
+	_waitingForSpec = 0
 	
-	if currentSpec == _waitingForSpec or auto then
-		-- spec is what we want, now equip the gear
-		beginEquipGearSet(currentSpec, 0)
+	if currentSpec == waitingSpec or auto then
+		-- spec is what we want, now equip the gear but after a short delay because the game auto-swaps artifact weapons
+		Amr.Wait(2, function()
+			beginEquipGearSet(GetSpecialization(), 0)
+		end)
 	end
-	
-	_waitingForSpec = 0
 end
 
 -- activate the specified spec and then equip the saved gear set
@@ -1069,13 +1105,13 @@
 		return
 	end
 	
-	_waitingForSpec = spec
-	
 	local currentSpec = GetSpecialization()
 	if currentSpec ~= spec then
+		_waitingForSpec = spec
 		SetSpecialization(spec)
 	else
-		onActiveTalentGroupChanged()
+		-- spec is what we want, now equip the gear
+		beginEquipGearSet(currentSpec, 0)
 	end
 end