view ProspectMe.lua @ 11:61b9ea84a44c

Added groundwork for Legion mass prospecting and milling.
author Geoff Brock <mischivin@gmail.com>
date Wed, 17 Aug 2016 13:41:17 -0400
parents 69b46322ff1b
children c5a66cdf45e2
line wrap: on
line source
local PROSPECT_ID = 31252
local MILLING_ID = 51005
local MASS_PROSPECT_FELSLATE_ID = 225902
local MASS_PROSPECT_LEYSTONE_ID = 225902
local MASS_MILLING_YSERALLINE_ID = 210116
local PROSPECT = GetSpellInfo(PROSPECT_ID)
local MILLING = GetSpellInfo(MILLING_ID)
local MASS_PROSPECT_FELSLATE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID)
local MASS_PROSPECT_LEYSTONE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID)
local MASS_MILLING_YSERALLINE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID)
local containerID, containerLink = nil, nil
local getContents = false
local bulkMultiplier = 1 --This will be used for mass prospecting/milling in Legion

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 + bulkMultiplier
	PM_SessionTable[containerID].timesProspected = PM_SessionTable[containerID].timesProspected + bulkMultiplier
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() or spellName:lower() == MASS_PROSPECT_FELSLATE:lower() or spellName:lower() == MASS_PROSPECT_LEYSTONE:lower() or spellName:lower() == MASS_MILLING_YSERALLINE :lower () then
		getContents = true
		if spellName:lower() == MASS_PROSPECT_FELSLATE:lower() or spellName:lower() == MASS_PROSPECT_LEYSTONE:lower() or spellName:lower() == MASS_MILLING_YSERALLINE :lower () then
			bulkMultiplier = 4
		else
			bulkMultiplier = 1
		end
	end
end)

hooksecurefunc("CastSpellByID", function(spellID)
	if spellID == PROSPECT_ID or spellID == MILLING_ID or spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then
		getContents = true
		if spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then
			bulkMultiplier = 4
		else
			bulkMultiplier = 1
		end
	end
end)

hooksecurefunc("UseAction", function(actionID)
	local spellID = select(2, GetActionInfo(actionID))
	if spellID == PROSPECT_ID or spellID == MILLING_ID or spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then
		getContents = true
		if spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then
			bulkMultiplier = 4
		else
			bulkMultiplier = 1
		end
	end
end)

hooksecurefunc("CastSpellByName", function(spellName, onSelf)
	if spellName:lower() == PROSPECT:lower() or spellName:lower() == MILLING:lower() or spellName:lower() == MASS_PROSPECT_FELSLATE:lower() or spellName:lower() == MASS_PROSPECT_LEYSTONE:lower() or spellName:lower() == MASS_MILLING_YSERALLINE :lower () then
		getContents = true
		if spellName:lower() == MASS_PROSPECT_FELSLATE:lower() or spellName:lower() == MASS_PROSPECT_LEYSTONE:lower() or spellName:lower() == MASS_MILLING_YSERALLINE :lower () then
			bulkMultiplier = 4
		else
			bulkMultiplier = 1
		end
	end
end)