Quantcast

automatically use keystone when opening the keystone window

Ironi [12-04-16 - 00:01]
automatically use keystone when opening the keystone window
Filename
iKeystones.lua
diff --git a/iKeystones.lua b/iKeystones.lua
index 145689e..ac61e1d 100644
--- a/iKeystones.lua
+++ b/iKeystones.lua
@@ -6,6 +6,7 @@ addon:RegisterEvent('ADDON_LOADED')
 addon:RegisterEvent('CHALLENGE_MODE_MAPS_UPDATE')
 addon:RegisterEvent('PLAYER_LOGIN')
 addon:RegisterEvent('BAG_UPDATE')
+addon:RegisterEvent('CHALLENGE_MODE_KEYSTONE_RECEPTABLE_OPEN')
 local iKS = {}
 local player = UnitGUID('player')

@@ -51,12 +52,15 @@ function iKS:scanCharacterMaps()
 	end
 	iKeystonesDB[player].maxCompleted = maxCompleted
 end
-function iKS:scanInventory()
+function iKS:scanInventory(requestingSlots)
 	if not iKS:createPlayer() then return end
 	for bagID = 0, 4 do
 		for invID = 1, GetContainerNumSlots(bagID) do
 			local itemID = GetContainerItemID(bagID, invID)
 			if itemID and itemID == 138019 then
+				if requestingSlots then
+					return bagID, invID
+				end
 				local itemLink = GetContainerItemLink(bagID, invID)
 				local tempTable = {strsplit(':', itemLink)}
 				-- debug
@@ -98,6 +102,7 @@ function iKS:scanInventory()
 					print('iKS: New keystone - ' .. itemLinkToPrint)
 				end
 				iKS.keyLevel = keyLevel
+				iKS.mapID = iKeystonesDB[player].key.map
 				return
 			end
 		end
@@ -173,6 +178,18 @@ end
 function addon:CHALLENGE_MODE_MAPS_UPDATE()
 	iKS:scanCharacterMaps()
 end
+function addon:CHALLENGE_MODE_KEYSTONE_RECEPTABLE_OPEN()
+	local _, _, _, _, _, _, _, mapID = GetInstanceInfo()
+	if iKS.mapID and iKS.mapID == mapID then
+		local bagID, slotID = iKS:scanInventory(true)
+		PickupContainerItem(bagID, slotID)
+		C_Timer.After(0.1, function()
+			if CursorHasItem() then
+				C_ChallengeMode.SlotKeystone()
+			end
+		end)
+	end
+end

 local function chatFiltering(self, event, msg, ...)
 	local linkStart = msg:find('Hitem:138019')