view ProspectMe.lua @ 0:69b46322ff1b v1.2.1-Alpha

Updated Prospect me for initial client v6.0.3 support. Warning, there may be bugs!
author Vynn
date Mon, 15 Dec 2014 22:51:49 -0500
parents
children 61b9ea84a44c
line wrap: on
line source
local PROSPECT_ID = 31252
local MILLING_ID = 51005
local PROSPECT = GetSpellInfo(PROSPECT_ID)
local MILLING = GetSpellInfo(MILLING_ID)
local containerID, containerLink = nil, nil
local getContents = false

local function PM_Init()
	if not PM_ResultsTable then
		PM_ResultsTable = {}
		PM_ItemTable = {}
	end
	PM_SessionTable = {}
end

local function CreateTableEntry(id)
	local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(id)
	PM_ItemTable[id] = {}
	PM_ItemTable[id].name = name 
	PM_ItemTable[id].link = link
	PM_ItemTable[id].quality = quality
	PM_ItemTable[id].iLevel = iLevel
	PM_ItemTable[id].reqLevel = reqLevel
	PM_ItemTable[id].class = class
	PM_ItemTable[id].subclass = subclass
	PM_ItemTable[id].maxStack = maxStack
	PM_ItemTable[id].equipSlot = equipSlot
	PM_ItemTable[id].texture = texture
	PM_ItemTable[id].vendorPrice = vendorPrice
	PM_ItemTable[id].price = PM_GetItemValue(id)
end

--debugging function to print the databases results
function PM_PrintResults()
	for container, k in pairs(PM_ResultsTable) do
		print(PM_ItemTable[container].link, PM_ResultsTable[container].timesProspected)
		for i, num in pairs(k) do 
			if i ~= "timesProspected" then
				print(PM_ItemTable[i].link, num)
			end
		end
	end
end

local function GetResults()
	--Create tables for the Container if it doesn't exist yet
	if not PM_ResultsTable[containerID] then
		PM_ResultsTable[containerID] = {timesProspected = 0}
		CreateTableEntry(containerID)
	end
	
	--Creates a session table entry, this will be cleared on log out/UI reload
	if not PM_SessionTable[containerID] then
		PM_SessionTable[containerID] = {timesProspected = 0}
	end
	
	for i = 1, GetNumLootItems() do
		local itemID = GetLootSlotLink(i):match("Hitem:(%d+)")
		local quantity = select(3, GetLootSlotInfo(i))
		if not PM_ItemTable[itemID]	then
			CreateTableEntry(itemID)
		end
		if PM_ResultsTable[containerID][itemID] then
			PM_ResultsTable[containerID][itemID] = PM_ResultsTable[containerID][itemID] + quantity
		else
			PM_ResultsTable[containerID][itemID] = quantity
		end
		if PM_SessionTable[containerID][itemID] then
			PM_SessionTable[containerID][itemID] = PM_SessionTable[containerID][itemID] + quantity
		else
			PM_SessionTable[containerID][itemID] = quantity
		end
	end
	
	PM_ResultsTable[containerID].timesProspected = PM_ResultsTable[containerID].timesProspected + 1
	PM_SessionTable[containerID].timesProspected = PM_SessionTable[containerID].timesProspected + 1
end

local function EventHandler(self, event, ...)
	if event == "VARIABLES_LOADED" then
		PM_Init()
		PM_UpdateValues()
	end
	if event == "UNIT_SPELLCAST_INTERRUPTED" then
		local unitID, spell, rank = ...
		if unitID == "player" and spell == PROSPECT then
			getContents = false
		end
	end
	if event == "LOOT_OPENED" then
		if getContents then
			GetResults()
		end
	end
	if event == "LOOT_CLOSED" then
		getContents = false
	end
	if event == "AUCTION_ITEM_LIST_UPDATE" then
		PM_UpdateValues()
	end
end

local frame = CreateFrame("FRAME", "PM_Frame")
frame:RegisterEvent("VARIABLES_LOADED")
frame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
frame:RegisterEvent("LOOT_OPENED")
frame:RegisterEvent("LOOT_CLOSED")
frame:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
frame:SetScript("OnEvent", EventHandler)

hooksecurefunc("UseContainerItem", function(...)
	if getContents then
		containerLink = GetContainerItemLink(...)
		containerID = containerLink:match("Hitem:(%d+)")
	end

end)

hooksecurefunc("UseItemByName", function(itemName)
	if getContents then
		containerLink = select(2, GetItemInfo(itemName))
		containerID = containerLink:match("Hitem:(%d+)")
	end
end)

hooksecurefunc("SpellTargetItem", function(itemName) 
	if getContents then 
		containerLink = select(2, GetItemInfo(itemName)) 
		containerID = containerLink:match("Hitem:(%d+)") 
	end 
end)

hooksecurefunc("CastSpell", function(...)
	local spellName = GetSpellInfo(...)
	if spellName:lower() == PROSPECT:lower() or spellName:lower() == MILLING:lower() then
		getContents = true
	end
end)

hooksecurefunc("CastSpellByID", function(spellID)
	if spellID == PROSPECT_ID or spellID == MILLING_ID then
		getContents = true
	end
end)

hooksecurefunc("UseAction", function(actionID)
	local spellID = select(2, GetActionInfo(actionID))
	if spellID == PROSPECT_ID or spellID == MILLING_ID then
		getContents = true
	end
end)

hooksecurefunc("CastSpellByName", function(spellName, onSelf)
	if spellName:lower() == PROSPECT:lower() or spellName:lower() == MILLING:lower() then
		getContents = true
	end
end)