Fix market issue with non stackable items.

This commit is contained in:
BeniS 2012-07-31 21:47:24 +12:00
parent f4641333f4
commit 82bfdc566f
1 changed files with 49 additions and 34 deletions

View File

@ -358,31 +358,39 @@ local function updateDepotItemCount(itemId, amount)
if depotItem and itemId == depotItem.ptr:getId() then if depotItem and itemId == depotItem.ptr:getId() then
local depotItemCount = depotItem.ptr:getCount() local depotItemCount = depotItem.ptr:getCount()
if depotItemCount <= 100 and depotItemCount >= amount then if depotItem.ptr:isStackable() then
if (depotItemCount - amount) <= 0 then if depotItemCount <= 100 and depotItemCount >= amount then
table.remove(information.depotItems, i) if (depotItemCount - amount) <= 0 then
else table.remove(information.depotItems, i)
depotItem.ptr:setCount(depotItemCount - amount)
information.depotItems[i] = depotItem
end
return true
else
local removeCount = math.floor(amount/100)
local remainder = amount % depotItemCount
if remainder > 0 then
removeCount = removeCount + 1
end
for i = 1, removeCount do
if i == removeCount and remainder > 0 then
updateDepotItemCount(itemId, remainder)
else else
updateDepotItemCount(itemId, 100) depotItem.ptr:setCount(depotItemCount - amount)
information.depotItems[i] = depotItem
end end
return true
else
local removeCount = math.floor(amount/100)
local remainder = amount % depotItemCount
if remainder > 0 then
removeCount = removeCount + 1
end
for j = 1, removeCount do
if j == removeCount and remainder > 0 then
updateDepotItemCount(itemId, remainder)
else
updateDepotItemCount(itemId, 100)
end
end
return true
end
else
if amount > 0 then
table.remove(information.depotItems, i)
amount = amount - 1
end end
return true
end end
end end
end end
return false
end end
local function updateFee(price, amount) local function updateFee(price, amount)
@ -873,25 +881,32 @@ function Market.loadDepotItems(depotItems)
local data = depotItems[i] local data = depotItems[i]
local id, count = data[1], data[2] local id, count = data[1], data[2]
if count > 100 then local tmpItem = Item.create(id)
local createCount = math.floor(count/100) if tmpItem:isStackable() then
local remainder = count % 100 if count > 100 then
if remainder > 0 then local createCount = math.floor(count/100)
createCount = createCount + 1 local remainder = count % 100
end if remainder > 0 then
for i = 1, createCount do createCount = createCount + 1
local newItem = Item.create(id)
if i == createCount and remainder > 0 then
newItem:setCount(remainder)
else
newItem:setCount(100)
end end
for i = 1, createCount do
local newItem = Item.create(id)
if i == createCount and remainder > 0 then
newItem:setCount(remainder)
else
newItem:setCount(100)
end
table.insert(items, newItem)
end
else
local newItem = Item.create(id)
newItem:setCount(count)
table.insert(items, newItem) table.insert(items, newItem)
end end
else else
local newItem = Item.create(id) for i = 1, count do
newItem:setCount(count) table.insert(items, Item.create(id))
table.insert(items, newItem) end
end end
end end