working on big scan/control refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-02-25 15:43:18 +01:00
parent 8d888f4e96
commit 5af1b28021
6 changed files with 78 additions and 158 deletions
+33 -41
View File
@@ -1,16 +1,16 @@
local private, public = {}, {}
Aux.post = public
local controller = (function()
local controller
return function()
controller = controller or Aux.control.controller()
return controller
end
end)()
local state
function private.as_soon_as(p, k)
if p() then
return k()
else
return Aux.control.wait(private.as_soon_as, p, k)
end
end
function private.process()
if state.posted < state.count or state.allow_partial then
if state.posted == state.count then
@@ -28,8 +28,8 @@ function private.process()
stack_slot = slot
end
)
controller().wait(function() return stacking_complete end, function()
private.as_soon_as(function() return stacking_complete end, function()
if stack_slot and Aux.info.container_item(stack_slot.bag, stack_slot.bag_slot).aux_quantity <= state.stack_size then
private.post_auction(stack_slot, function(stack_size)
@@ -40,12 +40,12 @@ function private.process()
return private.process()
end)
else
return private.stop()
return public.stop()
end
end)
else
return private.stop()
return public.stop()
end
end
@@ -58,13 +58,15 @@ function private.post_auction(slot, k)
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)
controller().wait(function() return not GetContainerItemInfo(slot.bag, slot.bag_slot) end, function()
private.as_soon_as(function() return not GetContainerItemInfo(slot.bag, slot.bag_slot) end, function()
return k(stack_size)
end)
end
function private.stop()
function public.stop()
if state then
Aux.control.kill(state.thread_id)
local callback = state.callback
local posted = state.posted
local partial_stack = state.partial_stack
@@ -77,32 +79,22 @@ function private.stop()
end
end
function public.stop(k)
controller().wait(function()
private.stop()
if k then
return k()
end
end)
end
function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, allow_partial, callback)
controller().wait(function()
private.stop()
state = {
item_key = item_key,
stack_size = stack_size,
duration = duration,
unit_start_price = unit_start_price,
unit_buyout_price = unit_buyout_price,
count = count,
allow_partial = allow_partial,
posted = 0,
callback = callback,
}
return private.process()
end)
public.stop()
local thread_id = Aux.control.new(private.process)
state = {
thread_id = thread_id,
item_key = item_key,
stack_size = stack_size,
duration = duration,
unit_start_price = unit_start_price,
unit_buyout_price = unit_buyout_price,
count = count,
allow_partial = allow_partial,
posted = 0,
callback = callback,
}
end