Merge branch 'master' into dev

This commit is contained in:
Manuel Simon Hirsig
2016-03-24 16:32:16 +01:00
8 changed files with 152 additions and 158 deletions
+3 -3
View File
@@ -63,12 +63,12 @@ function public.item_id(item_name)
end end
function private.scan_merchant() function private.scan_merchant()
Aux.util.loop_inventory(function(bag, slot) for slot in Aux.util.inventory() do
local item_info = Aux.info.container_item(bag, slot) local item_info = Aux.info.container_item(unpack(slot))
if item_info then if item_info then
aux_merchant_sell[item_info.item_id] = item_info.tooltip.money / item_info.aux_quantity aux_merchant_sell[item_info.item_id] = item_info.tooltip.money / item_info.aux_quantity
end end
end) end
-- TODO maybe more detail? zone or local merchant_name = UnitName('npc') -- TODO maybe more detail? zone or local merchant_name = UnitName('npc')
local merchant_item_count = GetMerchantNumItems() local merchant_item_count = GetMerchantNumItems()
+1 -1
View File
@@ -1,5 +1,5 @@
Aux = { Aux = {
version = '2.9.17', version = '2.9.18',
blizzard_ui_shown = false, blizzard_ui_shown = false,
orig = {}, orig = {},
} }
+30 -28
View File
@@ -9,52 +9,54 @@ function private.process()
state.allow_partial = false state.allow_partial = false
end end
local stacking_complete local stacking_complete, target_slot
local stack_slot
Aux.stack.start( Aux.stack.start(
state.item_key, state.item_key,
state.stack_size, state.stack_size,
function(slot) function(slot)
stacking_complete = true stacking_complete = true
stack_slot = slot target_slot = slot
end end
) )
Aux.control.wait_until(function() return stacking_complete end, function() return Aux.control.wait_until(function() return stacking_complete end, function()
if target_slot then
if stack_slot and Aux.info.container_item(stack_slot.bag, stack_slot.bag_slot).aux_quantity <= state.stack_size then return private.post_auction(target_slot, state.posted == state.count, private.process)
private.post_auction(stack_slot, function(stack_size)
if state.posted == state.count then
state.partial_stack = stack_size
end
state.posted = state.posted + 1
return private.process()
end)
else else
return public.stop() return public.stop()
end end
end) end)
end
return public.stop()
end
function private.post_auction(slot, partial, k)
local item_info = Aux.info.container_item(unpack(slot))
if item_info.item_key == state.item_key and Aux.info.auctionable(item_info.tooltip) and (item_info.aux_quantity == state.stack_size or partial and item_info.aux_quantity < state.stack_size) then
ClearCursor()
ClickAuctionSellItemButton()
ClearCursor()
PickupContainerItem(unpack(slot))
ClickAuctionSellItemButton()
ClearCursor()
StartAuction(max(1, Aux.round(state.unit_start_price * item_info.aux_quantity)), Aux.round(state.unit_buyout_price * item_info.aux_quantity), state.duration)
Aux.control.wait_until(function() return not GetContainerItemInfo(unpack(slot)) end, function()
if state.posted == state.count then
state.partial_stack = item_info.aux_quantity
end
state.posted = state.posted + 1
return k()
end)
else else
return public.stop() return public.stop()
end end
end end
function private.post_auction(slot, k)
ClearCursor()
ClickAuctionSellItemButton()
ClearCursor()
PickupContainerItem(slot.bag, slot.bag_slot)
ClickAuctionSellItemButton()
ClearCursor()
local stack_size = Aux.info.container_item(slot.bag, slot.bag_slot).aux_quantity
StartAuction(max(1, Aux.round(state.unit_start_price * stack_size)), Aux.round(state.unit_buyout_price * stack_size), state.duration)
Aux.control.wait_until(function() return not GetContainerItemInfo(slot.bag, slot.bag_slot) end, function()
return k(stack_size)
end)
end
function public.stop() function public.stop()
if state then if state then
Aux.control.kill_thread(state.thread_id) Aux.control.kill_thread(state.thread_id)
+5 -15
View File
@@ -747,20 +747,15 @@ function private.quantity_update()
end end
function private.unit_vendor_price(item_key) function private.unit_vendor_price(item_key)
local inventory_iterator = Aux.util.inventory_iterator()
while true do for slot in Aux.util.inventory() do
local slot = inventory_iterator()
if not slot then
break
end
local item_info = Aux.info.container_item(slot.bag, slot.bag_slot) local item_info = Aux.info.container_item(unpack(slot))
if item_info and item_info.item_key == item_key then if item_info and item_info.item_key == item_key then
if Aux.info.auctionable(item_info.tooltip, nil, item_info.lootable) then if Aux.info.auctionable(item_info.tooltip, nil, item_info.lootable) then
ClearCursor() ClearCursor()
PickupContainerItem(slot.bag, slot.bag_slot) PickupContainerItem(unpack(slot))
ClickAuctionSellItemButton() ClickAuctionSellItemButton()
local auction_sell_item = Aux.info.auction_sell_item() local auction_sell_item = Aux.info.auction_sell_item()
ClearCursor() ClearCursor()
@@ -828,14 +823,9 @@ function private.update_inventory_records()
local auction_candidate_map = {} local auction_candidate_map = {}
local inventory_iterator = Aux.util.inventory_iterator() for slot in Aux.util.inventory() do
while true do
local slot = inventory_iterator()
if not slot then
break
end
local item_info = Aux.info.container_item(slot.bag, slot.bag_slot) local item_info = Aux.info.container_item(unpack(slot))
if item_info then if item_info then
local charge_class = item_info.charges or 0 local charge_class = item_info.charges or 0
+2 -2
View File
@@ -231,8 +231,8 @@ function private.submit_query(k)
private.wait_for_results(function() private.wait_for_results(function()
local _, total_count = GetNumAuctionItems(private.current_thread().params.type) local _, total_count = GetNumAuctionItems(private.current_thread().params.type)
private.current_thread().total_pages = math.ceil(total_count / PAGE_SIZE) private.current_thread().total_pages = math.ceil(total_count / PAGE_SIZE)
if private.current_thread().total_pages >= private.current_thread().page + 1 then if max(1, private.current_thread().total_pages) >= private.current_thread().page + 1 then
private.wait_for_callback(private.current_thread().params.on_page_loaded, private.current_thread().page, private.current_thread().total_pages, function() private.wait_for_callback(private.current_thread().params.on_page_loaded, private.current_thread().page, max(1, private.current_thread().total_pages), function()
return k() return k()
end) end)
else else
+70 -75
View File
@@ -3,95 +3,103 @@ Aux.stack = public
local state local state
function private.item_slots(item_key) function private.stack_size(slot)
local slots = Aux.util.inventory_iterator() local container_item_info = Aux.info.container_item(unpack(slot))
return function() return container_item_info and container_item_info.count or 0
local slot
repeat
slot = slots()
until slot == nil or private.item_key(slot) == item_key
return slot
end
end end
function private.find_empty_slot() function private.charges(slot)
for slot in Aux.util.inventory_iterator() do local container_item_info = Aux.info.container_item(unpack(slot))
if not GetContainerItemInfo(slot.bag, slot.bag_slot) then return container_item_info and container_item_info.charges
end
function private.max_stack(slot)
local container_item_info = Aux.info.container_item(unpack(slot))
return container_item_info and container_item_info.max_stack
end
function private.locked(slot)
local container_item_info = Aux.info.container_item(unpack(slot))
return container_item_info and container_item_info.locked
end
function private.find_item_slot(partial)
for slot in Aux.util.inventory() do
if private.matching_item(slot, partial) and not Aux.util.table_eq(slot, state.target_slot) then
return slot return slot
end end
end end
end end
function private.find_charges_item_slot(item_key, charges) function private.matching_item(slot, partial)
for slot in private.item_slots(item_key) do local item_info = Aux.info.container_item(unpack(slot))
if private.item_charges(slot) == charges then return item_info and item_info.item_key == state.item_key and Aux.info.auctionable(item_info.tooltip) and (not partial or item_info.count < item_info.max_stack)
end
function private.find_empty_slot()
for slot, type in Aux.util.inventory() do
if type == 1 and not GetContainerItemInfo(unpack(slot)) then
return slot
end
end
end
function private.find_charge_item_slot()
for slot in private.item_slots(state.item_key) do
if private.charges(slot) == state.target_size then
return slot return slot
end end
end end
end end
function private.move_item(from_slot, to_slot, amount, k) function private.move_item(from_slot, to_slot, amount, k)
local size_before = private.stack_size(to_slot)
if private.locked(from_slot) or private.locked(to_slot) then
return Aux.control.wait(k)
end
amount = min(private.max_stack(from_slot) - private.stack_size(to_slot), private.stack_size(from_slot), amount) amount = min(private.max_stack(from_slot) - private.stack_size(to_slot), private.stack_size(from_slot), amount)
local expected_size = private.stack_size(to_slot) + amount
ClearCursor() ClearCursor()
SplitContainerItem(from_slot.bag, from_slot.bag_slot, amount) SplitContainerItem(from_slot[1], from_slot[2], amount)
PickupContainerItem(to_slot.bag, to_slot.bag_slot) PickupContainerItem(unpack(to_slot))
return Aux.control.wait_until(function() return private.stack_size(to_slot) == size_before + amount end, k) return Aux.control.wait_until(function() return private.stack_size(to_slot) == expected_size end, k)
end
function private.item_key(slot)
local container_item_info = Aux.info.container_item(slot.bag, slot.bag_slot)
return container_item_info and container_item_info.item_key
end
function private.stack_size(slot)
local container_item_info = Aux.info.container_item(slot.bag, slot.bag_slot)
return container_item_info and container_item_info.count or 0
end
function private.item_charges(slot)
local container_item_info = Aux.info.container_item(slot.bag, slot.bag_slot)
return container_item_info and container_item_info.charges
end end
function private.process() function private.process()
if private.stack_size(state.target_slot) > state.target_size then if not state.target_slot or not private.matching_item(state.target_slot) then
local empty_slot = private.find_empty_slot() state.target_slot = private.find_item_slot()
if not state.target_slot then
return public.stop()
end
end
if empty_slot then if private.charges(state.target_slot) then
state.target_slot = private.find_charge_item_slot()
return public.stop()
end
if private.stack_size(state.target_slot) > state.target_size then
local slot = private.find_item_slot(true) or private.find_empty_slot()
if slot then
return private.move_item( return private.move_item(
state.target_slot, state.target_slot,
empty_slot, slot,
private.stack_size(state.target_slot) - state.target_size, private.stack_size(state.target_slot) - state.target_size,
function() private.process
return private.process() )
end)
else
local next_slot = state.other_slots()
if next_slot then
return private.move_item(
state.target_slot,
next_slot,
private.stack_size(state.target_slot) - state.target_size,
function()
return private.process()
end)
end
end end
elseif private.stack_size(state.target_slot) < state.target_size then elseif private.stack_size(state.target_slot) < state.target_size then
local next_slot = state.other_slots() local slot = private.find_item_slot()
if next_slot then if slot then
return private.move_item( return private.move_item(
next_slot, slot,
state.target_slot, state.target_slot,
state.target_size - private.stack_size(state.target_slot), state.target_size - private.stack_size(state.target_slot),
function() private.process
return private.process()
end
) )
end end
end end
@@ -99,16 +107,14 @@ function private.process()
return public.stop() return public.stop()
end end
function private.max_stack(slot)
local container_item_info = Aux.info.container_item(slot.bag, slot.bag_slot)
return container_item_info and container_item_info.max_stack
end
function public.stop() function public.stop()
if state then if state then
Aux.control.kill_thread(state.thread_id) Aux.control.kill_thread(state.thread_id)
local callback, slot = state.callback, state.target_slot local callback, slot = state.callback, state.target_slot
if not private.matching_item(slot) then
slot = nil
end
state = nil state = nil
@@ -121,23 +127,12 @@ end
function public.start(item_key, size, callback) function public.start(item_key, size, callback)
public.stop() public.stop()
local slots = private.item_slots(item_key)
local target_slot = slots()
local thread_id = Aux.control.new_thread(private.process) local thread_id = Aux.control.new_thread(private.process)
state = { state = {
thread_id = thread_id, thread_id = thread_id,
item_key = item_key,
target_size = size, target_size = size,
target_slot = target_slot,
other_slots = slots,
callback = callback, callback = callback,
} }
if not target_slot then
public.stop()
elseif private.item_charges(target_slot) then
state.target_slot = private.find_charges_item_slot(item_key, size)
public.stop()
end
end end
+5 -9
View File
@@ -239,15 +239,11 @@ end
function game_tooltip_hooks:SetAuctionSellItem() function game_tooltip_hooks:SetAuctionSellItem()
local name, _, quantity, _, _, _ = GetAuctionSellItemInfo() local name, _, quantity, _, _, _ = GetAuctionSellItemInfo()
if name then if name then
for bag = 0, 4 do for slot in Aux.util.inventory() do
if GetBagName(bag) then local link = GetContainerItemLink(unpack(slot))
for slot = 1, GetContainerNumSlots(bag) do if link and ({Aux.info.parse_hyperlink(link)})[5] == name then
local link = GetContainerItemLink(bag, slot) private.extend_tooltip(GameTooltip, link, quantity)
if link and ({Aux.info.parse_hyperlink(link)})[5] == name then return
private.extend_tooltip(GameTooltip, link, quantity)
return
end
end
end end
end end
end end
+34 -23
View File
@@ -9,11 +9,16 @@ function public.id(object)
end end
function public.table_eq(t1, t2) function public.table_eq(t1, t2)
if not t1 or not t2 then
return false
end
for key, value in t1 do for key, value in t1 do
if t2[key] ~= value then if t2[key] ~= value then
return false return false
end end
end end
return true return true
end end
@@ -46,32 +51,38 @@ function public.trim(string)
return string return string
end end
function Aux.util.inventory_iterator() function public.inventory()
local inventory = {} local bag, slot = 0, 0
for bag = 0, 4 do
if GetBagName(bag) then
for bag_slot = 1, GetContainerNumSlots(bag) do
tinsert(inventory, { bag = bag, bag_slot = bag_slot })
end
end
end
local i = 0 return function()
local n = getn(inventory) if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then
return function() repeat
i = i + 1 bag = bag + 1
if i <= n then until GetBagName(bag) or bag > 4
return inventory[i] slot = 1
end else
end slot = slot + 1
end
if bag <= 4 then
return { bag, slot }, public.bag_type(bag)
end
end
end end
function public.loop_inventory(f) do
for bag = 0, 4 do local bag_types = { GetAuctionItemSubClasses(3) }
if GetBagName(bag) then
for slot = 1, GetContainerNumSlots(bag) do function public.bag_type(bag)
f(bag, slot) if bag == 0 then
end return 1
end
local link = GetInventoryItemLink('player', ContainerIDToInventoryID(bag))
if link then
local item_id = Aux.info.parse_hyperlink(GetInventoryItemLink('player', ContainerIDToInventoryID(bag)))
local item_info = Aux.info.item(item_id)
return Aux.item_subclass_index(3, item_info.subclass)
end end
end end
end end