big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-19 11:57:12 +02:00
parent 667990f7d8
commit 7740ba2f7a
28 changed files with 271 additions and 266 deletions
+11 -11
View File
@@ -1,28 +1,28 @@
aux.module 'stack'
private.state = nil
state = nil
function private.stack_size(slot)
function stack_size(slot)
local container_item_info = aux.info.container_item(unpack(slot))
return container_item_info and container_item_info.count or 0
end
function private.charges(slot)
function charges(slot)
local container_item_info = aux.info.container_item(unpack(slot))
return container_item_info and container_item_info.charges
end
function private.max_stack(slot)
function 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)
function 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)
function find_item_slot(partial)
for slot in aux.util.inventory() do
if m.matching_item(slot, partial) and not aux.util.eq(slot, m.state.target_slot) then
return slot
@@ -30,12 +30,12 @@ function private.find_item_slot(partial)
end
end
function private.matching_item(slot, partial)
function matching_item(slot, partial)
local item_info = aux.info.container_item(unpack(slot))
return item_info and item_info.item_key == m.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()
function find_empty_slot()
for slot, type in aux.util.inventory() do
if type == 1 and not GetContainerItemInfo(unpack(slot)) then
return slot
@@ -43,7 +43,7 @@ function private.find_empty_slot()
end
end
function private.find_charge_item_slot()
function find_charge_item_slot()
for slot in aux.util.inventory() do
if m.matching_item(slot) and m.charges(slot) == m.state.target_size then
return slot
@@ -51,7 +51,7 @@ function private.find_charge_item_slot()
end
end
function private.move_item(from_slot, to_slot, amount, k)
function move_item(from_slot, to_slot, amount, k)
if m.locked(from_slot) or m.locked(to_slot) then
return aux.control.wait(k)
end
@@ -66,7 +66,7 @@ function private.move_item(from_slot, to_slot, amount, k)
return aux.control.when(function() return m.stack_size(to_slot) == expected_size end, k)
end
function private.process()
function process()
if not m.state.target_slot or not m.matching_item(m.state.target_slot) then
m.state.target_slot = m.find_item_slot()